From f049867cd9c795eb50dbe9b64bdb9c877bc15795 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Date: Tue, 29 Mar 2022 21:32:01 +0200 Subject: [PATCH] vmm,memory_manager: Deny resizing only if the ram amount has changed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Similarly to the previous commit restricting the cpu resizing error only to the situations where the vcpu amount has changed, let's do the same with the memory and be consistent throughout our code base. Signed-off-by: Fabiano FidĂȘncio --- vmm/src/memory_manager.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/vmm/src/memory_manager.rs b/vmm/src/memory_manager.rs index f14be089b..0dfbbe939 100644 --- a/vmm/src/memory_manager.rs +++ b/vmm/src/memory_manager.rs @@ -1605,10 +1605,6 @@ impl MemoryManager { /// use case never adds a new region as the whole hotpluggable memory has /// already been allocated at boot time. pub fn resize(&mut self, desired_ram: u64) -> Result>, Error> { - if !self.dynamic { - return Err(Error::ResizingNotSupported); - } - if self.user_provided_zones { error!( "Not allowed to resize guest memory when backed with user \ @@ -1621,12 +1617,20 @@ impl MemoryManager { match self.hotplug_method { HotplugMethod::VirtioMem => { if desired_ram >= self.boot_ram { + if !self.dynamic { + return Err(Error::ResizingNotSupported); + } + self.virtio_mem_resize(DEFAULT_MEMORY_ZONE, desired_ram - self.boot_ram)?; self.current_ram = desired_ram; } } HotplugMethod::Acpi => { if desired_ram > self.current_ram { + if !self.dynamic { + return Err(Error::ResizingNotSupported); + } + region = Some(self.hotplug_ram_region((desired_ram - self.current_ram) as usize)?); self.current_ram = desired_ram;