[PATCH v2 66/66] KVM: x86: Move nSVM CPUID 0x8000000A handing into common x86 code

Sean Christopherson
2020-03-02T23:59:07Z

Handle CPUID 0x8000000A in the main switch in __do_cpuid_func() and drop
->set_supported_cpuid() now that both VMX and SVM implementations are
empty. Like leaf 0x14 (Intel PT) and leaf 0x8000001F (SEV), leaf
0x8000000A is is (obviously) vendor specific but can be queried in
common code while respecting SVM's wishes by querying kvm_cpu_cap_has().

Suggested-by: Vitaly Kuznetsov <vkuznets@redhat.com>
Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
---
arch/x86/include/asm/kvm_host.h | 2 --
arch/x86/kvm/cpuid.c | 13 +++++++++++--
arch/x86/kvm/svm.c | 19 -------------------
arch/x86/kvm/vmx/vmx.c | 6 ------
4 files changed, 11 insertions(+), 29 deletions(-)

diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index 27983e5895d9..ccafcbe82d9d 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -1151,8 +1151,6 @@ struct kvm_x86_ops {

void (*set_tdp_cr3)(struct kvm_vcpu *vcpu, unsigned long cr3);

- void (*set_supported_cpuid)(struct kvm_cpuid_entry2 *entry);
-
bool (*has_wbinvd_exit)(void);

u64 (*read_l1_tsc_offset)(struct kvm_vcpu *vcpu);
diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
index f0c4ad04d4dc..3347001bf3b0 100644
--- a/arch/x86/kvm/cpuid.c
+++ b/arch/x86/kvm/cpuid.c
@@ -746,6 +746,17 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function)
cpuid_entry_override(entry, CPUID_8000_0008_EBX);
break;
}
+ case 0x8000000A:
+ if (!kvm_cpu_cap_has(X86_FEATURE_SVM)) {
+ entry->eax = entry->ebx = entry->ecx = entry->edx = 0;
+ break;
+ }
+ entry->eax = 1; /* SVM revision 1 */
+ entry->ebx = 8; /* Lets support 8 ASIDs in case we add proper
+ ASID emulation to nested SVM */
+ entry->ecx = 0; /* Reserved */
+ /* Note, 0x8000000A.EDX is managed via kvm_cpu_caps. */;
+ break;
case 0x80000019:
entry->ecx = entry->edx = 0;
break;
@@ -775,8 +786,6 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function)
break;
}

- kvm_x86_ops->set_supported_cpuid(entry);
-
r = 0;

out:
diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
index 32d9c13ec6b9..a190bea5ba90 100644
--- a/arch/x86/kvm/svm.c
+++ b/arch/x86/kvm/svm.c
@@ -6048,23 +6048,6 @@ static void svm_cpuid_update(struct kvm_vcpu *vcpu)
APICV_INHIBIT_REASON_NESTED);
}

-static void svm_set_supported_cpuid(struct kvm_cpuid_entry2 *entry)
-{
- switch (entry->function) {
- case 0x8000000A:
- if (!kvm_cpu_cap_has(X86_FEATURE_SVM)) {
- entry->eax = entry->ebx = entry->ecx = entry->edx = 0;
- break;
- }
- entry->eax = 1; /* SVM revision 1 */
- entry->ebx = 8; /* Lets support 8 ASIDs in case we add proper
- ASID emulation to nested SVM */
- entry->ecx = 0; /* Reserved */
- /* Note, 0x8000000A.EDX is managed via kvm_cpu_caps. */;
- break;
- }
-}
-
static bool svm_has_wbinvd_exit(void)
{
return true;
@@ -7422,8 +7405,6 @@ static struct kvm_x86_ops svm_x86_ops __ro_after_init = {

.cpuid_update = svm_cpuid_update,

- .set_supported_cpuid = svm_set_supported_cpuid,
-
.has_wbinvd_exit = svm_has_wbinvd_exit,

.read_l1_tsc_offset = svm_read_l1_tsc_offset,
diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
index 180aeebd029a..eab3f77e9b7f 100644
--- a/arch/x86/kvm/vmx/vmx.c
+++ b/arch/x86/kvm/vmx/vmx.c
@@ -7098,11 +7098,6 @@ static void vmx_cpuid_update(struct kvm_vcpu *vcpu)
}
}

-static void vmx_set_supported_cpuid(struct kvm_cpuid_entry2 *entry)
-{
-
-}
-
static __init void vmx_set_cpu_caps(void)
{
/* CPUID 0x1 */
@@ -7915,7 +7910,6 @@ static struct kvm_x86_ops vmx_x86_ops __ro_after_init = {
.get_exit_info = vmx_get_exit_info,

.cpuid_update = vmx_cpuid_update,
- .set_supported_cpuid = vmx_set_supported_cpuid,

.has_wbinvd_exit = cpu_has_vmx_wbinvd_exit,

--
2.24.1