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

@ -471,7 +471,7 @@ pub trait Vcpu: Send + Sync {
&self,
vm: &Arc<dyn crate::Vm>,
kvi: &mut VcpuInit,
id: u8,
id: u32,
) -> Result<()>;
///
/// Returns VcpuInit with default value set
@ -498,7 +498,7 @@ pub trait Vcpu: Send + Sync {
/// Configure core registers for a given CPU.
///
#[cfg(any(target_arch = "aarch64", target_arch = "riscv64"))]
fn setup_regs(&self, cpu_id: u8, boot_ip: u64, fdt_start: u64) -> Result<()>;
fn setup_regs(&self, cpu_id: u32, boot_ip: u64, fdt_start: u64) -> Result<()>;
///
/// Check if the CPU supports PMU
///

View file

@ -559,7 +559,7 @@ impl vm::Vm for KvmVm {
///
fn create_vcpu(
&self,
id: u8,
id: u32,
vm_ops: Option<Arc<dyn VmOps>>,
) -> vm::Result<Arc<dyn cpu::Vcpu>> {
let fd = self
@ -2150,7 +2150,7 @@ impl cpu::Vcpu for KvmVcpu {
&self,
vm: &Arc<dyn crate::Vm>,
kvi: &mut crate::VcpuInit,
id: u8,
id: u32,
) -> cpu::Result<()> {
use std::arch::is_aarch64_feature_detected;
#[allow(clippy::nonminimal_bool)]
@ -2280,7 +2280,7 @@ impl cpu::Vcpu for KvmVcpu {
/// Configure core registers for a given CPU.
///
#[cfg(target_arch = "aarch64")]
fn setup_regs(&self, cpu_id: u8, boot_ip: u64, fdt_start: u64) -> cpu::Result<()> {
fn setup_regs(&self, cpu_id: u32, boot_ip: u64, fdt_start: u64) -> cpu::Result<()> {
// Get the register index of the PSTATE (Processor State) register.
let pstate = offset_of!(kvm_regs, regs.pstate);
self.fd
@ -2326,7 +2326,7 @@ impl cpu::Vcpu for KvmVcpu {
///
/// Configure registers for a given RISC-V CPU.
///
fn setup_regs(&self, cpu_id: u8, boot_ip: u64, fdt_start: u64) -> cpu::Result<()> {
fn setup_regs(&self, cpu_id: u32, boot_ip: u64, fdt_start: u64) -> cpu::Result<()> {
// Setting the A0 () to the hartid of this CPU.
let a0 = offset_of!(kvm_riscv_core, regs.a0);
self.fd

View file

@ -1262,7 +1262,7 @@ impl cpu::Vcpu for MshvVcpu {
}
#[cfg(target_arch = "aarch64")]
fn setup_regs(&self, cpu_id: u8, boot_ip: u64, fdt_start: u64) -> cpu::Result<()> {
fn setup_regs(&self, cpu_id: u32, boot_ip: u64, fdt_start: u64) -> cpu::Result<()> {
let arr_reg_name_value = [(
hv_register_name_HV_ARM64_REGISTER_PSTATE,
regs::PSTATE_FAULT_BITS_64,
@ -1324,7 +1324,7 @@ impl cpu::Vcpu for MshvVcpu {
&self,
_vm: &Arc<dyn crate::Vm>,
_kvi: &mut crate::VcpuInit,
_id: u8,
_id: u32,
) -> cpu::Result<()> {
Ok(())
}
@ -1834,9 +1834,10 @@ impl vm::Vm for MshvVm {
///
fn create_vcpu(
&self,
id: u8,
id: u32,
vm_ops: Option<Arc<dyn VmOps>>,
) -> vm::Result<Arc<dyn cpu::Vcpu>> {
let id: u8 = id.try_into().unwrap();
let vcpu_fd = self
.fd
.create_vcpu(id)

View file

@ -319,7 +319,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<Arc<dyn VmOps>>) -> Result<Arc<dyn Vcpu>>;
fn create_vcpu(&self, id: u32, vm_ops: Option<Arc<dyn VmOps>>) -> Result<Arc<dyn Vcpu>>;
#[cfg(target_arch = "aarch64")]
fn create_vgic(&self, config: VgicConfig) -> Result<Arc<Mutex<dyn Vgic>>>;
#[cfg(target_arch = "riscv64")]