Skip to content

Commit 5a15d83

Browse files
committed
x86/srso: Tie SBPB bit setting to microcode patch detection
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]>
1 parent 3bbbe97 commit 5a15d83

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
@@ -1238,14 +1238,19 @@ EXPORT_SYMBOL_GPL(amd_get_highest_perf);
12381238

12391239
bool cpu_has_ibpb_brtype_microcode(void)
12401240
{
1241-
u8 fam = boot_cpu_data.x86;
1242-
1241+
switch (boot_cpu_data.x86) {
12431242
/* Zen1/2 IBPB flushes branch type predictions too. */
1244-
if (fam == 0x17)
1243+
case 0x17:
12451244
return boot_cpu_has(X86_FEATURE_AMD_IBPB);
1246-
/* Poke the MSR bit on Zen3/4 to check its presence. */
1247-
else if (fam == 0x19)
1248-
return !wrmsrl_safe(MSR_IA32_PRED_CMD, PRED_CMD_SBPB);
1249-
else
1245+
case 0x19:
1246+
/* Poke the MSR bit on Zen3/4 to check its presence. */
1247+
if (!wrmsrl_safe(MSR_IA32_PRED_CMD, PRED_CMD_SBPB)) {
1248+
setup_force_cpu_cap(X86_FEATURE_SBPB);
1249+
return true;
1250+
} else {
1251+
return false;
1252+
}
1253+
default:
12501254
return false;
1255+
}
12511256
}

arch/x86/kernel/cpu/bugs.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2265,14 +2265,13 @@ static void __init srso_select_mitigation(void)
22652265
* flags for guests.
22662266
*/
22672267
setup_force_cpu_cap(X86_FEATURE_IBPB_BRTYPE);
2268-
setup_force_cpu_cap(X86_FEATURE_SBPB);
22692268

22702269
/*
22712270
* Zen1/2 with SMT off aren't vulnerable after the right
22722271
* IBPB microcode has been applied.
22732272
*/
22742273
if ((boot_cpu_data.x86 < 0x19) &&
2275-
(cpu_smt_control == CPU_SMT_DISABLED))
2274+
(!cpu_smt_possible() || (cpu_smt_control == CPU_SMT_DISABLED)))
22762275
setup_force_cpu_cap(X86_FEATURE_SRSO_NO);
22772276
}
22782277

@@ -2345,8 +2344,8 @@ static void __init srso_select_mitigation(void)
23452344
pr_info("%s%s\n", srso_strings[srso_mitigation], (has_microcode ? "" : ", no microcode"));
23462345

23472346
pred_cmd:
2348-
if (boot_cpu_has(X86_FEATURE_SRSO_NO) ||
2349-
srso_cmd == SRSO_CMD_OFF)
2347+
if ((boot_cpu_has(X86_FEATURE_SRSO_NO) || srso_cmd == SRSO_CMD_OFF) &&
2348+
boot_cpu_has(X86_FEATURE_SBPB))
23502349
x86_pred_cmd = PRED_CMD_SBPB;
23512350
}
23522351

0 commit comments

Comments
 (0)