Skip to content

Commit ebd2ed4

Browse files
authored
Merge pull request #2325 from microsoft/agents/issue-2317-ram-upper-caps
nvx: check the RAM upper's cap with the shared range
2 parents 8fc7a5f + 3cd9a8e commit ebd2ed4

2 files changed

Lines changed: 12 additions & 10 deletions

File tree

‎nvx/src/guest_restore/mod.rs‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ use std::net::IpAddr;
176176

177177
use crate::hex::write_hex;
178178
use crate::protocol::MAX_HOST_MAPPINGS;
179-
use crate::protocol::root::{ImageFormat, Journal, OverlayMode};
179+
use crate::protocol::root::{ImageFormat, Journal, OverlayMode, RAM_UPPER_CAPS};
180180
use crate::protocol::view::{MAX_HOSTNAME_BYTES, View, is_hostname};
181181
use crate::uuid::Uuid;
182182

@@ -390,7 +390,7 @@ impl Configuration {
390390
return Err(GuestRestoreError::FirstPartitionBound);
391391
}
392392
if let Upper::Tmpfs { max_memory_percent } = self.upper
393-
&& !(1..=90).contains(&max_memory_percent)
393+
&& !RAM_UPPER_CAPS.contains(&max_memory_percent)
394394
{
395395
return Err(GuestRestoreError::TmpfsMemoryPercent(max_memory_percent));
396396
}
@@ -533,7 +533,9 @@ impl fmt::Display for GuestRestoreError {
533533
}
534534
Self::TmpfsMemoryPercent(percent) => write!(
535535
formatter,
536-
"the tmpfs cap of {percent}% of the VM's memory is not 1 to 90%"
536+
"the tmpfs cap of {percent}% of the VM's memory is not {} to {}%",
537+
RAM_UPPER_CAPS.start(),
538+
RAM_UPPER_CAPS.end()
537539
),
538540
Self::ExportWithoutMappings => formatter.write_str("the export has no mappings"),
539541
Self::MappingsWithoutExport => formatter.write_str("the mappings have no export"),

‎nvx/src/host/config/mod.rs‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ mod command_line;
1212
use std::collections::BTreeMap;
1313
use std::ffi::{OsStr, OsString};
1414
use std::fmt;
15-
use std::ops::RangeInclusive;
1615
use std::path::{Path, PathBuf};
1716
use std::time::Duration;
1817

@@ -27,7 +26,9 @@ use crate::hex::{parse_hex, write_hex};
2726
use crate::net::Ipv4Cidr;
2827
use crate::protocol::cmdline::{self, Parameter};
2928
use crate::protocol::maps::HostMap;
30-
use crate::protocol::root::{ImageFormat, Journal, OverlayMode, RootImage, RootLayout, RootUpper};
29+
use crate::protocol::root::{
30+
ImageFormat, Journal, OverlayMode, RAM_UPPER_CAPS, RootImage, RootLayout, RootUpper,
31+
};
3132
use crate::protocol::view::{self, MAX_HOSTNAME_BYTES, View};
3233

3334
pub(crate) use self::command_line::check_argument_nuls;
@@ -47,9 +48,6 @@ const OPENVMM_COMMAND_LINE_RESERVE: usize = 2048;
4748
/// that [`Ipv4Cidr::parse`] reads.
4849
pub const DEFAULT_GUEST_NETWORK: &str = "10.0.0.2/24";
4950

50-
/// The caps of a RAM upper that [`VmConfig::check`] accepts, in percent of the VM's memory.
51-
const RAM_UPPER_CAPS: RangeInclusive<u8> = 1..=90;
52-
5351
/// The names of the cold boot tokens that OpenVMM's machine profile owns and supplies itself,
5452
/// beside the `virtfs_*` ones that NVX reserves: the consoles, device discovery, the NIC's
5553
/// bootstrap, the processor capacity, the capture tier, and the workload's identity and lifecycle.
@@ -1129,8 +1127,10 @@ impl LayeredRoot {
11291127
if !RAM_UPPER_CAPS.contains(max_memory_percent) =>
11301128
{
11311129
Err(Error::unsupported(format!(
1132-
"the RAM upper's cap of {max_memory_percent}% of the VM's memory is not 1 to \
1133-
90%"
1130+
"the RAM upper's cap of {max_memory_percent}% of the VM's memory is not {} to \
1131+
{}%",
1132+
RAM_UPPER_CAPS.start(),
1133+
RAM_UPPER_CAPS.end()
11341134
)))
11351135
}
11361136
_ => Ok(()),

0 commit comments

Comments
 (0)