Skip to content

Commit fb35d30

Browse files
sean-jcsuryasaimadhu
authored andcommitted
x86/cpufeatures: Assign dedicated feature word for CPUID_0x8000001F[EAX]
Collect the scattered SME/SEV related feature flags into a dedicated word. There are now five recognized features in CPUID.0x8000001F.EAX, with at least one more on the horizon (SEV-SNP). Using a dedicated word allows KVM to use its automagic CPUID adjustment logic when reporting the set of supported features to userspace. No functional change intended. Signed-off-by: Sean Christopherson <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Reviewed-by: Brijesh Singh <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 7c53f6b commit fb35d30

File tree

8 files changed

+27
-17
lines changed

8 files changed

+27
-17
lines changed

arch/x86/include/asm/cpufeature.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ enum cpuid_leafs
3030
CPUID_7_ECX,
3131
CPUID_8000_0007_EBX,
3232
CPUID_7_EDX,
33+
CPUID_8000_001F_EAX,
3334
};
3435

3536
#ifdef CONFIG_X86_FEATURE_NAMES
@@ -88,8 +89,9 @@ extern const char * const x86_bug_flags[NBUGINTS*32];
8889
CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 16, feature_bit) || \
8990
CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 17, feature_bit) || \
9091
CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 18, feature_bit) || \
92+
CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 19, feature_bit) || \
9193
REQUIRED_MASK_CHECK || \
92-
BUILD_BUG_ON_ZERO(NCAPINTS != 19))
94+
BUILD_BUG_ON_ZERO(NCAPINTS != 20))
9395

9496
#define DISABLED_MASK_BIT_SET(feature_bit) \
9597
( CHECK_BIT_IN_MASK_WORD(DISABLED_MASK, 0, feature_bit) || \
@@ -111,8 +113,9 @@ extern const char * const x86_bug_flags[NBUGINTS*32];
111113
CHECK_BIT_IN_MASK_WORD(DISABLED_MASK, 16, feature_bit) || \
112114
CHECK_BIT_IN_MASK_WORD(DISABLED_MASK, 17, feature_bit) || \
113115
CHECK_BIT_IN_MASK_WORD(DISABLED_MASK, 18, feature_bit) || \
116+
CHECK_BIT_IN_MASK_WORD(DISABLED_MASK, 19, feature_bit) || \
114117
DISABLED_MASK_CHECK || \
115-
BUILD_BUG_ON_ZERO(NCAPINTS != 19))
118+
BUILD_BUG_ON_ZERO(NCAPINTS != 20))
116119

