[3/3] x86/bugs: spectre_v2_user default mode depends on main default

Message ID 20240118173213.2008115-4-leitao@debian.org
State New
Headers
Series x86/bugs: Separate config for mitigations (part 2) |

Commit Message

Breno Leitao Jan. 18, 2024, 5:32 p.m. UTC
  Change the default value of spectre v2 in user mode to respect the
CONFIG_MITIGATION_SPECTRE_V2 config option.

Currently, user mode spectre v2 is set to auto
(SPECTRE_V2_USER_CMD_AUTO) by default, even if
CONFIG_MITIGATION_SPECTRE_V2 is disabled.

Set the Spectre_v2 value to auto (SPECTRE_V2_USER_CMD_AUTO) if the
Spectre v2 config (CONFIG_MITIGATION_SPECTRE_V2) is enabled, otherwise
set the value to none (SPECTRE_V2_USER_CMD_NONE).

Important to say the command line argument "spectre_v2_user" overwrites
the default value in both cases.

Signed-off-by: Breno Leitao <leitao@debian.org>
Acked-by: Josh Poimboeuf <jpoimboe@kernel.org>
---
 arch/x86/kernel/cpu/bugs.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
  

Comments

Pawan Gupta Jan. 23, 2024, 12:04 a.m. UTC | #1
On Thu, Jan 18, 2024 at 09:32:13AM -0800, Breno Leitao wrote:
>  static enum spectre_v2_user_cmd __init
>  spectre_v2_parse_user_cmdline(void)
>  {
> +	int ret, i, mode;

mode is being returned, it is better to match its type with function's
return type "enum spectre_v2_user_cmd".

>  	char arg[20];
> -	int ret, i;
> +
> +	mode = IS_ENABLED(CONFIG_MITIGATION_SPECTRE_V2) ?
> +		SPECTRE_V2_USER_CMD_AUTO : SPECTRE_V2_USER_CMD_NONE;
>  
>  	switch (spectre_v2_cmd) {
>  	case SPECTRE_V2_CMD_NONE:
> @@ -1236,7 +1239,7 @@ spectre_v2_parse_user_cmdline(void)
>  	ret = cmdline_find_option(boot_command_line, "spectre_v2_user",
>  				  arg, sizeof(arg));
>  	if (ret < 0)
> -		return SPECTRE_V2_USER_CMD_AUTO;
> +		return mode;
>  
>  	for (i = 0; i < ARRAY_SIZE(v2_user_options); i++) {
>  		if (match_option(arg, ret, v2_user_options[i].option)) {
> @@ -1246,8 +1249,8 @@ spectre_v2_parse_user_cmdline(void)
>  		}
>  	}
>  
> -	pr_err("Unknown user space protection option (%s). Switching to AUTO select\n", arg);
> -	return SPECTRE_V2_USER_CMD_AUTO;
> +	pr_err("Unknown user space protection option (%s). Switching to default\n", arg);
> +	return mode;
>  }
>  
>  static inline bool spectre_v2_in_ibrs_mode(enum spectre_v2_mitigation mode)
> -- 
> 2.34.1
>
  
Breno Leitao Jan. 23, 2024, 3:02 p.m. UTC | #2
On Mon, Jan 22, 2024 at 04:04:31PM -0800, Pawan Gupta wrote:
> On Thu, Jan 18, 2024 at 09:32:13AM -0800, Breno Leitao wrote:
> >  static enum spectre_v2_user_cmd __init
> >  spectre_v2_parse_user_cmdline(void)
> >  {
> > +	int ret, i, mode;
> 
> mode is being returned, it is better to match its type with function's
> return type "enum spectre_v2_user_cmd".

Agree. I will update. Thanks!
  

Patch

diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c
index 11ccbadd8800..4f1da92784c6 100644
--- a/arch/x86/kernel/cpu/bugs.c
+++ b/arch/x86/kernel/cpu/bugs.c
@@ -1221,8 +1221,11 @@  static __ro_after_init enum spectre_v2_mitigation_cmd spectre_v2_cmd;
 static enum spectre_v2_user_cmd __init
 spectre_v2_parse_user_cmdline(void)
 {
+	int ret, i, mode;
 	char arg[20];
-	int ret, i;
+
+	mode = IS_ENABLED(CONFIG_MITIGATION_SPECTRE_V2) ?
+		SPECTRE_V2_USER_CMD_AUTO : SPECTRE_V2_USER_CMD_NONE;
 
 	switch (spectre_v2_cmd) {
 	case SPECTRE_V2_CMD_NONE:
@@ -1236,7 +1239,7 @@  spectre_v2_parse_user_cmdline(void)
 	ret = cmdline_find_option(boot_command_line, "spectre_v2_user",
 				  arg, sizeof(arg));
 	if (ret < 0)
-		return SPECTRE_V2_USER_CMD_AUTO;
+		return mode;
 
 	for (i = 0; i < ARRAY_SIZE(v2_user_options); i++) {
 		if (match_option(arg, ret, v2_user_options[i].option)) {
@@ -1246,8 +1249,8 @@  spectre_v2_parse_user_cmdline(void)
 		}
 	}
 
-	pr_err("Unknown user space protection option (%s). Switching to AUTO select\n", arg);
-	return SPECTRE_V2_USER_CMD_AUTO;
+	pr_err("Unknown user space protection option (%s). Switching to default\n", arg);
+	return mode;
 }
 
 static inline bool spectre_v2_in_ibrs_mode(enum spectre_v2_mitigation mode)