virt_kvm: strip PSFD CPUID when KVM won't allow SPEC_CTRL MSR#3534
Merged
Conversation
…MSR access KVM has a bug where it advertises AMD PSFD (Predictive Store Forwarding Disable) in guest CPUID via leaf 0x80000008.EBX bit 28, but its `guest_has_spec_ctrl_msr()` function does not include PSFD when deciding whether to allow guest access to MSR 0x48 (IA32_SPEC_CTRL). PSFD is architecturally controlled via bit 7 of that MSR, so advertising PSFD implies the MSR should be accessible. This causes a problem for nested Hyper-V guests. The Hyper-V hypervisor includes PSFD (which it calls MDD) in its `HV_PARTITION_PROCESSOR_FEATURES0_MASK_SPEC_CTRL` mask, so seeing PSFD alone is enough to set `ValFeatureSet.SpecCtrlMsr = true`. On initialization, it writes zero to MSR 0x48 to clear speculation controls. KVM rejects this write because none of the four CPUID bits it checks (CPUID 7.0.EDX IBRS, 0x80000008.EBX IBRS/STIBP/SSBD) are set, and injects a #GP that crashes the nested hypervisor. This is only visible on AMD hosts where Hyper-V strips IBRS/STIBP/SSBD from the guest CPUID but leaves PSFD, which is the case when running KVM inside a Hyper-V VM with nested virtualization. The fix detects this inconsistency during partition construction: if PSFD is set in the guest CPUID but none of the bits that KVM uses to gate MSR 0x48 access are present, strip PSFD. This also removes the earlier `no_spec_ctrl` manual workaround flag since the fixup is now automatic.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds a targeted CPUID fixup in virt_kvm to avoid advertising AMD PSFD to guests in cases where KVM will still block guest access to IA32_SPEC_CTRL (MSR 0x48), which can crash nested Hyper-V guests during initialization.
Changes:
- Apply a partition-build-time CPUID fixup that conditionally strips
0x8000_0008.EBX[28](PSFD) when KVM’sSPEC_CTRLMSR gating CPUID bits are not present. - Document the KVM inconsistency and why it impacts nested Hyper-V.
Comment on lines
+495
to
+496
| /// MSR 0x48 by checking CPUID 7.0.EDX bit 26 (SPEC_CTRL), and | ||
| /// 0x80000008.EBX bits 14 (AMD_IBRS), 15 (AMD_STIBP), and 24 (AMD_SSBD). |
smalis-msft
approved these changes
May 20, 2026
smalis-msft
approved these changes
May 20, 2026
chris-oo
approved these changes
May 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
KVM has a bug where it advertises AMD PSFD (Predictive Store Forwarding Disable) in guest CPUID via leaf 0x80000008.EBX bit 28, but its
guest_has_spec_ctrl_msr()function does not include PSFD when deciding whether to allow guest access to MSR 0x48 (IA32_SPEC_CTRL). PSFD is architecturally controlled via bit 7 of that MSR, so advertising PSFD implies the MSR should be accessible.This causes a problem for nested Hyper-V guests. The Hyper-V hypervisor includes PSFD (which it calls MDD) in its
HV_PARTITION_PROCESSOR_FEATURES0_MASK_SPEC_CTRLmask, so seeing PSFD alone is enough to setValFeatureSet.SpecCtrlMsr = true. On initialization, it writes zero to MSR 0x48 to clear speculation controls. KVM rejects this write because none of the four CPUID bits it checks (CPUID 7.0.EDX IBRS, 0x80000008.EBX IBRS/STIBP/SSBD) are set, and so it injects a #GP that crashes the nested hypervisor.This is only visible on AMD hosts where Hyper-V strips IBRS/STIBP/SSBD from the guest CPUID but leaves PSFD, which is the case when running KVM inside a Hyper-V VM with nested virtualization.
The fix detects this inconsistency during partition construction: if PSFD is set in the guest CPUID but none of the bits that KVM uses to gate MSR 0x48 access are present, strip PSFD.