Skip to content

Commit 736a2dc

Browse files
committed
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
1 parent c957072 commit 736a2dc

3 files changed

Lines changed: 6 additions & 12 deletions

File tree

arch/x86/include/asm/msr-index.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -794,8 +794,8 @@
794794
#define MSR_F19H_UMC_PERF_CTR 0xc0010801
795795

796796
/* Zen 2 */
797-
#define MSR_ZEN2_SPECTRAL_CHICKEN 0xc00110e3
798-
#define MSR_ZEN2_SPECTRAL_CHICKEN_BIT BIT_ULL(1)
797+
#define MSR_ZEN2_SPECTRAL_CHICKEN 0xc00110e3
798+
#define MSR_ZEN2_SPECTRAL_CHICKEN_BIT 1
799799

800800
/* Fam 17h MSRs */
801801
#define MSR_F17H_IRPERF 0xc00000e9

arch/x86/kernel/cpu/amd.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -900,20 +900,14 @@ static void fix_erratum_1386(struct cpuinfo_x86 *c)
900900
void init_spectral_chicken(struct cpuinfo_x86 *c)
901901
{
902902
#ifdef CONFIG_MITIGATION_UNRET_ENTRY
903-
u64 value;
904-
905903
/*
906904
* On Zen2 we offer this chicken (bit) on the altar of Speculation.
907905
*
908906
* This suppresses speculation from the middle of a basic block, i.e. it
909907
* suppresses non-branch predictions.
910908
*/
911-
if (!cpu_has(c, X86_FEATURE_HYPERVISOR)) {
912-
if (!rdmsrq_safe(MSR_ZEN2_SPECTRAL_CHICKEN, &value)) {
913-
value |= MSR_ZEN2_SPECTRAL_CHICKEN_BIT;
914-
wrmsrq_safe(MSR_ZEN2_SPECTRAL_CHICKEN, value);
915-
}
916-
}
909+
if (!cpu_has(c, X86_FEATURE_HYPERVISOR))
910+
msr_set_bit(MSR_ZEN2_SPECTRAL_CHICKEN, MSR_ZEN2_SPECTRAL_CHICKEN_BIT);
917911
#endif
918912
}
919913

tools/arch/x86/include/asm/msr-index.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -770,8 +770,8 @@
770770
#define MSR_F19H_UMC_PERF_CTR 0xc0010801
771771

772772
/* Zen 2 */
773-
#define MSR_ZEN2_SPECTRAL_CHICKEN 0xc00110e3
774-
#define MSR_ZEN2_SPECTRAL_CHICKEN_BIT BIT_ULL(1)
773+
#define MSR_ZEN2_SPECTRAL_CHICKEN 0xc00110e3
774+
#define MSR_ZEN2_SPECTRAL_CHICKEN_BIT 1
775775

776776
/* Fam 17h MSRs */
777777
#define MSR_F17H_IRPERF 0xc00000e9

0 commit comments

Comments
 (0)