* [PATCH] x86/CPU/AMD: Simplify the spectral chicken fix
@ 2025-12-30 11:07 Borislav Petkov
2026-01-05 13:20 ` Nikolay Borisov
2026-01-09 11:59 ` [tip: x86/cleanups] " tip-bot2 for Borislav Petkov (AMD)
0 siblings, 2 replies; 3+ messages in thread
From: Borislav Petkov @ 2025-12-30 11:07 UTC (permalink / raw)
To: X86 ML; +Cc: LKML, Borislav Petkov (AMD)
From: "Borislav Petkov (AMD)" <bp@alien8.de>
msr_set_bit() takes a bit number to set but MSR_ZEN2_SPECTRAL_CHICKEN_BIT
is a bit mask. The usual pattern that code uses is a _BIT-named type
macro instead of a mask.
So convert it to a bit number to reflect that.
Also, msr_set_bit() already does the reading and checking whether the
bit needs to be set so use that instead of a local variable.
Fixup tabbing while at it.
No functional changes.
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
---
arch/x86/include/asm/msr-index.h | 4 ++--
arch/x86/kernel/cpu/amd.c | 10 ++--------
tools/arch/x86/include/asm/msr-index.h | 4 ++--
3 files changed, 6 insertions(+), 12 deletions(-)
diff --git a/arch/x86/include/asm/msr-index.h b/arch/x86/include/asm/msr-index.h
index 3d0a0950d20a..43adc38d31d5 100644
--- a/arch/x86/include/asm/msr-index.h
+++ b/arch/x86/include/asm/msr-index.h
@@ -794,8 +794,8 @@
#define MSR_F19H_UMC_PERF_CTR 0xc0010801
/* Zen 2 */
-#define MSR_ZEN2_SPECTRAL_CHICKEN 0xc00110e3
-#define MSR_ZEN2_SPECTRAL_CHICKEN_BIT BIT_ULL(1)
+#define MSR_ZEN2_SPECTRAL_CHICKEN 0xc00110e3
+#define MSR_ZEN2_SPECTRAL_CHICKEN_BIT 1
/* Fam 17h MSRs */
#define MSR_F17H_IRPERF 0xc00000e9
diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
index c792c2afd849..09de584e4c8f 100644
--- a/arch/x86/kernel/cpu/amd.c
+++ b/arch/x86/kernel/cpu/amd.c
@@ -900,20 +900,14 @@ static void fix_erratum_1386(struct cpuinfo_x86 *c)
void init_spectral_chicken(struct cpuinfo_x86 *c)
{
#ifdef CONFIG_MITIGATION_UNRET_ENTRY
- u64 value;
-
/*
* On Zen2 we offer this chicken (bit) on the altar of Speculation.
*
* This suppresses speculation from the middle of a basic block, i.e. it
* suppresses non-branch predictions.
*/
- if (!cpu_has(c, X86_FEATURE_HYPERVISOR)) {
- if (!rdmsrq_safe(MSR_ZEN2_SPECTRAL_CHICKEN, &value)) {
- value |= MSR_ZEN2_SPECTRAL_CHICKEN_BIT;
- wrmsrq_safe(MSR_ZEN2_SPECTRAL_CHICKEN, value);
- }
- }
+ if (!cpu_has(c, X86_FEATURE_HYPERVISOR))
+ msr_set_bit(MSR_ZEN2_SPECTRAL_CHICKEN, MSR_ZEN2_SPECTRAL_CHICKEN_BIT);
#endif
}
diff --git a/tools/arch/x86/include/asm/msr-index.h b/tools/arch/x86/include/asm/msr-index.h
index 9e1720d73244..d4137a302793 100644
--- a/tools/arch/x86/include/asm/msr-index.h
+++ b/tools/arch/x86/include/asm/msr-index.h
@@ -770,8 +770,8 @@
#define MSR_F19H_UMC_PERF_CTR 0xc0010801
/* Zen 2 */
-#define MSR_ZEN2_SPECTRAL_CHICKEN 0xc00110e3
-#define MSR_ZEN2_SPECTRAL_CHICKEN_BIT BIT_ULL(1)
+#define MSR_ZEN2_SPECTRAL_CHICKEN 0xc00110e3
+#define MSR_ZEN2_SPECTRAL_CHICKEN_BIT 1
/* Fam 17h MSRs */
#define MSR_F17H_IRPERF 0xc00000e9
--
2.51.0
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] x86/CPU/AMD: Simplify the spectral chicken fix
2025-12-30 11:07 [PATCH] x86/CPU/AMD: Simplify the spectral chicken fix Borislav Petkov
@ 2026-01-05 13:20 ` Nikolay Borisov
2026-01-09 11:59 ` [tip: x86/cleanups] " tip-bot2 for Borislav Petkov (AMD)
1 sibling, 0 replies; 3+ messages in thread
From: Nikolay Borisov @ 2026-01-05 13:20 UTC (permalink / raw)
To: Borislav Petkov, X86 ML; +Cc: LKML, Borislav Petkov (AMD)
On 30.12.25 г. 13:07 ч., Borislav Petkov wrote:
> From: "Borislav Petkov (AMD)" <bp@alien8.de>
>
> msr_set_bit() takes a bit number to set but MSR_ZEN2_SPECTRAL_CHICKEN_BIT
> is a bit mask. The usual pattern that code uses is a _BIT-named type
> macro instead of a mask.
>
> So convert it to a bit number to reflect that.
>
> Also, msr_set_bit() already does the reading and checking whether the
> bit needs to be set so use that instead of a local variable.
>
> Fixup tabbing while at it.
>
> No functional changes.
>
> Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Reviewed-by: Nikolay Borisov <nik.borisov@suse.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* [tip: x86/cleanups] x86/CPU/AMD: Simplify the spectral chicken fix
2025-12-30 11:07 [PATCH] x86/CPU/AMD: Simplify the spectral chicken fix Borislav Petkov
2026-01-05 13:20 ` Nikolay Borisov
@ 2026-01-09 11:59 ` tip-bot2 for Borislav Petkov (AMD)
1 sibling, 0 replies; 3+ messages in thread
From: tip-bot2 for Borislav Petkov (AMD) @ 2026-01-09 11:59 UTC (permalink / raw)
To: linux-tip-commits
Cc: Borislav Petkov (AMD), Nikolay Borisov, x86, linux-kernel
The following commit has been merged into the x86/cleanups branch of tip:
Commit-ID: 736a2dcfdae72483a36793bc92182f33bd61d30e
Gitweb: https://git.kernel.org/tip/736a2dcfdae72483a36793bc92182f33bd61d30e
Author: Borislav Petkov (AMD) <bp@alien8.de>
AuthorDate: Tue, 30 Dec 2025 12:07:31 +01:00
Committer: Borislav Petkov (AMD) <bp@alien8.de>
CommitterDate: Fri, 09 Jan 2026 11:36:52 +01:00
x86/CPU/AMD: Simplify the spectral chicken fix
msr_set_bit() takes a bit number to set but MSR_ZEN2_SPECTRAL_CHICKEN_BIT
is a bit mask. The usual pattern that code uses is a _BIT-named type
macro instead of a mask.
So convert it to a bit number to reflect that.
Also, msr_set_bit() already does the reading and checking whether the
bit needs to be set so use that instead of a local variable.
Fixup tabbing while at it.
No functional changes.
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Reviewed-by: Nikolay Borisov <nik.borisov@suse.com>
Link: https://patch.msgid.link/20251230110731.28108-1-bp@kernel.org
---
arch/x86/include/asm/msr-index.h | 4 ++--
arch/x86/kernel/cpu/amd.c | 10 ++--------
tools/arch/x86/include/asm/msr-index.h | 4 ++--
3 files changed, 6 insertions(+), 12 deletions(-)
diff --git a/arch/x86/include/asm/msr-index.h b/arch/x86/include/asm/msr-index.h
index 3d0a095..43adc38 100644
--- a/arch/x86/include/asm/msr-index.h
+++ b/arch/x86/include/asm/msr-index.h
@@ -794,8 +794,8 @@
#define MSR_F19H_UMC_PERF_CTR 0xc0010801
/* Zen 2 */
-#define MSR_ZEN2_SPECTRAL_CHICKEN 0xc00110e3
-#define MSR_ZEN2_SPECTRAL_CHICKEN_BIT BIT_ULL(1)
+#define MSR_ZEN2_SPECTRAL_CHICKEN 0xc00110e3
+#define MSR_ZEN2_SPECTRAL_CHICKEN_BIT 1
/* Fam 17h MSRs */
#define MSR_F17H_IRPERF 0xc00000e9
diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
index bc94ff1..ab9158c 100644
--- a/arch/x86/kernel/cpu/amd.c
+++ b/arch/x86/kernel/cpu/amd.c
@@ -900,20 +900,14 @@ static void fix_erratum_1386(struct cpuinfo_x86 *c)
void init_spectral_chicken(struct cpuinfo_x86 *c)
{
#ifdef CONFIG_MITIGATION_UNRET_ENTRY
- u64 value;
-
/*
* On Zen2 we offer this chicken (bit) on the altar of Speculation.
*
* This suppresses speculation from the middle of a basic block, i.e. it
* suppresses non-branch predictions.
*/
- if (!cpu_has(c, X86_FEATURE_HYPERVISOR)) {
- if (!rdmsrq_safe(MSR_ZEN2_SPECTRAL_CHICKEN, &value)) {
- value |= MSR_ZEN2_SPECTRAL_CHICKEN_BIT;
- wrmsrq_safe(MSR_ZEN2_SPECTRAL_CHICKEN, value);
- }
- }
+ if (!cpu_has(c, X86_FEATURE_HYPERVISOR))
+ msr_set_bit(MSR_ZEN2_SPECTRAL_CHICKEN, MSR_ZEN2_SPECTRAL_CHICKEN_BIT);
#endif
}
diff --git a/tools/arch/x86/include/asm/msr-index.h b/tools/arch/x86/include/asm/msr-index.h
index 9e1720d..d4137a3 100644
--- a/tools/arch/x86/include/asm/msr-index.h
+++ b/tools/arch/x86/include/asm/msr-index.h
@@ -770,8 +770,8 @@
#define MSR_F19H_UMC_PERF_CTR 0xc0010801
/* Zen 2 */
-#define MSR_ZEN2_SPECTRAL_CHICKEN 0xc00110e3
-#define MSR_ZEN2_SPECTRAL_CHICKEN_BIT BIT_ULL(1)
+#define MSR_ZEN2_SPECTRAL_CHICKEN 0xc00110e3
+#define MSR_ZEN2_SPECTRAL_CHICKEN_BIT 1
/* Fam 17h MSRs */
#define MSR_F17H_IRPERF 0xc00000e9
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-01-09 11:59 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-12-30 11:07 [PATCH] x86/CPU/AMD: Simplify the spectral chicken fix Borislav Petkov
2026-01-05 13:20 ` Nikolay Borisov
2026-01-09 11:59 ` [tip: x86/cleanups] " tip-bot2 for Borislav Petkov (AMD)
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®