From 50c7c098674de1cadc1690a1dcc46cab2247dcaa Mon Sep 17 00:00:00 2001 From: KshitijKapoor8 Date: Mon, 6 May 2024 15:09:43 -0500 Subject: [PATCH 1/6] arch: change vcpu variable size Modified vcpu related information to support more vcpu's. Signed-off-by: Kshitij Kapoor --- arch/src/aarch64/fdt.rs | 4 ++-- arch/src/aarch64/mod.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/src/aarch64/fdt.rs b/arch/src/aarch64/fdt.rs index af2695d01e..6e5da38a68 100644 --- a/arch/src/aarch64/fdt.rs +++ b/arch/src/aarch64/fdt.rs @@ -219,7 +219,7 @@ pub fn create_fdt, - vcpu_topology: Option<(u8, u8, u8)>, + vcpu_topology: Option<(u32, u32, u32)>, device_info: &HashMap<(DeviceType, String), T, S>, gic_device: &Arc>, initrd: &Option, @@ -281,7 +281,7 @@ pub fn write_fdt_to_memory(fdt_final: Vec, guest_mem: &GuestMemoryMmap) -> R fn create_cpu_nodes( fdt: &mut FdtWriter, vcpu_mpidr: &[u64], - vcpu_topology: Option<(u8, u8, u8)>, + vcpu_topology: Option<(u32, u32, u32)>, numa_nodes: &NumaNodes, ) -> FdtWriterResult<()> { // See https://github.com/torvalds/linux/blob/master/Documentation/devicetree/bindings/arm/cpus.yaml. diff --git a/arch/src/aarch64/mod.rs b/arch/src/aarch64/mod.rs index 7b11028261..d3f98061b0 100644 --- a/arch/src/aarch64/mod.rs +++ b/arch/src/aarch64/mod.rs @@ -125,7 +125,7 @@ pub fn configure_system, - vcpu_topology: Option<(u8, u8, u8)>, + vcpu_topology: Option<(u32, u32, u32)>, device_info: &HashMap<(DeviceType, String), T, S>, initrd: &Option, pci_space_info: &[PciSpaceInfo], From 2bf950670a7c1960f00fa7e7bb011e40af7a1950 Mon Sep 17 00:00:00 2001 From: KshitijKapoor8 Date: Mon, 6 May 2024 15:13:22 -0500 Subject: [PATCH 2/6] devices: change vcpu variable size Modified vcpu related information to support more vcpu's. Signed-off-by: Kshitij Kapoor --- devices/src/gic.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/devices/src/gic.rs b/devices/src/gic.rs index c47f2b48da..997eaa4f04 100644 --- a/devices/src/gic.rs +++ b/devices/src/gic.rs @@ -40,7 +40,7 @@ pub struct Gic { impl Gic { pub fn new( - vcpu_count: u8, + vcpu_count: u32, interrupt_manager: Arc>, vm: Arc, ) -> Result { From c98f07b75340e7c558569799af67a255b98d5723 Mon Sep 17 00:00:00 2001 From: KshitijKapoor8 Date: Mon, 6 May 2024 15:17:05 -0500 Subject: [PATCH 3/6] docs: changed docs to accurately reflect vcpu size The new vcpu size is an unsigned int of 32 bits, modified the docs to reflect this Signed-off-by: Kshitij Kapoor --- docs/cpu.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/cpu.md b/docs/cpu.md index 5dd797315b..8d9f590165 100644 --- a/docs/cpu.md +++ b/docs/cpu.md @@ -11,8 +11,8 @@ to set vCPUs options for Cloud Hypervisor. ```rust struct CpusConfig { - boot_vcpus: u8, - max_vcpus: u8, + boot_vcpus: u32, + max_vcpus: u32, topology: Option, kvm_hyperv: bool, max_phys_bits: u8, @@ -54,7 +54,7 @@ For instance, if booting the VM with 2 vCPUs and a maximum of 6 vCPUs, it means up to 4 vCPUs can be added later at runtime by resizing the VM. The value must be greater than or equal to the number of boot vCPUs. -The value is an unsigned integer of 8 bits. +The value is an unsigned integer of 32 bits. By default this option takes the value of `boot`, meaning vCPU hotplug is not expected and can't be performed. @@ -148,7 +148,7 @@ The affinity is described through the following structure: ```rust struct CpuAffinity { - vcpu: u8, + vcpu: u32, host_cpus: Vec, } ``` @@ -164,7 +164,7 @@ brackets attached to `@` define the list of host CPUs the vCPU is allowed to run onto. Multiple values can be provided to define each list. Each value is an unsigned -integer of 8 bits. +integer of 32 bits. For instance, if one needs to run vCPU 0 on host CPUs from 0 to 4, the syntax using `-` will help define a contiguous range with `affinity=0@[0-4]`. The From 4f284ca53e60915f58a88046aaa5d0641af68f38 Mon Sep 17 00:00:00 2001 From: KshitijKapoor8 Date: Mon, 6 May 2024 15:22:30 -0500 Subject: [PATCH 4/6] hypervisor: change vcpu variable size Modified vcpu related information to support more vcpu's Signed-off-by: Kshitij Kapoor --- hypervisor/src/kvm/mod.rs | 2 +- hypervisor/src/mshv/mod.rs | 2 +- hypervisor/src/vm.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/hypervisor/src/kvm/mod.rs b/hypervisor/src/kvm/mod.rs index 2ff93aa140..e96cd0dd68 100644 --- a/hypervisor/src/kvm/mod.rs +++ b/hypervisor/src/kvm/mod.rs @@ -451,7 +451,7 @@ impl vm::Vm for KvmVm { /// fn create_vcpu( &self, - id: u8, + id: u32, vm_ops: Option>, ) -> vm::Result> { let fd = self diff --git a/hypervisor/src/mshv/mod.rs b/hypervisor/src/mshv/mod.rs index b1b3a9c6c1..aedc0494a1 100644 --- a/hypervisor/src/mshv/mod.rs +++ b/hypervisor/src/mshv/mod.rs @@ -1709,7 +1709,7 @@ impl vm::Vm for MshvVm { /// fn create_vcpu( &self, - id: u8, + id: u32, vm_ops: Option>, ) -> vm::Result> { let vcpu_fd = self diff --git a/hypervisor/src/vm.rs b/hypervisor/src/vm.rs index cafced0a18..25fc6123cc 100644 --- a/hypervisor/src/vm.rs +++ b/hypervisor/src/vm.rs @@ -289,7 +289,7 @@ pub trait Vm: Send + Sync + Any { /// Unregister an event that will, when signaled, trigger the `gsi` IRQ. fn unregister_irqfd(&self, fd: &EventFd, gsi: u32) -> Result<()>; /// Creates a new KVM vCPU file descriptor and maps the memory corresponding - fn create_vcpu(&self, id: u8, vm_ops: Option>) -> Result>; + fn create_vcpu(&self, id: u32, vm_ops: Option>) -> Result>; #[cfg(target_arch = "aarch64")] fn create_vgic(&self, config: VgicConfig) -> Result>>; From 2ff5cd3d2e20cd39641d79752cc0b0ba07578f75 Mon Sep 17 00:00:00 2001 From: KshitijKapoor8 Date: Mon, 6 May 2024 15:24:02 -0500 Subject: [PATCH 5/6] performance-metrics: change vcpu variable size Modified vcpu related information to support more vcpu's Signed-off-by: Kshitij Kapoor --- performance-metrics/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/performance-metrics/src/main.rs b/performance-metrics/src/main.rs index 843066cab1..7b660b90f9 100644 --- a/performance-metrics/src/main.rs +++ b/performance-metrics/src/main.rs @@ -134,7 +134,7 @@ pub struct PerformanceTestControl { queue_size: Option, net_control: Option<(bool, bool)>, // First bool is for RX(true)/TX(false), second bool is for bandwidth or PPS fio_control: Option<(FioOps, bool)>, // Second parameter controls whether we want bandwidth or IOPS - num_boot_vcpus: Option, + num_boot_vcpus: Option, } impl fmt::Display for PerformanceTestControl { From ba0787af148ccec92c05c885901a62051f8a10c8 Mon Sep 17 00:00:00 2001 From: KshitijKapoor8 Date: Mon, 6 May 2024 15:40:36 -0500 Subject: [PATCH 6/6] misc: change vcpu variable size Modified vcpu related information to support more vcpu's, mostly in the vmm package Signed-off-by: Kshitij Kapoor --- src/bin/ch-remote.rs | 2 +- tests/integration.rs | 2 +- vmm/src/api/mod.rs | 4 ++-- vmm/src/config.rs | 4 ++-- vmm/src/cpu.rs | 38 +++++++++++++++++++------------------- vmm/src/lib.rs | 2 +- vmm/src/vm.rs | 2 +- vmm/src/vm_config.rs | 6 +++--- 8 files changed, 30 insertions(+), 30 deletions(-) diff --git a/src/bin/ch-remote.rs b/src/bin/ch-remote.rs index 1d4e2a4d87..0c446389ce 100644 --- a/src/bin/ch-remote.rs +++ b/src/bin/ch-remote.rs @@ -723,7 +723,7 @@ fn resize_config( memory: Option<&str>, balloon: Option<&str>, ) -> Result { - let desired_vcpus: Option = if let Some(cpus) = cpus { + let desired_vcpus: Option = if let Some(cpus) = cpus { Some(cpus.parse().map_err(Error::InvalidCpuCount)?) } else { None diff --git a/tests/integration.rs b/tests/integration.rs index 86fe70e037..4051acb5a5 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -653,7 +653,7 @@ fn remote_command_w_output(api_socket: &str, command: &str, arg: Option<&str>) - fn resize_command( api_socket: &str, - desired_vcpus: Option, + desired_vcpus: Option, desired_ram: Option, desired_balloon: Option, event_file: Option<&str>, diff --git a/vmm/src/api/mod.rs b/vmm/src/api/mod.rs index de68e23e2a..3e7b7a1e1f 100644 --- a/vmm/src/api/mod.rs +++ b/vmm/src/api/mod.rs @@ -226,7 +226,7 @@ pub struct VmmPingResponse { #[derive(Clone, Deserialize, Serialize, Default, Debug)] pub struct VmResizeData { - pub desired_vcpus: Option, + pub desired_vcpus: Option, pub desired_ram: Option, pub desired_balloon: Option, } @@ -316,7 +316,7 @@ pub trait RequestHandler { fn vm_resize( &mut self, - desired_vcpus: Option, + desired_vcpus: Option, desired_ram: Option, desired_balloon: Option, ) -> Result<(), VmError>; diff --git a/vmm/src/config.rs b/vmm/src/config.rs index f47fabc2d0..4a5c324d88 100644 --- a/vmm/src/config.rs +++ b/vmm/src/config.rs @@ -628,11 +628,11 @@ impl CpusConfig { .add("features"); parser.parse(cpus).map_err(Error::ParseCpus)?; - let boot_vcpus: u8 = parser + let boot_vcpus: u32 = parser .convert("boot") .map_err(Error::ParseCpus)? .unwrap_or(DEFAULT_VCPUS); - let max_vcpus: u8 = parser + let max_vcpus: u32 = parser .convert("max") .map_err(Error::ParseCpus)? .unwrap_or(boot_vcpus); diff --git a/vmm/src/cpu.rs b/vmm/src/cpu.rs index a737a15f9f..ffd32a5701 100644 --- a/vmm/src/cpu.rs +++ b/vmm/src/cpu.rs @@ -322,7 +322,7 @@ macro_rules! round_up { pub struct Vcpu { // The hypervisor abstracted CPU. vcpu: Arc, - id: u8, + id: u32, #[cfg(target_arch = "aarch64")] mpidr: u64, saved_state: Option, @@ -340,7 +340,7 @@ impl Vcpu { /// * `vm_ops` - Optional object for exit handling. /// * `cpu_vendor` - CPU vendor as reported by __cpuid(0x0) pub fn new( - id: u8, + id: u32, apic_id: u8, vm: &Arc, vm_ops: Option>, @@ -779,7 +779,7 @@ impl CpuManager { Ok(()) } - fn create_vcpu(&mut self, cpu_id: u8, snapshot: Option) -> Result>> { + fn create_vcpu(&mut self, cpu_id: u32, snapshot: Option) -> Result>> { info!("Creating vCPU: cpu_id = {}", cpu_id); #[cfg(target_arch = "x86_64")] @@ -791,7 +791,7 @@ impl CpuManager { let mut vcpu = Vcpu::new( cpu_id, - x2apic_id as u8, + x2apic_id as u32, &self.vm, Some(self.vm_ops.clone()), #[cfg(target_arch = "x86_64")] @@ -872,7 +872,7 @@ impl CpuManager { /// Only create new vCPUs if there aren't any inactive ones to reuse fn create_vcpus( &mut self, - desired_vcpus: u8, + desired_vcpus: u32, snapshot: Option, ) -> Result>>> { let mut vcpus: Vec>> = vec![]; @@ -889,7 +889,7 @@ impl CpuManager { } // Only create vCPUs in excess of all the allocated vCPUs. - for cpu_id in self.vcpus.len() as u8..desired_vcpus { + for cpu_id in self.vcpus.len() as u32..desired_vcpus { vcpus.push(self.create_vcpu( cpu_id, // TODO: The special format of the CPU id can be removed once @@ -927,7 +927,7 @@ impl CpuManager { fn start_vcpu( &mut self, vcpu: Arc>, - vcpu_id: u8, + vcpu_id: u32, vcpu_thread_barrier: Arc, inserting: bool, ) -> Result<()> { @@ -1187,7 +1187,7 @@ impl CpuManager { /// Start up as many vCPUs threads as needed to reach `desired_vcpus` fn activate_vcpus( &mut self, - desired_vcpus: u8, + desired_vcpus: u32, inserting: bool, paused: Option, ) -> Result<()> { @@ -1213,7 +1213,7 @@ impl CpuManager { // This reuses any inactive vCPUs as well as any that were newly created for vcpu_id in self.present_vcpus()..desired_vcpus { - let vcpu = Arc::clone(&self.vcpus[vcpu_id as usize]); + let vcpu = Arc::clone(&self.vcpus[vcpu_id as u32]); self.start_vcpu(vcpu, vcpu_id, vcpu_thread_barrier.clone(), inserting)?; } @@ -1222,7 +1222,7 @@ impl CpuManager { Ok(()) } - fn mark_vcpus_for_removal(&mut self, desired_vcpus: u8) { + fn mark_vcpus_for_removal(&mut self, desired_vcpus: u32) { // Mark vCPUs for removal, actual removal happens on ejection for cpu_id in desired_vcpus..self.present_vcpus() { self.vcpu_states[usize::from(cpu_id)].removing = true; @@ -1241,7 +1241,7 @@ impl CpuManager { false } - fn remove_vcpu(&mut self, cpu_id: u8) -> Result<()> { + fn remove_vcpu(&mut self, cpu_id: u32) -> Result<()> { info!("Removing vCPU: cpu_id = {}", cpu_id); let state = &mut self.vcpu_states[usize::from(cpu_id)]; state.kill.store(true, Ordering::SeqCst); @@ -1271,7 +1271,7 @@ impl CpuManager { } pub fn start_restored_vcpus(&mut self) -> Result<()> { - self.activate_vcpus(self.vcpus.len() as u8, false, Some(true)) + self.activate_vcpus(self.vcpus.len() as u32, false, Some(true)) .map_err(|e| { Error::StartRestoreVcpu(anyhow!("Failed to start restored vCPUs: {:#?}", e)) })?; @@ -1279,7 +1279,7 @@ impl CpuManager { Ok(()) } - pub fn resize(&mut self, desired_vcpus: u8) -> Result { + pub fn resize(&mut self, desired_vcpus: u32) -> Result { if desired_vcpus.cmp(&self.present_vcpus()) == cmp::Ordering::Equal { return Ok(false); } @@ -1348,11 +1348,11 @@ impl CpuManager { Ok(()) } - pub fn boot_vcpus(&self) -> u8 { + pub fn boot_vcpus(&self) -> u32 { self.config.boot_vcpus } - pub fn max_vcpus(&self) -> u8 { + pub fn max_vcpus(&self) -> u32 { self.config.max_vcpus } @@ -1362,10 +1362,10 @@ impl CpuManager { self.cpuid.clone() } - fn present_vcpus(&self) -> u8 { + fn present_vcpus(&self) -> u32 { self.vcpu_states .iter() - .fold(0, |acc, state| acc + state.active() as u8) + .fold(0, |acc, state| acc + state.active() as u32) } #[cfg(target_arch = "aarch64")] @@ -1384,7 +1384,7 @@ impl CpuManager { .collect() } - pub fn get_vcpu_topology(&self) -> Option<(u8, u8, u8)> { + pub fn get_vcpu_topology(&self) -> Option<(u32, u32, u32)> { self.config .topology .clone() @@ -2011,7 +2011,7 @@ impl Aml for CpuNotify { } struct CpuMethods { - max_vcpus: u8, + max_vcpus: u32, dynamic: bool, } diff --git a/vmm/src/lib.rs b/vmm/src/lib.rs index c75cce4acc..19834519b1 100644 --- a/vmm/src/lib.rs +++ b/vmm/src/lib.rs @@ -1536,7 +1536,7 @@ impl RequestHandler for Vmm { fn vm_resize( &mut self, - desired_vcpus: Option, + desired_vcpus: Option, desired_ram: Option, desired_balloon: Option, ) -> result::Result<(), VmError> { diff --git a/vmm/src/vm.rs b/vmm/src/vm.rs index 559d513885..34db5be7b4 100644 --- a/vmm/src/vm.rs +++ b/vmm/src/vm.rs @@ -1402,7 +1402,7 @@ impl Vm { pub fn resize( &mut self, - desired_vcpus: Option, + desired_vcpus: Option, desired_memory: Option, desired_balloon: Option, ) -> Result<()> { diff --git a/vmm/src/vm_config.rs b/vmm/src/vm_config.rs index 1f323df06f..d5bc4f91ed 100644 --- a/vmm/src/vm_config.rs +++ b/vmm/src/vm_config.rs @@ -9,7 +9,7 @@ use virtio_devices::RateLimiterConfig; #[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)] pub struct CpuAffinity { - pub vcpu: u8, + pub vcpu: u32, pub host_cpus: Vec, } @@ -39,8 +39,8 @@ pub fn default_cpuconfig_max_phys_bits() -> u8 { #[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)] pub struct CpusConfig { - pub boot_vcpus: u8, - pub max_vcpus: u8, + pub boot_vcpus: u32, + pub max_vcpus: u32, #[serde(default)] pub topology: Option, #[serde(default)]