Re: [RFC PATCH 04/56] x86/bugs: Reset spectre_v1 mitigations

From: Dave Hansen

Date: Tue Oct 14 2025 - 14:37:58 EST


On 10/13/25 07:33, David Kaplan wrote:
...
> +#ifdef CONFIG_DYNAMIC_MITIGATIONS
> +static void spectre_v1_reset_mitigation(void)
> +{
> + setup_clear_cpu_cap(X86_FEATURE_FENCE_SWAPGS_USER);
> + setup_clear_cpu_cap(X86_FEATURE_FENCE_SWAPGS_KERNEL);
> + spectre_v1_mitigation = SPECTRE_V1_MITIGATION_AUTO;
> +}
> +#endif
> +
> static int __init nospectre_v1_cmdline(char *str)
> {
> spectre_v1_mitigation = SPECTRE_V1_MITIGATION_NONE;
> @@ -3794,3 +3805,10 @@ void __warn_thunk(void)
> {
> WARN_ONCE(1, "Unpatched return thunk in use. This should not happen!\n");
> }
> +
> +#ifdef CONFIG_DYNAMIC_MITIGATIONS
> +void arch_cpu_reset_mitigations(void)
> +{
> + spectre_v1_reset_mitigation();
> +}
> +#endif

Are all the #ifdefs necessary? For instance, a single:

void arch_cpu_reset_mitigations(void)
{
+ if (!IS_ENABLED(CONFIG_DYNAMIC_MITIGATIONS))
+ return;
...

and removing *all* the #ifdefs might be enough to tell the compiler that
all the *_reset_mitigation() functions are unreachable.

But the larger concern through all of this is that this is all *new*
code. The reset concept is completely new and the reset functions look
to be ad-hoc. They follow a few patterns, but nothing super consistent.

Also, this series is going to need to be broken up. I'd suggest going
after the dynamic alternatives, first. I'm sure there's a need for that
_somewhere_ other than for vulnerabilities.

But, in the end, (IMNHO) this series really just adds complexity. It
doesn't do enough refactoring or complexity reduction to go in with this
approach.