Linux Perf Users
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Sasha Levin" <sashal@kernel.org>,
	"Nathan Chancellor" <nathan@kernel.org>,
	"Nicolas Schier" <nsc@kernel.org>,
	linux-kbuild@vger.kernel.org
Cc: "Shuah Khan" <shuah@kernel.org>,
	"Peter Zijlstra" <peterz@infradead.org>,
	"Ingo Molnar" <mingo@redhat.com>,
	"Arnaldo Carvalho de Melo" <acme@kernel.org>,
	"Namhyung Kim" <namhyung@kernel.org>,
	"Mark Rutland" <mark.rutland@arm.com>,
	"Alexander Shishkin" <alexander.shishkin@linux.intel.com>,
	"Jiri Olsa" <jolsa@kernel.org>, "Ian Rogers" <irogers@google.com>,
	"Adrian Hunter" <adrian.hunter@intel.com>,
	"James Clark" <james.clark@linaro.org>,
	linux-perf-users@vger.kernel.org,
	"Thomas Weißschuh" <linux@weissschuh.net>,
	"Andrew Morton" <akpm@linux-foundation.org>,
	"Thorsten Leemhuis" <linux@leemhuis.info>
Subject: Re: [PATCH v3 6/7] kbuild: build the tools selected in tools/Kconfig as part of "make all"
Date: Tue, 03 Nov 2026 02:13:25 +0000	[thread overview]
Message-ID: <sashiko-outbox-194454@kernel.org> (raw)
In-Reply-To: <20261102021253.2545235-7-sashal@kernel.org>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [Medium] kbuild: selftest-vDSO spawns recursive make headers during parallel make all
- [Medium] kbuild: unfiltered find in tools_build wipes selftest-vDSO on in-tree make all
- [Medium] kbuild: make -n all fails in tools_build when CONFIG_TOOLS_BUILD_PERF is set
--

commit 77668b75cf4c2802e979bfdc034af230364fe4c5
Author: Sasha Levin <sashal@kernel.org>

kbuild: build the tools selected in tools/Kconfig as part of "make all"

This commit makes the top-level all target depend on tools_build when
CONFIG_TOOLS_BUILD is enabled so that selected tools in tools/Kconfig are
built during standard kernel builds.

> diff --git a/Makefile b/Makefile
> index 7919263484f0a..2a69f4c73a641 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -1650,6 +1650,10 @@ PHONY += tools_build
>  tools_build: headers
>  	$(Q)$(MAKE) -f $(srctree)/tools/Makefile.kbuild
>  
> +ifdef CONFIG_TOOLS_BUILD
> +all: tools_build
> +endif

[Severity: Medium]
When running a parallel make all on x86_64 with CONFIG_TOOLS_BUILD=y,
CONFIG_TOOLS_BUILD_SELFTESTS_VDSO=y, and CONFIG_WERROR=y (as in allmodconfig
and allyesconfig), can this trigger an uncoordinated recursive make headers
pass in the kernel object tree that races with the main build and repeatedly
recompiles scripts/unifdef?

Once headers completes, tools_build runs tools/Makefile.kbuild in parallel
with the rest of the kernel build after unexporting sub_make_done, and invokes
each enabled selftest via:

tools/Makefile.kbuild:
$(selftest-targets): selftest-%: $(selftest-shared) FORCE
	$(call build,$(outdir)/selftests/$*,-C $(toolsdir)/testing/selftests/$* OUTPUT=$(outdir)/selftests/$* $(selftest-flags),...)

On x86, tools/testing/selftests/vDSO/Makefile declares an order-only
prerequisite on headers:

$(OUTPUT)/vdso_standalone_test_x86: vdso_standalone_test_x86.c parse_vdso.c | headers

Because tools/testing/selftests/lib.mk marks headers as .PHONY and no file
named headers exists on disk, GNU Make unconditionally runs the recipe in
lib.mk:

headers:
	$(Q)$(MAKE) -f $(top_srcdir)/Makefile -C $(khdr_output) headers

That spawns a second top-level make headers pass inside the kernel object tree
while the outer make all and other selftests are running. Because headers is
in no-dot-config-targets in the top-level Makefile, include/config/auto.conf
is not loaded in that sub-make, leaving CONFIG_WERROR unset. When
CONFIG_WERROR=y, the outer make all builds scripts/unifdef with -Werror and
-Wl,--fatal-warnings, whereas the inner make headers sees a command-line
mismatch in scripts/.unifdef.cmd and rebuilds scripts/unifdef concurrently
with the main build (and recompiles it twice on every subsequent incremental
make all or make tools_build).

[Severity: Medium]
On an in-tree make all build (without O=) with CONFIG_TOOLS_BUILD=y and
CONFIG_TOOLS_BUILD_SELFTESTS_VDSO=y or CONFIG_TOOLS_BUILD_SELFTESTS_X86=y,
will the unfiltered find in tools/Makefile.kbuild cause selftest-vDSO and
selftest-x86 to be wiped and rebuilt from scratch on the next incremental make
invocation?

