Re: [PATCH v2 2/2] x86/tsx: Get the tsx= command line parameter with early_param()

From: Petr Tesarik
Date: Fri Oct 10 2025 - 03:41:31 EST


On Thu, 9 Oct 2025 11:51:34 -0700
Pawan Gupta <pawan.kumar.gupta@xxxxxxxxxxxxxxx> wrote:

> On Fri, Sep 26, 2025 at 08:01:02PM +0200, Petr Tesarik wrote:
> > Use early_param() to get the value of the tsx= command line parameter.
> > Although cmdline_find_option() 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). Prior to this patch, the kernel logged an error message
> > and disabled TSX. With this patch, the parameter is ignored. The new
> > behavior is consistent with other parameters, e.g. "tsx_async_abort".
> >
> > Signed-off-by: Petr Tesarik <ptesarik@xxxxxxxx>
> > ---
> > arch/x86/kernel/cpu/tsx.c | 41 ++++++++++++++++++++++-----------------
> > 1 file changed, 23 insertions(+), 18 deletions(-)
> >
> > diff --git a/arch/x86/kernel/cpu/tsx.c b/arch/x86/kernel/cpu/tsx.c
> > index 167dfd38b87a2..bb407331f64b5 100644
> > --- a/arch/x86/kernel/cpu/tsx.c
> > +++ b/arch/x86/kernel/cpu/tsx.c
> > @@ -20,14 +20,14 @@
> > #define pr_fmt(fmt) "tsx: " fmt
> >
> > enum tsx_ctrl_states {
> > + TSC_CTRL_UNSPECIFIED,
>
> s/TSC/TSX/

Ouch. Yes. ;-)

> > TSX_CTRL_ENABLE,
> > TSX_CTRL_DISABLE,
> > TSX_CTRL_RTM_ALWAYS_ABORT,
> > TSX_CTRL_NOT_SUPPORTED,
> > };
> >
> > -static enum tsx_ctrl_states tsx_ctrl_state __ro_after_init =
> > - TSX_CTRL_NOT_SUPPORTED;
> > +static enum tsx_ctrl_states tsx_ctrl_state __ro_after_init;
> >
> > static void tsx_disable(void)
> > {
> > @@ -164,11 +164,28 @@ static void tsx_dev_mode_disable(void)
> > }
> > }
> >
> > -void __init tsx_init(void)
> > +static int __init tsx_parse_cmdline(char *str)
> > {
> > - char arg[5] = {};
> > - int ret;
> > + if (!str)
> > + return -EINVAL;
> > +
> > + if (!strcmp(str, "on")) {
> > + tsx_ctrl_state = TSX_CTRL_ENABLE;
> > + } else if (!strcmp(str, "off")) {
> > + tsx_ctrl_state = TSX_CTRL_DISABLE;
> > + } else if (!strcmp(str, "auto")) {
> > + tsx_ctrl_state = x86_get_tsx_auto_mode();
>
> NACK, this introduces a subtle bug. With this change x86_get_tsx_auto_mode()
> would return TSX_CTRL_ENABLE always, irrespective of whether the CPU has
> X86_BUG_TAA or not. This is because early_param() is executed before
> cpu_set_bug_bits().

Thank you. I was afraid of some sort of init ordering issues, and I
could not test on a CPU with X86_BUG_TAA, unfortunately (because I have
none at hand).

> > + } else {
> > + tsx_ctrl_state = TSX_CTRL_DISABLE;
> > + pr_err("invalid option, defaulting to off\n");
> > + }
> >
> > + return 0;
> > +}
> > +early_param("tsx", tsx_parse_cmdline);
>
> Rather, a patch to add a comment would be better.

Well, some explanation would also have to go into
Documentation/admin-guide/kernel-parameters.txt

I'll consider the other proposed approach.
Thank you!

Petr T