Skip to content

Commit 8d1e0db

Browse files
kimphillamdgregkh
authored andcommitted
KVM: x86: Move open-coded CPUID leaf 0x80000021 EAX bit propagation code
Commit c35ac8c upstream 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 <kim.phillips@amd.com> Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de> Acked-by: Sean Christopherson <seanjc@google.com> Link: https://lore.kernel.org/r/20230124163319.2277355-3-kim.phillips@amd.com Move setting of VERW_CLEAR bit to the new kvm_cpu_cap_mask(CPUID_8000_0021_EAX, ...) site. Cc: <stable@vger.kernel.org> # 6.1.y Signed-off-by: Boris Ostrovsky <boris.ostrovsky@oracle.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 7ce12a1 commit 8d1e0db

File tree

1 file changed

+14
-19
lines changed

1 file changed

+14
-19
lines changed

arch/x86/kvm/cpuid.c

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,18 @@ void kvm_set_cpu_caps(void)
749749
0 /* SME */ | F(SEV) | 0 /* VM_PAGE_FLUSH */ | F(SEV_ES) |
750750
F(SME_COHERENT));
751751

752+
kvm_cpu_cap_mask(CPUID_8000_0021_EAX,
753+
BIT(0) /* NO_NESTED_DATA_BP */ |
754+
BIT(2) /* LFENCE Always serializing */ | 0 /* SmmPgCfgLock */ |
755+
BIT(5) /* The memory form of VERW mitigates TSA */ |
756+
BIT(6) /* NULL_SEL_CLR_BASE */ | 0 /* PrefetchCtlMsr */
757+
);
758+
if (cpu_feature_enabled(X86_FEATURE_LFENCE_RDTSC))
759+
kvm_cpu_caps[CPUID_8000_0021_EAX] |= BIT(2) /* LFENCE Always serializing */;
760+
if (!static_cpu_has_bug(X86_BUG_NULL_SEG))
761+
kvm_cpu_caps[CPUID_8000_0021_EAX] |= BIT(6) /* NULL_SEL_CLR_BASE */;
762+
kvm_cpu_caps[CPUID_8000_0021_EAX] |= BIT(9) /* NO_SMM_CTL_MSR */;
763+
752764
kvm_cpu_cap_mask(CPUID_C000_0001_EDX,
753765
F(XSTORE) | F(XSTORE_EN) | F(XCRYPT) | F(XCRYPT_EN) |
754766
F(ACE2) | F(ACE2_EN) | F(PHE) | F(PHE_EN) |
@@ -758,8 +770,6 @@ void kvm_set_cpu_caps(void)
758770
if (cpu_feature_enabled(X86_FEATURE_SRSO_NO))
759771
kvm_cpu_cap_set(X86_FEATURE_SRSO_NO);
760772

761-
kvm_cpu_cap_mask(CPUID_8000_0021_EAX, F(VERW_CLEAR));
762-
763773
kvm_cpu_cap_init_kvm_defined(CPUID_8000_0021_ECX,
764774
F(TSA_SQ_NO) | F(TSA_L1_NO)
765775
);
@@ -1249,23 +1259,8 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function)
12491259
entry->eax = entry->ebx = entry->ecx = entry->edx = 0;
12501260
break;
12511261
case 0x80000021:
1252-
entry->ebx = entry->edx = 0;
1253-
/*
1254-
* Pass down these bits:
1255-
* EAX 0 NNDBP, Processor ignores nested data breakpoints
1256-
* EAX 2 LAS, LFENCE always serializing
1257-
* EAX 6 NSCB, Null selector clear base
1258-
*
1259-
* Other defined bits are for MSRs that KVM does not expose:
1260-
* EAX 3 SPCL, SMM page configuration lock
1261-
* EAX 13 PCMSR, Prefetch control MSR
1262-
*/
1263-
entry->eax &= BIT(0) | BIT(2) | BIT(6);
1264-
if (static_cpu_has(X86_FEATURE_LFENCE_RDTSC))
1265-
entry->eax |= BIT(2);
1266-
if (!static_cpu_has_bug(X86_BUG_NULL_SEG))
1267-
entry->eax |= BIT(6);
1268-
cpuid_entry_override(entry, CPUID_8000_0021_ECX);
1262+
entry->ebx = entry->ecx = entry->edx = 0;
1263+
cpuid_entry_override(entry, CPUID_8000_0021_EAX);
12691264
break;
12701265
/*Add support for Centaur's CPUID instruction*/
12711266
case 0xC0000000:

0 commit comments

Comments
 (0)