Skip to content

Commit 263e559

Browse files
sandip4nIngo Molnar
authored and
Ingo Molnar
committed
x86/cpu/amd: Fix workaround for erratum 1054
Erratum 1054 affects AMD Zen processors that are a part of Family 17h Models 00-2Fh and the workaround is to not set HWCR[IRPerfEn]. However, when X86_FEATURE_ZEN1 was introduced, the condition to detect unaffected processors was incorrectly changed in a way that the IRPerfEn bit gets set only for unaffected Zen 1 processors. Ensure that HWCR[IRPerfEn] is set for all unaffected processors. This includes a subset of Zen 1 (Family 17h Models 30h and above) and all later processors. Also clear X86_FEATURE_IRPERF on affected processors so that the IRPerfCount register is not used by other entities like the MSR PMU driver. Fixes: 232afb5 ("x86/CPU/AMD: Add X86_FEATURE_ZEN1") Signed-off-by: Sandipan Das <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Acked-by: Borislav Petkov <[email protected]> Cc: [email protected] Link: https://lore.kernel.org/r/caa057a9d6f8ad579e2f1abaa71efbd5bd4eaf6d.1744956467.git.sandipan.das@amd.com
1 parent d466304 commit 263e559

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

arch/x86/kernel/cpu/amd.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -869,6 +869,16 @@ static void init_amd_zen1(struct cpuinfo_x86 *c)
869869

870870
pr_notice_once("AMD Zen1 DIV0 bug detected. Disable SMT for full protection.\n");
871871
setup_force_cpu_bug(X86_BUG_DIV0);
872+
873+
/*
874+
* Turn off the Instructions Retired free counter on machines that are
875+
* susceptible to erratum #1054 "Instructions Retired Performance
876+
* Counter May Be Inaccurate".
877+
*/
878+
if (c->x86_model < 0x30) {
879+
msr_clear_bit(MSR_K7_HWCR, MSR_K7_HWCR_IRPERF_EN_BIT);
880+
clear_cpu_cap(c, X86_FEATURE_IRPERF);
881+
}
872882
}
873883

874884
static bool cpu_has_zenbleed_microcode(void)
@@ -1052,13 +1062,8 @@ static void init_amd(struct cpuinfo_x86 *c)
10521062
if (!cpu_feature_enabled(X86_FEATURE_XENPV))
10531063
set_cpu_bug(c, X86_BUG_SYSRET_SS_ATTRS);
10541064

1055-
/*
1056-
* Turn on the Instructions Retired free counter on machines not
1057-
* susceptible to erratum #1054 "Instructions Retired Performance
1058-
* Counter May Be Inaccurate".
1059-
*/
1060-
if (cpu_has(c, X86_FEATURE_IRPERF) &&
1061-
(boot_cpu_has(X86_FEATURE_ZEN1) && c->x86_model > 0x2f))
1065+
/* Enable the Instructions Retired free counter */
1066+
if (cpu_has(c, X86_FEATURE_IRPERF))
10621067
msr_set_bit(MSR_K7_HWCR, MSR_K7_HWCR_IRPERF_EN_BIT);
10631068

10641069
check_null_seg_clears_base(c);

0 commit comments

Comments
 (0)