Skip to content

Commit db734ba

Browse files
pa1guptagregkh
authored andcommitted
x86/bhi: Do not set BHI_DIS_S in 32-bit mode
commit 073fdbe02c69c43fb7c0d547ec265c7747d4a646 upstream. With the possibility of intra-mode BHI via cBPF, complete mitigation for BHI is to use IBHF (history fence) instruction with BHI_DIS_S set. Since this new instruction is only available in 64-bit mode, setting BHI_DIS_S in 32-bit mode is only a partial mitigation. Do not set BHI_DIS_S in 32-bit mode so as to avoid reporting misleading mitigated status. With this change IBHF won't be used in 32-bit mode, also remove the CONFIG_X86_64 check from emit_spectre_bhb_barrier(). Suggested-by: Josh Poimboeuf <[email protected]> Signed-off-by: Pawan Gupta <[email protected]> Signed-off-by: Dave Hansen <[email protected]> Reviewed-by: Josh Poimboeuf <[email protected]> Reviewed-by: Alexandre Chartre <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent cebc238 commit db734ba

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

arch/x86/kernel/cpu/bugs.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1656,10 +1656,11 @@ static void __init bhi_select_mitigation(void)
16561656
return;
16571657
}
16581658

1659-
if (spec_ctrl_bhi_dis())
1659+
if (!IS_ENABLED(CONFIG_X86_64))
16601660
return;
16611661

1662-
if (!IS_ENABLED(CONFIG_X86_64))
1662+
/* Mitigate in hardware if supported */
1663+
if (spec_ctrl_bhi_dis())
16631664
return;
16641665

16651666
/* Mitigate KVM by default */

arch/x86/net/bpf_jit_comp.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -971,8 +971,7 @@ static int emit_spectre_bhb_barrier(u8 **pprog, u8 *ip,
971971
/* Insert IBHF instruction */
972972
if ((cpu_feature_enabled(X86_FEATURE_CLEAR_BHB_LOOP) &&
973973
cpu_feature_enabled(X86_FEATURE_HYPERVISOR)) ||
974-
(cpu_feature_enabled(X86_FEATURE_CLEAR_BHB_HW) &&
975-
IS_ENABLED(CONFIG_X86_64))) {
974+
cpu_feature_enabled(X86_FEATURE_CLEAR_BHB_HW)) {
976975
/*
977976
* Add an Indirect Branch History Fence (IBHF). IBHF acts as a
978977
* fence preventing branch history from before the fence from
@@ -982,6 +981,8 @@ static int emit_spectre_bhb_barrier(u8 **pprog, u8 *ip,
982981
* hardware that doesn't need or support it. The REP and REX.W
983982
* prefixes are required by the microcode, and they also ensure
984983
* that the NOP is unlikely to be used in existing code.
984+
*
985+
* IBHF is not a valid instruction in 32-bit mode.
985986
*/
986987
EMIT5(0xF3, 0x48, 0x0F, 0x1E, 0xF8); /* ibhf */
987988
}

0 commit comments

Comments
 (0)