Skip to content

Commit e94caf0

Browse files
author
Maxim Levitsky
committed
KVM: SVM: Disable interception of SPEC_CTRL iff the MSR exists for the guest
JIRA: https://issues.redhat.com/browse/RHEL-47242 commit 674ffc6 Author: Sean Christopherson <seanjc@google.com> Date: Tue Jun 10 15:57:06 2025 -0700 KVM: SVM: Disable interception of SPEC_CTRL iff the MSR exists for the guest Disable interception of SPEC_CTRL when the CPU virtualizes (i.e. context switches) SPEC_CTRL if and only if the MSR exists according to the vCPU's CPUID model. Letting the guest access SPEC_CTRL is generally benign, but the guest would see inconsistent behavior if KVM happened to emulate an access to the MSR. Fixes: d00b99c ("KVM: SVM: Add support for Virtual SPEC_CTRL") Reported-by: Chao Gao <chao.gao@intel.com> Link: https://lore.kernel.org/r/20250610225737.156318-2-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com> Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com>
1 parent fef417b commit e94caf0

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

arch/x86/kvm/svm/svm.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1357,11 +1357,14 @@ static void init_vmcb(struct kvm_vcpu *vcpu)
13571357
svm_recalc_instruction_intercepts(vcpu, svm);
13581358

13591359
/*
1360-
* If the host supports V_SPEC_CTRL then disable the interception
1361-
* of MSR_IA32_SPEC_CTRL.
1360+
* If the CPU virtualizes MSR_IA32_SPEC_CTRL, i.e. KVM doesn't need to
1361+
* manually context switch the MSR, immediately configure interception
1362+
* of SPEC_CTRL, without waiting for the guest to access the MSR.
13621363
*/
13631364
if (boot_cpu_has(X86_FEATURE_V_SPEC_CTRL))
1364-
set_msr_interception(vcpu, svm->msrpm, MSR_IA32_SPEC_CTRL, 1, 1);
1365+
set_msr_interception(vcpu, svm->msrpm, MSR_IA32_SPEC_CTRL,
1366+
guest_has_spec_ctrl_msr(vcpu),
1367+
guest_has_spec_ctrl_msr(vcpu));
13651368

13661369
if (kvm_vcpu_apicv_active(vcpu))
13671370
avic_init_vmcb(svm, vmcb);

0 commit comments

Comments
 (0)