Skip to content

Commit ee785c8

Browse files
committed
KVM: nSVM: Use KVM-governed feature framework to track "vNMI enabled"
Track "virtual NMI exposed to L1" via a governed feature flag instead of using a dedicated bit/flag in vcpu_svm. Note, checking KVM's capabilities instead of the "vnmi" param means that the code isn't strictly equivalent, as vnmi_enabled could have been set if nested=false where as that the governed feature cannot. But that's a glorified nop as the feature/flag is consumed only by paths that are gated by nSVM being enabled. Link: https://lore.kernel.org/r/20230815203653.519297-15-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent b89456a commit ee785c8

File tree

3 files changed

+3
-6
lines changed

3 files changed

+3
-6
lines changed

arch/x86/kvm/governed_features.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ KVM_GOVERNED_X86_FEATURE(LBRV)
1515
KVM_GOVERNED_X86_FEATURE(PAUSEFILTER)
1616
KVM_GOVERNED_X86_FEATURE(PFTHRESHOLD)
1717
KVM_GOVERNED_X86_FEATURE(VGIF)
18+
KVM_GOVERNED_X86_FEATURE(VNMI)
1819

1920
#undef KVM_GOVERNED_X86_FEATURE
2021
#undef KVM_GOVERNED_FEATURE

arch/x86/kvm/svm/svm.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4274,8 +4274,7 @@ static void svm_vcpu_after_set_cpuid(struct kvm_vcpu *vcpu)
42744274
kvm_governed_feature_check_and_set(vcpu, X86_FEATURE_PAUSEFILTER);
42754275
kvm_governed_feature_check_and_set(vcpu, X86_FEATURE_PFTHRESHOLD);
42764276
kvm_governed_feature_check_and_set(vcpu, X86_FEATURE_VGIF);
4277-
4278-
svm->vnmi_enabled = vnmi && guest_cpuid_has(vcpu, X86_FEATURE_VNMI);
4277+
kvm_governed_feature_check_and_set(vcpu, X86_FEATURE_VNMI);
42794278

42804279
svm_recalc_instruction_intercepts(vcpu, svm);
42814280

arch/x86/kvm/svm/svm.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -259,9 +259,6 @@ struct vcpu_svm {
259259
unsigned long soft_int_next_rip;
260260
bool soft_int_injected;
261261

262-
/* optional nested SVM features that are enabled for this guest */
263-
bool vnmi_enabled : 1;
264-
265262
u32 ldr_reg;
266263
u32 dfr_reg;
267264
struct page *avic_backing_page;
@@ -537,7 +534,7 @@ static inline bool nested_npt_enabled(struct vcpu_svm *svm)
537534

538535
static inline bool nested_vnmi_enabled(struct vcpu_svm *svm)
539536
{
540-
return svm->vnmi_enabled &&
537+
return guest_can_use(&svm->vcpu, X86_FEATURE_VNMI) &&
541538
(svm->nested.ctl.int_ctl & V_NMI_ENABLE_MASK);
542539
}
543540

0 commit comments

Comments
 (0)