117120
#define cpu_has(c, bit) \
118121
(__builtin_constant_p(bit) && REQUIRED_MASK_BIT_SET(bit) ? 1 : \

arch/x86/include/asm/cpufeatures.h

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
/*
1414
* Defines x86 CPU feature bits
1515
*/
16-
#define NCAPINTS 19 /* N 32-bit words worth of info */
16+
#define NCAPINTS 20 /* N 32-bit words worth of info */
1717
#define NBUGINTS 1 /* N 32-bit bug flags */
1818

1919
/*
@@ -96,7 +96,7 @@
9696
#define X86_FEATURE_SYSCALL32 ( 3*32+14) /* "" syscall in IA32 userspace */
9797
#define X86_FEATURE_SYSENTER32 ( 3*32+15) /* "" sysenter in IA32 userspace */
9898
#define X86_FEATURE_REP_GOOD ( 3*32+16) /* REP microcode works well */
99-
#define X86_FEATURE_SME_COHERENT ( 3*32+17) /* "" AMD hardware-enforced cache coherency */
99+
/* FREE! ( 3*32+17) */
100100
#define X86_FEATURE_LFENCE_RDTSC ( 3*32+18) /* "" LFENCE synchronizes RDTSC */
101101
#define X86_FEATURE_ACC_POWER ( 3*32+19) /* AMD Accumulated Power Mechanism */
102102
#define X86_FEATURE_NOPL ( 3*32+20) /* The NOPL (0F 1F) instructions */
@@ -201,7 +201,7 @@
201201
#define X86_FEATURE_INVPCID_SINGLE ( 7*32+ 7) /* Effectively INVPCID && CR4.PCIDE=1 */
202202
#define X86_FEATURE_HW_PSTATE ( 7*32+ 8) /* AMD HW-PState */
203203
#define X86_FEATURE_PROC_FEEDBACK ( 7*32+ 9) /* AMD ProcFeedbackInterface */
204-
#define X86_FEATURE_SME ( 7*32+10) /* AMD Secure Memory Encryption */
204+
/* FREE! ( 7*32+10) */
205205
#define X86_FEATURE_PTI ( 7*32+11) /* Kernel Page Table Isolation enabled */
206206
#define X86_FEATURE_RETPOLINE ( 7*32+12) /* "" Generic Retpoline mitigation for Spectre variant 2 */
207207
#define X86_FEATURE_RETPOLINE_AMD ( 7*32+13) /* "" AMD Retpoline mitigation for Spectre variant 2 */
@@ -211,7 +211,7 @@
211211
#define X86_FEATURE_SSBD ( 7*32+17) /* Speculative Store Bypass Disable */
212212
#define X86_FEATURE_MBA ( 7*32+18) /* Memory Bandwidth Allocation */
213213
#define X86_FEATURE_RSB_CTXSW ( 7*32+19) /* "" Fill RSB on context switches */
214-
#define X86_FEATURE_SEV ( 7*32+20) /* AMD Secure Encrypted Virtualization */
214+
/* FREE! ( 7*32+20) */
215215
#define X86_FEATURE_USE_IBPB ( 7*32+21) /* "" Indirect Branch Prediction Barrier enabled */
216216
#define X86_FEATURE_USE_IBRS_FW ( 7*32+22) /* "" Use IBRS during runtime firmware calls */
217217
#define X86_FEATURE_SPEC_STORE_BYPASS_DISABLE ( 7*32+23) /* "" Disable Speculative Store Bypass. */
@@ -236,8 +236,6 @@
236236
#define X86_FEATURE_EPT_AD ( 8*32+17) /* Intel Extended Page Table access-dirty bit */
237237
#define X86_FEATURE_VMCALL ( 8*32+18) /* "" Hypervisor supports the VMCALL instruction */
238238
#define X86_FEATURE_VMW_VMMCALL ( 8*32+19) /* "" VMware prefers VMMCALL hypercall instruction */
239-
#define X86_FEATURE_SEV_ES ( 8*32+20) /* AMD Secure Encrypted Virtualization - Encrypted State */
240-
#define X86_FEATURE_VM_PAGE_FLUSH ( 8*32+21) /* "" VM Page Flush MSR is supported */
241239

242240
/* Intel-defined CPU features, CPUID level 0x00000007:0 (EBX), word 9 */
243241
#define X86_FEATURE_FSGSBASE ( 9*32+ 0) /* RDFSBASE, WRFSBASE, RDGSBASE, WRGSBASE instructions*/
@@ -385,6 +383,13 @@
385383
#define X86_FEATURE_CORE_CAPABILITIES (18*32+30) /* "" IA32_CORE_CAPABILITIES MSR */
386384
#define X86_FEATURE_SPEC_CTRL_SSBD (18*32+31) /* "" Speculative Store Bypass Disable */
387385

386+
/* AMD-defined memory encryption features, CPUID level 0x8000001f (EAX), word 19 */
387+
#define X86_FEATURE_SME (19*32+ 0) /* AMD Secure Memory Encryption */
388+
#define X86_FEATURE_SEV (19*32+ 1) /* AMD Secure Encrypted Virtualization */
389+
#define X86_FEATURE_VM_PAGE_FLUSH (19*32+ 2) /* "" VM Page Flush MSR is supported */
390+
#define X86_FEATURE_SEV_ES (19*32+ 3) /* AMD Secure Encrypted Virtualization - Encrypted State */
391+
#define X86_FEATURE_SME_COHERENT (19*32+10) /* "" AMD hardware-enforced cache coherency */
392+
388393
/*
389394
* BUG word(s)
390395
*/

arch/x86/include/asm/disabled-features.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
DISABLE_ENQCMD)
9292
#define DISABLED_MASK17 0
9393
#define DISABLED_MASK18 0
94-
#define DISABLED_MASK_CHECK BUILD_BUG_ON_ZERO(NCAPINTS != 19)
94+
#define DISABLED_MASK19 0
95+
#define DISABLED_MASK_CHECK BUILD_BUG_ON_ZERO(NCAPINTS != 20)
9596

