Skip to content

Commit dc2b8b2

Browse files
committed
KVM: SVM: Emulate SYSENTER RIP/RSP behavior for all Intel compat vCPUs
Emulate bits 63:32 of the SYSENTER_R{I,S}P MSRs for all vCPUs that are compatible with Intel's architecture, not just strictly vCPUs that have vendor==Intel. The behavior of bits 63:32 is architecturally defined in the SDM, i.e. not some uarch specific quirk of Intel CPUs. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sean Christopherson <[email protected]>
1 parent d99e4cb commit dc2b8b2

File tree

2 files changed

+7
-15
lines changed

2 files changed

+7
-15
lines changed

arch/x86/kvm/cpuid.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,6 @@ static inline bool guest_cpuid_is_amd_or_hygon(struct kvm_vcpu *vcpu)
112112
is_guest_vendor_hygon(best->ebx, best->ecx, best->edx));
113113
}
114114

115-
static inline bool guest_cpuid_is_intel(struct kvm_vcpu *vcpu)
116-
{
117-
struct kvm_cpuid_entry2 *best;
118-
119-
best = kvm_find_cpuid_entry(vcpu, 0);
120-
return best && is_guest_vendor_intel(best->ebx, best->ecx, best->edx);
121-
}
122-
123115
static inline bool guest_cpuid_is_amd_compatible(struct kvm_vcpu *vcpu)
124116
{
125117
return vcpu->arch.is_amd_compatible;

arch/x86/kvm/svm/svm.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,7 +1196,7 @@ static inline void init_vmcb_after_set_cpuid(struct kvm_vcpu *vcpu)
11961196
{
11971197
struct vcpu_svm *svm = to_svm(vcpu);
11981198

1199-
if (guest_cpuid_is_intel(vcpu)) {
1199+
if (guest_cpuid_is_intel_compatible(vcpu)) {
12001200
/*
12011201
* We must intercept SYSENTER_EIP and SYSENTER_ESP
12021202
* accesses because the processor only stores 32 bits.
@@ -2855,12 +2855,12 @@ static int svm_get_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
28552855
break;
28562856
case MSR_IA32_SYSENTER_EIP:
28572857
msr_info->data = (u32)svm->vmcb01.ptr->save.sysenter_eip;
2858-
if (guest_cpuid_is_intel(vcpu))
2858+
if (guest_cpuid_is_intel_compatible(vcpu))
28592859
msr_info->data |= (u64)svm->sysenter_eip_hi << 32;
28602860
break;
28612861
case MSR_IA32_SYSENTER_ESP:
28622862
msr_info->data = svm->vmcb01.ptr->save.sysenter_esp;
2863-
if (guest_cpuid_is_intel(vcpu))
2863+
if (guest_cpuid_is_intel_compatible(vcpu))
28642864
msr_info->data |= (u64)svm->sysenter_esp_hi << 32;
28652865
break;
28662866
case MSR_TSC_AUX:
@@ -3083,11 +3083,11 @@ static int svm_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr)
30833083
* 32 bit part of these msrs to support Intel's
30843084
* implementation of SYSENTER/SYSEXIT.
30853085
*/
3086-
svm->sysenter_eip_hi = guest_cpuid_is_intel(vcpu) ? (data >> 32) : 0;
3086+
svm->sysenter_eip_hi = guest_cpuid_is_intel_compatible(vcpu) ? (data >> 32) : 0;
30873087
break;
30883088
case MSR_IA32_SYSENTER_ESP:
30893089
svm->vmcb01.ptr->save.sysenter_esp = (u32)data;
3090-
svm->sysenter_esp_hi = guest_cpuid_is_intel(vcpu) ? (data >> 32) : 0;
3090+
svm->sysenter_esp_hi = guest_cpuid_is_intel_compatible(vcpu) ? (data >> 32) : 0;
30913091
break;
30923092
case MSR_TSC_AUX:
30933093
/*
@@ -4337,11 +4337,11 @@ static void svm_vcpu_after_set_cpuid(struct kvm_vcpu *vcpu)
43374337
kvm_governed_feature_check_and_set(vcpu, X86_FEATURE_LBRV);
43384338

43394339
/*
4340-
* Intercept VMLOAD if the vCPU mode is Intel in order to emulate that
4340+
* Intercept VMLOAD if the vCPU model is Intel in order to emulate that
43414341
* VMLOAD drops bits 63:32 of SYSENTER (ignoring the fact that exposing
43424342
* SVM on Intel is bonkers and extremely unlikely to work).
43434343
*/
4344-
if (!guest_cpuid_is_intel(vcpu))
4344+
if (!guest_cpuid_is_intel_compatible(vcpu))
43454345
kvm_governed_feature_check_and_set(vcpu, X86_FEATURE_V_VMSAVE_VMLOAD);
43464346

43474347
kvm_governed_feature_check_and_set(vcpu, X86_FEATURE_PAUSEFILTER);

0 commit comments

Comments
 (0)