Skip to content

Commit 9bb80fc

Browse files
committed
x86/alternatives: Catch late X86_FEATURE modifiers
JIRA: https://issues.redhat.com/browse/RHEL-68940 commit ee89620 Author: Borislav Petkov (AMD) <bp@alien8.de> Date: Wed, 27 Mar 2024 16:43:14 +0100 x86/alternatives: Catch late X86_FEATURE modifiers After alternatives have been patched, changes to the X86_FEATURE flags won't take effect and could potentially even be wrong. Warn about it. This is something which has been long overdue. Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de> Signed-off-by: Ingo Molnar <mingo@kernel.org> Tested-by: Srikanth Aithal <sraithal@amd.com> Link: https://lore.kernel.org/r/20240327154317.29909-3-bp@alien8.de Signed-off-by: Waiman Long <longman@redhat.com>
1 parent fac4d60 commit 9bb80fc

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

arch/x86/include/asm/cpufeature.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,12 @@ extern const char * const x86_bug_flags[NBUGINTS*32];
163163
extern void setup_clear_cpu_cap(unsigned int bit);
164164
extern void clear_cpu_cap(struct cpuinfo_x86 *c, unsigned int bit);
165165

166-
#define setup_force_cpu_cap(bit) do { \
167-
set_cpu_cap(&boot_cpu_data, bit); \
166+
#define setup_force_cpu_cap(bit) do { \
167+
\
168+
if (!boot_cpu_has(bit)) \
169+
WARN_ON(alternatives_patched); \
170+
\
171+
set_cpu_cap(&boot_cpu_data, bit); \
168172
set_bit(bit, (unsigned long *)cpu_caps_set); \
169173
} while (0)
170174

arch/x86/kernel/cpu/cpuid-deps.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ static void do_clear_cpu_cap(struct cpuinfo_x86 *c, unsigned int feature)
112112
if (WARN_ON(feature >= MAX_FEATURE_BITS))
113113
return;
114114

115+
if (boot_cpu_has(feature))
116+
WARN_ON(alternatives_patched);
117+
115118
clear_feature(c, feature);
116119

117120
/* Collect all features to disable, handling dependencies */

0 commit comments

Comments
 (0)