Skip to content

Commit 4f25355

Browse files
bp3tk0vgregkh
authored andcommitted
x86/srso: Tie SBPB bit setting to microcode patch detection
commit 5a15d83 upstream. The SBPB bit in MSR_IA32_PRED_CMD is supported only after a microcode patch has been applied so set X86_FEATURE_SBPB only then. Otherwise, guests would attempt to set that bit and #GP on the MSR write. While at it, make SMT detection more robust as some guests - depending on how and what CPUID leafs their report - lead to cpu_smt_control getting set to CPU_SMT_NOT_SUPPORTED but SRSO_NO should be set for any guest incarnation where one simply cannot do SMT, for whatever reason. Fixes: fb3bd91 ("x86/srso: Add a Speculative RAS Overflow mitigation") Reported-by: Konrad Rzeszutek Wilk <[email protected]> Reported-by: Salvatore Bonaccorso <[email protected]> Signed-off-by: Borislav Petkov (AMD) <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 77cf32d commit 4f25355

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

arch/x86/kernel/cpu/amd.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1247,16 +1247,21 @@ EXPORT_SYMBOL_GPL(amd_get_highest_perf);
12471247

12481248
bool cpu_has_ibpb_brtype_microcode(void)
12491249
{
1250-
u8 fam = boot_cpu_data.x86;
1251-
1250+
switch (boot_cpu_data.x86) {
12521251
/* Zen1/2 IBPB flushes branch type predictions too. */
1253-
if (fam == 0x17)
1252+
case 0x17:
12541253
return boot_cpu_has(X86_FEATURE_AMD_IBPB);
1255-
/* Poke the MSR bit on Zen3/4 to check its presence. */
1256-
else if (fam == 0x19)
1257-
return !wrmsrl_safe(MSR_IA32_PRED_CMD, PRED_CMD_SBPB);
1258-
else
1254+
case 0x19:
1255+
/* Poke the MSR bit on Zen3/4 to check its presence. */
1256+
if (!wrmsrl_safe(MSR_IA32_PRED_CMD, PRED_CMD_SBPB)) {
1257+
setup_force_cpu_cap(X86_FEATURE_SBPB);
1258+
return true;
1259+
} else {
1260+
return false;
1261+
}
1262+
default:
12591263
return false;
1264+
}
12601265
}
12611266

12621267
static void zenbleed_check_cpu(void *unused)

arch/x86/kernel/cpu/bugs.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2383,14 +2383,13 @@ static void __init srso_select_mitigation(void)
23832383
* flags for guests.
23842384
*/
23852385
setup_force_cpu_cap(X86_FEATURE_IBPB_BRTYPE);
2386-
setup_force_cpu_cap(X86_FEATURE_SBPB);
23872386

23882387
/*
23892388
* Zen1/2 with SMT off aren't vulnerable after the right
23902389
* IBPB microcode has been applied.
23912390
*/
23922391
if ((boot_cpu_data.x86 < 0x19) &&
2393-
(cpu_smt_control == CPU_SMT_DISABLED))
2392+
(!cpu_smt_possible() || (cpu_smt_control == CPU_SMT_DISABLED)))
23942393
setup_force_cpu_cap(X86_FEATURE_SRSO_NO);
23952394
}
23962395

@@ -2463,8 +2462,8 @@ static void __init srso_select_mitigation(void)
24632462
pr_info("%s%s\n", srso_strings[srso_mitigation], (has_microcode ? "" : ", no microcode"));
24642463

24652464
pred_cmd:
2466-
if (boot_cpu_has(X86_FEATURE_SRSO_NO) ||
2467-
srso_cmd == SRSO_CMD_OFF)
2465+
if ((boot_cpu_has(X86_FEATURE_SRSO_NO) || srso_cmd == SRSO_CMD_OFF) &&
2466+
boot_cpu_has(X86_FEATURE_SBPB))
24682467
x86_pred_cmd = PRED_CMD_SBPB;
24692468
}
24702469

0 commit comments

Comments
 (0)