Skip to content

Commit b89456a

Browse files
committed
KVM: nSVM: Use KVM-governed feature framework to track "vGIF enabled"
Track "virtual GIF 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 "vgif" param means that the code isn't strictly equivalent, as vgif_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 Link: https://lore.kernel.org/r/20230815203653.519297-14-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent 59d67fc commit b89456a

File tree

4 files changed

+7
-5
lines changed

4 files changed

+7
-5
lines changed

arch/x86/kvm/governed_features.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ KVM_GOVERNED_X86_FEATURE(V_VMSAVE_VMLOAD)
1414
KVM_GOVERNED_X86_FEATURE(LBRV)
1515
KVM_GOVERNED_X86_FEATURE(PAUSEFILTER)
1616
KVM_GOVERNED_X86_FEATURE(PFTHRESHOLD)
17+
KVM_GOVERNED_X86_FEATURE(VGIF)
1718

1819
#undef KVM_GOVERNED_X86_FEATURE
1920
#undef KVM_GOVERNED_FEATURE

arch/x86/kvm/svm/nested.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,8 @@ static void nested_vmcb02_prepare_control(struct vcpu_svm *svm,
660660
* exit_int_info, exit_int_info_err, next_rip, insn_len, insn_bytes.
661661
*/
662662

663-
if (svm->vgif_enabled && (svm->nested.ctl.int_ctl & V_GIF_ENABLE_MASK))
663+
if (guest_can_use(vcpu, X86_FEATURE_VGIF) &&
664+
(svm->nested.ctl.int_ctl & V_GIF_ENABLE_MASK))
664665
int_ctl_vmcb12_bits |= (V_GIF_MASK | V_GIF_ENABLE_MASK);
665666
else
666667
int_ctl_vmcb01_bits |= (V_GIF_MASK | V_GIF_ENABLE_MASK);

arch/x86/kvm/svm/svm.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4273,8 +4273,7 @@ static void svm_vcpu_after_set_cpuid(struct kvm_vcpu *vcpu)
42734273

42744274
kvm_governed_feature_check_and_set(vcpu, X86_FEATURE_PAUSEFILTER);
42754275
kvm_governed_feature_check_and_set(vcpu, X86_FEATURE_PFTHRESHOLD);
4276-
4277-
svm->vgif_enabled = vgif && guest_cpuid_has(vcpu, X86_FEATURE_VGIF);
4276+
kvm_governed_feature_check_and_set(vcpu, X86_FEATURE_VGIF);
42784277

42794278
svm->vnmi_enabled = vnmi && guest_cpuid_has(vcpu, X86_FEATURE_VNMI);
42804279

arch/x86/kvm/svm/svm.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <asm/svm.h>
2323
#include <asm/sev-common.h>
2424

25+
#include "cpuid.h"
2526
#include "kvm_cache_regs.h"
2627

2728
#define __sme_page_pa(x) __sme_set(page_to_pfn(x) << PAGE_SHIFT)
@@ -259,7 +260,6 @@ struct vcpu_svm {
259260
bool soft_int_injected;
260261

261262
/* optional nested SVM features that are enabled for this guest */
262-
bool vgif_enabled : 1;
263263
bool vnmi_enabled : 1;
264264

265265
u32 ldr_reg;
@@ -485,7 +485,8 @@ static inline bool svm_is_intercept(struct vcpu_svm *svm, int bit)
485485

486486
static inline bool nested_vgif_enabled(struct vcpu_svm *svm)
487487
{
488-
return svm->vgif_enabled && (svm->nested.ctl.int_ctl & V_GIF_ENABLE_MASK);
488+
return guest_can_use(&svm->vcpu, X86_FEATURE_VGIF) &&
489+
(svm->nested.ctl.int_ctl & V_GIF_ENABLE_MASK);
489490
}
490491

491492
static inline struct vmcb *get_vgif_vmcb(struct vcpu_svm *svm)

0 commit comments

Comments
 (0)