Skip to content

Commit 9139f4b

Browse files
bp3tk0vgregkh
authored andcommitted
x86/srso: Add IBPB_BRTYPE support
Upstream commit: 79113e4 Add support for the synthetic CPUID flag which "if this bit is 1, it indicates that MSR 49h (PRED_CMD) bit 0 (IBPB) flushes all branch type predictions from the CPU branch predictor." This flag is there so that this capability in guests can be detected easily (otherwise one would have to track microcode revisions which is impossible for guests). It is also needed only for Zen3 and -4. The other two (Zen1 and -2) always flush branch type predictions by default. Signed-off-by: Borislav Petkov (AMD) <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent ac41e90 commit 9139f4b

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

arch/x86/include/asm/cpufeatures.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,8 @@
426426
#define X86_FEATURE_V_TSC_AUX (19*32+ 9) /* "" Virtual TSC_AUX */
427427
#define X86_FEATURE_SME_COHERENT (19*32+10) /* "" AMD hardware-enforced cache coherency */
428428

429+
#define X86_FEATURE_IBPB_BRTYPE (20*32+28) /* "" MSR_PRED_CMD[IBPB] flushes all branch type predictions */
430+
429431
/*
430432
* BUG word(s)
431433
*/

arch/x86/kernel/cpu/bugs.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2356,10 +2356,20 @@ static void __init srso_select_mitigation(void)
23562356
if (!boot_cpu_has_bug(X86_BUG_SRSO) || cpu_mitigations_off())
23572357
return;
23582358

2359-
has_microcode = cpu_has_ibpb_brtype_microcode();
2359+
/*
2360+
* The first check is for the kernel running as a guest in order
2361+
* for guests to verify whether IBPB is a viable mitigation.
2362+
*/
2363+
has_microcode = boot_cpu_has(X86_FEATURE_IBPB_BRTYPE) || cpu_has_ibpb_brtype_microcode();
23602364
if (!has_microcode) {
23612365
pr_warn("IBPB-extending microcode not applied!\n");
23622366
pr_warn(SRSO_NOTICE);
2367+
} else {
2368+
/*
2369+
* Enable the synthetic (even if in a real CPUID leaf)
2370+
* flag for guests.
2371+
*/
2372+
setup_force_cpu_cap(X86_FEATURE_IBPB_BRTYPE);
23632373
}
23642374

23652375
switch (srso_cmd) {

0 commit comments

Comments
 (0)