mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
vmm: mshv: Set PROCESSORS_PER_SOCKET property for CPU topologies
On MSHV, exposing multithreaded CPU topologies requires setting the PROCESSORS_PER_SOCKET partition property so that CPUID.0xB reports correct logical processor counts and topology levels to the guest. This property must be set after all vCPUs are configured, as the hypervisor uses the complete vCPU layout to derive and report CPU topology information. Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
This commit is contained in:
@@ -216,6 +216,10 @@ pub enum Error {
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
#[error("Failed to inject NMI")]
|
||||
NmiError(#[source] hypervisor::HypervisorCpuError),
|
||||
|
||||
#[cfg(feature = "mshv")]
|
||||
#[error("Failed to set partition property")]
|
||||
SetPartitionProperty(#[source] anyhow::Error),
|
||||
}
|
||||
pub type Result<T> = result::Result<T, Error>;
|
||||
|
||||
@@ -1374,6 +1378,25 @@ impl CpuManager {
|
||||
self.activate_vcpus(self.boot_vcpus(), false, Some(paused))
|
||||
}
|
||||
|
||||
#[cfg(feature = "mshv")]
|
||||
pub fn set_processors_per_socket_property(&self) -> Result<()> {
|
||||
if let Some(mshv_vm) = self.vm.as_any().downcast_ref::<hypervisor::mshv::MshvVm>() {
|
||||
let threads_per_core = if let Some(ref topology) = self.config.topology {
|
||||
topology.threads_per_core as u64
|
||||
} else {
|
||||
1u64
|
||||
};
|
||||
|
||||
mshv_vm
|
||||
.set_partition_property(
|
||||
hypervisor::mshv::HV_PARTITION_PROPERTY_PROCESSORS_PER_SOCKET,
|
||||
threads_per_core,
|
||||
)
|
||||
.map_err(Error::SetPartitionProperty)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn start_restored_vcpus(&mut self) -> Result<()> {
|
||||
self.activate_vcpus(self.vcpus.len() as u32, false, Some(true))
|
||||
.map_err(|e| {
|
||||
|
||||
@@ -2415,6 +2415,15 @@ impl Vm {
|
||||
.map_err(Error::CpuManager)?;
|
||||
}
|
||||
|
||||
#[cfg(feature = "mshv")]
|
||||
{
|
||||
self.cpu_manager
|
||||
.lock()
|
||||
.unwrap()
|
||||
.set_processors_per_socket_property()
|
||||
.ok();
|
||||
}
|
||||
|
||||
#[cfg(feature = "tdx")]
|
||||
let (sections, guid_found) = if tdx_enabled {
|
||||
self.extract_tdvf_sections()?
|
||||
|
||||
Reference in New Issue
Block a user