Thanks to visit codestin.com
Credit goes to github.com

Skip to content

mshv: Fix CPU topology detection - #7576

Merged
likebreath merged 2 commits into
cloud-hypervisor:mainfrom
weltling:mshv-cpu-topology-fixes
Jan 5, 2026
Merged

likebreath merged 2 commits into
cloud-hypervisor:mainfrom
weltling:mshv-cpu-topology-fixes

Conversation

@weltling

@weltling weltling commented Dec 22, 2025

Copy link
Copy Markdown
Member

This PR enables proper CPU topology detection on MSHV with multithreaded configurations. The PROCESSORS_PER_SOCKET partition property has to be set after vCPU configuration for correct threads-per-core reporting in CPUID.0xB EBX.

Fixes: #7433

@weltling
weltling force-pushed the mshv-cpu-topology-fixes branch 2 times, most recently from de3313b to 314f6de Compare December 22, 2025 22:51
@weltling
weltling marked this pull request as ready for review December 23, 2025 09:50
@weltling
weltling requested a review from a team as a code owner December 23, 2025 09:50
Comment thread vmm/src/cpu.rs Outdated
Comment on lines +1383 to +1391
const HV_PARTITION_PROPERTY_PROCESSORS_PER_SOCKET: u32 = 0x00050003;

let threads_per_core = if let Some(ref topology) = self.config.topology {
topology.threads_per_core as u64
} else {
1u64
};

if let Some(mshv_vm) = self.vm.as_any().downcast_ref::<hypervisor::mshv::MshvVm>() {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this should be included to the downcast if statement too - particularly we are releasing binaries that have both mshv and kvm feature flags enabled.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't we add an API to hypervisor/vm.rs and make nothing for kvm and mshv implements.

@weltling weltling Dec 31, 2025

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved all the related stuff into the downcast if block now.

With the Vm trait suggestion - while it would eliminate the downcast, this is MSHV specific. The current approach keeps it out of the public API. Both work technically, of course.

Thanks

Comment thread cloud-hypervisor/tests/integration.rs
Comment thread vmm/src/cpu.rs Outdated
Comment thread vmm/src/cpu.rs Outdated
Comment on lines +1383 to +1391
const HV_PARTITION_PROPERTY_PROCESSORS_PER_SOCKET: u32 = 0x00050003;

let threads_per_core = if let Some(ref topology) = self.config.topology {
topology.threads_per_core as u64
} else {
1u64
};

if let Some(mshv_vm) = self.vm.as_any().downcast_ref::<hypervisor::mshv::MshvVm>() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't we add an API to hypervisor/vm.rs and make nothing for kvm and mshv implements.

@weltling
weltling force-pushed the mshv-cpu-topology-fixes branch 5 times, most recently from 5bdef61 to 326e57e Compare December 31, 2025 16:07
@weltling
weltling force-pushed the mshv-cpu-topology-fixes branch from 326e57e to 092ef38 Compare December 31, 2025 16:09
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 <[email protected]>
@weltling
weltling force-pushed the mshv-cpu-topology-fixes branch from 092ef38 to d0385ec Compare December 31, 2025 16:17
@weltling

Copy link
Copy Markdown
Member Author

Regarding to possible moving some of this to the mshv crate - IMO it's not necessary. The mshv crates provide the primitives, but this specific workaround for CPU topology is cloud-hypervisor specific. The logic how to apply it belongs here in the VMM.

Thanks

Comment thread vmm/src/vm.rs
@russell-islam

Copy link
Copy Markdown
Contributor

LGTM

@likebreath
likebreath added this pull request to the merge queue Jan 5, 2026
Merged via the queue into cloud-hypervisor:main with commit 3657db7 Jan 5, 2026
42 of 43 checks passed
@weltling
weltling deleted the mshv-cpu-topology-fixes branch January 6, 2026 11:34
@github-project-automation github-project-automation Bot moved this from 🆕 New to ✅ Done in Cloud Hypervisor Roadmap Feb 19, 2026
@likebreath likebreath added the mshv Affects mshv only label Feb 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mshv Affects mshv only

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

test_cpu_topology_* failing for MSHV in CI

3 participants