From d46517559b530855f87055d511b9057f3dec2cd2 Mon Sep 17 00:00:00 2001 From: Thomas Prescher Date: Wed, 21 May 2025 16:11:55 +0200 Subject: [PATCH] vmm: don't allow resizing to 0 vCPUs No sane guest OS will allow hotplugging all cpus. However, the REST API currently allows specifying `ch-remote resize --cpus 0`. On Linux, we can then observe the following error in the kernel log: processor cpu0: Offline failed. Subsequent resize commands via ch-remote will then fail with VcpuPendingRemovedVcpu because the removal of cpu0 was never successful. Fix this by disallowing resizing to zero vCPUs. Signed-off-by: Thomas Prescher On-behalf-of: SAP thomas.prescher@sap.com --- vmm/src/cpu.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/vmm/src/cpu.rs b/vmm/src/cpu.rs index 11d4f2dc9..166a9104c 100644 --- a/vmm/src/cpu.rs +++ b/vmm/src/cpu.rs @@ -157,6 +157,9 @@ pub enum Error { #[error("Error adding CpuManager to MMIO bus: {0}")] BusError(#[source] vm_device::BusError), + #[error("Requested zero vCPUs")] + DesiredVCpuCountIsZero, + #[error("Requested vCPUs exceed maximum")] DesiredVCpuCountExceedsMax, @@ -1320,6 +1323,10 @@ impl CpuManager { return Ok(false); } + if desired_vcpus < 1 { + return Err(Error::DesiredVCpuCountIsZero); + } + if self.check_pending_removed_vcpu() { return Err(Error::VcpuPendingRemovedVcpu); }