Skip to contentSkip to conversation

x86/bugs: Keep BHI mitigation when only user->kernel is mitigated

PATCH Applied Breno Leitao 4 participants 4 messages Oct 29 – Nov 2

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/bugs: Keep BHI mitigation when only user->kernel is mitigated

The BHI mitigation selection is inconsistent with the documentation (attack_vector_controls.rst), which lists BHI under both the user->kernel and guest->host attack vectors. bhi_select_mitigation() only enables it when CPU_MITIGATE_GUEST_HOST is set; otherwise it selects BHI_MITIGATION_OFF, even if CPU_MITIGATE_USER_KERNEL is set.

As a result, a kernel compiled with KVM disabled gets BHI automatically disabled, since CPU_MITIGATE_GUEST_HOST defaults to off without KVM. This is a bug, given that CPU_MITIGATE_USER_KERNEL still needs it: on affected Intel CPUs these kernels lose BHI_DIS_S or the BHB clearing loop by default. Booting with mitigations=auto,no_guest_host has the same effect.

Select BHI_MITIGATION_ON whenever user->kernel is mitigated, and keep BHI_MITIGATION_VMEXIT_ONLY for the guest->host-only case.

Fixes ddcd4d3cb37c ("x86/bugs: Add attack vector controls for BHI")
Cc David Kaplan <[email protected]>
---
 arch/x86/kernel/cpu/bugs.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)
arch/x86/kernel/cpu/bugs.c +5 -7
index 000ebee2d247b1..4ced10c6ba0db9 100644
@@ -2088,14 +2088,12 @@ static void __init bhi_select_mitigation(void)
 	if (bhi_mitigation != BHI_MITIGATION_AUTO)
 		return;
 
-	if (cpu_attack_vector_mitigated(CPU_MITIGATE_GUEST_HOST)) {
-		if (cpu_attack_vector_mitigated(CPU_MITIGATE_USER_KERNEL))
-			bhi_mitigation = BHI_MITIGATION_ON;
-		else
-			bhi_mitigation = BHI_MITIGATION_VMEXIT_ONLY;
-	} else {
+	if (cpu_attack_vector_mitigated(CPU_MITIGATE_USER_KERNEL))
+		bhi_mitigation = BHI_MITIGATION_ON;
+	else if (cpu_attack_vector_mitigated(CPU_MITIGATE_GUEST_HOST))
+		bhi_mitigation = BHI_MITIGATION_VMEXIT_ONLY;
+	else
 		bhi_mitigation = BHI_MITIGATION_OFF;
-	}
 }
 
 static void __init bhi_update_mitigation(void)

---
base-commit: 6d0933ae9d46674a6ea63a87e9e9ab4e662670c9
change-id: 20261029-bhi-attack-vector-c36ea6854904

Best regards,

Signature · 1 line
Breno Leitao <[email protected]>
Acked-by on v1 1/1
#1 lore raw

AMD General

Quoted 73 lines

-----Original Message-----
From: Breno Leitao <[email protected]>
Sent: Thursday, October 29, 2026 9:45 AM
To: Thomas Gleixner <[email protected]>; Borislav Petkov <[email protected]>; Peter Zijlstra <[email protected]>; Josh Poimboeuf <[email protected]>; Pawan Gupta <[email protected]>; Ingo Molnar <[email protected]>; Dave Hansen <[email protected]>; [email protected]; H. Peter Anvin <[email protected]>; Kaplan, David <[email protected]>
Cc: [email protected]; [email protected]; Breno Leitao <[email protected]>
Subject: [PATCH] x86/bugs: Keep BHI mitigation when only user->kernel is mitigated

[You don't often get email from [email protected]. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]

Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.

The BHI mitigation selection is inconsistent with the documentation (attack_vector_controls.rst), which lists BHI under both the user->kernel and guest->host attack vectors. bhi_select_mitigation() only enables it when CPU_MITIGATE_GUEST_HOST is set; otherwise it selects BHI_MITIGATION_OFF, even if CPU_MITIGATE_USER_KERNEL is set.

As a result, a kernel compiled with KVM disabled gets BHI automatically disabled, since CPU_MITIGATE_GUEST_HOST defaults to off without KVM. This is a bug, given that CPU_MITIGATE_USER_KERNEL still needs it: on affected Intel CPUs these kernels lose BHI_DIS_S or the BHB clearing loop by default. Booting with mitigations=auto,no_guest_host has the same effect.

Select BHI_MITIGATION_ON whenever user->kernel is mitigated, and keep BHI_MITIGATION_VMEXIT_ONLY for the guest->host-only case.

Fixes ddcd4d3cb37c ("x86/bugs: Add attack vector controls for BHI")
Cc David Kaplan <[email protected]>
---
 arch/x86/kernel/cpu/bugs.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)
arch/x86/kernel/cpu/bugs.c +5 -8
index 000ebee2d247b1..4ced10c6ba0db9 100644
@@ -2088,14 +2088,12 @@ static void __init bhi_select_mitigation(void)
        if (bhi_mitigation != BHI_MITIGATION_AUTO)
                return;
 
