]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
x86/bugs: Fix spectre_v2 forcing
authorDavid Kaplan <david.kaplan@amd.com>
Mon, 15 Sep 2025 13:47:04 +0000 (08:47 -0500)
committerBorislav Petkov (AMD) <bp@alien8.de>
Tue, 16 Sep 2025 10:59:55 +0000 (12:59 +0200)
commit30ef245c6f5a6842d60308590cf26d0ae836fbf0
tree65ce3a3541644f217ebb68bfcc526c9b48587abb
parent440d20154add24082eb43305f85288a756a5cc56
x86/bugs: Fix spectre_v2 forcing

There were two oddities with spectre_v2 command line options.

First, any option other than 'off' or 'auto' would force spectre_v2
mitigations even if the CPU (hypothetically) wasn't vulnerable to spectre_v2.
That was inconsistent with all the other bugs where mitigations are ignored
unless an explicit 'force' option is specified.

Second, even though spectre_v2 mitigations would be enabled in these cases,
the X86_BUG_SPECTRE_V2 bit wasn't set.  This is again inconsistent with the
forcing behavior of other bugs and arguably incorrect as it doesn't make sense
to enable a mitigation if the X86_BUG bit isn't set.

Fix both issues by only forcing spectre_v2 mitigations when the
'spectre_v2=on' option is specified (which was already called
SPECTRE_V2_CMD_FORCE) and setting the relevant X86_BUG_* bits in that case.

This also allows for simplifying bhi_update_mitigation() because
spectre_v2_cmd will now always be SPECTRE_V2_CMD_NONE if the CPU is immune to
spectre_v2.

Signed-off-by: David Kaplan <david.kaplan@amd.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Link: https://lore.kernel.org/20250915134706.3201818-1-david.kaplan@amd.com
arch/x86/kernel/cpu/bugs.c