diff --git a/vmm/src/memory_manager.rs b/vmm/src/memory_manager.rs index c20febec4..64508f448 100644 --- a/vmm/src/memory_manager.rs +++ b/vmm/src/memory_manager.rs @@ -1093,25 +1093,11 @@ impl MemoryManager { Ok(start_addr) } - fn hotplug_ram_region(&mut self, size: usize) -> Result, Error> { - info!("Hotplugging new RAM: {}", size); - - // Check that there is a free slot - if self.next_hotplug_slot >= HOTPLUG_COUNT { - return Err(Error::NoSlotAvailable); - } - - // "Inserted" DIMM must have a size that is a multiple of 128MiB - if size % (128 << 20) != 0 { - return Err(Error::InvalidSize); - } - - let start_addr = MemoryManager::start_addr(self.guest_memory.memory().last_addr(), true)?; - - if start_addr.checked_add(size.try_into().unwrap()).unwrap() > self.start_of_device_area() { - return Err(Error::InsufficientHotplugRAM); - } - + pub fn add_ram_region( + &mut self, + start_addr: GuestAddress, + size: usize, + ) -> Result, Error> { // Allocate memory for the region let region = MemoryManager::create_ram_region( &None, @@ -1140,6 +1126,32 @@ impl MemoryManager { slot, }); + self.add_region(Arc::clone(®ion))?; + + Ok(region) + } + + fn hotplug_ram_region(&mut self, size: usize) -> Result, Error> { + info!("Hotplugging new RAM: {}", size); + + // Check that there is a free slot + if self.next_hotplug_slot >= HOTPLUG_COUNT { + return Err(Error::NoSlotAvailable); + } + + // "Inserted" DIMM must have a size that is a multiple of 128MiB + if size % (128 << 20) != 0 { + return Err(Error::InvalidSize); + } + + let start_addr = MemoryManager::start_addr(self.guest_memory.memory().last_addr(), true)?; + + if start_addr.checked_add(size.try_into().unwrap()).unwrap() > self.start_of_device_area() { + return Err(Error::InsufficientHotplugRAM); + } + + let region = self.add_ram_region(start_addr, size)?; + // Tell the allocator self.allocator .lock() @@ -1156,8 +1168,6 @@ impl MemoryManager { self.next_hotplug_slot += 1; - self.add_region(Arc::clone(®ion))?; - Ok(region) }