Skip to content

Commit 9bf7334

Browse files
sandip4njfvogel
authored andcommitted
x86/cpu/amd: Fix workaround for erratum 1054
commit 263e55949d8902a6a09bdb92a1ab6a3f67231abe upstream. 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 Signed-off-by: Greg Kroah-Hartman <[email protected]> (cherry picked from commit 519718a3384a5826da4472b95f5a04cbf8c4cea0) Signed-off-by: Jack Vogel <[email protected]>
1 parent 280459c commit 9bf7334

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
@@ -871,6 +871,16 @@ static void init_amd_zen1(struct cpuinfo_x86 *c)
871871

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

876886
static bool cpu_has_zenbleed_microcode(void)
@@ -1066,13 +1076,8 @@ static void init_amd(struct cpuinfo_x86 *c)
10661076
if (!cpu_feature_enabled(X86_FEATURE_XENPV))
10671077
set_cpu_bug(c, X86_BUG_SYSRET_SS_ATTRS);
10681078

1069-
/*
1070-
* Turn on the Instructions Retired free counter on machines not
1071-
* susceptible to erratum #1054 "Instructions Retired Performance
1072-
* Counter May Be Inaccurate".
1073-
*/
1074-
if (cpu_has(c, X86_FEATURE_IRPERF) &&
1075-
(boot_cpu_has(X86_FEATURE_ZEN1) && c->x86_model > 0x2f))
1079+
/* Enable the Instructions Retired free counter */
1080+
if (cpu_has(c, X86_FEATURE_IRPERF))
10761081
msr_set_bit(MSR_K7_HWCR, MSR_K7_HWCR_IRPERF_EN_BIT);
10771082

10781083
check_null_seg_clears_base(c);

0 commit comments

Comments
 (0)