RE: [RFC PATCH 52/56] x86/bugs: Support parsing mitigation options

Kaplan, David
2025-10-27T13:56:44Z

[AMD Official Use Only - AMD Internal Distribution Only]

> -----Original Message-----
> From: Nikolay Borisov <nik.borisov@suse.com>
> Sent: Monday, October 27, 2025 6:31 AM
> To: Kaplan, David <David.Kaplan@amd.com>; Thomas Gleixner
> <tglx@linutronix.de>; Borislav Petkov <bp@alien8.de>; Peter Zijlstra
> <peterz@infradead.org>; Josh Poimboeuf <jpoimboe@kernel.org>; Pawan Gupta
> <pawan.kumar.gupta@linux.intel.com>; Ingo Molnar <mingo@redhat.com>; Dave
> Hansen <dave.hansen@linux.intel.com>; x86@kernel.org; H . Peter Anvin
> <hpa@zytor.com>
> Cc: Alexander Graf <graf@amazon.com>; Boris Ostrovsky
> <boris.ostrovsky@oracle.com>; linux-kernel@vger.kernel.org
> Subject: Re: [RFC PATCH 52/56] x86/bugs: Support parsing mitigation options
>
> Caution: This message originated from an External Source. Use proper caution
> when opening attachments, clicking links, or responding.
>
>
> On 10/13/25 17:34, David Kaplan wrote:
> > Add arch-specific function for determining if an option is related to a
> > mitigation and parsing it. These will be used for parsing a string of
> > options for re-evaluating cpu mitigations.
> >
> > Signed-off-by: David Kaplan <david.kaplan@amd.com>
> > ---
> > arch/x86/include/asm/bugs.h | 2 ++
> > arch/x86/kernel/cpu/bugs.c | 56
> +++++++++++++++++++++++++++++++++++++
> > 2 files changed, 58 insertions(+)
> >
> > diff --git a/arch/x86/include/asm/bugs.h b/arch/x86/include/asm/bugs.h
> > index 2e1a7d282e51..1e142a676335 100644
> > --- a/arch/x86/include/asm/bugs.h
> > +++ b/arch/x86/include/asm/bugs.h
> > @@ -13,5 +13,7 @@ static inline int ppro_with_ram_bug(void) { return 0; }
> > extern void cpu_bugs_smt_update(void);
> > void arch_cpu_reset_mitigations(void);
> > void cpu_bugs_update_speculation_msrs(void);
> > +bool arch_is_mitigation_opt(char *param);
> > +int arch_parse_mitigation_opt(char *param, char *val);
> >
> > #endif /* _ASM_X86_BUGS_H */
> > diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c
> > index 2f82261d033d..26ceb42e0cfb 100644
> > --- a/arch/x86/kernel/cpu/bugs.c
> > +++ b/arch/x86/kernel/cpu/bugs.c
> > @@ -3991,6 +3991,62 @@ void __warn_thunk(void)
> > }
> >
> > #ifdef CONFIG_DYNAMIC_MITIGATIONS
> > +struct mitigation_info {
> > + char *param;
> > + int (*parse)(char *str);
> > +};
> > +
> > +static struct mitigation_info mitigation_parsers[] = {
> > + {"mds", mds_cmdline},
> > + {"tsx_async_abort", tsx_async_abort_parse_cmdline},
> > + {"mmio_stale_data", mmio_stale_data_parse_cmdline},
> > + {"reg_file_data_sampling", rfds_parse_cmdline},
> > + {"srbds", srbds_parse_cmdline},
> > + {"gather_data_sampling", gds_parse_cmdline},
> > + {"nospectre_v1", nospectre_v1_cmdline},
> > + {"retbleed", retbleed_parse_cmdline},
> > + {"indirect_target_selection", its_parse_cmdline},
> > + {"spectre_v2_user", spectre_v2_user_parse_cmdline},
> > + {"nospectre_v2", nospectre_v2_parse_cmdline},
> > + {"spectre_v2", spectre_v2_parse_cmdline},
> > + {"spectre_bhi", spectre_bhi_parse_cmdline},
> > + {"nospec_store_bypass_disable", nossb_parse_cmdline},
> > + {"spec_store_bypass_disable", ssb_parse_cmdline},
> > + {"l1tf", l1tf_cmdline},
> > + {"spec_rstack_overflow", srso_parse_cmdline},
> > + {"tsa", tsa_parse_cmdline},
> > + {"vmscape", vmscape_parse_cmdline}
> > +};
> > +
> > +static struct mitigation_info *get_mitigation_info(char *param)
> > +{
> > + int i;
> > +
> > + for (i = 0; i < ARRAY_SIZE(mitigation_parsers); i++) {
> > + if (parameq(param, mitigation_parsers[i].param))
> > + return &mitigation_parsers[i];
> > + }
> > +
> > + return NULL;
> > +}
> > +
> > +bool arch_is_mitigation_opt(char *param)
> > +{
> > + return get_mitigation_info(param);
>
> nit: This has an implied conversion from a pointer to a bool, should it
> be return get_mitigation_info != NULL
>
> It would work either ways but being explicit is better?

Ack

>
> > +}
> > +
> > +int arch_parse_mitigation_opt(char *param, char *val)
> > +{
> > + struct mitigation_info *info = get_mitigation_info(param);
> > +
> > + if (!info) {
> > + pr_warn("Ignoring non-mitigation option %s\n", param);
>
> nit: Do we want to be that verbose?

My thinking was that the admin is writing a series of cmdline options to this interface, but the interface only recognizes a small number of specific cmdline options (the ones related to mitigation settings). It therefore may make sense to warn them if they've written an option (thinking it will have an effect) but it is not supported by this interface. It's also a way to notify them if they made a typo on an option.

That said, open to other ideas here.

Thanks
--David Kaplan