mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
vmm: raise the (v)CPU limit on kvm/x86_64
Raise the max number of supported (v)CPUs on kvm x86_64 hosts to 8192 (the max allowed value of CONFIG_NR_CPUS in the Linux kernel). Other platfroms keep their existing CPU limits pending further development and testing. The change has been tested on Intel and AMD hosts. 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:
+25
-5
@@ -27,6 +27,11 @@ use crate::vm_config::*;
|
||||
const MAX_NUM_PCI_SEGMENTS: u16 = 96;
|
||||
const MAX_IOMMU_ADDRESS_WIDTH_BITS: u8 = 64;
|
||||
|
||||
#[cfg(all(feature = "kvm", target_arch = "x86_64"))]
|
||||
const MAX_SUPPORTED_CPUS: u32 = 8192;
|
||||
#[cfg(not(all(feature = "kvm", target_arch = "x86_64")))]
|
||||
const MAX_SUPPORTED_CPUS: u32 = 255;
|
||||
|
||||
/// Errors associated with VM configuration parameters.
|
||||
#[derive(Debug, Error)]
|
||||
pub enum Error {
|
||||
@@ -182,6 +187,9 @@ pub enum ValidationError {
|
||||
/// Max is less than boot
|
||||
#[error("Max CPUs lower than boot CPUs")]
|
||||
CpusMaxLowerThanBoot,
|
||||
/// Too many CPUs.
|
||||
#[error("Too many CPUs: specified {0} but {MAX_SUPPORTED_CPUS} is the limit")]
|
||||
TooManyCpus(u32 /* specified CPUs */),
|
||||
/// Missing file value for debug-console
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
#[error("Path missing when using file mode for debug console")]
|
||||
@@ -586,11 +594,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);
|
||||
@@ -605,7 +613,7 @@ impl CpusConfig {
|
||||
.map_err(Error::ParseCpus)?
|
||||
.unwrap_or(DEFAULT_MAX_PHYS_BITS);
|
||||
let affinity = parser
|
||||
.convert::<Tuple<u8, Vec<usize>>>("affinity")
|
||||
.convert::<Tuple<u32, Vec<usize>>>("affinity")
|
||||
.map_err(Error::ParseCpus)?
|
||||
.map(|v| {
|
||||
v.0.iter()
|
||||
@@ -2147,7 +2155,7 @@ impl NumaConfig {
|
||||
let cpus = parser
|
||||
.convert::<IntegerList>("cpus")
|
||||
.map_err(Error::ParseNuma)?
|
||||
.map(|v| v.0.iter().map(|e| *e as u8).collect());
|
||||
.map(|v| v.0.iter().map(|e| *e as u32).collect());
|
||||
let distances = parser
|
||||
.convert::<Tuple<u64, u64>>("distances")
|
||||
.map_err(Error::ParseNuma)?
|
||||
@@ -2523,6 +2531,15 @@ impl VmConfig {
|
||||
return Err(ValidationError::CpusMaxLowerThanBoot);
|
||||
}
|
||||
|
||||
if self.cpus.max_vcpus > MAX_SUPPORTED_CPUS {
|
||||
// Note: historically, Cloud Hypervisor did not support more than 255(254 on x64)
|
||||
// vCPUs: self.cpus.max_vcpus was of type u8, so 255 was the maximum;
|
||||
// on x86_64, the legacy mptable/apic was limited to 254 CPUs.
|
||||
//
|
||||
// Now the limit is lifted on x86_64 targets. Other targests/archs: TBD.
|
||||
return Err(ValidationError::TooManyCpus(self.cpus.max_vcpus));
|
||||
}
|
||||
|
||||
if let Some(rate_limit_groups) = &self.rate_limit_groups {
|
||||
for rate_limit_group in rate_limit_groups {
|
||||
rate_limit_group.validate(self)?;
|
||||
@@ -2614,7 +2631,10 @@ impl VmConfig {
|
||||
return Err(ValidationError::CpuTopologyDiesPerPackage);
|
||||
}
|
||||
|
||||
let total = t.threads_per_core * t.cores_per_die * t.dies_per_package * t.packages;
|
||||
let total: u32 = (t.threads_per_core as u32)
|
||||
* (t.cores_per_die as u32)
|
||||
* (t.dies_per_package as u32)
|
||||
* (t.packages as u32);
|
||||
if total != self.cpus.max_vcpus {
|
||||
return Err(ValidationError::CpuTopologyCount);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user