[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <aEE4BEHAHdhNTGoG@intel.com>
Date: Thu, 5 Jun 2025 14:24:04 +0800
From: Chao Gao <chao.gao@...el.com>
To: Sean Christopherson <seanjc@...gle.com>
CC: Paolo Bonzini <pbonzini@...hat.com>, <kvm@...r.kernel.org>,
<linux-kernel@...r.kernel.org>, Borislav Petkov <bp@...en8.de>, Xin Li
<xin@...or.com>, Dapeng Mi <dapeng1.mi@...ux.intel.com>
Subject: Re: [PATCH 17/28] KVM: SVM: Manually recalc all MSR intercepts on
userspace MSR filter change
>+static void svm_recalc_msr_intercepts(struct kvm_vcpu *vcpu)
>+{
>+ struct vcpu_svm *svm = to_svm(vcpu);
>+
>+ svm_vcpu_init_msrpm(vcpu);
>+
>+ if (lbrv)
>+ svm_recalc_lbr_msr_intercepts(vcpu);
>+
>+ if (boot_cpu_has(X86_FEATURE_IBPB))
>+ svm_set_intercept_for_msr(vcpu, MSR_IA32_PRED_CMD, MSR_TYPE_W,
>+ !guest_has_pred_cmd_msr(vcpu));
>+
>+ if (boot_cpu_has(X86_FEATURE_FLUSH_L1D))
>+ svm_set_intercept_for_msr(vcpu, MSR_IA32_FLUSH_CMD, MSR_TYPE_W,
>+ !guest_cpu_cap_has(vcpu, X86_FEATURE_FLUSH_L1D));
>+
>+ /*
>+ * Unconditionally disable interception of SPEC_CTRL if V_SPEC_CTRL is
>+ * supported, i.e. if VMRUN/#VMEXIT context switch MSR_IA32_SPEC_CTRL.
>+ */
>+ if (boot_cpu_has(X86_FEATURE_V_SPEC_CTRL))
>+ svm_disable_intercept_for_msr(vcpu, MSR_IA32_SPEC_CTRL, MSR_TYPE_RW);
I think there is a bug in the original code. KVM should inject #GP when guests
try to access unsupported MSRs. Specifically, a guest w/o spec_ctrl support
should get #GP when it tries to access the MSR regardless of V_SPEC_CTRL
support on the host.
So, here should be
if (boot_cpu_has(X86_FEATURE_V_SPEC_CTRL))
svm_set_intercept_for_msr(vcpu, MSR_IA32_SPEC_CTRL, MSR_TYPE_RW,
!guest_has_spec_ctrl_msr(vcpu));
Powered by blists - more mailing lists