misc: Make CPU profile part of various configs

We integrate the CPU profile into the various configs that
ultimately get set by the user.

This quickly ends up involving multiple files, luckily Rust
helps us find which ones via compilation errors.

Signed-off-by: Oliver Anderson <oliver.anderson@cyberus-technology.de>
On-behalf-of: SAP oliver.anderson@sap.com
This commit is contained in:
Oliver Anderson
2025-10-07 05:34:22 +02:00
committed by Rob Bradford
parent a9440d2919
commit 549f3d6c04
8 changed files with 53 additions and 12 deletions

View File

@@ -11,6 +11,7 @@ use std::result;
use std::str::FromStr;
use std::sync::LazyLock;
use arch::CpuProfile;
use block::ImageType;
use clap::ArgMatches;
use log::{debug, warn};
@@ -697,7 +698,8 @@ impl CpusConfig {
.add("affinity")
.add("features")
.add("nested")
.add("core_scheduling");
.add("core_scheduling")
.add("profile");
parser.parse(cpus).map_err(Error::ParseCpus)?;
let boot_vcpus: u32 = parser
@@ -729,6 +731,12 @@ impl CpusConfig {
})
.collect()
});
let profile = parser
.convert::<CpuProfile>("profile")
.map_err(Error::ParseCpus)?
.unwrap_or_default();
let features_list = parser
.convert::<StringList>("features")
.map_err(Error::ParseCpus)?
@@ -771,6 +779,7 @@ impl CpusConfig {
features,
nested,
core_scheduling,
profile,
})
}
}

View File

@@ -963,6 +963,7 @@ impl CpuManager {
#[cfg(feature = "tdx")]
tdx,
amx: self.config.features.amx,
profile: self.config.profile,
},
)
.map_err(Error::CommonCpuId)?

View File

@@ -1428,17 +1428,27 @@ impl Vmm {
)));
}
let amx = vm_config.lock().unwrap().cpus.features.amx;
let phys_bits =
vm::physical_bits(hypervisor, vm_config.lock().unwrap().cpus.max_phys_bits);
let (amx, max_phys_bits, profile, kvm_hyperv) = {
let guard = vm_config.lock().unwrap();
(
guard.cpus.features.amx,
guard.cpus.max_phys_bits,
guard.cpus.profile,
guard.cpus.kvm_hyperv,
)
};
let phys_bits = vm::physical_bits(hypervisor, max_phys_bits);
arch::generate_common_cpuid(
hypervisor,
&arch::CpuidConfig {
phys_bits,
kvm_hyperv: vm_config.lock().unwrap().cpus.kvm_hyperv,
kvm_hyperv,
#[cfg(feature = "tdx")]
tdx: false,
amx,
profile,
},
)
.map_err(|e| {
@@ -1584,6 +1594,7 @@ impl Vmm {
#[cfg(feature = "tdx")]
tdx: false,
amx: vm_config.cpus.features.amx,
profile: vm_config.cpus.profile,
},
)
.map_err(|e| {
@@ -2653,6 +2664,8 @@ const DEVICE_MANAGER_SNAPSHOT_ID: &str = "device-manager";
mod unit_tests {
use std::path::PathBuf;
use arch::CpuProfile;
use super::*;
#[cfg(target_arch = "x86_64")]
use crate::vm_config::DebugConsoleConfig;
@@ -2690,6 +2703,7 @@ mod unit_tests {
features: CpuFeatures::default(),
nested: true,
core_scheduling: CoreScheduling::default(),
profile: CpuProfile::default(),
},
memory: MemoryConfig {
size: 536_870_912,

View File

@@ -3359,19 +3359,28 @@ impl Snapshottable for Vm {
#[cfg(all(feature = "kvm", target_arch = "x86_64"))]
let common_cpuid = {
let amx = self.config.lock().unwrap().cpus.features.amx;
let phys_bits = physical_bits(
self.hypervisor.as_ref(),
self.config.lock().unwrap().cpus.max_phys_bits,
);
let (amx, max_phys_bits, kvm_hyperv, profile) = {
let guard = self.config.lock().unwrap();
let VmConfig { cpus, .. } = &*guard;
(
cpus.features.amx,
cpus.max_phys_bits,
cpus.kvm_hyperv,
cpus.profile,
)
};
let phys_bits = physical_bits(self.hypervisor.as_ref(), max_phys_bits);
arch::generate_common_cpuid(
self.hypervisor.as_ref(),
&arch::CpuidConfig {
phys_bits,
kvm_hyperv: self.config.lock().unwrap().cpus.kvm_hyperv,
kvm_hyperv,
#[cfg(feature = "tdx")]
tdx: false,
amx,
profile,
},
)
.map_err(|e| {

View File

@@ -9,6 +9,7 @@ use std::path::{Path, PathBuf};
use std::str::FromStr;
use std::{fs, result};
use arch::CpuProfile;
use block::ImageType;
pub use block::fcntl::LockGranularityChoice;
use log::{debug, warn};
@@ -84,6 +85,9 @@ pub struct CpusConfig {
pub nested: bool,
#[serde(default)]
pub core_scheduling: CoreScheduling,
// Defaults to "Host" if no profile is given.
#[serde(default)]
pub profile: CpuProfile,
}
pub const DEFAULT_VCPUS: u32 = 1;
@@ -100,6 +104,7 @@ impl Default for CpusConfig {
features: CpuFeatures::default(),
nested: true,
core_scheduling: CoreScheduling::default(),
profile: CpuProfile::default(),
}
}
}