[PATCH 1/2] x86/alternatives: Check the correct cpu_data's caps

From: Borislav Petkov
Date: Sat May 04 2024 - 08:50:16 EST


From: "Borislav Petkov (AMD)" <bp@xxxxxxxxx>
Date: Wed, 1 May 2024 11:26:16 +0200

Commit

ee8962082a44 ("x86/alternatives: Catch late X86_FEATURE modifiers")

added warns for when code modifies feature flags after alternatives have
been patched.

The clearing, however, checks whether the feature flag is previously
set on the boot CPU but the @c argument supplied can be any CPU.

Make sure that other CPU's feature flag is checked instead, as it should
be.

Fixes: ee8962082a44 ("x86/alternatives: Catch late X86_FEATURE modifiers")
Signed-off-by: Borislav Petkov (AMD) <bp@xxxxxxxxx>
---
arch/x86/kernel/cpu/cpuid-deps.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/kernel/cpu/cpuid-deps.c b/arch/x86/kernel/cpu/cpuid-deps.c
index 5dd427c6feb2..93fa2afc0c67 100644
--- a/arch/x86/kernel/cpu/cpuid-deps.c
+++ b/arch/x86/kernel/cpu/cpuid-deps.c
@@ -114,7 +114,7 @@ static void do_clear_cpu_cap(struct cpuinfo_x86 *c, unsigned int feature)
if (WARN_ON(feature >= MAX_FEATURE_BITS))
return;

- if (boot_cpu_has(feature))
+ if (c && cpu_has(c, feature))
WARN_ON(alternatives_patched);

clear_feature(c, feature);
--
2.43.0


--
Regards/Gruss,
Boris.

https://people.kernel.org/tglx/notes-about-netiquette