* [PATCH v7 0/4] x86/cpufeatures: Automatically generate required and disabled feature masks
@ 2025-03-05 18:47 Xin Li (Intel)
2025-03-05 18:47 ` [PATCH v7 1/4] x86/cpufeatures: Add {required,disabled} feature configs Xin Li (Intel)
` (4 more replies)
0 siblings, 5 replies; 20+ messages in thread
From: Xin Li (Intel) @ 2025-03-05 18:47 UTC (permalink / raw)
To: linux-kernel, linux-perf-users
Cc: tglx, mingo, bp, dave.hansen, x86, hpa, will, peterz, yury.norov,
akpm, acme, namhyung, brgerst, andrew.cooper3, nik.borisov,
sraithal, philip.li
The x86 build process first generates required and disabled feature
masks based on current build config, and then uses these generated
masks to compile the source code. When a CPU feature is not enabled
in a build config, e.g., when CONFIG_X86_FRED=n, its feature disable
flag, i.e., DISABLE_FRED, needs to be properly defined and added to
a specific disabled CPU features mask in <asm/disabled-features.h>,
as the following patch does:
https://lore.kernel.org/all/20231205105030.8698-8-xin3.li@intel.com/.
As a result, the FRED feature bit is surely cleared in the generated
kernel binary when CONFIG_X86_FRED=n.
Recently there is another case to repeat the same exercise for the
AMD SEV-SNP CPU feature:
https://lore.kernel.org/all/20240126041126.1927228-2-michael.roth@amd.com/.
https://lore.kernel.org/all/20240126041126.1927228-23-michael.roth@amd.com/.
It was one thing when there were four of CPU feature masks, but with
over 20 it is going to cause mistakes, e.g.,
https://lore.kernel.org/lkml/aaed79d5-d683-d1bc-7ba1-b33c8d6db618@suse.com/.
We want to eliminate the stupidly repeated exercise to manually assign
features to CPU feature words through introducing an AWK script to
automatically generate a header with required and disabled CPU feature
masks based on current build config, and this patch set does that.
Link to v6:
https://lore.kernel.org/lkml/20250228082338.73859-1-xin@zytor.com/
Changes in v7:
* Fix build error with "make distclean; make headers" (Aithal, Srikanth)
* Collect reviewed-bys.
H. Peter Anvin (Intel) (2):
x86/cpufeatures: Add {required,disabled} feature configs
x86/cpufeatures: Generate a feature mask header based on build config
Xin Li (Intel) (2):
x86/cpufeatures: Remove {disabled,required}-features.h
x86/cpufeatures: Use AWK to generate {REQUIRED|DISABLED}_MASK_BIT_SET
arch/x86/Kconfig | 2 +
arch/x86/Kconfig.cpufeatures | 197 ++++++++++++++++++
arch/x86/Makefile | 15 ++
arch/x86/boot/cpucheck.c | 3 +-
arch/x86/boot/cpuflags.c | 1 -
arch/x86/boot/mkcpustr.c | 3 +-
arch/x86/include/asm/Kbuild | 1 +
arch/x86/include/asm/cpufeature.h | 70 +------
arch/x86/include/asm/cpufeatures.h | 8 -
arch/x86/include/asm/disabled-features.h | 161 --------------
arch/x86/include/asm/required-features.h | 105 ----------
arch/x86/kernel/verify_cpu.S | 4 +
arch/x86/tools/featuremasks.awk | 88 ++++++++
tools/arch/x86/include/asm/cpufeatures.h | 8 -
.../arch/x86/include/asm/disabled-features.h | 161 --------------
.../arch/x86/include/asm/required-features.h | 105 ----------
tools/perf/check-headers.sh | 2 -
17 files changed, 311 insertions(+), 623 deletions(-)
create mode 100644 arch/x86/Kconfig.cpufeatures
delete mode 100644 arch/x86/include/asm/disabled-features.h
delete mode 100644 arch/x86/include/asm/required-features.h
create mode 100755 arch/x86/tools/featuremasks.awk
delete mode 100644 tools/arch/x86/include/asm/disabled-features.h
delete mode 100644 tools/arch/x86/include/asm/required-features.h
base-commit: 32dc26a2f55f71907af0874468298c6ab8a8f7f9
--
2.48.1
^ permalink raw reply [flat|nested] 20+ messages in thread
* [PATCH v7 1/4] x86/cpufeatures: Add {required,disabled} feature configs
2025-03-05 18:47 [PATCH v7 0/4] x86/cpufeatures: Automatically generate required and disabled feature masks Xin Li (Intel)
@ 2025-03-05 18:47 ` Xin Li (Intel)
2025-03-05 18:47 ` [PATCH v7 2/4] x86/cpufeatures: Generate a feature mask header based on build config Xin Li (Intel)
` (3 subsequent siblings)
4 siblings, 0 replies; 20+ messages in thread
From: Xin Li (Intel) @ 2025-03-05 18:47 UTC (permalink / raw)
To: linux-kernel, linux-perf-users
Cc: tglx, mingo, bp, dave.hansen, x86, hpa, will, peterz, yury.norov,
akpm, acme, namhyung, brgerst, andrew.cooper3, nik.borisov,
sraithal, philip.li
From: "H. Peter Anvin (Intel)" <hpa@zytor.com>
Required and disabled feature masks completely rely on build configs,
i.e., once a build config is fixed, so are the feature masks. To
prepare for auto-generating a header with required and disabled feature
masks based on a build config, add feature Kconfig items:
- X86_REQUIRED_FEATURE_x
- X86_DISABLED_FEATURE_x
each of which may be set to "y" if and only if its preconditions from
current build config are met.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
Signed-off-by: Xin Li (Intel) <xin@zytor.com>
Reviewed-by: Ingo Molnar <mingo@kernel.org>
---
Change in v7:
* Collect reviewed-bys.
Changes in v6:
* Move changes to X86_CMPXCHG64 to a separate patch (Borislav Petkov).
* Keep X86_{CX8,CMOV} and define X86_REQUIRED_FEATURE_{CX8,CMOV} on top
(Borislav Petkov).
Changes in v2:
* Keep the X86_{REQUIRED,DISABLED}_FEATURE_ prefixes solely in
arch/x86/Kconfig.cpufeatures (Borislav Petkov).
* Explain how config option names X86_{REQUIRED,DISABLED}_FEATURE_<name>
are formed (Borislav Petkov).
---
arch/x86/Kconfig | 2 +
arch/x86/Kconfig.cpufeatures | 197 +++++++++++++++++++++++++++++++++++
2 files changed, 199 insertions(+)
create mode 100644 arch/x86/Kconfig.cpufeatures
diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 1e50da06ffc4..1b12725cac8c 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -3130,4 +3130,6 @@ config HAVE_ATOMIC_IOMAP
source "arch/x86/kvm/Kconfig"
+source "arch/x86/Kconfig.cpufeatures"
+
source "arch/x86/Kconfig.assembler"
diff --git a/arch/x86/Kconfig.cpufeatures b/arch/x86/Kconfig.cpufeatures
new file mode 100644
index 000000000000..5dcc49d928c5
--- /dev/null
+++ b/arch/x86/Kconfig.cpufeatures
@@ -0,0 +1,197 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+# x86 feature bits (see arch/x86/include/asm/cpufeatures.h) that are
+# either REQUIRED to be enabled, or DISABLED (always ignored) for this
+# particular compile-time configuration. The tests for these features
+# are turned into compile-time constants via the generated
+# <asm/featuremasks.h>.
+#
+# The naming of these variables *must* match asm/cpufeatures.h, e.g.,
+# X86_FEATURE_ALWAYS <==> X86_REQUIRED_FEATURE_ALWAYS
+# X86_FEATURE_FRED <==> X86_DISABLED_FEATURE_FRED
+#
+# And these REQUIRED and DISABLED config options are manipulated in an
+# AWK script as the following example:
+#
+# +----------------------+
+# | X86_FRED = y ? |
+# +----------------------+
+# / \
+# Y / \ N
+# +-------------------------------------+ +-------------------------------+
+# | X86_DISABLED_FEATURE_FRED undefined | | X86_DISABLED_FEATURE_FRED = y |
+# +-------------------------------------+ +-------------------------------+
+# |
+# |
+# +-------------------------------------------+ |
+# | X86_FEATURE_FRED: feature word 12, bit 17 | ---->|
+# +-------------------------------------------+ |
+# |
+# |
+# +-------------------------------+
+# | set bit 17 of DISABLED_MASK12 |
+# +-------------------------------+
+#
+
+config X86_REQUIRED_FEATURE_ALWAYS
+ def_bool y
+
+config X86_REQUIRED_FEATURE_NOPL
+ def_bool y
+ depends on X86_64 || X86_P6_NOP
+
+config X86_REQUIRED_FEATURE_CX8
+ def_bool y
+ depends on X86_CX8
+
+# this should be set for all -march=.. options where the compiler
+# generates cmov.
+config X86_REQUIRED_FEATURE_CMOV
+ def_bool y
+ depends on X86_CMOV
+
+# this should be set for all -march= options where the compiler
+# generates movbe.
+config X86_REQUIRED_FEATURE_MOVBE
+ def_bool y
+ depends on MATOM
+
+config X86_REQUIRED_FEATURE_CPUID
+ def_bool y
+ depends on X86_64
+
+config X86_REQUIRED_FEATURE_UP
+ def_bool y
+ depends on !SMP
+
+config X86_REQUIRED_FEATURE_FPU
+ def_bool y
+ depends on !MATH_EMULATION
+
+config X86_REQUIRED_FEATURE_PAE
+ def_bool y
+ depends on X86_64 || X86_PAE
+
+config X86_REQUIRED_FEATURE_PSE
+ def_bool y
+ depends on X86_64 && !PARAVIRT_XXL
+
+config X86_REQUIRED_FEATURE_PGE
+ def_bool y
+ depends on X86_64 && !PARAVIRT_XXL
+
+config X86_REQUIRED_FEATURE_MSR
+ def_bool y
+ depends on X86_64
+
+config X86_REQUIRED_FEATURE_FXSR
+ def_bool y
+ depends on X86_64
+
+config X86_REQUIRED_FEATURE_XMM
+ def_bool y
+ depends on X86_64
+
+config X86_REQUIRED_FEATURE_XMM2
+ def_bool y
+ depends on X86_64
+
+config X86_REQUIRED_FEATURE_LM
+ def_bool y
+ depends on X86_64
+
+config X86_DISABLED_FEATURE_UMIP
+ def_bool y
+ depends on !X86_UMIP
+
+config X86_DISABLED_FEATURE_VME
+ def_bool y
+ depends on X86_64
+
+config X86_DISABLED_FEATURE_K6_MTRR
+ def_bool y
+ depends on X86_64
+
+config X86_DISABLED_FEATURE_CYRIX_ARR
+ def_bool y
+ depends on X86_64
+
+config X86_DISABLED_FEATURE_CENTAUR_MCR
+ def_bool y
+ depends on X86_64
+
+config X86_DISABLED_FEATURE_PCID
+ def_bool y
+ depends on !X86_64
+
+config X86_DISABLED_FEATURE_PKU
+ def_bool y
+ depends on !X86_INTEL_MEMORY_PROTECTION_KEYS
+
+config X86_DISABLED_FEATURE_OSPKE
+ def_bool y
+ depends on !X86_INTEL_MEMORY_PROTECTION_KEYS
+
+config X86_DISABLED_FEATURE_LA57
+ def_bool y
+ depends on !X86_5LEVEL
+
+config X86_DISABLED_FEATURE_PTI
+ def_bool y
+ depends on !MITIGATION_PAGE_TABLE_ISOLATION
+
+config X86_DISABLED_FEATURE_RETPOLINE
+ def_bool y
+ depends on !MITIGATION_RETPOLINE
+
+config X86_DISABLED_FEATURE_RETPOLINE_LFENCE
+ def_bool y
+ depends on !MITIGATION_RETPOLINE
+
+config X86_DISABLED_FEATURE_RETHUNK
+ def_bool y
+ depends on !MITIGATION_RETHUNK
+
+config X86_DISABLED_FEATURE_UNRET
+ def_bool y
+ depends on !MITIGATION_UNRET_ENTRY
+
+config X86_DISABLED_FEATURE_CALL_DEPTH
+ def_bool y
+ depends on !MITIGATION_CALL_DEPTH_TRACKING
+
+config X86_DISABLED_FEATURE_LAM
+ def_bool y
+ depends on !ADDRESS_MASKING
+
+config X86_DISABLED_FEATURE_ENQCMD
+ def_bool y
+ depends on !INTEL_IOMMU_SVM
+
+config X86_DISABLED_FEATURE_SGX
+ def_bool y
+ depends on !X86_SGX
+
+config X86_DISABLED_FEATURE_XENPV
+ def_bool y
+ depends on !XEN_PV
+
+config X86_DISABLED_FEATURE_TDX_GUEST
+ def_bool y
+ depends on !INTEL_TDX_GUEST
+
+config X86_DISABLED_FEATURE_USER_SHSTK
+ def_bool y
+ depends on !X86_USER_SHADOW_STACK
+
+config X86_DISABLED_FEATURE_IBT
+ def_bool y
+ depends on !X86_KERNEL_IBT
+
+config X86_DISABLED_FEATURE_FRED
+ def_bool y
+ depends on !X86_FRED
+
+config X86_DISABLED_FEATURE_SEV_SNP
+ def_bool y
+ depends on !KVM_AMD_SEV
--
2.48.1
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH v7 2/4] x86/cpufeatures: Generate a feature mask header based on build config
2025-03-05 18:47 [PATCH v7 0/4] x86/cpufeatures: Automatically generate required and disabled feature masks Xin Li (Intel)
2025-03-05 18:47 ` [PATCH v7 1/4] x86/cpufeatures: Add {required,disabled} feature configs Xin Li (Intel)
@ 2025-03-05 18:47 ` Xin Li (Intel)
2025-03-10 8:18 ` [tip: x86/cpu] x86/cpufeatures: Generate the <asm/cpufeaturemasks.h> " tip-bot2 for H. Peter Anvin (Intel)
2025-03-19 11:03 ` [tip: x86/core] " tip-bot2 for H. Peter Anvin (Intel)
2025-03-05 18:47 ` [PATCH v7 3/4] x86/cpufeatures: Remove {disabled,required}-features.h Xin Li (Intel)
` (2 subsequent siblings)
4 siblings, 2 replies; 20+ messages in thread
From: Xin Li (Intel) @ 2025-03-05 18:47 UTC (permalink / raw)
To: linux-kernel, linux-perf-users
Cc: tglx, mingo, bp, dave.hansen, x86, hpa, will, peterz, yury.norov,
akpm, acme, namhyung, brgerst, andrew.cooper3, nik.borisov,
sraithal, philip.li
From: "H. Peter Anvin (Intel)" <hpa@zytor.com>
Introduce an AWK script to auto-generate a header with required and
disabled feature masks based on <asm/cpufeatures.h> and current build
config. Thus for any CPU feature with a build config, e.g., X86_FRED,
simply add
config X86_DISABLED_FEATURE_FRED
def_bool y
depends on !X86_FRED
to arch/x86/Kconfig.cpufeatures, instead of adding a conditional CPU
feature disable flag, e.g., DISABLE_FRED.
Lastly the generated required and disabled feature masks will be added
to their corresponding feature masks for this particular compile-time
configuration.
[ Xin: build integration improvements ]
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
Signed-off-by: Xin Li (Intel) <xin@zytor.com>
Reviewed-by: Nikolay Borisov <nik.borisov@suse.com>
Reviewed-by: Ingo Molnar <mingo@kernel.org>
---
Changes in v7:
* Fix build error with "make distclean; make headers" (Aithal, Srikanth).
* Collect reviewed-bys.
Change in v6:
* Make the AWK script work for mawk and BusyBox awk (Borislav Petkov).
Change in v5:
* More polishes (Nikolay Borisov).
Changes in v4:
* Add a few high-level comments to the AWK script (Nikolay Borisov).
* Enforce CPU feature mask values to be unsigned.
Changes in v3:
* Remove AWK code that generates extra debugging comments (Brian Gerst).
* Move SSE_MASK to verify_cpu.S, the only place it is used (Brian Gerst).
Change in v2:
* Remove code generating unused macros {REQUIRED,DISABLED}_FEATURE(x)
to tell if a CPU feature, e.g., X86_FEATURE_FRED, is a required or
disabled feature for this particular compile-time configuration.
---
arch/x86/Makefile | 15 ++++++
arch/x86/boot/cpucheck.c | 3 +-
arch/x86/boot/cpuflags.c | 1 -
arch/x86/boot/mkcpustr.c | 3 +-
arch/x86/include/asm/Kbuild | 1 +
arch/x86/include/asm/cpufeature.h | 1 +
arch/x86/include/asm/cpufeatures.h | 8 ---
arch/x86/kernel/verify_cpu.S | 4 ++
arch/x86/tools/featuremasks.awk | 81 ++++++++++++++++++++++++++++++
9 files changed, 105 insertions(+), 12 deletions(-)
create mode 100755 arch/x86/tools/featuremasks.awk
diff --git a/arch/x86/Makefile b/arch/x86/Makefile
index 6784129328f6..f0e8a23d2678 100644
--- a/arch/x86/Makefile
+++ b/arch/x86/Makefile
@@ -268,6 +268,21 @@ archscripts: scripts_basic
archheaders:
$(Q)$(MAKE) $(build)=arch/x86/entry/syscalls all
+###
+# Feature masks header generation
+
+featuremasks_hdr := arch/x86/include/generated/asm/featuremasks.h
+featuremasks_awk := $(srctree)/arch/x86/tools/featuremasks.awk
+cpufeatures_hdr := $(srctree)/arch/x86/include/asm/cpufeatures.h
+targets += $(featuremasks_hdr)
+quiet_cmd_gen_featuremasks = GEN $@
+ cmd_gen_featuremasks = $(AWK) -f $(featuremasks_awk) $(cpufeatures_hdr) $(KCONFIG_CONFIG) > $@
+
+$(featuremasks_hdr): $(featuremasks_awk) $(cpufeatures_hdr) $(KCONFIG_CONFIG) FORCE
+ $(shell mkdir -p $(dir $@))
+ $(call if_changed,gen_featuremasks)
+archprepare: $(featuremasks_hdr)
+
###
# Kernel objects
diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
index 0aae4d4ed615..8d03a741d1b2 100644
--- a/arch/x86/boot/cpucheck.c
+++ b/arch/x86/boot/cpucheck.c
@@ -22,10 +22,11 @@
# include "boot.h"
#endif
#include <linux/types.h>
+#include <asm/featuremasks.h>
#include <asm/intel-family.h>
#include <asm/processor-flags.h>
-#include <asm/required-features.h>
#include <asm/msr-index.h>
+
#include "string.h"
#include "msr.h"
diff --git a/arch/x86/boot/cpuflags.c b/arch/x86/boot/cpuflags.c
index d75237ba7ce9..0cabdacb2a2f 100644
--- a/arch/x86/boot/cpuflags.c
+++ b/arch/x86/boot/cpuflags.c
@@ -3,7 +3,6 @@
#include "bitops.h"
#include <asm/processor-flags.h>
-#include <asm/required-features.h>
#include <asm/msr-index.h>
#include "cpuflags.h"
diff --git a/arch/x86/boot/mkcpustr.c b/arch/x86/boot/mkcpustr.c
index da0ccc5de538..b90110109675 100644
--- a/arch/x86/boot/mkcpustr.c
+++ b/arch/x86/boot/mkcpustr.c
@@ -12,8 +12,6 @@
#include <stdio.h>
-#include "../include/asm/required-features.h"
-#include "../include/asm/disabled-features.h"
#include "../include/asm/cpufeatures.h"
#include "../include/asm/vmxfeatures.h"
#include "../kernel/cpu/capflags.c"
@@ -23,6 +21,7 @@ int main(void)
int i, j;
const char *str;
+ printf("#include <asm/featuremasks.h>\n\n");
printf("static const char x86_cap_strs[] =\n");
for (i = 0; i < NCAPINTS; i++) {
diff --git a/arch/x86/include/asm/Kbuild b/arch/x86/include/asm/Kbuild
index 58f4ddecc5fa..51022d21003e 100644
--- a/arch/x86/include/asm/Kbuild
+++ b/arch/x86/include/asm/Kbuild
@@ -8,6 +8,7 @@ generated-y += syscalls_x32.h
generated-y += unistd_32_ia32.h
generated-y += unistd_64_x32.h
generated-y += xen-hypercalls.h
+generated-y += featuremasks.h
generic-y += early_ioremap.h
generic-y += fprobe.h
diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
index e955da397e0e..d521759fe40d 100644
--- a/arch/x86/include/asm/cpufeature.h
+++ b/arch/x86/include/asm/cpufeature.h
@@ -9,6 +9,7 @@
#include <asm/asm.h>
#include <linux/bitops.h>
#include <asm/alternative.h>
+#include <asm/featuremasks.h>
enum cpuid_leafs
{
diff --git a/arch/x86/include/asm/cpufeatures.h b/arch/x86/include/asm/cpufeatures.h
index 0bc420319ee2..966685fe6d52 100644
--- a/arch/x86/include/asm/cpufeatures.h
+++ b/arch/x86/include/asm/cpufeatures.h
@@ -2,14 +2,6 @@
#ifndef _ASM_X86_CPUFEATURES_H
#define _ASM_X86_CPUFEATURES_H
-#ifndef _ASM_X86_REQUIRED_FEATURES_H
-#include <asm/required-features.h>
-#endif
-
-#ifndef _ASM_X86_DISABLED_FEATURES_H
-#include <asm/disabled-features.h>
-#endif
-
/*
* Defines x86 CPU feature bits
*/
diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
index 1258a5872d12..a23a65d5d177 100644
--- a/arch/x86/kernel/verify_cpu.S
+++ b/arch/x86/kernel/verify_cpu.S
@@ -29,8 +29,12 @@
*/
#include <asm/cpufeatures.h>
+#include <asm/featuremasks.h>
#include <asm/msr-index.h>
+#define SSE_MASK \
+ (REQUIRED_MASK0 & ((1<<(X86_FEATURE_XMM & 31)) | (1<<(X86_FEATURE_XMM2 & 31))))
+
SYM_FUNC_START_LOCAL(verify_cpu)
pushf # Save caller passed flags
push $0 # Kill any dangerous flags
diff --git a/arch/x86/tools/featuremasks.awk b/arch/x86/tools/featuremasks.awk
new file mode 100755
index 000000000000..fd3e72147157
--- /dev/null
+++ b/arch/x86/tools/featuremasks.awk
@@ -0,0 +1,81 @@
+#!/usr/bin/awk
+#
+# Convert cpufeatures.h to a list of compile-time masks
+# Note: this blithly assumes that each word has at least one
+# feature defined in it; if not, something else is wrong!
+#
+
+BEGIN {
+ printf "#ifndef _ASM_X86_FEATUREMASKS_H\n";
+ printf "#define _ASM_X86_FEATUREMASKS_H\n\n";
+
+ file = 0
+}
+
+FNR == 1 {
+ ++file;
+
+ # arch/x86/include/asm/cpufeatures.h
+ if (file == 1)
+ FS = "[ \t()*+]+";
+
+ # .config
+ if (file == 2)
+ FS = "=";
+}
+
+# Create a dictionary of sorts, containing all defined feature bits
+file == 1 && $1 ~ /^#define$/ && $2 ~ /^X86_FEATURE_/ {
+ nfeat = $3 * $4 + $5;
+ feat = $2;
+ sub(/^X86_FEATURE_/, "", feat);
+ feats[nfeat] = feat;
+}
+file == 1 && $1 ~ /^#define$/ && $2 == "NCAPINTS" {
+ ncapints = int($3);
+}
+
+# Create a dictionary featstat[REQUIRED|DISABLED, FEATURE_NAME] = on | off
+file == 2 && $1 ~ /^CONFIG_X86_(REQUIRED|DISABLED)_FEATURE_/ {
+ on = ($2 == "y");
+ if (split($1, fs, "CONFIG_X86_|_FEATURE_") == 3)
+ featstat[fs[2], fs[3]] = on;
+}
+
+END {
+ sets[1] = "REQUIRED";
+ sets[2] = "DISABLED";
+
+ for (ns in sets) {
+ s = sets[ns];
+
+ printf "/*\n";
+ printf " * %s features:\n", s;
+ printf " *\n";
+ fstr = "";
+ for (i = 0; i < ncapints; i++) {
+ mask = 0;
+ for (j = 0; j < 32; j++) {
+ feat = feats[i*32 + j];
+ if (featstat[s, feat]) {
+ nfstr = fstr " " feat;
+ if (length(nfstr) > 72) {
+ printf " * %s\n", fstr;
+ nfstr = " " feat;
+ }
+ fstr = nfstr;
+ mask += (2 ^ j);
+ }
+ }
+ masks[i] = mask;
+ }
+ printf " * %s\n */\n", fstr;
+
+ for (i = 0; i < ncapints; i++)
+ printf "#define %s_MASK%d\t0x%08xU\n", s, i, masks[i];
+
+ printf "#define %s_MASK_CHECK BUILD_BUG_ON_ZERO(NCAPINTS != %d)\n\n", s, ncapints;
+ }
+
+ printf "#endif /* _ASM_X86_FEATUREMASKS_H */\n";
+}
--
2.48.1
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH v7 3/4] x86/cpufeatures: Remove {disabled,required}-features.h
2025-03-05 18:47 [PATCH v7 0/4] x86/cpufeatures: Automatically generate required and disabled feature masks Xin Li (Intel)
2025-03-05 18:47 ` [PATCH v7 1/4] x86/cpufeatures: Add {required,disabled} feature configs Xin Li (Intel)
2025-03-05 18:47 ` [PATCH v7 2/4] x86/cpufeatures: Generate a feature mask header based on build config Xin Li (Intel)
@ 2025-03-05 18:47 ` Xin Li (Intel)
2025-03-10 8:18 ` [tip: x86/cpu] " tip-bot2 for Xin Li (Intel)
2025-03-19 11:03 ` [tip: x86/core] " tip-bot2 for Xin Li (Intel)
2025-03-05 18:47 ` [PATCH v7 4/4] x86/cpufeatures: Use AWK to generate {REQUIRED|DISABLED}_MASK_BIT_SET Xin Li (Intel)
2025-03-07 18:28 ` [PATCH v7 0/4] x86/cpufeatures: Automatically generate required and disabled feature masks Xin Li
4 siblings, 2 replies; 20+ messages in thread
From: Xin Li (Intel) @ 2025-03-05 18:47 UTC (permalink / raw)
To: linux-kernel, linux-perf-users
Cc: tglx, mingo, bp, dave.hansen, x86, hpa, will, peterz, yury.norov,
akpm, acme, namhyung, brgerst, andrew.cooper3, nik.borisov,
sraithal, philip.li
The functionalities of {disabled,required}-features.h are replaced
with the auto-generated header cpufeature_masks.h. Thus they are no
longer needed. So delete them.
None of the macros defined in {disabled,required}-features.h is used
in tools, delete them too.
Signed-off-by: Xin Li (Intel) <xin@zytor.com>
Reviewed-by: Ingo Molnar <mingo@kernel.org>
---
Change in v7:
* Collect reviewed-bys.
---
arch/x86/include/asm/disabled-features.h | 161 ------------------
arch/x86/include/asm/required-features.h | 105 ------------
tools/arch/x86/include/asm/cpufeatures.h | 8 -
.../arch/x86/include/asm/disabled-features.h | 161 ------------------
.../arch/x86/include/asm/required-features.h | 105 ------------
| 2 -
6 files changed, 542 deletions(-)
delete mode 100644 arch/x86/include/asm/disabled-features.h
delete mode 100644 arch/x86/include/asm/required-features.h
delete mode 100644 tools/arch/x86/include/asm/disabled-features.h
delete mode 100644 tools/arch/x86/include/asm/required-features.h
diff --git a/arch/x86/include/asm/disabled-features.h b/arch/x86/include/asm/disabled-features.h
deleted file mode 100644
index c492bdc97b05..000000000000
--- a/arch/x86/include/asm/disabled-features.h
+++ /dev/null
@@ -1,161 +0,0 @@
-#ifndef _ASM_X86_DISABLED_FEATURES_H
-#define _ASM_X86_DISABLED_FEATURES_H
-
-/* These features, although they might be available in a CPU
- * will not be used because the compile options to support
- * them are not present.
- *
- * This code allows them to be checked and disabled at
- * compile time without an explicit #ifdef. Use
- * cpu_feature_enabled().
- */
-
-#ifdef CONFIG_X86_UMIP
-# define DISABLE_UMIP 0
-#else
-# define DISABLE_UMIP (1<<(X86_FEATURE_UMIP & 31))
-#endif
-
-#ifdef CONFIG_X86_64
-# define DISABLE_VME (1<<(X86_FEATURE_VME & 31))
-# define DISABLE_K6_MTRR (1<<(X86_FEATURE_K6_MTRR & 31))
-# define DISABLE_CYRIX_ARR (1<<(X86_FEATURE_CYRIX_ARR & 31))
-# define DISABLE_CENTAUR_MCR (1<<(X86_FEATURE_CENTAUR_MCR & 31))
-# define DISABLE_PCID 0
-#else
-# define DISABLE_VME 0
-# define DISABLE_K6_MTRR 0
-# define DISABLE_CYRIX_ARR 0
-# define DISABLE_CENTAUR_MCR 0
-# define DISABLE_PCID (1<<(X86_FEATURE_PCID & 31))
-#endif /* CONFIG_X86_64 */
-
-#ifdef CONFIG_X86_INTEL_MEMORY_PROTECTION_KEYS
-# define DISABLE_PKU 0
-# define DISABLE_OSPKE 0
-#else
-# define DISABLE_PKU (1<<(X86_FEATURE_PKU & 31))
-# define DISABLE_OSPKE (1<<(X86_FEATURE_OSPKE & 31))
-#endif /* CONFIG_X86_INTEL_MEMORY_PROTECTION_KEYS */
-
-#ifdef CONFIG_X86_5LEVEL
-# define DISABLE_LA57 0
-#else
-# define DISABLE_LA57 (1<<(X86_FEATURE_LA57 & 31))
-#endif
-
-#ifdef CONFIG_MITIGATION_PAGE_TABLE_ISOLATION
-# define DISABLE_PTI 0
-#else
-# define DISABLE_PTI (1 << (X86_FEATURE_PTI & 31))
-#endif
-
-#ifdef CONFIG_MITIGATION_RETPOLINE
-# define DISABLE_RETPOLINE 0
-#else
-# define DISABLE_RETPOLINE ((1 << (X86_FEATURE_RETPOLINE & 31)) | \
- (1 << (X86_FEATURE_RETPOLINE_LFENCE & 31)))
-#endif
-
-#ifdef CONFIG_MITIGATION_RETHUNK
-# define DISABLE_RETHUNK 0
-#else
-# define DISABLE_RETHUNK (1 << (X86_FEATURE_RETHUNK & 31))
-#endif
-
-#ifdef CONFIG_MITIGATION_UNRET_ENTRY
-# define DISABLE_UNRET 0
-#else
-# define DISABLE_UNRET (1 << (X86_FEATURE_UNRET & 31))
-#endif
-
-#ifdef CONFIG_MITIGATION_CALL_DEPTH_TRACKING
-# define DISABLE_CALL_DEPTH_TRACKING 0
-#else
-# define DISABLE_CALL_DEPTH_TRACKING (1 << (X86_FEATURE_CALL_DEPTH & 31))
-#endif
-
-#ifdef CONFIG_ADDRESS_MASKING
-# define DISABLE_LAM 0
-#else
-# define DISABLE_LAM (1 << (X86_FEATURE_LAM & 31))
-#endif
-
-#ifdef CONFIG_INTEL_IOMMU_SVM
-# define DISABLE_ENQCMD 0
-#else
-# define DISABLE_ENQCMD (1 << (X86_FEATURE_ENQCMD & 31))
-#endif
-
-#ifdef CONFIG_X86_SGX
-# define DISABLE_SGX 0
-#else
-# define DISABLE_SGX (1 << (X86_FEATURE_SGX & 31))
-#endif
-
-#ifdef CONFIG_XEN_PV
-# define DISABLE_XENPV 0
-#else
-# define DISABLE_XENPV (1 << (X86_FEATURE_XENPV & 31))
-#endif
-
-#ifdef CONFIG_INTEL_TDX_GUEST
-# define DISABLE_TDX_GUEST 0
-#else
-# define DISABLE_TDX_GUEST (1 << (X86_FEATURE_TDX_GUEST & 31))
-#endif
-
-#ifdef CONFIG_X86_USER_SHADOW_STACK
-#define DISABLE_USER_SHSTK 0
-#else
-#define DISABLE_USER_SHSTK (1 << (X86_FEATURE_USER_SHSTK & 31))
-#endif
-
-#ifdef CONFIG_X86_KERNEL_IBT
-#define DISABLE_IBT 0
-#else
-#define DISABLE_IBT (1 << (X86_FEATURE_IBT & 31))
-#endif
-
-#ifdef CONFIG_X86_FRED
-# define DISABLE_FRED 0
-#else
-# define DISABLE_FRED (1 << (X86_FEATURE_FRED & 31))
-#endif
-
-#ifdef CONFIG_KVM_AMD_SEV
-#define DISABLE_SEV_SNP 0
-#else
-#define DISABLE_SEV_SNP (1 << (X86_FEATURE_SEV_SNP & 31))
-#endif
-
-/*
- * Make sure to add features to the correct mask
- */
-#define DISABLED_MASK0 (DISABLE_VME)
-#define DISABLED_MASK1 0
-#define DISABLED_MASK2 0
-#define DISABLED_MASK3 (DISABLE_CYRIX_ARR|DISABLE_CENTAUR_MCR|DISABLE_K6_MTRR)
-#define DISABLED_MASK4 (DISABLE_PCID)
-#define DISABLED_MASK5 0
-#define DISABLED_MASK6 0
-#define DISABLED_MASK7 (DISABLE_PTI)
-#define DISABLED_MASK8 (DISABLE_XENPV|DISABLE_TDX_GUEST)
-#define DISABLED_MASK9 (DISABLE_SGX)
-#define DISABLED_MASK10 0
-#define DISABLED_MASK11 (DISABLE_RETPOLINE|DISABLE_RETHUNK|DISABLE_UNRET| \
- DISABLE_CALL_DEPTH_TRACKING|DISABLE_USER_SHSTK)
-#define DISABLED_MASK12 (DISABLE_FRED|DISABLE_LAM)
-#define DISABLED_MASK13 0
-#define DISABLED_MASK14 0
-#define DISABLED_MASK15 0
-#define DISABLED_MASK16 (DISABLE_PKU|DISABLE_OSPKE|DISABLE_LA57|DISABLE_UMIP| \
- DISABLE_ENQCMD)
-#define DISABLED_MASK17 0
-#define DISABLED_MASK18 (DISABLE_IBT)
-#define DISABLED_MASK19 (DISABLE_SEV_SNP)
-#define DISABLED_MASK20 0
-#define DISABLED_MASK21 0
-#define DISABLED_MASK_CHECK BUILD_BUG_ON_ZERO(NCAPINTS != 22)
-
-#endif /* _ASM_X86_DISABLED_FEATURES_H */
diff --git a/arch/x86/include/asm/required-features.h b/arch/x86/include/asm/required-features.h
deleted file mode 100644
index 0068133cb622..000000000000
--- a/arch/x86/include/asm/required-features.h
+++ /dev/null
@@ -1,105 +0,0 @@
-#ifndef _ASM_X86_REQUIRED_FEATURES_H
-#define _ASM_X86_REQUIRED_FEATURES_H
-
-/* Define minimum CPUID feature set for kernel These bits are checked
- really early to actually display a visible error message before the
- kernel dies. Make sure to assign features to the proper mask!
-
- Some requirements that are not in CPUID yet are also in the
- CONFIG_X86_MINIMUM_CPU_FAMILY which is checked too.
-
- The real information is in arch/x86/Kconfig.cpu, this just converts
- the CONFIGs into a bitmask */
-
-#ifndef CONFIG_MATH_EMULATION
-# define NEED_FPU (1<<(X86_FEATURE_FPU & 31))
-#else
-# define NEED_FPU 0
-#endif
-
-#if defined(CONFIG_X86_PAE) || defined(CONFIG_X86_64)
-# define NEED_PAE (1<<(X86_FEATURE_PAE & 31))
-#else
-# define NEED_PAE 0
-#endif
-
-#ifdef CONFIG_X86_CX8
-# define NEED_CX8 (1<<(X86_FEATURE_CX8 & 31))
-#else
-# define NEED_CX8 0
-#endif
-
-#if defined(CONFIG_X86_CMOV) || defined(CONFIG_X86_64)
-# define NEED_CMOV (1<<(X86_FEATURE_CMOV & 31))
-#else
-# define NEED_CMOV 0
-#endif
-
-# define NEED_3DNOW 0
-
-#if defined(CONFIG_X86_P6_NOP) || defined(CONFIG_X86_64)
-# define NEED_NOPL (1<<(X86_FEATURE_NOPL & 31))
-#else
-# define NEED_NOPL 0
-#endif
-
-#ifdef CONFIG_MATOM
-# define NEED_MOVBE (1<<(X86_FEATURE_MOVBE & 31))
-#else
-# define NEED_MOVBE 0
-#endif
-
-#ifdef CONFIG_X86_64
-#ifdef CONFIG_PARAVIRT_XXL
-/* Paravirtualized systems may not have PSE or PGE available */
-#define NEED_PSE 0
-#define NEED_PGE 0
-#else
-#define NEED_PSE (1<<(X86_FEATURE_PSE) & 31)
-#define NEED_PGE (1<<(X86_FEATURE_PGE) & 31)
-#endif
-#define NEED_MSR (1<<(X86_FEATURE_MSR & 31))
-#define NEED_FXSR (1<<(X86_FEATURE_FXSR & 31))
-#define NEED_XMM (1<<(X86_FEATURE_XMM & 31))
-#define NEED_XMM2 (1<<(X86_FEATURE_XMM2 & 31))
-#define NEED_LM (1<<(X86_FEATURE_LM & 31))
-#else
-#define NEED_PSE 0
-#define NEED_MSR 0
-#define NEED_PGE 0
-#define NEED_FXSR 0
-#define NEED_XMM 0
-#define NEED_XMM2 0
-#define NEED_LM 0
-#endif
-
-#define REQUIRED_MASK0 (NEED_FPU|NEED_PSE|NEED_MSR|NEED_PAE|\
- NEED_CX8|NEED_PGE|NEED_FXSR|NEED_CMOV|\
- NEED_XMM|NEED_XMM2)
-#define SSE_MASK (NEED_XMM|NEED_XMM2)
-
-#define REQUIRED_MASK1 (NEED_LM|NEED_3DNOW)
-
-#define REQUIRED_MASK2 0
-#define REQUIRED_MASK3 (NEED_NOPL)
-#define REQUIRED_MASK4 (NEED_MOVBE)
-#define REQUIRED_MASK5 0
-#define REQUIRED_MASK6 0
-#define REQUIRED_MASK7 0
-#define REQUIRED_MASK8 0
-#define REQUIRED_MASK9 0
-#define REQUIRED_MASK10 0
-#define REQUIRED_MASK11 0
-#define REQUIRED_MASK12 0
-#define REQUIRED_MASK13 0
-#define REQUIRED_MASK14 0
-#define REQUIRED_MASK15 0
-#define REQUIRED_MASK16 0
-#define REQUIRED_MASK17 0
-#define REQUIRED_MASK18 0
-#define REQUIRED_MASK19 0
-#define REQUIRED_MASK20 0
-#define REQUIRED_MASK21 0
-#define REQUIRED_MASK_CHECK BUILD_BUG_ON_ZERO(NCAPINTS != 22)
-
-#endif /* _ASM_X86_REQUIRED_FEATURES_H */
diff --git a/tools/arch/x86/include/asm/cpufeatures.h b/tools/arch/x86/include/asm/cpufeatures.h
index ec9911379c61..9e3fa7942e7d 100644
--- a/tools/arch/x86/include/asm/cpufeatures.h
+++ b/tools/arch/x86/include/asm/cpufeatures.h
@@ -2,14 +2,6 @@
#ifndef _ASM_X86_CPUFEATURES_H
#define _ASM_X86_CPUFEATURES_H
-#ifndef _ASM_X86_REQUIRED_FEATURES_H
-#include <asm/required-features.h>
-#endif
-
-#ifndef _ASM_X86_DISABLED_FEATURES_H
-#include <asm/disabled-features.h>
-#endif
-
/*
* Defines x86 CPU feature bits
*/
diff --git a/tools/arch/x86/include/asm/disabled-features.h b/tools/arch/x86/include/asm/disabled-features.h
deleted file mode 100644
index c492bdc97b05..000000000000
--- a/tools/arch/x86/include/asm/disabled-features.h
+++ /dev/null
@@ -1,161 +0,0 @@
-#ifndef _ASM_X86_DISABLED_FEATURES_H
-#define _ASM_X86_DISABLED_FEATURES_H
-
-/* These features, although they might be available in a CPU
- * will not be used because the compile options to support
- * them are not present.
- *
- * This code allows them to be checked and disabled at
- * compile time without an explicit #ifdef. Use
- * cpu_feature_enabled().
- */
-
-#ifdef CONFIG_X86_UMIP
-# define DISABLE_UMIP 0
-#else
-# define DISABLE_UMIP (1<<(X86_FEATURE_UMIP & 31))
-#endif
-
-#ifdef CONFIG_X86_64
-# define DISABLE_VME (1<<(X86_FEATURE_VME & 31))
-# define DISABLE_K6_MTRR (1<<(X86_FEATURE_K6_MTRR & 31))
-# define DISABLE_CYRIX_ARR (1<<(X86_FEATURE_CYRIX_ARR & 31))
-# define DISABLE_CENTAUR_MCR (1<<(X86_FEATURE_CENTAUR_MCR & 31))
-# define DISABLE_PCID 0
-#else
-# define DISABLE_VME 0
-# define DISABLE_K6_MTRR 0
-# define DISABLE_CYRIX_ARR 0
-# define DISABLE_CENTAUR_MCR 0
-# define DISABLE_PCID (1<<(X86_FEATURE_PCID & 31))
-#endif /* CONFIG_X86_64 */
-
-#ifdef CONFIG_X86_INTEL_MEMORY_PROTECTION_KEYS
-# define DISABLE_PKU 0
-# define DISABLE_OSPKE 0
-#else
-# define DISABLE_PKU (1<<(X86_FEATURE_PKU & 31))
-# define DISABLE_OSPKE (1<<(X86_FEATURE_OSPKE & 31))
-#endif /* CONFIG_X86_INTEL_MEMORY_PROTECTION_KEYS */
-
-#ifdef CONFIG_X86_5LEVEL
-# define DISABLE_LA57 0
-#else
-# define DISABLE_LA57 (1<<(X86_FEATURE_LA57 & 31))
-#endif
-
-#ifdef CONFIG_MITIGATION_PAGE_TABLE_ISOLATION
-# define DISABLE_PTI 0
-#else
-# define DISABLE_PTI (1 << (X86_FEATURE_PTI & 31))
-#endif
-
-#ifdef CONFIG_MITIGATION_RETPOLINE
-# define DISABLE_RETPOLINE 0
-#else
-# define DISABLE_RETPOLINE ((1 << (X86_FEATURE_RETPOLINE & 31)) | \
- (1 << (X86_FEATURE_RETPOLINE_LFENCE & 31)))
-#endif
-
-#ifdef CONFIG_MITIGATION_RETHUNK
-# define DISABLE_RETHUNK 0
-#else
-# define DISABLE_RETHUNK (1 << (X86_FEATURE_RETHUNK & 31))
-#endif
-
-#ifdef CONFIG_MITIGATION_UNRET_ENTRY
-# define DISABLE_UNRET 0
-#else
-# define DISABLE_UNRET (1 << (X86_FEATURE_UNRET & 31))
-#endif
-
-#ifdef CONFIG_MITIGATION_CALL_DEPTH_TRACKING
-# define DISABLE_CALL_DEPTH_TRACKING 0
-#else
-# define DISABLE_CALL_DEPTH_TRACKING (1 << (X86_FEATURE_CALL_DEPTH & 31))
-#endif
-
-#ifdef CONFIG_ADDRESS_MASKING
-# define DISABLE_LAM 0
-#else
-# define DISABLE_LAM (1 << (X86_FEATURE_LAM & 31))
-#endif
-
-#ifdef CONFIG_INTEL_IOMMU_SVM
-# define DISABLE_ENQCMD 0
-#else
-# define DISABLE_ENQCMD (1 << (X86_FEATURE_ENQCMD & 31))
-#endif
-
-#ifdef CONFIG_X86_SGX
-# define DISABLE_SGX 0
-#else
-# define DISABLE_SGX (1 << (X86_FEATURE_SGX & 31))
-#endif
-
-#ifdef CONFIG_XEN_PV
-# define DISABLE_XENPV 0
-#else
-# define DISABLE_XENPV (1 << (X86_FEATURE_XENPV & 31))
-#endif
-
-#ifdef CONFIG_INTEL_TDX_GUEST
-# define DISABLE_TDX_GUEST 0
-#else
-# define DISABLE_TDX_GUEST (1 << (X86_FEATURE_TDX_GUEST & 31))
-#endif
-
-#ifdef CONFIG_X86_USER_SHADOW_STACK
-#define DISABLE_USER_SHSTK 0
-#else
-#define DISABLE_USER_SHSTK (1 << (X86_FEATURE_USER_SHSTK & 31))
-#endif
-
-#ifdef CONFIG_X86_KERNEL_IBT
-#define DISABLE_IBT 0
-#else
-#define DISABLE_IBT (1 << (X86_FEATURE_IBT & 31))
-#endif
-
-#ifdef CONFIG_X86_FRED
-# define DISABLE_FRED 0
-#else
-# define DISABLE_FRED (1 << (X86_FEATURE_FRED & 31))
-#endif
-
-#ifdef CONFIG_KVM_AMD_SEV
-#define DISABLE_SEV_SNP 0
-#else
-#define DISABLE_SEV_SNP (1 << (X86_FEATURE_SEV_SNP & 31))
-#endif
-
-/*
- * Make sure to add features to the correct mask
- */
-#define DISABLED_MASK0 (DISABLE_VME)
-#define DISABLED_MASK1 0
-#define DISABLED_MASK2 0
-#define DISABLED_MASK3 (DISABLE_CYRIX_ARR|DISABLE_CENTAUR_MCR|DISABLE_K6_MTRR)
-#define DISABLED_MASK4 (DISABLE_PCID)
-#define DISABLED_MASK5 0
-#define DISABLED_MASK6 0
-#define DISABLED_MASK7 (DISABLE_PTI)
-#define DISABLED_MASK8 (DISABLE_XENPV|DISABLE_TDX_GUEST)
-#define DISABLED_MASK9 (DISABLE_SGX)
-#define DISABLED_MASK10 0
-#define DISABLED_MASK11 (DISABLE_RETPOLINE|DISABLE_RETHUNK|DISABLE_UNRET| \
- DISABLE_CALL_DEPTH_TRACKING|DISABLE_USER_SHSTK)
-#define DISABLED_MASK12 (DISABLE_FRED|DISABLE_LAM)
-#define DISABLED_MASK13 0
-#define DISABLED_MASK14 0
-#define DISABLED_MASK15 0
-#define DISABLED_MASK16 (DISABLE_PKU|DISABLE_OSPKE|DISABLE_LA57|DISABLE_UMIP| \
- DISABLE_ENQCMD)
-#define DISABLED_MASK17 0
-#define DISABLED_MASK18 (DISABLE_IBT)
-#define DISABLED_MASK19 (DISABLE_SEV_SNP)
-#define DISABLED_MASK20 0
-#define DISABLED_MASK21 0
-#define DISABLED_MASK_CHECK BUILD_BUG_ON_ZERO(NCAPINTS != 22)
-
-#endif /* _ASM_X86_DISABLED_FEATURES_H */
diff --git a/tools/arch/x86/include/asm/required-features.h b/tools/arch/x86/include/asm/required-features.h
deleted file mode 100644
index 0068133cb622..000000000000
--- a/tools/arch/x86/include/asm/required-features.h
+++ /dev/null
@@ -1,105 +0,0 @@
-#ifndef _ASM_X86_REQUIRED_FEATURES_H
-#define _ASM_X86_REQUIRED_FEATURES_H
-
-/* Define minimum CPUID feature set for kernel These bits are checked
- really early to actually display a visible error message before the
- kernel dies. Make sure to assign features to the proper mask!
-
- Some requirements that are not in CPUID yet are also in the
- CONFIG_X86_MINIMUM_CPU_FAMILY which is checked too.
-
- The real information is in arch/x86/Kconfig.cpu, this just converts
- the CONFIGs into a bitmask */
-
-#ifndef CONFIG_MATH_EMULATION
-# define NEED_FPU (1<<(X86_FEATURE_FPU & 31))
-#else
-# define NEED_FPU 0
-#endif
-
-#if defined(CONFIG_X86_PAE) || defined(CONFIG_X86_64)
-# define NEED_PAE (1<<(X86_FEATURE_PAE & 31))
-#else
-# define NEED_PAE 0
-#endif
-
-#ifdef CONFIG_X86_CX8
-# define NEED_CX8 (1<<(X86_FEATURE_CX8 & 31))
-#else
-# define NEED_CX8 0
-#endif
-
-#if defined(CONFIG_X86_CMOV) || defined(CONFIG_X86_64)
-# define NEED_CMOV (1<<(X86_FEATURE_CMOV & 31))
-#else
-# define NEED_CMOV 0
-#endif
-
-# define NEED_3DNOW 0
-
-#if defined(CONFIG_X86_P6_NOP) || defined(CONFIG_X86_64)
-# define NEED_NOPL (1<<(X86_FEATURE_NOPL & 31))
-#else
-# define NEED_NOPL 0
-#endif
-
-#ifdef CONFIG_MATOM
-# define NEED_MOVBE (1<<(X86_FEATURE_MOVBE & 31))
-#else
-# define NEED_MOVBE 0
-#endif
-
-#ifdef CONFIG_X86_64
-#ifdef CONFIG_PARAVIRT_XXL
-/* Paravirtualized systems may not have PSE or PGE available */
-#define NEED_PSE 0
-#define NEED_PGE 0
-#else
-#define NEED_PSE (1<<(X86_FEATURE_PSE) & 31)
-#define NEED_PGE (1<<(X86_FEATURE_PGE) & 31)
-#endif
-#define NEED_MSR (1<<(X86_FEATURE_MSR & 31))
-#define NEED_FXSR (1<<(X86_FEATURE_FXSR & 31))
-#define NEED_XMM (1<<(X86_FEATURE_XMM & 31))
-#define NEED_XMM2 (1<<(X86_FEATURE_XMM2 & 31))
-#define NEED_LM (1<<(X86_FEATURE_LM & 31))
-#else
-#define NEED_PSE 0
-#define NEED_MSR 0
-#define NEED_PGE 0
-#define NEED_FXSR 0
-#define NEED_XMM 0
-#define NEED_XMM2 0
-#define NEED_LM 0
-#endif
-
-#define REQUIRED_MASK0 (NEED_FPU|NEED_PSE|NEED_MSR|NEED_PAE|\
- NEED_CX8|NEED_PGE|NEED_FXSR|NEED_CMOV|\
- NEED_XMM|NEED_XMM2)
-#define SSE_MASK (NEED_XMM|NEED_XMM2)
-
-#define REQUIRED_MASK1 (NEED_LM|NEED_3DNOW)
-
-#define REQUIRED_MASK2 0
-#define REQUIRED_MASK3 (NEED_NOPL)
-#define REQUIRED_MASK4 (NEED_MOVBE)
-#define REQUIRED_MASK5 0
-#define REQUIRED_MASK6 0
-#define REQUIRED_MASK7 0
-#define REQUIRED_MASK8 0
-#define REQUIRED_MASK9 0
-#define REQUIRED_MASK10 0
-#define REQUIRED_MASK11 0
-#define REQUIRED_MASK12 0
-#define REQUIRED_MASK13 0
-#define REQUIRED_MASK14 0
-#define REQUIRED_MASK15 0
-#define REQUIRED_MASK16 0
-#define REQUIRED_MASK17 0
-#define REQUIRED_MASK18 0
-#define REQUIRED_MASK19 0
-#define REQUIRED_MASK20 0
-#define REQUIRED_MASK21 0
-#define REQUIRED_MASK_CHECK BUILD_BUG_ON_ZERO(NCAPINTS != 22)
-
-#endif /* _ASM_X86_REQUIRED_FEATURES_H */
--git a/tools/perf/check-headers.sh b/tools/perf/check-headers.sh
index d3c6e10dce73..a4499e5a6f9c 100755
--- a/tools/perf/check-headers.sh
+++ b/tools/perf/check-headers.sh
@@ -26,8 +26,6 @@ FILES=(
"include/linux/hash.h"
"include/linux/list-sort.h"
"include/uapi/linux/hw_breakpoint.h"
- "arch/x86/include/asm/disabled-features.h"
- "arch/x86/include/asm/required-features.h"
"arch/x86/include/asm/cpufeatures.h"
"arch/x86/include/asm/inat_types.h"
"arch/x86/include/asm/emulate_prefix.h"
--
2.48.1
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH v7 4/4] x86/cpufeatures: Use AWK to generate {REQUIRED|DISABLED}_MASK_BIT_SET
2025-03-05 18:47 [PATCH v7 0/4] x86/cpufeatures: Automatically generate required and disabled feature masks Xin Li (Intel)
` (2 preceding siblings ...)
2025-03-05 18:47 ` [PATCH v7 3/4] x86/cpufeatures: Remove {disabled,required}-features.h Xin Li (Intel)
@ 2025-03-05 18:47 ` Xin Li (Intel)
2025-03-07 18:28 ` [PATCH v7 0/4] x86/cpufeatures: Automatically generate required and disabled feature masks Xin Li
4 siblings, 0 replies; 20+ messages in thread
From: Xin Li (Intel) @ 2025-03-05 18:47 UTC (permalink / raw)
To: linux-kernel, linux-perf-users
Cc: tglx, mingo, bp, dave.hansen, x86, hpa, will, peterz, yury.norov,
akpm, acme, namhyung, brgerst, andrew.cooper3, nik.borisov,
sraithal, philip.li
Generate macros {REQUIRED|DISABLED}_MASK_BIT_SET in the newly added AWK
script that generates the required and disabled feature mask header.
Suggested-by: Brian Gerst <brgerst@gmail.com>
Signed-off-by: Xin Li (Intel) <xin@zytor.com>
Reviewed-by: Brian Gerst <brgerst@gmail.com>
Reviewed-by: Nikolay Borisov <nik.borisov@suse.com>
Reviewed-by: Ingo Molnar <mingo@kernel.org>
---
Change in v7:
* Collect reviewed-bys.
Changes in v4:
* Use '1U' instead of '1' in feature mask shifting (Andrew Cooper).
* Checking NCAPINTS isn't necessary anymore. It was needed when these
macros had to be manually updated, but now if cpufeatures.h changes
this header will be regenerated (Brian Gerst).
---
arch/x86/include/asm/cpufeature.h | 69 -------------------------------
arch/x86/tools/featuremasks.awk | 9 +++-
2 files changed, 8 insertions(+), 70 deletions(-)
diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
index d521759fe40d..7937823ded89 100644
--- a/arch/x86/include/asm/cpufeature.h
+++ b/arch/x86/include/asm/cpufeature.h
@@ -51,75 +51,6 @@ extern const char * const x86_bug_flags[NBUGINTS*32];
#define test_cpu_cap(c, bit) \
arch_test_bit(bit, (unsigned long *)((c)->x86_capability))
-/*
- * There are 32 bits/features in each mask word. The high bits
- * (selected with (bit>>5) give us the word number and the low 5
- * bits give us the bit/feature number inside the word.
- * (1UL<<((bit)&31) gives us a mask for the feature_bit so we can
- * see if it is set in the mask word.
- */
-#define CHECK_BIT_IN_MASK_WORD(maskname, word, bit) \
- (((bit)>>5)==(word) && (1UL<<((bit)&31) & maskname##word ))
-
-/*
- * {REQUIRED,DISABLED}_MASK_CHECK below may seem duplicated with the
- * following BUILD_BUG_ON_ZERO() check but when NCAPINTS gets changed, all
- * header macros which use NCAPINTS need to be changed. The duplicated macro
- * use causes the compiler to issue errors for all headers so that all usage
- * sites can be corrected.
- */
-#define REQUIRED_MASK_BIT_SET(feature_bit) \
- ( CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 0, feature_bit) || \
- CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 1, feature_bit) || \
- CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 2, feature_bit) || \
- CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 3, feature_bit) || \
- CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 4, feature_bit) || \
- CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 5, feature_bit) || \
- CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 6, feature_bit) || \
- CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 7, feature_bit) || \
- CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 8, feature_bit) || \
- CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 9, feature_bit) || \
- CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 10, feature_bit) || \
- CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 11, feature_bit) || \
- CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 12, feature_bit) || \
- CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 13, feature_bit) || \
- CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 14, feature_bit) || \
- CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 15, feature_bit) || \
- CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 16, feature_bit) || \
- CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 17, feature_bit) || \
- CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 18, feature_bit) || \
- CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 19, feature_bit) || \
- CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 20, feature_bit) || \
- CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 21, feature_bit) || \
- REQUIRED_MASK_CHECK || \
- BUILD_BUG_ON_ZERO(NCAPINTS != 22))
-
-#define DISABLED_MASK_BIT_SET(feature_bit) \
- ( CHECK_BIT_IN_MASK_WORD(DISABLED_MASK, 0, feature_bit) || \
- CHECK_BIT_IN_MASK_WORD(DISABLED_MASK, 1, feature_bit) || \
- CHECK_BIT_IN_MASK_WORD(DISABLED_MASK, 2, feature_bit) || \
- CHECK_BIT_IN_MASK_WORD(DISABLED_MASK, 3, feature_bit) || \
- CHECK_BIT_IN_MASK_WORD(DISABLED_MASK, 4, feature_bit) || \
- CHECK_BIT_IN_MASK_WORD(DISABLED_MASK, 5, feature_bit) || \
- CHECK_BIT_IN_MASK_WORD(DISABLED_MASK, 6, feature_bit) || \
- CHECK_BIT_IN_MASK_WORD(DISABLED_MASK, 7, feature_bit) || \
- CHECK_BIT_IN_MASK_WORD(DISABLED_MASK, 8, feature_bit) || \
- CHECK_BIT_IN_MASK_WORD(DISABLED_MASK, 9, feature_bit) || \
- CHECK_BIT_IN_MASK_WORD(DISABLED_MASK, 10, feature_bit) || \
- CHECK_BIT_IN_MASK_WORD(DISABLED_MASK, 11, feature_bit) || \
- CHECK_BIT_IN_MASK_WORD(DISABLED_MASK, 12, feature_bit) || \
- CHECK_BIT_IN_MASK_WORD(DISABLED_MASK, 13, feature_bit) || \
- CHECK_BIT_IN_MASK_WORD(DISABLED_MASK, 14, feature_bit) || \
- CHECK_BIT_IN_MASK_WORD(DISABLED_MASK, 15, feature_bit) || \
- CHECK_BIT_IN_MASK_WORD(DISABLED_MASK, 16, feature_bit) || \
- CHECK_BIT_IN_MASK_WORD(DISABLED_MASK, 17, feature_bit) || \
- CHECK_BIT_IN_MASK_WORD(DISABLED_MASK, 18, feature_bit) || \
- CHECK_BIT_IN_MASK_WORD(DISABLED_MASK, 19, feature_bit) || \
- CHECK_BIT_IN_MASK_WORD(DISABLED_MASK, 20, feature_bit) || \
- CHECK_BIT_IN_MASK_WORD(DISABLED_MASK, 21, feature_bit) || \
- DISABLED_MASK_CHECK || \
- BUILD_BUG_ON_ZERO(NCAPINTS != 22))
-
#define cpu_has(c, bit) \
(__builtin_constant_p(bit) && REQUIRED_MASK_BIT_SET(bit) ? 1 : \
test_cpu_cap(c, bit))
diff --git a/arch/x86/tools/featuremasks.awk b/arch/x86/tools/featuremasks.awk
index fd3e72147157..2d9201c841cb 100755
--- a/arch/x86/tools/featuremasks.awk
+++ b/arch/x86/tools/featuremasks.awk
@@ -74,7 +74,14 @@ END {
for (i = 0; i < ncapints; i++)
printf "#define %s_MASK%d\t0x%08xU\n", s, i, masks[i];
- printf "#define %s_MASK_CHECK BUILD_BUG_ON_ZERO(NCAPINTS != %d)\n\n", s, ncapints;
+ printf "\n#define %s_MASK_BIT_SET(x)\t\t\t\\\n", s;
+ printf "\t((\t\t\t\t\t";
+ for (i = 0; i < ncapints; i++) {
+ if (masks[i])
+ printf "\t\\\n\t\t((x) >> 5) == %2d ? %s_MASK%d :", i, s, i;
+ }
+ printf " 0\t\\\n";
+ printf "\t) & (1U << ((x) & 31)))\n\n";
}
printf "#endif /* _ASM_X86_FEATUREMASKS_H */\n";
--
2.48.1
^ permalink raw reply related [flat|nested] 20+ messages in thread
* Re: [PATCH v7 0/4] x86/cpufeatures: Automatically generate required and disabled feature masks
2025-03-05 18:47 [PATCH v7 0/4] x86/cpufeatures: Automatically generate required and disabled feature masks Xin Li (Intel)
` (3 preceding siblings ...)
2025-03-05 18:47 ` [PATCH v7 4/4] x86/cpufeatures: Use AWK to generate {REQUIRED|DISABLED}_MASK_BIT_SET Xin Li (Intel)
@ 2025-03-07 18:28 ` Xin Li
2025-03-07 19:18 ` Borislav Petkov
4 siblings, 1 reply; 20+ messages in thread
From: Xin Li @ 2025-03-07 18:28 UTC (permalink / raw)
To: linux-kernel, linux-perf-users
Cc: tglx, mingo, bp, dave.hansen, x86, hpa, will, peterz, yury.norov,
akpm, acme, namhyung, brgerst, andrew.cooper3, nik.borisov,
sraithal, philip.li
On 3/5/2025 10:47 AM, Xin Li (Intel) wrote:
> The x86 build process first generates required and disabled feature
> masks based on current build config, and then uses these generated
> masks to compile the source code. When a CPU feature is not enabled
> in a build config, e.g., when CONFIG_X86_FRED=n, its feature disable
> flag, i.e., DISABLE_FRED, needs to be properly defined and added to
> a specific disabled CPU features mask in <asm/disabled-features.h>,
> as the following patch does:
> https://lore.kernel.org/all/20231205105030.8698-8-xin3.li@intel.com/.
> As a result, the FRED feature bit is surely cleared in the generated
> kernel binary when CONFIG_X86_FRED=n.
>
> Recently there is another case to repeat the same exercise for the
> AMD SEV-SNP CPU feature:
> https://lore.kernel.org/all/20240126041126.1927228-2-michael.roth@amd.com/.
> https://lore.kernel.org/all/20240126041126.1927228-23-michael.roth@amd.com/.
>
> It was one thing when there were four of CPU feature masks, but with
> over 20 it is going to cause mistakes, e.g.,
> https://lore.kernel.org/lkml/aaed79d5-d683-d1bc-7ba1-b33c8d6db618@suse.com/.
>
> We want to eliminate the stupidly repeated exercise to manually assign
> features to CPU feature words through introducing an AWK script to
> automatically generate a header with required and disabled CPU feature
> masks based on current build config, and this patch set does that.
>
> Link to v6:
> https://lore.kernel.org/lkml/20250228082338.73859-1-xin@zytor.com/
>
> Changes in v7:
> * Fix build error with "make distclean; make headers" (Aithal, Srikanth)
> * Collect reviewed-bys.
>
This version v7 can be cleanly applied on tip/x86/cpu but NOT the latest
tip/master.
I guess I don't have to rebase on the latest tip/master and resend it?
Thanks!
Xin
>
> H. Peter Anvin (Intel) (2):
> x86/cpufeatures: Add {required,disabled} feature configs
> x86/cpufeatures: Generate a feature mask header based on build config
>
> Xin Li (Intel) (2):
> x86/cpufeatures: Remove {disabled,required}-features.h
> x86/cpufeatures: Use AWK to generate {REQUIRED|DISABLED}_MASK_BIT_SET
>
> arch/x86/Kconfig | 2 +
> arch/x86/Kconfig.cpufeatures | 197 ++++++++++++++++++
> arch/x86/Makefile | 15 ++
> arch/x86/boot/cpucheck.c | 3 +-
> arch/x86/boot/cpuflags.c | 1 -
> arch/x86/boot/mkcpustr.c | 3 +-
> arch/x86/include/asm/Kbuild | 1 +
> arch/x86/include/asm/cpufeature.h | 70 +------
> arch/x86/include/asm/cpufeatures.h | 8 -
> arch/x86/include/asm/disabled-features.h | 161 --------------
> arch/x86/include/asm/required-features.h | 105 ----------
> arch/x86/kernel/verify_cpu.S | 4 +
> arch/x86/tools/featuremasks.awk | 88 ++++++++
> tools/arch/x86/include/asm/cpufeatures.h | 8 -
> .../arch/x86/include/asm/disabled-features.h | 161 --------------
> .../arch/x86/include/asm/required-features.h | 105 ----------
> tools/perf/check-headers.sh | 2 -
> 17 files changed, 311 insertions(+), 623 deletions(-)
> create mode 100644 arch/x86/Kconfig.cpufeatures
> delete mode 100644 arch/x86/include/asm/disabled-features.h
> delete mode 100644 arch/x86/include/asm/required-features.h
> create mode 100755 arch/x86/tools/featuremasks.awk
> delete mode 100644 tools/arch/x86/include/asm/disabled-features.h
> delete mode 100644 tools/arch/x86/include/asm/required-features.h
>
>
> base-commit: 32dc26a2f55f71907af0874468298c6ab8a8f7f9
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH v7 0/4] x86/cpufeatures: Automatically generate required and disabled feature masks
2025-03-07 18:28 ` [PATCH v7 0/4] x86/cpufeatures: Automatically generate required and disabled feature masks Xin Li
@ 2025-03-07 19:18 ` Borislav Petkov
0 siblings, 0 replies; 20+ messages in thread
From: Borislav Petkov @ 2025-03-07 19:18 UTC (permalink / raw)
To: Xin Li
Cc: linux-kernel, linux-perf-users, tglx, mingo, dave.hansen, x86,
hpa, will, peterz, yury.norov, akpm, acme, namhyung, brgerst,
andrew.cooper3, nik.borisov, sraithal, philip.li
On Fri, Mar 07, 2025 at 10:28:56AM -0800, Xin Li wrote:
> I guess I don't have to rebase on the latest tip/master and resend it?
No, you don't need to do anything for now. The patch tetris pleasure is all
mine. I'll ask you to test once stuff is ready.
Thx.
--
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquette
^ permalink raw reply [flat|nested] 20+ messages in thread
* [tip: x86/cpu] x86/cpufeatures: Remove {disabled,required}-features.h
2025-03-05 18:47 ` [PATCH v7 3/4] x86/cpufeatures: Remove {disabled,required}-features.h Xin Li (Intel)
@ 2025-03-10 8:18 ` tip-bot2 for Xin Li (Intel)
2025-03-19 11:03 ` [tip: x86/core] " tip-bot2 for Xin Li (Intel)
1 sibling, 0 replies; 20+ messages in thread
From: tip-bot2 for Xin Li (Intel) @ 2025-03-10 8:18 UTC (permalink / raw)
To: linux-tip-commits
Cc: Xin Li (Intel), Borislav Petkov (AMD), Ingo Molnar,
Linus Torvalds, x86, linux-kernel
The following commit has been merged into the x86/cpu branch of tip:
Commit-ID: 892a533b724688062d5cd873be044b5fa50e1568
Gitweb: https://git.kernel.org/tip/892a533b724688062d5cd873be044b5fa50e1568
Author: Xin Li (Intel) <xin@zytor.com>
AuthorDate: Mon, 10 Mar 2025 08:32:12 +01:00
Committer: Ingo Molnar <mingo@kernel.org>
CommitterDate: Mon, 10 Mar 2025 09:03:23 +01:00
x86/cpufeatures: Remove {disabled,required}-features.h
The functionalities of {disabled,required}-features.h have been replaced with
the auto-generated generated/<asm/cpufeaturemasks.h> header.
Thus they are no longer needed and can be removed.
None of the macros defined in {disabled,required}-features.h is used in tools,
delete them too.
Signed-off-by: Xin Li (Intel) <xin@zytor.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Link: https://lore.kernel.org/r/20250305184725.3341760-4-xin@zytor.com
---
arch/x86/include/asm/disabled-features.h | 167 +----------------
arch/x86/include/asm/required-features.h | 105 +----------
tools/arch/x86/include/asm/cpufeatures.h | 8 +-
tools/arch/x86/include/asm/disabled-features.h | 161 +---------------
tools/arch/x86/include/asm/required-features.h | 105 +----------
| 2 +-
6 files changed, 548 deletions(-)
delete mode 100644 arch/x86/include/asm/disabled-features.h
delete mode 100644 arch/x86/include/asm/required-features.h
delete mode 100644 tools/arch/x86/include/asm/disabled-features.h
delete mode 100644 tools/arch/x86/include/asm/required-features.h
diff --git a/arch/x86/include/asm/disabled-features.h b/arch/x86/include/asm/disabled-features.h
deleted file mode 100644
index be8c388..0000000
--- a/arch/x86/include/asm/disabled-features.h
+++ /dev/null
@@ -1,167 +0,0 @@
-#ifndef _ASM_X86_DISABLED_FEATURES_H
-#define _ASM_X86_DISABLED_FEATURES_H
-
-/* These features, although they might be available in a CPU
- * will not be used because the compile options to support
- * them are not present.
- *
- * This code allows them to be checked and disabled at
- * compile time without an explicit #ifdef. Use
- * cpu_feature_enabled().
- */
-
-#ifdef CONFIG_X86_UMIP
-# define DISABLE_UMIP 0
-#else
-# define DISABLE_UMIP (1<<(X86_FEATURE_UMIP & 31))
-#endif
-
-#ifdef CONFIG_X86_64
-# define DISABLE_VME (1<<(X86_FEATURE_VME & 31))
-# define DISABLE_K6_MTRR (1<<(X86_FEATURE_K6_MTRR & 31))
-# define DISABLE_CYRIX_ARR (1<<(X86_FEATURE_CYRIX_ARR & 31))
-# define DISABLE_CENTAUR_MCR (1<<(X86_FEATURE_CENTAUR_MCR & 31))
-# define DISABLE_PCID 0
-#else
-# define DISABLE_VME 0
-# define DISABLE_K6_MTRR 0
-# define DISABLE_CYRIX_ARR 0
-# define DISABLE_CENTAUR_MCR 0
-# define DISABLE_PCID (1<<(X86_FEATURE_PCID & 31))
-#endif /* CONFIG_X86_64 */
-
-#ifdef CONFIG_X86_INTEL_MEMORY_PROTECTION_KEYS
-# define DISABLE_PKU 0
-# define DISABLE_OSPKE 0
-#else
-# define DISABLE_PKU (1<<(X86_FEATURE_PKU & 31))
-# define DISABLE_OSPKE (1<<(X86_FEATURE_OSPKE & 31))
-#endif /* CONFIG_X86_INTEL_MEMORY_PROTECTION_KEYS */
-
-#ifdef CONFIG_X86_5LEVEL
-# define DISABLE_LA57 0
-#else
-# define DISABLE_LA57 (1<<(X86_FEATURE_LA57 & 31))
-#endif
-
-#ifdef CONFIG_MITIGATION_PAGE_TABLE_ISOLATION
-# define DISABLE_PTI 0
-#else
-# define DISABLE_PTI (1 << (X86_FEATURE_PTI & 31))
-#endif
-
-#ifdef CONFIG_MITIGATION_RETPOLINE
-# define DISABLE_RETPOLINE 0
-#else
-# define DISABLE_RETPOLINE ((1 << (X86_FEATURE_RETPOLINE & 31)) | \
- (1 << (X86_FEATURE_RETPOLINE_LFENCE & 31)))
-#endif
-
-#ifdef CONFIG_MITIGATION_RETHUNK
-# define DISABLE_RETHUNK 0
-#else
-# define DISABLE_RETHUNK (1 << (X86_FEATURE_RETHUNK & 31))
-#endif
-
-#ifdef CONFIG_MITIGATION_UNRET_ENTRY
-# define DISABLE_UNRET 0
-#else
-# define DISABLE_UNRET (1 << (X86_FEATURE_UNRET & 31))
-#endif
-
-#ifdef CONFIG_MITIGATION_CALL_DEPTH_TRACKING
-# define DISABLE_CALL_DEPTH_TRACKING 0
-#else
-# define DISABLE_CALL_DEPTH_TRACKING (1 << (X86_FEATURE_CALL_DEPTH & 31))
-#endif
-
-#ifdef CONFIG_ADDRESS_MASKING
-# define DISABLE_LAM 0
-#else
-# define DISABLE_LAM (1 << (X86_FEATURE_LAM & 31))
-#endif
-
-#ifdef CONFIG_INTEL_IOMMU_SVM
-# define DISABLE_ENQCMD 0
-#else
-# define DISABLE_ENQCMD (1 << (X86_FEATURE_ENQCMD & 31))
-#endif
-
-#ifdef CONFIG_X86_SGX
-# define DISABLE_SGX 0
-#else
-# define DISABLE_SGX (1 << (X86_FEATURE_SGX & 31))
-#endif
-
-#ifdef CONFIG_XEN_PV
-# define DISABLE_XENPV 0
-#else
-# define DISABLE_XENPV (1 << (X86_FEATURE_XENPV & 31))
-#endif
-
-#ifdef CONFIG_INTEL_TDX_GUEST
-# define DISABLE_TDX_GUEST 0
-#else
-# define DISABLE_TDX_GUEST (1 << (X86_FEATURE_TDX_GUEST & 31))
-#endif
-
-#ifdef CONFIG_X86_USER_SHADOW_STACK
-#define DISABLE_USER_SHSTK 0
-#else
-#define DISABLE_USER_SHSTK (1 << (X86_FEATURE_USER_SHSTK & 31))
-#endif
-
-#ifdef CONFIG_X86_KERNEL_IBT
-#define DISABLE_IBT 0
-#else
-#define DISABLE_IBT (1 << (X86_FEATURE_IBT & 31))
-#endif
-
-#ifdef CONFIG_X86_FRED
-# define DISABLE_FRED 0
-#else
-# define DISABLE_FRED (1 << (X86_FEATURE_FRED & 31))
-#endif
-
-#ifdef CONFIG_KVM_AMD_SEV
-#define DISABLE_SEV_SNP 0
-#else
-#define DISABLE_SEV_SNP (1 << (X86_FEATURE_SEV_SNP & 31))
-#endif
-
-#ifdef CONFIG_BROADCAST_TLB_FLUSH
-#define DISABLE_INVLPGB 0
-#else
-#define DISABLE_INVLPGB (1 << (X86_FEATURE_INVLPGB & 31))
-#endif
-
-/*
- * Make sure to add features to the correct mask
- */
-#define DISABLED_MASK0 (DISABLE_VME)
-#define DISABLED_MASK1 0
-#define DISABLED_MASK2 0
-#define DISABLED_MASK3 (DISABLE_CYRIX_ARR|DISABLE_CENTAUR_MCR|DISABLE_K6_MTRR)
-#define DISABLED_MASK4 (DISABLE_PCID)
-#define DISABLED_MASK5 0
-#define DISABLED_MASK6 0
-#define DISABLED_MASK7 (DISABLE_PTI)
-#define DISABLED_MASK8 (DISABLE_XENPV|DISABLE_TDX_GUEST)
-#define DISABLED_MASK9 (DISABLE_SGX)
-#define DISABLED_MASK10 0
-#define DISABLED_MASK11 (DISABLE_RETPOLINE|DISABLE_RETHUNK|DISABLE_UNRET| \
- DISABLE_CALL_DEPTH_TRACKING|DISABLE_USER_SHSTK)
-#define DISABLED_MASK12 (DISABLE_FRED|DISABLE_LAM)
-#define DISABLED_MASK13 (DISABLE_INVLPGB)
-#define DISABLED_MASK14 0
-#define DISABLED_MASK15 0
-#define DISABLED_MASK16 (DISABLE_PKU|DISABLE_OSPKE|DISABLE_LA57|DISABLE_UMIP| \
- DISABLE_ENQCMD)
-#define DISABLED_MASK17 0
-#define DISABLED_MASK18 (DISABLE_IBT)
-#define DISABLED_MASK19 (DISABLE_SEV_SNP)
-#define DISABLED_MASK20 0
-#define DISABLED_MASK21 0
-#define DISABLED_MASK_CHECK BUILD_BUG_ON_ZERO(NCAPINTS != 22)
-
-#endif /* _ASM_X86_DISABLED_FEATURES_H */
diff --git a/arch/x86/include/asm/required-features.h b/arch/x86/include/asm/required-features.h
deleted file mode 100644
index 0068133..0000000
--- a/arch/x86/include/asm/required-features.h
+++ /dev/null
@@ -1,105 +0,0 @@
-#ifndef _ASM_X86_REQUIRED_FEATURES_H
-#define _ASM_X86_REQUIRED_FEATURES_H
-
-/* Define minimum CPUID feature set for kernel These bits are checked
- really early to actually display a visible error message before the
- kernel dies. Make sure to assign features to the proper mask!
-
- Some requirements that are not in CPUID yet are also in the
- CONFIG_X86_MINIMUM_CPU_FAMILY which is checked too.
-
- The real information is in arch/x86/Kconfig.cpu, this just converts
- the CONFIGs into a bitmask */
-
-#ifndef CONFIG_MATH_EMULATION
-# define NEED_FPU (1<<(X86_FEATURE_FPU & 31))
-#else
-# define NEED_FPU 0
-#endif
-
-#if defined(CONFIG_X86_PAE) || defined(CONFIG_X86_64)
-# define NEED_PAE (1<<(X86_FEATURE_PAE & 31))
-#else
-# define NEED_PAE 0
-#endif
-
-#ifdef CONFIG_X86_CX8
-# define NEED_CX8 (1<<(X86_FEATURE_CX8 & 31))
-#else
-# define NEED_CX8 0
-#endif
-
-#if defined(CONFIG_X86_CMOV) || defined(CONFIG_X86_64)
-# define NEED_CMOV (1<<(X86_FEATURE_CMOV & 31))
-#else
-# define NEED_CMOV 0
-#endif
-
-# define NEED_3DNOW 0
-
-#if defined(CONFIG_X86_P6_NOP) || defined(CONFIG_X86_64)
-# define NEED_NOPL (1<<(X86_FEATURE_NOPL & 31))
-#else
-# define NEED_NOPL 0
-#endif
-
-#ifdef CONFIG_MATOM
-# define NEED_MOVBE (1<<(X86_FEATURE_MOVBE & 31))
-#else
-# define NEED_MOVBE 0
-#endif
-
-#ifdef CONFIG_X86_64
-#ifdef CONFIG_PARAVIRT_XXL
-/* Paravirtualized systems may not have PSE or PGE available */
-#define NEED_PSE 0
-#define NEED_PGE 0
-#else
-#define NEED_PSE (1<<(X86_FEATURE_PSE) & 31)
-#define NEED_PGE (1<<(X86_FEATURE_PGE) & 31)
-#endif
-#define NEED_MSR (1<<(X86_FEATURE_MSR & 31))
-#define NEED_FXSR (1<<(X86_FEATURE_FXSR & 31))
-#define NEED_XMM (1<<(X86_FEATURE_XMM & 31))
-#define NEED_XMM2 (1<<(X86_FEATURE_XMM2 & 31))
-#define NEED_LM (1<<(X86_FEATURE_LM & 31))
-#else
-#define NEED_PSE 0
-#define NEED_MSR 0
-#define NEED_PGE 0
-#define NEED_FXSR 0
-#define NEED_XMM 0
-#define NEED_XMM2 0
-#define NEED_LM 0
-#endif
-
-#define REQUIRED_MASK0 (NEED_FPU|NEED_PSE|NEED_MSR|NEED_PAE|\
- NEED_CX8|NEED_PGE|NEED_FXSR|NEED_CMOV|\
- NEED_XMM|NEED_XMM2)
-#define SSE_MASK (NEED_XMM|NEED_XMM2)
-
-#define REQUIRED_MASK1 (NEED_LM|NEED_3DNOW)
-
-#define REQUIRED_MASK2 0
-#define REQUIRED_MASK3 (NEED_NOPL)
-#define REQUIRED_MASK4 (NEED_MOVBE)
-#define REQUIRED_MASK5 0
-#define REQUIRED_MASK6 0
-#define REQUIRED_MASK7 0
-#define REQUIRED_MASK8 0
-#define REQUIRED_MASK9 0
-#define REQUIRED_MASK10 0
-#define REQUIRED_MASK11 0
-#define REQUIRED_MASK12 0
-#define REQUIRED_MASK13 0
-#define REQUIRED_MASK14 0
-#define REQUIRED_MASK15 0
-#define REQUIRED_MASK16 0
-#define REQUIRED_MASK17 0
-#define REQUIRED_MASK18 0
-#define REQUIRED_MASK19 0
-#define REQUIRED_MASK20 0
-#define REQUIRED_MASK21 0
-#define REQUIRED_MASK_CHECK BUILD_BUG_ON_ZERO(NCAPINTS != 22)
-
-#endif /* _ASM_X86_REQUIRED_FEATURES_H */
diff --git a/tools/arch/x86/include/asm/cpufeatures.h b/tools/arch/x86/include/asm/cpufeatures.h
index 17b6590..c691481 100644
--- a/tools/arch/x86/include/asm/cpufeatures.h
+++ b/tools/arch/x86/include/asm/cpufeatures.h
@@ -2,14 +2,6 @@
#ifndef _ASM_X86_CPUFEATURES_H
#define _ASM_X86_CPUFEATURES_H
-#ifndef _ASM_X86_REQUIRED_FEATURES_H
-#include <asm/required-features.h>
-#endif
-
-#ifndef _ASM_X86_DISABLED_FEATURES_H
-#include <asm/disabled-features.h>
-#endif
-
/*
* Defines x86 CPU feature bits
*/
diff --git a/tools/arch/x86/include/asm/disabled-features.h b/tools/arch/x86/include/asm/disabled-features.h
deleted file mode 100644
index c492bdc..0000000
--- a/tools/arch/x86/include/asm/disabled-features.h
+++ /dev/null
@@ -1,161 +0,0 @@
-#ifndef _ASM_X86_DISABLED_FEATURES_H
-#define _ASM_X86_DISABLED_FEATURES_H
-
-/* These features, although they might be available in a CPU
- * will not be used because the compile options to support
- * them are not present.
- *
- * This code allows them to be checked and disabled at
- * compile time without an explicit #ifdef. Use
- * cpu_feature_enabled().
- */
-
-#ifdef CONFIG_X86_UMIP
-# define DISABLE_UMIP 0
-#else
-# define DISABLE_UMIP (1<<(X86_FEATURE_UMIP & 31))
-#endif
-
-#ifdef CONFIG_X86_64
-# define DISABLE_VME (1<<(X86_FEATURE_VME & 31))
-# define DISABLE_K6_MTRR (1<<(X86_FEATURE_K6_MTRR & 31))
-# define DISABLE_CYRIX_ARR (1<<(X86_FEATURE_CYRIX_ARR & 31))
-# define DISABLE_CENTAUR_MCR (1<<(X86_FEATURE_CENTAUR_MCR & 31))
-# define DISABLE_PCID 0
-#else
-# define DISABLE_VME 0
-# define DISABLE_K6_MTRR 0
-# define DISABLE_CYRIX_ARR 0
-# define DISABLE_CENTAUR_MCR 0
-# define DISABLE_PCID (1<<(X86_FEATURE_PCID & 31))
-#endif /* CONFIG_X86_64 */
-
-#ifdef CONFIG_X86_INTEL_MEMORY_PROTECTION_KEYS
-# define DISABLE_PKU 0
-# define DISABLE_OSPKE 0
-#else
-# define DISABLE_PKU (1<<(X86_FEATURE_PKU & 31))
-# define DISABLE_OSPKE (1<<(X86_FEATURE_OSPKE & 31))
-#endif /* CONFIG_X86_INTEL_MEMORY_PROTECTION_KEYS */
-
-#ifdef CONFIG_X86_5LEVEL
-# define DISABLE_LA57 0
-#else
-# define DISABLE_LA57 (1<<(X86_FEATURE_LA57 & 31))
-#endif
-
-#ifdef CONFIG_MITIGATION_PAGE_TABLE_ISOLATION
-# define DISABLE_PTI 0
-#else
-# define DISABLE_PTI (1 << (X86_FEATURE_PTI & 31))
-#endif
-
-#ifdef CONFIG_MITIGATION_RETPOLINE
-# define DISABLE_RETPOLINE 0
-#else
-# define DISABLE_RETPOLINE ((1 << (X86_FEATURE_RETPOLINE & 31)) | \
- (1 << (X86_FEATURE_RETPOLINE_LFENCE & 31)))
-#endif
-
-#ifdef CONFIG_MITIGATION_RETHUNK
-# define DISABLE_RETHUNK 0
-#else
-# define DISABLE_RETHUNK (1 << (X86_FEATURE_RETHUNK & 31))
-#endif
-
-#ifdef CONFIG_MITIGATION_UNRET_ENTRY
-# define DISABLE_UNRET 0
-#else
-# define DISABLE_UNRET (1 << (X86_FEATURE_UNRET & 31))
-#endif
-
-#ifdef CONFIG_MITIGATION_CALL_DEPTH_TRACKING
-# define DISABLE_CALL_DEPTH_TRACKING 0
-#else
-# define DISABLE_CALL_DEPTH_TRACKING (1 << (X86_FEATURE_CALL_DEPTH & 31))
-#endif
-
-#ifdef CONFIG_ADDRESS_MASKING
-# define DISABLE_LAM 0
-#else
-# define DISABLE_LAM (1 << (X86_FEATURE_LAM & 31))
-#endif
-
-#ifdef CONFIG_INTEL_IOMMU_SVM
-# define DISABLE_ENQCMD 0
-#else
-# define DISABLE_ENQCMD (1 << (X86_FEATURE_ENQCMD & 31))
-#endif
-
-#ifdef CONFIG_X86_SGX
-# define DISABLE_SGX 0
-#else
-# define DISABLE_SGX (1 << (X86_FEATURE_SGX & 31))
-#endif
-
-#ifdef CONFIG_XEN_PV
-# define DISABLE_XENPV 0
-#else
-# define DISABLE_XENPV (1 << (X86_FEATURE_XENPV & 31))
-#endif
-
-#ifdef CONFIG_INTEL_TDX_GUEST
-# define DISABLE_TDX_GUEST 0
-#else
-# define DISABLE_TDX_GUEST (1 << (X86_FEATURE_TDX_GUEST & 31))
-#endif
-
-#ifdef CONFIG_X86_USER_SHADOW_STACK
-#define DISABLE_USER_SHSTK 0
-#else
-#define DISABLE_USER_SHSTK (1 << (X86_FEATURE_USER_SHSTK & 31))
-#endif
-
-#ifdef CONFIG_X86_KERNEL_IBT
-#define DISABLE_IBT 0
-#else
-#define DISABLE_IBT (1 << (X86_FEATURE_IBT & 31))
-#endif
-
-#ifdef CONFIG_X86_FRED
-# define DISABLE_FRED 0
-#else
-# define DISABLE_FRED (1 << (X86_FEATURE_FRED & 31))
-#endif
-
-#ifdef CONFIG_KVM_AMD_SEV
-#define DISABLE_SEV_SNP 0
-#else
-#define DISABLE_SEV_SNP (1 << (X86_FEATURE_SEV_SNP & 31))
-#endif
-
-/*
- * Make sure to add features to the correct mask
- */
-#define DISABLED_MASK0 (DISABLE_VME)
-#define DISABLED_MASK1 0
-#define DISABLED_MASK2 0
-#define DISABLED_MASK3 (DISABLE_CYRIX_ARR|DISABLE_CENTAUR_MCR|DISABLE_K6_MTRR)
-#define DISABLED_MASK4 (DISABLE_PCID)
-#define DISABLED_MASK5 0
-#define DISABLED_MASK6 0
-#define DISABLED_MASK7 (DISABLE_PTI)
-#define DISABLED_MASK8 (DISABLE_XENPV|DISABLE_TDX_GUEST)
-#define DISABLED_MASK9 (DISABLE_SGX)
-#define DISABLED_MASK10 0
-#define DISABLED_MASK11 (DISABLE_RETPOLINE|DISABLE_RETHUNK|DISABLE_UNRET| \
- DISABLE_CALL_DEPTH_TRACKING|DISABLE_USER_SHSTK)
-#define DISABLED_MASK12 (DISABLE_FRED|DISABLE_LAM)
-#define DISABLED_MASK13 0
-#define DISABLED_MASK14 0
-#define DISABLED_MASK15 0
-#define DISABLED_MASK16 (DISABLE_PKU|DISABLE_OSPKE|DISABLE_LA57|DISABLE_UMIP| \
- DISABLE_ENQCMD)
-#define DISABLED_MASK17 0
-#define DISABLED_MASK18 (DISABLE_IBT)
-#define DISABLED_MASK19 (DISABLE_SEV_SNP)
-#define DISABLED_MASK20 0
-#define DISABLED_MASK21 0
-#define DISABLED_MASK_CHECK BUILD_BUG_ON_ZERO(NCAPINTS != 22)
-
-#endif /* _ASM_X86_DISABLED_FEATURES_H */
diff --git a/tools/arch/x86/include/asm/required-features.h b/tools/arch/x86/include/asm/required-features.h
deleted file mode 100644
index 0068133..0000000
--- a/tools/arch/x86/include/asm/required-features.h
+++ /dev/null
@@ -1,105 +0,0 @@
-#ifndef _ASM_X86_REQUIRED_FEATURES_H
-#define _ASM_X86_REQUIRED_FEATURES_H
-
-/* Define minimum CPUID feature set for kernel These bits are checked
- really early to actually display a visible error message before the
- kernel dies. Make sure to assign features to the proper mask!
-
- Some requirements that are not in CPUID yet are also in the
- CONFIG_X86_MINIMUM_CPU_FAMILY which is checked too.
-
- The real information is in arch/x86/Kconfig.cpu, this just converts
- the CONFIGs into a bitmask */
-
-#ifndef CONFIG_MATH_EMULATION
-# define NEED_FPU (1<<(X86_FEATURE_FPU & 31))
-#else
-# define NEED_FPU 0
-#endif
-
-#if defined(CONFIG_X86_PAE) || defined(CONFIG_X86_64)
-# define NEED_PAE (1<<(X86_FEATURE_PAE & 31))
-#else
-# define NEED_PAE 0
-#endif
-
-#ifdef CONFIG_X86_CX8
-# define NEED_CX8 (1<<(X86_FEATURE_CX8 & 31))
-#else
-# define NEED_CX8 0
-#endif
-
-#if defined(CONFIG_X86_CMOV) || defined(CONFIG_X86_64)
-# define NEED_CMOV (1<<(X86_FEATURE_CMOV & 31))
-#else
-# define NEED_CMOV 0
-#endif
-
-# define NEED_3DNOW 0
-
-#if defined(CONFIG_X86_P6_NOP) || defined(CONFIG_X86_64)
-# define NEED_NOPL (1<<(X86_FEATURE_NOPL & 31))
-#else
-# define NEED_NOPL 0
-#endif
-
-#ifdef CONFIG_MATOM
-# define NEED_MOVBE (1<<(X86_FEATURE_MOVBE & 31))
-#else
-# define NEED_MOVBE 0
-#endif
-
-#ifdef CONFIG_X86_64
-#ifdef CONFIG_PARAVIRT_XXL
-/* Paravirtualized systems may not have PSE or PGE available */
-#define NEED_PSE 0
-#define NEED_PGE 0
-#else
-#define NEED_PSE (1<<(X86_FEATURE_PSE) & 31)
-#define NEED_PGE (1<<(X86_FEATURE_PGE) & 31)
-#endif
-#define NEED_MSR (1<<(X86_FEATURE_MSR & 31))
-#define NEED_FXSR (1<<(X86_FEATURE_FXSR & 31))
-#define NEED_XMM (1<<(X86_FEATURE_XMM & 31))
-#define NEED_XMM2 (1<<(X86_FEATURE_XMM2 & 31))
-#define NEED_LM (1<<(X86_FEATURE_LM & 31))
-#else
-#define NEED_PSE 0
-#define NEED_MSR 0
-#define NEED_PGE 0
-#define NEED_FXSR 0
-#define NEED_XMM 0
-#define NEED_XMM2 0
-#define NEED_LM 0
-#endif
-
-#define REQUIRED_MASK0 (NEED_FPU|NEED_PSE|NEED_MSR|NEED_PAE|\
- NEED_CX8|NEED_PGE|NEED_FXSR|NEED_CMOV|\
- NEED_XMM|NEED_XMM2)
-#define SSE_MASK (NEED_XMM|NEED_XMM2)
-
-#define REQUIRED_MASK1 (NEED_LM|NEED_3DNOW)
-
-#define REQUIRED_MASK2 0
-#define REQUIRED_MASK3 (NEED_NOPL)
-#define REQUIRED_MASK4 (NEED_MOVBE)
-#define REQUIRED_MASK5 0
-#define REQUIRED_MASK6 0
-#define REQUIRED_MASK7 0
-#define REQUIRED_MASK8 0
-#define REQUIRED_MASK9 0
-#define REQUIRED_MASK10 0
-#define REQUIRED_MASK11 0
-#define REQUIRED_MASK12 0
-#define REQUIRED_MASK13 0
-#define REQUIRED_MASK14 0
-#define REQUIRED_MASK15 0
-#define REQUIRED_MASK16 0
-#define REQUIRED_MASK17 0
-#define REQUIRED_MASK18 0
-#define REQUIRED_MASK19 0
-#define REQUIRED_MASK20 0
-#define REQUIRED_MASK21 0
-#define REQUIRED_MASK_CHECK BUILD_BUG_ON_ZERO(NCAPINTS != 22)
-
-#endif /* _ASM_X86_REQUIRED_FEATURES_H */
--git a/tools/perf/check-headers.sh b/tools/perf/check-headers.sh
index d3c6e10..a4499e5 100755
--- a/tools/perf/check-headers.sh
+++ b/tools/perf/check-headers.sh
@@ -26,8 +26,6 @@ FILES=(
"include/linux/hash.h"
"include/linux/list-sort.h"
"include/uapi/linux/hw_breakpoint.h"
- "arch/x86/include/asm/disabled-features.h"
- "arch/x86/include/asm/required-features.h"
"arch/x86/include/asm/cpufeatures.h"
"arch/x86/include/asm/inat_types.h"
"arch/x86/include/asm/emulate_prefix.h"
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [tip: x86/cpu] x86/cpufeatures: Generate the <asm/cpufeaturemasks.h> header based on build config
2025-03-05 18:47 ` [PATCH v7 2/4] x86/cpufeatures: Generate a feature mask header based on build config Xin Li (Intel)
@ 2025-03-10 8:18 ` tip-bot2 for H. Peter Anvin (Intel)
2025-03-19 11:03 ` [tip: x86/core] " tip-bot2 for H. Peter Anvin (Intel)
1 sibling, 0 replies; 20+ messages in thread
From: tip-bot2 for H. Peter Anvin (Intel) @ 2025-03-10 8:18 UTC (permalink / raw)
To: linux-tip-commits
Cc: H. Peter Anvin (Intel), Xin Li (Intel), Borislav Petkov (AMD),
Ingo Molnar, Nikolay Borisov, Linus Torvalds, x86, linux-kernel
The following commit has been merged into the x86/cpu branch of tip:
Commit-ID: 7a7bd24a0ca02dfe68bd8a7a567b3da3b716bd8d
Gitweb: https://git.kernel.org/tip/7a7bd24a0ca02dfe68bd8a7a567b3da3b716bd8d
Author: H. Peter Anvin (Intel) <hpa@zytor.com>
AuthorDate: Wed, 05 Mar 2025 10:47:22 -08:00
Committer: Ingo Molnar <mingo@kernel.org>
CommitterDate: Mon, 10 Mar 2025 09:02:47 +01:00
x86/cpufeatures: Generate the <asm/cpufeaturemasks.h> header based on build config
Introduce an AWK script to auto-generate the <asm/cpufeaturemasks.h> header
with required and disabled feature masks based on <asm/cpufeatures.h>
and the current build config.
Thus for any CPU feature with a build config, e.g., X86_FRED, simply add:
config X86_DISABLED_FEATURE_FRED
def_bool y
depends on !X86_FRED
to arch/x86/Kconfig.cpufeatures, instead of adding a conditional CPU
feature disable flag, e.g., DISABLE_FRED.
Lastly, the generated required and disabled feature masks will be added to
their corresponding feature masks for this particular compile-time
configuration.
[ Xin: build integration improvements ]
[ mingo: Improved changelog and comments ]
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
Signed-off-by: Xin Li (Intel) <xin@zytor.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Reviewed-by: Nikolay Borisov <nik.borisov@suse.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Link: https://lore.kernel.org/r/20250305184725.3341760-3-xin@zytor.com
---
arch/x86/Makefile | 15 +++++-
arch/x86/boot/cpucheck.c | 3 +-
arch/x86/boot/cpuflags.c | 1 +-
arch/x86/boot/mkcpustr.c | 3 +-
arch/x86/include/asm/Kbuild | 1 +-
arch/x86/include/asm/cpufeature.h | 1 +-
arch/x86/include/asm/cpufeatures.h | 8 +---
arch/x86/kernel/verify_cpu.S | 4 +-
arch/x86/tools/cpufeaturemasks.awk | 81 +++++++++++++++++++++++++++++-
9 files changed, 105 insertions(+), 12 deletions(-)
create mode 100755 arch/x86/tools/cpufeaturemasks.awk
diff --git a/arch/x86/Makefile b/arch/x86/Makefile
index 8120085..420f086 100644
--- a/arch/x86/Makefile
+++ b/arch/x86/Makefile
@@ -265,6 +265,21 @@ archheaders:
$(Q)$(MAKE) $(build)=arch/x86/entry/syscalls all
###
+# <asm/cpufeaturemasks.h> header generation
+
+cpufeaturemasks.hdr := arch/x86/include/generated/asm/cpufeaturemasks.h
+cpufeaturemasks.awk := $(srctree)/arch/x86/tools/cpufeaturemasks.awk
+cpufeatures_hdr := $(srctree)/arch/x86/include/asm/cpufeatures.h
+targets += $(cpufeaturemasks.hdr)
+quiet_cmd_gen_featuremasks = GEN $@
+ cmd_gen_featuremasks = $(AWK) -f $(cpufeaturemasks.awk) $(cpufeatures_hdr) $(KCONFIG_CONFIG) > $@
+
+$(cpufeaturemasks.hdr): $(cpufeaturemasks.awk) $(cpufeatures_hdr) $(KCONFIG_CONFIG) FORCE
+ $(shell mkdir -p $(dir $@))
+ $(call if_changed,gen_featuremasks)
+archprepare: $(cpufeaturemasks.hdr)
+
+###
# Kernel objects
libs-y += arch/x86/lib/
diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
index 0aae4d4..f82de8d 100644
--- a/arch/x86/boot/cpucheck.c
+++ b/arch/x86/boot/cpucheck.c
@@ -22,10 +22,11 @@
# include "boot.h"
#endif
#include <linux/types.h>
+#include <asm/cpufeaturemasks.h>
#include <asm/intel-family.h>
#include <asm/processor-flags.h>
-#include <asm/required-features.h>
#include <asm/msr-index.h>
+
#include "string.h"
#include "msr.h"
diff --git a/arch/x86/boot/cpuflags.c b/arch/x86/boot/cpuflags.c
index d75237b..0cabdac 100644
--- a/arch/x86/boot/cpuflags.c
+++ b/arch/x86/boot/cpuflags.c
@@ -3,7 +3,6 @@
#include "bitops.h"
#include <asm/processor-flags.h>
-#include <asm/required-features.h>
#include <asm/msr-index.h>
#include "cpuflags.h"
diff --git a/arch/x86/boot/mkcpustr.c b/arch/x86/boot/mkcpustr.c
index da0ccc5..22d730b 100644
--- a/arch/x86/boot/mkcpustr.c
+++ b/arch/x86/boot/mkcpustr.c
@@ -12,8 +12,6 @@
#include <stdio.h>
-#include "../include/asm/required-features.h"
-#include "../include/asm/disabled-features.h"
#include "../include/asm/cpufeatures.h"
#include "../include/asm/vmxfeatures.h"
#include "../kernel/cpu/capflags.c"
@@ -23,6 +21,7 @@ int main(void)
int i, j;
const char *str;
+ printf("#include <asm/cpufeaturemasks.h>\n\n");
printf("static const char x86_cap_strs[] =\n");
for (i = 0; i < NCAPINTS; i++) {
diff --git a/arch/x86/include/asm/Kbuild b/arch/x86/include/asm/Kbuild
index 58f4dde..4566000 100644
--- a/arch/x86/include/asm/Kbuild
+++ b/arch/x86/include/asm/Kbuild
@@ -8,6 +8,7 @@ generated-y += syscalls_x32.h
generated-y += unistd_32_ia32.h
generated-y += unistd_64_x32.h
generated-y += xen-hypercalls.h
+generated-y += cpufeaturemasks.h
generic-y += early_ioremap.h
generic-y += fprobe.h
diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
index e955da3..d54db88 100644
--- a/arch/x86/include/asm/cpufeature.h
+++ b/arch/x86/include/asm/cpufeature.h
@@ -9,6 +9,7 @@
#include <asm/asm.h>
#include <linux/bitops.h>
#include <asm/alternative.h>
+#include <asm/cpufeaturemasks.h>
enum cpuid_leafs
{
diff --git a/arch/x86/include/asm/cpufeatures.h b/arch/x86/include/asm/cpufeatures.h
index 8770dc1..c0462be 100644
--- a/arch/x86/include/asm/cpufeatures.h
+++ b/arch/x86/include/asm/cpufeatures.h
@@ -2,14 +2,6 @@
#ifndef _ASM_X86_CPUFEATURES_H
#define _ASM_X86_CPUFEATURES_H
-#ifndef _ASM_X86_REQUIRED_FEATURES_H
-#include <asm/required-features.h>
-#endif
-
-#ifndef _ASM_X86_DISABLED_FEATURES_H
-#include <asm/disabled-features.h>
-#endif
-
/*
* Defines x86 CPU feature bits
*/
diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
index 1258a58..37ad437 100644
--- a/arch/x86/kernel/verify_cpu.S
+++ b/arch/x86/kernel/verify_cpu.S
@@ -29,8 +29,12 @@
*/
#include <asm/cpufeatures.h>
+#include <asm/cpufeaturemasks.h>
#include <asm/msr-index.h>
+#define SSE_MASK \
+ (REQUIRED_MASK0 & ((1<<(X86_FEATURE_XMM & 31)) | (1<<(X86_FEATURE_XMM2 & 31))))
+
SYM_FUNC_START_LOCAL(verify_cpu)
pushf # Save caller passed flags
push $0 # Kill any dangerous flags
diff --git a/arch/x86/tools/cpufeaturemasks.awk b/arch/x86/tools/cpufeaturemasks.awk
new file mode 100755
index 0000000..59757ca
--- /dev/null
+++ b/arch/x86/tools/cpufeaturemasks.awk
@@ -0,0 +1,81 @@
+#!/usr/bin/awk
+#
+# Convert cpufeatures.h to a list of compile-time masks
+# Note: this blithely assumes that each word has at least one
+# feature defined in it; if not, something else is wrong!
+#
+
+BEGIN {
+ printf "#ifndef _ASM_X86_CPUFEATUREMASKS_H\n";
+ printf "#define _ASM_X86_CPUFEATUREMASKS_H\n\n";
+
+ file = 0
+}
+
+FNR == 1 {
+ ++file;
+
+ # arch/x86/include/asm/cpufeatures.h
+ if (file == 1)
+ FS = "[ \t()*+]+";
+
+ # .config
+ if (file == 2)
+ FS = "=";
+}
+
+# Create a dictionary of sorts, containing all defined feature bits
+file == 1 && $1 ~ /^#define$/ && $2 ~ /^X86_FEATURE_/ {
+ nfeat = $3 * $4 + $5;
+ feat = $2;
+ sub(/^X86_FEATURE_/, "", feat);
+ feats[nfeat] = feat;
+}
+file == 1 && $1 ~ /^#define$/ && $2 == "NCAPINTS" {
+ ncapints = int($3);
+}
+
+# Create a dictionary featstat[REQUIRED|DISABLED, FEATURE_NAME] = on | off
+file == 2 && $1 ~ /^CONFIG_X86_(REQUIRED|DISABLED)_FEATURE_/ {
+ on = ($2 == "y");
+ if (split($1, fs, "CONFIG_X86_|_FEATURE_") == 3)
+ featstat[fs[2], fs[3]] = on;
+}
+
+END {
+ sets[1] = "REQUIRED";
+ sets[2] = "DISABLED";
+
+ for (ns in sets) {
+ s = sets[ns];
+
+ printf "/*\n";
+ printf " * %s features:\n", s;
+ printf " *\n";
+ fstr = "";
+ for (i = 0; i < ncapints; i++) {
+ mask = 0;
+ for (j = 0; j < 32; j++) {
+ feat = feats[i*32 + j];
+ if (featstat[s, feat]) {
+ nfstr = fstr " " feat;
+ if (length(nfstr) > 72) {
+ printf " * %s\n", fstr;
+ nfstr = " " feat;
+ }
+ fstr = nfstr;
+ mask += (2 ^ j);
+ }
+ }
+ masks[i] = mask;
+ }
+ printf " * %s\n */\n", fstr;
+
+ for (i = 0; i < ncapints; i++)
+ printf "#define %s_MASK%d\t0x%08xU\n", s, i, masks[i];
+
+ printf "#define %s_MASK_CHECK BUILD_BUG_ON_ZERO(NCAPINTS != %d)\n\n", s, ncapints;
+ }
+
+ printf "#endif /* _ASM_X86_CPUFEATUREMASKS_H */\n";
+}
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [tip: x86/core] x86/cpufeatures: Generate the <asm/cpufeaturemasks.h> header based on build config
2025-03-05 18:47 ` [PATCH v7 2/4] x86/cpufeatures: Generate a feature mask header based on build config Xin Li (Intel)
2025-03-10 8:18 ` [tip: x86/cpu] x86/cpufeatures: Generate the <asm/cpufeaturemasks.h> " tip-bot2 for H. Peter Anvin (Intel)
@ 2025-03-19 11:03 ` tip-bot2 for H. Peter Anvin (Intel)
2025-03-20 16:23 ` Michael Kelley
1 sibling, 1 reply; 20+ messages in thread
From: tip-bot2 for H. Peter Anvin (Intel) @ 2025-03-19 11:03 UTC (permalink / raw)
To: linux-tip-commits
Cc: H. Peter Anvin (Intel), Xin Li (Intel), Borislav Petkov (AMD),
Ingo Molnar, Nikolay Borisov, Linus Torvalds, x86, linux-kernel
The following commit has been merged into the x86/core branch of tip:
Commit-ID: 841326332bcb13ae4e6cd456350bf566a402b45e
Gitweb: https://git.kernel.org/tip/841326332bcb13ae4e6cd456350bf566a402b45e
Author: H. Peter Anvin (Intel) <hpa@zytor.com>
AuthorDate: Wed, 05 Mar 2025 10:47:22 -08:00
Committer: Ingo Molnar <mingo@kernel.org>
CommitterDate: Wed, 19 Mar 2025 11:15:11 +01:00
x86/cpufeatures: Generate the <asm/cpufeaturemasks.h> header based on build config
Introduce an AWK script to auto-generate the <asm/cpufeaturemasks.h> header
with required and disabled feature masks based on <asm/cpufeatures.h>
and the current build config.
Thus for any CPU feature with a build config, e.g., X86_FRED, simply add:
config X86_DISABLED_FEATURE_FRED
def_bool y
depends on !X86_FRED
to arch/x86/Kconfig.cpufeatures, instead of adding a conditional CPU
feature disable flag, e.g., DISABLE_FRED.
Lastly, the generated required and disabled feature masks will be added to
their corresponding feature masks for this particular compile-time
configuration.
[ Xin: build integration improvements ]
[ mingo: Improved changelog and comments ]
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
Signed-off-by: Xin Li (Intel) <xin@zytor.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Reviewed-by: Nikolay Borisov <nik.borisov@suse.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Link: https://lore.kernel.org/r/20250305184725.3341760-3-xin@zytor.com
---
arch/x86/Makefile | 15 +++++-
arch/x86/boot/cpucheck.c | 3 +-
arch/x86/boot/cpuflags.c | 1 +-
arch/x86/boot/mkcpustr.c | 3 +-
arch/x86/include/asm/Kbuild | 1 +-
arch/x86/include/asm/cpufeature.h | 1 +-
arch/x86/include/asm/cpufeatures.h | 8 +---
arch/x86/kernel/verify_cpu.S | 4 +-
arch/x86/tools/cpufeaturemasks.awk | 81 +++++++++++++++++++++++++++++-
9 files changed, 105 insertions(+), 12 deletions(-)
create mode 100755 arch/x86/tools/cpufeaturemasks.awk
diff --git a/arch/x86/Makefile b/arch/x86/Makefile
index 6784129..a607769 100644
--- a/arch/x86/Makefile
+++ b/arch/x86/Makefile
@@ -269,6 +269,21 @@ archheaders:
$(Q)$(MAKE) $(build)=arch/x86/entry/syscalls all
###
+# <asm/cpufeaturemasks.h> header generation
+
+cpufeaturemasks.hdr := arch/x86/include/generated/asm/cpufeaturemasks.h
+cpufeaturemasks.awk := $(srctree)/arch/x86/tools/cpufeaturemasks.awk
+cpufeatures_hdr := $(srctree)/arch/x86/include/asm/cpufeatures.h
+targets += $(cpufeaturemasks.hdr)
+quiet_cmd_gen_featuremasks = GEN $@
+ cmd_gen_featuremasks = $(AWK) -f $(cpufeaturemasks.awk) $(cpufeatures_hdr) $(KCONFIG_CONFIG) > $@
+
+$(cpufeaturemasks.hdr): $(cpufeaturemasks.awk) $(cpufeatures_hdr) $(KCONFIG_CONFIG) FORCE
+ $(shell mkdir -p $(dir $@))
+ $(call if_changed,gen_featuremasks)
+archprepare: $(cpufeaturemasks.hdr)
+
+###
# Kernel objects
libs-y += arch/x86/lib/
diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
index 0aae4d4..f82de8d 100644
--- a/arch/x86/boot/cpucheck.c
+++ b/arch/x86/boot/cpucheck.c
@@ -22,10 +22,11 @@
# include "boot.h"
#endif
#include <linux/types.h>
+#include <asm/cpufeaturemasks.h>
#include <asm/intel-family.h>
#include <asm/processor-flags.h>
-#include <asm/required-features.h>
#include <asm/msr-index.h>
+
#include "string.h"
#include "msr.h"
diff --git a/arch/x86/boot/cpuflags.c b/arch/x86/boot/cpuflags.c
index d75237b..0cabdac 100644
--- a/arch/x86/boot/cpuflags.c
+++ b/arch/x86/boot/cpuflags.c
@@ -3,7 +3,6 @@
#include "bitops.h"
#include <asm/processor-flags.h>
-#include <asm/required-features.h>
#include <asm/msr-index.h>
#include "cpuflags.h"
diff --git a/arch/x86/boot/mkcpustr.c b/arch/x86/boot/mkcpustr.c
index da0ccc5..22d730b 100644
--- a/arch/x86/boot/mkcpustr.c
+++ b/arch/x86/boot/mkcpustr.c
@@ -12,8 +12,6 @@
#include <stdio.h>
-#include "../include/asm/required-features.h"
-#include "../include/asm/disabled-features.h"
#include "../include/asm/cpufeatures.h"
#include "../include/asm/vmxfeatures.h"
#include "../kernel/cpu/capflags.c"
@@ -23,6 +21,7 @@ int main(void)
int i, j;
const char *str;
+ printf("#include <asm/cpufeaturemasks.h>\n\n");
printf("static const char x86_cap_strs[] =\n");
for (i = 0; i < NCAPINTS; i++) {
diff --git a/arch/x86/include/asm/Kbuild b/arch/x86/include/asm/Kbuild
index 58f4dde..4566000 100644
--- a/arch/x86/include/asm/Kbuild
+++ b/arch/x86/include/asm/Kbuild
@@ -8,6 +8,7 @@ generated-y += syscalls_x32.h
generated-y += unistd_32_ia32.h
generated-y += unistd_64_x32.h
generated-y += xen-hypercalls.h
+generated-y += cpufeaturemasks.h
generic-y += early_ioremap.h
generic-y += fprobe.h
diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
index e955da3..d54db88 100644
--- a/arch/x86/include/asm/cpufeature.h
+++ b/arch/x86/include/asm/cpufeature.h
@@ -9,6 +9,7 @@
#include <asm/asm.h>
#include <linux/bitops.h>
#include <asm/alternative.h>
+#include <asm/cpufeaturemasks.h>
enum cpuid_leafs
{
diff --git a/arch/x86/include/asm/cpufeatures.h b/arch/x86/include/asm/cpufeatures.h
index 8770dc1..c0462be 100644
--- a/arch/x86/include/asm/cpufeatures.h
+++ b/arch/x86/include/asm/cpufeatures.h
@@ -2,14 +2,6 @@
#ifndef _ASM_X86_CPUFEATURES_H
#define _ASM_X86_CPUFEATURES_H
-#ifndef _ASM_X86_REQUIRED_FEATURES_H
-#include <asm/required-features.h>
-#endif
-
-#ifndef _ASM_X86_DISABLED_FEATURES_H
-#include <asm/disabled-features.h>
-#endif
-
/*
* Defines x86 CPU feature bits
*/
diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
index 1258a58..37ad437 100644
--- a/arch/x86/kernel/verify_cpu.S
+++ b/arch/x86/kernel/verify_cpu.S
@@ -29,8 +29,12 @@
*/
#include <asm/cpufeatures.h>
+#include <asm/cpufeaturemasks.h>
#include <asm/msr-index.h>
+#define SSE_MASK \
+ (REQUIRED_MASK0 & ((1<<(X86_FEATURE_XMM & 31)) | (1<<(X86_FEATURE_XMM2 & 31))))
+
SYM_FUNC_START_LOCAL(verify_cpu)
pushf # Save caller passed flags
push $0 # Kill any dangerous flags
diff --git a/arch/x86/tools/cpufeaturemasks.awk b/arch/x86/tools/cpufeaturemasks.awk
new file mode 100755
index 0000000..59757ca
--- /dev/null
+++ b/arch/x86/tools/cpufeaturemasks.awk
@@ -0,0 +1,81 @@
+#!/usr/bin/awk
+#
+# Convert cpufeatures.h to a list of compile-time masks
+# Note: this blithely assumes that each word has at least one
+# feature defined in it; if not, something else is wrong!
+#
+
+BEGIN {
+ printf "#ifndef _ASM_X86_CPUFEATUREMASKS_H\n";
+ printf "#define _ASM_X86_CPUFEATUREMASKS_H\n\n";
+
+ file = 0
+}
+
+FNR == 1 {
+ ++file;
+
+ # arch/x86/include/asm/cpufeatures.h
+ if (file == 1)
+ FS = "[ \t()*+]+";
+
+ # .config
+ if (file == 2)
+ FS = "=";
+}
+
+# Create a dictionary of sorts, containing all defined feature bits
+file == 1 && $1 ~ /^#define$/ && $2 ~ /^X86_FEATURE_/ {
+ nfeat = $3 * $4 + $5;
+ feat = $2;
+ sub(/^X86_FEATURE_/, "", feat);
+ feats[nfeat] = feat;
+}
+file == 1 && $1 ~ /^#define$/ && $2 == "NCAPINTS" {
+ ncapints = int($3);
+}
+
+# Create a dictionary featstat[REQUIRED|DISABLED, FEATURE_NAME] = on | off
+file == 2 && $1 ~ /^CONFIG_X86_(REQUIRED|DISABLED)_FEATURE_/ {
+ on = ($2 == "y");
+ if (split($1, fs, "CONFIG_X86_|_FEATURE_") == 3)
+ featstat[fs[2], fs[3]] = on;
+}
+
+END {
+ sets[1] = "REQUIRED";
+ sets[2] = "DISABLED";
+
+ for (ns in sets) {
+ s = sets[ns];
+
+ printf "/*\n";
+ printf " * %s features:\n", s;
+ printf " *\n";
+ fstr = "";
+ for (i = 0; i < ncapints; i++) {
+ mask = 0;
+ for (j = 0; j < 32; j++) {
+ feat = feats[i*32 + j];
+ if (featstat[s, feat]) {
+ nfstr = fstr " " feat;
+ if (length(nfstr) > 72) {
+ printf " * %s\n", fstr;
+ nfstr = " " feat;
+ }
+ fstr = nfstr;
+ mask += (2 ^ j);
+ }
+ }
+ masks[i] = mask;
+ }
+ printf " * %s\n */\n", fstr;
+
+ for (i = 0; i < ncapints; i++)
+ printf "#define %s_MASK%d\t0x%08xU\n", s, i, masks[i];
+
+ printf "#define %s_MASK_CHECK BUILD_BUG_ON_ZERO(NCAPINTS != %d)\n\n", s, ncapints;
+ }
+
+ printf "#endif /* _ASM_X86_CPUFEATUREMASKS_H */\n";
+}
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [tip: x86/core] x86/cpufeatures: Remove {disabled,required}-features.h
2025-03-05 18:47 ` [PATCH v7 3/4] x86/cpufeatures: Remove {disabled,required}-features.h Xin Li (Intel)
2025-03-10 8:18 ` [tip: x86/cpu] " tip-bot2 for Xin Li (Intel)
@ 2025-03-19 11:03 ` tip-bot2 for Xin Li (Intel)
1 sibling, 0 replies; 20+ messages in thread
From: tip-bot2 for Xin Li (Intel) @ 2025-03-19 11:03 UTC (permalink / raw)
To: linux-tip-commits
Cc: Xin Li (Intel), Borislav Petkov (AMD), Ingo Molnar,
Linus Torvalds, x86, linux-kernel
The following commit has been merged into the x86/core branch of tip:
Commit-ID: 8f97566c8a8165cd994baf6219d86fbbf250d2df
Gitweb: https://git.kernel.org/tip/8f97566c8a8165cd994baf6219d86fbbf250d2df
Author: Xin Li (Intel) <xin@zytor.com>
AuthorDate: Mon, 10 Mar 2025 08:32:12 +01:00
Committer: Ingo Molnar <mingo@kernel.org>
CommitterDate: Wed, 19 Mar 2025 11:15:12 +01:00
x86/cpufeatures: Remove {disabled,required}-features.h
The functionalities of {disabled,required}-features.h have been replaced with
the auto-generated generated/<asm/cpufeaturemasks.h> header.
Thus they are no longer needed and can be removed.
None of the macros defined in {disabled,required}-features.h is used in tools,
delete them too.
Signed-off-by: Xin Li (Intel) <xin@zytor.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Link: https://lore.kernel.org/r/20250305184725.3341760-4-xin@zytor.com
---
arch/x86/include/asm/disabled-features.h | 167 +----------------
arch/x86/include/asm/required-features.h | 105 +----------
tools/arch/x86/include/asm/cpufeatures.h | 8 +-
tools/arch/x86/include/asm/disabled-features.h | 161 +---------------
tools/arch/x86/include/asm/required-features.h | 105 +----------
| 2 +-
6 files changed, 548 deletions(-)
delete mode 100644 arch/x86/include/asm/disabled-features.h
delete mode 100644 arch/x86/include/asm/required-features.h
delete mode 100644 tools/arch/x86/include/asm/disabled-features.h
delete mode 100644 tools/arch/x86/include/asm/required-features.h
diff --git a/arch/x86/include/asm/disabled-features.h b/arch/x86/include/asm/disabled-features.h
deleted file mode 100644
index be8c388..0000000
--- a/arch/x86/include/asm/disabled-features.h
+++ /dev/null
@@ -1,167 +0,0 @@
-#ifndef _ASM_X86_DISABLED_FEATURES_H
-#define _ASM_X86_DISABLED_FEATURES_H
-
-/* These features, although they might be available in a CPU
- * will not be used because the compile options to support
- * them are not present.
- *
- * This code allows them to be checked and disabled at
- * compile time without an explicit #ifdef. Use
- * cpu_feature_enabled().
- */
-
-#ifdef CONFIG_X86_UMIP
-# define DISABLE_UMIP 0
-#else
-# define DISABLE_UMIP (1<<(X86_FEATURE_UMIP & 31))
-#endif
-
-#ifdef CONFIG_X86_64
-# define DISABLE_VME (1<<(X86_FEATURE_VME & 31))
-# define DISABLE_K6_MTRR (1<<(X86_FEATURE_K6_MTRR & 31))
-# define DISABLE_CYRIX_ARR (1<<(X86_FEATURE_CYRIX_ARR & 31))
-# define DISABLE_CENTAUR_MCR (1<<(X86_FEATURE_CENTAUR_MCR & 31))
-# define DISABLE_PCID 0
-#else
-# define DISABLE_VME 0
-# define DISABLE_K6_MTRR 0
-# define DISABLE_CYRIX_ARR 0
-# define DISABLE_CENTAUR_MCR 0
-# define DISABLE_PCID (1<<(X86_FEATURE_PCID & 31))
-#endif /* CONFIG_X86_64 */
-
-#ifdef CONFIG_X86_INTEL_MEMORY_PROTECTION_KEYS
-# define DISABLE_PKU 0
-# define DISABLE_OSPKE 0
-#else
-# define DISABLE_PKU (1<<(X86_FEATURE_PKU & 31))
-# define DISABLE_OSPKE (1<<(X86_FEATURE_OSPKE & 31))
-#endif /* CONFIG_X86_INTEL_MEMORY_PROTECTION_KEYS */
-
-#ifdef CONFIG_X86_5LEVEL
-# define DISABLE_LA57 0
-#else
-# define DISABLE_LA57 (1<<(X86_FEATURE_LA57 & 31))
-#endif
-
-#ifdef CONFIG_MITIGATION_PAGE_TABLE_ISOLATION
-# define DISABLE_PTI 0
-#else
-# define DISABLE_PTI (1 << (X86_FEATURE_PTI & 31))
-#endif
-
-#ifdef CONFIG_MITIGATION_RETPOLINE
-# define DISABLE_RETPOLINE 0
-#else
-# define DISABLE_RETPOLINE ((1 << (X86_FEATURE_RETPOLINE & 31)) | \
- (1 << (X86_FEATURE_RETPOLINE_LFENCE & 31)))
-#endif
-
-#ifdef CONFIG_MITIGATION_RETHUNK
-# define DISABLE_RETHUNK 0
-#else
-# define DISABLE_RETHUNK (1 << (X86_FEATURE_RETHUNK & 31))
-#endif
-
-#ifdef CONFIG_MITIGATION_UNRET_ENTRY
-# define DISABLE_UNRET 0
-#else
-# define DISABLE_UNRET (1 << (X86_FEATURE_UNRET & 31))
-#endif
-
-#ifdef CONFIG_MITIGATION_CALL_DEPTH_TRACKING
-# define DISABLE_CALL_DEPTH_TRACKING 0
-#else
-# define DISABLE_CALL_DEPTH_TRACKING (1 << (X86_FEATURE_CALL_DEPTH & 31))
-#endif
-
-#ifdef CONFIG_ADDRESS_MASKING
-# define DISABLE_LAM 0
-#else
-# define DISABLE_LAM (1 << (X86_FEATURE_LAM & 31))
-#endif
-
-#ifdef CONFIG_INTEL_IOMMU_SVM
-# define DISABLE_ENQCMD 0
-#else
-# define DISABLE_ENQCMD (1 << (X86_FEATURE_ENQCMD & 31))
-#endif
-
-#ifdef CONFIG_X86_SGX
-# define DISABLE_SGX 0
-#else
-# define DISABLE_SGX (1 << (X86_FEATURE_SGX & 31))
-#endif
-
-#ifdef CONFIG_XEN_PV
-# define DISABLE_XENPV 0
-#else
-# define DISABLE_XENPV (1 << (X86_FEATURE_XENPV & 31))
-#endif
-
-#ifdef CONFIG_INTEL_TDX_GUEST
-# define DISABLE_TDX_GUEST 0
-#else
-# define DISABLE_TDX_GUEST (1 << (X86_FEATURE_TDX_GUEST & 31))
-#endif
-
-#ifdef CONFIG_X86_USER_SHADOW_STACK
-#define DISABLE_USER_SHSTK 0
-#else
-#define DISABLE_USER_SHSTK (1 << (X86_FEATURE_USER_SHSTK & 31))
-#endif
-
-#ifdef CONFIG_X86_KERNEL_IBT
-#define DISABLE_IBT 0
-#else
-#define DISABLE_IBT (1 << (X86_FEATURE_IBT & 31))
-#endif
-
-#ifdef CONFIG_X86_FRED
-# define DISABLE_FRED 0
-#else
-# define DISABLE_FRED (1 << (X86_FEATURE_FRED & 31))
-#endif
-
-#ifdef CONFIG_KVM_AMD_SEV
-#define DISABLE_SEV_SNP 0
-#else
-#define DISABLE_SEV_SNP (1 << (X86_FEATURE_SEV_SNP & 31))
-#endif
-
-#ifdef CONFIG_BROADCAST_TLB_FLUSH
-#define DISABLE_INVLPGB 0
-#else
-#define DISABLE_INVLPGB (1 << (X86_FEATURE_INVLPGB & 31))
-#endif
-
-/*
- * Make sure to add features to the correct mask
- */
-#define DISABLED_MASK0 (DISABLE_VME)
-#define DISABLED_MASK1 0
-#define DISABLED_MASK2 0
-#define DISABLED_MASK3 (DISABLE_CYRIX_ARR|DISABLE_CENTAUR_MCR|DISABLE_K6_MTRR)
-#define DISABLED_MASK4 (DISABLE_PCID)
-#define DISABLED_MASK5 0
-#define DISABLED_MASK6 0
-#define DISABLED_MASK7 (DISABLE_PTI)
-#define DISABLED_MASK8 (DISABLE_XENPV|DISABLE_TDX_GUEST)
-#define DISABLED_MASK9 (DISABLE_SGX)
-#define DISABLED_MASK10 0
-#define DISABLED_MASK11 (DISABLE_RETPOLINE|DISABLE_RETHUNK|DISABLE_UNRET| \
- DISABLE_CALL_DEPTH_TRACKING|DISABLE_USER_SHSTK)
-#define DISABLED_MASK12 (DISABLE_FRED|DISABLE_LAM)
-#define DISABLED_MASK13 (DISABLE_INVLPGB)
-#define DISABLED_MASK14 0
-#define DISABLED_MASK15 0
-#define DISABLED_MASK16 (DISABLE_PKU|DISABLE_OSPKE|DISABLE_LA57|DISABLE_UMIP| \
- DISABLE_ENQCMD)
-#define DISABLED_MASK17 0
-#define DISABLED_MASK18 (DISABLE_IBT)
-#define DISABLED_MASK19 (DISABLE_SEV_SNP)
-#define DISABLED_MASK20 0
-#define DISABLED_MASK21 0
-#define DISABLED_MASK_CHECK BUILD_BUG_ON_ZERO(NCAPINTS != 22)
-
-#endif /* _ASM_X86_DISABLED_FEATURES_H */
diff --git a/arch/x86/include/asm/required-features.h b/arch/x86/include/asm/required-features.h
deleted file mode 100644
index 0068133..0000000
--- a/arch/x86/include/asm/required-features.h
+++ /dev/null
@@ -1,105 +0,0 @@
-#ifndef _ASM_X86_REQUIRED_FEATURES_H
-#define _ASM_X86_REQUIRED_FEATURES_H
-
-/* Define minimum CPUID feature set for kernel These bits are checked
- really early to actually display a visible error message before the
- kernel dies. Make sure to assign features to the proper mask!
-
- Some requirements that are not in CPUID yet are also in the
- CONFIG_X86_MINIMUM_CPU_FAMILY which is checked too.
-
- The real information is in arch/x86/Kconfig.cpu, this just converts
- the CONFIGs into a bitmask */
-
-#ifndef CONFIG_MATH_EMULATION
-# define NEED_FPU (1<<(X86_FEATURE_FPU & 31))
-#else
-# define NEED_FPU 0
-#endif
-
-#if defined(CONFIG_X86_PAE) || defined(CONFIG_X86_64)
-# define NEED_PAE (1<<(X86_FEATURE_PAE & 31))
-#else
-# define NEED_PAE 0
-#endif
-
-#ifdef CONFIG_X86_CX8
-# define NEED_CX8 (1<<(X86_FEATURE_CX8 & 31))
-#else
-# define NEED_CX8 0
-#endif
-
-#if defined(CONFIG_X86_CMOV) || defined(CONFIG_X86_64)
-# define NEED_CMOV (1<<(X86_FEATURE_CMOV & 31))
-#else
-# define NEED_CMOV 0
-#endif
-
-# define NEED_3DNOW 0
-
-#if defined(CONFIG_X86_P6_NOP) || defined(CONFIG_X86_64)
-# define NEED_NOPL (1<<(X86_FEATURE_NOPL & 31))
-#else
-# define NEED_NOPL 0
-#endif
-
-#ifdef CONFIG_MATOM
-# define NEED_MOVBE (1<<(X86_FEATURE_MOVBE & 31))
-#else
-# define NEED_MOVBE 0
-#endif
-
-#ifdef CONFIG_X86_64
-#ifdef CONFIG_PARAVIRT_XXL
-/* Paravirtualized systems may not have PSE or PGE available */
-#define NEED_PSE 0
-#define NEED_PGE 0
-#else
-#define NEED_PSE (1<<(X86_FEATURE_PSE) & 31)
-#define NEED_PGE (1<<(X86_FEATURE_PGE) & 31)
-#endif
-#define NEED_MSR (1<<(X86_FEATURE_MSR & 31))
-#define NEED_FXSR (1<<(X86_FEATURE_FXSR & 31))
-#define NEED_XMM (1<<(X86_FEATURE_XMM & 31))
-#define NEED_XMM2 (1<<(X86_FEATURE_XMM2 & 31))
-#define NEED_LM (1<<(X86_FEATURE_LM & 31))
-#else
-#define NEED_PSE 0
-#define NEED_MSR 0
-#define NEED_PGE 0
-#define NEED_FXSR 0
-#define NEED_XMM 0
-#define NEED_XMM2 0
-#define NEED_LM 0
-#endif
-
-#define REQUIRED_MASK0 (NEED_FPU|NEED_PSE|NEED_MSR|NEED_PAE|\
- NEED_CX8|NEED_PGE|NEED_FXSR|NEED_CMOV|\
- NEED_XMM|NEED_XMM2)
-#define SSE_MASK (NEED_XMM|NEED_XMM2)
-
-#define REQUIRED_MASK1 (NEED_LM|NEED_3DNOW)
-
-#define REQUIRED_MASK2 0
-#define REQUIRED_MASK3 (NEED_NOPL)
-#define REQUIRED_MASK4 (NEED_MOVBE)
-#define REQUIRED_MASK5 0
-#define REQUIRED_MASK6 0
-#define REQUIRED_MASK7 0
-#define REQUIRED_MASK8 0
-#define REQUIRED_MASK9 0
-#define REQUIRED_MASK10 0
-#define REQUIRED_MASK11 0
-#define REQUIRED_MASK12 0
-#define REQUIRED_MASK13 0
-#define REQUIRED_MASK14 0
-#define REQUIRED_MASK15 0
-#define REQUIRED_MASK16 0
-#define REQUIRED_MASK17 0
-#define REQUIRED_MASK18 0
-#define REQUIRED_MASK19 0
-#define REQUIRED_MASK20 0
-#define REQUIRED_MASK21 0
-#define REQUIRED_MASK_CHECK BUILD_BUG_ON_ZERO(NCAPINTS != 22)
-
-#endif /* _ASM_X86_REQUIRED_FEATURES_H */
diff --git a/tools/arch/x86/include/asm/cpufeatures.h b/tools/arch/x86/include/asm/cpufeatures.h
index 17b6590..c691481 100644
--- a/tools/arch/x86/include/asm/cpufeatures.h
+++ b/tools/arch/x86/include/asm/cpufeatures.h
@@ -2,14 +2,6 @@
#ifndef _ASM_X86_CPUFEATURES_H
#define _ASM_X86_CPUFEATURES_H
-#ifndef _ASM_X86_REQUIRED_FEATURES_H
-#include <asm/required-features.h>
-#endif
-
-#ifndef _ASM_X86_DISABLED_FEATURES_H
-#include <asm/disabled-features.h>
-#endif
-
/*
* Defines x86 CPU feature bits
*/
diff --git a/tools/arch/x86/include/asm/disabled-features.h b/tools/arch/x86/include/asm/disabled-features.h
deleted file mode 100644
index c492bdc..0000000
--- a/tools/arch/x86/include/asm/disabled-features.h
+++ /dev/null
@@ -1,161 +0,0 @@
-#ifndef _ASM_X86_DISABLED_FEATURES_H
-#define _ASM_X86_DISABLED_FEATURES_H
-
-/* These features, although they might be available in a CPU
- * will not be used because the compile options to support
- * them are not present.
- *
- * This code allows them to be checked and disabled at
- * compile time without an explicit #ifdef. Use
- * cpu_feature_enabled().
- */
-
-#ifdef CONFIG_X86_UMIP
-# define DISABLE_UMIP 0
-#else
-# define DISABLE_UMIP (1<<(X86_FEATURE_UMIP & 31))
-#endif
-
-#ifdef CONFIG_X86_64
-# define DISABLE_VME (1<<(X86_FEATURE_VME & 31))
-# define DISABLE_K6_MTRR (1<<(X86_FEATURE_K6_MTRR & 31))
-# define DISABLE_CYRIX_ARR (1<<(X86_FEATURE_CYRIX_ARR & 31))
-# define DISABLE_CENTAUR_MCR (1<<(X86_FEATURE_CENTAUR_MCR & 31))
-# define DISABLE_PCID 0
-#else
-# define DISABLE_VME 0
-# define DISABLE_K6_MTRR 0
-# define DISABLE_CYRIX_ARR 0
-# define DISABLE_CENTAUR_MCR 0
-# define DISABLE_PCID (1<<(X86_FEATURE_PCID & 31))
-#endif /* CONFIG_X86_64 */
-
-#ifdef CONFIG_X86_INTEL_MEMORY_PROTECTION_KEYS
-# define DISABLE_PKU 0
-# define DISABLE_OSPKE 0
-#else
-# define DISABLE_PKU (1<<(X86_FEATURE_PKU & 31))
-# define DISABLE_OSPKE (1<<(X86_FEATURE_OSPKE & 31))
-#endif /* CONFIG_X86_INTEL_MEMORY_PROTECTION_KEYS */
-
-#ifdef CONFIG_X86_5LEVEL
-# define DISABLE_LA57 0
-#else
-# define DISABLE_LA57 (1<<(X86_FEATURE_LA57 & 31))
-#endif
-
-#ifdef CONFIG_MITIGATION_PAGE_TABLE_ISOLATION
-# define DISABLE_PTI 0
-#else
-# define DISABLE_PTI (1 << (X86_FEATURE_PTI & 31))
-#endif
-
-#ifdef CONFIG_MITIGATION_RETPOLINE
-# define DISABLE_RETPOLINE 0
-#else
-# define DISABLE_RETPOLINE ((1 << (X86_FEATURE_RETPOLINE & 31)) | \
- (1 << (X86_FEATURE_RETPOLINE_LFENCE & 31)))
-#endif
-
-#ifdef CONFIG_MITIGATION_RETHUNK
-# define DISABLE_RETHUNK 0
-#else
-# define DISABLE_RETHUNK (1 << (X86_FEATURE_RETHUNK & 31))
-#endif
-
-#ifdef CONFIG_MITIGATION_UNRET_ENTRY
-# define DISABLE_UNRET 0
-#else
-# define DISABLE_UNRET (1 << (X86_FEATURE_UNRET & 31))
-#endif
-
-#ifdef CONFIG_MITIGATION_CALL_DEPTH_TRACKING
-# define DISABLE_CALL_DEPTH_TRACKING 0
-#else
-# define DISABLE_CALL_DEPTH_TRACKING (1 << (X86_FEATURE_CALL_DEPTH & 31))
-#endif
-
-#ifdef CONFIG_ADDRESS_MASKING
-# define DISABLE_LAM 0
-#else
-# define DISABLE_LAM (1 << (X86_FEATURE_LAM & 31))
-#endif
-
-#ifdef CONFIG_INTEL_IOMMU_SVM
-# define DISABLE_ENQCMD 0
-#else
-# define DISABLE_ENQCMD (1 << (X86_FEATURE_ENQCMD & 31))
-#endif
-
-#ifdef CONFIG_X86_SGX
-# define DISABLE_SGX 0
-#else
-# define DISABLE_SGX (1 << (X86_FEATURE_SGX & 31))
-#endif
-
-#ifdef CONFIG_XEN_PV
-# define DISABLE_XENPV 0
-#else
-# define DISABLE_XENPV (1 << (X86_FEATURE_XENPV & 31))
-#endif
-
-#ifdef CONFIG_INTEL_TDX_GUEST
-# define DISABLE_TDX_GUEST 0
-#else
-# define DISABLE_TDX_GUEST (1 << (X86_FEATURE_TDX_GUEST & 31))
-#endif
-
-#ifdef CONFIG_X86_USER_SHADOW_STACK
-#define DISABLE_USER_SHSTK 0
-#else
-#define DISABLE_USER_SHSTK (1 << (X86_FEATURE_USER_SHSTK & 31))
-#endif
-
-#ifdef CONFIG_X86_KERNEL_IBT
-#define DISABLE_IBT 0
-#else
-#define DISABLE_IBT (1 << (X86_FEATURE_IBT & 31))
-#endif
-
-#ifdef CONFIG_X86_FRED
-# define DISABLE_FRED 0
-#else
-# define DISABLE_FRED (1 << (X86_FEATURE_FRED & 31))
-#endif
-
-#ifdef CONFIG_KVM_AMD_SEV
-#define DISABLE_SEV_SNP 0
-#else
-#define DISABLE_SEV_SNP (1 << (X86_FEATURE_SEV_SNP & 31))
-#endif
-
-/*
- * Make sure to add features to the correct mask
- */
-#define DISABLED_MASK0 (DISABLE_VME)
-#define DISABLED_MASK1 0
-#define DISABLED_MASK2 0
-#define DISABLED_MASK3 (DISABLE_CYRIX_ARR|DISABLE_CENTAUR_MCR|DISABLE_K6_MTRR)
-#define DISABLED_MASK4 (DISABLE_PCID)
-#define DISABLED_MASK5 0
-#define DISABLED_MASK6 0
-#define DISABLED_MASK7 (DISABLE_PTI)
-#define DISABLED_MASK8 (DISABLE_XENPV|DISABLE_TDX_GUEST)
-#define DISABLED_MASK9 (DISABLE_SGX)
-#define DISABLED_MASK10 0
-#define DISABLED_MASK11 (DISABLE_RETPOLINE|DISABLE_RETHUNK|DISABLE_UNRET| \
- DISABLE_CALL_DEPTH_TRACKING|DISABLE_USER_SHSTK)
-#define DISABLED_MASK12 (DISABLE_FRED|DISABLE_LAM)
-#define DISABLED_MASK13 0
-#define DISABLED_MASK14 0
-#define DISABLED_MASK15 0
-#define DISABLED_MASK16 (DISABLE_PKU|DISABLE_OSPKE|DISABLE_LA57|DISABLE_UMIP| \
- DISABLE_ENQCMD)
-#define DISABLED_MASK17 0
-#define DISABLED_MASK18 (DISABLE_IBT)
-#define DISABLED_MASK19 (DISABLE_SEV_SNP)
-#define DISABLED_MASK20 0
-#define DISABLED_MASK21 0
-#define DISABLED_MASK_CHECK BUILD_BUG_ON_ZERO(NCAPINTS != 22)
-
-#endif /* _ASM_X86_DISABLED_FEATURES_H */
diff --git a/tools/arch/x86/include/asm/required-features.h b/tools/arch/x86/include/asm/required-features.h
deleted file mode 100644
index 0068133..0000000
--- a/tools/arch/x86/include/asm/required-features.h
+++ /dev/null
@@ -1,105 +0,0 @@
-#ifndef _ASM_X86_REQUIRED_FEATURES_H
-#define _ASM_X86_REQUIRED_FEATURES_H
-
-/* Define minimum CPUID feature set for kernel These bits are checked
- really early to actually display a visible error message before the
- kernel dies. Make sure to assign features to the proper mask!
-
- Some requirements that are not in CPUID yet are also in the
- CONFIG_X86_MINIMUM_CPU_FAMILY which is checked too.
-
- The real information is in arch/x86/Kconfig.cpu, this just converts
- the CONFIGs into a bitmask */
-
-#ifndef CONFIG_MATH_EMULATION
-# define NEED_FPU (1<<(X86_FEATURE_FPU & 31))
-#else
-# define NEED_FPU 0
-#endif
-
-#if defined(CONFIG_X86_PAE) || defined(CONFIG_X86_64)
-# define NEED_PAE (1<<(X86_FEATURE_PAE & 31))
-#else
-# define NEED_PAE 0
-#endif
-
-#ifdef CONFIG_X86_CX8
-# define NEED_CX8 (1<<(X86_FEATURE_CX8 & 31))
-#else
-# define NEED_CX8 0
-#endif
-
-#if defined(CONFIG_X86_CMOV) || defined(CONFIG_X86_64)
-# define NEED_CMOV (1<<(X86_FEATURE_CMOV & 31))
-#else
-# define NEED_CMOV 0
-#endif
-
-# define NEED_3DNOW 0
-
-#if defined(CONFIG_X86_P6_NOP) || defined(CONFIG_X86_64)
-# define NEED_NOPL (1<<(X86_FEATURE_NOPL & 31))
-#else
-# define NEED_NOPL 0
-#endif
-
-#ifdef CONFIG_MATOM
-# define NEED_MOVBE (1<<(X86_FEATURE_MOVBE & 31))
-#else
-# define NEED_MOVBE 0
-#endif
-
-#ifdef CONFIG_X86_64
-#ifdef CONFIG_PARAVIRT_XXL
-/* Paravirtualized systems may not have PSE or PGE available */
-#define NEED_PSE 0
-#define NEED_PGE 0
-#else
-#define NEED_PSE (1<<(X86_FEATURE_PSE) & 31)
-#define NEED_PGE (1<<(X86_FEATURE_PGE) & 31)
-#endif
-#define NEED_MSR (1<<(X86_FEATURE_MSR & 31))
-#define NEED_FXSR (1<<(X86_FEATURE_FXSR & 31))
-#define NEED_XMM (1<<(X86_FEATURE_XMM & 31))
-#define NEED_XMM2 (1<<(X86_FEATURE_XMM2 & 31))
-#define NEED_LM (1<<(X86_FEATURE_LM & 31))
-#else
-#define NEED_PSE 0
-#define NEED_MSR 0
-#define NEED_PGE 0
-#define NEED_FXSR 0
-#define NEED_XMM 0
-#define NEED_XMM2 0
-#define NEED_LM 0
-#endif
-
-#define REQUIRED_MASK0 (NEED_FPU|NEED_PSE|NEED_MSR|NEED_PAE|\
- NEED_CX8|NEED_PGE|NEED_FXSR|NEED_CMOV|\
- NEED_XMM|NEED_XMM2)
-#define SSE_MASK (NEED_XMM|NEED_XMM2)
-
-#define REQUIRED_MASK1 (NEED_LM|NEED_3DNOW)
-
-#define REQUIRED_MASK2 0
-#define REQUIRED_MASK3 (NEED_NOPL)
-#define REQUIRED_MASK4 (NEED_MOVBE)
-#define REQUIRED_MASK5 0
-#define REQUIRED_MASK6 0
-#define REQUIRED_MASK7 0
-#define REQUIRED_MASK8 0
-#define REQUIRED_MASK9 0
-#define REQUIRED_MASK10 0
-#define REQUIRED_MASK11 0
-#define REQUIRED_MASK12 0
-#define REQUIRED_MASK13 0
-#define REQUIRED_MASK14 0
-#define REQUIRED_MASK15 0
-#define REQUIRED_MASK16 0
-#define REQUIRED_MASK17 0
-#define REQUIRED_MASK18 0
-#define REQUIRED_MASK19 0
-#define REQUIRED_MASK20 0
-#define REQUIRED_MASK21 0
-#define REQUIRED_MASK_CHECK BUILD_BUG_ON_ZERO(NCAPINTS != 22)
-
-#endif /* _ASM_X86_REQUIRED_FEATURES_H */
--git a/tools/perf/check-headers.sh b/tools/perf/check-headers.sh
index d3c6e10..a4499e5 100755
--- a/tools/perf/check-headers.sh
+++ b/tools/perf/check-headers.sh
@@ -26,8 +26,6 @@ FILES=(
"include/linux/hash.h"
"include/linux/list-sort.h"
"include/uapi/linux/hw_breakpoint.h"
- "arch/x86/include/asm/disabled-features.h"
- "arch/x86/include/asm/required-features.h"
"arch/x86/include/asm/cpufeatures.h"
"arch/x86/include/asm/inat_types.h"
"arch/x86/include/asm/emulate_prefix.h"
^ permalink raw reply related [flat|nested] 20+ messages in thread
* RE: [tip: x86/core] x86/cpufeatures: Generate the <asm/cpufeaturemasks.h> header based on build config
2025-03-19 11:03 ` [tip: x86/core] " tip-bot2 for H. Peter Anvin (Intel)
@ 2025-03-20 16:23 ` Michael Kelley
2025-03-20 16:56 ` Linus Torvalds
0 siblings, 1 reply; 20+ messages in thread
From: Michael Kelley @ 2025-03-20 16:23 UTC (permalink / raw)
To: H. Peter Anvin (Intel), Xin Li (Intel), Borislav Petkov (AMD),
Ingo Molnar, Nikolay Borisov, Linus Torvalds, x86@kernel.org
Cc: linux-kernel@vger.kernel.org
From: tip-bot2@linutronix.de <tip-bot2@linutronix.de> Sent: Wednesday, March 19, 2025 4:04 AM
>
> The following commit has been merged into the x86/core branch of tip:
>
> Commit-ID: 841326332bcb13ae4e6cd456350bf566a402b45e
> Gitweb: https://lore.kernel.org/all/20250305184725.3341760-3-xin@zytor.com/
> Author: H. Peter Anvin (Intel) <hpa@zytor.com>
> AuthorDate: Wed, 05 Mar 2025 10:47:22 -08:00
> Committer: Ingo Molnar <mingo@kernel.org>
> CommitterDate: Wed, 19 Mar 2025 11:15:11 +01:00
>
> x86/cpufeatures: Generate the <asm/cpufeaturemasks.h> header based on build config
This commit is producing a subtle change in build behavior, as seen in linux-next.
In the current behavior, assume the kernel has been fully built. Then if nothing
is changed but the modified time on the .config file (and the contents of .config
are unchanged), a new build runs
SYNC include/config/auto.conf.cmd
and figures out that nothing has changed, so it does nothing.
With this commit, changing the modified time on .config causes cpufeaturemasks.h
to be rebuilt, and then all dependencies on cpufeaturemasks.h are also rebuilt. It
doesn't figure out that nothing has changed in .config. A fair amount of
unnecessary rebuilding is done.
I'm seeing this changed behavior specifically with the make-kpkg script on
Ubuntu 20.04. It's not clear why make-kpkg is updating the modified time
on .config, but prior to this commit, that update had no negative effect.
I don't know if anything can be done about this change in behavior, as
Makefiles and build dependencies aren't my expertise. But I wanted to
point out what's happening.
Michael
>
> Introduce an AWK script to auto-generate the <asm/cpufeaturemasks.h> header
> with required and disabled feature masks based on <asm/cpufeatures.h>
> and the current build config.
>
> Thus for any CPU feature with a build config, e.g., X86_FRED, simply add:
>
> config X86_DISABLED_FEATURE_FRED
> def_bool y
> depends on !X86_FRED
>
> to arch/x86/Kconfig.cpufeatures, instead of adding a conditional CPU
> feature disable flag, e.g., DISABLE_FRED.
>
> Lastly, the generated required and disabled feature masks will be added to
> their corresponding feature masks for this particular compile-time
> configuration.
>
> [ Xin: build integration improvements ]
> [ mingo: Improved changelog and comments ]
>
> Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
> Signed-off-by: Xin Li (Intel) <xin@zytor.com>
> Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
> Signed-off-by: Ingo Molnar <mingo@kernel.org>
> Reviewed-by: Nikolay Borisov <nik.borisov@suse.com>
> Cc: Linus Torvalds <torvalds@linux-foundation.org>
> Link:
> https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flore.kernel.org%2
> Fr%2F20250305184725.3341760-3-
> xin%40zytor.com&data=05%7C02%7C%7C6243cf4a3cb84dbe135208dd66d70d34%7C84
> df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C638779796029571293%7CUnknown%
> 7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMi
> IsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=TSpia2XulsyZ%2BwNqB
> 2tdp66Z4hbaojEHgZ0x%2BUi2OF8%3D&reserved=0
> ---
> arch/x86/Makefile | 15 +++++-
> arch/x86/boot/cpucheck.c | 3 +-
> arch/x86/boot/cpuflags.c | 1 +-
> arch/x86/boot/mkcpustr.c | 3 +-
> arch/x86/include/asm/Kbuild | 1 +-
> arch/x86/include/asm/cpufeature.h | 1 +-
> arch/x86/include/asm/cpufeatures.h | 8 +---
> arch/x86/kernel/verify_cpu.S | 4 +-
> arch/x86/tools/cpufeaturemasks.awk | 81 +++++++++++++++++++++++++++++-
> 9 files changed, 105 insertions(+), 12 deletions(-)
> create mode 100755 arch/x86/tools/cpufeaturemasks.awk
>
> diff --git a/arch/x86/Makefile b/arch/x86/Makefile
> index 6784129..a607769 100644
> --- a/arch/x86/Makefile
> +++ b/arch/x86/Makefile
> @@ -269,6 +269,21 @@ archheaders:
> $(Q)$(MAKE) $(build)=arch/x86/entry/syscalls all
>
> ###
> +# <asm/cpufeaturemasks.h> header generation
> +
> +cpufeaturemasks.hdr := arch/x86/include/generated/asm/cpufeaturemasks.h
> +cpufeaturemasks.awk := $(srctree)/arch/x86/tools/cpufeaturemasks.awk
> +cpufeatures_hdr := $(srctree)/arch/x86/include/asm/cpufeatures.h
> +targets += $(cpufeaturemasks.hdr)
> +quiet_cmd_gen_featuremasks = GEN $@
> + cmd_gen_featuremasks = $(AWK) -f $(cpufeaturemasks.awk) $(cpufeatures_hdr)
> $(KCONFIG_CONFIG) > $@
> +
> +$(cpufeaturemasks.hdr): $(cpufeaturemasks.awk) $(cpufeatures_hdr)
> $(KCONFIG_CONFIG) FORCE
> + $(shell mkdir -p $(dir $@))
> + $(call if_changed,gen_featuremasks)
> +archprepare: $(cpufeaturemasks.hdr)
> +
> +###
> # Kernel objects
>
> libs-y += arch/x86/lib/
> diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
> index 0aae4d4..f82de8d 100644
> --- a/arch/x86/boot/cpucheck.c
> +++ b/arch/x86/boot/cpucheck.c
> @@ -22,10 +22,11 @@
> # include "boot.h"
> #endif
> #include <linux/types.h>
> +#include <asm/cpufeaturemasks.h>
> #include <asm/intel-family.h>
> #include <asm/processor-flags.h>
> -#include <asm/required-features.h>
> #include <asm/msr-index.h>
> +
> #include "string.h"
> #include "msr.h"
>
> diff --git a/arch/x86/boot/cpuflags.c b/arch/x86/boot/cpuflags.c
> index d75237b..0cabdac 100644
> --- a/arch/x86/boot/cpuflags.c
> +++ b/arch/x86/boot/cpuflags.c
> @@ -3,7 +3,6 @@
> #include "bitops.h"
>
> #include <asm/processor-flags.h>
> -#include <asm/required-features.h>
> #include <asm/msr-index.h>
> #include "cpuflags.h"
>
> diff --git a/arch/x86/boot/mkcpustr.c b/arch/x86/boot/mkcpustr.c
> index da0ccc5..22d730b 100644
> --- a/arch/x86/boot/mkcpustr.c
> +++ b/arch/x86/boot/mkcpustr.c
> @@ -12,8 +12,6 @@
>
> #include <stdio.h>
>
> -#include "../include/asm/required-features.h"
> -#include "../include/asm/disabled-features.h"
> #include "../include/asm/cpufeatures.h"
> #include "../include/asm/vmxfeatures.h"
> #include "../kernel/cpu/capflags.c"
> @@ -23,6 +21,7 @@ int main(void)
> int i, j;
> const char *str;
>
> + printf("#include <asm/cpufeaturemasks.h>\n\n");
> printf("static const char x86_cap_strs[] =\n");
>
> for (i = 0; i < NCAPINTS; i++) {
> diff --git a/arch/x86/include/asm/Kbuild b/arch/x86/include/asm/Kbuild
> index 58f4dde..4566000 100644
> --- a/arch/x86/include/asm/Kbuild
> +++ b/arch/x86/include/asm/Kbuild
> @@ -8,6 +8,7 @@ generated-y += syscalls_x32.h
> generated-y += unistd_32_ia32.h
> generated-y += unistd_64_x32.h
> generated-y += xen-hypercalls.h
> +generated-y += cpufeaturemasks.h
>
> generic-y += early_ioremap.h
> generic-y += fprobe.h
> diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
> index e955da3..d54db88 100644
> --- a/arch/x86/include/asm/cpufeature.h
> +++ b/arch/x86/include/asm/cpufeature.h
> @@ -9,6 +9,7 @@
> #include <asm/asm.h>
> #include <linux/bitops.h>
> #include <asm/alternative.h>
> +#include <asm/cpufeaturemasks.h>
>
> enum cpuid_leafs
> {
> diff --git a/arch/x86/include/asm/cpufeatures.h b/arch/x86/include/asm/cpufeatures.h
> index 8770dc1..c0462be 100644
> --- a/arch/x86/include/asm/cpufeatures.h
> +++ b/arch/x86/include/asm/cpufeatures.h
> @@ -2,14 +2,6 @@
> #ifndef _ASM_X86_CPUFEATURES_H
> #define _ASM_X86_CPUFEATURES_H
>
> -#ifndef _ASM_X86_REQUIRED_FEATURES_H
> -#include <asm/required-features.h>
> -#endif
> -
> -#ifndef _ASM_X86_DISABLED_FEATURES_H
> -#include <asm/disabled-features.h>
> -#endif
> -
> /*
> * Defines x86 CPU feature bits
> */
> diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
> index 1258a58..37ad437 100644
> --- a/arch/x86/kernel/verify_cpu.S
> +++ b/arch/x86/kernel/verify_cpu.S
> @@ -29,8 +29,12 @@
> */
>
> #include <asm/cpufeatures.h>
> +#include <asm/cpufeaturemasks.h>
> #include <asm/msr-index.h>
>
> +#define SSE_MASK \
> + (REQUIRED_MASK0 & ((1<<(X86_FEATURE_XMM & 31)) |
> (1<<(X86_FEATURE_XMM2 & 31))))
> +
> SYM_FUNC_START_LOCAL(verify_cpu)
> pushf # Save caller passed flags
> push $0 # Kill any dangerous flags
> diff --git a/arch/x86/tools/cpufeaturemasks.awk
> b/arch/x86/tools/cpufeaturemasks.awk
> new file mode 100755
> index 0000000..59757ca
> --- /dev/null
> +++ b/arch/x86/tools/cpufeaturemasks.awk
> @@ -0,0 +1,81 @@
> +#!/usr/bin/awk
> +#
> +# Convert cpufeatures.h to a list of compile-time masks
> +# Note: this blithely assumes that each word has at least one
> +# feature defined in it; if not, something else is wrong!
> +#
> +
> +BEGIN {
> + printf "#ifndef _ASM_X86_CPUFEATUREMASKS_H\n";
> + printf "#define _ASM_X86_CPUFEATUREMASKS_H\n\n";
> +
> + file = 0
> +}
> +
> +FNR == 1 {
> + ++file;
> +
> + # arch/x86/include/asm/cpufeatures.h
> + if (file == 1)
> + FS = "[ \t()*+]+";
> +
> + # .config
> + if (file == 2)
> + FS = "=";
> +}
> +
> +# Create a dictionary of sorts, containing all defined feature bits
> +file == 1 && $1 ~ /^#define$/ && $2 ~ /^X86_FEATURE_/ {
> + nfeat = $3 * $4 + $5;
> + feat = $2;
> + sub(/^X86_FEATURE_/, "", feat);
> + feats[nfeat] = feat;
> +}
> +file == 1 && $1 ~ /^#define$/ && $2 == "NCAPINTS" {
> + ncapints = int($3);
> +}
> +
> +# Create a dictionary featstat[REQUIRED|DISABLED, FEATURE_NAME] = on | off
> +file == 2 && $1 ~ /^CONFIG_X86_(REQUIRED|DISABLED)_FEATURE_/ {
> + on = ($2 == "y");
> + if (split($1, fs, "CONFIG_X86_|_FEATURE_") == 3)
> + featstat[fs[2], fs[3]] = on;
> +}
> +
> +END {
> + sets[1] = "REQUIRED";
> + sets[2] = "DISABLED";
> +
> + for (ns in sets) {
> + s = sets[ns];
> +
> + printf "/*\n";
> + printf " * %s features:\n", s;
> + printf " *\n";
> + fstr = "";
> + for (i = 0; i < ncapints; i++) {
> + mask = 0;
> + for (j = 0; j < 32; j++) {
> + feat = feats[i*32 + j];
> + if (featstat[s, feat]) {
> + nfstr = fstr " " feat;
> + if (length(nfstr) > 72) {
> + printf " * %s\n", fstr;
> + nfstr = " " feat;
> + }
> + fstr = nfstr;
> + mask += (2 ^ j);
> + }
> + }
> + masks[i] = mask;
> + }
> + printf " * %s\n */\n", fstr;
> +
> + for (i = 0; i < ncapints; i++)
> + printf "#define %s_MASK%d\t0x%08xU\n", s, i, masks[i];
> +
> + printf "#define %s_MASK_CHECK BUILD_BUG_ON_ZERO(NCAPINTS !=
> %d)\n\n", s, ncapints;
> + }
> +
> + printf "#endif /* _ASM_X86_CPUFEATUREMASKS_H */\n";
> +}
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [tip: x86/core] x86/cpufeatures: Generate the <asm/cpufeaturemasks.h> header based on build config
2025-03-20 16:23 ` Michael Kelley
@ 2025-03-20 16:56 ` Linus Torvalds
2025-03-23 18:06 ` Michael Kelley
0 siblings, 1 reply; 20+ messages in thread
From: Linus Torvalds @ 2025-03-20 16:56 UTC (permalink / raw)
To: Michael Kelley
Cc: H. Peter Anvin (Intel), Xin Li (Intel), Borislav Petkov (AMD),
Ingo Molnar, Nikolay Borisov, x86@kernel.org,
linux-kernel@vger.kernel.org
On Thu, 20 Mar 2025 at 09:23, Michael Kelley <mhklinux@outlook.com> wrote:
>
> With this commit, changing the modified time on .config causes cpufeaturemasks.h
> to be rebuilt, and then all dependencies on cpufeaturemasks.h are also rebuilt. It
> doesn't figure out that nothing has changed in .config. A fair amount of
> unnecessary rebuilding is done.
Hmm. Normally it is the tools that *create* the config file that
should notice that it hasn't changed, and not write a new one.
See conf_write() in scripts/kconfig/confdata.c for the particular case
of the regular "make *config*'
> I'm seeing this changed behavior specifically with the make-kpkg script on
> Ubuntu 20.04. It's not clear why make-kpkg is updating the modified time
> on .config, but prior to this commit, that update had no negative effect.
It sounds like the make-kpkg script should probably be fixed to not
overwrite the config file unconditionally, and do that "make
oldconfig" and friends do, which is to notice when it hasn't changed
and leave it alone.
Linus
^ permalink raw reply [flat|nested] 20+ messages in thread
* RE: [tip: x86/core] x86/cpufeatures: Generate the <asm/cpufeaturemasks.h> header based on build config
2025-03-20 16:56 ` Linus Torvalds
@ 2025-03-23 18:06 ` Michael Kelley
2025-03-28 23:23 ` Jakub Kicinski
0 siblings, 1 reply; 20+ messages in thread
From: Michael Kelley @ 2025-03-23 18:06 UTC (permalink / raw)
To: Linus Torvalds
Cc: H. Peter Anvin (Intel), Xin Li (Intel), Borislav Petkov (AMD),
Ingo Molnar, Nikolay Borisov, x86@kernel.org,
linux-kernel@vger.kernel.org
From: Linus Torvalds <torvalds@linux-foundation.org> Sent: Thursday, March 20, 2025 9:56 AM
>
> On Thu, 20 Mar 2025 at 09:23, Michael Kelley <mhklinux@outlook.com> wrote:
> >
> > With this commit, changing the modified time on .config causes cpufeaturemasks.h
> > to be rebuilt, and then all dependencies on cpufeaturemasks.h are also rebuilt. It
> > doesn't figure out that nothing has changed in .config. A fair amount of
> > unnecessary rebuilding is done.
>
> Hmm. Normally it is the tools that *create* the config file that
> should notice that it hasn't changed, and not write a new one.
>
> See conf_write() in scripts/kconfig/confdata.c for the particular case
> of the regular "make *config*'
>
> > I'm seeing this changed behavior specifically with the make-kpkg script on
> > Ubuntu 20.04. It's not clear why make-kpkg is updating the modified time
> > on .config, but prior to this commit, that update had no negative effect.
>
> It sounds like the make-kpkg script should probably be fixed to not
> overwrite the config file unconditionally, and do that "make
> oldconfig" and friends do, which is to notice when it hasn't changed
> and leave it alone.
>
For the record, the problem with make-kpkg is that it does "make syncconfig"
multiple times in prepping to build, sometimes passing environment
variable ARCH=x86 and sometimes ARCH=x86_64. scripts/kconfig/conf uses
that environment variable to decorate the header of the generated .config
file, and to force a rebuild in include/config/auto.conf.cmd if the value changes.
So flipping between two different values causes a "new" .config to be
generated even though nothing of substance has changed.
I hacked the make-kpkg scripts to consistently use ARCH=x86 and that
solves the problem. But this is a private hack as make-kpkg hasn't been
updated in years and is no longer supported. In Ubuntu releases, it is
deprecated after 20.04.
Michael
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [tip: x86/core] x86/cpufeatures: Generate the <asm/cpufeaturemasks.h> header based on build config
2025-03-23 18:06 ` Michael Kelley
@ 2025-03-28 23:23 ` Jakub Kicinski
2025-03-29 0:14 ` Linus Torvalds
0 siblings, 1 reply; 20+ messages in thread
From: Jakub Kicinski @ 2025-03-28 23:23 UTC (permalink / raw)
To: H. Peter Anvin (Intel)
Cc: Michael Kelley, Linus Torvalds, Xin Li (Intel),
Borislav Petkov (AMD), Ingo Molnar, Nikolay Borisov,
x86@kernel.org, linux-kernel@vger.kernel.org
On Sun, 23 Mar 2025 18:06:07 +0000 Michael Kelley wrote:
> > > With this commit, changing the modified time on .config causes cpufeaturemasks.h
> > > to be rebuilt, and then all dependencies on cpufeaturemasks.h are also rebuilt. It
> > > doesn't figure out that nothing has changed in .config. A fair amount of
> > > unnecessary rebuilding is done.
> >
> > Hmm. Normally it is the tools that *create* the config file that
> > should notice that it hasn't changed, and not write a new one.
> >
> > See conf_write() in scripts/kconfig/confdata.c for the particular case
> > of the regular "make *config*'
> >
> > > I'm seeing this changed behavior specifically with the make-kpkg script on
> > > Ubuntu 20.04. It's not clear why make-kpkg is updating the modified time
> > > on .config, but prior to this commit, that update had no negative effect.
> >
> > It sounds like the make-kpkg script should probably be fixed to not
> > overwrite the config file unconditionally, and do that "make
> > oldconfig" and friends do, which is to notice when it hasn't changed
> > and leave it alone.
> >
>
> For the record, the problem with make-kpkg is that it does "make syncconfig"
> multiple times in prepping to build, sometimes passing environment
> variable ARCH=x86 and sometimes ARCH=x86_64. scripts/kconfig/conf uses
> that environment variable to decorate the header of the generated .config
> file, and to force a rebuild in include/config/auto.conf.cmd if the value changes.
> So flipping between two different values causes a "new" .config to be
> generated even though nothing of substance has changed.
>
> I hacked the make-kpkg scripts to consistently use ARCH=x86 and that
> solves the problem. But this is a private hack as make-kpkg hasn't been
> updated in years and is no longer supported. In Ubuntu releases, it is
> deprecated after 20.04.
FWIW this also makes netdev CI melt down. Combination of allmodconfig
insisting on WERROR, us insisting on W=1, and this change insisting on
full kernel rebuild every time .config is touched :( IOW we do:
make allmodconfig
./scripts/config -d werror
make -j W=1
Could a hack like this fly? I don't see an easy way out ..
diff --git a/arch/x86/Makefile b/arch/x86/Makefile
index a607769a25af..35401572d039 100644
--- a/arch/x86/Makefile
+++ b/arch/x86/Makefile
@@ -276,7 +276,9 @@ cpufeaturemasks.awk := $(srctree)/arch/x86/tools/cpufeaturemasks.awk
cpufeatures_hdr := $(srctree)/arch/x86/include/asm/cpufeatures.h
targets += $(cpufeaturemasks.hdr)
quiet_cmd_gen_featuremasks = GEN $@
- cmd_gen_featuremasks = $(AWK) -f $(cpufeaturemasks.awk) $(cpufeatures_hdr) $(KCONFIG_CONFIG) > $@
+ cmd_gen_featuremasks = $(AWK) -f $(cpufeaturemasks.awk) $(cpufeatures_hdr) $(KCONFIG_CONFIG) > $@.new; \
+ if [ -e $@ ] && cmp -s $@ $@.new; then rm $@.new; \
+ else mv $@.new $@; fi
$(cpufeaturemasks.hdr): $(cpufeaturemasks.awk) $(cpufeatures_hdr) $(KCONFIG_CONFIG) FORCE
$(shell mkdir -p $(dir $@))
^ permalink raw reply related [flat|nested] 20+ messages in thread
* Re: [tip: x86/core] x86/cpufeatures: Generate the <asm/cpufeaturemasks.h> header based on build config
2025-03-28 23:23 ` Jakub Kicinski
@ 2025-03-29 0:14 ` Linus Torvalds
2025-03-29 0:22 ` Linus Torvalds
2025-03-29 0:56 ` [tip: x86/core] x86/cpufeatures: Generate the <asm/cpufeaturemasks.h> header based on build config H. Peter Anvin
0 siblings, 2 replies; 20+ messages in thread
From: Linus Torvalds @ 2025-03-29 0:14 UTC (permalink / raw)
To: Jakub Kicinski
Cc: H. Peter Anvin (Intel), Michael Kelley, Xin Li (Intel),
Borislav Petkov (AMD), Ingo Molnar, Nikolay Borisov,
x86@kernel.org, linux-kernel@vger.kernel.org
On Fri, 28 Mar 2025 at 16:23, Jakub Kicinski <kuba@kernel.org> wrote:
>
> FWIW this also makes netdev CI melt down. Combination of allmodconfig
> insisting on WERROR, us insisting on W=1, and this change insisting on
> full kernel rebuild every time .config is touched :( IOW we do:
>
> make allmodconfig
> ./scripts/config -d werror
> make -j W=1
>
> Could a hack like this fly? I don't see an easy way out ..
Ok, clearly we need something like this.
That said, your patch makes my skin crawl a bit. Not because it's
wrong, but because it really makes me think "why don't we have this as
part of our normal "cmd_gen_" infrastructure?
In fact, we *do* have something like that for our infrastructure: it's
the 'filechk' macro.
So I think the real fix is something like this ENTIRELY UNTESTED
patch. Whitespace-damaged again to make sure people don't apply this
mindlessly, it needs more thought:
arch/x86/Makefile | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/arch/x86/Makefile b/arch/x86/Makefile
index 0fc7e8fd1a2e..769b29bf26ba 100644
--- a/arch/x86/Makefile
+++ b/arch/x86/Makefile
@@ -278,11 +278,11 @@ cpufeaturemasks.awk :=
$(srctree)/arch/x86/tools/cpufeaturemasks.awk
cpufeatures_hdr := $(srctree)/arch/x86/include/asm/cpufeatures.h
targets += $(cpufeaturemasks.hdr)
quiet_cmd_gen_featuremasks = GEN $@
- cmd_gen_featuremasks = $(AWK) -f $(cpufeaturemasks.awk)
$(cpufeatures_hdr) $(KCONFIG_CONFIG) > $@
+ filechk_featuremasks = $(AWK) -f $(cpufeaturemasks.awk)
$(cpufeatures_hdr) $(KCONFIG_CONFIG)
$(cpufeaturemasks.hdr): $(cpufeaturemasks.awk) $(cpufeatures_hdr)
$(KCONFIG_CONFIG) FORCE
$(shell mkdir -p $(dir $@))
- $(call if_changed,gen_featuremasks)
+ $(call filechk,featuremasks)
archprepare: $(cpufeaturemasks.hdr)
###
does something like that work? (And really: note the "something like
that" part, this may be *entirely* broken)
Linus
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [tip: x86/core] x86/cpufeatures: Generate the <asm/cpufeaturemasks.h> header based on build config
2025-03-29 0:14 ` Linus Torvalds
@ 2025-03-29 0:22 ` Linus Torvalds
2025-03-29 0:56 ` Jakub Kicinski
2025-04-01 7:00 ` [PATCH] x86: don't re-generate cpufeaturemasks.h so eagerly Ingo Molnar
2025-03-29 0:56 ` [tip: x86/core] x86/cpufeatures: Generate the <asm/cpufeaturemasks.h> header based on build config H. Peter Anvin
1 sibling, 2 replies; 20+ messages in thread
From: Linus Torvalds @ 2025-03-29 0:22 UTC (permalink / raw)
To: Jakub Kicinski, Masahiro Yamada
Cc: H. Peter Anvin (Intel), Michael Kelley, Xin Li (Intel),
Borislav Petkov (AMD), Ingo Molnar, Nikolay Borisov,
x86@kernel.org, linux-kernel@vger.kernel.org
On Fri, 28 Mar 2025 at 17:14, Linus Torvalds
<torvalds@linux-foundation.org> wrote:
>
> So I think the real fix is something like this ENTIRELY UNTESTED
> patch. Whitespace-damaged again to make sure people don't apply this
> mindlessly, it needs more thought:
.. and that ended up being even more whitespace-damaged than I meant
to make it, because it also line-wrapped.
Oh well. Not pretty, but I hope people still get the idea.
And I just actually tried doing a build after touching the .config
file, and it did seem to work.
But since I had _also_ messed with the config file on purpose earlier,
I'm not sure I'm actually testing the thing the networking builds
trigger. So I might be entirely missing something.
Adding Masahiro to the cc, so that somebody competent can actually
check my thinking.
Masahiro, see the complaint (and my reply) in
https://lore.kernel.org/all/20250328162311.08134fa6@kernel.org/
for background...
Linus
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [tip: x86/core] x86/cpufeatures: Generate the <asm/cpufeaturemasks.h> header based on build config
2025-03-29 0:22 ` Linus Torvalds
@ 2025-03-29 0:56 ` Jakub Kicinski
2025-04-01 7:00 ` [PATCH] x86: don't re-generate cpufeaturemasks.h so eagerly Ingo Molnar
1 sibling, 0 replies; 20+ messages in thread
From: Jakub Kicinski @ 2025-03-29 0:56 UTC (permalink / raw)
To: Linus Torvalds
Cc: Masahiro Yamada, H. Peter Anvin (Intel), Michael Kelley,
Xin Li (Intel), Borislav Petkov (AMD), Ingo Molnar,
Nikolay Borisov, x86@kernel.org, linux-kernel@vger.kernel.org
On Fri, 28 Mar 2025 17:22:03 -0700 Linus Torvalds wrote:
> > So I think the real fix is something like this ENTIRELY UNTESTED
> > patch. Whitespace-damaged again to make sure people don't apply this
> > mindlessly, it needs more thought:
>
> .. and that ended up being even more whitespace-damaged than I meant
> to make it, because it also line-wrapped.
>
> Oh well. Not pretty, but I hope people still get the idea.
>
> And I just actually tried doing a build after touching the .config
> file, and it did seem to work.
Excellent, can confirm that it works for me, too!
Thanks!!
> But since I had _also_ messed with the config file on purpose earlier,
> I'm not sure I'm actually testing the thing the networking builds
> trigger. So I might be entirely missing something.
FWIW the exact commands our build script uses are:
make W=1 LLVM=1 O=build_allmodconfig_cl -j 6 allmodconfig
./scripts/config --file build_allmodconfig_cl/.config -d werror -d kvm_werror -d drm_werror
make W=1 LLVM=1 O=build_allmodconfig_cl -j 6
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [tip: x86/core] x86/cpufeatures: Generate the <asm/cpufeaturemasks.h> header based on build config
2025-03-29 0:14 ` Linus Torvalds
2025-03-29 0:22 ` Linus Torvalds
@ 2025-03-29 0:56 ` H. Peter Anvin
1 sibling, 0 replies; 20+ messages in thread
From: H. Peter Anvin @ 2025-03-29 0:56 UTC (permalink / raw)
To: Linus Torvalds, Jakub Kicinski
Cc: Michael Kelley, Xin Li (Intel), Borislav Petkov (AMD),
Ingo Molnar, Nikolay Borisov, x86@kernel.org,
linux-kernel@vger.kernel.org
On March 28, 2025 5:14:25 PM PDT, Linus Torvalds <torvalds@linux-foundation.org> wrote:
>On Fri, 28 Mar 2025 at 16:23, Jakub Kicinski <kuba@kernel.org> wrote:
>>
>> FWIW this also makes netdev CI melt down. Combination of allmodconfig
>> insisting on WERROR, us insisting on W=1, and this change insisting on
>> full kernel rebuild every time .config is touched :( IOW we do:
>>
>> make allmodconfig
>> ./scripts/config -d werror
>> make -j W=1
>>
>> Could a hack like this fly? I don't see an easy way out ..
>
>Ok, clearly we need something like this.
>
>That said, your patch makes my skin crawl a bit. Not because it's
>wrong, but because it really makes me think "why don't we have this as
>part of our normal "cmd_gen_" infrastructure?
>
>In fact, we *do* have something like that for our infrastructure: it's
>the 'filechk' macro.
>
>So I think the real fix is something like this ENTIRELY UNTESTED
>patch. Whitespace-damaged again to make sure people don't apply this
>mindlessly, it needs more thought:
>
> arch/x86/Makefile | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/arch/x86/Makefile b/arch/x86/Makefile
> index 0fc7e8fd1a2e..769b29bf26ba 100644
> --- a/arch/x86/Makefile
> +++ b/arch/x86/Makefile
> @@ -278,11 +278,11 @@ cpufeaturemasks.awk :=
>$(srctree)/arch/x86/tools/cpufeaturemasks.awk
> cpufeatures_hdr := $(srctree)/arch/x86/include/asm/cpufeatures.h
> targets += $(cpufeaturemasks.hdr)
> quiet_cmd_gen_featuremasks = GEN $@
> - cmd_gen_featuremasks = $(AWK) -f $(cpufeaturemasks.awk)
>$(cpufeatures_hdr) $(KCONFIG_CONFIG) > $@
> + filechk_featuremasks = $(AWK) -f $(cpufeaturemasks.awk)
>$(cpufeatures_hdr) $(KCONFIG_CONFIG)
>
> $(cpufeaturemasks.hdr): $(cpufeaturemasks.awk) $(cpufeatures_hdr)
>$(KCONFIG_CONFIG) FORCE
> $(shell mkdir -p $(dir $@))
> - $(call if_changed,gen_featuremasks)
> + $(call filechk,featuremasks)
> archprepare: $(cpufeaturemasks.hdr)
>
> ###
>
>does something like that work? (And really: note the "something like
>that" part, this may be *entirely* broken)
>
> Linus
This also points out a need here: the header generator output probably should suffer replace-if-changed. Too bad we have to use such primitive tools :(
^ permalink raw reply [flat|nested] 20+ messages in thread
* [PATCH] x86: don't re-generate cpufeaturemasks.h so eagerly
2025-03-29 0:22 ` Linus Torvalds
2025-03-29 0:56 ` Jakub Kicinski
@ 2025-04-01 7:00 ` Ingo Molnar
1 sibling, 0 replies; 20+ messages in thread
From: Ingo Molnar @ 2025-04-01 7:00 UTC (permalink / raw)
To: Linus Torvalds
Cc: Jakub Kicinski, Masahiro Yamada, H. Peter Anvin (Intel),
Michael Kelley, Xin Li (Intel), Borislav Petkov (AMD),
Nikolay Borisov, x86@kernel.org, linux-kernel@vger.kernel.org
* Linus Torvalds <torvalds@linux-foundation.org> wrote:
> On Fri, 28 Mar 2025 at 17:14, Linus Torvalds
> <torvalds@linux-foundation.org> wrote:
> >
> > So I think the real fix is something like this ENTIRELY UNTESTED
> > patch. Whitespace-damaged again to make sure people don't apply this
> > mindlessly, it needs more thought:
>
> .. and that ended up being even more whitespace-damaged than I meant
> to make it, because it also line-wrapped.
>
> Oh well. Not pretty, but I hope people still get the idea.
>
> And I just actually tried doing a build after touching the .config
> file, and it did seem to work.
>
> But since I had _also_ messed with the config file on purpose earlier,
> I'm not sure I'm actually testing the thing the networking builds
> trigger. So I might be entirely missing something.
>
> Adding Masahiro to the cc, so that somebody competent can actually
> check my thinking.
>
> Masahiro, see the complaint (and my reply) in
>
> https://lore.kernel.org/all/20250328162311.08134fa6@kernel.org/
>
> for background...
Just an update: Linus applied the fix below directly, which should
resolve the problem. Thanks Linus!
Thanks,
Ingo
==============>
From: Linus Torvalds <torvalds@linux-foundation.org>
Date: Mon, 31 Mar 2025 14:19:55 -0700
Subject: [PATCH] x86: don't re-generate cpufeaturemasks.h so eagerly
It turns out the code to generate the x86 cpufeaturemasks.h header was
way too aggressive, and would re-generate it whenever the timestamp on
the kernel config file changed.
Now, the regular 'make *config' tools are fairly careful to not rewrite
the kernel config file unless the contents change, but other usecases
aren't that careful.
Michael Kelley reports that 'make-kpkg' ends up doing "make syncconfig"
multiple times in prepping to build, and will modify the config file in
the process (and then modify it back, but by then the timestamps have
changed).
Jakub Kicinski reports that the netdev CI does something similar in how
it generates the config file in multiple steps.
In both cases, the config file timestamp updates then cause the
cpufeaturemasks.h file to be regenerated, and that in turn then causes
lots of unnecessary rebuilds due to all the normal dependencies.
Fix it by using our 'filechk' infrastructure in the Makefile to generate
the header file. That will only write a new version of the file if the
contents of the file have actually changed.
Fixes: 841326332bcb ("x86/cpufeatures: Generate the <asm/cpufeaturemasks.h> header based on build config")
Reported-by: Michael Kelley <mhklinux@outlook.com>
Reported-by: Jakub Kicinski <kuba@kernel.org>
Link: https://lore.kernel.org/all/SN6PR02MB415756D1829740F6E8AC11D1D4D82@SN6PR02MB4157.namprd02.prod.outlook.com/
Link: https://lore.kernel.org/all/20250328162311.08134fa6@kernel.org/
Cc: Peter Anvin <hpa@zytor.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
---
arch/x86/Makefile | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/arch/x86/Makefile b/arch/x86/Makefile
index 0fc7e8fd1a2e..27efe2dc2aa8 100644
--- a/arch/x86/Makefile
+++ b/arch/x86/Makefile
@@ -277,12 +277,11 @@ cpufeaturemasks.hdr := arch/x86/include/generated/asm/cpufeaturemasks.h
cpufeaturemasks.awk := $(srctree)/arch/x86/tools/cpufeaturemasks.awk
cpufeatures_hdr := $(srctree)/arch/x86/include/asm/cpufeatures.h
targets += $(cpufeaturemasks.hdr)
-quiet_cmd_gen_featuremasks = GEN $@
- cmd_gen_featuremasks = $(AWK) -f $(cpufeaturemasks.awk) $(cpufeatures_hdr) $(KCONFIG_CONFIG) > $@
+ filechk_gen_featuremasks = $(AWK) -f $(cpufeaturemasks.awk) $(cpufeatures_hdr) $(KCONFIG_CONFIG)
$(cpufeaturemasks.hdr): $(cpufeaturemasks.awk) $(cpufeatures_hdr) $(KCONFIG_CONFIG) FORCE
$(shell mkdir -p $(dir $@))
- $(call if_changed,gen_featuremasks)
+ $(call filechk,gen_featuremasks)
archprepare: $(cpufeaturemasks.hdr)
###
^ permalink raw reply related [flat|nested] 20+ messages in thread
end of thread, other threads:[~2025-04-01 7:00 UTC | newest]
Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-05 18:47 [PATCH v7 0/4] x86/cpufeatures: Automatically generate required and disabled feature masks Xin Li (Intel)
2025-03-05 18:47 ` [PATCH v7 1/4] x86/cpufeatures: Add {required,disabled} feature configs Xin Li (Intel)
2025-03-05 18:47 ` [PATCH v7 2/4] x86/cpufeatures: Generate a feature mask header based on build config Xin Li (Intel)
2025-03-10 8:18 ` [tip: x86/cpu] x86/cpufeatures: Generate the <asm/cpufeaturemasks.h> " tip-bot2 for H. Peter Anvin (Intel)
2025-03-19 11:03 ` [tip: x86/core] " tip-bot2 for H. Peter Anvin (Intel)
2025-03-20 16:23 ` Michael Kelley
2025-03-20 16:56 ` Linus Torvalds
2025-03-23 18:06 ` Michael Kelley
2025-03-28 23:23 ` Jakub Kicinski
2025-03-29 0:14 ` Linus Torvalds
2025-03-29 0:22 ` Linus Torvalds
2025-03-29 0:56 ` Jakub Kicinski
2025-04-01 7:00 ` [PATCH] x86: don't re-generate cpufeaturemasks.h so eagerly Ingo Molnar
2025-03-29 0:56 ` [tip: x86/core] x86/cpufeatures: Generate the <asm/cpufeaturemasks.h> header based on build config H. Peter Anvin
2025-03-05 18:47 ` [PATCH v7 3/4] x86/cpufeatures: Remove {disabled,required}-features.h Xin Li (Intel)
2025-03-10 8:18 ` [tip: x86/cpu] " tip-bot2 for Xin Li (Intel)
2025-03-19 11:03 ` [tip: x86/core] " tip-bot2 for Xin Li (Intel)
2025-03-05 18:47 ` [PATCH v7 4/4] x86/cpufeatures: Use AWK to generate {REQUIRED|DISABLED}_MASK_BIT_SET Xin Li (Intel)
2025-03-07 18:28 ` [PATCH v7 0/4] x86/cpufeatures: Automatically generate required and disabled feature masks Xin Li
2025-03-07 19:18 ` Borislav Petkov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox