]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
KVM: x86: Use KVM_REQ_RECALC_INTERCEPTS to react to CPUID updates
authorSean Christopherson <seanjc@google.com>
Wed, 6 Aug 2025 19:56:47 +0000 (12:56 -0700)
committerSean Christopherson <seanjc@google.com>
Thu, 18 Sep 2025 19:57:19 +0000 (12:57 -0700)
Defer recalculating MSR and instruction intercepts after a CPUID update
via RECALC_INTERCEPTS to converge on RECALC_INTERCEPTS as the "official"
mechanism for triggering recalcs.  As a bonus, because KVM does a "recalc"
during vCPU creation, and every functional VMM sets CPUID at least once,
for all intents and purposes this saves at least one recalc.

Tested-by: Xudong Hao <xudong.hao@intel.com>
Link: https://lore.kernel.org/r/20250806195706.1650976-26-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
arch/x86/kvm/cpuid.c
arch/x86/kvm/svm/svm.c
arch/x86/kvm/vmx/vmx.c

index ad6cadf099305c6b4db9c72b2546b3afdb50a0af..efee08fad72ea9277f95ec0e24f3b4bd34e799a8 100644 (file)
@@ -448,6 +448,8 @@ void kvm_vcpu_after_set_cpuid(struct kvm_vcpu *vcpu)
         * adjustments to the reserved GPA bits.
         */
        kvm_mmu_after_set_cpuid(vcpu);
+
+       kvm_make_request(KVM_REQ_RECALC_INTERCEPTS, vcpu);
 }
 
 int cpuid_query_maxphyaddr(struct kvm_vcpu *vcpu)
index 711f160113d118f5e5e70a1b1be62bec5c822512..22c5e4ffa13266ef068f2fb8b16ed5f92d252221 100644 (file)
@@ -1225,7 +1225,7 @@ static void init_vmcb(struct kvm_vcpu *vcpu)
 
        svm_hv_init_vmcb(vmcb);
 
-       svm_recalc_intercepts(vcpu);
+       kvm_make_request(KVM_REQ_RECALC_INTERCEPTS, vcpu);
 
        vmcb_mark_all_dirty(vmcb);
 
@@ -4478,8 +4478,6 @@ static void svm_vcpu_after_set_cpuid(struct kvm_vcpu *vcpu)
 
        if (sev_guest(vcpu->kvm))
                sev_vcpu_after_set_cpuid(svm);
-
-       svm_recalc_intercepts(vcpu);
 }
 
 static bool svm_has_wbinvd_exit(void)
index 68bec421f3fc661896a14a12f4169298d2162bc1..6b9523ca082cf8ec0f8978fde1a709a21c700a3b 100644 (file)
@@ -7806,9 +7806,6 @@ void vmx_vcpu_after_set_cpuid(struct kvm_vcpu *vcpu)
                vmx->msr_ia32_feature_control_valid_bits &=
                        ~FEAT_CTL_SGX_LC_ENABLED;
 
-       /* Recalc MSR interception to account for feature changes. */
-       vmx_recalc_intercepts(vcpu);
-
        /* Refresh #PF interception to account for MAXPHYADDR changes. */
        vmx_update_exception_bitmap(vcpu);
 }