misc: Change cpu ID type from u8 to u32

This is the first change to Cloud Hypervisor in a series of changes
intended to increase the max number of supported vCPUs in guest VMs,
which is currently limited to 255 (254 on x86_64).

No user-visible/behavior changes are expected as a result of
applying this patch, as the type of boot_cpus and related
fields in config structs remains u8 for now, and all configuration
validations remain the same.

Signed-off-by: Barret Rhoden <brho@google.com>
Signed-off-by: Neel Natu <neelnatu@google.com>
Signed-off-by: Ofir Weisse <oweisse@google.com>
Signed-off-by: Peter Oskolkov <posk@google.com>
This commit is contained in:
Peter Oskolkov
2025-07-29 19:02:20 +00:00
committed by Bo Chen
parent 5d478c534e
commit aa8e9cd91a
21 changed files with 116 additions and 123 deletions

View File

@@ -621,7 +621,7 @@ impl Vm {
#[cfg(feature = "tdx")]
if tdx_enabled {
let cpuid = cpu_manager.lock().unwrap().common_cpuid();
let max_vcpus = cpu_manager.lock().unwrap().max_vcpus() as u32;
let max_vcpus = cpu_manager.lock().unwrap().max_vcpus();
vm.tdx_init(&cpuid, max_vcpus)
.map_err(Error::InitializeTdxVm)?;
}
@@ -948,7 +948,7 @@ impl Vm {
}
if let Some(cpus) = &config.cpus {
node.cpus.extend(cpus);
node.cpus.extend(cpus.iter().map(|cpu| *cpu as u32));
}
if let Some(pci_segments) = &config.pci_segments {
@@ -1719,7 +1719,7 @@ impl Vm {
pub fn resize(
&mut self,
desired_vcpus: Option<u8>,
desired_vcpus: Option<u32>,
desired_memory: Option<u64>,
desired_balloon: Option<u64>,
) -> Result<()> {
@@ -1739,7 +1739,7 @@ impl Vm {
.notify_hotplug(AcpiNotificationFlags::CPU_DEVICES_CHANGED)
.map_err(Error::DeviceManager)?;
}
self.config.lock().unwrap().cpus.boot_vcpus = desired_vcpus;
self.config.lock().unwrap().cpus.boot_vcpus = desired_vcpus.try_into().unwrap();
}
if let Some(desired_memory) = desired_memory {