[RFC PATCH 15/56] x86/bugs: Reset BHI mitigations

David Kaplan
2025-10-13T14:35:35Z

Add function to reset BHI mitigations back to their boot-time defaults.

Signed-off-by: David Kaplan <david.kaplan@amd.com>
---
arch/x86/kernel/cpu/bugs.c | 12 ++++++++++++
1 file changed, 12 insertions(+)

diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c
index e765ac0b9240..67561e5c2154 100644
--- a/arch/x86/kernel/cpu/bugs.c
+++ b/arch/x86/kernel/cpu/bugs.c
@@ -2360,6 +2360,17 @@ static void __init bhi_apply_mitigation(void)
setup_force_cpu_cap(X86_FEATURE_CLEAR_BHB_VMEXIT);
}

+#ifdef CONFIG_DYNAMIC_MITIGATIONS
+static void bhi_reset_mitigation(void)
+{
+ /* RRSBA already cleared in spectre_v2_reset_mitigation() */
+ setup_clear_cpu_cap(X86_FEATURE_CLEAR_BHB_VMEXIT);
+ setup_clear_cpu_cap(X86_FEATURE_CLEAR_BHB_LOOP);
+ bhi_mitigation = IS_ENABLED(CONFIG_MITIGATION_SPECTRE_BHI) ?
+ BHI_MITIGATION_AUTO : BHI_MITIGATION_OFF;
+}
+#endif
+
static void __init spectre_v2_select_mitigation(void)
{
if ((spectre_v2_cmd == SPECTRE_V2_CMD_RETPOLINE ||
@@ -3954,5 +3965,6 @@ void arch_cpu_reset_mitigations(void)
srbds_reset_mitigation();
srso_reset_mitigation();
gds_reset_mitigation();
+ bhi_reset_mitigation();
}
#endif
--
2.34.1