Skip to content

Commit 5da5614

Browse files
bp3tk0vgregkh
authored andcommitted
x86/CPU/AMD: Add ZenX generations flags
Commit 30fa928 upstream. 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) <bp@alien8.de> Reviewed-by: Nikolay Borisov <nik.borisov@suse.com> Acked-by: Thomas Gleixner <tglx@linutronix.de> Link: http://lore.kernel.org/r/20231120104152.13740-2-bp@alien8.de Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 15b828a commit 5da5614

2 files changed

Lines changed: 72 additions & 3 deletions

File tree

arch/x86/include/asm/cpufeatures.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@
219219
#define X86_FEATURE_IBRS ( 7*32+25) /* Indirect Branch Restricted Speculation */
220220
#define X86_FEATURE_IBPB ( 7*32+26) /* "ibpb" Indirect Branch Prediction Barrier without a guaranteed RSB flush */
221221
#define X86_FEATURE_STIBP ( 7*32+27) /* Single Thread Indirect Branch Predictors */
222-
#define X86_FEATURE_ZEN ( 7*32+28) /* "" CPU is AMD family 0x17 or above (Zen) */
222+
#define X86_FEATURE_ZEN ( 7*32+28) /* "" CPU based on Zen microarchitecture */
223223
#define X86_FEATURE_L1TF_PTEINV ( 7*32+29) /* "" L1TF workaround PTE inversion */
224224
#define X86_FEATURE_IBRS_ENHANCED ( 7*32+30) /* Enhanced IBRS */
225225
#define X86_FEATURE_MSR_IA32_FEAT_CTL ( 7*32+31) /* "" MSR IA32_FEAT_CTL configured */
@@ -310,6 +310,9 @@
310310
#define X86_FEATURE_SRSO_ALIAS (11*32+25) /* "" AMD BTB untrain RETs through aliasing */
311311
#define X86_FEATURE_IBPB_ON_VMEXIT (11*32+26) /* "" Issue an IBPB only on VMEXIT */
312312
#define X86_FEATURE_APIC_MSRS_FENCE (11*32+27) /* "" IA32_TSC_DEADLINE and X2APIC MSRs need fencing */
313+
#define X86_FEATURE_ZEN2 (11*32+28) /* "" CPU based on Zen2 microarchitecture */
314+
#define X86_FEATURE_ZEN3 (11*32+29) /* "" CPU based on Zen3 microarchitecture */
315+
#define X86_FEATURE_ZEN4 (11*32+30) /* "" CPU based on Zen4 microarchitecture */
313316

314317
/* Intel-defined CPU features, CPUID level 0x00000007:1 (EAX), word 12 */
315318
#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
@@ -708,7 +708,50 @@ static void bsp_init_amd(struct cpuinfo_x86 *c)
708708

709709
resctrl_cpu_detect(c);
710710

711+
/* Figure out Zen generations: */
712+
switch (c->x86) {
713+
case 0x17: {
714+
switch (c->x86_model) {
715+
case 0x00 ... 0x2f:
716+
case 0x50 ... 0x5f:
717+
setup_force_cpu_cap(X86_FEATURE_ZEN);
718+
break;
719+
case 0x30 ... 0x4f:
720+
case 0x60 ... 0x7f:
721+
case 0x90 ... 0x91:
722+
case 0xa0 ... 0xaf:
723+
setup_force_cpu_cap(X86_FEATURE_ZEN2);
724+
break;
725+
default:
726+
goto warn;
727+
}
728+
break;
729+
}
730+
case 0x19: {
731+
switch (c->x86_model) {
732+
case 0x00 ... 0x0f:
733+
case 0x20 ... 0x5f:
734+
setup_force_cpu_cap(X86_FEATURE_ZEN3);
735+
break;
736+
case 0x10 ... 0x1f:
737+
case 0x60 ... 0xaf:
738+
setup_force_cpu_cap(X86_FEATURE_ZEN4);
739+
break;
740+
default:
741+
goto warn;
742+
}
743+
break;
744+
}
745+
default:
746+
break;
747+
}
748+
711749
tsa_init(c);
750+
751+
return;
752+
753+
warn:
754+
WARN_ONCE(1, "Family 0x%x, model: 0x%x??\n", c->x86, c->x86_model);
712755
}
713756

714757
static void early_detect_mem_encrypt(struct cpuinfo_x86 *c)
@@ -1054,8 +1097,6 @@ void init_spectral_chicken(struct cpuinfo_x86 *c)
10541097

10551098
static void init_amd_zn(struct cpuinfo_x86 *c)
10561099
{
1057-
set_cpu_cap(c, X86_FEATURE_ZEN);
1058-
10591100
#ifdef CONFIG_NUMA
10601101
node_reclaim_distance = 32;
10611102
#endif
@@ -1121,6 +1162,22 @@ static void zenbleed_check(struct cpuinfo_x86 *c)
11211162
}
11221163
}
11231164

1165+
static void init_amd_zen(struct cpuinfo_x86 *c)
1166+
{
1167+
}
1168+
1169+
static void init_amd_zen2(struct cpuinfo_x86 *c)
1170+
{
1171+
}
1172+
1173+
static void init_amd_zen3(struct cpuinfo_x86 *c)
1174+
{
1175+
}
1176+
1177+
static void init_amd_zen4(struct cpuinfo_x86 *c)
1178+
{
1179+
}
1180+
11241181
static void init_amd(struct cpuinfo_x86 *c)
11251182
{
11261183
early_init_amd(c);
@@ -1155,6 +1212,15 @@ static void init_amd(struct cpuinfo_x86 *c)
11551212
case 0x19: init_amd_zn(c); break;
11561213
}
11571214

1215+
if (boot_cpu_has(X86_FEATURE_ZEN))
1216+
init_amd_zen(c);
1217+
else if (boot_cpu_has(X86_FEATURE_ZEN2))
1218+
init_amd_zen2(c);
1219+
else if (boot_cpu_has(X86_FEATURE_ZEN3))
1220+
init_amd_zen3(c);
1221+
else if (boot_cpu_has(X86_FEATURE_ZEN4))
1222+
init_amd_zen4(c);
1223+
11581224
/*
11591225
* Enable workaround for FXSAVE leak on CPUs
11601226
* without a XSaveErPtr feature

0 commit comments

Comments
 (0)