Skip to content

Commit 5a1a726

Browse files
committed
KVM: x86: Use KVM_REQ_RECALC_INTERCEPTS to react to CPUID updates
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>
1 parent 6057497 commit 5a1a726

File tree

3 files changed

+3
-6
lines changed

3 files changed

+3
-6
lines changed

arch/x86/kvm/cpuid.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,8 @@ void kvm_vcpu_after_set_cpuid(struct kvm_vcpu *vcpu)
448448
* adjustments to the reserved GPA bits.
449449
*/
450450
kvm_mmu_after_set_cpuid(vcpu);
451+
452+
kvm_make_request(KVM_REQ_RECALC_INTERCEPTS, vcpu);
451453
}
452454

453455
int cpuid_query_maxphyaddr(struct kvm_vcpu *vcpu)

arch/x86/kvm/svm/svm.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,7 +1225,7 @@ static void init_vmcb(struct kvm_vcpu *vcpu)
12251225

12261226
svm_hv_init_vmcb(vmcb);
12271227

1228-
svm_recalc_intercepts(vcpu);
1228+
kvm_make_request(KVM_REQ_RECALC_INTERCEPTS, vcpu);
12291229

12301230
vmcb_mark_all_dirty(vmcb);
12311231

@@ -4478,8 +4478,6 @@ static void svm_vcpu_after_set_cpuid(struct kvm_vcpu *vcpu)
44784478

44794479
if (sev_guest(vcpu->kvm))
44804480
sev_vcpu_after_set_cpuid(svm);
4481-
4482-
svm_recalc_intercepts(vcpu);
44834481
}
44844482

44854483
static bool svm_has_wbinvd_exit(void)

arch/x86/kvm/vmx/vmx.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7806,9 +7806,6 @@ void vmx_vcpu_after_set_cpuid(struct kvm_vcpu *vcpu)
78067806
vmx->msr_ia32_feature_control_valid_bits &=
78077807
~FEAT_CTL_SGX_LC_ENABLED;
78087808

7809-
/* Recalc MSR interception to account for feature changes. */
7810-
vmx_recalc_intercepts(vcpu);
7811-
78127809
/* Refresh #PF interception to account for MAXPHYADDR changes. */
78137810
vmx_update_exception_bitmap(vcpu);
78147811
}

0 commit comments

Comments
 (0)