Skip to content

Commit ee89620

Browse files
committed
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) <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Tested-by: Srikanth Aithal <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent fec50db commit ee89620

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
@@ -150,8 +150,12 @@ extern const char * const x86_bug_flags[NBUGINTS*32];
150150
extern void setup_clear_cpu_cap(unsigned int bit);
151151
extern void clear_cpu_cap(struct cpuinfo_x86 *c, unsigned int bit);
152152

153-
#define setup_force_cpu_cap(bit) do { \
154-
set_cpu_cap(&boot_cpu_data, bit); \
153+
#define setup_force_cpu_cap(bit) do { \
154+
\
155+
if (!boot_cpu_has(bit)) \
156+
WARN_ON(alternatives_patched); \
157+
\
158+
set_cpu_cap(&boot_cpu_data, bit); \
155159
set_bit(bit, (unsigned long *)cpu_caps_set); \
156160
} while (0)
157161

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

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

117+
if (boot_cpu_has(feature))
118+
WARN_ON(alternatives_patched);
119+
117120
clear_feature(c, feature);
118121

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

0 commit comments

Comments
 (0)