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

From: Pawan Gupta
Date: Mon Jan 22 2024 - 19:25:59 EST


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
>