Skip to content

Commit c35ac8c

Browse files
kimphillamdbp3tk0v
authored andcommitted
KVM: x86: Move open-coded CPUID leaf 0x80000021 EAX bit propagation code
Move code from __do_cpuid_func() to kvm_set_cpu_caps() in preparation for adding the features in their native leaf. Also drop the bit description comments as it will be more self-describing once the individual features are added. Whilst there, switch to using the more efficient cpu_feature_enabled() instead of static_cpu_has(). Note, LFENCE_RDTSC and "NULL selector clears base" are currently synthetic, Linux-defined feature flags as Linux tracking of the features predates AMD's definition. Keep the manual propagation of the flags from their synthetic counterparts until the kernel fully converts to AMD's definition, otherwise KVM would stop synthesizing the flags as intended. Signed-off-by: Kim Phillips <[email protected]> Signed-off-by: Borislav Petkov (AMD) <[email protected]> Acked-by: Sean Christopherson <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 8415a74 commit c35ac8c

File tree

1 file changed

+12
-19
lines changed

1 file changed

+12
-19
lines changed

arch/x86/kvm/cpuid.c

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,17 @@ void kvm_set_cpu_caps(void)
741741
0 /* SME */ | F(SEV) | 0 /* VM_PAGE_FLUSH */ | F(SEV_ES) |
742742
F(SME_COHERENT));
743743

744+
kvm_cpu_cap_mask(CPUID_8000_0021_EAX,
745+
BIT(0) /* NO_NESTED_DATA_BP */ |
746+
BIT(2) /* LFENCE Always serializing */ | 0 /* SmmPgCfgLock */ |
747+
BIT(6) /* NULL_SEL_CLR_BASE */ | 0 /* PrefetchCtlMsr */
748+
);
749+
if (cpu_feature_enabled(X86_FEATURE_LFENCE_RDTSC))
750+
kvm_cpu_caps[CPUID_8000_0021_EAX] |= BIT(2) /* LFENCE Always serializing */;
751+
if (!static_cpu_has_bug(X86_BUG_NULL_SEG))
752+
kvm_cpu_caps[CPUID_8000_0021_EAX] |= BIT(6) /* NULL_SEL_CLR_BASE */;
753+
kvm_cpu_caps[CPUID_8000_0021_EAX] |= BIT(9) /* NO_SMM_CTL_MSR */;
754+
744755
kvm_cpu_cap_mask(CPUID_C000_0001_EDX,
745756
F(XSTORE) | F(XSTORE_EN) | F(XCRYPT) | F(XCRYPT_EN) |
746757
F(ACE2) | F(ACE2_EN) | F(PHE) | F(PHE_EN) |
@@ -1222,25 +1233,7 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function)
12221233
break;
12231234
case 0x80000021:
12241235
entry->ebx = entry->ecx = entry->edx = 0;
1225-
/*
1226-
* Pass down these bits:
1227-
* EAX 0 NNDBP, Processor ignores nested data breakpoints
1228-
* EAX 2 LAS, LFENCE always serializing
1229-
* EAX 6 NSCB, Null selector clear base
1230-
*
1231-
* Other defined bits are for MSRs that KVM does not expose:
1232-
* EAX 3 SPCL, SMM page configuration lock
1233-
* EAX 13 PCMSR, Prefetch control MSR
1234-
*
1235-
* KVM doesn't support SMM_CTL.
1236-
* EAX 9 SMM_CTL MSR is not supported
1237-
*/
1238-
entry->eax &= BIT(0) | BIT(2) | BIT(6);
1239-
entry->eax |= BIT(9);
1240-
if (static_cpu_has(X86_FEATURE_LFENCE_RDTSC))
1241-
entry->eax |= BIT(2);
1242-
if (!static_cpu_has_bug(X86_BUG_NULL_SEG))
1243-
entry->eax |= BIT(6);
1236+
cpuid_entry_override(entry, CPUID_8000_0021_EAX);
12441237
break;
12451238
/*Add support for Centaur's CPUID instruction*/
12461239
case 0xC0000000:

0 commit comments

Comments
 (0)