From f5137e84bb2f6e662b3d11b24d2c77e3ab02a0f2 Mon Sep 17 00:00:00 2001 From: Rob Bradford Date: Tue, 7 Jan 2020 11:25:55 +0000 Subject: [PATCH] vmm, main: Add optional "hotplug_size" to --mem This specifies how much address space should be reserved for hotplugging of RAM. This space is reserved by adding move the start of the device area by the desired amount. Signed-off-by: Rob Bradford --- src/main.rs | 4 +++- vmm/src/config.rs | 11 +++++++++++ vmm/src/memory_manager.rs | 7 ++++++- vmm/src/vm.rs | 1 + 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 3a943cf86..f5d065443 100755 --- a/src/main.rs +++ b/src/main.rs @@ -94,7 +94,8 @@ fn create_app<'a, 'b>( .long("memory") .help( "Memory parameters \"size=,\ - file=,mergeable=on|off\"", + file=,mergeable=on|off,\ + hotplug_size=\"", ) .default_value(&default_memory) .group("vm-config"), @@ -451,6 +452,7 @@ mod unit_tests { size: 536_870_912, file: None, mergeable: false, + hotplug_size: None, }, kernel: None, cmdline: CmdlineConfig { diff --git a/vmm/src/config.rs b/vmm/src/config.rs index 35afc2062..cf3f4f08b 100644 --- a/vmm/src/config.rs +++ b/vmm/src/config.rs @@ -248,6 +248,8 @@ pub struct MemoryConfig { pub file: Option, #[serde(default)] pub mergeable: bool, + #[serde(default)] + pub hotplug_size: Option, } impl MemoryConfig { @@ -259,6 +261,7 @@ impl MemoryConfig { let mut file_str: &str = ""; let mut mergeable_str: &str = ""; let mut backed = false; + let mut hotplug_str: &str = ""; for param in params_list.iter() { if param.starts_with("size=") { @@ -268,6 +271,8 @@ impl MemoryConfig { file_str = ¶m[5..]; } else if param.starts_with("mergeable=") { mergeable_str = ¶m[10..]; + } else if param.starts_with("hotplug_size=") { + hotplug_str = ¶m[13..] } } @@ -285,6 +290,11 @@ impl MemoryConfig { size: parse_size(size_str)?, file, mergeable: parse_on_off(mergeable_str)?, + hotplug_size: if hotplug_str == "" { + None + } else { + Some(parse_size(hotplug_str)?) + }, }) } } @@ -295,6 +305,7 @@ impl Default for MemoryConfig { size: DEFAULT_MEMORY_MB << 20, file: None, mergeable: false, + hotplug_size: None, } } } diff --git a/vmm/src/memory_manager.rs b/vmm/src/memory_manager.rs index 86930a89a..1d223964d 100644 --- a/vmm/src/memory_manager.rs +++ b/vmm/src/memory_manager.rs @@ -81,6 +81,7 @@ impl MemoryManager { allocator: Arc>, fd: Arc, boot_ram: u64, + hotplug_size: Option, backing_file: &Option, mergeable: bool, ) -> Result>, Error> { @@ -107,12 +108,16 @@ impl MemoryManager { let end_of_device_area = GuestAddress((1 << get_host_cpu_phys_bits()) - 1); let mem_end = guest_memory.end_addr(); - let start_of_device_area = if mem_end < arch::layout::MEM_32BIT_RESERVED_START { + let mut start_of_device_area = if mem_end < arch::layout::MEM_32BIT_RESERVED_START { arch::layout::RAM_64BIT_START } else { mem_end.unchecked_add(1) }; + if let Some(size) = hotplug_size { + start_of_device_area = start_of_device_area.unchecked_add(size); + } + let guest_memory = Arc::new(ArcSwap::new(Arc::new(guest_memory))); let memory_manager = Arc::new(Mutex::new(MemoryManager { diff --git a/vmm/src/vm.rs b/vmm/src/vm.rs index 8e58a619d..1a933f8e4 100755 --- a/vmm/src/vm.rs +++ b/vmm/src/vm.rs @@ -309,6 +309,7 @@ impl Vm { allocator.clone(), fd.clone(), memory_config.size, + memory_config.hotplug_size, &memory_config.file, memory_config.mergeable, )