Skip to content

Commit 8cc68c9

Browse files
committed
x86/CPU/AMD: Make sure EFER[AIBRSE] is set
The AutoIBRS bit gets set only on the BSP as part of determining which mitigation to enable on AMD. Setting on the APs relies on the circumstance that the APs get booted through the trampoline and EFER - the MSR which contains that bit - gets replicated on every AP from the BSP. However, this can change in the future and considering the security implications of this bit not being set on every CPU, make sure it is set by verifying EFER later in the boot process and on every AP. Reported-by: Josh Poimboeuf <jpoimboe@kernel.org> Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de> Acked-by: Dave Hansen <dave.hansen@linux.intel.com> Link: https://lore.kernel.org/r/20230224185257.o3mcmloei5zqu7wa@treble
1 parent fe15c26 commit 8cc68c9

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

arch/x86/kernel/cpu/amd.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -996,6 +996,17 @@ static void init_amd(struct cpuinfo_x86 *c)
996996
msr_set_bit(MSR_K7_HWCR, MSR_K7_HWCR_IRPERF_EN_BIT);
997997

998998
check_null_seg_clears_base(c);
999+
1000+
/*
1001+
* Make sure EFER[AIBRSE - Automatic IBRS Enable] is set. The APs are brought up
1002+
* using the trampoline code and as part of it, MSR_EFER gets prepared there in
1003+
* order to be replicated onto them. Regardless, set it here again, if not set,
1004+
* to protect against any future refactoring/code reorganization which might
1005+
* miss setting this important bit.
1006+
*/
1007+
if (spectre_v2_in_eibrs_mode(spectre_v2_enabled) &&
1008+
cpu_has(c, X86_FEATURE_AUTOIBRS))
1009+
WARN_ON_ONCE(msr_set_bit(MSR_EFER, _EFER_AUTOIBRS));
9991010
}
10001011

10011012
#ifdef CONFIG_X86_32

arch/x86/kernel/cpu/bugs.c

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -784,8 +784,7 @@ static int __init nospectre_v1_cmdline(char *str)
784784
}
785785
early_param("nospectre_v1", nospectre_v1_cmdline);
786786

787-
static enum spectre_v2_mitigation spectre_v2_enabled __ro_after_init =
788-
SPECTRE_V2_NONE;
787+
enum spectre_v2_mitigation spectre_v2_enabled __ro_after_init = SPECTRE_V2_NONE;
789788

790789
#undef pr_fmt
791790
#define pr_fmt(fmt) "RETBleed: " fmt
@@ -1133,13 +1132,6 @@ spectre_v2_parse_user_cmdline(void)
11331132
return SPECTRE_V2_USER_CMD_AUTO;
11341133
}
11351134

1136-
static inline bool spectre_v2_in_eibrs_mode(enum spectre_v2_mitigation mode)
1137-
{
1138-
return mode == SPECTRE_V2_EIBRS ||
1139-
mode == SPECTRE_V2_EIBRS_RETPOLINE ||
1140-
mode == SPECTRE_V2_EIBRS_LFENCE;
1141-
}
1142-
11431135
static inline bool spectre_v2_in_ibrs_mode(enum spectre_v2_mitigation mode)
11441136
{
11451137
return spectre_v2_in_eibrs_mode(mode) || mode == SPECTRE_V2_IBRS;

arch/x86/kernel/cpu/cpu.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,12 @@ unsigned int aperfmperf_get_khz(int cpu);
8383
extern void x86_spec_ctrl_setup_ap(void);
8484
extern void update_srbds_msr(void);
8585

86+
extern enum spectre_v2_mitigation spectre_v2_enabled;
87+
88+
static inline bool spectre_v2_in_eibrs_mode(enum spectre_v2_mitigation mode)
89+
{
90+
return mode == SPECTRE_V2_EIBRS ||
91+
mode == SPECTRE_V2_EIBRS_RETPOLINE ||
92+
mode == SPECTRE_V2_EIBRS_LFENCE;
93+
}
8694
#endif /* ARCH_X86_CPU_H */

0 commit comments

Comments
 (0)