Skip to content

Commit 26a0cd2

Browse files
KarimAllah Ahmedjfvogel
authored andcommitted
KVM/VMX: Allow direct access to MSR_IA32_SPEC_CTRL
[ Based on a patch from Ashok Raj <[email protected]> ] Add direct access to MSR_IA32_SPEC_CTRL for guests. This is needed for guests that will only mitigate Spectre V2 through IBRS+IBPB and will not be using a retpoline+IBPB based approach. To avoid the overhead of saving and restoring the MSR_IA32_SPEC_CTRL for guests that do not actually use the MSR, only start saving and restoring when a non-zero is written to it. No attempt is made to handle STIBP here, intentionally. Filtering STIBP may be added in a future patch, which may require trapping all writes if we don't want to pass it through directly to the guest. [dwmw2: Clean up CPUID bits, save/restore manually, handle reset] Signed-off-by: KarimAllah Ahmed <[email protected]> Signed-off-by: David Woodhouse <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Reviewed-by: Darren Kenny <[email protected]> Reviewed-by: Konrad Rzeszutek Wilk <[email protected]> Reviewed-by: Jim Mattson <[email protected]> Cc: Andrea Arcangeli <[email protected]> Cc: Andi Kleen <[email protected]> Cc: Jun Nakajima <[email protected]> Cc: [email protected] Cc: Dave Hansen <[email protected]> Cc: Tim Chen <[email protected]> Cc: Andy Lutomirski <[email protected]> Cc: Asit Mallick <[email protected]> Cc: Arjan Van De Ven <[email protected]> Cc: Greg KH <[email protected]> Cc: Paolo Bonzini <[email protected]> Cc: Dan Williams <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Ashok Raj <[email protected]> Link: https://lkml.kernel.org/r/[email protected] (cherry picked from commit d28b387) Orabug: 27525575 Signed-off-by: Konrad Rzeszutek Wilk <[email protected]> [Backport: There is a lot that this patch does not pick up - but the most important we need to pick up is the wrmsr(0x48, 0) when the retpoline is used. That is we cannot leave the MSR048 hanging around with the guest value. The reason is that on a particular CPU we may schedule another guest vCPU (a different) one, and the check on whether to write the MSR0x48 is if 'vmx->spec_ctrl' (the vmx is tied to a specific VCPU). Which means we may not write the prpoer guest vCPU MSR value in and have the stale one in the guest.!]
1 parent 4583a6b commit 26a0cd2

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

arch/x86/kvm/svm.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4032,6 +4032,8 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
40324032
rdmsrl(MSR_IA32_SPEC_CTRL, svm->spec_ctrl);
40334033
if (ibrs_inuse)
40344034
wrmsrl(MSR_IA32_SPEC_CTRL, SPEC_CTRL_FEATURE_ENABLE_IBRS);
4035+
else if (svm->spec_ctrl)
4036+
wrmsrl(MSR_IA32_SPEC_CTRL, SPEC_CTRL_FEATURE_DISABLE_IBRS);
40354037
}
40364038

40374039
/* Eliminate branch target predictions from guest mode */

arch/x86/kvm/vmx.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8327,6 +8327,8 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
83278327
rdmsrl(MSR_IA32_SPEC_CTRL, vmx->spec_ctrl);
83288328
if (ibrs_inuse)
83298329
wrmsrl(MSR_IA32_SPEC_CTRL, SPEC_CTRL_FEATURE_ENABLE_IBRS);
8330+
else if (vmx->spec_ctrl)
8331+
wrmsrl(MSR_IA32_SPEC_CTRL, SPEC_CTRL_FEATURE_DISABLE_IBRS);
83308332
}
83318333

83328334
/* MSR_IA32_DEBUGCTLMSR is zeroed on vmexit. Restore it if needed */

0 commit comments

Comments
 (0)