Commit 24652b74 authored by Vitaly Kuznetsov's avatar Vitaly Kuznetsov Committed by Paolo Bonzini

KVM: x86: Add a KVM-only leaf for CPUID_8000_0007_EDX

CPUID_8000_0007_EDX may come handy when X86_FEATURE_CONSTANT_TSC
needs to be checked.

No functional change intended.
Signed-off-by: default avatarVitaly Kuznetsov <vkuznets@redhat.com>
Reviewed-by: default avatarSean Christopherson <seanjc@google.com>
Message-Id: <20221013095849.705943-3-vkuznets@redhat.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent 916dde51
...@@ -701,6 +701,10 @@ void kvm_set_cpu_caps(void) ...@@ -701,6 +701,10 @@ void kvm_set_cpu_caps(void)
if (!tdp_enabled && IS_ENABLED(CONFIG_X86_64)) if (!tdp_enabled && IS_ENABLED(CONFIG_X86_64))
kvm_cpu_cap_set(X86_FEATURE_GBPAGES); kvm_cpu_cap_set(X86_FEATURE_GBPAGES);
kvm_cpu_cap_init_kvm_defined(CPUID_8000_0007_EDX,
SF(CONSTANT_TSC)
);
kvm_cpu_cap_mask(CPUID_8000_0008_EBX, kvm_cpu_cap_mask(CPUID_8000_0008_EBX,
F(CLZERO) | F(XSAVEERPTR) | F(CLZERO) | F(XSAVEERPTR) |
F(WBNOINVD) | F(AMD_IBPB) | F(AMD_IBRS) | F(AMD_SSBD) | F(VIRT_SSBD) | F(WBNOINVD) | F(AMD_IBPB) | F(AMD_IBRS) | F(AMD_SSBD) | F(VIRT_SSBD) |
...@@ -1153,8 +1157,8 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function) ...@@ -1153,8 +1157,8 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function)
entry->edx &= ~GENMASK(17, 16); entry->edx &= ~GENMASK(17, 16);
break; break;
case 0x80000007: /* Advanced power management */ case 0x80000007: /* Advanced power management */
/* invariant TSC is CPUID.80000007H:EDX[8] */ cpuid_entry_override(entry, CPUID_8000_0007_EDX);
entry->edx &= (1 << 8);
/* mask against host */ /* mask against host */
entry->edx &= boot_cpu_data.x86_power; entry->edx &= boot_cpu_data.x86_power;
entry->eax = entry->ebx = entry->ecx = 0; entry->eax = entry->ebx = entry->ecx = 0;
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
enum kvm_only_cpuid_leafs { enum kvm_only_cpuid_leafs {
CPUID_12_EAX = NCAPINTS, CPUID_12_EAX = NCAPINTS,
CPUID_7_1_EDX, CPUID_7_1_EDX,
CPUID_8000_0007_EDX,
NR_KVM_CPU_CAPS, NR_KVM_CPU_CAPS,
NKVMCAPINTS = NR_KVM_CPU_CAPS - NCAPINTS, NKVMCAPINTS = NR_KVM_CPU_CAPS - NCAPINTS,
...@@ -42,6 +43,9 @@ enum kvm_only_cpuid_leafs { ...@@ -42,6 +43,9 @@ enum kvm_only_cpuid_leafs {
#define X86_FEATURE_AVX_NE_CONVERT KVM_X86_FEATURE(CPUID_7_1_EDX, 5) #define X86_FEATURE_AVX_NE_CONVERT KVM_X86_FEATURE(CPUID_7_1_EDX, 5)
#define X86_FEATURE_PREFETCHITI KVM_X86_FEATURE(CPUID_7_1_EDX, 14) #define X86_FEATURE_PREFETCHITI KVM_X86_FEATURE(CPUID_7_1_EDX, 14)
/* CPUID level 0x80000007 (EDX). */
#define KVM_X86_FEATURE_CONSTANT_TSC KVM_X86_FEATURE(CPUID_8000_0007_EDX, 8)
struct cpuid_reg { struct cpuid_reg {
u32 function; u32 function;
u32 index; u32 index;
...@@ -67,6 +71,7 @@ static const struct cpuid_reg reverse_cpuid[] = { ...@@ -67,6 +71,7 @@ static const struct cpuid_reg reverse_cpuid[] = {
[CPUID_12_EAX] = {0x00000012, 0, CPUID_EAX}, [CPUID_12_EAX] = {0x00000012, 0, CPUID_EAX},
[CPUID_8000_001F_EAX] = {0x8000001f, 0, CPUID_EAX}, [CPUID_8000_001F_EAX] = {0x8000001f, 0, CPUID_EAX},
[CPUID_7_1_EDX] = { 7, 1, CPUID_EDX}, [CPUID_7_1_EDX] = { 7, 1, CPUID_EDX},
[CPUID_8000_0007_EDX] = {0x80000007, 0, CPUID_EDX},
}; };
/* /*
...@@ -97,6 +102,8 @@ static __always_inline u32 __feature_translate(int x86_feature) ...@@ -97,6 +102,8 @@ static __always_inline u32 __feature_translate(int x86_feature)
return KVM_X86_FEATURE_SGX1; return KVM_X86_FEATURE_SGX1;
else if (x86_feature == X86_FEATURE_SGX2) else if (x86_feature == X86_FEATURE_SGX2)
return KVM_X86_FEATURE_SGX2; return KVM_X86_FEATURE_SGX2;
else if (x86_feature == X86_FEATURE_CONSTANT_TSC)
return KVM_X86_FEATURE_CONSTANT_TSC;
return x86_feature; return x86_feature;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment