Skip to contentSkip to conversation

Bugs clean-up

PATCH Applied David Kaplan 5 participants 27 messages Aug 19, 2025 – Aug 28, 2025

Subsystems (3)

v2 of 3 Applied Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover Bugs clean-up

Patches 1-3 focus on cleaning up parameter parsing. Most mitigations use early_param but a few older ones do not and look at boot_command_line directly. Modify those to be consistent with the newer ones.

Patch 4 adds missing attack vector controls for spec store bypass.

Patch 5 cleans up straggling unnecessary calls to cpu_mitigations_off().

Changes from v1
- Removed spec_*_print_cond() functions
- Fixed bugs pointed out by Pawan
- Added last 2 patches

David Kaplan (5):
x86/bugs: Use early_param for spectre_v2_user
x86/bugs: Use early_param for spectre_v2
x86/bugs: Simplify SSB cmdline parsing
x86/bugs: Add attack vector controls for SSB
x86/bugs: Remove uses of cpu_mitigations_off()

 .../hw-vuln/attack_vector_controls.rst        |   5 +-
 arch/x86/include/asm/nospec-branch.h          |   1 +
 arch/x86/kernel/cpu/bugs.c                    | 387 ++++++++----------
 3 files changed, 169 insertions(+), 224 deletions(-)

base-commit: 2fd6a6194558303fffd2d7a7fa73fc318d680f38

Signature · 1 line
2.34.1
#1 lore raw

PATCH v2 1/5 x86/bugs: Use early_param for spectre_v2_user

Most of the mitigations in bugs.c use early_param to parse their command line options. Modify spectre_v2_user to use early_param for consistency.

Remove spec_v2_user_print_cond() because informing a user about their cmdline choice isn't very interesting and the chosen mitigation is already printed in spectre_v2_user_update_mitigation().

---
 arch/x86/kernel/cpu/bugs.c | 65 +++++++++++++++-----------------------
 1 file changed, 26 insertions(+), 39 deletions(-)
