Skip to content

Commit e9cc991

Browse files
ptesarikbp3tk0v
authored andcommitted
x86/tsx: Get the tsx= command line parameter with early_param()
Use early_param() to get the value of the tsx= command line parameter. It is an early parameter, because it must be parsed before tsx_init(), which is called long before kernel_init(), where normal parameters are parsed. Although cmdline_find_option() from tsx_init() works fine, the option is later reported as unknown and passed to user space. The latter is not a real issue, but the former is confusing and makes people wonder if the tsx= parameter had any effect and double-check for typos unnecessarily. The behavior changes slightly if "tsx" is given without any argument (which is invalid syntax). Until now, the kernel logged an error message and disabled TSX. Now, the kernel still issues a warning (Malformed early option 'tsx'), but TSX state is unchanged. The new behavior is consistent with other parameters, e.g. "tsx_async_abort". [ bp: Fixup minor formatting request during review. ] Suggested-by: Pawan Gupta <pawan.kumar.gupta@linux.intel.com> Signed-off-by: Petr Tesarik <ptesarik@suse.com> Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de> Link: https://lore.kernel.org/all/cover.1758906115.git.ptesarik@suse.com
1 parent f018fca commit e9cc991

1 file changed

Lines changed: 26 additions & 25 deletions

File tree

arch/x86/kernel/cpu/tsx.c

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,16 @@
2020
#define pr_fmt(fmt) "tsx: " fmt
2121

2222
enum tsx_ctrl_states {
23+
TSX_CTRL_AUTO,
2324
TSX_CTRL_ENABLE,
2425
TSX_CTRL_DISABLE,
2526
TSX_CTRL_RTM_ALWAYS_ABORT,
2627
TSX_CTRL_NOT_SUPPORTED,
2728
};
2829

29-
static enum tsx_ctrl_states tsx_ctrl_state __ro_after_init = TSX_CTRL_NOT_SUPPORTED;
30+
static enum tsx_ctrl_states tsx_ctrl_state __ro_after_init =
31+
IS_ENABLED(CONFIG_X86_INTEL_TSX_MODE_AUTO) ? TSX_CTRL_AUTO :
32+
IS_ENABLED(CONFIG_X86_INTEL_TSX_MODE_OFF) ? TSX_CTRL_DISABLE : TSX_CTRL_ENABLE;
3033

3134
static void tsx_disable(void)
3235
{
@@ -163,11 +166,28 @@ static void tsx_dev_mode_disable(void)
163166
}
164167
}
165168

166-
void __init tsx_init(void)
169+
static int __init tsx_parse_cmdline(char *str)
167170
{
168-
char arg[5] = {};
169-
int ret;
171+
if (!str)
172+
return -EINVAL;
173+
174+
if (!strcmp(str, "on")) {
175+
tsx_ctrl_state = TSX_CTRL_ENABLE;
176+
} else if (!strcmp(str, "off")) {
177+
tsx_ctrl_state = TSX_CTRL_DISABLE;
178+
} else if (!strcmp(str, "auto")) {
179+
tsx_ctrl_state = TSX_CTRL_AUTO;
180+
} else {
181+
tsx_ctrl_state = TSX_CTRL_DISABLE;
182+
pr_err("invalid option, defaulting to off\n");
183+
}
184+
185+
return 0;
186+
}
187+
early_param("tsx", tsx_parse_cmdline);
170188

189+
void __init tsx_init(void)
190+
{
171191
tsx_dev_mode_disable();
172192

173193
/*
@@ -201,27 +221,8 @@ void __init tsx_init(void)
201221
return;
202222
}
203223

204-
ret = cmdline_find_option(boot_command_line, "tsx", arg, sizeof(arg));
205-
if (ret >= 0) {
206-
if (!strcmp(arg, "on")) {
207-
tsx_ctrl_state = TSX_CTRL_ENABLE;
208-
} else if (!strcmp(arg, "off")) {
209-
tsx_ctrl_state = TSX_CTRL_DISABLE;
210-
} else if (!strcmp(arg, "auto")) {
211-
tsx_ctrl_state = x86_get_tsx_auto_mode();
212-
} else {
213-
tsx_ctrl_state = TSX_CTRL_DISABLE;
214-
pr_err("invalid option, defaulting to off\n");
215-
}
216-
} else {
217-
/* tsx= not provided */
218-
if (IS_ENABLED(CONFIG_X86_INTEL_TSX_MODE_AUTO))
219-
tsx_ctrl_state = x86_get_tsx_auto_mode();
220-
else if (IS_ENABLED(CONFIG_X86_INTEL_TSX_MODE_OFF))
221-
tsx_ctrl_state = TSX_CTRL_DISABLE;
222-
else
223-
tsx_ctrl_state = TSX_CTRL_ENABLE;
224-
}
224+
if (tsx_ctrl_state == TSX_CTRL_AUTO)
225+
tsx_ctrl_state = x86_get_tsx_auto_mode();
225226

226227
if (tsx_ctrl_state == TSX_CTRL_DISABLE) {
227228
tsx_disable();

0 commit comments

Comments
 (0)