Skip to content

Commit ac5bd67

Browse files
committed
x86/bugs: Fix spectre_v2 forcing
JIRA: https://issues.redhat.com/browse/RHEL-119227 commit 30ef245 Author: David Kaplan <david.kaplan@amd.com> Date: Mon, 15 Sep 2025 08:47:04 -0500 x86/bugs: Fix spectre_v2 forcing There were two oddities with spectre_v2 command line options. First, any option other than 'off' or 'auto' would force spectre_v2 mitigations even if the CPU (hypothetically) wasn't vulnerable to spectre_v2. That was inconsistent with all the other bugs where mitigations are ignored unless an explicit 'force' option is specified. Second, even though spectre_v2 mitigations would be enabled in these cases, the X86_BUG_SPECTRE_V2 bit wasn't set. This is again inconsistent with the forcing behavior of other bugs and arguably incorrect as it doesn't make sense to enable a mitigation if the X86_BUG bit isn't set. Fix both issues by only forcing spectre_v2 mitigations when the 'spectre_v2=on' option is specified (which was already called SPECTRE_V2_CMD_FORCE) and setting the relevant X86_BUG_* bits in that case. This also allows for simplifying bhi_update_mitigation() because spectre_v2_cmd will now always be SPECTRE_V2_CMD_NONE if the CPU is immune to spectre_v2. Signed-off-by: David Kaplan <david.kaplan@amd.com> Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de> Link: https://lore.kernel.org/20250915134706.3201818-1-david.kaplan@amd.com Signed-off-by: Waiman Long <longman@redhat.com>
1 parent b0c6499 commit ac5bd67

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

arch/x86/kernel/cpu/bugs.c

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2057,29 +2057,32 @@ static int __init spectre_v2_parse_cmdline(char *str)
20572057
if (nospectre_v2)
20582058
return 0;
20592059

2060-
if (!strcmp(str, "off"))
2060+
if (!strcmp(str, "off")) {
20612061
spectre_v2_cmd = SPECTRE_V2_CMD_NONE;
2062-
else if (!strcmp(str, "on"))
2062+
} else if (!strcmp(str, "on")) {
20632063
spectre_v2_cmd = SPECTRE_V2_CMD_FORCE;
2064-
else if (!strcmp(str, "retpoline"))
2064+
setup_force_cpu_bug(X86_BUG_SPECTRE_V2);
2065+
setup_force_cpu_bug(X86_BUG_SPECTRE_V2_USER);
2066+
} else if (!strcmp(str, "retpoline")) {
20652067
spectre_v2_cmd = SPECTRE_V2_CMD_RETPOLINE;
2066-
else if (!strcmp(str, "retpoline,amd") ||
2067-
!strcmp(str, "retpoline,lfence"))
2068+
} else if (!strcmp(str, "retpoline,amd") ||
2069+
!strcmp(str, "retpoline,lfence")) {
20682070
spectre_v2_cmd = SPECTRE_V2_CMD_RETPOLINE_LFENCE;
2069-
else if (!strcmp(str, "retpoline,generic"))
2071+
} else if (!strcmp(str, "retpoline,generic")) {
20702072
spectre_v2_cmd = SPECTRE_V2_CMD_RETPOLINE_GENERIC;
2071-
else if (!strcmp(str, "eibrs"))
2073+
} else if (!strcmp(str, "eibrs")) {
20722074
spectre_v2_cmd = SPECTRE_V2_CMD_EIBRS;
2073-
else if (!strcmp(str, "eibrs,lfence"))
2075+
} else if (!strcmp(str, "eibrs,lfence")) {
20742076
spectre_v2_cmd = SPECTRE_V2_CMD_EIBRS_LFENCE;
2075-
else if (!strcmp(str, "eibrs,retpoline"))
2077+
} else if (!strcmp(str, "eibrs,retpoline")) {
20762078
spectre_v2_cmd = SPECTRE_V2_CMD_EIBRS_RETPOLINE;
2077-
else if (!strcmp(str, "auto"))
2079+
} else if (!strcmp(str, "auto")) {
20782080
spectre_v2_cmd = SPECTRE_V2_CMD_AUTO;
2079-
else if (!strcmp(str, "ibrs"))
2081+
} else if (!strcmp(str, "ibrs")) {
20802082
spectre_v2_cmd = SPECTRE_V2_CMD_IBRS;
2081-
else
2083+
} else {
20822084
pr_err("Ignoring unknown spectre_v2 option (%s).", str);
2085+
}
20832086

20842087
return 0;
20852088
}
@@ -2232,10 +2235,6 @@ static void __init bhi_update_mitigation(void)
22322235
{
22332236
if (spectre_v2_cmd == SPECTRE_V2_CMD_NONE)
22342237
bhi_mitigation = BHI_MITIGATION_OFF;
2235-
2236-
if (!boot_cpu_has_bug(X86_BUG_SPECTRE_V2) &&
2237-
spectre_v2_cmd == SPECTRE_V2_CMD_AUTO)
2238-
bhi_mitigation = BHI_MITIGATION_OFF;
22392238
}
22402239

22412240
static void __init bhi_apply_mitigation(void)
@@ -2316,9 +2315,10 @@ static void __init spectre_v2_select_mitigation(void)
23162315
spectre_v2_cmd = SPECTRE_V2_CMD_AUTO;
23172316
}
23182317

2319-
if (!boot_cpu_has_bug(X86_BUG_SPECTRE_V2) &&
2320-
(spectre_v2_cmd == SPECTRE_V2_CMD_NONE || spectre_v2_cmd == SPECTRE_V2_CMD_AUTO))
2318+
if (!boot_cpu_has_bug(X86_BUG_SPECTRE_V2)) {
2319+
spectre_v2_cmd = SPECTRE_V2_CMD_NONE;
23212320
return;
2321+
}
23222322

23232323
switch (spectre_v2_cmd) {
23242324
case SPECTRE_V2_CMD_NONE:

0 commit comments

Comments
 (0)