mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Maciej Wieczor-Retman <m.wieczorretman@pm.me>
To: bp@alien8.de, dave.hansen@linux.intel.com, hpa@zytor.com,
	xin@zytor.com, chang.seok.bae@intel.com, mingo@redhat.com,
	elena.reshetova@intel.com, maciej.wieczor-retman@intel.com,
	babu.moger@amd.com, sohil.mehta@intel.com,
	pawan.kumar.gupta@linux.intel.com, pmladek@suse.com,
	nik.borisov@suse.com, ptesarik@suse.com, darwi@linutronix.de,
	tglx@kernel.org, peterz@infradead.org, jpoimboe@kernel.org,
	ak@linux.intel.com
Cc: linux-kernel@vger.kernel.org, x86@kernel.org,
	m.wieczorretman@pm.me, Farrah Chen <farrah.chen@intel.com>
Subject: [PATCH v12 1/4] x86/cpu: Clear feature bits disabled at compile-time
Date: Fri, 27 Mar 2026 15:10:46 +0000	[thread overview]
Message-ID: <f6f113b46199d996c4f81fc89858c2f484256418.1774623092.git.m.wieczorretman@pm.me> (raw)
In-Reply-To: <cover.1774623092.git.m.wieczorretman@pm.me>

From: Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>

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. Examples of such feature flags are lam, fred, sgx, user_shstk and
enqcmd.

Initialize cpu_caps_cleared[] with an autogenerated disabled bitmask.
During CPU init, apply_forced_caps() will clear the corresponding bits
in struct cpuinfo_x86 for each CPU. Thus features disabled at compile
time won't show up in /proc/cpuinfo.

No BUGS are defined to be cleared at compile time, therefore only the
NCAPINTS part of cpu_caps_cleared[] is initialized using the macro. The
NBUGINTS part is set to zero.

Reported-by: Farrah Chen <farrah.chen@intel.com>
Closes: https://bugzilla.kernel.org/show_bug.cgi?id=220348
Signed-off-by: Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>
Reviewed-by: Sohil Mehta <sohil.mehta@intel.com>
---
Changelog v10:
- Remove examples of feature flags that came from stable kernels.
- Redo the patch message a bit with Sohil's suggestions.
- Add Sohil's Reviewed-by tag.

Changelog v9:
- *_MASK_INITIALIZER -> *_MASK_INIT
- Remove Cc stable.
- Note that the BUGS part of cpu_caps_cleared[] is zeroed.

Changelog v6:
- Remove patch message portions that are not just describing the diff.

 arch/x86/kernel/cpu/common.c       | 3 ++-
 arch/x86/tools/cpufeaturemasks.awk | 6 ++++++
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
index a8ff4376c286..76339e988304 100644
--- a/arch/x86/kernel/cpu/common.c
+++ b/arch/x86/kernel/cpu/common.c
@@ -735,7 +735,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_INIT;
 __u32 cpu_caps_set[NCAPINTS + NBUGINTS] __aligned(sizeof(unsigned long));
 
 #ifdef CONFIG_X86_32
diff --git a/arch/x86/tools/cpufeaturemasks.awk b/arch/x86/tools/cpufeaturemasks.awk
index 173d5bf2d999..9382bd15279a 100755
--- a/arch/x86/tools/cpufeaturemasks.awk
+++ b/arch/x86/tools/cpufeaturemasks.awk
@@ -82,6 +82,12 @@ END {
 		}
 		printf " 0\t\\\n";
 		printf "\t) & (1U << ((x) & 31)))\n\n";
+
+		printf "\n#define %s_MASK_INIT\t\t\t\\", s;
+		printf "\n\t{\t\t\t\t\t\t\\";
+		for (i = 0; i < ncapints; i++)
+			printf "\n\t\t%s_MASK%d,\t\t\t\\", s, i;
+		printf "\n\t}\n\n";
 	}
 
 	printf "#endif /* _ASM_X86_CPUFEATUREMASKS_H */\n";
-- 
2.53.0



  reply	other threads:[~2026-03-27 15:10 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-27 15:10 [PATCH v12 0/4] x86: Capability bits fix and required bits sanity check Maciej Wieczor-Retman
2026-03-27 15:10 ` Maciej Wieczor-Retman [this message]
2026-03-27 15:10 ` [PATCH v12 2/4] x86/cpu: Check if feature string is non-zero Maciej Wieczor-Retman
2026-03-27 17:50   ` Sohil Mehta
2026-03-27 21:28     ` Maciej Wieczor-Retman
2026-03-30 20:00   ` Borislav Petkov
2026-03-30 20:42     ` Maciej Wieczor-Retman
2026-03-30 21:15       ` Borislav Petkov
2026-03-30 21:44         ` H. Peter Anvin
2026-03-30 22:59           ` Borislav Petkov
2026-03-30 23:42             ` H. Peter Anvin
2026-03-31  2:15               ` H. Peter Anvin
2026-03-31 13:27               ` Borislav Petkov
2026-03-27 15:10 ` [PATCH v12 3/4] x86/cpu: Do a sanity check on required feature bits Maciej Wieczor-Retman
2026-03-27 17:10   ` Pawan Gupta
2026-03-27 17:22     ` Maciej Wieczor-Retman
2026-03-27 15:11 ` [PATCH v12 4/4] x86/cpu: Clear feature bits whose dependencies were cleared Maciej Wieczor-Retman
2026-03-28  2:22   ` H. Peter Anvin
2026-03-30 10:40     ` Maciej Wieczor-Retman
2026-03-30 21:41     ` Ahmed S. Darwish
2026-03-31 11:41       ` Maciej Wieczor-Retman
2026-04-01 15:16       ` Maciej Wieczor-Retman
2026-04-13 14:42         ` Ahmed S. Darwish
2026-03-30  6:11 ` [PATCH v12 0/4] x86: Capability bits fix and required bits sanity check Andi Kleen
2026-03-30  8:52   ` Maciej Wieczor-Retman
2026-03-30 23:40   ` H. Peter Anvin
2026-03-31 14:02 ` Borislav Petkov
2026-03-31 14:27   ` Maciej Wieczor-Retman
2026-03-31 14:46     ` Borislav Petkov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f6f113b46199d996c4f81fc89858c2f484256418.1774623092.git.m.wieczorretman@pm.me \
    --to=m.wieczorretman@pm.me \
    --cc=ak@linux.intel.com \
    --cc=babu.moger@amd.com \
    --cc=bp@alien8.de \
    --cc=chang.seok.bae@intel.com \
    --cc=darwi@linutronix.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=elena.reshetova@intel.com \
    --cc=farrah.chen@intel.com \
    --cc=hpa@zytor.com \
    --cc=jpoimboe@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maciej.wieczor-retman@intel.com \
    --cc=mingo@redhat.com \
    --cc=nik.borisov@suse.com \
    --cc=pawan.kumar.gupta@linux.intel.com \
    --cc=peterz@infradead.org \
    --cc=pmladek@suse.com \
    --cc=ptesarik@suse.com \
    --cc=sohil.mehta@intel.com \
    --cc=tglx@kernel.org \
    --cc=x86@kernel.org \
    --cc=xin@zytor.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox