KVM/SVM/VMX/x86/spectre_v2: Support the combination of guest IBRS and ours.
PATCH 4/7 KVM/SVM/VMX/x86/spectre_v2: Support the combination of guest IBRS and ours.
A guest may modify the SPEC_CTRL MSR from the value used by the kernel. Since we don't use IBRS, this means a value of zero is what we need in the host.
But the 336996-Speculative-Execution-Side-Channel-Mitigations.pdf refers to the other bits as reserved so we should respect the boot time SPEC_CTRL value and use that.
This allows us to deal with future extensions to the SPEC_CTRL interface if any at all.
---
v2: New patch
v2.1: Replaced with simple save/restore functions
--- arch/x86/kvm/svm.c | 6 ++---- arch/x86/kvm/vmx.c | 6 ++---- 2 files changed, 4 insertions(+), 8 deletions(-)
arch/x86/kvm/svm.c +2 -4
@@ -5557,8 +5557,7 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)* is no need to worry about the conditional branch over the wrmsr * being speculatively taken. */ -if (svm->spec_ctrl) -native_wrmsrl (MSR_IA32_SPEC_CTRL , svm->spec_ctrl); +x86_set_guest_spec_ctrl (svm->spec_ctrl); asmvolatile ( "push %%" _ASM_BP "; \n\t"
@@ -5670,8 +5669,7 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)if (unlikely (!msr_write_intercepted (vcpu,MSR_IA32_SPEC_CTRL ))) svm->spec_ctrl =native_read_msr (MSR_IA32_SPEC_CTRL ); -if (svm->spec_ctrl) -native_wrmsrl (MSR_IA32_SPEC_CTRL ,0 ); +x86_restore_kernel_spec_ctrl (svm->spec_ctrl);/* Eliminate branch target predictions from guest mode */ vmexit_fill_RSB ();
arch/x86/kvm/vmx.c +2 -4
@@ -9726,8 +9726,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)* is no need to worry about the conditional branch over the wrmsr * being speculatively taken. */ -if (vmx->spec_ctrl) -native_wrmsrl (MSR_IA32_SPEC_CTRL , vmx->spec_ctrl); +x86_set_guest_spec_ctrl (vmx->spec_ctrl); vmx->__launched = vmx->loaded_vmcs->launched;
@@ -9875,8 +9874,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)if (unlikely (!msr_write_intercepted (vcpu,MSR_IA32_SPEC_CTRL ))) vmx->spec_ctrl =native_read_msr (MSR_IA32_SPEC_CTRL ); -if (vmx->spec_ctrl) -native_wrmsrl (MSR_IA32_SPEC_CTRL ,0 ); +x86_restore_kernel_spec_ctrl (vmx->spec_ctrl);/* Eliminate branch target predictions from guest mode */ vmexit_fill_RSB ();
Signature · 1 line
1.8.3.1