Skip to content

Commit bd2adc9

Browse files
committed
Merge: x86/cpu/amd: Fix workaround for erratum 1054
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/7078 JIRA: https://issues.redhat.com/browse/RHEL-98688 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. Signed-off-by: Michael Petlan <mpetlan@redhat.com> Approved-by: David Arcari <darcari@redhat.com> Approved-by: Lenny Szubowicz <lszubowi@redhat.com> Approved-by: CKI KWF Bot <cki-ci-bot+kwf-gitlab-com@redhat.com> Merged-by: Augusto Caringi <acaringi@redhat.com>
2 parents 7b2e808 + 07cde8b commit bd2adc9

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

851851
pr_notice_once("AMD Zen1 DIV0 bug detected. Disable SMT for full protection.\n");
852852
setup_force_cpu_bug(X86_BUG_DIV0);
853+
854+
/*
855+
* Turn off the Instructions Retired free counter on machines that are
856+
* susceptible to erratum #1054 "Instructions Retired Performance
857+
* Counter May Be Inaccurate".
858+
*/
859+
if (c->x86_model < 0x30) {
860+
msr_clear_bit(MSR_K7_HWCR, MSR_K7_HWCR_IRPERF_EN_BIT);
861+
clear_cpu_cap(c, X86_FEATURE_IRPERF);
862+
}
853863
}
854864

855865
static bool cpu_has_zenbleed_microcode(void)
@@ -1033,13 +1043,8 @@ static void init_amd(struct cpuinfo_x86 *c)
10331043
if (!cpu_feature_enabled(X86_FEATURE_XENPV))
10341044
set_cpu_bug(c, X86_BUG_SYSRET_SS_ATTRS);
10351045

1036-
/*
1037-
* Turn on the Instructions Retired free counter on machines not
1038-
* susceptible to erratum #1054 "Instructions Retired Performance
1039-
* Counter May Be Inaccurate".
1040-
*/
1041-
if (cpu_has(c, X86_FEATURE_IRPERF) &&
1042-
(boot_cpu_has(X86_FEATURE_ZEN1) && c->x86_model > 0x2f))
1046+
/* Enable the Instructions Retired free counter */
1047+
if (cpu_has(c, X86_FEATURE_IRPERF))
10431048
msr_set_bit(MSR_K7_HWCR, MSR_K7_HWCR_IRPERF_EN_BIT);
10441049

10451050
check_null_seg_clears_base(c);

0 commit comments

Comments
 (0)