Skip to content

Commit 4d2a156

Browse files
committed
KVM: nSVM: Use KVM-governed feature framework to track "vVM{SAVE,LOAD} enabled"
Track "virtual VMSAVE/VMLOAD exposed to L1" via a governed feature flag instead of using a dedicated bit/flag in vcpu_svm. Opportunistically add a comment explaining why KVM disallows virtual VMLOAD/VMSAVE when the vCPU model is Intel. No functional change intended. Link: https://lore.kernel.org/r/20230815203653.519297-11-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent 4365a45 commit 4d2a156

File tree

4 files changed

+9
-5
lines changed

4 files changed

+9
-5
lines changed

arch/x86/kvm/governed_features.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ KVM_GOVERNED_X86_FEATURE(XSAVES)
1010
KVM_GOVERNED_X86_FEATURE(VMX)
1111
KVM_GOVERNED_X86_FEATURE(NRIPS)
1212
KVM_GOVERNED_X86_FEATURE(TSCRATEMSR)
13+
KVM_GOVERNED_X86_FEATURE(V_VMSAVE_VMLOAD)
1314

1415
#undef KVM_GOVERNED_X86_FEATURE
1516
#undef KVM_GOVERNED_FEATURE

arch/x86/kvm/svm/nested.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ static void nested_svm_uninit_mmu_context(struct kvm_vcpu *vcpu)
107107

108108
static bool nested_vmcb_needs_vls_intercept(struct vcpu_svm *svm)
109109
{
110-
if (!svm->v_vmload_vmsave_enabled)
110+
if (!guest_can_use(&svm->vcpu, X86_FEATURE_V_VMSAVE_VMLOAD))
111111
return true;
112112

113113
if (!nested_npt_enabled(svm))

arch/x86/kvm/svm/svm.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,8 +1194,6 @@ static inline void init_vmcb_after_set_cpuid(struct kvm_vcpu *vcpu)
11941194

11951195
set_msr_interception(vcpu, svm->msrpm, MSR_IA32_SYSENTER_EIP, 0, 0);
11961196
set_msr_interception(vcpu, svm->msrpm, MSR_IA32_SYSENTER_ESP, 0, 0);
1197-
1198-
svm->v_vmload_vmsave_enabled = false;
11991197
} else {
12001198
/*
12011199
* If hardware supports Virtual VMLOAD VMSAVE then enable it
@@ -4266,7 +4264,13 @@ static void svm_vcpu_after_set_cpuid(struct kvm_vcpu *vcpu)
42664264

42674265
svm->lbrv_enabled = lbrv && guest_cpuid_has(vcpu, X86_FEATURE_LBRV);
42684266

4269-
svm->v_vmload_vmsave_enabled = vls && guest_cpuid_has(vcpu, X86_FEATURE_V_VMSAVE_VMLOAD);
4267+
/*
4268+
* Intercept VMLOAD if the vCPU mode is Intel in order to emulate that
4269+
* VMLOAD drops bits 63:32 of SYSENTER (ignoring the fact that exposing
4270+
* SVM on Intel is bonkers and extremely unlikely to work).
4271+
*/
4272+
if (!guest_cpuid_is_intel(vcpu))
4273+
kvm_governed_feature_check_and_set(vcpu, X86_FEATURE_V_VMSAVE_VMLOAD);
42704274

42714275
svm->pause_filter_enabled = kvm_cpu_cap_has(X86_FEATURE_PAUSEFILTER) &&
42724276
guest_cpuid_has(vcpu, X86_FEATURE_PAUSEFILTER);

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 v_vmload_vmsave_enabled : 1;
263262
bool lbrv_enabled : 1;
264263
bool pause_filter_enabled : 1;
265264
bool pause_threshold_enabled : 1;

0 commit comments

Comments
 (0)