[PATCH v4 01/10] x86/bugs: Only log missing retpoline when it's actually the missing mitigation

From: Kim Phillips

Date: Tue Aug 04 2026 - 20:02:43 EST


spectre_v2_select_retpoline() unconditionally emits a pr_err when the
kernel lacks retpoline support before returning SPECTRE_V2_NONE to its
callers. A caller may then select an alternative mitigation, making the
"no mitigation available!" message alarming and misleading to
administrators on a system that is actually mitigated.

Drop the pr_err from the helper and emit it once from
spectre_v2_update_mitigation(). Guard it on
!IS_ENABLED(CONFIG_MITIGATION_RETPOLINE) so it only fires when retpoline
truly cannot be built in, and restrict it to the cases where retpoline
was the implied choice: SPECTRE_V2_CMD_FORCE, or SPECTRE_V2_CMD_AUTO
when should_mitigate_vuln(X86_BUG_SPECTRE_V2) indicates we actually
intended to mitigate. This avoids the spurious error on a
CONFIG_MITIGATION_RETPOLINE=n kernel where a caller of
spectre_v2_select_retpoline() selects an alternative mitigation, leaving
the system protected while the old message claimed otherwise.

Cc: stable@xxxxxxxxxx
Signed-off-by: Kim Phillips <kim.phillips@xxxxxxx>
Assisted-by: ClaudeCode:claude-opus-4-7
---
arch/x86/kernel/cpu/bugs.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c
index ddf0db5326fa..b345f64f4258 100644
--- a/arch/x86/kernel/cpu/bugs.c
+++ b/arch/x86/kernel/cpu/bugs.c
@@ -1956,10 +1956,8 @@ early_param("spectre_v2", spectre_v2_parse_cmdline);

static enum spectre_v2_mitigation __init spectre_v2_select_retpoline(void)
{
- if (!IS_ENABLED(CONFIG_MITIGATION_RETPOLINE)) {
- pr_err("Kernel not compiled with retpoline; no mitigation available!");
+ if (!IS_ENABLED(CONFIG_MITIGATION_RETPOLINE))
return SPECTRE_V2_NONE;
- }

return SPECTRE_V2_RETPOLINE;
}
@@ -2247,6 +2245,13 @@ static void __init spectre_v2_update_mitigation(void)
}
}

+ if (!IS_ENABLED(CONFIG_MITIGATION_RETPOLINE) &&
+ spectre_v2_enabled == SPECTRE_V2_NONE &&
+ (spectre_v2_cmd == SPECTRE_V2_CMD_FORCE ||
+ (spectre_v2_cmd == SPECTRE_V2_CMD_AUTO &&
+ should_mitigate_vuln(X86_BUG_SPECTRE_V2))))
+ pr_err("Kernel not compiled with retpoline; no mitigation available!");
+
if (boot_cpu_has_bug(X86_BUG_SPECTRE_V2))
pr_info("%s\n", spectre_v2_strings[spectre_v2_enabled]);
}
--
2.43.0