@@ -648,6 +648,16 @@ static __always_inline void kvm_cpu_cap_init(enum cpuid_leafs leaf, u32 mask)
(IS_ENABLED(CONFIG_X86_64) ? F(name) : 0); \
})
+/*
+ * Aliased Features - For features in 0x8000_0001.EDX that are duplicates of
+ * identical 0x1.EDX features, and thus are aliased from 0x1 to 0x8000_0001.
+ */
+#define ALIASED_1_EDX_F(name) \
+({ \
+ BUILD_BUG_ON(__feature_leaf(X86_FEATURE_##name) != CPUID_1_EDX); \
+ feature_bit(name); \
+})
+
void kvm_set_cpu_caps(void)
{
memset(kvm_cpu_caps, 0, sizeof(kvm_cpu_caps));
@@ -892,30 +902,30 @@ void kvm_set_cpu_caps(void)
);
kvm_cpu_cap_init(CPUID_8000_0001_EDX,
- F(FPU) |
- F(VME) |
- F(DE) |
- F(PSE) |
- F(TSC) |
- F(MSR) |
- F(PAE) |
- F(MCE) |
- F(CX8) |
- F(APIC) |
+ ALIASED_1_EDX_F(FPU) |
+ ALIASED_1_EDX_F(VME) |
+ ALIASED_1_EDX_F(DE) |
+ ALIASED_1_EDX_F(PSE) |
+ ALIASED_1_EDX_F(TSC) |
+ ALIASED_1_EDX_F(MSR) |
+ ALIASED_1_EDX_F(PAE) |
+ ALIASED_1_EDX_F(MCE) |
+ ALIASED_1_EDX_F(CX8) |
+ ALIASED_1_EDX_F(APIC) |
0 /* Reserved */ |
F(SYSCALL) |
- F(MTRR) |
- F(PGE) |
- F(MCA) |
- F(CMOV) |
- F(PAT) |
- F(PSE36) |
+ ALIASED_1_EDX_F(MTRR) |
+ ALIASED_1_EDX_F(PGE) |
+ ALIASED_1_EDX_F(MCA) |
+ ALIASED_1_EDX_F(CMOV) |
+ ALIASED_1_EDX_F(PAT) |
+ ALIASED_1_EDX_F(PSE36) |
0 /* Reserved */ |
F(NX) |
0 /* Reserved */ |
F(MMXEXT) |
- F(MMX) |
- F(FXSR) |
+ ALIASED_1_EDX_F(MMX) |
+ ALIASED_1_EDX_F(FXSR) |
F(FXSR_OPT) |
X86_64_F(GBPAGES) |
F(RDTSCP) |
@@ -1055,6 +1065,7 @@ EXPORT_SYMBOL_GPL(kvm_set_cpu_caps);
#undef F
#undef SF
#undef X86_64_F
+#undef ALIASED_1_EDX_F
struct kvm_cpuid_array {
struct kvm_cpuid_entry2 *entries;
Add a macro to precisely handle CPUID features that AMD duplicated from CPUID.0x1.EDX into CPUID.0x8000_0001.EDX. This will allow adding an assert that all features passed to kvm_cpu_cap_init() match the word being processed, e.g. to prevent passing a feature from CPUID 0x7 to CPUID 0x1. Because the kernel simply reuses the X86_FEATURE_* definitions from CPUID.0x1.EDX, KVM's use of the aliased features would result in false positives from such an assert. No functional change intended. Signed-off-by: Sean Christopherson <seanjc@google.com> --- arch/x86/kvm/cpuid.c | 47 +++++++++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 18 deletions(-)