Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: ec9404e40e8f ("x86/bhi: Add BHI mitigation knob")
Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Reviewed-by: Pawan Gupta <pawan.kumar.gupta@linux.intel.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Link: https://lore.kernel.org/r/ad3807424a3953f0323c011a643405619f2a4927.1712944776.git.jpoimboe@kernel.org

authored by

Josh Poimboeuf and committed by
Ingo Molnar
69129794 7211274f

+7 -4
+7 -4
arch/x86/kernel/cpu/bugs.c
··· 1652 1652 return; 1653 1653 1654 1654 /* 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)) { 1656 1657 spec_ctrl_disable_kernel_rrsba(); 1657 1658 if (rrsba_disabled) 1658 1659 return; ··· 2805 2804 { 2806 2805 if (!boot_cpu_has_bug(X86_BUG_BHI)) 2807 2806 return "; BHI: Not affected"; 2808 - else if (boot_cpu_has(X86_FEATURE_CLEAR_BHB_HW)) 2807 + else if (boot_cpu_has(X86_FEATURE_CLEAR_BHB_HW)) 2809 2808 return "; BHI: BHI_DIS_S"; 2810 - else if (boot_cpu_has(X86_FEATURE_CLEAR_BHB_LOOP)) 2809 + else if (boot_cpu_has(X86_FEATURE_CLEAR_BHB_LOOP)) 2811 2810 return "; BHI: SW loop, KVM: SW loop"; 2812 - else if (boot_cpu_has(X86_FEATURE_RETPOLINE) && rrsba_disabled) 2811 + else if (boot_cpu_has(X86_FEATURE_RETPOLINE) && 2812 + !boot_cpu_has(X86_FEATURE_RETPOLINE_LFENCE) && 2813 + rrsba_disabled) 2813 2814 return "; BHI: Retpoline"; 2814 2815 else if (boot_cpu_has(X86_FEATURE_CLEAR_BHB_LOOP_ON_VMEXIT)) 2815 2816 return "; BHI: Vulnerable, KVM: SW loop";