-       if (cpu_attack_vector_mitigated(CPU_MITIGATE_GUEST_HOST)) {
-               if (cpu_attack_vector_mitigated(CPU_MITIGATE_USER_KERNEL))
-                       bhi_mitigation = BHI_MITIGATION_ON;
-               else
-                       bhi_mitigation = BHI_MITIGATION_VMEXIT_ONLY;
-       } else {
+       if (cpu_attack_vector_mitigated(CPU_MITIGATE_USER_KERNEL))
+               bhi_mitigation = BHI_MITIGATION_ON;
+       else if (cpu_attack_vector_mitigated(CPU_MITIGATE_GUEST_HOST))
+               bhi_mitigation = BHI_MITIGATION_VMEXIT_ONLY;
+       else
                bhi_mitigation = BHI_MITIGATION_OFF;
-       }
 }
 
 static void __init bhi_update_mitigation(void)
 
---

base-commit: 6d0933ae9d46674a6ea63a87e9e9ab4e662670c9
change-id: 20261029-bhi-attack-vector-c36ea6854904

Quoted 3 lines

Best regards,
--
Breno Leitao <[email protected]>

Looks like I had done this correctly up through v5 of my attack vector series but the final version messed it up when I tried to simplify it. Fix looks good to me.

--David Kaplan

maintainer
#2 lore raw
In reply to Breno Leitao
Quoted 16 lines · Breno Leitao

The BHI mitigation selection is inconsistent with the documentation (attack_vector_controls.rst), which lists BHI under both the user->kernel and guest->host attack vectors. bhi_select_mitigation() only enables it when CPU_MITIGATE_GUEST_HOST is set; otherwise it selects BHI_MITIGATION_OFF, even if CPU_MITIGATE_USER_KERNEL is set.

As a result, a kernel compiled with KVM disabled gets BHI automatically disabled, since CPU_MITIGATE_GUEST_HOST defaults to off without KVM. This is a bug, given that CPU_MITIGATE_USER_KERNEL still needs it: on affected Intel CPUs these kernels lose BHI_DIS_S or the BHB clearing loop by default. Booting with mitigations=auto,no_guest_host has the same effect.

Select BHI_MITIGATION_ON whenever user->kernel is mitigated, and keep BHI_MITIGATION_VMEXIT_ONLY for the guest->host-only case.

Quoted 6 lines
Fixes ddcd4d3cb37c ("x86/bugs: Add attack vector controls for BHI")
Cc David Kaplan <[email protected]>
---
 arch/x86/kernel/cpu/bugs.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

Queued, thx.

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
merge bot Applied
#3 lore raw

[tip: x86/urgent] x86/bugs: Select the BHI mitigation based on the attack vector properly

In reply to Breno Leitao
The following commit has been merged into the x86/urgent branch of tip:

The following commit has been merged into the x86/urgent branch of tip:

Commit-ID:     3457b3bcd344005af894876cab4e634cabdcbb62
Gitweb:        https://git.kernel.org/tip/3457b3bcd344005af894876cab4e634cabdcbb62
Author:        Breno Leitao <[email protected]>
AuthorDate:    Thu, 29 Oct 2026 07:45:03 -07:00
Committer:     Borislav Petkov (AMD) <[email protected]>
CommitterDate: Sun, 01 Nov 2026 17:32:45 -08:00

x86/bugs: Select the BHI mitigation based on the attack vector properly

The BHI mitigation selection is inconsistent with the documentation (attack_vector_controls.rst), which lists BHI under both the user->kernel and guest->host attack vectors. bhi_select_mitigation() only enables it when CPU_MITIGATE_GUEST_HOST is set; otherwise it selects BHI_MITIGATION_OFF, even if CPU_MITIGATE_USER_KERNEL is set.

As a result, a kernel compiled with KVM disabled gets BHI automatically disabled, since CPU_MITIGATE_GUEST_HOST defaults to off without KVM. This is a bug, given that CPU_MITIGATE_USER_KERNEL still needs it: on affected Intel CPUs these kernels lose BHI_DIS_S or the BHB clearing loop by default. Booting with mitigations=auto,no_guest_host has the same effect.

Select BHI_MITIGATION_ON whenever user->kernel is mitigated, and keep BHI_MITIGATION_VMEXIT_ONLY for the guest->host-only case.

[ bp: Clarify commit title. ]

---
 arch/x86/kernel/cpu/bugs.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)
arch/x86/kernel/cpu/bugs.c +5 -7
index 000ebee..4ced10c 100644
@@ -2088,14 +2088,12 @@ static void __init bhi_select_mitigation(void)
 	if (bhi_mitigation != BHI_MITIGATION_AUTO)
 		return;
 
-	if (cpu_attack_vector_mitigated(CPU_MITIGATE_GUEST_HOST)) {
-		if (cpu_attack_vector_mitigated(CPU_MITIGATE_USER_KERNEL))
-			bhi_mitigation = BHI_MITIGATION_ON;
-		else
-			bhi_mitigation = BHI_MITIGATION_VMEXIT_ONLY;
-	} else {
+	if (cpu_attack_vector_mitigated(CPU_MITIGATE_USER_KERNEL))
+		bhi_mitigation = BHI_MITIGATION_ON;
+	else if (cpu_attack_vector_mitigated(CPU_MITIGATE_GUEST_HOST))
+		bhi_mitigation = BHI_MITIGATION_VMEXIT_ONLY;
+	else
 		bhi_mitigation = BHI_MITIGATION_OFF;
-	}
 }
 
 static void __init bhi_update_mitigation(void)