>From 7dd94f58d28ac98dc39bebc8ce8479039bc069c8 Mon Sep 17 00:00:00 2001 From: Maciej Wieczor-Retman Date: Thu, 24 Jul 2025 08:34:33 +0200 Subject: [PATCH] x86: Clear feature bits disabled at compile time If some config options are disabled during compile time, they still are enumerated in macros that use the x86_capability bitmask - cpu_has() or this_cpu_has(). The features are also visible in /proc/cpuinfo even though they are not enabled - which is contrary to what the documentation states about the file. Mainline upstream kernel autogenerates the disabled masks at compile time, but this infrastructure was introduced in the 6.14 kernel. To backport this, open code the DISABLED_MASK_INITIALIZER macro instead. Initialize the cpu_caps_cleared array with the disabled bitmask. Fixes: ea4e3bef4c94 ("Documentation/x86: Add documentation for /proc/cpuinfo feature flags") Reported-by: Farrah Chen Signed-off-by: Maciej Wieczor-Retman Cc: --- arch/x86/include/asm/disabled-features.h | 26 ++++++++++++++++++++++++ arch/x86/kernel/cpu/common.c | 3 ++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/disabled-features.h b/arch/x86/include/asm/disabled-features.h index 170c87253340..a84e62cdae57 100644 --- a/arch/x86/include/asm/disabled-features.h +++ b/arch/x86/include/asm/disabled-features.h @@ -106,4 +106,30 @@ #define DISABLED_MASK21 0 #define DISABLED_MASK_CHECK BUILD_BUG_ON_ZERO(NCAPINTS != 23) +#define DISABLED_MASK_INITIALIZER \ + { \ + DISABLED_MASK0, \ + DISABLED_MASK1, \ + DISABLED_MASK2, \ + DISABLED_MASK3, \ + DISABLED_MASK4, \ + DISABLED_MASK5, \ + DISABLED_MASK6, \ + DISABLED_MASK7, \ + DISABLED_MASK8, \ + DISABLED_MASK9, \ + DISABLED_MASK10, \ + DISABLED_MASK11, \ + DISABLED_MASK12, \ + DISABLED_MASK13, \ + DISABLED_MASK14, \ + DISABLED_MASK15, \ + DISABLED_MASK16, \ + DISABLED_MASK17, \ + DISABLED_MASK18, \ + DISABLED_MASK19, \ + DISABLED_MASK20, \ + DISABLED_MASK21, \ + } + #endif /* _ASM_X86_DISABLED_FEATURES_H */ diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c index 258e28933abe..a3c323acff5f 100644 --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -588,7 +588,8 @@ static const char *table_lookup_model(struct cpuinfo_x86 *c) } /* Aligned to unsigned long to avoid split lock in atomic bitmap ops */ -__u32 cpu_caps_cleared[NCAPINTS + NBUGINTS] __aligned(sizeof(unsigned long)); +__u32 cpu_caps_cleared[NCAPINTS + NBUGINTS] __aligned(sizeof(unsigned long)) = + DISABLED_MASK_INITIALIZER; __u32 cpu_caps_set[NCAPINTS + NBUGINTS] __aligned(sizeof(unsigned long)); void load_percpu_segment(int cpu) -- 2.49.0