Skip to content

Commit c4994f1

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 4709234 commit c4994f1

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 based on Zen microarchitecture */
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 */
@@ -313,6 +313,9 @@
313313
#define X86_FEATURE_SRSO_ALIAS (11*32+25) /* "" AMD BTB untrain RETs through aliasing */
314314
#define X86_FEATURE_IBPB_ON_VMEXIT (11*32+26) /* "" Issue an IBPB only on VMEXIT */
315315
#define X86_FEATURE_APIC_MSRS_FENCE (11*32+27) /* "" IA32_TSC_DEADLINE and X2APIC MSRs need fencing */
316+
#define X86_FEATURE_ZEN2 (11*32+28) /* "" CPU based on Zen2 microarchitecture */
317+
#define X86_FEATURE_ZEN3 (11*32+29) /* "" CPU based on Zen3 microarchitecture */
318+
#define X86_FEATURE_ZEN4 (11*32+30) /* "" CPU based on Zen4 microarchitecture */
316319

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

680680
resctrl_cpu_detect(c);
681681

682+
/* Figure out Zen generations: */
683+
switch (c->x86) {
684+
case 0x17: {
685+
switch (c->x86_model) {
686+
case 0x00 ... 0x2f:
687+
case 0x50 ... 0x5f:
688+
setup_force_cpu_cap(X86_FEATURE_ZEN);
689+
break;
690+
case 0x30 ... 0x4f:
691+
case 0x60 ... 0x7f:
692+
case 0x90 ... 0x91:
693+
case 0xa0 ... 0xaf:
694+
setup_force_cpu_cap(X86_FEATURE_ZEN2);
695+
break;
696+
default:
697+
goto warn;
698+
}
699+
break;
700+
}
701+
case 0x19: {
702+
switch (c->x86_model) {
703+
case 0x00 ... 0x0f:
704+
case 0x20 ... 0x5f:
705+
setup_force_cpu_cap(X86_FEATURE_ZEN3);
706+
break;
707+
case 0x10 ... 0x1f:
708+
case 0x60 ... 0xaf:
709+
setup_force_cpu_cap(X86_FEATURE_ZEN4);
710+
break;
711+
default:
712+
goto warn;
713+
}
714+
break;
715+
}
716+
default:
717+
break;
718+
}
719+
682720
tsa_init(c);
721+
722+
return;
723+
724+
warn:
725+
WARN_ONCE(1, "Family 0x%x, model: 0x%x??\n", c->x86, c->x86_model);
683726
}
684727

685728
static void early_detect_mem_encrypt(struct cpuinfo_x86 *c)
@@ -1030,8 +1073,6 @@ void init_spectral_chicken(struct cpuinfo_x86 *c)
10301073

10311074
static void init_amd_zn(struct cpuinfo_x86 *c)
10321075
{
1033-
set_cpu_cap(c, X86_FEATURE_ZEN);
1034-
10351076
#ifdef CONFIG_NUMA
10361077
node_reclaim_distance = 32;
10371078
#endif
@@ -1097,6 +1138,22 @@ static void zenbleed_check(struct cpuinfo_x86 *c)
10971138
}
10981139
}
10991140

1141+
static void init_amd_zen(struct cpuinfo_x86 *c)
1142+
{
1143+
}
1144+
1145+
static void init_amd_zen2(struct cpuinfo_x86 *c)
1146+
{
1147+
}
1148+
1149+
static void init_amd_zen3(struct cpuinfo_x86 *c)
1150+
{
1151+
}
1152+
1153+
static void init_amd_zen4(struct cpuinfo_x86 *c)
1154+
{
1155+
}
1156+
11001157
static void init_amd(struct cpuinfo_x86 *c)
11011158
{
11021159
early_init_amd(c);
@@ -1131,6 +1188,15 @@ static void init_amd(struct cpuinfo_x86 *c)
11311188
case 0x19: init_amd_zn(c); break;
11321189
}
11331190

1191+
if (boot_cpu_has(X86_FEATURE_ZEN))
1192+
init_amd_zen(c);
1193+
else if (boot_cpu_has(X86_FEATURE_ZEN2))
1194+
init_amd_zen2(c);
1195+
else if (boot_cpu_has(X86_FEATURE_ZEN3))
1196+
init_amd_zen3(c);
1197+
else if (boot_cpu_has(X86_FEATURE_ZEN4))
1198+
init_amd_zen4(c);
1199+
11341200
/*
11351201
* Enable workaround for FXSAVE leak on CPUs
11361202
* without a XSaveErPtr feature

0 commit comments

Comments
 (0)