kbuild: build the userspace tools in tools/ with the kernel
Subsystems (6)
v2 cover kbuild: build the userspace tools in tools/ with the kernel
The userspace programs under tools/ are disconnected from the rest of the kernel's build system. Each has its own makefiles and build framework, and "make" never builds them: apart from the few host tools the build itself needs, such as objtool and resolve_btfids, nothing under tools/ is compiled as part of a kernel build.
That makes them easy to break. Most people, and most of the build bots, check a change with "make allmodconfig && make", which doesn't cover tools/ at all. A change that breaks a tool passes every build check and is only noticed when someone happens to build that tool by hand, often much later.
We keep seeing this in tools/testing/: selftests that stop building after a change elsewhere in the tree, or after a backport to a stable tree, and stay broken until someone tries to build them. Others brought up the same concern at LPC.
This series lets the kernel build also build the tools it is configured for:
- tools/Kconfig adds a "Build userspace tools from tools/" menu (CONFIG_TOOLS_BUILD) with one entry per tool and per selftests directory, so .config records what gets built, and a tool that breaks can be turned off on its own.
- "make tools_build" builds the selected tools for the target, each with its own build system as it is built standalone, into tools-build/ in the object tree.
- With CONFIG_TOOLS_BUILD=y, "make all" builds them too. allmodconfig and allyesconfig enable every entry that applies to the target when the compiler can link glibc programs for it (currently x86_64 and arm64), so the usual build test catches tools breakage. Other toolchains are unaffected, as are "make vmlinux", "make modules" and external module builds.
This is useful beyond build testing: the tools are built for the same target, from the same tree, as the kernel they go with.
Changes in v2:
- 1/7: Add Thomas's Reviewed-by.
- 2/7: Put each "depends on" condition on its own line. Allow UML: the tools are built for the architecture UML runs on (HEADER_ARCH), as their build systems do not know ARCH=um. Drop the PYTHONDONTWRITEBYTECODE export, as 5479e1a13b75 ("perf tools: Put Python bytecode in output directory") in perf-tools-next keeps perf's bytecode in its output directory.
- 3/7: New. Add MINIMAL=1 to perf, which turns off every optional feature, as Ian suggested.
- 4/7: Build perf with MINIMAL=1 instead of a list of NO_* variables.
- 5/7: As with "make kselftest-all", a selftest that fails to build no longer fails the build unless FORCE_TARGETS is set, and kselftest_deps.sh lists the libraries it needs that the compiler cannot link with. Also rebuild the selftests when headers under tools/arch change, the vDSO test when kernel headers change, and the x86 tests when the x86 headers they include change.
3/7 is against mainline. perf-tools-next renamed NO_LIBPYTHON to NO_PYTHON_MODULE and runs mypy and pylint by default, so there it also needs NO_PYTHON_MODULE, NO_MYPY and NO_PYLINT.
v1: https://lore.kernel.org/r/[email protected]
Sasha Levin (7):
kbuild: factor the userspace ABI flags out into KBUILD_USERABI
kbuild: add "make tools_build" to build userspace tools from tools/ perf build: Add MINIMAL=1 to build without optional features
tools: build perf in tools_build
tools: build kernel selftests in tools_build
kbuild: build the tools selected in tools/Kconfig as part of "make
all"
Documentation: describe building tools with the kernel
.gitignore | 5 + Documentation/dev-tools/kselftest.rst | 4 + Documentation/kbuild/kbuild.rst | 4 +- Documentation/process/submit-checklist.rst | 5 + Makefile | 24 +- lib/Kconfig.debug | 2 + tools/Kconfig | 330 +++++++++++++++++++++ tools/Makefile.kbuild | 205 +++++++++++++ tools/perf/Makefile.config | 8 +- tools/perf/Makefile.perf | 40 ++- tools/perf/tests/make | 8 +- 11 files changed, 617 insertions(+), 18 deletions(-) create mode 100644 tools/Kconfig create mode 100644 tools/Makefile.kbuild
base-commit: a5ebb76233b79db01e82e061173cb73c6d2b5c6b
prerequisite-patch-id: 68eb8785244b88ec7e696e716420e2d9b1367dbc
prerequisite-patch-id: 37c57cf4c2a9700788cd1755912753f363cbb3f9
prerequisite-patch-id: 7772557d5d842a42f1bbb3ee18d41f337db9783a
prerequisite-patch-id: 75abf8d47ec8093740c215e9eebe7bbb5846ddd6
prerequisite-patch-id: de33c5273a0f7619a54dc6d1fd9c47383b7dd60e
prerequisite-patch-id: 5243b7b03f2c12a6e66c353b0c083f7f21fd7ba2
prerequisite-patch-id: 7153a847ba7b05e49a670caba5d5b8fa2508eff1
prerequisite-patch-id: 67a995618952454c30eb77960a5bf6f897d22547
prerequisite-patch-id: f0580be789bfbd90c903bfef8cf6099609e63347
prerequisite-patch-id: 975b27a83085ae7532771fbd7bb17b779ea2c254
prerequisite-patch-id: 1eee5ec66bc4c1ff3ba9f57e005484ed514c77a1
prerequisite-patch-id: 333bf51a132f726bf970b5963017bdc607c0e315
prerequisite-patch-id: 7853ec5197ec9b9322a102a6b02dd62bba4df102
prerequisite-patch-id: bc69d99570e4326ce7736b244838e1e97cc13358
prerequisite-patch-id: 7a28872d234cdfa7bd5ec851e9dde01a65e91130
prerequisite-patch-id: f75a478f103e8707f7ce1ebb136e3a605f026cae
prerequisite-patch-id: c6aacf3772c239df0224afb7e4bb661fb9b81c63
prerequisite-patch-id: a71f47de3fd339d680c9f18e80f5bcde7eae0abf
Signature · 1 line
2.53.0
RFC PATCH v2 1/7 kbuild: factor the userspace ABI flags out into KBUILD_USERABI
KBUILD_USERCFLAGS and KBUILD_USERLDFLAGS pick up the flags that select the target ABI for userspace programs: --target= under clang, -m32/-m64, or CONFIG_ARCH_USERFLAGS. Collect those in KBUILD_USERABI and export it, so programs built outside of kbuild's userprogs can be compiled for the same ABI without also inheriting kbuild's warning and language flags.
No functional change: KBUILD_USERCFLAGS and KBUILD_USERLDFLAGS keep the same value.
--- Makefile | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
Makefile +7 -5
@@ -650,7 +650,7 @@ export CPP AR NM STRIP OBJCOPY OBJDUMP READELF PAHOLE RESOLVE_BTFIDS LEX YACC AW export PERL PYTHON3 CHECK CHECKFLAGS MAKE UTS_MACHINE HOSTCXX export KGZIP KBZIP2 KLZOP LZMA LZ4 XZ ZSTD TAR export KBUILD_HOSTCXXFLAGS KBUILD_HOSTLDFLAGS KBUILD_HOSTLDLIBS KBUILD_PROCMACROLDFLAGS LDFLAGS_MODULE -export KBUILD_USERCFLAGS KBUILD_USERLDFLAGS +export KBUILD_USERCFLAGS KBUILD_USERLDFLAGS KBUILD_USERABI export KBUILD_CPPFLAGS NOSTDINC_FLAGS LINUXINCLUDE OBJCOPYFLAGS KBUILD_LDFLAGS export KBUILD_CFLAGS CFLAGS_KERNEL CFLAGS_MODULE
@@ -1270,15 +1270,17 @@ endif USERFLAGS_FROM_KERNEL := --target=% ifdef CONFIG_ARCH_USERFLAGS -KBUILD_USERCFLAGS += $(CONFIG_ARCH_USERFLAGS) -KBUILD_USERLDFLAGS += $(CONFIG_ARCH_USERFLAGS) +KBUILD_USERABI := $(CONFIG_ARCH_USERFLAGS) else +KBUILD_USERABI := # If not overridden also inherit the bit size USERFLAGS_FROM_KERNEL += -m32 -m64 endif -KBUILD_USERCFLAGS += $(filter $(USERFLAGS_FROM_KERNEL), $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS)) -KBUILD_USERLDFLAGS += $(filter $(USERFLAGS_FROM_KERNEL), $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS)) +KBUILD_USERABI += $(filter $(USERFLAGS_FROM_KERNEL), $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS)) + +KBUILD_USERCFLAGS += $(KBUILD_USERABI) +KBUILD_USERLDFLAGS += $(KBUILD_USERABI) # userspace programs are linked via the compiler, use the correct linker ifdef CONFIG_CC_IS_CLANG
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [RFC PATCH v2 1/7] kbuild: factor the userspace ABI flags out into KBUILD_USERABI
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] kbuild: KBUILD_USERABI omitted from SBOM environment allowlist --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] kbuild: KBUILD_USERABI omitted from SBOM environment allowlist
--
commit 907dedf7b95c5c493b503479d22886e4a895a2f8
Author: Sasha Levin <[email protected]>
kbuild: factor the userspace ABI flags out into KBUILD_USERABI
This commit factors out the userspace ABI flags into a new KBUILD_USERABI variable and exports it. This allows programs built outside of kbuild's userprogs to be compiled for the same ABI without inheriting other flags.
Makefile export CPP AR NM STRIP OBJCOPY OBJDUMP READELF PAHOLE RESOLVE_BTFIDS LEX YACC AW · line 653
Quoted 10 lines
Makefile +1
-1@@ -650,7 +650,7 @@ export CPP AR NM STRIP OBJCOPY OBJDUMP READELF PAHOLE RESOLVE_BTFIDS LEX YACC AW export PERL PYTHON3 CHECK CHECKFLAGS MAKE UTS_MACHINE HOSTCXX export KGZIP KBZIP2 KLZOP LZMA LZ4 XZ ZSTD TAR export KBUILD_HOSTCXXFLAGS KBUILD_HOSTLDFLAGS KBUILD_HOSTLDLIBS KBUILD_PROCMACROLDFLAGS LDFLAGS_MODULE -export KBUILD_USERCFLAGS KBUILD_USERLDFLAGS +export KBUILD_USERCFLAGS KBUILD_USERLDFLAGS KBUILD_USERABI
[Severity: Low]
Does this new exported variable also need to be added to the SPDX SBOM environment allowlist?
Currently, KBUILD_USERCFLAGS and KBUILD_USERLDFLAGS are explicitly tracked in KERNEL_BUILD_VARIABLES_ALLOWLIST in scripts/sbom/sbom/environment.py:
scripts/sbom/sbom/environment.py:KERNEL_BUILD_VARIABLES_ALLOWLIST = [
...
"KBUILD_USERCFLAGS",
"KBUILD_USERLDFLAGS",
...]
Leaving KBUILD_USERABI off this list means its value will not be captured in the SPDX SBOM generated by scripts/sbom, resulting in incomplete build metadata documentation for the userspace ABI configuration.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Re: [RFC PATCH v2 1/7] kbuild: factor the userspace ABI flags out into KBUILD_USERABI
Quoted 6 lines · On Sat, Oct 17, 2026 at 02:32:08PM +0000, [email protected] wrote:
[Severity: Low]
Does this new exported variable also need to be added to the SPDX SBOM environment allowlist?Currently,
KBUILD_USERCFLAGSandKBUILD_USERLDFLAGSare explicitly tracked inKERNEL_BUILD_VARIABLES_ALLOWLISTinscripts/sbom/sbom/environment.py:
[...]
Quoted 3 lines
Leaving
KBUILD_USERABIoff this list means its value will not be captured in the SPDX SBOM generated byscripts/sbom, resulting in incomplete build metadata documentation for the userspace ABI configuration.
KBUILD_USERABI is appended to both KBUILD_USERCFLAGS and KBUILD_USERLDFLAGS, which are on that list, so its flags are already in the SBOM. Listing it as well would only record the same flags again.
Signature · 2 lines
Thanks, Sasha
RFC PATCH v2 2/7 kbuild: add "make tools_build" to build userspace tools from tools/
In reply to Sasha LevinThe programs under tools/ have their own build systems and are not built by "make", so nothing builds them together with the kernel they belong to, and breakage in them is only noticed when someone happens to build them by hand, sometimes many stable releases later.
Add a "Build userspace tools from tools/" menu (CONFIG_TOOLS_BUILD) with an entry for each tool, and a "tools_build" target that builds the selected ones for the target:
- Each tool is built by its own build system, as it is built standalone, into tools-build/ in the object tree. "make clean" removes that directory without running the tools' own clean rules.
- The compiler is the one CONFIG_CC_CAN_LINK was tested with: $(CC), USERCFLAGS and KBUILD_USERABI, so cross builds, including LLVM=1 ARCH=<arch> without CROSS_COMPILE, produce target binaries. USERLDFLAGS reach the tools as LDFLAGS.
- kbuild's own state (srctree, objtree, VPATH, sub_make_done, ...) and the user's CFLAGS/LDFLAGS/O= from the environment or the command line are kept away from the tools.
- Under UML, ARCH and SRCARCH are set to the architecture UML runs on (HEADER_ARCH): a UML kernel runs that architecture's programs, and the tools' build systems do not know ARCH=um.
- A tool is rebuilt from scratch when its make arguments change. "make -n" shows the build without removing or recording anything.
- On failure, the message names the option that skips the tool.
The menu depends on CC_CAN_LINK, so toolchains without a C library are unaffected, and is limited to glibc toolchains for x86_64 and arm64, which is what it has been tested with.
The first entries are the tools that only need a C library: bootconfig, counter, dma, gpio, hv, iio, spi and usb.
--- .gitignore | 5 +++ Makefile | 8 +++- lib/Kconfig.debug | 2 + tools/Kconfig | 73 +++++++++++++++++++++++++++++++++++++ tools/Makefile.kbuild | 85 +++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 172 insertions(+), 1 deletion(-) create mode 100644 tools/Kconfig create mode 100644 tools/Makefile.kbuild
.gitignore +5 -0
@@ -101,6 +101,11 @@ modules.order # /tar-install/ +# +# userspace tools (make tools_build) +# +/tools-build/ + # # pacman files (make pacman-pkg) #
Makefile +7 -1
@@ -1633,6 +1633,11 @@ tools/%: FORCE $(Q)mkdir -p $(objtree)/tools $(Q)$(MAKE) O=$(abspath $(objtree)) subdir=tools -C $(srctree)/tools/ $* +# The userspace programs selected in tools/Kconfig, built for the target +PHONY += tools_build +tools_build: headers + $(Q)$(MAKE) -f $(srctree)/tools/Makefile.kbuild + # --------------------------------------------------------------------------- # Kernel selftest
@@ -1772,7 +1777,7 @@ CLEAN_FILES += vmlinux.symvers modules-only.symvers \ modules.builtin modules.builtin.modinfo modules.nsdeps \ modules.builtin.ranges vmlinux.o.map vmlinux.unstripped \ vmlinux.thinlto-index builtin.order \ - compile_commands.json rust/test \ + compile_commands.json rust/test tools-build \ rust-project.json .vmlinux.objs .vmlinux.export.c \ .builtin-dtbs-list .builtin-dtbs.S sbom-*.spdx.json
@@ -1894,6 +1899,7 @@ help: @echo ' clang-tidy - Check with clang-tidy' @echo '' @echo 'Tools:' + @echo ' tools_build - Build the userspace tools selected in tools/Kconfig' @echo ' nsdeps - Generate missing symbol namespace dependencies' @echo ' sbom - Generate Software Bill of Materials' @echo ''
lib/Kconfig.debug +2 -0
@@ -1913,6 +1913,8 @@ config PROVIDE_OHCI1394_DMA_INIT source "samples/Kconfig" +source "tools/Kconfig" + config ARCH_HAS_DEVMEM_IS_ALLOWED bool
tools/Kconfig new file +73 -0
73 lines not on this page · raw message
tools/Makefile.kbuild new file +85 -0
85 lines not on this page · raw message
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [RFC PATCH v2 2/7] kbuild: add "make tools_build" to build userspace tools from tools/
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] kbuild: flawed dry-run detection breaks incremental rebuilds --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] kbuild: flawed dry-run detection breaks incremental rebuilds
--
commit af4d0e2311f445e8ceb17d3fd81b05fa2c242614
Author: Sasha Levin <[email protected]>
kbuild: add "make tools_build" to build userspace tools from tools/
This commit adds a new target to build userspace tools from the tools/ directory as part of the kernel build process. It introduces a Kconfig menu and a Makefile for building the selected programs independently.
Quoted 5 lines
tools/Makefile.kbuild new file +0
-0
[ ... ]
tools/Makefile.kbuild line 52
Quoted 6 lines
tools/Makefile.kbuild new file +6
-0+# $(call build,<output directory>,<make arguments>,<files to check>,<CONFIG_ symbol>) +# Builds in an empty directory when the make arguments or LDFLAGS changed, or +# when one of the files is newer than the last build. "make -n" only shows +# the build. +build-key = $(call escsq,$(2) LDFLAGS=$(USERLDFLAGS)) +dry-run := $(findstring n,$(firstword -$(MAKEFLAGS)))
[Severity: Medium]
Could this dry-run detection logic produce a false positive for common make arguments?
If MAKEFLAGS starts with a long option containing 'n' (such as Kbuild's frequent default --no-print-directory), -$(MAKEFLAGS) evaluates to something like ---no-print-directory, and findstring erroneously matches the letter 'n'.
When evaluated as a dry run, the Makefile silently skips creating the .tools_build tracking file and refuses to clear out stale objects, which breaks incremental rebuilds.
Is it possible to use the standard Kbuild idiom here, like $(findstring n,$(filter-out --%,$(MAKEFLAGS))), to properly check the flags?
Quoted 10 lines
tools/Makefile.kbuild new file +10
-0+ +define build + +$(Q)$(if $(dry-run),,if [ "$$(cat $(1)/.tools_build 2>/dev/null)" != '$(build-key)' ] $(if $(3),|| \ + [ -n "$$(find $(3) -newer $(1)/.tools_build -print -quit 2>/dev/null)" ]); then \ + rm -rf $(1); \ + fi;) \ + mkdir -p $(1) && $(MAKE) $(2) && \ + $(if $(dry-run),:,printf '%s' '$(build-key)' > $(1)/.tools_build) || \ + { echo >&2 "tools_build: $(patsubst $(outdir)/%,%,$(1)) failed to build; set CONFIG_$(4)=n to skip it"; false; } +endef
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Re: [RFC PATCH v2 2/7] kbuild: add "make tools_build" to build userspace tools from tools/
Quoted 9 lines · On Sat, Oct 17, 2026 at 02:32:09PM +0000, [email protected] wrote:
Quoted 1 line
+dry-run := $(findstring n,$(firstword -$(MAKEFLAGS)))
[Severity: Medium]
Could this dry-run detection logic produce a false positive for common make arguments?If MAKEFLAGS starts with a long option containing 'n' (such as Kbuild's frequent default --no-print-directory), -$(MAKEFLAGS) evaluates to something like ---no-print-directory, and findstring erroneously matches the letter 'n'.
[...]
Quoted 2 lines
Is it possible to use the standard
Kbuildidiom here, like $(findstring n,$(filter-out --%,$(MAKEFLAGS))), to properly check the flags?
MAKEFLAGS does not start with a long option. With make 4.0 and later, which the kernel requires, its first word holds the single letter options and the long options follow after a space. With no single letter options, -$(MAKEFLAGS) starts with "- --no-print-directory" and the first word is "-". The top level Makefile detects -s the same way.
Under kbuild the first word is "-rR", as kbuild adds -rR to MAKEFLAGS. I checked with make 4.4.1, calling Makefile.kbuild from a parent that adds -rR --no-print-directory: dry-run is empty for a plain, -j, -k and -s build, and is "n" only with -n.
Signature · 2 lines
Thanks, Sasha
RFC PATCH v2 3/7 perf build: Add MINIMAL=1 to build without optional features
In reply to Sasha LevinTurning off every optional feature takes a long list of NO_* variables, and the list has to follow features as they are added and renamed. The one in tests/make for make_minimal has fallen behind: it leaves libtraceevent, jevents, slang, AIO, LZMA, zlib, libLLVM and Rust to be detected, so a make_minimal build still needs libtraceevent and python.
Add MINIMAL=1, which turns off every optional feature, the BPF skeletons and the shellcheck run. perf then builds, natively or cross, with no library beyond the C library and without python, pkg-config, clang or rustc, and the result does not depend on what is installed on the build machine.
A MINIMAL=1 build also leaves out the notices that post unwind and python support are disabled, which it asked for, and the one about the pkg-config search path for cross builds, as pkg-config is not needed then.
It is handled in Makefile.perf rather than Makefile.config, as Makefile.config is included after the pkg-config and shellcheck setup.
Use it for make_minimal in tests/make.
--- tools/perf/Makefile.config | 8 ++++++-- tools/perf/Makefile.perf | 40 ++++++++++++++++++++++++++++++++++++-- tools/perf/tests/make | 8 +------- 3 files changed, 45 insertions(+), 11 deletions(-)
tools/perf/Makefile.config +6 -2
@@ -742,7 +742,9 @@ dwarf-post-unwind-text := BUG # setup DWARF post unwinder ifdef NO_LIBUNWIND ifdef NO_LIBDW - $(warning Disabling post unwind, no support found.) + ifneq ($(MINIMAL),1) + $(warning Disabling post unwind, no support found.) + endif dwarf-post-unwind := 0 else dwarf-post-unwind-text := libdw
@@ -828,7 +830,9 @@ endef PYTHON_EXTENSION_SUFFIX := '.so' ifdef NO_LIBPYTHON - $(call disable-python,Python support disabled by user) + ifneq ($(MINIMAL),1) + $(call disable-python,Python support disabled by user) + endif else ifndef PYTHON
tools/perf/Makefile.perf +38 -2
@@ -129,6 +129,9 @@ include ../scripts/utilities.mak # Define GEN_VMLINUX_H to generate vmlinux.h from the BTF. # # Define NO_SHELLCHECK if you do not want to run shellcheck during build +# +# Define MINIMAL=1 to build without any optional feature, needing only a C +# compiler and library, flex and bison # As per kernel Makefile, avoid funny character set dependencies unexport LC_ALL
@@ -174,6 +177,37 @@ endef LD += $(EXTRA_LDFLAGS) +# MINIMAL=1 is handled here rather than in Makefile.config, which is included +# after the pkg-config and shellcheck setup below +ifeq ($(MINIMAL),1) + NO_LIBELF := 1 + NO_LIBDW := 1 + NO_LIBTRACEEVENT := 1 + NO_JEVENTS := 1 + NO_LIBPYTHON := 1 + NO_LIBBPF := 1 + BUILD_BPF_SKEL := 0 + NO_SLANG := 1 + NO_DEMANGLE := 1 + NO_BACKTRACE := 1 + NO_AIO := 1 + NO_ZLIB := 1 + NO_LZMA := 1 + NO_LIBZSTD := 1 + NO_LIBNUMA := 1 + NO_LIBLLVM := 1 + NO_CAPSTONE := 1 + NO_LIBPFM4 := 1 + NO_LIBDEBUGINFOD := 1 + NO_BABELTRACE2 := 1 + NO_SDT := 1 + NO_JVMTI := 1 + NO_RUST := 1 + NO_PERF_READ_VDSO32 := 1 + NO_PERF_READ_VDSOX32 := 1 + NO_SHELLCHECK := 1 +endif + # Some distros provide the command $(CROSS_COMPILE)pkg-config for # searching packges installed with Multiarch. Use it for cross # compilation if it is existed.
@@ -195,8 +229,10 @@ else PKG_CONFIG_LIBDIR := $(PKG_CONFIG_LIBDIR):/usr/local/share/pkgconfig/ PKG_CONFIG_LIBDIR := $(PKG_CONFIG_LIBDIR):/usr/share/pkgconfig/ export PKG_CONFIG_LIBDIR - $(warning Missing PKG_CONFIG_LIBDIR, PKG_CONFIG_PATH and PKG_CONFIG_SYSROOT_DIR for cross compilation,) - $(warning set PKG_CONFIG_LIBDIR for using Multiarch libs.) + ifneq ($(MINIMAL),1) + $(warning Missing PKG_CONFIG_LIBDIR, PKG_CONFIG_PATH and PKG_CONFIG_SYSROOT_DIR for cross compilation,) + $(warning set PKG_CONFIG_LIBDIR for using Multiarch libs.) + endif endif endif endif
tools/perf/tests/make +1 -7
@@ -115,13 +115,7 @@ make_install_prefix := install prefix=/tmp/krava make_install_prefix_slash := install prefix=/tmp/krava/ make_static := LDFLAGS=-static NO_PERF_READ_VDSO32=1 NO_PERF_READ_VDSOX32=1 NO_JVMTI=1 NO_LIBTRACEEVENT=1 NO_LIBELF=1 -# all the NO_* variable combined -make_minimal := NO_LIBPYTHON=1 -make_minimal += NO_DEMANGLE=1 NO_LIBELF=1 NO_BACKTRACE=1 -make_minimal += NO_LIBNUMA=1 NO_LIBBIONIC=1 NO_LIBDW=1 -make_minimal += NO_LIBBPF=1 -make_minimal += NO_SDT=1 NO_JVMTI=1 NO_LIBZSTD=1 -make_minimal += NO_CAPSTONE=1 +make_minimal := MINIMAL=1 # binutils 2_42 and newer have bfd_thread_init() new_libbfd := $(shell echo '#include <bfd.h>' | $(CC) -E -x c - | grep bfd_thread_init)
Signature · 1 line
2.53.0
Ian Rogers
reviewerRe: [RFC PATCH v2 3/7] perf build: Add MINIMAL=1 to build without optional features
Quoted 49 lines · Sasha Levin
Turning off every optional feature takes a long list of NO_* variables, and the list has to follow features as they are added and renamed. The one in tests/make for
make_minimalhas fallen behind: it leaves libtraceevent, jevents, slang, AIO, LZMA, zlib, libLLVM and Rust to be detected, so amake_minimalbuild still needs libtraceevent and python.Add MINIMAL=1, which turns off every optional feature, the BPF skeletons and the shellcheck run. perf then builds, natively or cross, with no library beyond the C library and without python, pkg-config, clang or rustc, and the result does not depend on what is installed on the build machine.
A MINIMAL=1 build also leaves out the notices that post unwind and python support are disabled, which it asked for, and the one about the pkg-config search path for cross builds, as pkg-config is not needed then.
It is handled in Makefile.perf rather than Makefile.config, as Makefile.config is included after the pkg-config and shellcheck setup.
Use it for
make_minimalin tests/make.Suggested-by Ian Rogers <[email protected]>Link https://lore.kernel.org/r/CAP-5=fWFY-tpJz2vcBZvurwdZY5gwd8cuTemE9q1rtZ0Vi0dng@mail.gmail.com open hereAssisted-by LLMSigned-off-by Sasha Levin <[email protected]>--- tools/perf/Makefile.config | 8 ++++++-- tools/perf/Makefile.perf | 40 ++++++++++++++++++++++++++++++++++++-- tools/perf/tests/make | 8 +------- 3 files changed, 45 insertions(+), 11 deletions(-)tools/perf/Makefile.config +3
-1@@ -742,7 +742,9 @@ dwarf-post-unwind-text := BUG # setup DWARF post unwinder ifdef NO_LIBUNWIND ifdef NO_LIBDW - $(warning Disabling post unwind, no support found.) + ifneq ($(MINIMAL),1) + $(warning Disabling post unwind, no support found.) + endif dwarf-post-unwind := 0 else dwarf-post-unwind-text := libdw
tools/perf/Makefile.config endef · line 835
Quoted 7 lines
tools/perf/Makefile.config +3
-1@@ -828,7 +830,9 @@ endef PYTHON_EXTENSION_SUFFIX := '.so' ifdef NO_LIBPYTHON - $(call disable-python,Python support disabled by user) + ifneq ($(MINIMAL),1) + $(call disable-python,Python support disabled by user) + endif
Thanks for the clean up!
In perf-tools-next/linux-next both LIBPYTHON and LIBPERL are gone
(context in https://lore.kernel.org/linux-perf-users/[email protected]/#t
).
Quoted 40 lines
tools/perf/Makefile.config +0
-0else ifndef PYTHONtools/perf/Makefile.perf +22
-0@@ -129,6 +129,9 @@ include ../scripts/utilities.mak # Define GEN_VMLINUX_H to generate vmlinux.h from the BTF. # # Define NO_SHELLCHECK if you do not want to run shellcheck during build +# +# Define MINIMAL=1 to build without any optional feature, needing only a C +# compiler and library, flex and bison # As per kernel Makefile, avoid funny character set dependencies unexport LC_ALL@@ -174,6 +177,37 @@ endef LD += $(EXTRA_LDFLAGS) +# MINIMAL=1 is handled here rather than in Makefile.config, which is included +# after the pkg-config and shellcheck setup below +ifeq ($(MINIMAL),1) + NO_LIBELF := 1 + NO_LIBDW := 1 + NO_LIBTRACEEVENT := 1 + NO_JEVENTS := 1 + NO_LIBPYTHON := 1 + NO_LIBBPF := 1 + BUILD_BPF_SKEL := 0 + NO_SLANG := 1 + NO_DEMANGLE := 1 + NO_BACKTRACE := 1 + NO_AIO := 1 + NO_ZLIB := 1 + NO_LZMA := 1 + NO_LIBZSTD := 1 + NO_LIBNUMA := 1 + NO_LIBLLVM := 1
tools/perf/Makefile.perf endef · line 208
Quoted 10 lines
tools/perf/Makefile.perf +10
-0+ NO_CAPSTONE := 1 + NO_LIBPFM4 := 1 + NO_LIBDEBUGINFOD := 1 + NO_BABELTRACE2 := 1 + NO_SDT := 1 + NO_JVMTI := 1 + NO_RUST := 1 + NO_PERF_READ_VDSO32 := 1 + NO_PERF_READ_VDSOX32 := 1 + NO_SHELLCHECK := 1
We should expand this with NO_MYPY and NO_PYLINT for the perf-tools-next version.
Thanks,
Ian
Quoted 40 lines
tools/perf/Makefile.perf +6
-2+endif + # Some distros provide the command $(CROSS_COMPILE)pkg-config for # searching packges installed with Multiarch. Use it for cross # compilation if it is existed.@@ -195,8 +229,10 @@ else PKG_CONFIG_LIBDIR := $(PKG_CONFIG_LIBDIR):/usr/local/share/pkgconfig/ PKG_CONFIG_LIBDIR := $(PKG_CONFIG_LIBDIR):/usr/share/pkgconfig/ export PKG_CONFIG_LIBDIR - $(warning Missing PKG_CONFIG_LIBDIR, PKG_CONFIG_PATH and PKG_CONFIG_SYSROOT_DIR for cross compilation,) - $(warning set PKG_CONFIG_LIBDIR for using Multiarch libs.) + ifneq ($(MINIMAL),1) + $(warning Missing PKG_CONFIG_LIBDIR, PKG_CONFIG_PATH and PKG_CONFIG_SYSROOT_DIR for cross compilation,) + $(warning set PKG_CONFIG_LIBDIR for using Multiarch libs.) + endif endif endif endiftools/perf/tests/make +1
-8@@ -115,13 +115,7 @@ make_install_prefix := install prefix=/tmp/krava make_install_prefix_slash := install prefix=/tmp/krava/ make_static := LDFLAGS=-static NO_PERF_READ_VDSO32=1 NO_PERF_READ_VDSOX32=1 NO_JVMTI=1 NO_LIBTRACEEVENT=1 NO_LIBELF=1 -# all the NO_* variable combined -make_minimal := NO_LIBPYTHON=1 -make_minimal += NO_DEMANGLE=1 NO_LIBELF=1 NO_BACKTRACE=1 -make_minimal += NO_LIBNUMA=1 NO_LIBBIONIC=1 NO_LIBDW=1 -make_minimal += NO_LIBBPF=1 -make_minimal += NO_SDT=1 NO_JVMTI=1 NO_LIBZSTD=1 -make_minimal += NO_CAPSTONE=1 +make_minimal := MINIMAL=1 # binutils 2_42 and newer have bfd_thread_init() new_libbfd := $(shell echo '#include <bfd.h>' | $(CC) -E -x c - | grep bfd_thread_init) --2.53.0
Re: [RFC PATCH v2 3/7] perf build: Add MINIMAL=1 to build without optional features
Quoted 3 lines · Ian Rogers
In perf-tools-next/linux-next both LIBPYTHON and LIBPERL are gone
(context in https://lore.kernel.org/linux-perf-users/[email protected]/#t
).
[...]
Quoted 2 lines
We should expand this with
NO_MYPYandNO_PYLINTfor the perf-tools-next version.
The series is based on mainline, which still has NO_LIBPYTHON and runs mypy and pylint only when asked to, so 3/7 only covers those knobs.
I sent the perf-tools-next version on its own: it uses NO_PYTHON_MODULE and also sets NO_MYPY and NO_PYLINT.
https://lore.kernel.org/r/[email protected]
Signature · 2 lines
Thanks, Sasha
Re: [RFC PATCH v2 3/7] perf build: Add MINIMAL=1 to build without optional features
Quoted 8 lines · Sasha Levin
Quoted 3 lines · Ian Rogers
In perf-tools-next/linux-next both LIBPYTHON and LIBPERL are gone
(context in https://lore.kernel.org/linux-perf-users/[email protected]/#t
).[...]
Quoted 2 lines
We should expand this with
NO_MYPYandNO_PYLINTfor the perf-tools-next version.
Quoted 7 lines
The series is based on mainline, which still has
NO_LIBPYTHONand runs mypy and pylint only when asked to, so 3/7 only covers those knobs.I sent the perf-tools-next version on its own: it uses
NO_PYTHON_MODULEand also setsNO_MYPYandNO_PYLINT.
I've acked that, but in case you need it here:
Thanks,
Namhyung
[email protected]
AI reviewRe: [RFC PATCH v2 3/7] perf build: Add MINIMAL=1 to build without optional features
In reply to Sasha LevinSashiko has reviewed this patch and found no issues.
Quoted 20 lines
Turning off every optional feature takes a long list of NO_* variables, and the list has to follow features as they are added and renamed. The one in tests/make for
make_minimalhas fallen behind: it leaves libtraceevent, jevents, slang, AIO, LZMA, zlib, libLLVM and Rust to be detected, so amake_minimalbuild still needs libtraceevent and python.Add MINIMAL=1, which turns off every optional feature, the BPF skeletons and the shellcheck run. perf then builds, natively or cross, with no library beyond the C library and without python, pkg-config, clang or rustc, and the result does not depend on what is installed on the build machine.
A MINIMAL=1 build also leaves out the notices that post unwind and python support are disabled, which it asked for, and the one about the pkg-config search path for cross builds, as pkg-config is not needed then.
It is handled in Makefile.perf rather than Makefile.config, as Makefile.config is included after the pkg-config and shellcheck setup.
Quoted 6 lines
Use it for
make_minimalin tests/make.Suggested-by Ian Rogers <[email protected]>Link https://lore.kernel.org/r/CAP-5=fWFY-tpJz2vcBZvurwdZY5gwd8cuTemE9q1rtZ0Vi0dng@mail.gmail.com open hereAssisted-by LLMSigned-off-by Sasha Levin <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
RFC PATCH v2 4/7 tools: build perf in tools_build
In reply to Sasha LevinAdd CONFIG_TOOLS_BUILD_PERF. perf is built as it is built standalone, with optional features enabled when their libraries are installed, and with perf's WERROR setting following CONFIG_WERROR. The feature table is left out of the kernel build log.
CONFIG_TOOLS_BUILD_PERF_MINIMAL builds it with MINIMAL=1 instead, which turns every optional feature off, so the result does not depend on the build machine. allmodconfig and allyesconfig turn it on.
--- tools/Kconfig | 16 ++++++++++++++++ tools/Makefile.kbuild | 10 ++++++++++ 2 files changed, 26 insertions(+)
tools/Kconfig +16 -0
@@ -60,6 +60,22 @@ config TOOLS_BUILD_IIO help Build tools/iio (lsiio, iio_event_monitor, iio_generic_buffer). +config TOOLS_BUILD_PERF + bool "perf" + help + Build tools/perf. As in a standalone perf build, optional + features are enabled when the libraries they need are installed. + +config TOOLS_BUILD_PERF_MINIMAL + bool "Build perf with all optional features disabled" + depends on TOOLS_BUILD_PERF + help + Build perf with MINIMAL=1, which turns off every optional + feature, so that the result does not depend on which libraries + the build machine has installed. allmodconfig and allyesconfig + turn this on, which keeps their builds the same on every + machine. + config TOOLS_BUILD_SPI bool "SPI tools" help
tools/Makefile.kbuild +10 -0
@@ -79,6 +79,16 @@ PHONY += $(tool-targets) $(tool-targets): tool-%: FORCE $(call build,$(outdir)/$*,-C $(toolsdir)/$* O=$(outdir)/$* CC='$(call escsq,$(tools-cc))',,TOOLS_BUILD_$(shell echo $* | tr a-z A-Z)) +# perf, without the feature table in the kernel build log +perf-flags := CC='$(call escsq,$(tools-cc))' FEATURE_DISPLAY= WERROR=$(if $(CONFIG_WERROR),1,0) +perf-flags-$(CONFIG_TOOLS_BUILD_PERF_MINIMAL) += MINIMAL=1 + +__tools_build: $(if $(CONFIG_TOOLS_BUILD_PERF),perf) + +PHONY += perf +perf: FORCE + $(call build,$(outdir)/perf,-C $(toolsdir)/perf -f Makefile.perf O=$(outdir)/perf $(perf-flags) $(perf-flags-y),,TOOLS_BUILD_PERF) + PHONY += FORCE FORCE:
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [RFC PATCH v2 4/7] tools: build perf in tools_build
Sashiko has reviewed this patch and found no issues.
Quoted 11 lines
Add
CONFIG_TOOLS_BUILD_PERF. perf is built as it is built standalone, with optional features enabled when their libraries are installed, and with perf's WERROR setting followingCONFIG_WERROR. The feature table is left out of the kernel build log.
CONFIG_TOOLS_BUILD_PERF_MINIMALbuilds it with MINIMAL=1 instead, which turns every optional feature off, so the result does not depend on the build machine. allmodconfig and allyesconfig turn it on.Assisted-by LLMSigned-off-by Sasha Levin <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
Re: [RFC PATCH v2 4/7] tools: build perf in tools_build
In reply to Sasha LevinQuoted 11 lines · Sasha Levin
Add
CONFIG_TOOLS_BUILD_PERF. perf is built as it is built standalone, with optional features enabled when their libraries are installed, and with perf's WERROR setting followingCONFIG_WERROR. The feature table is left out of the kernel build log.
CONFIG_TOOLS_BUILD_PERF_MINIMALbuilds it with MINIMAL=1 instead, which turns every optional feature off, so the result does not depend on the build machine. allmodconfig and allyesconfig turn it on.Assisted-by LLMSigned-off-by Sasha Levin <[email protected]>
Thanks,
Namhyung
Quoted 56 lines
--- tools/Kconfig | 16 ++++++++++++++++ tools/Makefile.kbuild | 10 ++++++++++ 2 files changed, 26 insertions(+)tools/Kconfig +16
-0@@ -60,6 +60,22 @@ config TOOLS_BUILD_IIO help Build tools/iio (lsiio, iio_event_monitor, iio_generic_buffer). +config TOOLS_BUILD_PERF + bool "perf" + help + Build tools/perf. As in a standalone perf build, optional + features are enabled when the libraries they need are installed. + +config TOOLS_BUILD_PERF_MINIMAL + bool "Build perf with all optional features disabled" + depends on TOOLS_BUILD_PERF + help + Build perf with MINIMAL=1, which turns off every optional + feature, so that the result does not depend on which libraries + the build machine has installed. allmodconfig and allyesconfig + turn this on, which keeps their builds the same on every + machine. + config TOOLS_BUILD_SPI bool "SPI tools" helptools/Makefile.kbuild +10
-0@@ -79,6 +79,16 @@ PHONY += $(tool-targets) $(tool-targets): tool-%: FORCE $(call build,$(outdir)/$*,-C $(toolsdir)/$* O=$(outdir)/$* CC='$(call escsq,$(tools-cc))',,TOOLS_BUILD_$(shell echo $* | tr a-z A-Z)) +# perf, without the feature table in the kernel build log +perf-flags := CC='$(call escsq,$(tools-cc))' FEATURE_DISPLAY= WERROR=$(if $(CONFIG_WERROR),1,0) +perf-flags-$(CONFIG_TOOLS_BUILD_PERF_MINIMAL) += MINIMAL=1 + +__tools_build: $(if $(CONFIG_TOOLS_BUILD_PERF),perf) + +PHONY += perf +perf: FORCE + $(call build,$(outdir)/perf,-C $(toolsdir)/perf -f Makefile.perf O=$(outdir)/perf $(perf-flags) $(perf-flags-y),,TOOLS_BUILD_PERF) + PHONY += FORCE FORCE:Signature · 1 line
2.53.0
RFC PATCH v2 5/7 tools: build kernel selftests in tools_build
In reply to Sasha LevinAdd a "Kernel selftests" sub-menu with one entry per selftests directory that builds with only a C library and does not write into the source tree. Each is built as "make kselftest-all" builds it, with KHDR_INCLUDES pointing at the UAPI headers installed in the object tree, but by its own make, so the selected ones build in parallel. Selftests whose Makefile does not use KHDR_INCLUDES still build against the C library's copy of the UAPI headers.
As with "make kselftest-all", a selftest that fails to build does not fail the build unless FORCE_TARGETS is set. kselftest_deps.sh then lists the libraries the selftest needs that the compiler cannot link with.
The selftests do not track header dependencies, so a selftest is built again from scratch when its own directory, a header or makefile any selftest may share, or the kernel sources and headers it includes (the vDSO test includes the architecture's vDSO code) are newer than its last build.
Selftests that need libraries beyond the C library, a vmlinux with BTF, or a sanitizer runtime are left out for now.
--- tools/Kconfig | 241 ++++++++++++++++++++++++++++++++++++++++++ tools/Makefile.kbuild | 118 ++++++++++++++++++++- 2 files changed, 355 insertions(+), 4 deletions(-)
tools/Kconfig +241 -0
@@ -86,4 +86,245 @@ config TOOLS_BUILD_USB help Build tools/usb (testusb, ffs-test). +menuconfig TOOLS_BUILD_SELFTESTS + bool "Kernel selftests" + help + Build the selected targets under tools/testing/selftests, as + "make kselftest-all" would, without running them. As there, a + selftest that fails to build does not fail the build unless + FORCE_TARGETS=1 is passed to make. + +if TOOLS_BUILD_SELFTESTS + +config TOOLS_BUILD_SELFTESTS_ACCT + bool "acct" + +config TOOLS_BUILD_SELFTESTS_ALLOC_TAG + bool "alloc_tag" + +config TOOLS_BUILD_SELFTESTS_BREAKPOINTS + bool "breakpoints" + +config TOOLS_BUILD_SELFTESTS_CACHESTAT + bool "cachestat" + +config TOOLS_BUILD_SELFTESTS_CGROUP + bool "cgroup" + +config TOOLS_BUILD_SELFTESTS_CONNECTOR + bool "connector" + +config TOOLS_BUILD_SELFTESTS_CORE + bool "core" + +config TOOLS_BUILD_SELFTESTS_COREDUMP + bool "coredump" + +config TOOLS_BUILD_SELFTESTS_DAMON + bool "damon" + +config TOOLS_BUILD_SELFTESTS_DMABUF_HEAPS + bool "dmabuf-heaps" + +config TOOLS_BUILD_SELFTESTS_DRIVERS_DMA_BUF + bool "drivers/dma-buf" + +config TOOLS_BUILD_SELFTESTS_DRIVERS_NTSYNC + bool "drivers/ntsync" + +config TOOLS_BUILD_SELFTESTS_EFIVARFS + bool "efivarfs" + +config TOOLS_BUILD_SELFTESTS_FILELOCK + bool "filelock" + +config TOOLS_BUILD_SELFTESTS_FILESYSTEMS_BINDERFS + bool "filesystems/binderfs" + +config TOOLS_BUILD_SELFTESTS_FILESYSTEMS_EPOLL + bool "filesystems/epoll" + +config TOOLS_BUILD_SELFTESTS_FILESYSTEMS_EVENTFD + bool "filesystems/eventfd" + +config TOOLS_BUILD_SELFTESTS_FILESYSTEMS_FAILFS + bool "filesystems/failfs" + +config TOOLS_BUILD_SELFTESTS_FILESYSTEMS_FAT + bool "filesystems/fat" + +config TOOLS_BUILD_SELFTESTS_FILESYSTEMS_MNTNS_UNBINDABLE + bool "filesystems/mntns_unbindable" + +config TOOLS_BUILD_SELFTESTS_FILESYSTEMS_MOUNT_CYCLE + bool "filesystems/mount_cycle" + +config TOOLS_BUILD_SELFTESTS_FILESYSTEMS_NSFS + bool "filesystems/nsfs" + +config TOOLS_BUILD_SELFTESTS_FILESYSTEMS_UMOUNT_PROPAGATION + bool "filesystems/umount_propagation" + +config TOOLS_BUILD_SELFTESTS_FILESYSTEMS_XATTR + bool "filesystems/xattr" + +config TOOLS_BUILD_SELFTESTS_FIRMWARE + bool "firmware" + +config TOOLS_BUILD_SELFTESTS_FPU + bool "fpu" + +config TOOLS_BUILD_SELFTESTS_FTRACE + bool "ftrace" + +config TOOLS_BUILD_SELFTESTS_GPIO + bool "gpio" + +config TOOLS_BUILD_SELFTESTS_INTEL_PSTATE + bool "intel_pstate" + depends on X86 + +config TOOLS_BUILD_SELFTESTS_IPC + bool "ipc" + +config TOOLS_BUILD_SELFTESTS_IR + bool "ir" + +config TOOLS_BUILD_SELFTESTS_KCMP + bool "kcmp" + +config TOOLS_BUILD_SELFTESTS_KEXEC + bool "kexec" + depends on X86_64 + +config TOOLS_BUILD_SELFTESTS_KSELFTEST_HARNESS + bool "kselftest_harness" + +config TOOLS_BUILD_SELFTESTS_LSM + bool "lsm" + +config TOOLS_BUILD_SELFTESTS_MEDIA_TESTS + bool "media_tests" + +config TOOLS_BUILD_SELFTESTS_MEMBARRIER + bool "membarrier" + +config TOOLS_BUILD_SELFTESTS_MINCORE + bool "mincore" + +config TOOLS_BUILD_SELFTESTS_MOUNT + bool "mount" + +config TOOLS_BUILD_SELFTESTS_MOUNT_SETATTR + bool "mount_setattr" + +config TOOLS_BUILD_SELFTESTS_MOVE_MOUNT_SET_GROUP + bool "move_mount_set_group" + +config TOOLS_BUILD_SELFTESTS_MSEAL_SYSTEM_MAPPINGS + bool "mseal_system_mappings" + +config TOOLS_BUILD_SELFTESTS_NCI + bool "nci" + +config TOOLS_BUILD_SELFTESTS_NET_CAN + bool "net/can" + +config TOOLS_BUILD_SELFTESTS_NET_FORWARDING + bool "net/forwarding" + +config TOOLS_BUILD_SELFTESTS_NET_MPTCP + bool "net/mptcp" + +config TOOLS_BUILD_SELFTESTS_PCI_ENDPOINT + bool "pci_endpoint" + +config TOOLS_BUILD_SELFTESTS_PERF_EVENTS + bool "perf_events" + +config TOOLS_BUILD_SELFTESTS_PID_NAMESPACE + bool "pid_namespace" + +config TOOLS_BUILD_SELFTESTS_PIDFD + bool "pidfd" + +config TOOLS_BUILD_SELFTESTS_PIPE + bool "pipe" + +config TOOLS_BUILD_SELFTESTS_PROC + bool "proc" + +config TOOLS_BUILD_SELFTESTS_PTP + bool "ptp" + +config TOOLS_BUILD_SELFTESTS_PTRACE + bool "ptrace" + +config TOOLS_BUILD_SELFTESTS_RESCTRL + bool "resctrl" + depends on X86 + +config TOOLS_BUILD_SELFTESTS_RING_BUFFER + bool "ring-buffer" + +config TOOLS_BUILD_SELFTESTS_RLIMITS + bool "rlimits" + +config TOOLS_BUILD_SELFTESTS_RSEQ + bool "rseq" + +config TOOLS_BUILD_SELFTESTS_RTC + bool "rtc" + +config TOOLS_BUILD_SELFTESTS_SCHED + bool "sched" + +config TOOLS_BUILD_SELFTESTS_SIGNAL + bool "signal" + +config TOOLS_BUILD_SELFTESTS_SIZE + bool "size" + +config TOOLS_BUILD_SELFTESTS_SPLICE + bool "splice" + +config TOOLS_BUILD_SELFTESTS_SYNC + bool "sync" + +config TOOLS_BUILD_SELFTESTS_SYSCALL_USER_DISPATCH + bool "syscall_user_dispatch" + +config TOOLS_BUILD_SELFTESTS_TDX + bool "tdx" + depends on X86 + +config TOOLS_BUILD_SELFTESTS_THERMAL_INTEL_POWER_FLOOR + bool "thermal/intel/power_floor" + depends on X86 + +config TOOLS_BUILD_SELFTESTS_THERMAL_INTEL_WORKLOAD_HINT + bool "thermal/intel/workload_hint" + depends on X86 + +config TOOLS_BUILD_SELFTESTS_TIMENS + bool "timens" + +config TOOLS_BUILD_SELFTESTS_TMPFS + bool "tmpfs" + +config TOOLS_BUILD_SELFTESTS_USER_EVENTS + bool "user_events" + +config TOOLS_BUILD_SELFTESTS_VDSO + bool "vDSO" + +config TOOLS_BUILD_SELFTESTS_WATCHDOG + bool "watchdog" + +config TOOLS_BUILD_SELFTESTS_X86 + bool "x86" + depends on X86 + +endif # TOOLS_BUILD_SELFTESTS + endif # TOOLS_BUILD
tools/Makefile.kbuild +114 -4
137 lines not on this page · raw message
Signature · 1 line
2.53.0
Re: [RFC PATCH v2 5/7] tools: build kernel selftests in tools_build
Quoted 18 lines · Sasha Levin
Add a "Kernel selftests" sub-menu with one entry per selftests directory that builds with only a C library and does not write into the source tree. Each is built as "make kselftest-all" builds it, with
KHDR_INCLUDESpointing at the UAPI headers installed in the object tree, but by its own make, so the selected ones build in parallel. Selftests whoseMakefiledoes not useKHDR_INCLUDESstill build against the C library's copy of the UAPI headers.As with "make kselftest-all", a selftest that fails to build does not fail the build unless
FORCE_TARGETSis set.kselftest_deps.shthen lists the libraries the selftest needs that the compiler cannot link with.The selftests do not track header dependencies, so a selftest is built again from scratch when its own directory, a header or makefile any selftest may share, or the kernel sources and headers it includes (the vDSO test includes the architecture's vDSO code) are newer than its last build.
Quoted 5 lines
Selftests that need libraries beyond the C library, a vmlinux with BTF, or a sanitizer runtime are left out for now.
Assisted-by LLMSigned-off-by Sasha Levin <[email protected]>
Thank you.
thanks,
-- Shuah
[email protected]
AI reviewRe: [RFC PATCH v2 5/7] tools: build kernel selftests in tools_build
In reply to Sasha LevinThank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [High] build: Fatal Make syntax error on empty target variables in static pattern rules - [Medium]…
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] build: Fatal Make syntax error on empty target variables in static pattern rules
- [Medium] selftests: kexec Kconfig unnecessarily restricted to X86_64
- [Medium] kbuild: missing dependencies on scripts/ Makefiles for selftests rebuilds --
commit f8d06182dd0adbe69406863fbe53894162f78089
Author: Sasha Levin <[email protected]>
Subject: tools: build kernel selftests in tools_build
This commit adds a "Kernel selftests" sub-menu to the tools build framework, allowing selftests to be built without writing to the source tree. Each selftest runs under its own make instance, enabling parallel builds using a pre-installed C library and UAPI headers. Rebuild dependencies are handled by tracking timestamps of shared files and headers since selftests do not natively track header dependencies.
Quoted 3 lines
tools/Kconfig +0
-0
[ ... ]
tools/Kconfig config TOOLS_BUILD_USB · line 198
Quoted 3 lines
tools/Kconfig +3
-0+config TOOLS_BUILD_SELFTESTS_KEXEC + bool "kexec" + depends on X86_64
[Severity: Medium]
Does this unnecessarily restrict the kexec selftest to X86_64?
Looking at tools/testing/selftests/kexec/Makefile, it explicitly supports both x86 (32-bit and 64-bit) and ppc64le:
ifeq ($(ARCH_PROCESSED),$(filter $(ARCH_PROCESSED),x86 ppc64le)) TEST_PROGS := test_kexec_load.sh test_kexec_file_load.sh TEST_FILES := kexec_common_lib.sh
Configuring the tools build on ppc64le or 32-bit x86 will not expose this option, silently excluding the test from being built and installed on these platforms.
[ ... ]
Quoted 3 lines
tools/Makefile.kbuild +0
-0
[ ... ]
tools/Makefile.kbuild PHONY += perf · line 184
Quoted 6 lines
+$(selftest-shared): FORCE
tools/Makefile.kbuild +5
-0+ $(Q)mkdir -p $(@D); \ + newest=$$(find $(CURDIR)/usr/include $(toolsdir)/include $(toolsdir)/arch $(toolsdir)/testing/selftests \ + -type f \( -name '*.h' -o -name '*.mk' -o -name Makefile \) -printf '%T@\n' | \ + sort -n | tail -n 1); \ + touch -d "@$${newest:-0}" $@
[Severity: Medium]
Will this miss rebuild dependencies on shared build scripts?
The find command omits the tools/scripts/ and scripts/ directories, and its filters exclude files named Makefile.* or *.include.
Modifying core shared files like tools/scripts/Makefile.include, tools/scripts/Makefile.arch, or scripts/subarch.include will not trigger a rebuild of selftests that include them, which can lead to stale builds.
Quoted 6 lines
tools/Makefile.kbuild +6
-0+ +# As with "make kselftest-all", a selftest that fails to build does not fail +# the build unless FORCE_TARGETS is set. kselftest_deps.sh lists the libraries +# it needs that the compiler cannot link with. It leaves files behind in +# TMPDIR, so it gets one of its own. +selftest-failed = (cd $(toolsdir)/testing/selftests && tmp=$$(mktemp -d) && \
tools/Makefile.kbuild PHONY += perf · line 200
Quoted 10 lines
tools/Makefile.kbuild +10
-0+ TMPDIR=$$tmp ./kselftest_deps.sh '$(call escsq,$(tools-cc))' $(1) | grep '^FAIL' >&2; \ + rm -rf "$$tmp"); $(if $(FORCE_TARGETS),false,:) + +selftest-targets := $(addprefix selftest-,$(selftests-y)) + +__tools_build: $(selftest-targets) + +PHONY += $(selftest-targets) +$(selftest-targets): selftest-%: $(selftest-shared) FORCE + $(call build,$(outdir)/selftests/$*,-C $(toolsdir)/testing/selftests/$* OUTPUT=$(outdir)/selftests/$* $(selftest-flags),$(selftest-shared) $(toolsdir)/testing/selftests/$* $(selftest-extra-$*),TOOLS_BUILD_SELFTESTS_$(shell echo $* | tr a-z/- A-Z__),$(call selftest-failed,$*))
[Severity: High]
Can this trigger a fatal Make syntax error if no selftests are selected?
If a user enables the tools build selftests option but disables all individual selftests, $(selftests-y) and $(selftest-targets) will be empty.
Since this rule uses two colons, it is a static pattern rule. While GNU Make ignores empty targets for single-colon rules, an empty target list in a double-colon static pattern rule evaluates to : selftest-%: ... and triggers a fatal missing target pattern. Stop. build error.
The same issue would apply to the $(tool-targets): tool-%: FORCE rule if the tools build is enabled but no individual tools are selected.
Should these static pattern rules be guarded with an ifneq check (e.g., ifneq ($(selftest-targets),)) to prevent breaking the build on minimal configurations?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
Re: [RFC PATCH v2 5/7] tools: build kernel selftests in tools_build
Quoted 9 lines · On Sat, Oct 17, 2026 at 02:32:12PM +0000, [email protected] wrote:
tools/Kconfig config TOOLS_BUILD_USB · line 198
Quoted 3 lines
tools/Kconfig +3
-0+config TOOLS_BUILD_SELFTESTS_KEXEC + bool "kexec" + depends on X86_64[Severity: Medium]
Does this unnecessarily restrict the kexec selftest toX86_64?Looking at
tools/testing/selftests/kexec/Makefile, it explicitly supports both x86 (32-bit and 64-bit) and ppc64le:
[...]
Quoted 3 lines
Configuring the tools build on ppc64le or 32-bit x86 will not expose this option, silently excluding the test from being built and installed on these platforms.
TOOLS_BUILD is only available on x86_64 and arm64 for now (TOOLS_BUILD_ABI), so no entry can be selected on ppc64le or 32-bit x86. The kexec Makefile has no tests for arm64, which leaves x86_64.
Quoted 9 lines
tools/Makefile.kbuild PHONY += perf · line 184
Quoted 6 lines
+$(selftest-shared): FORCE
tools/Makefile.kbuild +5
-0+ $(Q)mkdir -p $(@D); \ + newest=$$(find $(CURDIR)/usr/include $(toolsdir)/include $(toolsdir)/arch $(toolsdir)/testing/selftests \ + -type f \( -name '*.h' -o -name '*.mk' -o -name Makefile \) -printf '%T@\n' | \ + sort -n | tail -n 1); \ + touch -d "@$${newest:-0}" $@[Severity: Medium]
Will this miss rebuild dependencies on shared build scripts?
[...]
Quoted 3 lines
Modifying core shared files like
tools/scripts/Makefile.include,tools/scripts/Makefile.arch, orscripts/subarch.includewill not trigger a rebuild of selftests that include them, which can lead to stale builds.
Right. Of the selftests built here, kexec and vDSO include tools/scripts/Makefile.arch and rseq includes scripts/subarch.include, and neither file is checked. I'll add both in the next version.
Quoted 2 lines
[Severity: High]
Can this trigger a fatal Make syntax error if no selftests are selected?
[...]
Quoted 4 lines
Since this rule uses two colons, it is a static pattern rule. While GNU Make ignores empty targets for single-colon rules, an empty target list in a double-colon static pattern rule evaluates to : selftest-%: ... and triggers a fatal missing target pattern. Stop. build error.
This is not a double-colon rule, and make ignores a static pattern rule whose target list is empty. With CONFIG_TOOLS_BUILD=y and no tool or selftest selected, Makefile.kbuild runs with make 4.4.1 and reports nothing to be done for __tools_build, with and without -n.
Signature · 2 lines
Thanks, Sasha
RFC PATCH v2 6/7 kbuild: build the tools selected in tools/Kconfig as part of "make all"
In reply to Sasha LevinWith CONFIG_TOOLS_BUILD set, make "all" depend on tools_build, so the selected tools are built with every kernel build, and allmodconfig and allyesconfig builds catch changes that break them.
"make vmlinux", "make modules", single target and external module builds are unaffected.
--- Makefile | 4 ++++ 1 file changed, 4 insertions(+)
Makefile +4 -0
@@ -1638,6 +1638,10 @@ PHONY += tools_build tools_build: headers $(Q)$(MAKE) -f $(srctree)/tools/Makefile.kbuild +ifdef CONFIG_TOOLS_BUILD +all: tools_build +endif + # --------------------------------------------------------------------------- # Kernel selftest
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [RFC PATCH v2 6/7] kbuild: build the tools selected in tools/Kconfig as part of "make all"
Sashiko has reviewed this patch and found no issues.
Quoted 9 lines
With
CONFIG_TOOLS_BUILDset, make "all" depend ontools_build, so the selected tools are built with every kernel build, and allmodconfig and allyesconfig builds catch changes that break them."make vmlinux", "make modules", single target and external module builds are unaffected.
Assisted-by LLMSigned-off-by Sasha Levin <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
RFC PATCH v2 7/7 Documentation: describe building tools with the kernel
In reply to Sasha LevinMention CONFIG_TOOLS_BUILD and "make tools_build" in the submit checklist, ask for libc-only selftests to be added to tools/Kconfig, and note that USERCFLAGS and USERLDFLAGS also apply to the tools.
--- Documentation/dev-tools/kselftest.rst | 4 ++++ Documentation/kbuild/kbuild.rst | 4 +++- Documentation/process/submit-checklist.rst | 5 +++++ 3 files changed, 12 insertions(+), 1 deletion(-)
Documentation/dev-tools/kselftest.rst +4 -0
@@ -315,6 +315,10 @@ Contributing new tests (details) TARGETS += android + * If the test builds with only a C library, add an entry for it to the + "Kernel selftests" menu in tools/Kconfig and to tools/Makefile.kbuild, + so that it is built together with the kernel. + * All changes should pass:: kselftest-{all,install,clean,gen_tar}
Documentation/kbuild/kbuild.rst +3 -1
@@ -114,12 +114,14 @@ Additional libraries to link against when building host programs. USERCFLAGS ---------- -Additional options used for $(CC) when compiling userprogs. +Additional options used for $(CC) when compiling userprogs and the tools +selected in tools/Kconfig. USERLDFLAGS ----------- Additional options used for $(LD) when linking userprogs. userprogs are linked with CC, so $(USERLDFLAGS) should include "-Wl," prefix as applicable. +The tools selected in tools/Kconfig get these options in LDFLAGS. KBUILD_KCONFIG --------------
Documentation/process/submit-checklist.rst +5 -0
@@ -91,6 +91,11 @@ Build your code Use ``make htmldocs`` or ``make pdfdocs`` to check the build and fix any issues. + e) Changes to tools/ or to UAPI headers do not break the userspace tools + selected by ``CONFIG_TOOLS_BUILD``. ``allmodconfig`` turns it on when + the compiler can link glibc programs for the target (currently x86_64 + and arm64), and ``make tools_build`` builds only the tools. + 2) Builds on multiple CPU architectures by using local cross-compile tools or some other build farm. Note that testing against architectures of different word sizes
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [RFC PATCH v2 7/7] Documentation: describe building tools with the kernel
Sashiko has reviewed this patch and found no issues.
Quoted 6 lines
Mention
CONFIG_TOOLS_BUILDand "maketools_build" in the submit checklist, ask for libc-only selftests to be added totools/Kconfig, and note that USERCFLAGS and USERLDFLAGS also apply to the tools.Assisted-by LLMSigned-off-by Sasha Levin <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=7
Quoted 11 lines · Sasha Levin
The userspace programs under
tools/are disconnected from the rest of the kernel's build system. Each has its own makefiles and build framework, and "make" never builds them: apart from the few host tools the build itself needs, such as objtool andresolve_btfids, nothing undertools/is compiled as part of a kernel build.That makes them easy to break. Most people, and most of the build bots, check a change with "make allmodconfig && make", which doesn't cover
tools/at all. A change that breaks a tool passes every build check and is only noticed when someone happens to build that tool by hand, often much later.
Quoted 4 lines
We keep seeing this in
tools/testing/: selftests that stop building after a change elsewhere in the tree, or after a backport to a stable tree, and stay broken until someone tries to build them. Others brought up the same concern at LPC. [...]
I noticed that "keeps what is built the same on every machine" in 3/6. But is it explained anywhere why this is the done?
I wonder, as the overall goal of this patch set is to increase build coverage. So why disable optional features that could be built on machines that have the required userland libs installed?
Isn't that in a very limited scope what we do for the kernel itself already, as some small aspects of the build environment (like the versions of gcc or rust installed or the availability of things like gcc-plugins) already influence somewhat what is built when you run "make allmodconfig all"? Or do I misremember this bit?
Anyway: many thx for this, as I occasionally run into issues with my builds of linux-next and stable-rc rpms when while building perf or selftests -- and thx to these patches, submitters with a bit of luck in the future will notice more of those problems themselves. :-D
Ciao, Thorsten
Quoted 6 lines · Thorsten Leemhuis
I noticed that "keeps what is built the same on every machine" in 3/6. But is it explained anywhere why this is the done?
I wonder, as the overall goal of this patch set is to increase build coverage. So why disable optional features that could be built on machines that have the required userland libs installed?
Only allmodconfig and allyesconfig turn TOOLS_BUILD_PERF_MINIMAL on. It is off by default, and then perf is built as a standalone build would build it, with every feature whose libraries are installed.
For allmodconfig the main reason is that perf's feature detection does not always turn a feature off when its library is missing: without libelf, libtraceevent, pkg-config, or python for jevents, the build stops with an error. Building perf with everything it detects would make those a requirement for "make allmodconfig all" on every machine, and cross builds would fail unless the target's libraries are installed as well.
The rest is about reproducing failures: when a bot reports that allmodconfig breaks perf, the same build should break on the developer's machine too, whatever libraries it has.
Quoted 5 lines
Isn't that in a very limited scope what we do for the kernel itself already, as some small aspects of the build environment (like the versions of gcc or rust installed or the availability of things like gcc-plugins) already influence somewhat what is built when you run "make allmodconfig all"? Or do I misremember this bit?
You remember it right. The difference is that Kconfig probes for those, so a missing tool turns the option off rather than failing the build, and the result is recorded in .config.
That is how I'd like to add the selftests that need libraries: a Kconfig probe per library, so allmodconfig builds them where the libraries are installed and .config says which ones were built.
Signature · 2 lines
Thanks, Sasha
Quoted 5 lines · Sasha Levin
On Tue, Oct 20, 2026 at 01:52:17PM +0200, Thorsten Leemhuis wrote:
For allmodconfig the main reason is that perf's feature detection does not always turn a feature off when its library is missing: [...]
Quoted 7 lines
You remember it right. The difference is that
Kconfigprobes for those, so a missing tool turns the option off rather than failing the build, and the result is recorded in .config.That is how I'd like to add the selftests that need libraries: a
Kconfigprobe per library, so allmodconfig builds them where the libraries are installed and .config says which ones were built.
Okay, now this makes more sense to me, many thx for taking the time for a reply!
Ciao, Thorsten