From b95e46565c895ed8fad0be15bc8904a943ee7bb0 Mon Sep 17 00:00:00 2001 From: Rob Bradford Date: Wed, 12 Jan 2022 10:50:08 +0000 Subject: [PATCH] vmm: Support using existing files for memory slots Signed-off-by: Rob Bradford --- vmm/src/memory_manager.rs | 14 +++++++++++--- vmm/src/vm.rs | 2 ++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/vmm/src/memory_manager.rs b/vmm/src/memory_manager.rs index de8303c06..db4188ca8 100644 --- a/vmm/src/memory_manager.rs +++ b/vmm/src/memory_manager.rs @@ -532,6 +532,7 @@ impl MemoryManager { guest_ram_mappings: &[GuestRamMapping], zones_config: &[MemoryZoneConfig], prefault: Option, + mut existing_memory_files: HashMap, ) -> Result<(Vec>, MemoryZones), Error> { let mut memory_regions = Vec::new(); let mut memory_zones = HashMap::new(); @@ -556,7 +557,7 @@ impl MemoryManager { zone_config.hugepages, zone_config.hugepage_size, zone_config.host_numa_node, - None, + existing_memory_files.remove(&guest_ram_mapping.slot), )?; memory_regions.push(Arc::clone(®ion)); if let Some(memory_zone) = memory_zones.get_mut(&guest_ram_mapping.zone_id) { @@ -819,6 +820,7 @@ impl MemoryManager { Ok(()) } + #[allow(clippy::too_many_arguments)] pub fn new( vm: Arc, config: &MemoryConfig, @@ -826,6 +828,7 @@ impl MemoryManager { phys_bits: u8, #[cfg(feature = "tdx")] tdx_enabled: bool, restore_data: Option<&MemoryManagerSnapshotData>, + existing_memory_files: Option>, #[cfg(target_arch = "x86_64")] sgx_epc_config: Option>, ) -> Result>, Error> { let user_provided_zones = config.size == 0; @@ -855,8 +858,12 @@ impl MemoryManager { selected_slot, next_hotplug_slot, ) = if let Some(data) = restore_data { - let (regions, memory_zones) = - Self::restore_memory_regions_and_zones(&data.guest_ram_mappings, &zones, prefault)?; + let (regions, memory_zones) = Self::restore_memory_regions_and_zones( + &data.guest_ram_mappings, + &zones, + prefault, + existing_memory_files.unwrap_or_default(), + )?; let guest_memory = GuestMemoryMmap::from_arc_regions(regions).map_err(Error::GuestMemory)?; let boot_guest_memory = guest_memory.clone(); @@ -1096,6 +1103,7 @@ impl MemoryManager { #[cfg(feature = "tdx")] false, Some(&mem_snapshot), + None, #[cfg(target_arch = "x86_64")] None, )?; diff --git a/vmm/src/vm.rs b/vmm/src/vm.rs index 733c95e52..ecd6f1057 100644 --- a/vmm/src/vm.rs +++ b/vmm/src/vm.rs @@ -777,6 +777,7 @@ impl Vm { #[cfg(feature = "tdx")] tdx_enabled, None, + None, #[cfg(target_arch = "x86_64")] sgx_epc_config, ) @@ -896,6 +897,7 @@ impl Vm { #[cfg(feature = "tdx")] false, Some(memory_manager_data), + None, #[cfg(target_arch = "x86_64")] None, )