x86/cpufeatures: Automatically generate required and disabled feature masks
Subsystems (2)
v7 cover x86/cpufeatures: Automatically generate required and disabled feature masks
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/[email protected]/.
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/[email protected]/.
https://lore.kernel.org/all/[email protected]/.
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/[email protected]/.
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/[email protected]/
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
Signature · 1 line
2.48.1
PATCH v7 1/4 x86/cpufeatures: Add {required,disabled} feature configs
From: "H. Peter Anvin (Intel)" <[email protected]>
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.
---
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
arch/x86/Kconfig +2 -0
@@ -3130,4 +3130,6 @@ config HAVE_ATOMIC_IOMAP source "arch/x86/kvm/Kconfig" +source "arch/x86/Kconfig.cpufeatures" + source "arch/x86/Kconfig.assembler"
arch/x86/Kconfig.cpufeatures new file +197 -0
197 lines not on this page · raw message
Signature · 1 line
2.48.1
PATCH v7 2/4 x86/cpufeatures: Generate a feature mask header based on build config
In reply to Xin Li (Intel)From: "H. Peter Anvin (Intel)" <[email protected]>
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 ]
---
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
arch/x86/Makefile +15 -0
@@ -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
arch/x86/boot/cpucheck.c +2 -1
@@ -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"
arch/x86/boot/cpuflags.c +0 -1
@@ -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"
arch/x86/boot/mkcpustr.c +1 -2
@@ -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++) {
arch/x86/include/asm/Kbuild +1 -0
@@ -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
arch/x86/include/asm/cpufeature.h +1 -0
@@ -9,6 +9,7 @@#include <asm/asm.h> #include <linux/bitops.h> #include <asm/alternative.h> +#include <asm/featuremasks.h> enum cpuid_leafs {
arch/x86/include/asm/cpufeatures.h +0 -8
@@ -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 */
arch/x86/kernel/verify_cpu.S +4 -0
@@ -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
arch/x86/tools/featuremasks.awk new file +81 -0
81 lines not on this page · raw message
Signature · 1 line
2.48.1
[tip: x86/cpu] x86/cpufeatures: Generate the <asm/cpufeaturemasks.h> header based on build config
The following commit has been merged into the x86/cpu branch of tip:
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) <[email protected]> AuthorDate: Wed, 05 Mar 2025 10:47:22 -08:00 Committer: Ingo Molnar <[email protected]> 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 ]
--- 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
arch/x86/Makefile +15 -0
@@ -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/
arch/x86/boot/cpucheck.c +2 -1
@@ -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"
arch/x86/boot/cpuflags.c +0 -1
@@ -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"
arch/x86/boot/mkcpustr.c +1 -2
@@ -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++) {
arch/x86/include/asm/Kbuild +1 -0
@@ -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
arch/x86/include/asm/cpufeature.h +1 -0
@@ -9,6 +9,7 @@#include <asm/asm.h> #include <linux/bitops.h> #include <asm/alternative.h> +#include <asm/cpufeaturemasks.h> enum cpuid_leafs {
arch/x86/include/asm/cpufeatures.h +0 -8
@@ -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 */
arch/x86/kernel/verify_cpu.S +4 -0
@@ -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
arch/x86/tools/cpufeaturemasks.awk new file +81 -0
81 lines not on this page · raw message
[tip: x86/core] x86/cpufeatures: Generate the <asm/cpufeaturemasks.h> header based on build config
In reply to Xin Li (Intel)The following commit has been merged into the x86/core branch of tip:
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) <[email protected]> AuthorDate: Wed, 05 Mar 2025 10:47:22 -08:00 Committer: Ingo Molnar <[email protected]> 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 ]
--- 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
arch/x86/Makefile +15 -0
@@ -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/
arch/x86/boot/cpucheck.c +2 -1
@@ -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"
arch/x86/boot/cpuflags.c +0 -1
@@ -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"
arch/x86/boot/mkcpustr.c +1 -2
@@ -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++) {
arch/x86/include/asm/Kbuild +1 -0
@@ -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
arch/x86/include/asm/cpufeature.h +1 -0
@@ -9,6 +9,7 @@#include <asm/asm.h> #include <linux/bitops.h> #include <asm/alternative.h> +#include <asm/cpufeaturemasks.h> enum cpuid_leafs {
arch/x86/include/asm/cpufeatures.h +0 -8
@@ -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 */
arch/x86/kernel/verify_cpu.S +4 -0
@@ -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
arch/x86/tools/cpufeaturemasks.awk new file +81 -0
81 lines not on this page · raw message
RE: [tip: x86/core] x86/cpufeatures: Generate the <asm/cpufeaturemasks.h> header based on build config
From: [email protected] <[email protected]> Sent: Wednesday, March 19, 2025 4:04 AM
Quoted 11 lines
The following commit has been merged into the x86/core branch of tip:
Commit-ID: 841326332bcb13ae4e6cd456350bf566a402b45e Gitweb: https://lore.kernel.org/all/[email protected]/ Author: H. Peter Anvin (Intel) <[email protected]> AuthorDate: Wed, 05 Mar 2025 10:47:22 -08:00 Committer: Ingo Molnar <[email protected]> CommitterDate: Wed, 19 Mar 2025 11:15:11 +01:00x86/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
Quoted 276 lines
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_booly
depends on !X86_FREDto
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) <[email protected]>Signed-off-by Xin Li (Intel) <[email protected]>Signed-off-by Borislav Petkov (AMD) <[email protected]>Signed-off-by Ingo Molnar <[email protected]>Reviewed-by Nikolay Borisov <[email protected]>Cc Linus Torvalds <[email protected]>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.awkarch/x86/Makefile +8
-0@@ -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) FORCEarch/x86/Makefile +5
-0+ $(shell mkdir -p $(dir $@)) + $(call if_changed,gen_featuremasks) +archprepare: $(cpufeaturemasks.hdr) + +### # Kernel objects libs-y += arch/x86/lib/arch/x86/boot/cpucheck.c +2
-1@@ -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" arch/x86/boot/cpuflags.c +0
-1@@ -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" arch/x86/boot/mkcpustr.c +1
-2@@ -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++) {arch/x86/include/asm/Kbuild +1
-0@@ -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.harch/x86/include/asm/cpufeature.h +1
-0@@ -9,6 +9,7 @@#include <asm/asm.h> #include <linux/bitops.h> #include <asm/alternative.h> +#include <asm/cpufeaturemasks.h> enum cpuid_leafs {arch/x86/include/asm/cpufeatures.h +0
-8@@ -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 */ arch/x86/kernel/verify_cpu.S +4
-0@@ -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 flagsarch/x86/kernel/verify_cpu.S +0
-0push $0 # Kill any dangerous flagsarch/x86/tools/cpufeaturemasks.awk new file +77
-0@@ -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;
arch/x86/tools/cpufeaturemasks.awk new file +4
-0+ } + + printf "#endif /* _ASM_X86_CPUFEATUREMASKS_H */\n"; +}
Re: [tip: x86/core] x86/cpufeatures: Generate the <asm/cpufeaturemasks.h> header based on build config
Quoted 5 lines · Michael Kelley
With this commit, changing the modified time on .config causes
cpufeaturemasks.hto be rebuilt, and then all dependencies oncpufeaturemasks.hare 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*'
Quoted 3 lines
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
RE: [tip: x86/core] x86/cpufeatures: Generate the <asm/cpufeaturemasks.h> header based on build config
From: Linus Torvalds <[email protected]> Sent: Thursday, March 20, 2025 9:56 AM
Quoted 14 lines · Michael Kelley
Quoted 5 lines
With this commit, changing the modified time on .config causes
cpufeaturemasks.hto be rebuilt, and then all dependencies oncpufeaturemasks.hare 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()inscripts/kconfig/confdata.cfor the particular case of the regular "make *config*'
Quoted 9 lines
Quoted 3 lines
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
Re: [tip: x86/core] x86/cpufeatures: Generate the <asm/cpufeaturemasks.h> header based on build config
Quoted 29 lines · On Sun, 23 Mar 2025 18:06:07 +0000 Michael Kelley wrote:
Quoted 11 lines
Quoted 4 lines
With this commit, changing the modified time on .config causes
cpufeaturemasks.hto be rebuilt, and then all dependencies oncpufeaturemasks.hare 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()inscripts/kconfig/confdata.cfor the particular case of the regular "make *config*'Quoted 9 lines
Quoted 3 lines
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/confuses that environment variable to decorate the header of the generated .config file, and to force a rebuild ininclude/config/auto.conf.cmdif the value changes. So flipping between two different values causes a "new" .config to be generated even though nothing of substance has changed.
Quoted 4 lines
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 ..
arch/x86/Makefile +3 -1
@@ -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) > [email protected]; \ + if [ -e $@ ] && cmp -s $@ [email protected]; then rm [email protected]; \ + else mv [email protected] $@; fi $(cpufeaturemasks.hdr): $(cpufeaturemasks.awk) $(cpufeatures_hdr) $(KCONFIG_CONFIG) FORCE $(shell mkdir -p $(dir $@))
Re: [tip: x86/core] x86/cpufeatures: Generate the <asm/cpufeaturemasks.h> header based on build config
Quoted 10 lines · Jakub Kicinski
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=1Could 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
Re: [tip: x86/core] x86/cpufeatures: Generate the <asm/cpufeaturemasks.h> header based on build config
Quoted 4 lines · Linus Torvalds
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/[email protected]/
for background...
Linus
Re: [tip: x86/core] x86/cpufeatures: Generate the <asm/cpufeaturemasks.h> header based on build config
Quoted 11 lines · On Fri, 28 Mar 2025 17:22:03 -0700 Linus Torvalds wrote:
Quoted 3 lines
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!!
Quoted 3 lines
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
PATCH 1/1 x86: don't re-generate cpufeaturemasks.h so eagerly
In reply to Linus TorvaldsQuoted 19 lines · Linus Torvalds
Quoted 4 lines · Linus Torvalds
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.
Quoted 8 lines
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/[email protected]/for background...
Just an update: Linus applied the fix below directly, which should resolve the problem. Thanks Linus!
Thanks,
Ingo
==============>
From: Linus Torvalds <[email protected]>
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.
--- arch/x86/Makefile | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
arch/x86/Makefile +2 -3
@@ -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) ###
H. Peter Anvin
reviewerRe: [tip: x86/core] x86/cpufeatures: Generate the <asm/cpufeaturemasks.h> header based on build config
In reply to Linus TorvaldsQuoted 49 lines · Linus Torvalds
Quoted 10 lines · Jakub Kicinski
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=1Could 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..769b29bf26ba100644
--- 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)
Quoted 6 lines
###
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 :(
PATCH v7 3/4 x86/cpufeatures: Remove {disabled,required}-features.h
In reply to Xin Li (Intel)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.
---
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 ------------ tools/perf/check-headers.sh | 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
arch/x86/include/asm/disabled-features.h deleted +0 -161
@@ -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 */
arch/x86/include/asm/required-features.h deleted +0 -105
105 lines not on this page · raw message
tools/arch/x86/include/asm/cpufeatures.h +0 -8
@@ -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 */
tools/arch/x86/include/asm/disabled-features.h deleted +0 -161
161 lines not on this page · raw message
tools/arch/x86/include/asm/required-features.h deleted +0 -105
105 lines not on this page · raw message
tools/perf/check-headers.sh +0 -2
@@ -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"
Signature · 1 line
2.48.1
[tip: x86/cpu] x86/cpufeatures: Remove {disabled,required}-features.h
The following commit has been merged into the x86/cpu branch of tip:
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) <[email protected]> AuthorDate: Mon, 10 Mar 2025 08:32:12 +01:00 Committer: Ingo Molnar <[email protected]> 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.
--- 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 +---------- tools/perf/check-headers.sh | 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
arch/x86/include/asm/disabled-features.h deleted +0 -167
@@ -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 */
arch/x86/include/asm/required-features.h deleted +0 -105
105 lines not on this page · raw message
tools/arch/x86/include/asm/cpufeatures.h +0 -8
@@ -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 */
tools/arch/x86/include/asm/disabled-features.h deleted +0 -161
161 lines not on this page · raw message
tools/arch/x86/include/asm/required-features.h deleted +0 -105
105 lines not on this page · raw message
tools/perf/check-headers.sh +0 -2
@@ -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"
[tip: x86/core] x86/cpufeatures: Remove {disabled,required}-features.h
In reply to Xin Li (Intel)The following commit has been merged into the x86/core branch of tip:
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) <[email protected]> AuthorDate: Mon, 10 Mar 2025 08:32:12 +01:00 Committer: Ingo Molnar <[email protected]> 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.
--- 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 +---------- tools/perf/check-headers.sh | 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
arch/x86/include/asm/disabled-features.h deleted +0 -167
@@ -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 */
arch/x86/include/asm/required-features.h deleted +0 -105
105 lines not on this page · raw message
tools/arch/x86/include/asm/cpufeatures.h +0 -8
@@ -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 */
tools/arch/x86/include/asm/disabled-features.h deleted +0 -161
161 lines not on this page · raw message
tools/arch/x86/include/asm/required-features.h deleted +0 -105
105 lines not on this page · raw message
tools/perf/check-headers.sh +0 -2
@@ -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"
PATCH v7 4/4 x86/cpufeatures: Use AWK to generate {REQUIRED|DISABLED}_MASK_BIT_SET
In reply to Xin Li (Intel)Generate macros {REQUIRED|DISABLED}_MASK_BIT_SET in the newly added AWK script that generates the required and disabled feature mask header.
---
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(-)
arch/x86/include/asm/cpufeature.h +0 -69
@@ -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))
arch/x86/tools/featuremasks.awk +8 -1
@@ -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";
Signature · 1 line
2.48.1
Quoted 25 lines · Xin Li (Intel)
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/[email protected]/.
As a result, the FRED feature bit is surely cleared in the generated kernel binary whenCONFIG_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/[email protected]/.
https://lore.kernel.org/all/[email protected]/.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/[email protected]/.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.
Quoted 7 lines
Link to v6:
https://lore.kernel.org/lkml/[email protected]/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
Quoted 36 lines
H. Peter Anvin (Intel) (2):
x86/cpufeatures: Add {required,disabled} feature configs x86/cpufeatures: Generate a feature mask header based on build configXin Li (Intel) (2):
x86/cpufeatures: Remove {disabled,required}-features.h x86/cpufeatures: Use AWK to generate {REQUIRED|DISABLED}_MASK_BIT_SETarch/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 100644arch/x86/include/asm/disabled-features.hdelete mode 100644arch/x86/include/asm/required-features.hcreate mode 100755arch/x86/tools/featuremasks.awkdelete mode 100644tools/arch/x86/include/asm/disabled-features.hdelete mode 100644tools/arch/x86/include/asm/required-features.hbase-commit:
32dc26a2f55f71907af0874468298c6ab8a8f7f9
Borislav Petkov
maintainerQuoted 1 line · Xin Li
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.
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquette