Skip to content

Commit 6912979

Browse files
jpoimboeIngo Molnar
authored andcommitted
x86/bugs: Fix BHI retpoline check
Confusingly, X86_FEATURE_RETPOLINE doesn't mean retpolines are enabled, as it also includes the original "AMD retpoline" which isn't a retpoline at all. Also replace cpu_feature_enabled() with boot_cpu_has() because this is before alternatives are patched and cpu_feature_enabled()'s fallback path is slower than plain old boot_cpu_has(). Fixes: ec9404e ("x86/bhi: Add BHI mitigation knob") Signed-off-by: Josh Poimboeuf <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Reviewed-by: Pawan Gupta <[email protected]> Cc: Borislav Petkov <[email protected]> Cc: Linus Torvalds <[email protected]> Link: https://lore.kernel.org/r/ad3807424a3953f0323c011a643405619f2a4927.1712944776.git.jpoimboe@kernel.org
1 parent 7211274 commit 6912979

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

arch/x86/kernel/cpu/bugs.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1652,7 +1652,8 @@ static void __init bhi_select_mitigation(void)
16521652
return;
16531653

16541654
/* Retpoline mitigates against BHI unless the CPU has RRSBA behavior */
1655-
if (cpu_feature_enabled(X86_FEATURE_RETPOLINE)) {
1655+
if (boot_cpu_has(X86_FEATURE_RETPOLINE) &&
1656+
!boot_cpu_has(X86_FEATURE_RETPOLINE_LFENCE)) {
16561657
spec_ctrl_disable_kernel_rrsba();
16571658
if (rrsba_disabled)
16581659
return;
@@ -2804,11 +2805,13 @@ static const char *spectre_bhi_state(void)
28042805
{
28052806
if (!boot_cpu_has_bug(X86_BUG_BHI))
28062807
return "; BHI: Not affected";
2807-
else if (boot_cpu_has(X86_FEATURE_CLEAR_BHB_HW))
2808+
else if (boot_cpu_has(X86_FEATURE_CLEAR_BHB_HW))
28082809
return "; BHI: BHI_DIS_S";
2809-
else if (boot_cpu_has(X86_FEATURE_CLEAR_BHB_LOOP))
2810+
else if (boot_cpu_has(X86_FEATURE_CLEAR_BHB_LOOP))
28102811
return "; BHI: SW loop, KVM: SW loop";
2811-
else if (boot_cpu_has(X86_FEATURE_RETPOLINE) && rrsba_disabled)
2812+
else if (boot_cpu_has(X86_FEATURE_RETPOLINE) &&
2813+
!boot_cpu_has(X86_FEATURE_RETPOLINE_LFENCE) &&
2814+
rrsba_disabled)
28122815
return "; BHI: Retpoline";
28132816
else if (boot_cpu_has(X86_FEATURE_CLEAR_BHB_LOOP_ON_VMEXIT))
28142817
return "; BHI: Vulnerable, KVM: SW loop";

0 commit comments

Comments
 (0)