arch/x86/kernel/cpu/amd.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-)
The following commit has been merged into the x86/urgent branch of tip:
Commit-ID: f4efdb357680bef4584faedbd44b90cd53d3245f
Gitweb: https://git.kernel.org/tip/f4efdb357680bef4584faedbd44b90cd53d3245f
Author: Sandipan Das <sandipan.das@amd.com>
AuthorDate: Fri, 18 Apr 2025 11:49:40 +05:30
Committer: Ingo Molnar <mingo@kernel.org>
CommitterDate: Fri, 18 Apr 2025 08:31:07 +02:00
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: 232afb557835 ("x86/CPU/AMD: Add X86_FEATURE_ZEN1")
Signed-off-by: Sandipan Das <sandipan.das@amd.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Link: https://lore.kernel.org/r/caa057a9d6f8ad579e2f1abaa71efbd5bd4eaf6d.1744956467.git.sandipan.das@amd.com
---
arch/x86/kernel/cpu/amd.c | 19 ++++++++++++-------
1 file changed, 12 insertions(+), 7 deletions(-)
diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
index a839ff5..2b36379 100644
--- a/arch/x86/kernel/cpu/amd.c
+++ b/arch/x86/kernel/cpu/amd.c
@@ -869,6 +869,16 @@ static void init_amd_zen1(struct cpuinfo_x86 *c)
pr_notice_once("AMD Zen1 DIV0 bug detected. Disable SMT for full protection.\n");
setup_force_cpu_bug(X86_BUG_DIV0);
+
+ /*
+ * Turn off the Instructions Retired free counter on machines that are
+ * susceptible to erratum #1054 "Instructions Retired Performance
+ * Counter May Be Inaccurate".
+ */
+ if (c->x86_model < 0x30) {
+ msr_clear_bit(MSR_K7_HWCR, MSR_K7_HWCR_IRPERF_EN_BIT);
+ clear_cpu_cap(c, X86_FEATURE_IRPERF);
+ }
}
static bool cpu_has_zenbleed_microcode(void)
@@ -1052,13 +1062,8 @@ static void init_amd(struct cpuinfo_x86 *c)
if (!cpu_feature_enabled(X86_FEATURE_XENPV))
set_cpu_bug(c, X86_BUG_SYSRET_SS_ATTRS);
- /*
- * Turn on the Instructions Retired free counter on machines not
- * susceptible to erratum #1054 "Instructions Retired Performance
- * Counter May Be Inaccurate".
- */
- if (cpu_has(c, X86_FEATURE_IRPERF) &&
- (boot_cpu_has(X86_FEATURE_ZEN1) && c->x86_model > 0x2f))
+ /* Enable the Instructions Retired free counter */
+ if (cpu_has(c, X86_FEATURE_IRPERF))
msr_set_bit(MSR_K7_HWCR, MSR_K7_HWCR_IRPERF_EN_BIT);
check_null_seg_clears_base(c);
On Fri, Apr 18, 2025 at 06:36:19AM -0000, tip-bot2 for Sandipan Das wrote:
> The following commit has been merged into the x86/urgent branch of tip:
>
> Commit-ID: f4efdb357680bef4584faedbd44b90cd53d3245f
> Gitweb: https://git.kernel.org/tip/f4efdb357680bef4584faedbd44b90cd53d3245f
> Author: Sandipan Das <sandipan.das@amd.com>
> AuthorDate: Fri, 18 Apr 2025 11:49:40 +05:30
> Committer: Ingo Molnar <mingo@kernel.org>
> CommitterDate: Fri, 18 Apr 2025 08:31:07 +02:00
>
> 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.
Whoops, sorry about that.
> Fixes: 232afb557835 ("x86/CPU/AMD: Add X86_FEATURE_ZEN1")
> Signed-off-by: Sandipan Das <sandipan.das@amd.com>
> Signed-off-by: Ingo Molnar <mingo@kernel.org>
> Link: https://lore.kernel.org/r/caa057a9d6f8ad579e2f1abaa71efbd5bd4eaf6d.1744956467.git.sandipan.das@amd.com
This needs
Cc: <stable@kernel.org>
Thx.
* Borislav Petkov <bp@alien8.de> wrote:
> > Fixes: 232afb557835 ("x86/CPU/AMD: Add X86_FEATURE_ZEN1")
> > Signed-off-by: Sandipan Das <sandipan.das@amd.com>
> > Signed-off-by: Ingo Molnar <mingo@kernel.org>
> > Link: https://lore.kernel.org/r/caa057a9d6f8ad579e2f1abaa71efbd5bd4eaf6d.1744956467.git.sandipan.das@amd.com
>
> This needs
>
> Cc: <stable@kernel.org>
No, it doesn't really 'need' a stable tag, it has a Fixes tag already,
which gets processed by the -stable team.
Also, the bug is old, 1.5 years old:
Date: Sat, 2 Dec 2023 12:50:23 +0100
plus the erratum is a perf-counters information quality bug affecting
what appears to be a limited number of models, with the workaround
likely incorporated in BIOS updates as well. Leave it up to the -stable
team whether they think it's severe enough to backport it?
Thanks,
Ingo
On Fri, Apr 18, 2025 at 02:11:44PM +0200, Ingo Molnar wrote:
> No, it doesn't really 'need' a stable tag, it has a Fixes tag already,
> which gets processed by the -stable team.
Last time I asked Greg, he said they scan for those tags but it doesn't hurt
to Cc stable as it helps.
Greg?
> Also, the bug is old, 1.5 years old:
>
> Date: Sat, 2 Dec 2023 12:50:23 +0100
>
> plus the erratum is a perf-counters information quality bug affecting
> what appears to be a limited number of models, with the workaround
No, the fix is needed because Zen2 and newer won't set
MSR_K7_HWCR_IRPERF_EN_BIT. It needs to go everywhere.
> likely incorporated in BIOS updates as well.
You can very much forget that argument. I have hard BIOS adoption data which
paints an abysmal picture. So NEVER EVER rely on BIOS to do anything.
Especially for Zen1 which is oooold in BIOS time.
> Leave it up to the -stable team whether they think it's severe enough to
> backport it?
No, they leave it to us section maintainers to decide AFAIK.
Thx.
--
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquette
On Fri, Apr 18, 2025 at 02:37:13PM +0200, Borislav Petkov wrote: > On Fri, Apr 18, 2025 at 02:11:44PM +0200, Ingo Molnar wrote: > > No, it doesn't really 'need' a stable tag, it has a Fixes tag already, > > which gets processed by the -stable team. NOOOOOO!!!! > Last time I asked Greg, he said they scan for those tags but it doesn't hurt > to Cc stable as it helps. > > Greg? Fixes: is a "best effort if we get around to it because a maintainer forgot to put an actual cc: stable tag on it". As the documentation has stated, since the start of the stable kernel tree work, use a cc: stable tag if you want it to go to a stable tree. Fixes came years later and we are forced to dig through them occasionally because people forget. But you do NOT get a FAILED email if the commit does not apply to a stable tree, and sometimes we just ignore them entirely if we are busy with other stuff. So please ALWAYS use cc: stable@ on patches you know you want to be applied to stable trees. Use the Fixes: tag to tell us how far back to backport them. That's it. Use both. thanks, greg k-h
* Greg KH <gregkh@linuxfoundation.org> wrote: > On Fri, Apr 18, 2025 at 02:37:13PM +0200, Borislav Petkov wrote: > > On Fri, Apr 18, 2025 at 02:11:44PM +0200, Ingo Molnar wrote: > > > No, it doesn't really 'need' a stable tag, it has a Fixes tag already, > > > which gets processed by the -stable team. > > NOOOOOO!!!! Noted!! :-) > So please ALWAYS use cc: stable@ on patches you know you want to be > applied to stable trees. Use the Fixes: tag to tell us how far back > to backport them. That's it. Use both. Undertood! Thanks, Ingo
* Borislav Petkov <bp@alien8.de> wrote:
> > plus the erratum is a perf-counters information quality bug
> > affecting what appears to be a limited number of models, with the
> > workaround
>
> No, the fix is needed because Zen2 and newer won't set
> MSR_K7_HWCR_IRPERF_EN_BIT. It needs to go everywhere.
Fair enough - the current version already has Cc: stable:
263e55949d89 x86/cpu/amd: Fix workaround for erratum 1054
...
Fixes: 232afb557835 ("x86/CPU/AMD: Add X86_FEATURE_ZEN1")
Signed-off-by: Sandipan Das <sandipan.das@amd.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Acked-by: Borislav Petkov <bp@alien8.de>
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/r/caa057a9d6f8ad579e2f1abaa71efbd5bd4eaf6d.1744956467.git.sandipan.das@amd.com
Thanks,
Ingo
* Ingo Molnar <mingo@kernel.org> wrote:
>
> * Borislav Petkov <bp@alien8.de> wrote:
>
> > > Fixes: 232afb557835 ("x86/CPU/AMD: Add X86_FEATURE_ZEN1")
> > > Signed-off-by: Sandipan Das <sandipan.das@amd.com>
> > > Signed-off-by: Ingo Molnar <mingo@kernel.org>
> > > Link: https://lore.kernel.org/r/caa057a9d6f8ad579e2f1abaa71efbd5bd4eaf6d.1744956467.git.sandipan.das@amd.com
> >
> > This needs
> >
> > Cc: <stable@kernel.org>
>
> No, it doesn't really 'need' a stable tag, it has a Fixes tag already,
> which gets processed by the -stable team.
Anyway, I agree with you that it cannot hurt to have a Cc: stable,
so I've added the tag along with your Acked-by, thanks Boris!
Ingo
© 2016 - 2025 Red Hat, Inc.