9697
#endif /* _ASM_X86_DISABLED_FEATURES_H */

arch/x86/include/asm/required-features.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@
101101
#define REQUIRED_MASK16 0
102102
#define REQUIRED_MASK17 0
103103
#define REQUIRED_MASK18 0
104-
#define REQUIRED_MASK_CHECK BUILD_BUG_ON_ZERO(NCAPINTS != 19)
104+
#define REQUIRED_MASK19 0
105+
#define REQUIRED_MASK_CHECK BUILD_BUG_ON_ZERO(NCAPINTS != 20)
105106

106107
#endif /* _ASM_X86_REQUIRED_FEATURES_H */

arch/x86/kernel/cpu/common.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -960,6 +960,9 @@ void get_cpu_cap(struct cpuinfo_x86 *c)
960960
if (c->extended_cpuid_level >= 0x8000000a)
961961
c->x86_capability[CPUID_8000_000A_EDX] = cpuid_edx(0x8000000a);
962962

963+
if (c->extended_cpuid_level >= 0x8000001f)
964+
c->x86_capability[CPUID_8000_001F_EAX] = cpuid_eax(0x8000001f);
965+
963966
init_scattered_cpuid_features(c);
964967
init_speculation_control(c);
965968

arch/x86/kernel/cpu/scattered.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,6 @@ static const struct cpuid_bit cpuid_bits[] = {
4040
{ X86_FEATURE_CPB, CPUID_EDX, 9, 0x80000007, 0 },
4141
{ X86_FEATURE_PROC_FEEDBACK, CPUID_EDX, 11, 0x80000007, 0 },
4242
{ X86_FEATURE_MBA, CPUID_EBX, 6, 0x80000008, 0 },
43-
{ X86_FEATURE_SME, CPUID_EAX, 0, 0x8000001f, 0 },
44-
{ X86_FEATURE_SEV, CPUID_EAX, 1, 0x8000001f, 0 },
45-
{ X86_FEATURE_SEV_ES, CPUID_EAX, 3, 0x8000001f, 0 },
46-
{ X86_FEATURE_SME_COHERENT, CPUID_EAX, 10, 0x8000001f, 0 },
47-
{ X86_FEATURE_VM_PAGE_FLUSH, CPUID_EAX, 2, 0x8000001f, 0 },
4843
{ 0, 0, 0, 0, 0 }
4944
};
5045

tools/arch/x86/include/asm/disabled-features.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
DISABLE_ENQCMD)
9292
#define DISABLED_MASK17 0
9393
#define DISABLED_MASK18 0
94-
#define DISABLED_MASK_CHECK BUILD_BUG_ON_ZERO(NCAPINTS != 19)
94+
#define DISABLED_MASK19 0
95+
#define DISABLED_MASK_CHECK BUILD_BUG_ON_ZERO(NCAPINTS != 20)
9596

9697
#endif /* _ASM_X86_DISABLED_FEATURES_H */

tools/arch/x86/include/asm/required-features.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@
101101
#define REQUIRED_MASK16 0
102102
#define REQUIRED_MASK17 0
103103
#define REQUIRED_MASK18 0
104-
#define REQUIRED_MASK_CHECK BUILD_BUG_ON_ZERO(NCAPINTS != 19)
104+
#define REQUIRED_MASK19 0
105+
#define REQUIRED_MASK_CHECK BUILD_BUG_ON_ZERO(NCAPINTS != 20)
105106

106107
#endif /* _ASM_X86_REQUIRED_FEATURES_H */

0 commit comments

Comments
 (0)