arch/x86/kernel/cpu/bugs.c +26 -39
index 49ef1b832c1a..de78b76ae851 100644
@@ -1826,7 +1826,7 @@ enum spectre_v2_mitigation_cmd {
 
 static enum spectre_v2_mitigation_cmd spectre_v2_cmd __ro_after_init = SPECTRE_V2_CMD_AUTO;
 
-enum spectre_v2_user_cmd {
+enum spectre_v2_user_mitigation_cmd {
 	SPECTRE_V2_USER_CMD_NONE,
 	SPECTRE_V2_USER_CMD_AUTO,
 	SPECTRE_V2_USER_CMD_FORCE,
@@ -1836,6 +1836,9 @@ enum spectre_v2_user_cmd {
 	SPECTRE_V2_USER_CMD_SECCOMP_IBPB,
 };
 
+static enum spectre_v2_user_mitigation_cmd spectre_v2_user_cmd __ro_after_init =
+	SPECTRE_V2_USER_CMD_AUTO;
+
 static const char * const spectre_v2_user_strings[] = {
 	[SPECTRE_V2_USER_NONE]			= "User space: Vulnerable",
 	[SPECTRE_V2_USER_STRICT]		= "User space: Mitigation: STIBP protection",
@@ -1844,50 +1847,34 @@ static const char * const spectre_v2_user_strings[] = {
 	[SPECTRE_V2_USER_SECCOMP]		= "User space: Mitigation: STIBP via seccomp and prctl",
 };
 
-static const struct {
-	const char			*option;
-	enum spectre_v2_user_cmd	cmd;
-	bool				secure;
-} v2_user_options[] __initconst = {
-	{ "auto",		SPECTRE_V2_USER_CMD_AUTO,		false },
-	{ "off",		SPECTRE_V2_USER_CMD_NONE,		false },
-	{ "on",			SPECTRE_V2_USER_CMD_FORCE,		true  },
-	{ "prctl",		SPECTRE_V2_USER_CMD_PRCTL,		false },
-	{ "prctl,ibpb",		SPECTRE_V2_USER_CMD_PRCTL_IBPB,		false },
-	{ "seccomp",		SPECTRE_V2_USER_CMD_SECCOMP,		false },
-	{ "seccomp,ibpb",	SPECTRE_V2_USER_CMD_SECCOMP_IBPB,	false },
-};
-
-static void __init spec_v2_user_print_cond(const char *reason, bool secure)
-{
-	if (boot_cpu_has_bug(X86_BUG_SPECTRE_V2) != secure)
-		pr_info("spectre_v2_user=%s forced on command line.\n", reason);
-}
-
-static enum spectre_v2_user_cmd __init spectre_v2_parse_user_cmdline(void)
+static int __init spectre_v2_parse_user_cmdline(char *str)
 {
-	char arg[20];
-	int ret, i;
+	if (!str)
+		return -EINVAL;
 
 	if (!IS_ENABLED(CONFIG_MITIGATION_SPECTRE_V2))
 		return SPECTRE_V2_USER_CMD_NONE;
 
-	ret = cmdline_find_option(boot_command_line, "spectre_v2_user",
-				  arg, sizeof(arg));
-	if (ret < 0)
-		return SPECTRE_V2_USER_CMD_AUTO;
-
-	for (i = 0; i < ARRAY_SIZE(v2_user_options); i++) {
-		if (match_option(arg, ret, v2_user_options[i].option)) {
-			spec_v2_user_print_cond(v2_user_options[i].option,
-						v2_user_options[i].secure);
-			return v2_user_options[i].cmd;
-		}
-	}
+	if (!strcmp(str, "auto"))
+		spectre_v2_user_cmd = SPECTRE_V2_USER_CMD_AUTO;
+	else if (!strcmp(str, "off"))
+		spectre_v2_user_cmd = SPECTRE_V2_USER_CMD_NONE;
+	else if (!strcmp(str, "on"))
+		spectre_v2_user_cmd = SPECTRE_V2_USER_CMD_FORCE;
+	else if (!strcmp(str, "prctl"))
+		spectre_v2_user_cmd = SPECTRE_V2_USER_CMD_PRCTL;
+	else if (!strcmp(str, "prctl,ibpb"))
+		spectre_v2_user_cmd = SPECTRE_V2_USER_CMD_PRCTL_IBPB;
+	else if (!strcmp(str, "seccomp"))
+		spectre_v2_user_cmd = SPECTRE_V2_USER_CMD_SECCOMP;
+	else if (!strcmp(str, "seccomp,ibpb"))
+		spectre_v2_user_cmd = SPECTRE_V2_USER_CMD_SECCOMP_IBPB;
+	else
+		pr_err("Ignoring unknown spectre_v2_user option (%s).", str);
 
-	pr_err("Unknown user space protection option (%s). Switching to default\n", arg);
-	return SPECTRE_V2_USER_CMD_AUTO;
+	return 0;
 }
+early_param("spectre_v2_user", spectre_v2_parse_user_cmdline);
 
 static inline bool spectre_v2_in_ibrs_mode(enum spectre_v2_mitigation mode)
 {
@@ -1899,7 +1886,7 @@ static void __init spectre_v2_user_select_mitigation(void)
 	if (!boot_cpu_has(X86_FEATURE_IBPB) && !boot_cpu_has(X86_FEATURE_STIBP))
 		return;
 
-	switch (spectre_v2_parse_user_cmdline()) {
+	switch (spectre_v2_user_cmd) {
 	case SPECTRE_V2_USER_CMD_NONE:
 		return;
 	case SPECTRE_V2_USER_CMD_FORCE:
Signature · 1 line
2.34.1
maintainer Reviewed-by on v2 1/5
#2 lore raw

Re: [PATCH v2 1/5] x86/bugs: Use early_param for spectre_v2_user

Quoted 11 lines · David Kaplan

Most of the mitigations in bugs.c use early_param to parse their command line options. Modify spectre_v2_user to use early_param for consistency.

Remove spec_v2_user_print_cond() because informing a user about their cmdline choice isn't very interesting and the chosen mitigation is already printed in spectre_v2_user_update_mitigation().

---
 arch/x86/kernel/cpu/bugs.c | 65 +++++++++++++++-----------------------
 1 file changed, 26 insertions(+), 39 deletions(-)
Signature · 4 lines
Regards/Gruss,
    Boris.

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

Re: [PATCH v2 1/5] x86/bugs: Use early_param for spectre_v2_user

In reply to David Kaplan
Quoted 11 lines · David Kaplan

+++ b/arch/x86/kernel/cpu/bugs.c

arch/x86/kernel/cpu/bugs.c +1 -1
@@ -1826,7 +1826,7 @@ enum spectre_v2_mitigation_cmd {
 
 static enum spectre_v2_mitigation_cmd spectre_v2_cmd __ro_after_init = SPECTRE_V2_CMD_AUTO;
 
-enum spectre_v2_user_cmd {
+enum spectre_v2_user_mitigation_cmd {
 	SPECTRE_V2_USER_CMD_NONE,
 	SPECTRE_V2_USER_CMD_AUTO,
 	SPECTRE_V2_USER_CMD_FORCE,

arch/x86/kernel/cpu/bugs.c enum spectre_v2_user_cmd { · line 1840

Quoted 5 lines
arch/x86/kernel/cpu/bugs.c +2 -0
@@ -1836,6 +1836,9 @@ enum spectre_v2_user_cmd {
 	SPECTRE_V2_USER_CMD_SECCOMP_IBPB,
 };
 
+static enum spectre_v2_user_mitigation_cmd spectre_v2_user_cmd __ro_after_init =
+	SPECTRE_V2_USER_CMD_AUTO;

Should this default not be dependent on CONFIG_MITIGATION_SPECTRE_V2?

arch/x86/kernel/cpu/bugs.c static const char * const spectre_v2_user_strings[] = { · line 1850

Quoted 2 lines
arch/x86/kernel/cpu/bugs.c +1 -1
-static enum spectre_v2_user_cmd __init spectre_v2_parse_user_cmdline(void)
+static int __init spectre_v2_parse_user_cmdline(char *str)

Should probably swap "parse" and "user" to match the namespace of the surrounding code, i.e. spectre_v2_user_parse_cmdline(). This is for parsing the "spectre_v2_user" option after all.

arch/x86/kernel/cpu/bugs.c static const char * const spectre_v2_user_strings[] = { · line 1856

Quoted 8 lines
arch/x86/kernel/cpu/bugs.c +2 -2
 {
-	char arg[20];
-	int ret, i;
+	if (!str)
+		return -EINVAL;
 
 	if (!IS_ENABLED(CONFIG_MITIGATION_SPECTRE_V2))
 		return SPECTRE_V2_USER_CMD_NONE;

This return value no longer makes sense here, as this no longer returns 'enum spectre_v2_user_cmd'.

But also, most of the other mitigations allow you to override the compile time default with the cmdline. Might as well allow that here too for consistency.

Signature · 1 line
Josh
#4 lore raw

RE: [PATCH v2 1/5] x86/bugs: Use early_param for spectre_v2_user

[AMD Official Use Only - AMD Internal Distribution Only]

Quoted 31 lines

-----Original Message-----
From: Josh Poimboeuf <[email protected]>
Sent: Wednesday, August 27, 2025 4:52 PM
To: Kaplan, David <[email protected]>
Cc: Thomas Gleixner <[email protected]>; Borislav Petkov <[email protected]>; Peter Zijlstra <[email protected]>; Pawan Gupta <[email protected]>; Ingo Molnar <[email protected]>; Dave Hansen <[email protected]>; [email protected]; H . Peter Anvin <[email protected]>; [email protected]
Subject: Re: [PATCH v2 1/5] x86/bugs: Use early_param for spectre_v2_user

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

Review enum spectre_v2_mitigation_cmd { · line 1827

Quoted 4 lines · David Kaplan

+++ b/arch/x86/kernel/cpu/bugs.c

(quoted diff) +0 -0
@@ -1826,7 +1826,7 @@ enum spectre_v2_mitigation_cmd {
 
 static enum spectre_v2_mitigation_cmd spectre_v2_cmd __ro_after_init =

SPECTRE_V2_CMD_AUTO;

Quoted 10 lines
arch/x86/kernel/cpu/bugs.c +1 -1
-enum spectre_v2_user_cmd {
+enum spectre_v2_user_mitigation_cmd {
      SPECTRE_V2_USER_CMD_NONE,
      SPECTRE_V2_USER_CMD_AUTO,
      SPECTRE_V2_USER_CMD_FORCE,
@@ -1836,6 +1836,9 @@ enum spectre_v2_user_cmd {
      SPECTRE_V2_USER_CMD_SECCOMP_IBPB,
 };
 
Quoted 5 lines

Review enum spectre_v2_user_cmd { · line 1839

Quoted 1 line
(quoted diff) +1 -0
+static enum spectre_v2_user_mitigation_cmd spectre_v2_user_cmd

__ro_after_init =

arch/x86/kernel/cpu/bugs.c enum spectre_v2_user_cmd { · line 1840

Quoted 1 line
arch/x86/kernel/cpu/bugs.c +1 -0
+     SPECTRE_V2_USER_CMD_AUTO;

Should this default not be dependent on CONFIG_MITIGATION_SPECTRE_V2?

Ah, good catch. Yes, it should be looking at that.

Quoted 7 lines

arch/x86/kernel/cpu/bugs.c static const char * const spectre_v2_user_strings[] = { · line 1850

Quoted 3 lines
arch/x86/kernel/cpu/bugs.c +1 -1
-static enum spectre_v2_user_cmd __init spectre_v2_parse_user_cmdline(void)
+static int __init spectre_v2_parse_user_cmdline(char *str)

Should probably swap "parse" and "user" to match the namespace of the surrounding code, i.e. spectre_v2_user_parse_cmdline(). This is for parsing the "spectre_v2_user" option after all.

Ok

Quoted 7 lines
Quoted 7 lines
arch/x86/kernel/cpu/bugs.c +2 -2
 {
-     char arg[20];
-     int ret, i;
+     if (!str)
+             return -EINVAL;
Quoted 5 lines
Quoted 2 lines
      if (!IS_ENABLED(CONFIG_MITIGATION_SPECTRE_V2))
              return SPECTRE_V2_USER_CMD_NONE;

This return value no longer makes sense here, as this no longer returns 'enum spectre_v2_user_cmd'.

Yeah, this should be removed. And the check should be in the initialization as noted above.

Quoted 5 lines

But also, most of the other mitigations allow you to override the compile time default with the cmdline. Might as well allow that here too for consistency.

Agreed, and with the check removed that should happen correctly.

Thanks
--David Kaplan

#5 lore raw

PATCH v2 2/5 x86/bugs: Use early_param for spectre_v2

In reply to David Kaplan

Most of the mitigations in bugs.c use early_param for command line parsing. Rework the spectre_v2 and nospectre_v2 command line options to be consistent with the others.

Remove spec_v2_print_cond() as informing the user of the their cmdline choice isn't interesting.

---
 arch/x86/kernel/cpu/bugs.c | 186 +++++++++++++++++--------------------
 1 file changed, 87 insertions(+), 99 deletions(-)
arch/x86/kernel/cpu/bugs.c +87 -99
index de78b76ae851..44e0315b58a5 100644
@@ -1824,7 +1824,8 @@ enum spectre_v2_mitigation_cmd {
 	SPECTRE_V2_CMD_IBRS,
 };
 
-static enum spectre_v2_mitigation_cmd spectre_v2_cmd __ro_after_init = SPECTRE_V2_CMD_AUTO;
+static enum spectre_v2_mitigation_cmd spectre_v2_cmd __ro_after_init =
+	IS_ENABLED(CONFIG_MITIGATION_SPECTRE_V2) ? SPECTRE_V2_CMD_AUTO : SPECTRE_V2_CMD_NONE;
 
 enum spectre_v2_user_mitigation_cmd {
 	SPECTRE_V2_USER_CMD_NONE,
@@ -2021,112 +2022,51 @@ static const char * const spectre_v2_strings[] = {
 	[SPECTRE_V2_IBRS]			= "Mitigation: IBRS",
 };
 
-static const struct {
-	const char *option;
-	enum spectre_v2_mitigation_cmd cmd;
-	bool secure;
-} mitigation_options[] __initconst = {
-	{ "off",		SPECTRE_V2_CMD_NONE,		  false },
-	{ "on",			SPECTRE_V2_CMD_FORCE,		  true  },
-	{ "retpoline",		SPECTRE_V2_CMD_RETPOLINE,	  false },
-	{ "retpoline,amd",	SPECTRE_V2_CMD_RETPOLINE_LFENCE,  false },
-	{ "retpoline,lfence",	SPECTRE_V2_CMD_RETPOLINE_LFENCE,  false },
-	{ "retpoline,generic",	SPECTRE_V2_CMD_RETPOLINE_GENERIC, false },
-	{ "eibrs",		SPECTRE_V2_CMD_EIBRS,		  false },
-	{ "eibrs,lfence",	SPECTRE_V2_CMD_EIBRS_LFENCE,	  false },
-	{ "eibrs,retpoline",	SPECTRE_V2_CMD_EIBRS_RETPOLINE,	  false },
-	{ "auto",		SPECTRE_V2_CMD_AUTO,		  false },
-	{ "ibrs",		SPECTRE_V2_CMD_IBRS,              false },
-};
+static bool nospectre_v2 __ro_after_init;
 
-static void __init spec_v2_print_cond(const char *reason, bool secure)
+static int __init nospectre_v2_parse_cmdline(char *str)
 {
-	if (boot_cpu_has_bug(X86_BUG_SPECTRE_V2) != secure)
-		pr_info("%s selected on command line.\n", reason);
+	nospectre_v2 = true;
+	spectre_v2_cmd = SPECTRE_V2_CMD_NONE;
+	return 0;
 }
+early_param("nospectre_v2", nospectre_v2_parse_cmdline);
 
-static enum spectre_v2_mitigation_cmd __init spectre_v2_parse_cmdline(void)
+static int __init spectre_v2_parse_cmdline(char *str)
 {
-	enum spectre_v2_mitigation_cmd cmd;
-	char arg[20];
-	int ret, i;
-
-	cmd = IS_ENABLED(CONFIG_MITIGATION_SPECTRE_V2) ?  SPECTRE_V2_CMD_AUTO : SPECTRE_V2_CMD_NONE;
-	if (cmdline_find_option_bool(boot_command_line, "nospectre_v2"))
-		return SPECTRE_V2_CMD_NONE;
-
-	ret = cmdline_find_option(boot_command_line, "spectre_v2", arg, sizeof(arg));
-	if (ret < 0)
-		return cmd;
-
-	for (i = 0; i < ARRAY_SIZE(mitigation_options); i++) {
-		if (!match_option(arg, ret, mitigation_options[i].option))
-			continue;
-		cmd = mitigation_options[i].cmd;
-		break;
-	}
-
-	if (i >= ARRAY_SIZE(mitigation_options)) {
-		pr_err("unknown option (%s). Switching to default mode\n", arg);
-		return cmd;
-	}
-
-	if ((cmd == SPECTRE_V2_CMD_RETPOLINE ||
-	     cmd == SPECTRE_V2_CMD_RETPOLINE_LFENCE ||
-	     cmd == SPECTRE_V2_CMD_RETPOLINE_GENERIC ||
-	     cmd == SPECTRE_V2_CMD_EIBRS_LFENCE ||
-	     cmd == SPECTRE_V2_CMD_EIBRS_RETPOLINE) &&
-	    !IS_ENABLED(CONFIG_MITIGATION_RETPOLINE)) {
-		pr_err("%s selected but not compiled in. Switching to AUTO select\n",
-		       mitigation_options[i].option);
-		return SPECTRE_V2_CMD_AUTO;
-	}
-
-	if ((cmd == SPECTRE_V2_CMD_EIBRS ||
-	     cmd == SPECTRE_V2_CMD_EIBRS_LFENCE ||
-	     cmd == SPECTRE_V2_CMD_EIBRS_RETPOLINE) &&
-	    !boot_cpu_has(X86_FEATURE_IBRS_ENHANCED)) {
-		pr_err("%s selected but CPU doesn't have Enhanced or Automatic IBRS. Switching to AUTO select\n",
-		       mitigation_options[i].option);
-		return SPECTRE_V2_CMD_AUTO;
-	}
-
-	if ((cmd == SPECTRE_V2_CMD_RETPOLINE_LFENCE ||
-	     cmd == SPECTRE_V2_CMD_EIBRS_LFENCE) &&
-	    !boot_cpu_has(X86_FEATURE_LFENCE_RDTSC)) {
-		pr_err("%s selected, but CPU doesn't have a serializing LFENCE. Switching to AUTO select\n",
-		       mitigation_options[i].option);
-		return SPECTRE_V2_CMD_AUTO;
-	}
-
-	if (cmd == SPECTRE_V2_CMD_IBRS && !IS_ENABLED(CONFIG_MITIGATION_IBRS_ENTRY)) {
-		pr_err("%s selected but not compiled in. Switching to AUTO select\n",
-		       mitigation_options[i].option);
-		return SPECTRE_V2_CMD_AUTO;
-	}
-
-	if (cmd == SPECTRE_V2_CMD_IBRS && boot_cpu_data.x86_vendor != X86_VENDOR_INTEL) {
-		pr_err("%s selected but not Intel CPU. Switching to AUTO select\n",
-		       mitigation_options[i].option);
-		return SPECTRE_V2_CMD_AUTO;
-	}
+	if (!str)
+		return -EINVAL;
 
-	if (cmd == SPECTRE_V2_CMD_IBRS && !boot_cpu_has(X86_FEATURE_IBRS)) {
-		pr_err("%s selected but CPU doesn't have IBRS. Switching to AUTO select\n",
-		       mitigation_options[i].option);
-		return SPECTRE_V2_CMD_AUTO;
-	}
+	if (nospectre_v2)
+		return 0;
 
-	if (cmd == SPECTRE_V2_CMD_IBRS && cpu_feature_enabled(X86_FEATURE_XENPV)) {
-		pr_err("%s selected but running as XenPV guest. Switching to AUTO select\n",
-		       mitigation_options[i].option);
-		return SPECTRE_V2_CMD_AUTO;
-	}
+	if (!strcmp(str, "off"))
+		spectre_v2_cmd = SPECTRE_V2_CMD_NONE;
+	else if (!strcmp(str, "on"))
+		spectre_v2_cmd = SPECTRE_V2_CMD_FORCE;
+	else if (!strcmp(str, "retpoline"))
+		spectre_v2_cmd = SPECTRE_V2_CMD_RETPOLINE;
+	else if (!strcmp(str, "retpoline,amd") ||
+		 !strcmp(str, "retpoline,lfence"))
+		spectre_v2_cmd = SPECTRE_V2_CMD_RETPOLINE_LFENCE;
+	else if (!strcmp(str, "retpoline,generic"))
+		spectre_v2_cmd = SPECTRE_V2_CMD_RETPOLINE_GENERIC;
+	else if (!strcmp(str, "eibrs"))
+		spectre_v2_cmd = SPECTRE_V2_CMD_EIBRS;
+	else if (!strcmp(str, "eibrs,lfence"))
+		spectre_v2_cmd = SPECTRE_V2_CMD_EIBRS_LFENCE;
+	else if (!strcmp(str, "eibrs,retpoline"))
+		spectre_v2_cmd = SPECTRE_V2_CMD_EIBRS_RETPOLINE;
+	else if (!strcmp(str, "auto"))
+		spectre_v2_cmd = SPECTRE_V2_CMD_AUTO;
+	else if (!strcmp(str, "ibrs"))
+		spectre_v2_cmd = SPECTRE_V2_CMD_IBRS;
+	else
+		pr_err("Ignoring unknown spectre_v2 option (%s).", str);
 
-	spec_v2_print_cond(mitigation_options[i].option,
-			   mitigation_options[i].secure);
-	return cmd;
+	return 0;
 }
+early_param("spectre_v2", spectre_v2_parse_cmdline);
 
 static enum spectre_v2_mitigation __init spectre_v2_select_retpoline(void)
 {
@@ -2312,9 +2252,57 @@ static void __init bhi_apply_mitigation(void)
 	setup_force_cpu_cap(X86_FEATURE_CLEAR_BHB_VMEXIT);
 }
 
+static void __init spectre_v2_check_cmd(void)
+{
+	if ((spectre_v2_cmd == SPECTRE_V2_CMD_RETPOLINE ||
+	     spectre_v2_cmd == SPECTRE_V2_CMD_RETPOLINE_LFENCE ||
+	     spectre_v2_cmd == SPECTRE_V2_CMD_RETPOLINE_GENERIC ||
+	     spectre_v2_cmd == SPECTRE_V2_CMD_EIBRS_LFENCE ||
+	     spectre_v2_cmd == SPECTRE_V2_CMD_EIBRS_RETPOLINE) &&
+	    !IS_ENABLED(CONFIG_MITIGATION_RETPOLINE)) {
+		pr_err("RETPOLINE selected but not compiled in. Switching to AUTO select\n");
+		spectre_v2_cmd = SPECTRE_V2_CMD_AUTO;
+	}
+
+	if ((spectre_v2_cmd == SPECTRE_V2_CMD_EIBRS ||
+	     spectre_v2_cmd == SPECTRE_V2_CMD_EIBRS_LFENCE ||
+	     spectre_v2_cmd == SPECTRE_V2_CMD_EIBRS_RETPOLINE) &&
+	    !boot_cpu_has(X86_FEATURE_IBRS_ENHANCED)) {
+		pr_err("EIBRS selected but CPU doesn't have Enhanced or Automatic IBRS. Switching to AUTO select\n");
+		spectre_v2_cmd = SPECTRE_V2_CMD_AUTO;
+	}
+
+	if ((spectre_v2_cmd == SPECTRE_V2_CMD_RETPOLINE_LFENCE ||
+	     spectre_v2_cmd == SPECTRE_V2_CMD_EIBRS_LFENCE) &&
+	    !boot_cpu_has(X86_FEATURE_LFENCE_RDTSC)) {
+		pr_err("LFENCE selected, but CPU doesn't have a serializing LFENCE. Switching to AUTO select\n");
+		spectre_v2_cmd = SPECTRE_V2_CMD_AUTO;
+	}
+
+	if (spectre_v2_cmd == SPECTRE_V2_CMD_IBRS && !IS_ENABLED(CONFIG_MITIGATION_IBRS_ENTRY)) {
+		pr_err("IBRS selected but not compiled in. Switching to AUTO select\n");
+		spectre_v2_cmd = SPECTRE_V2_CMD_AUTO;
+	}
+
+	if (spectre_v2_cmd == SPECTRE_V2_CMD_IBRS && boot_cpu_data.x86_vendor != X86_VENDOR_INTEL) {
+		pr_err("IBRS selected but not Intel CPU. Switching to AUTO select\n");
+		spectre_v2_cmd = SPECTRE_V2_CMD_AUTO;
+	}
+
+	if (spectre_v2_cmd == SPECTRE_V2_CMD_IBRS && !boot_cpu_has(X86_FEATURE_IBRS)) {
+		pr_err("IBRS selected but CPU doesn't have IBRS. Switching to AUTO select\n");
+		spectre_v2_cmd = SPECTRE_V2_CMD_AUTO;
+	}
+
+	if (spectre_v2_cmd == SPECTRE_V2_CMD_IBRS && cpu_feature_enabled(X86_FEATURE_XENPV)) {
+		pr_err("IBRS selected but running as XenPV guest. Switching to AUTO select\n");
+		spectre_v2_cmd = SPECTRE_V2_CMD_AUTO;
+	}
+}
+
 static void __init spectre_v2_select_mitigation(void)
 {
-	spectre_v2_cmd = spectre_v2_parse_cmdline();
+	spectre_v2_check_cmd();
 
 	if (!boot_cpu_has_bug(X86_BUG_SPECTRE_V2) &&
 	    (spectre_v2_cmd == SPECTRE_V2_CMD_NONE || spectre_v2_cmd == SPECTRE_V2_CMD_AUTO))
Signature · 1 line
2.34.1
maintainer
#6 lore raw

Re: [PATCH v2 2/5] x86/bugs: Use early_param for spectre_v2

Quoted 1 line · David Kaplan

+static void __init spectre_v2_check_cmd(void)

Why the separate function?

This can simply go in spectre_v2_select_mitigation() before the switch-case like with all the others *_select_mitigation() functions...

Quoted 57 lines
arch/x86/kernel/cpu/bugs.c +48 -1
+{
+	if ((spectre_v2_cmd == SPECTRE_V2_CMD_RETPOLINE ||
+	     spectre_v2_cmd == SPECTRE_V2_CMD_RETPOLINE_LFENCE ||
+	     spectre_v2_cmd == SPECTRE_V2_CMD_RETPOLINE_GENERIC ||
+	     spectre_v2_cmd == SPECTRE_V2_CMD_EIBRS_LFENCE ||
+	     spectre_v2_cmd == SPECTRE_V2_CMD_EIBRS_RETPOLINE) &&
+	    !IS_ENABLED(CONFIG_MITIGATION_RETPOLINE)) {
+		pr_err("RETPOLINE selected but not compiled in. Switching to AUTO select\n");
+		spectre_v2_cmd = SPECTRE_V2_CMD_AUTO;
+	}
+
+	if ((spectre_v2_cmd == SPECTRE_V2_CMD_EIBRS ||
+	     spectre_v2_cmd == SPECTRE_V2_CMD_EIBRS_LFENCE ||
+	     spectre_v2_cmd == SPECTRE_V2_CMD_EIBRS_RETPOLINE) &&
+	    !boot_cpu_has(X86_FEATURE_IBRS_ENHANCED)) {
+		pr_err("EIBRS selected but CPU doesn't have Enhanced or Automatic IBRS. Switching to AUTO select\n");
+		spectre_v2_cmd = SPECTRE_V2_CMD_AUTO;
+	}
+
+	if ((spectre_v2_cmd == SPECTRE_V2_CMD_RETPOLINE_LFENCE ||
+	     spectre_v2_cmd == SPECTRE_V2_CMD_EIBRS_LFENCE) &&
+	    !boot_cpu_has(X86_FEATURE_LFENCE_RDTSC)) {
+		pr_err("LFENCE selected, but CPU doesn't have a serializing LFENCE. Switching to AUTO select\n");
+		spectre_v2_cmd = SPECTRE_V2_CMD_AUTO;
+	}
+
+	if (spectre_v2_cmd == SPECTRE_V2_CMD_IBRS && !IS_ENABLED(CONFIG_MITIGATION_IBRS_ENTRY)) {
+		pr_err("IBRS selected but not compiled in. Switching to AUTO select\n");
+		spectre_v2_cmd = SPECTRE_V2_CMD_AUTO;
+	}
+
+	if (spectre_v2_cmd == SPECTRE_V2_CMD_IBRS && boot_cpu_data.x86_vendor != X86_VENDOR_INTEL) {
+		pr_err("IBRS selected but not Intel CPU. Switching to AUTO select\n");
+		spectre_v2_cmd = SPECTRE_V2_CMD_AUTO;
+	}
+
+	if (spectre_v2_cmd == SPECTRE_V2_CMD_IBRS && !boot_cpu_has(X86_FEATURE_IBRS)) {
+		pr_err("IBRS selected but CPU doesn't have IBRS. Switching to AUTO select\n");
+		spectre_v2_cmd = SPECTRE_V2_CMD_AUTO;
+	}
+
+	if (spectre_v2_cmd == SPECTRE_V2_CMD_IBRS && cpu_feature_enabled(X86_FEATURE_XENPV)) {
+		pr_err("IBRS selected but running as XenPV guest. Switching to AUTO select\n");
+		spectre_v2_cmd = SPECTRE_V2_CMD_AUTO;
+	}
+}
+
 static void __init spectre_v2_select_mitigation(void)
 {
-	spectre_v2_cmd = spectre_v2_parse_cmdline();
+	spectre_v2_check_cmd();
 
 	if (!boot_cpu_has_bug(X86_BUG_SPECTRE_V2) &&
 	    (spectre_v2_cmd == SPECTRE_V2_CMD_NONE || spectre_v2_cmd == SPECTRE_V2_CMD_AUTO))
Signature · 1 line
2.34.1
Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
#7 lore raw

RE: [PATCH v2 2/5] x86/bugs: Use early_param for spectre_v2

[AMD Official Use Only - AMD Internal Distribution Only]

Quoted 15 lines

-----Original Message-----
From: Borislav Petkov <[email protected]>
Sent: Friday, August 22, 2025 6:49 AM
To: Kaplan, David <[email protected]>
Cc: Thomas Gleixner <[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]>; [email protected]
Subject: Re: [PATCH v2 2/5] x86/bugs: Use early_param for spectre_v2

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

Quoted 7 lines
Quoted 1 line · David Kaplan

+static void __init spectre_v2_check_cmd(void)

Why the separate function?

This can simply go in spectre_v2_select_mitigation() before the switch-case like with all the others *_select_mitigation() functions...

It could, but I felt this was a way to logically separate the code vs having one giant function. All the code in spectre_v2_check_cmd() does one thing: verifies if the chosen command is possible on this system. The rest of spectre_v2_select_mitigation() then uses the cmd to actually pick a mitigation.

Since these were two distinct flows, I thought having a separate function made sense to make the code more readable. But that was just my opinion, I won't object if you want to inline it.

--David Kaplan

maintainer
#8 lore raw

Re: [PATCH v2 2/5] x86/bugs: Use early_param for spectre_v2

Quoted 9 lines · David

It could, but I felt this was a way to logically separate the code vs having one giant function. All the code in spectre_v2_check_cmd() does one thing:
verifies if the chosen command is possible on this system. The rest of spectre_v2_select_mitigation() then uses the cmd to actually pick a mitigation.

Since these were two distinct flows, I thought having a separate function made sense to make the code more readable. But that was just my opinion, I won't object if you want to inline it.

Right, since we're making all the mitigations handling uniform, I'd prefer to have the same code pattern here too. The function does get a bit big but it is clear that it does two things: (1) checks the command before it (2) selects the mitigation. And the others do the same so...

Thx.

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
#9 lore raw

RE: [PATCH v2 2/5] x86/bugs: Use early_param for spectre_v2

[AMD Official Use Only - AMD Internal Distribution Only]

Quoted 22 lines

-----Original Message-----
From: Borislav Petkov <[email protected]>
Sent: Friday, August 22, 2025 9:30 AM
To: Kaplan, David <[email protected]>
Cc: Thomas Gleixner <[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]>; [email protected]
Subject: Re: [PATCH v2 2/5] x86/bugs: Use early_param for spectre_v2

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

Quoted 6 lines · David

It could, but I felt this was a way to logically separate the code vs having one giant function. All the code in spectre_v2_check_cmd() does one thing:
verifies if the chosen command is possible on this system. The rest of spectre_v2_select_mitigation() then uses the cmd to actually pick a mitigation.

Quoted 9 lines
Quoted 3 lines

Since these were two distinct flows, I thought having a separate function made sense to make the code more readable. But that was just my opinion, I won't object if you want to inline it.

Right, since we're making all the mitigations handling uniform, I'd prefer to have the same code pattern here too. The function does get a bit big but it is clear that it does two things: (1) checks the command before it (2) selects the mitigation. And the others do the same so...

Sort of. Spectre_v2 is a bit unique is that it is more complicated than almost any other ones in terms of the number of options it has. There are 11 command line options for spectre_v2, the next closest one has 7. Spectre_v2 (and spectre_v2_user) are the only remaining mitigations where a 'cmd' is initially chosen instead of a mitigation because of all this complexity and checks that have to occur.

--David Kaplan

#10 lore raw

PATCH v2 3/5 x86/bugs: Simplify SSB cmdline parsing

In reply to David Kaplan

Simplify the SSB command line parsing by selecting a mitigation directly, as is done in most of the simpler vulnerabilities. Use early_param instead of cmdline_find_option for consistency with the other mitigation selections.

---
 arch/x86/kernel/cpu/bugs.c | 118 ++++++++++++-------------------------
 1 file changed, 39 insertions(+), 79 deletions(-)
arch/x86/kernel/cpu/bugs.c +39 -79
index 44e0315b58a5..8dc654ccdbb9 100644
@@ -2594,16 +2594,8 @@ void cpu_bugs_smt_update(void)
 #undef pr_fmt
 #define pr_fmt(fmt)	"Speculative Store Bypass: " fmt
 
-static enum ssb_mitigation ssb_mode __ro_after_init = SPEC_STORE_BYPASS_NONE;
-
-/* The kernel command line selection */
-enum ssb_mitigation_cmd {
-	SPEC_STORE_BYPASS_CMD_NONE,
-	SPEC_STORE_BYPASS_CMD_AUTO,
-	SPEC_STORE_BYPASS_CMD_ON,
-	SPEC_STORE_BYPASS_CMD_PRCTL,
-	SPEC_STORE_BYPASS_CMD_SECCOMP,
-};
+static enum ssb_mitigation ssb_mode __ro_after_init =
+	IS_ENABLED(CONFIG_MITIGATION_SSB) ? SPEC_STORE_BYPASS_PRCTL : SPEC_STORE_BYPASS_NONE;
 
 static const char * const ssb_strings[] = {
 	[SPEC_STORE_BYPASS_NONE]	= "Vulnerable",
@@ -2612,89 +2604,57 @@ static const char * const ssb_strings[] = {
 	[SPEC_STORE_BYPASS_SECCOMP]	= "Mitigation: Speculative Store Bypass disabled via prctl and seccomp",
 };
 
-static const struct {
-	const char *option;
-	enum ssb_mitigation_cmd cmd;
-} ssb_mitigation_options[]  __initconst = {
-	{ "auto",	SPEC_STORE_BYPASS_CMD_AUTO },    /* Platform decides */
-	{ "on",		SPEC_STORE_BYPASS_CMD_ON },      /* Disable Speculative Store Bypass */
-	{ "off",	SPEC_STORE_BYPASS_CMD_NONE },    /* Don't touch Speculative Store Bypass */
-	{ "prctl",	SPEC_STORE_BYPASS_CMD_PRCTL },   /* Disable Speculative Store Bypass via prctl */
-	{ "seccomp",	SPEC_STORE_BYPASS_CMD_SECCOMP }, /* Disable Speculative Store Bypass via prctl and seccomp */
-};
+static bool nossb __ro_after_init;
 
-static enum ssb_mitigation_cmd __init ssb_parse_cmdline(void)
+static int __init nossb_parse_cmdline(char *str)
 {
-	enum ssb_mitigation_cmd cmd;
-	char arg[20];
-	int ret, i;
+	nossb = true;
+	ssb_mode = SPEC_STORE_BYPASS_NONE;
+	return 0;
+}
+early_param("nospec_store_bypass_disable", nossb_parse_cmdline);
 
-	cmd = IS_ENABLED(CONFIG_MITIGATION_SSB) ?
-		SPEC_STORE_BYPASS_CMD_AUTO : SPEC_STORE_BYPASS_CMD_NONE;
-	if (cmdline_find_option_bool(boot_command_line, "nospec_store_bypass_disable") ||
-	    cpu_mitigations_off()) {
-		return SPEC_STORE_BYPASS_CMD_NONE;
-	} else {
-		ret = cmdline_find_option(boot_command_line, "spec_store_bypass_disable",
-					  arg, sizeof(arg));
-		if (ret < 0)
-			return cmd;
+static int __init ssb_parse_cmdline(char *str)
+{
+	if (!str)
+		return -EINVAL;
 
-		for (i = 0; i < ARRAY_SIZE(ssb_mitigation_options); i++) {
-			if (!match_option(arg, ret, ssb_mitigation_options[i].option))
-				continue;
+	if (!IS_ENABLED(CONFIG_MITIGATION_SSB))
+		return 0;
 
-			cmd = ssb_mitigation_options[i].cmd;
-			break;
-		}
+	if (nossb)
+		return 0;
 
-		if (i >= ARRAY_SIZE(ssb_mitigation_options)) {
-			pr_err("unknown option (%s). Switching to default mode\n", arg);
-			return cmd;
-		}
-	}
+	if (!strcmp(str, "auto"))
+		ssb_mode = SPEC_STORE_BYPASS_PRCTL;
+	else if (!strcmp(str, "on"))
+		ssb_mode = SPEC_STORE_BYPASS_DISABLE;
+	else if (!strcmp(str, "off"))
+		ssb_mode = SPEC_STORE_BYPASS_NONE;
+	else if (!strcmp(str, "prctl"))
+		ssb_mode = SPEC_STORE_BYPASS_PRCTL;
+	else if (!strcmp(str, "seccomp"))
+		ssb_mode = IS_ENABLED(CONFIG_SECCOMP) ?
+			SPEC_STORE_BYPASS_SECCOMP : SPEC_STORE_BYPASS_PRCTL;
+	else
+		pr_err("Ignoring unknown spec_store_bypass_disable option (%s).\n",
+			str);
 
-	return cmd;
+	return 0;
 }
+early_param("spec_store_bypass_disable", ssb_parse_cmdline);
 
 static void __init ssb_select_mitigation(void)
 {
-	enum ssb_mitigation_cmd cmd;
-
-	if (!boot_cpu_has(X86_FEATURE_SSBD))
-		goto out;
-
-	cmd = ssb_parse_cmdline();
-	if (!boot_cpu_has_bug(X86_BUG_SPEC_STORE_BYPASS) &&
-	    (cmd == SPEC_STORE_BYPASS_CMD_NONE ||
-	     cmd == SPEC_STORE_BYPASS_CMD_AUTO))
+	if (!boot_cpu_has_bug(X86_BUG_SPEC_STORE_BYPASS) || cpu_mitigations_off()) {
+		ssb_mode = SPEC_STORE_BYPASS_NONE;
 		return;
-
-	switch (cmd) {
-	case SPEC_STORE_BYPASS_CMD_SECCOMP:
-		/*
-		 * Choose prctl+seccomp as the default mode if seccomp is
-		 * enabled.
-		 */
-		if (IS_ENABLED(CONFIG_SECCOMP))
-			ssb_mode = SPEC_STORE_BYPASS_SECCOMP;
-		else
-			ssb_mode = SPEC_STORE_BYPASS_PRCTL;
-		break;
-	case SPEC_STORE_BYPASS_CMD_ON:
-		ssb_mode = SPEC_STORE_BYPASS_DISABLE;
-		break;
-	case SPEC_STORE_BYPASS_CMD_AUTO:
-	case SPEC_STORE_BYPASS_CMD_PRCTL:
-		ssb_mode = SPEC_STORE_BYPASS_PRCTL;
-		break;
-	case SPEC_STORE_BYPASS_CMD_NONE:
-		break;
 	}
 
-out:
-	if (boot_cpu_has_bug(X86_BUG_SPEC_STORE_BYPASS))
-		pr_info("%s\n", ssb_strings[ssb_mode]);
+	if (!boot_cpu_has(X86_FEATURE_SSBD))
+		ssb_mode = SPEC_STORE_BYPASS_NONE;
+
+	pr_info("%s\n", ssb_strings[ssb_mode]);
 }
 
 static void __init ssb_apply_mitigation(void)
Signature · 1 line
2.34.1
maintainer
#11 lore raw

Re: [PATCH v2 3/5] x86/bugs: Simplify SSB cmdline parsing

arch/x86/kernel/cpu/bugs.c static const char * const ssb_strings[] = { · line 2623

Quoted 10 lines · David Kaplan
arch/x86/kernel/cpu/bugs.c +6 -3
+static int __init ssb_parse_cmdline(char *str)
+{
+	if (!str)
+		return -EINVAL;
 
-		for (i = 0; i < ARRAY_SIZE(ssb_mitigation_options); i++) {
-			if (!match_option(arg, ret, ssb_mitigation_options[i].option))
-				continue;
+	if (!IS_ENABLED(CONFIG_MITIGATION_SSB))
+		return 0;

Similar to elsewhere, I think we want to be consistent and allow overriding the compile time default.

Signature · 1 line
Josh
#12 lore raw

PATCH v2 4/5 x86/bugs: Add attack vector controls for SSB

In reply to David Kaplan

Attack vector controls for SSB were missed in the initial attack vector series. The default mitigation for SSB requires user-space opt-in so it is only relevant for user->user attacks. Add an AUTO mitigation for SSB and use this attack vector control to select the SSB mitigation.

---
 .../hw-vuln/attack_vector_controls.rst         |  5 +----
 arch/x86/include/asm/nospec-branch.h           |  1 +
 arch/x86/kernel/cpu/bugs.c                     | 18 +++++++++++++++---
 3 files changed, 17 insertions(+), 7 deletions(-)
Documentation/admin-guide/hw-vuln/attack_vector_controls.rst +1 -4
index 6dd0800146f6..5964901d66e3 100644
@@ -215,7 +215,7 @@ Spectre_v2            X                           X
 Spectre_v2_user                      X                           X            *       (Note 1)
 SRBDS                 X              X            X              X
 SRSO                  X              X            X              X
-SSB                                                                                   (Note 4)
+SSB                                  X
 TAA                   X              X            X              X            *       (Note 2)
 TSA                   X              X            X              X
 =============== ============== ============ ============= ============== ============ ========
@@ -229,9 +229,6 @@ Notes:
    3 --  Disables SMT if cross-thread mitigations are fully enabled, the CPU is
    vulnerable, and STIBP is not supported
 
-   4 --  Speculative store bypass is always enabled by default (no kernel
-   mitigation applied) unless overridden with spec_store_bypass_disable option
-
 When an attack-vector is disabled, all mitigations for the vulnerabilities
 listed in the above table are disabled, unless mitigation is required for a
 different enabled attack-vector or a mitigation is explicitly selected via a
arch/x86/include/asm/nospec-branch.h +1 -0
index 10f261678749..e263c126723a 100644
@@ -514,6 +514,7 @@ enum spectre_v2_user_mitigation {
 /* The Speculative Store Bypass disable variants */
 enum ssb_mitigation {
 	SPEC_STORE_BYPASS_NONE,
+	SPEC_STORE_BYPASS_AUTO,
 	SPEC_STORE_BYPASS_DISABLE,
 	SPEC_STORE_BYPASS_PRCTL,
 	SPEC_STORE_BYPASS_SECCOMP,
arch/x86/kernel/cpu/bugs.c +15 -3
index 8dc654ccdbb9..059269f3f56f 100644
@@ -416,6 +416,10 @@ static bool __init should_mitigate_vuln(unsigned int bug)
 		       cpu_attack_vector_mitigated(CPU_MITIGATE_USER_USER) ||
 		       cpu_attack_vector_mitigated(CPU_MITIGATE_GUEST_GUEST) ||
 		       (smt_mitigations != SMT_MITIGATIONS_OFF);
+
+	case X86_BUG_SPEC_STORE_BYPASS:
+		return cpu_attack_vector_mitigated(CPU_MITIGATE_USER_USER);
+
 	default:
 		WARN(1, "Unknown bug %x\n", bug);
 		return false;
@@ -2595,7 +2599,7 @@ void cpu_bugs_smt_update(void)
 #define pr_fmt(fmt)	"Speculative Store Bypass: " fmt
 
 static enum ssb_mitigation ssb_mode __ro_after_init =
-	IS_ENABLED(CONFIG_MITIGATION_SSB) ? SPEC_STORE_BYPASS_PRCTL : SPEC_STORE_BYPASS_NONE;
+	IS_ENABLED(CONFIG_MITIGATION_SSB) ? SPEC_STORE_BYPASS_AUTO : SPEC_STORE_BYPASS_NONE;
 
 static const char * const ssb_strings[] = {
 	[SPEC_STORE_BYPASS_NONE]	= "Vulnerable",
@@ -2626,7 +2630,7 @@ static int __init ssb_parse_cmdline(char *str)
 		return 0;
 
 	if (!strcmp(str, "auto"))
-		ssb_mode = SPEC_STORE_BYPASS_PRCTL;
+		ssb_mode = SPEC_STORE_BYPASS_AUTO;
 	else if (!strcmp(str, "on"))
 		ssb_mode = SPEC_STORE_BYPASS_DISABLE;
 	else if (!strcmp(str, "off"))
@@ -2646,11 +2650,18 @@ early_param("spec_store_bypass_disable", ssb_parse_cmdline);
 
 static void __init ssb_select_mitigation(void)
 {
-	if (!boot_cpu_has_bug(X86_BUG_SPEC_STORE_BYPASS) || cpu_mitigations_off()) {
+	if (!boot_cpu_has_bug(X86_BUG_SPEC_STORE_BYPASS)) {
 		ssb_mode = SPEC_STORE_BYPASS_NONE;
 		return;
 	}
 
+	if (ssb_mode == SPEC_STORE_BYPASS_AUTO) {
+		if (should_mitigate_vuln(X86_BUG_SPEC_STORE_BYPASS))
+			ssb_mode = SPEC_STORE_BYPASS_PRCTL;
+		else
+			ssb_mode = SPEC_STORE_BYPASS_NONE;
+	}
+
 	if (!boot_cpu_has(X86_FEATURE_SSBD))
 		ssb_mode = SPEC_STORE_BYPASS_NONE;
 
@@ -2870,6 +2881,7 @@ static int ssb_prctl_get(struct task_struct *task)
 		return PR_SPEC_DISABLE;
 	case SPEC_STORE_BYPASS_SECCOMP:
 	case SPEC_STORE_BYPASS_PRCTL:
+	case SPEC_STORE_BYPASS_AUTO:
 		if (task_spec_ssb_force_disable(task))
 			return PR_SPEC_PRCTL | PR_SPEC_FORCE_DISABLE;
 		if (task_spec_ssb_noexec(task))
Signature · 1 line
2.34.1
reviewer
#13 lore raw

Re: [PATCH v2 4/5] x86/bugs: Add attack vector controls for SSB

arch/x86/kernel/cpu/bugs.c early_param("spec_store_bypass_disable", ssb_parse_cmdline); · line 2653

Quoted 6 lines · David Kaplan
arch/x86/kernel/cpu/bugs.c +1 -1
@@ -2646,11 +2650,18 @@ early_param("spec_store_bypass_disable", ssb_parse_cmdline);
 
 static void __init ssb_select_mitigation(void)
 {
-	if (!boot_cpu_has_bug(X86_BUG_SPEC_STORE_BYPASS) || cpu_mitigations_off()) {
+	if (!boot_cpu_has_bug(X86_BUG_SPEC_STORE_BYPASS)) {

Nothing major, but this change belongs to the next patch that cleans up cpu_mitigations_off().

maintainer
#14 lore raw

Re: [PATCH v2 4/5] x86/bugs: Add attack vector controls for SSB

Quoted 10 lines · Pawan Gupta

arch/x86/kernel/cpu/bugs.c early_param("spec_store_bypass_disable", ssb_parse_cmdline); · line 2653

Quoted 6 lines · David Kaplan
arch/x86/kernel/cpu/bugs.c +1 -1
@@ -2646,11 +2650,18 @@ early_param("spec_store_bypass_disable", ssb_parse_cmdline);
 
 static void __init ssb_select_mitigation(void)
 {
-	if (!boot_cpu_has_bug(X86_BUG_SPEC_STORE_BYPASS) || cpu_mitigations_off()) {
+	if (!boot_cpu_has_bug(X86_BUG_SPEC_STORE_BYPASS)) {

Nothing major, but this change belongs to the next patch that cleans up cpu_mitigations_off().

Fixed and expediting this one so that 6.17 releases with the full attack vectors functionality.

Thx.

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
maintainer Reviewed-by Pawan Gupta
#15 lore raw

Re: [PATCH v2 4/5] x86/bugs: Add attack vector controls for SSB

Quoted 2 lines · Borislav Petkov

Fixed and expediting this one so that 6.17 releases with the full attack vectors functionality.

Ok, so I'm thinking we should do a minimal fix like this below which goes to Linus now so that 6.17 has full attack vectors support and then slap all cleanups ontop. Thoughts?

---
From: David Kaplan <[email protected]>
Date: Tue, 19 Aug 2025 14:21:59 -0500
Subject: [PATCH] x86/bugs: Add attack vector controls for SSB

Attack vector controls for SSB were missed in the initial attack vector series. The default mitigation for SSB requires user-space opt-in so it is only relevant for user->user attacks. Add an AUTO mitigation for SSB and use this attack vector control to select the SSB mitigation.

Fixes 2d31d2874663 ("x86/bugs: Define attack vectors relevant for each bug")
---
 .../hw-vuln/attack_vector_controls.rst            |  5 +----
 arch/x86/include/asm/nospec-branch.h              |  1 +
 arch/x86/kernel/cpu/bugs.c                        | 15 ++++++++++++++-
 3 files changed, 16 insertions(+), 5 deletions(-)
Documentation/admin-guide/hw-vuln/attack_vector_controls.rst +1 -4
index 6dd0800146f6..5964901d66e3 100644
@@ -215,7 +215,7 @@ Spectre_v2            X                           X
 Spectre_v2_user                      X                           X            *       (Note 1)
 SRBDS                 X              X            X              X
 SRSO                  X              X            X              X
-SSB                                                                                   (Note 4)
+SSB                                  X
 TAA                   X              X            X              X            *       (Note 2)
 TSA                   X              X            X              X
 =============== ============== ============ ============= ============== ============ ========
@@ -229,9 +229,6 @@ Notes:
    3 --  Disables SMT if cross-thread mitigations are fully enabled, the CPU is
    vulnerable, and STIBP is not supported
 
-   4 --  Speculative store bypass is always enabled by default (no kernel
-   mitigation applied) unless overridden with spec_store_bypass_disable option
-
 When an attack-vector is disabled, all mitigations for the vulnerabilities
 listed in the above table are disabled, unless mitigation is required for a
 different enabled attack-vector or a mitigation is explicitly selected via a
arch/x86/include/asm/nospec-branch.h +1 -0
index 10f261678749..e263c126723a 100644
@@ -514,6 +514,7 @@ enum spectre_v2_user_mitigation {
 /* The Speculative Store Bypass disable variants */
 enum ssb_mitigation {
 	SPEC_STORE_BYPASS_NONE,
+	SPEC_STORE_BYPASS_AUTO,
 	SPEC_STORE_BYPASS_DISABLE,
 	SPEC_STORE_BYPASS_PRCTL,
 	SPEC_STORE_BYPASS_SECCOMP,
arch/x86/kernel/cpu/bugs.c +14 -1
index 49ef1b832c1a..159beed05ee8 100644
@@ -416,6 +416,10 @@ static bool __init should_mitigate_vuln(unsigned int bug)
 		       cpu_attack_vector_mitigated(CPU_MITIGATE_USER_USER) ||
 		       cpu_attack_vector_mitigated(CPU_MITIGATE_GUEST_GUEST) ||
 		       (smt_mitigations != SMT_MITIGATIONS_OFF);
+
+	case X86_BUG_SPEC_STORE_BYPASS:
+		return cpu_attack_vector_mitigated(CPU_MITIGATE_USER_USER);
+
 	default:
 		WARN(1, "Unknown bug %x\n", bug);
 		return false;
@@ -2619,7 +2623,8 @@ void cpu_bugs_smt_update(void)
 #undef pr_fmt
 #define pr_fmt(fmt)	"Speculative Store Bypass: " fmt
 
-static enum ssb_mitigation ssb_mode __ro_after_init = SPEC_STORE_BYPASS_NONE;
+static enum ssb_mitigation ssb_mode __ro_after_init =
+	IS_ENABLED(CONFIG_MITIGATION_SSB) ? SPEC_STORE_BYPASS_AUTO : SPEC_STORE_BYPASS_NONE;
 
 /* The kernel command line selection */
 enum ssb_mitigation_cmd {
@@ -2695,6 +2700,13 @@ static void __init ssb_select_mitigation(void)
 	     cmd == SPEC_STORE_BYPASS_CMD_AUTO))
 		return;
 
+	if (ssb_mode == SPEC_STORE_BYPASS_AUTO) {
+		if (should_mitigate_vuln(X86_BUG_SPEC_STORE_BYPASS))
+			ssb_mode = SPEC_STORE_BYPASS_PRCTL;
+		else
+			ssb_mode = SPEC_STORE_BYPASS_NONE;
+	}
+
 	switch (cmd) {
 	case SPEC_STORE_BYPASS_CMD_SECCOMP:
 		/*
@@ -2935,6 +2947,7 @@ static int ssb_prctl_get(struct task_struct *task)
 		return PR_SPEC_DISABLE;
 	case SPEC_STORE_BYPASS_SECCOMP:
 	case SPEC_STORE_BYPASS_PRCTL:
+	case SPEC_STORE_BYPASS_AUTO:
 		if (task_spec_ssb_force_disable(task))
 			return PR_SPEC_PRCTL | PR_SPEC_FORCE_DISABLE;
 		if (task_spec_ssb_noexec(task))
Signature · 7 lines
2.51.0

-- 
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
#16 lore raw

RE: [PATCH v2 4/5] x86/bugs: Add attack vector controls for SSB

[AMD Official Use Only - AMD Internal Distribution Only]

Quoted 132 lines

-----Original Message-----
From: Borislav Petkov <[email protected]>
Sent: Wednesday, August 27, 2025 6:04 AM
To: Pawan Gupta <[email protected]>; Kaplan, David <[email protected]>
Cc: Thomas Gleixner <[email protected]>; Peter Zijlstra <[email protected]>; Josh Poimboeuf <[email protected]>; Ingo Molnar <[email protected]>; Dave Hansen <[email protected]>; [email protected]; H . Peter Anvin <[email protected]>; [email protected]
Subject: Re: [PATCH v2 4/5] x86/bugs: Add attack vector controls for SSB

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

Quoted 2 lines · Borislav Petkov

Fixed and expediting this one so that 6.17 releases with the full attack vectors functionality.

Ok, so I'm thinking we should do a minimal fix like this below which goes to Linus now so that 6.17 has full attack vectors support and then slap all cleanups ontop. Thoughts?

---
From: David Kaplan <[email protected]>
Date: Tue, 19 Aug 2025 14:21:59 -0500
Subject: [PATCH] x86/bugs: Add attack vector controls for SSB

Attack vector controls for SSB were missed in the initial attack vector series. The default mitigation for SSB requires user-space opt-in so it is only relevant for user->user attacks. Add an AUTO mitigation for SSB and use this attack vector control to select the SSB mitigation.

Fixes 2d31d2874663 ("x86/bugs: Define attack vectors relevant for each bug")
---
 .../hw-vuln/attack_vector_controls.rst            |  5 +----
 arch/x86/include/asm/nospec-branch.h              |  1 +
 arch/x86/kernel/cpu/bugs.c                        | 15 ++++++++++++++-
 3 files changed, 16 insertions(+), 5 deletions(-)
Documentation/admin-guide/hw-vuln/attack_vector_controls.rst +1 -1
index 6dd0800146f6..5964901d66e3 100644
@@ -215,7 +215,7 @@ Spectre_v2            X                           X
 Spectre_v2_user                      X                           X            *       (Note 1)
 SRBDS                 X              X            X              X
 SRSO                  X              X            X              X
-SSB                                                                                   (Note 4)
+SSB                                  X
 TAA                   X              X            X              X            *       (Note 2)
 TSA                   X              X            X              X
 =============== ============== ============ =============

============== ============ ========

Documentation/admin-guide/hw-vuln/attack_vector_controls.rst +0 -3
@@ -229,9 +229,6 @@ Notes:
    3 --  Disables SMT if cross-thread mitigations are fully enabled, the CPU is
    vulnerable, and STIBP is not supported
 
-   4 --  Speculative store bypass is always enabled by default (no kernel
-   mitigation applied) unless overridden with spec_store_bypass_disable option
-
 When an attack-vector is disabled, all mitigations for the vulnerabilities
 listed in the above table are disabled, unless mitigation is required for a
 different enabled attack-vector or a mitigation is explicitly selected via a
arch/x86/include/asm/nospec- renamed from arch/x86/include/asm/nospec-branch.h +0 -0

branch.h
index 10f261678749..e263c126723a 100644

arch/x86/include/asm/nospec-branch.h +1 -0
@@ -514,6 +514,7 @@ enum spectre_v2_user_mitigation {
 /* The Speculative Store Bypass disable variants */
 enum ssb_mitigation {
        SPEC_STORE_BYPASS_NONE,
+       SPEC_STORE_BYPASS_AUTO,
        SPEC_STORE_BYPASS_DISABLE,
        SPEC_STORE_BYPASS_PRCTL,
        SPEC_STORE_BYPASS_SECCOMP,
arch/x86/kernel/cpu/bugs.c +6 -1
index 49ef1b832c1a..159beed05ee8 100644
@@ -416,6 +416,10 @@ static bool __init should_mitigate_vuln(unsigned int bug)
                       cpu_attack_vector_mitigated(CPU_MITIGATE_USER_USER) ||
                       cpu_attack_vector_mitigated(CPU_MITIGATE_GUEST_GUEST) ||
                       (smt_mitigations != SMT_MITIGATIONS_OFF);
+
+       case X86_BUG_SPEC_STORE_BYPASS:
+               return cpu_attack_vector_mitigated(CPU_MITIGATE_USER_USER);
+
        default:
                WARN(1, "Unknown bug %x\n", bug);
                return false;
@@ -2619,7 +2623,8 @@ void cpu_bugs_smt_update(void)
 #undef pr_fmt
 #define pr_fmt(fmt)    "Speculative Store Bypass: " fmt
 
-static enum ssb_mitigation ssb_mode __ro_after_init =
 SPEC_STORE_BYPASS_NONE;
+static enum ssb_mitigation ssb_mode __ro_after_init =
+       IS_ENABLED(CONFIG_MITIGATION_SSB) ?
 SPEC_STORE_BYPASS_AUTO : SPEC_STORE_BYPASS_NONE;
 

/* The kernel command line selection */
enum ssb_mitigation_cmd {

arch/x86/kernel/cpu/bugs.c +8 -1
@@ -2695,6 +2700,13 @@ static void __init ssb_select_mitigation(void)
             cmd == SPEC_STORE_BYPASS_CMD_AUTO))
                return;
 
+       if (ssb_mode == SPEC_STORE_BYPASS_AUTO) {
+               if (should_mitigate_vuln(X86_BUG_SPEC_STORE_BYPASS))
+                       ssb_mode = SPEC_STORE_BYPASS_PRCTL;
+               else
+                       ssb_mode = SPEC_STORE_BYPASS_NONE;
+       }
+
        switch (cmd) {
        case SPEC_STORE_BYPASS_CMD_SECCOMP:
                /*
@@ -2935,6 +2947,7 @@ static int ssb_prctl_get(struct task_struct *task)
                return PR_SPEC_DISABLE;
        case SPEC_STORE_BYPASS_SECCOMP:
        case SPEC_STORE_BYPASS_PRCTL:
+       case SPEC_STORE_BYPASS_AUTO:
                if (task_spec_ssb_force_disable(task))
                        return PR_SPEC_PRCTL | PR_SPEC_FORCE_DISABLE;
                if (task_spec_ssb_noexec(task))
--
Quoted 2 lines

2.51.0

This patch won't work if you don't pick up the SSB clean-up (patch #3). The SSB clean-up patch removes the ssb_mitigation_cmd and makes all selection on ssb_mode, which is simpler and allows the attack vector control to easily work.

In the above code, ssb_mode is always SPEC_STORE_BYPASS_AUTO when ssb_select_mitigation() runs. But then ssb_mode will be overwritten by the switch statement later. In particular, if no cmdline option is passed, the cmd will be SPEC_STORE_BYPASS_CMD_AUTO which in the switch statement always sets mode to SPEC_STORE_BYPASS_PRCTL, ignoring the attack vector.

If you really want to not pick up patch #3 yet, then you could move the should_mitigate_vuln() check into the switch statement for SPEC_STORE_BYPASS_CMD_AUTO only. Or just pick up the clean-up patch which also reduces the overall code size.

--David Kaplan

maintainer
#17 lore raw

Re: [PATCH v2 4/5] x86/bugs: Add attack vector controls for SSB

Quoted 4 lines · David

If you really want to not pick up patch #3 yet, then you could move the should_mitigate_vuln() check into the switch statement for SPEC_STORE_BYPASS_CMD_AUTO only. Or just pick up the clean-up patch which also reduces the overall code size.

I need a minimal fix which goes into 6.17 now because we forgot SSB. This patch was my attempt at doing something like that.

Cleanups can then go ontop.

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
#18 lore raw

RE: [PATCH v2 4/5] x86/bugs: Add attack vector controls for SSB

[AMD Official Use Only - AMD Internal Distribution Only]

Quoted 19 lines

-----Original Message-----
From: Borislav Petkov <[email protected]>
Sent: Wednesday, August 27, 2025 9:22 AM
To: Kaplan, David <[email protected]>
Cc: Pawan Gupta <[email protected]>; Thomas Gleixner <[email protected]>; Peter Zijlstra <[email protected]>; Josh Poimboeuf <[email protected]>; Ingo Molnar <[email protected]>; Dave Hansen <[email protected]>; [email protected]; H . Peter Anvin <[email protected]>; [email protected]
Subject: Re: [PATCH v2 4/5] x86/bugs: Add attack vector controls for SSB

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

Quoted 3 lines · David

If you really want to not pick up patch #3 yet, then you could move the should_mitigate_vuln() check into the switch statement for SPEC_STORE_BYPASS_CMD_AUTO only. Or just pick up the clean-up patch

Quoted 8 lines

which

Quoted 1 line

also reduces the overall code size.

I need a minimal fix which goes into 6.17 now because we forgot SSB. This patch was my attempt at doing something like that.

Cleanups can then go ontop.

Ok. Then I would go with the suggestion in my reply...move the should_mitigate_vuln() logic into the SPEC_STORE_BYPASS_CMD_AUTO branch of the switch. I think that should work as expected.

Rest of the patch was fine I think.

--David Kaplan

maintainer
#19 lore raw

Re: [PATCH v2 4/5] x86/bugs: Add attack vector controls for SSB

Quoted 3 lines · David

Ok. Then I would go with the suggestion in my reply...move the should_mitigate_vuln() logic into the SPEC_STORE_BYPASS_CMD_AUTO branch of the switch. I think that should work as expected.

Makes sense...

Quoted 1 line

Rest of the patch was fine I think.

Here it is - I *think* it looks good now but doublecheck me again pls.

Thx.

---
From: David Kaplan <[email protected]>
Date: Tue, 19 Aug 2025 14:21:59 -0500
Subject: [PATCH] x86/bugs: Add attack vector controls for SSB

Attack vector controls for SSB were missed in the initial attack vector series. The default mitigation for SSB requires user-space opt-in so it is only relevant for user->user attacks. Add an AUTO mitigation for SSB and use this attack vector control to select the SSB mitigation.

Fixes 2d31d2874663 ("x86/bugs: Define attack vectors relevant for each bug")
---
 .../admin-guide/hw-vuln/attack_vector_controls.rst  |  5 +----
 arch/x86/include/asm/nospec-branch.h                |  1 +
 arch/x86/kernel/cpu/bugs.c                          | 13 ++++++++++++-
 3 files changed, 14 insertions(+), 5 deletions(-)
Documentation/admin-guide/hw-vuln/attack_vector_controls.rst +1 -4
index 6dd0800146f6..5964901d66e3 100644
@@ -215,7 +215,7 @@ Spectre_v2            X                           X
 Spectre_v2_user                      X                           X            *       (Note 1)
 SRBDS                 X              X            X              X
 SRSO                  X              X            X              X
-SSB                                                                                   (Note 4)
+SSB                                  X
 TAA                   X              X            X              X            *       (Note 2)
 TSA                   X              X            X              X
 =============== ============== ============ ============= ============== ============ ========
@@ -229,9 +229,6 @@ Notes:
    3 --  Disables SMT if cross-thread mitigations are fully enabled, the CPU is
    vulnerable, and STIBP is not supported
 
-   4 --  Speculative store bypass is always enabled by default (no kernel
-   mitigation applied) unless overridden with spec_store_bypass_disable option
-
 When an attack-vector is disabled, all mitigations for the vulnerabilities
 listed in the above table are disabled, unless mitigation is required for a
 different enabled attack-vector or a mitigation is explicitly selected via a
arch/x86/include/asm/nospec-branch.h +1 -0
index 10f261678749..e263c126723a 100644
@@ -514,6 +514,7 @@ enum spectre_v2_user_mitigation {
 /* The Speculative Store Bypass disable variants */
 enum ssb_mitigation {
 	SPEC_STORE_BYPASS_NONE,
+	SPEC_STORE_BYPASS_AUTO,
 	SPEC_STORE_BYPASS_DISABLE,
 	SPEC_STORE_BYPASS_PRCTL,
 	SPEC_STORE_BYPASS_SECCOMP,
arch/x86/kernel/cpu/bugs.c +12 -1
index 49ef1b832c1a..7b4b43aabd18 100644
@@ -416,6 +416,10 @@ static bool __init should_mitigate_vuln(unsigned int bug)
 		       cpu_attack_vector_mitigated(CPU_MITIGATE_USER_USER) ||
 		       cpu_attack_vector_mitigated(CPU_MITIGATE_GUEST_GUEST) ||
 		       (smt_mitigations != SMT_MITIGATIONS_OFF);
+
+	case X86_BUG_SPEC_STORE_BYPASS:
+		return cpu_attack_vector_mitigated(CPU_MITIGATE_USER_USER);
+
 	default:
 		WARN(1, "Unknown bug %x\n", bug);
 		return false;
@@ -2619,7 +2623,8 @@ void cpu_bugs_smt_update(void)
 #undef pr_fmt
 #define pr_fmt(fmt)	"Speculative Store Bypass: " fmt
 
-static enum ssb_mitigation ssb_mode __ro_after_init = SPEC_STORE_BYPASS_NONE;
+static enum ssb_mitigation ssb_mode __ro_after_init =
+	IS_ENABLED(CONFIG_MITIGATION_SSB) ? SPEC_STORE_BYPASS_AUTO : SPEC_STORE_BYPASS_NONE;
 
 /* The kernel command line selection */
 enum ssb_mitigation_cmd {
@@ -2710,6 +2715,11 @@ static void __init ssb_select_mitigation(void)
 		ssb_mode = SPEC_STORE_BYPASS_DISABLE;
 		break;
 	case SPEC_STORE_BYPASS_CMD_AUTO:
+		if (should_mitigate_vuln(X86_BUG_SPEC_STORE_BYPASS))
+			ssb_mode = SPEC_STORE_BYPASS_PRCTL;
+		else
+			ssb_mode = SPEC_STORE_BYPASS_NONE;
+		break;
 	case SPEC_STORE_BYPASS_CMD_PRCTL:
 		ssb_mode = SPEC_STORE_BYPASS_PRCTL;
 		break;
@@ -2935,6 +2945,7 @@ static int ssb_prctl_get(struct task_struct *task)
 		return PR_SPEC_DISABLE;
 	case SPEC_STORE_BYPASS_SECCOMP:
 	case SPEC_STORE_BYPASS_PRCTL:
+	case SPEC_STORE_BYPASS_AUTO:
 		if (task_spec_ssb_force_disable(task))
 			return PR_SPEC_PRCTL | PR_SPEC_FORCE_DISABLE;
 		if (task_spec_ssb_noexec(task))
Signature · 7 lines
2.51.0

-- 
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
#20 lore raw

RE: [PATCH v2 4/5] x86/bugs: Add attack vector controls for SSB

[AMD Official Use Only - AMD Internal Distribution Only]

Quoted 32 lines

-----Original Message-----
From: Borislav Petkov <[email protected]>
Sent: Wednesday, August 27, 2025 10:34 AM
To: Kaplan, David <[email protected]>
Cc: Pawan Gupta <[email protected]>; Thomas Gleixner <[email protected]>; Peter Zijlstra <[email protected]>; Josh Poimboeuf <[email protected]>; Ingo Molnar <[email protected]>; Dave Hansen <[email protected]>; [email protected]; H . Peter Anvin <[email protected]>; [email protected]
Subject: Re: [PATCH v2 4/5] x86/bugs: Add attack vector controls for SSB

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

Quoted 2 lines · David

Ok. Then I would go with the suggestion in my reply...move the should_mitigate_vuln() logic into the SPEC_STORE_BYPASS_CMD_AUTO

branch of

Quoted 1 line

the switch. I think that should work as expected.

Makes sense...

Quoted 1 line

Rest of the patch was fine I think.

Here it is - I *think* it looks good now but doublecheck me again pls.

Thx.

arch/x86/include/asm/nospec-branch.h enum spectre_v2_user_mitigation { · line 520

Quoted 7 lines
arch/x86/include/asm/nospec-branch.h +1 -0
@@ -514,6 +514,7 @@ enum spectre_v2_user_mitigation {
 /* The Speculative Store Bypass disable variants */
 enum ssb_mitigation {
        SPEC_STORE_BYPASS_NONE,
+       SPEC_STORE_BYPASS_AUTO,
        SPEC_STORE_BYPASS_DISABLE,
        SPEC_STORE_BYPASS_PRCTL,
        SPEC_STORE_BYPASS_SECCOMP,

After reviewing this further, this change should be removed. The AUTO mitigation is intended to say 'choose based on attack vector', but with this patch you're not looking at ssb_mode to decide to do that. You're looking at the ssb mitigation cmd (which already defaults to SPEC_STORE_BYPASS_CMD_AUTO). Therefore there is no need for a SPEC_STORE_BYPASS_AUTO setting of ssb_mode.

(The clean-up patch removes ssb_mitigation_cmd entirely, so it needs an AUTO setting of ssb_mitigation)

Quoted 7 lines

-static enum ssb_mitigation ssb_mode __ro_after_init = SPEC_STORE_BYPASS_NONE;

arch/x86/include/asm/nospec-branch.h +2 -0
+static enum ssb_mitigation ssb_mode __ro_after_init =
+       IS_ENABLED(CONFIG_MITIGATION_SSB) ?

SPEC_STORE_BYPASS_AUTO : SPEC_STORE_BYPASS_NONE;

But more importantly, please remove this. That's because in the current patch, if the user says 'nospec_store_bypass_disable' then the ssb_select_mitigation() function does not change ssb_mode. So it needs to default to NONE.

Thanks
--David Kaplan

maintainer
#21 lore raw

Re: [PATCH v2 4/5] x86/bugs: Add attack vector controls for SSB

Quoted 3 lines · David

After reviewing this further, this change should be removed. The AUTO mitigation is intended to say 'choose based on attack vector', but with this patch you're not looking at ssb_mode to decide to do that. You're looking at the ssb mitigation cmd (which already defaults to SPEC_STORE_BYPASS_CMD_AUTO). Therefore there is no need for a SPEC_STORE_BYPASS_AUTO setting of ssb_mode.

(The clean-up patch removes ssb_mitigation_cmd entirely, so it needs an AUTO setting of ssb_mitigation)

...

Quoted 1 line

But more importantly, please remove this. That's because in the current patch, if the user says 'nospec_store_bypass_disable' then the ssb_select_mitigation() function does not change ssb_mode. So it needs to default to NONE.

Yah, agreed with both. Here's a minimal thing.

---
From: David Kaplan <[email protected]>
Date: Tue, 19 Aug 2025 14:21:59 -0500
Subject: [PATCH] x86/bugs: Add attack vector controls for SSB

Attack vector controls for SSB were missed in the initial attack vector series. The default mitigation for SSB requires user-space opt-in so it is only relevant for user->user attacks. Add an AUTO mitigation for SSB and use this attack vector control to select the SSB mitigation.

Fixes 2d31d2874663 ("x86/bugs: Define attack vectors relevant for each bug")
---
 .../admin-guide/hw-vuln/attack_vector_controls.rst       | 5 +----
 arch/x86/kernel/cpu/bugs.c                               | 9 +++++++++
 2 files changed, 10 insertions(+), 4 deletions(-)
Documentation/admin-guide/hw-vuln/attack_vector_controls.rst +1 -4
index 6dd0800146f6..5964901d66e3 100644
@@ -215,7 +215,7 @@ Spectre_v2            X                           X
 Spectre_v2_user                      X                           X            *       (Note 1)
 SRBDS                 X              X            X              X
 SRSO                  X              X            X              X
-SSB                                                                                   (Note 4)
+SSB                                  X
 TAA                   X              X            X              X            *       (Note 2)
 TSA                   X              X            X              X
 =============== ============== ============ ============= ============== ============ ========
@@ -229,9 +229,6 @@ Notes:
    3 --  Disables SMT if cross-thread mitigations are fully enabled, the CPU is
    vulnerable, and STIBP is not supported
 
-   4 --  Speculative store bypass is always enabled by default (no kernel
-   mitigation applied) unless overridden with spec_store_bypass_disable option
-
 When an attack-vector is disabled, all mitigations for the vulnerabilities
 listed in the above table are disabled, unless mitigation is required for a
 different enabled attack-vector or a mitigation is explicitly selected via a
arch/x86/kernel/cpu/bugs.c +9 -0
index 49ef1b832c1a..af838b8d845c 100644
@@ -416,6 +416,10 @@ static bool __init should_mitigate_vuln(unsigned int bug)
 		       cpu_attack_vector_mitigated(CPU_MITIGATE_USER_USER) ||
 		       cpu_attack_vector_mitigated(CPU_MITIGATE_GUEST_GUEST) ||
 		       (smt_mitigations != SMT_MITIGATIONS_OFF);
+
+	case X86_BUG_SPEC_STORE_BYPASS:
+		return cpu_attack_vector_mitigated(CPU_MITIGATE_USER_USER);
+
 	default:
 		WARN(1, "Unknown bug %x\n", bug);
 		return false;
@@ -2710,6 +2714,11 @@ static void __init ssb_select_mitigation(void)
 		ssb_mode = SPEC_STORE_BYPASS_DISABLE;
 		break;
 	case SPEC_STORE_BYPASS_CMD_AUTO:
+		if (should_mitigate_vuln(X86_BUG_SPEC_STORE_BYPASS))
+			ssb_mode = SPEC_STORE_BYPASS_PRCTL;
+		else
+			ssb_mode = SPEC_STORE_BYPASS_NONE;
+		break;
 	case SPEC_STORE_BYPASS_CMD_PRCTL:
 		ssb_mode = SPEC_STORE_BYPASS_PRCTL;
 		break;
Signature · 7 lines
2.51.0

-- 
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
#22 lore raw

RE: [PATCH v2 4/5] x86/bugs: Add attack vector controls for SSB

[AMD Official Use Only - AMD Internal Distribution Only]

Quoted 105 lines

-----Original Message-----
From: Borislav Petkov <[email protected]>
Sent: Wednesday, August 27, 2025 11:12 AM
To: Kaplan, David <[email protected]>
Cc: Pawan Gupta <[email protected]>; Thomas Gleixner <[email protected]>; Peter Zijlstra <[email protected]>; Josh Poimboeuf <[email protected]>; Ingo Molnar <[email protected]>; Dave Hansen <[email protected]>; [email protected]; H . Peter Anvin <[email protected]>; [email protected]
Subject: Re: [PATCH v2 4/5] x86/bugs: Add attack vector controls for SSB

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

Quoted 1 line · David

After reviewing this further, this change should be removed. The AUTO mitigation

is intended to say 'choose based on attack vector', but with this patch you're not looking at ssb_mode to decide to do that. You're looking at the ssb mitigation cmd (which already defaults to SPEC_STORE_BYPASS_CMD_AUTO). Therefore there is no need for a SPEC_STORE_BYPASS_AUTO setting of ssb_mode.

Quoted 2 lines

(The clean-up patch removes ssb_mitigation_cmd entirely, so it needs an AUTO

setting of ssb_mitigation)

...

Quoted 1 line

But more importantly, please remove this. That's because in the current patch, if

the user says 'nospec_store_bypass_disable' then the ssb_select_mitigation() function does not change ssb_mode. So it needs to default to NONE.

Yah, agreed with both. Here's a minimal thing.

---
From: David Kaplan <[email protected]>
Date: Tue, 19 Aug 2025 14:21:59 -0500
Subject: [PATCH] x86/bugs: Add attack vector controls for SSB

Attack vector controls for SSB were missed in the initial attack vector series. The default mitigation for SSB requires user-space opt-in so it is only relevant for user->user attacks. Add an AUTO mitigation for SSB and use this attack vector control to select the SSB mitigation.

Fixes 2d31d2874663 ("x86/bugs: Define attack vectors relevant for each bug")
---
 .../admin-guide/hw-vuln/attack_vector_controls.rst       | 5 +----
 arch/x86/kernel/cpu/bugs.c                               | 9 +++++++++
 2 files changed, 10 insertions(+), 4 deletions(-)
Documentation/admin-guide/hw-vuln/attack_vector_controls.rst +1 -1
index 6dd0800146f6..5964901d66e3 100644
@@ -215,7 +215,7 @@ Spectre_v2            X                           X
 Spectre_v2_user                      X                           X            *       (Note 1)
 SRBDS                 X              X            X              X
 SRSO                  X              X            X              X
-SSB                                                                                   (Note 4)
+SSB                                  X
 TAA                   X              X            X              X            *       (Note 2)
 TSA                   X              X            X              X
 =============== ============== ============ =============

============== ============ ========

Documentation/admin-guide/hw-vuln/attack_vector_controls.rst +0 -3
@@ -229,9 +229,6 @@ Notes:
    3 --  Disables SMT if cross-thread mitigations are fully enabled, the CPU is
    vulnerable, and STIBP is not supported
 
-   4 --  Speculative store bypass is always enabled by default (no kernel
-   mitigation applied) unless overridden with spec_store_bypass_disable option
-
 When an attack-vector is disabled, all mitigations for the vulnerabilities
 listed in the above table are disabled, unless mitigation is required for a
 different enabled attack-vector or a mitigation is explicitly selected via a
arch/x86/kernel/cpu/bugs.c +9 -1
index 49ef1b832c1a..af838b8d845c 100644
@@ -416,6 +416,10 @@ static bool __init should_mitigate_vuln(unsigned int bug)
                       cpu_attack_vector_mitigated(CPU_MITIGATE_USER_USER) ||
                       cpu_attack_vector_mitigated(CPU_MITIGATE_GUEST_GUEST) ||
                       (smt_mitigations != SMT_MITIGATIONS_OFF);
+
+       case X86_BUG_SPEC_STORE_BYPASS:
+               return cpu_attack_vector_mitigated(CPU_MITIGATE_USER_USER);
+
        default:
                WARN(1, "Unknown bug %x\n", bug);
                return false;
@@ -2710,6 +2714,11 @@ static void __init ssb_select_mitigation(void)
                ssb_mode = SPEC_STORE_BYPASS_DISABLE;
                break;
        case SPEC_STORE_BYPASS_CMD_AUTO:
+               if (should_mitigate_vuln(X86_BUG_SPEC_STORE_BYPASS))
+                       ssb_mode = SPEC_STORE_BYPASS_PRCTL;
+               else
+                       ssb_mode = SPEC_STORE_BYPASS_NONE;
+               break;
        case SPEC_STORE_BYPASS_CMD_PRCTL:
                ssb_mode = SPEC_STORE_BYPASS_PRCTL;
                break;
--
Quoted 2 lines

2.51.0

LGTM. Just make sure to update the commit description since it no longer is adding an AUTO mitigation.

Thanks --David Kaplan

maintainer
#23 lore raw

Re: [PATCH v2 4/5] x86/bugs: Add attack vector controls for SSB

Quoted 2 lines · David

LGTM. Just make sure to update the commit description since it no longer is adding an AUTO mitigation.

I have this now:

"Attack vector controls for SSB were missed in the initial attack vector series. The default mitigation for SSB requires user-space opt-in so it is only relevant for user->user attacks. Check with attack vector controls when the command is auto - i.e., no explicit user selection has been done."

Thx.

Signature · 4 lines
Regards/Gruss,
    Boris.

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

[tip: x86/urgent] x86/bugs: Add attack vector controls for SSB

In reply to David Kaplan
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:     8b3641dfb6f902407495c63b9b64482b32319b66
Gitweb:        https://git.kernel.org/tip/8b3641dfb6f902407495c63b9b64482b32319b66
Author:        David Kaplan <[email protected]>
AuthorDate:    Tue, 19 Aug 2025 14:21:59 -05:00
Committer:     Borislav Petkov (AMD) <[email protected]>
CommitterDate: Wed, 27 Aug 2025 18:17:12 +02:00

x86/bugs: Add attack vector controls for SSB

Attack vector controls for SSB were missed in the initial attack vector series. The default mitigation for SSB requires user-space opt-in so it is only relevant for user->user attacks. Check with attack vector controls when the command is auto - i.e., no explicit user selection has been done.

Fixes 2d31d2874663 ("x86/bugs: Define attack vectors relevant for each bug")
---
 Documentation/admin-guide/hw-vuln/attack_vector_controls.rst |  5 +----
 arch/x86/kernel/cpu/bugs.c                                   |  9 +++++++-
 2 files changed, 10 insertions(+), 4 deletions(-)
Documentation/admin-guide/hw-vuln/attack_vector_controls.rst +1 -4
index 6dd0800..5964901 100644
@@ -215,7 +215,7 @@ Spectre_v2            X                           X
 Spectre_v2_user                      X                           X            *       (Note 1)
 SRBDS                 X              X            X              X
 SRSO                  X              X            X              X
-SSB                                                                                   (Note 4)
+SSB                                  X
 TAA                   X              X            X              X            *       (Note 2)
 TSA                   X              X            X              X
 =============== ============== ============ ============= ============== ============ ========
@@ -229,9 +229,6 @@ Notes:
    3 --  Disables SMT if cross-thread mitigations are fully enabled, the CPU is
    vulnerable, and STIBP is not supported
 
-   4 --  Speculative store bypass is always enabled by default (no kernel
-   mitigation applied) unless overridden with spec_store_bypass_disable option
-
 When an attack-vector is disabled, all mitigations for the vulnerabilities
 listed in the above table are disabled, unless mitigation is required for a
 different enabled attack-vector or a mitigation is explicitly selected via a
arch/x86/kernel/cpu/bugs.c +9 -0
index 49ef1b8..af838b8 100644
@@ -416,6 +416,10 @@ static bool __init should_mitigate_vuln(unsigned int bug)
 		       cpu_attack_vector_mitigated(CPU_MITIGATE_USER_USER) ||
 		       cpu_attack_vector_mitigated(CPU_MITIGATE_GUEST_GUEST) ||
 		       (smt_mitigations != SMT_MITIGATIONS_OFF);
+
+	case X86_BUG_SPEC_STORE_BYPASS:
+		return cpu_attack_vector_mitigated(CPU_MITIGATE_USER_USER);
+
 	default:
 		WARN(1, "Unknown bug %x\n", bug);
 		return false;
@@ -2710,6 +2714,11 @@ static void __init ssb_select_mitigation(void)
 		ssb_mode = SPEC_STORE_BYPASS_DISABLE;
 		break;
 	case SPEC_STORE_BYPASS_CMD_AUTO:
+		if (should_mitigate_vuln(X86_BUG_SPEC_STORE_BYPASS))
+			ssb_mode = SPEC_STORE_BYPASS_PRCTL;
+		else
+			ssb_mode = SPEC_STORE_BYPASS_NONE;
+		break;
 	case SPEC_STORE_BYPASS_CMD_PRCTL:
 		ssb_mode = SPEC_STORE_BYPASS_PRCTL;
 		break;
#25 lore raw

PATCH v2 5/5 x86/bugs: Remove uses of cpu_mitigations_off()

In reply to David Kaplan

cpu_mitigations_off() is no longer needed because all bugs use attack vector controls to select a mitigation, and cpu_mitigations_off() is equivalent to no attack vectors being selected.

Remove the few remaining unnecessary uses of this function in this file.

---
 arch/x86/kernel/cpu/bugs.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
arch/x86/kernel/cpu/bugs.c +5 -5
index 059269f3f56f..556b3ba638f0 100644
@@ -670,8 +670,7 @@ static const char * const mmio_strings[] = {
 
 static void __init mmio_select_mitigation(void)
 {
-	if (!boot_cpu_has_bug(X86_BUG_MMIO_STALE_DATA) ||
-	     cpu_mitigations_off()) {
+	if (!boot_cpu_has_bug(X86_BUG_MMIO_STALE_DATA)) {
 		mmio_mitigation = MMIO_MITIGATION_OFF;
 		return;
 	}
@@ -3201,14 +3200,15 @@ static void __init srso_select_mitigation(void)
 
 static void __init srso_update_mitigation(void)
 {
+	if (!boot_cpu_has_bug(X86_BUG_SRSO))
+		return;
+
 	/* If retbleed is using IBPB, that works for SRSO as well */
 	if (retbleed_mitigation == RETBLEED_MITIGATION_IBPB &&
 	    boot_cpu_has(X86_FEATURE_IBPB_BRTYPE))
 		srso_mitigation = SRSO_MITIGATION_IBPB;
 
-	if (boot_cpu_has_bug(X86_BUG_SRSO) &&
-	    !cpu_mitigations_off())
-		pr_info("%s\n", srso_strings[srso_mitigation]);
+	pr_info("%s\n", srso_strings[srso_mitigation]);
 }
 
 static void __init srso_apply_mitigation(void)
Signature · 1 line
2.34.1
reviewer Reviewed-by on the v2 series
#26 lore raw
In reply to David Kaplan
Quoted 13 lines · David Kaplan

Patches 1-3 focus on cleaning up parameter parsing. Most mitigations use early_param but a few older ones do not and look at boot_command_line directly. Modify those to be consistent with the newer ones.

Patch 4 adds missing attack vector controls for spec store bypass.

Patch 5 cleans up straggling unnecessary calls to cpu_mitigations_off().

Changes from v1
- Removed spec_*_print_cond() functions
- Fixed bugs pointed out by Pawan
- Added last 2 patches

Quoted 6 lines

David Kaplan (5):
x86/bugs: Use early_param for spectre_v2_user
x86/bugs: Use early_param for spectre_v2
x86/bugs: Simplify SSB cmdline parsing
x86/bugs: Add attack vector controls for SSB
x86/bugs: Remove uses of cpu_mitigations_off()

For the series: