Skip to content

Commit 91857ae

Browse files
jpoimboebp3tk0v
authored andcommitted
x86/srso: Set CPUID feature bits independently of bug or mitigation status
Booting with mitigations=off incorrectly prevents the X86_FEATURE_{IBPB_BRTYPE,SBPB} CPUID bits from getting set. Also, future CPUs without X86_BUG_SRSO might still have IBPB with branch type prediction flushing, in which case SBPB should be used instead of IBPB. The current code doesn't allow for that. Also, cpu_has_ibpb_brtype_microcode() has some surprising side effects and the setting of these feature bits really doesn't belong in the mitigation code anyway. Move it to earlier. Fixes: fb3bd91 ("x86/srso: Add a Speculative RAS Overflow mitigation") Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org> Signed-off-by: Ingo Molnar <mingo@kernel.org> Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de> Reviewed-by: Nikolay Borisov <nik.borisov@suse.com> Reviewed-by: Borislav Petkov (AMD) <bp@alien8.de> Acked-by: Borislav Petkov (AMD) <bp@alien8.de> Link: https://lore.kernel.org/r/869a1709abfe13b673bdd10c2f4332ca253a40bc.1693889988.git.jpoimboe@kernel.org
1 parent a8cf700 commit 91857ae

File tree

3 files changed

+10
-33
lines changed

3 files changed

+10
-33
lines changed

arch/x86/include/asm/processor.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -683,13 +683,11 @@ extern u16 get_llc_id(unsigned int cpu);
683683
#ifdef CONFIG_CPU_SUP_AMD
684684
extern u32 amd_get_nodes_per_socket(void);
685685
extern u32 amd_get_highest_perf(void);
686-
extern bool cpu_has_ibpb_brtype_microcode(void);
687686
extern void amd_clear_divider(void);
688687
extern void amd_check_microcode(void);
689688
#else
690689
static inline u32 amd_get_nodes_per_socket(void) { return 0; }
691690
static inline u32 amd_get_highest_perf(void) { return 0; }
692-
static inline bool cpu_has_ibpb_brtype_microcode(void) { return false; }
693691
static inline void amd_clear_divider(void) { }
694692
static inline void amd_check_microcode(void) { }
695693
#endif

arch/x86/kernel/cpu/amd.c

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -766,6 +766,15 @@ static void early_init_amd(struct cpuinfo_x86 *c)
766766

767767
if (cpu_has(c, X86_FEATURE_TOPOEXT))
768768
smp_num_siblings = ((cpuid_ebx(0x8000001e) >> 8) & 0xff) + 1;
769+
770+
if (!cpu_has(c, X86_FEATURE_IBPB_BRTYPE)) {
771+
if (c->x86 == 0x17 && boot_cpu_has(X86_FEATURE_AMD_IBPB))
772+
setup_force_cpu_cap(X86_FEATURE_IBPB_BRTYPE);
773+
else if (c->x86 >= 0x19 && !wrmsrl_safe(MSR_IA32_PRED_CMD, PRED_CMD_SBPB)) {
774+
setup_force_cpu_cap(X86_FEATURE_IBPB_BRTYPE);
775+
setup_force_cpu_cap(X86_FEATURE_SBPB);
776+
}
777+
}
769778
}
770779

771780
static void init_amd_k8(struct cpuinfo_x86 *c)
@@ -1301,25 +1310,6 @@ void amd_check_microcode(void)
13011310
on_each_cpu(zenbleed_check_cpu, NULL, 1);
13021311
}
13031312

1304-
bool cpu_has_ibpb_brtype_microcode(void)
1305-
{
1306-
switch (boot_cpu_data.x86) {
1307-
/* Zen1/2 IBPB flushes branch type predictions too. */
1308-
case 0x17:
1309-
return boot_cpu_has(X86_FEATURE_AMD_IBPB);
1310-
case 0x19:
1311-
/* Poke the MSR bit on Zen3/4 to check its presence. */
1312-
if (!wrmsrl_safe(MSR_IA32_PRED_CMD, PRED_CMD_SBPB)) {
1313-
setup_force_cpu_cap(X86_FEATURE_SBPB);
1314-
return true;
1315-
} else {
1316-
return false;
1317-
}
1318-
default:
1319-
return false;
1320-
}
1321-
}
1322-
13231313
/*
13241314
* Issue a DIV 0/1 insn to clear any division data from previous DIV
13251315
* operations.

arch/x86/kernel/cpu/bugs.c

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2404,26 +2404,15 @@ early_param("spec_rstack_overflow", srso_parse_cmdline);
24042404

24052405
static void __init srso_select_mitigation(void)
24062406
{
2407-
bool has_microcode;
2407+
bool has_microcode = boot_cpu_has(X86_FEATURE_IBPB_BRTYPE);
24082408

24092409
if (!boot_cpu_has_bug(X86_BUG_SRSO) || cpu_mitigations_off())
24102410
goto pred_cmd;
24112411

2412-
/*
2413-
* The first check is for the kernel running as a guest in order
2414-
* for guests to verify whether IBPB is a viable mitigation.
2415-
*/
2416-
has_microcode = boot_cpu_has(X86_FEATURE_IBPB_BRTYPE) || cpu_has_ibpb_brtype_microcode();
24172412
if (!has_microcode) {
24182413
pr_warn("IBPB-extending microcode not applied!\n");
24192414
pr_warn(SRSO_NOTICE);
24202415
} else {
2421-
/*
2422-
* Enable the synthetic (even if in a real CPUID leaf)
2423-
* flags for guests.
2424-
*/
2425-
setup_force_cpu_cap(X86_FEATURE_IBPB_BRTYPE);
2426-
24272416
/*
24282417
* Zen1/2 with SMT off aren't vulnerable after the right
24292418
* IBPB microcode has been applied.

0 commit comments

Comments
 (0)