In tools/Makefile.kbuild, the extra dependency directories for those targets
point into the kernel source tree:

selftest-extra-vDSO := $(abs_srctree)/arch/$(SRCARCH) $(abs_srctree)/include
selftest-extra-x86 := $(abs_srctree)/arch/x86/include

And the build macro checks for newer files across those directories without
filtering out build artifacts:

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;) \

Because all: tools_build only orders tools_build after headers, the main
in-tree kernel build continues writing object files, .cmd files, generated
headers (such as include/generated/compile.h), and boot images (such as
arch/x86/boot/bzImage) under arch/$(SRCARCH) and include after
tools-build/selftests/vDSO/.tools_build is written. On the following make
invocation, find matches those newer kernel build artifacts and runs rm -rf on
the selftest output directory even when no sources or headers changed.

[Severity: Medium]
Does adding tools_build to all break make -n all on a clean tree when
CONFIG_TOOLS_BUILD=y and CONFIG_TOOLS_BUILD_PERF=y?

In tools/Makefile.kbuild, the build macro uses a leading + prefix and runs
mkdir -p before invoking the sub-make:

define build
	...
	mkdir -p $(1) && $(MAKE) $(2) && \
	$(if $(dry-run),:,printf '%s' '$(build-key)' > $(1)/.tools_build) || \

Under make -n, this creates tools-build/<target> directories on disk and
invokes tools/perf/Makefile.perf with -n in MAKEFLAGS. In
tools/perf/Makefile.perf, the sub-make pass for FIXDEP_BUILT=1 runs under
make -n (writing detection files into tools-build/perf) and evaluates the
prepare prerequisite $(LIBAPI):

$(LIBAPI): FORCE | $(LIBAPI_OUTPUT)
	$(Q)$(MAKE) -C $(LIBAPI_DIR) O=$(LIBAPI_OUTPUT) \
		DESTDIR=$(LIBAPI_DESTDIR) prefix= subdir= \
		$@ install_headers

However, the rule that creates $(LIBAPI_OUTPUT) in tools/perf/Makefile.perf:

$(LIBAPI_OUTPUT):
	$(Q)$(MKDIR) -p $@

has neither a + prefix nor $(MAKE) in its recipe, so GNU Make skips it during
make -n and never creates tools-build/perf/libapi. When the $(LIBAPI) recipe
then runs its sub-make, tools/scripts/Makefile.include checks whether $(O)
exists at parse time:

$(if $(shell cd $(PWD); test -d $(O) || echo $(O)),$(error O=$(O) does not exist),)

which aborts make -n all with an error that tools-build/perf/libapi does not
exist.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261102021253.2545235-1-sashal@kernel.org?part=6

  reply	other threads:[~2026-11-03  2:13 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-02  2:12 [PATCH v3 0/7] kbuild: build the userspace tools in tools/ with the kernel Sasha Levin
2026-11-02  2:12 ` [PATCH v3 1/7] kbuild: factor the userspace ABI flags out into KBUILD_USERABI Sasha Levin
2026-11-03  2:13   ` sashiko-bot
2026-11-02  2:12 ` [PATCH v3 2/7] kbuild: add "make tools_build" to build userspace tools from tools/ Sasha Levin
2026-11-03  2:13   ` sashiko-bot
2026-11-02  2:12 ` [PATCH v3 3/7] perf build: Add MINIMAL=1 to build without optional features Sasha Levin
2026-11-03  2:13   ` sashiko-bot
2026-11-02  2:12 ` [PATCH v3 4/7] tools: build perf in tools_build Sasha Levin
2026-11-03  2:13   ` sashiko-bot
2026-11-02  2:12 ` [PATCH v3 5/7] tools: build kernel selftests " Sasha Levin
2026-11-03  2:13   ` sashiko-bot
2026-11-02  2:12 ` [PATCH v3 6/7] kbuild: build the tools selected in tools/Kconfig as part of "make all" Sasha Levin
2026-11-03  2:13   ` sashiko-bot [this message]
2026-11-02  2:12 ` [PATCH v3 7/7] Documentation: describe building tools with the kernel Sasha Levin
2026-11-03  2:13   ` sashiko-bot

Reply instructions:

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

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

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

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

  git send-email \
    --in-reply-to=sashiko-outbox-194454@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=akpm@linux-foundation.org \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=irogers@google.com \
    --cc=james.clark@linaro.org \
    --cc=jolsa@kernel.org \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=linux@leemhuis.info \
    --cc=linux@weissschuh.net \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=nathan@kernel.org \
    --cc=nsc@kernel.org \
    --cc=peterz@infradead.org \
    --cc=sashal@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=shuah@kernel.org \
    /path/to/YOUR_REPLY

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

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