Skip to content

Commit 7a6a6a3

Browse files
committed
KVM: nSVM: Use KVM-governed feature framework to track "NRIPS enabled"
Track "NRIPS exposed to L1" via a governed feature flag instead of using a dedicated bit/flag in vcpu_svm. No functional change intended. Reviewed-by: Yuan Yao <yuan.yao@intel.com> Link: https://lore.kernel.org/r/20230815203653.519297-9-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent 1c18efd commit 7a6a6a3

File tree

4 files changed

+5
-7
lines changed

4 files changed

+5
-7
lines changed

arch/x86/kvm/governed_features.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ BUILD_BUG()
88
KVM_GOVERNED_X86_FEATURE(GBPAGES)
99
KVM_GOVERNED_X86_FEATURE(XSAVES)
1010
KVM_GOVERNED_X86_FEATURE(VMX)
11+
KVM_GOVERNED_X86_FEATURE(NRIPS)
1112

1213
#undef KVM_GOVERNED_X86_FEATURE
1314
#undef KVM_GOVERNED_FEATURE

arch/x86/kvm/svm/nested.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,7 @@ static void nested_vmcb02_prepare_control(struct vcpu_svm *svm,
716716
* what a nrips=0 CPU would do (L1 is responsible for advancing RIP
717717
* prior to injecting the event).
718718
*/
719-
if (svm->nrips_enabled)
719+
if (guest_can_use(vcpu, X86_FEATURE_NRIPS))
720720
vmcb02->control.next_rip = svm->nested.ctl.next_rip;
721721
else if (boot_cpu_has(X86_FEATURE_NRIPS))
722722
vmcb02->control.next_rip = vmcb12_rip;
@@ -726,7 +726,7 @@ static void nested_vmcb02_prepare_control(struct vcpu_svm *svm,
726726
svm->soft_int_injected = true;
727727
svm->soft_int_csbase = vmcb12_csbase;
728728
svm->soft_int_old_rip = vmcb12_rip;
729-
if (svm->nrips_enabled)
729+
if (guest_can_use(vcpu, X86_FEATURE_NRIPS))
730730
svm->soft_int_next_rip = svm->nested.ctl.next_rip;
731731
else
732732
svm->soft_int_next_rip = vmcb12_rip;
@@ -1026,7 +1026,7 @@ int nested_svm_vmexit(struct vcpu_svm *svm)
10261026
if (vmcb12->control.exit_code != SVM_EXIT_ERR)
10271027
nested_save_pending_event_to_vmcb12(svm, vmcb12);
10281028

1029-
if (svm->nrips_enabled)
1029+
if (guest_can_use(vcpu, X86_FEATURE_NRIPS))
10301030
vmcb12->control.next_rip = vmcb02->control.next_rip;
10311031

10321032
vmcb12->control.int_ctl = svm->nested.ctl.int_ctl;

arch/x86/kvm/svm/svm.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4259,9 +4259,7 @@ static void svm_vcpu_after_set_cpuid(struct kvm_vcpu *vcpu)
42594259
guest_cpuid_has(vcpu, X86_FEATURE_XSAVE))
42604260
kvm_governed_feature_set(vcpu, X86_FEATURE_XSAVES);
42614261

4262-
/* Update nrips enabled cache */
4263-
svm->nrips_enabled = kvm_cpu_cap_has(X86_FEATURE_NRIPS) &&
4264-
guest_cpuid_has(vcpu, X86_FEATURE_NRIPS);
4262+
kvm_governed_feature_check_and_set(vcpu, X86_FEATURE_NRIPS);
42654263

42664264
svm->tsc_scaling_enabled = tsc_scaling && guest_cpuid_has(vcpu, X86_FEATURE_TSCRATEMSR);
42674265
svm->lbrv_enabled = lbrv && guest_cpuid_has(vcpu, X86_FEATURE_LBRV);

arch/x86/kvm/svm/svm.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,6 @@ struct vcpu_svm {
259259
bool soft_int_injected;
260260

261261
/* optional nested SVM features that are enabled for this guest */
262-
bool nrips_enabled : 1;
263262
bool tsc_scaling_enabled : 1;
264263
bool v_vmload_vmsave_enabled : 1;
265264
bool lbrv_enabled : 1;

0 commit comments

Comments
 (0)