Skip to content

virt_kvm: strip PSFD CPUID when KVM won't allow SPEC_CTRL MSR#3534

Merged
jstarks merged 2 commits into
microsoft:mainfrom
jstarks:kvm_spec
May 20, 2026
Merged

virt_kvm: strip PSFD CPUID when KVM won't allow SPEC_CTRL MSR#3534
jstarks merged 2 commits into
microsoft:mainfrom
jstarks:kvm_spec

Conversation

@jstarks
Copy link
Copy Markdown
Member

@jstarks jstarks commented May 20, 2026

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 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.

…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.
Copilot AI review requested due to automatic review settings May 20, 2026 18:46
@jstarks jstarks requested a review from a team as a code owner May 20, 2026 18:46
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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’s SPEC_CTRL MSR 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).
@jstarks jstarks enabled auto-merge (squash) May 20, 2026 20:16
@jstarks jstarks merged commit 7124977 into microsoft:main May 20, 2026
67 checks passed
@jstarks jstarks deleted the kvm_spec branch May 20, 2026 21:37
@github-actions
Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants