Skip to content

Commit 30fa928

Browse files
committed
x86/CPU/AMD: Add ZenX generations flags
Add X86_FEATURE flags for each Zen generation. They should be used from now on instead of checking f/m/s. Signed-off-by: Borislav Petkov (AMD) <[email protected]> Reviewed-by: Nikolay Borisov <[email protected]> Acked-by: Thomas Gleixner <[email protected]> Link: http://lore.kernel.org/r/[email protected]
1 parent 5bfa0e4 commit 30fa928

File tree

2 files changed

+72
-3
lines changed

2 files changed

+72
-3
lines changed

arch/x86/include/asm/cpufeatures.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@
218218
#define X86_FEATURE_IBRS ( 7*32+25) /* Indirect Branch Restricted Speculation */
219219
#define X86_FEATURE_IBPB ( 7*32+26) /* Indirect Branch Prediction Barrier */
220220
#define X86_FEATURE_STIBP ( 7*32+27) /* Single Thread Indirect Branch Predictors */
221-
#define X86_FEATURE_ZEN (7*32+28) /* "" CPU based on Zen microarchitecture */
221+
#define X86_FEATURE_ZEN ( 7*32+28) /* "" CPU based on Zen microarchitecture */
222222
#define X86_FEATURE_L1TF_PTEINV ( 7*32+29) /* "" L1TF workaround PTE inversion */
223223
#define X86_FEATURE_IBRS_ENHANCED ( 7*32+30) /* Enhanced IBRS */
224224
#define X86_FEATURE_MSR_IA32_FEAT_CTL ( 7*32+31) /* "" MSR IA32_FEAT_CTL configured */
@@ -312,6 +312,9 @@
312312
#define X86_FEATURE_SRSO_ALIAS (11*32+25) /* "" AMD BTB untrain RETs through aliasing */
313313
#define X86_FEATURE_IBPB_ON_VMEXIT (11*32+26) /* "" Issue an IBPB only on VMEXIT */
314314
#define X86_FEATURE_APIC_MSRS_FENCE (11*32+27) /* "" IA32_TSC_DEADLINE and X2APIC MSRs need fencing */
315+
#define X86_FEATURE_ZEN2 (11*32+28) /* "" CPU based on Zen2 microarchitecture */
316+
#define X86_FEATURE_ZEN3 (11*32+29) /* "" CPU based on Zen3 microarchitecture */
317+
#define X86_FEATURE_ZEN4 (11*32+30) /* "" CPU based on Zen4 microarchitecture */
315318

316319
/* Intel-defined CPU features, CPUID level 0x00000007:1 (EAX), word 12 */
317320
#define X86_FEATURE_AVX_VNNI (12*32+ 4) /* AVX VNNI instructions */

arch/x86/kernel/cpu/amd.c

Lines changed: 68 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,49 @@ static void bsp_init_amd(struct cpuinfo_x86 *c)
616616
}
617617

618618
resctrl_cpu_detect(c);
619+
620+
/* Figure out Zen generations: */
621+
switch (c->x86) {
622+
case 0x17: {
623+
switch (c->x86_model) {
624+
case 0x00 ... 0x2f:
625+
case 0x50 ... 0x5f:
626+
setup_force_cpu_cap(X86_FEATURE_ZEN);
627+
break;
628+
case 0x30 ... 0x4f:
629+
case 0x60 ... 0x7f:
630+
case 0x90 ... 0x91:
631+
case 0xa0 ... 0xaf:
632+
setup_force_cpu_cap(X86_FEATURE_ZEN2);
633+
break;
634+
default:
635+
goto warn;
636+
}
637+
break;
638+
}
639+
case 0x19: {
640+
switch (c->x86_model) {
641+
case 0x00 ... 0x0f:
642+
case 0x20 ... 0x5f:
643+
setup_force_cpu_cap(X86_FEATURE_ZEN3);
644+
break;
645+
case 0x10 ... 0x1f:
646+
case 0x60 ... 0xaf:
647+
setup_force_cpu_cap(X86_FEATURE_ZEN4);
648+
break;
649+
default:
650+
goto warn;
651+
}
652+
break;
653+
}
654+
default:
655+
break;
656+
}
657+
658+
return;
659+
660+
warn:
661+
WARN_ONCE(1, "Family 0x%x, model: 0x%x??\n", c->x86, c->x86_model);
619662
}
620663

621664
static void early_detect_mem_encrypt(struct cpuinfo_x86 *c)
@@ -974,8 +1017,6 @@ void init_spectral_chicken(struct cpuinfo_x86 *c)
9741017

9751018
static void init_amd_zn(struct cpuinfo_x86 *c)
9761019
{
977-
set_cpu_cap(c, X86_FEATURE_ZEN);
978-
9791020
#ifdef CONFIG_NUMA
9801021
node_reclaim_distance = 32;
9811022
#endif
@@ -1037,6 +1078,22 @@ static void zenbleed_check(struct cpuinfo_x86 *c)
10371078
}
10381079
}
10391080

1081+
static void init_amd_zen(struct cpuinfo_x86 *c)
1082+
{
1083+
}
1084+
1085+
static void init_amd_zen2(struct cpuinfo_x86 *c)
1086+
{
1087+
}
1088+
1089+
static void init_amd_zen3(struct cpuinfo_x86 *c)
1090+
{
1091+
}
1092+
1093+
static void init_amd_zen4(struct cpuinfo_x86 *c)
1094+
{
1095+
}
1096+
10401097
static void init_amd(struct cpuinfo_x86 *c)
10411098
{
10421099
u64 vm_cr;
@@ -1077,6 +1134,15 @@ static void init_amd(struct cpuinfo_x86 *c)
10771134
case 0x19: init_amd_zn(c); break;
10781135
}
10791136

1137+
if (boot_cpu_has(X86_FEATURE_ZEN))
1138+
init_amd_zen(c);
1139+
else if (boot_cpu_has(X86_FEATURE_ZEN2))
1140+
init_amd_zen2(c);
1141+
else if (boot_cpu_has(X86_FEATURE_ZEN3))
1142+
init_amd_zen3(c);
1143+
else if (boot_cpu_has(X86_FEATURE_ZEN4))
1144+
init_amd_zen4(c);
1145+
10801146
/*
10811147
* Enable workaround for FXSAVE leak on CPUs
10821148
* without a XSaveErPtr feature

0 commit comments

Comments
 (0)