Skip to content

Commit 7497589

Browse files
jpoimboegregkh
authored andcommitted
x86/bugs: Fix BHI handling of RRSBA
commit 1cea8a2 upstream. The ARCH_CAP_RRSBA check isn't correct: RRSBA may have already been disabled by the Spectre v2 mitigation (or can otherwise be disabled by the BHI mitigation itself if needed). In that case retpolines are fine. Fixes: ec9404e ("x86/bhi: Add BHI mitigation knob") Signed-off-by: Josh Poimboeuf <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Sean Christopherson <[email protected]> Link: https://lore.kernel.org/r/6f56f13da34a0834b69163467449be7f58f253dc.1712813475.git.jpoimboe@kernel.org Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent c83e35f commit 7497589

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

arch/x86/kernel/cpu/bugs.c

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1537,20 +1537,25 @@ static enum spectre_v2_mitigation __init spectre_v2_select_retpoline(void)
15371537
return SPECTRE_V2_RETPOLINE;
15381538
}
15391539

1540+
static bool __ro_after_init rrsba_disabled;
1541+
15401542
/* Disable in-kernel use of non-RSB RET predictors */
15411543
static void __init spec_ctrl_disable_kernel_rrsba(void)
15421544
{
1543-
u64 x86_arch_cap_msr;
1545+
if (rrsba_disabled)
1546+
return;
15441547

1545-
if (!boot_cpu_has(X86_FEATURE_RRSBA_CTRL))
1548+
if (!(x86_arch_cap_msr & ARCH_CAP_RRSBA)) {
1549+
rrsba_disabled = true;
15461550
return;
1551+
}
15471552

1548-
x86_arch_cap_msr = x86_read_arch_cap_msr();
1553+
if (!boot_cpu_has(X86_FEATURE_RRSBA_CTRL))
1554+
return;
15491555

1550-
if (x86_arch_cap_msr & ARCH_CAP_RRSBA) {
1551-
x86_spec_ctrl_base |= SPEC_CTRL_RRSBA_DIS_S;
1552-
update_spec_ctrl(x86_spec_ctrl_base);
1553-
}
1556+
x86_spec_ctrl_base |= SPEC_CTRL_RRSBA_DIS_S;
1557+
update_spec_ctrl(x86_spec_ctrl_base);
1558+
rrsba_disabled = true;
15541559
}
15551560

15561561
static void __init spectre_v2_determine_rsb_fill_type_at_vmexit(enum spectre_v2_mitigation mode)
@@ -1651,9 +1656,11 @@ static void __init bhi_select_mitigation(void)
16511656
return;
16521657

16531658
/* Retpoline mitigates against BHI unless the CPU has RRSBA behavior */
1654-
if (cpu_feature_enabled(X86_FEATURE_RETPOLINE) &&
1655-
!(x86_read_arch_cap_msr() & ARCH_CAP_RRSBA))
1656-
return;
1659+
if (cpu_feature_enabled(X86_FEATURE_RETPOLINE)) {
1660+
spec_ctrl_disable_kernel_rrsba();
1661+
if (rrsba_disabled)
1662+
return;
1663+
}
16571664

16581665
if (spec_ctrl_bhi_dis())
16591666
return;
@@ -2808,8 +2815,7 @@ static const char *spectre_bhi_state(void)
28082815
return "; BHI: BHI_DIS_S";
28092816
else if (boot_cpu_has(X86_FEATURE_CLEAR_BHB_LOOP))
28102817
return "; BHI: SW loop, KVM: SW loop";
2811-
else if (boot_cpu_has(X86_FEATURE_RETPOLINE) &&
2812-
!(x86_arch_cap_msr & ARCH_CAP_RRSBA))
2818+
else if (boot_cpu_has(X86_FEATURE_RETPOLINE) && rrsba_disabled)
28132819
return "; BHI: Retpoline";
28142820
else if (boot_cpu_has(X86_FEATURE_CLEAR_BHB_LOOP_ON_VMEXIT))
28152821
return "; BHI: Syscall hardening, KVM: SW loop";

0 commit comments

Comments
 (0)