* [PATCH 1/3] selftests/bpf: Route generated test headers to OUTPUT
2026-07-29 0:06 [PATCH 0/3] selftests/bpf: Fixes for out-of-tree builds Ricardo B. Marlière (SUSE)
@ 2026-07-29 0:06 ` Ricardo B. Marlière (SUSE)
2026-07-29 0:16 ` sashiko-bot
2026-07-29 0:06 ` [PATCH 2/3] selftests/bpf: Route libarena build artifacts " Ricardo B. Marlière (SUSE)
2026-07-29 0:06 ` [PATCH 3/3] selftests/bpf: Route test_kmods " Ricardo B. Marlière (SUSE)
2 siblings, 1 reply; 6+ messages in thread
From: Ricardo B. Marlière (SUSE) @ 2026-07-29 0:06 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
Eduard Zingerman, Kumar Kartikeya Dwivedi, Martin KaFai Lau,
Song Liu, Yonghong Song, Jiri Olsa, Emil Tsalapatis, Shuah Khan
Cc: bpf, linux-kselftest, linux-kernel,
Ricardo B. Marlière (SUSE)
When building with O= the test-runner enumeration headers
(prog_tests/tests.h, map_tests/tests.h), the verifier test list
(verifier/tests.h) and the signing certificate header (verification_cert.h)
are written into the source tree instead of the out-of-tree build
directory.
Fix TRUNNER_TESTS_HDR to resolve under $(OUTPUT) and add an order-only
prerequisite so the subdirectory exists before the recipe runs. The mkdir
must precede the shell redirect in the same command, so use '&&' rather
than nesting mkdir inside the parenthesised group (the redirect opens the
file before the subshell starts).
Fix VERIFY_SIG_HDR likewise; the recipe already writes to $@ so no further
changes are needed there.
For verifier/tests.h, also resolve the target under $(OUTPUT) and generate
absolute paths in the '#include' directives, since the relative '"file.c"'
form would resolve against the output directory rather than the source
tree.
Signed-off-by: Ricardo B. Marlière (SUSE) <ricardo@marliere.net>
---
tools/testing/selftests/bpf/Makefile | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
index b642ee489ea6..b289183475d4 100644
--- a/tools/testing/selftests/bpf/Makefile
+++ b/tools/testing/selftests/bpf/Makefile
@@ -580,7 +580,7 @@ TRUNNER_EXTRA_OBJS := $$(patsubst %.c,$$(TRUNNER_OUTPUT)/%.o, \
TRUNNER_LIB_OBJS := $$(patsubst %.c,$$(TRUNNER_OUTPUT)/%.o, \
$$(filter %.c,$(TRUNNER_LIB_SOURCES)))
TRUNNER_EXTRA_HDRS := $$(filter %.h,$(TRUNNER_EXTRA_SOURCES))
-TRUNNER_TESTS_HDR := $(TRUNNER_TESTS_DIR)/tests.h
+TRUNNER_TESTS_HDR := $(OUTPUT)/$(TRUNNER_TESTS_DIR)/tests.h
TRUNNER_BPF_SRCS := $$(notdir $$(wildcard $(TRUNNER_BPF_PROGS_DIR)/*.c))
TRUNNER_BPF_OBJS := $$(patsubst %.c,$$(TRUNNER_OUTPUT)/%.bpf.o, $$(TRUNNER_BPF_SRCS))
TRUNNER_BPF_SKELS := $$(patsubst %.c,$$(TRUNNER_OUTPUT)/%.skel.h, \
@@ -720,9 +720,9 @@ endif
# ensure we set up tests.h header generation rule just once
ifeq ($($(TRUNNER_TESTS_DIR)-tests-hdr),)
$(TRUNNER_TESTS_DIR)-tests-hdr := y
-$(TRUNNER_TESTS_HDR): $(TRUNNER_TESTS_DIR)/*.c
+$(TRUNNER_TESTS_HDR): $(TRUNNER_TESTS_DIR)/*.c | $(TRUNNER_OUTPUT)
$$(call msg,TEST-HDR,$(TRUNNER_BINARY),$$@)
- $$(shell (echo '/* Generated header, do not edit */'; \
+ $$(shell mkdir -p $$(dir $$@) && (echo '/* Generated header, do not edit */'; \
sed -n -E 's/^void (serial_)?test_([a-zA-Z0-9_]+)\((void)?\).*/DEFINE_TEST(\2)/p' \
$(TRUNNER_TESTS_DIR)/*.c | sort ; \
) > $$@)
@@ -802,7 +802,7 @@ $(OUTPUT)/$(TRUNNER_BINARY): $(if $(filter test_progs%,$1),$(if $(PERMISSIVE),$$
endef
VERIFY_SIG_SETUP := $(CURDIR)/verify_sig_setup.sh
-VERIFY_SIG_HDR := verification_cert.h
+VERIFY_SIG_HDR := $(OUTPUT)/verification_cert.h
VERIFICATION_CERT := $(BUILD_DIR)/signing_key.der
PRIVATE_KEY := $(BUILD_DIR)/signing_key.pem
@@ -923,14 +923,14 @@ $(eval $(call DEFINE_TEST_RUNNER,test_maps))
# It is much simpler than test_maps/test_progs and sufficiently different from
# them (e.g., test.h is using completely pattern), that it's worth just
# explicitly defining all the rules explicitly.
-verifier/tests.h: verifier/*.c
- $(shell ( cd verifier/; \
+$(OUTPUT)/verifier/tests.h: verifier/*.c | $(OUTPUT)
+ $(shell mkdir -p $(OUTPUT)/verifier && ( \
echo '/* Generated header, do not edit */'; \
echo '#ifdef FILL_ARRAY'; \
- ls *.c 2> /dev/null | sed -e 's@\(.*\)@#include \"\1\"@'; \
+ ls verifier/*.c 2> /dev/null | sed -e 's@\(.*\)@#include "$(CURDIR)/\1"@'; \
echo '#endif' \
- ) > verifier/tests.h)
-$(OUTPUT)/test_verifier: test_verifier.c verifier/tests.h $(BPFOBJ) | $(OUTPUT)
+ ) > $(OUTPUT)/verifier/tests.h)
+$(OUTPUT)/test_verifier: test_verifier.c $(OUTPUT)/verifier/tests.h $(BPFOBJ) | $(OUTPUT)
$(call msg,BINARY,,$@)
$(Q)$(CC) $(CFLAGS) $(filter %.a %.o %.c,$^) $(LDLIBS) -o $@
--
2.55.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 1/3] selftests/bpf: Route generated test headers to OUTPUT
2026-07-29 0:06 ` [PATCH 1/3] selftests/bpf: Route generated test headers to OUTPUT Ricardo B. Marlière (SUSE)
@ 2026-07-29 0:16 ` sashiko-bot
0 siblings, 0 replies; 6+ messages in thread
From: sashiko-bot @ 2026-07-29 0:16 UTC (permalink / raw)
To: Ricardo B. Marlière (SUSE); +Cc: bpf
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] Unescaped path injection in `sed` with the `@` delimiter can cause verifier tests to be silently skipped if the build path contains an `@` character.
- [Low] Generated test headers moved to $(OUTPUT) are not cleaned during out-of-tree builds because EXTRA_CLEAN is not updated.
--
--- Patch [1]: [PATCH 1/3] selftests/bpf: Route generated test headers to OUTPUT ---
commit 63d1e1deab06130ae6d45a6e98fd6e8bf85c23ef
Author: Ricardo B. Marlière (SUSE) <ricardo@marliere.net>
selftests/bpf: Route generated test headers to OUTPUT
This commit updates the Makefile to write generated test-runner enumeration
headers, verifier test lists, and signing certificate headers to $(OUTPUT)
instead of the source tree during out-of-tree builds. It modifies the
target prerequisites to ensure the output subdirectories are created before
generating these headers.
> diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
> index b642ee489ea64..b289183475d4c 100644
> --- a/tools/testing/selftests/bpf/Makefile
> +++ b/tools/testing/selftests/bpf/Makefile
[ ... ]
> @@ -923,14 +923,14 @@ $(eval $(call DEFINE_TEST_RUNNER,test_maps))
> # It is much simpler than test_maps/test_progs and sufficiently different from
> # them (e.g., test.h is using completely pattern), that it's worth just
> # explicitly defining all the rules explicitly.
> -verifier/tests.h: verifier/*.c
> - $(shell ( cd verifier/; \
> +$(OUTPUT)/verifier/tests.h: verifier/*.c | $(OUTPUT)
> + $(shell mkdir -p $(OUTPUT)/verifier && ( \
> echo '/* Generated header, do not edit */'; \
> echo '#ifdef FILL_ARRAY'; \
> - ls *.c 2> /dev/null | sed -e 's@\(.*\)@#include \"\1\"@'; \
> + ls verifier/*.c 2> /dev/null | sed -e 's@\(.*\)@#include "$(CURDIR)/\1"@'; \
[Severity: Medium]
Does this change introduce a regression if the build path $(CURDIR) contains
an @ character?
If the user's working directory contains an @ symbol (such as in Jenkins
workspaces like @tmp), sed fails with a syntax error because @ is used
as the replacement delimiter.
Since the failure occurs within a subshell (...) > $(OUTPUT)/verifier/tests.h,
Make ignores the failure and writes an empty test array to the header.
Will this cause the verifier test suite to compile successfully but run zero
tests?
> echo '#endif' \
> - ) > verifier/tests.h)
> -$(OUTPUT)/test_verifier: test_verifier.c verifier/tests.h $(BPFOBJ) | $(OUTPUT)
> + ) > $(OUTPUT)/verifier/tests.h)
> +$(OUTPUT)/test_verifier: test_verifier.c $(OUTPUT)/verifier/tests.h $(BPFOBJ) | $(OUTPUT)
> $(call msg,BINARY,,$@)
> $(Q)$(CC) $(CFLAGS) $(filter %.a %.o %.c,$^) $(LDLIBS) -o $@
[Severity: Low]
With the generated test headers moving to $(OUTPUT), will they be left behind
during a clean build?
Looking at EXTRA_CLEAN further down in tools/testing/selftests/bpf/Makefile:
EXTRA_CLEAN := $(SCRATCH_DIR) $(HOST_SCRATCH_DIR) \
prog_tests/tests.h map_tests/tests.h verifier/tests.h \
...
Since EXTRA_CLEAN still hardcodes the old relative paths, does this mean
`make clean O=out` will miss the newly relocated headers in the output
directory?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260728-selftests-bpf_oot-v1-0-05feb15d94db@marliere.net?part=1
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 2/3] selftests/bpf: Route libarena build artifacts to OUTPUT
2026-07-29 0:06 [PATCH 0/3] selftests/bpf: Fixes for out-of-tree builds Ricardo B. Marlière (SUSE)
2026-07-29 0:06 ` [PATCH 1/3] selftests/bpf: Route generated test headers to OUTPUT Ricardo B. Marlière (SUSE)
@ 2026-07-29 0:06 ` Ricardo B. Marlière (SUSE)
2026-07-29 0:18 ` sashiko-bot
2026-07-29 0:06 ` [PATCH 3/3] selftests/bpf: Route test_kmods " Ricardo B. Marlière (SUSE)
2 siblings, 1 reply; 6+ messages in thread
From: Ricardo B. Marlière (SUSE) @ 2026-07-29 0:06 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
Eduard Zingerman, Kumar Kartikeya Dwivedi, Martin KaFai Lau,
Song Liu, Yonghong Song, Jiri Olsa, Emil Tsalapatis, Shuah Khan
Cc: bpf, linux-kselftest, linux-kernel,
Ricardo B. Marlière (SUSE)
libarena's BPF objects, linked objects, and skeleton headers are always
written into the source tree regardless of whether an out-of-tree build
directory was specified via O=.
Add OUTPUT support to libarena/Makefile: default OUTPUT to '.' for
standalone builds, prefix all generated file targets with $(OUTPUT)/, and
use addprefix to propagate the directory into the per-object lists. Create
$(OUTPUT) at Makefile-load time with a $(shell mkdir -p) so all rules have
a valid destination.
In the parent bpf/Makefile, pass OUTPUT="$(OUTPUT)/libarena" in
LIBARENA_MAKE_ARGS and update LIBARENA_SKEL/LIBARENA_ASAN_SKEL to reflect
the new location. Pass the absolute target path as the make goal so the
sub-make goal matches the $(OUTPUT)/... rule in libarena/Makefile
regardless of the invocation directory.
Signed-off-by: Ricardo B. Marlière (SUSE) <ricardo@marliere.net>
---
tools/testing/selftests/bpf/Makefile | 11 ++++++-----
tools/testing/selftests/bpf/libarena/Makefile | 24 ++++++++++++++----------
2 files changed, 20 insertions(+), 15 deletions(-)
diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
index b289183475d4..7d42632f9d42 100644
--- a/tools/testing/selftests/bpf/Makefile
+++ b/tools/testing/selftests/bpf/Makefile
@@ -826,7 +826,8 @@ LIBARENA_MAKE_ARGS = \
CLANG="$(CLANG)" \
BPF_CFLAGS="$(BPF_CFLAGS) $(CLANG_CFLAGS)" \
BPF_TARGET_ENDIAN="$(BPF_TARGET_ENDIAN)" \
- Q="$(Q)"
+ Q="$(Q)" \
+ OUTPUT="$(OUTPUT)/libarena"
LIBARENA_BPF_DEPS := $(wildcard libarena/Makefile \
libarena/include/* \
@@ -835,17 +836,17 @@ LIBARENA_BPF_DEPS := $(wildcard libarena/Makefile \
libarena/selftests/* \
libarena/*.bpf.o)
-LIBARENA_SKEL := libarena/libarena.skel.h
+LIBARENA_SKEL := $(OUTPUT)/libarena/libarena.skel.h
$(LIBARENA_SKEL): $(INCLUDE_DIR)/vmlinux.h $(BPFOBJ) $(LIBARENA_BPF_DEPS)
- +$(MAKE) -C libarena libarena.skel.h $(LIBARENA_MAKE_ARGS)
+ +$(MAKE) -C libarena $(LIBARENA_SKEL) $(LIBARENA_MAKE_ARGS)
ifneq ($(CLANG_HAS_ARENA_ASAN),)
-LIBARENA_ASAN_SKEL := libarena/libarena_asan.skel.h
+LIBARENA_ASAN_SKEL := $(OUTPUT)/libarena/libarena_asan.skel.h
CFLAGS += -DHAS_BPF_ARENA_ASAN
$(LIBARENA_ASAN_SKEL): $(INCLUDE_DIR)/vmlinux.h $(BPFOBJ) $(LIBARENA_BPF_DEPS)
- +$(MAKE) -C libarena libarena_asan.skel.h $(LIBARENA_MAKE_ARGS)
+ +$(MAKE) -C libarena $(LIBARENA_ASAN_SKEL) $(LIBARENA_MAKE_ARGS)
endif
# Define test_progs test runner.
diff --git a/tools/testing/selftests/bpf/libarena/Makefile b/tools/testing/selftests/bpf/libarena/Makefile
index 5e2ab514805e..195d5f833186 100644
--- a/tools/testing/selftests/bpf/libarena/Makefile
+++ b/tools/testing/selftests/bpf/libarena/Makefile
@@ -27,10 +27,14 @@ BPFDIR=$(abspath $(LIBARENA)/..)
INCLUDE_DIR ?= $(BPFDIR)/tools/include
LIBBPF_INCLUDE ?= $(INCLUDE_DIR)
+# Build output directory; defaults to in-tree for standalone builds.
+OUTPUT ?= .
+$(shell mkdir -p $(OUTPUT))
+
# Scan src/ and selftests/ to generate the final binaries
LIBARENA_SOURCES = $(wildcard $(LIBARENA)/src/*.bpf.c) $(wildcard $(LIBARENA)/selftests/*.bpf.c)
-LIBARENA_OBJECTS = $(notdir $(LIBARENA_SOURCES:.bpf.c=.bpf.o))
-LIBARENA_OBJECTS_ASAN = $(notdir $(LIBARENA_SOURCES:.bpf.c=_asan.bpf.o))
+LIBARENA_OBJECTS = $(addprefix $(OUTPUT)/,$(notdir $(LIBARENA_SOURCES:.bpf.c=.bpf.o)))
+LIBARENA_OBJECTS_ASAN = $(addprefix $(OUTPUT)/,$(notdir $(LIBARENA_SOURCES:.bpf.c=_asan.bpf.o)))
INCLUDES = -I$(LIBARENA)/include -I$(BPFDIR)
ifneq ($(INCLUDE_DIR),)
@@ -61,32 +65,32 @@ CFLAGS += $(INCLUDES)
vpath %.bpf.c $(LIBARENA)/src $(LIBARENA)/selftests
vpath %.c $(LIBARENA)/src $(LIBARENA)/selftests
-skeletons: libarena.skel.h libarena_asan.skel.h
+skeletons: $(OUTPUT)/libarena.skel.h $(OUTPUT)/libarena_asan.skel.h
.PHONY: skeletons
-libarena_asan.skel.h: libarena_asan.bpf.o
+$(OUTPUT)/libarena_asan.skel.h: $(OUTPUT)/libarena_asan.bpf.o
$(call msg,GEN-SKEL,libarena,$@)
$(Q)$(BPFTOOL) gen skeleton $< name "libarena_asan" > $@
-libarena.skel.h: libarena.bpf.o
+$(OUTPUT)/libarena.skel.h: $(OUTPUT)/libarena.bpf.o
$(call msg,GEN-SKEL,libarena,$@)
$(Q)$(BPFTOOL) gen skeleton $< name "libarena" > $@
-libarena_asan.bpf.o: $(LIBARENA_OBJECTS_ASAN)
+$(OUTPUT)/libarena_asan.bpf.o: $(LIBARENA_OBJECTS_ASAN)
$(call msg,GEN-OBJ,libarena,$@)
$(Q)$(BPFTOOL) gen object $@ $^
-libarena.bpf.o: $(LIBARENA_OBJECTS)
+$(OUTPUT)/libarena.bpf.o: $(LIBARENA_OBJECTS)
$(call msg,GEN-OBJ,libarena,$@)
$(Q)$(BPFTOOL) gen object $@ $^
-%_asan.bpf.o: %.bpf.c
+$(OUTPUT)/%_asan.bpf.o: %.bpf.c
$(call msg,CLNG-BPF,libarena,$@)
$(Q)$(CLANG) $(BPF_CFLAGS) $(ASAN_FLAGS) -DBPF_ARENA_ASAN $(BPF_TARGET_ENDIAN) -c $< -o $@
-%.bpf.o: %.bpf.c
+$(OUTPUT)/%.bpf.o: %.bpf.c
$(call msg,CLNG-BPF,libarena,$@)
$(Q)$(CLANG) $(BPF_CFLAGS) $(BPF_TARGET_ENDIAN) -c $< -o $@
clean:
- $(Q)rm -f *.skel.h *.bpf.o *.linked*.o
+ $(Q)rm -f $(OUTPUT)/*.skel.h $(OUTPUT)/*.bpf.o $(OUTPUT)/*.linked*.o
--
2.55.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 2/3] selftests/bpf: Route libarena build artifacts to OUTPUT
2026-07-29 0:06 ` [PATCH 2/3] selftests/bpf: Route libarena build artifacts " Ricardo B. Marlière (SUSE)
@ 2026-07-29 0:18 ` sashiko-bot
0 siblings, 0 replies; 6+ messages in thread
From: sashiko-bot @ 2026-07-29 0:18 UTC (permalink / raw)
To: Ricardo B. Marlière (SUSE); +Cc: bpf
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] The `clean` rule in `selftests/bpf/Makefile` fails to pass the overridden `OUTPUT` path to the `libarena` sub-make, causing out-of-tree builds to leak libarena artifacts.
--
--- Patch [2]: [PATCH 2/3] selftests/bpf: Route libarena build artifacts to OUTPUT ---
commit b4bd21c68fbd2a022ffbf1208ac0ac06aa993754
Author: Ricardo B. Marlière (SUSE) <ricardo@marliere.net>
selftests/bpf: Route libarena build artifacts to OUTPUT
This commit adds OUTPUT support to libarena's Makefile and propagates it
from the parent bpf Makefile. It ensures generated files like BPF objects
and skeleton headers are correctly written into the out-of-tree build
directory.
> diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
> index b289183475d4c..7d42632f9d424 100644
> --- a/tools/testing/selftests/bpf/Makefile
> +++ b/tools/testing/selftests/bpf/Makefile
[ ... ]
> @@ -826,7 +826,8 @@ LIBARENA_MAKE_ARGS = \
> CLANG="$(CLANG)" \
> BPF_CFLAGS="$(BPF_CFLAGS) $(CLANG_CFLAGS)" \
> BPF_TARGET_ENDIAN="$(BPF_TARGET_ENDIAN)" \
> - Q="$(Q)"
> + Q="$(Q)" \
> + OUTPUT="$(OUTPUT)/libarena"
[ ... ]
> diff --git a/tools/testing/selftests/bpf/libarena/Makefile b/tools/testing/selftests/bpf/libarena/Makefile
> index 5e2ab514805e4..195d5f833186a 100644
> --- a/tools/testing/selftests/bpf/libarena/Makefile
> +++ b/tools/testing/selftests/bpf/libarena/Makefile
[ ... ]
> clean:
> - $(Q)rm -f *.skel.h *.bpf.o *.linked*.o
> + $(Q)rm -f $(OUTPUT)/*.skel.h $(OUTPUT)/*.bpf.o $(OUTPUT)/*.linked*.o
[Severity: Low]
Will this fail to clean the libarena artifacts when building out-of-tree?
In the parent bpf/Makefile, the clean target invokes make without the
LIBARENA_MAKE_ARGS override:
tools/testing/selftests/bpf/Makefile:
clean:
...
$(Q)$(MAKE) -C libarena clean
Since OUTPUT is inherited unmodified from the parent Makefile, it resolves
to the parent directory instead of $(OUTPUT)/libarena/.
Will this cause make clean to inadvertently run rm -f against the parent's
$(OUTPUT) directory, leaving the actual libarena artifacts behind?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260728-selftests-bpf_oot-v1-0-05feb15d94db@marliere.net?part=2
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 3/3] selftests/bpf: Route test_kmods build artifacts to OUTPUT
2026-07-29 0:06 [PATCH 0/3] selftests/bpf: Fixes for out-of-tree builds Ricardo B. Marlière (SUSE)
2026-07-29 0:06 ` [PATCH 1/3] selftests/bpf: Route generated test headers to OUTPUT Ricardo B. Marlière (SUSE)
2026-07-29 0:06 ` [PATCH 2/3] selftests/bpf: Route libarena build artifacts " Ricardo B. Marlière (SUSE)
@ 2026-07-29 0:06 ` Ricardo B. Marlière (SUSE)
2 siblings, 0 replies; 6+ messages in thread
From: Ricardo B. Marlière (SUSE) @ 2026-07-29 0:06 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
Eduard Zingerman, Kumar Kartikeya Dwivedi, Martin KaFai Lau,
Song Liu, Yonghong Song, Jiri Olsa, Emil Tsalapatis, Shuah Khan
Cc: bpf, linux-kselftest, linux-kernel,
Ricardo B. Marlière (SUSE)
When building bpf selftests with O=, the kernel module intermediates (.ko,
.o, .mod.*, .cmd files, Module.symvers, modules.order) produced by the
test_kmods sub-make are placed in the source tree instead of the
out-of-tree directory, because kbuild external-module builds always write
output to the M= source directory by default.
Introduce TEST_KMODS_OUTDIR in bpf/Makefile that resolves to
$(OUTPUT)/test_kmods when OUTPUT is set, and fall back to the in-tree
test_kmods/ directory for standalone builds. Update the pattern rule, the
RM invocation, and the copy rule to use this variable, and pass
OUTPUT=$(OUTPUT)/test_kmods to the test_kmods sub-make.
In test_kmods/Makefile, forward the received OUTPUT value as MO= to the
kernel Makefile. The top-level kernel Makefile maps MO= to
KBUILD_EXTMOD_OUTPUT, which redirects all external-module build output to
the specified directory. The kernel also creates that directory
automatically, so no explicit mkdir is needed.
Also update the CLEAN target in bpf/Makefile to propagate OUTPUT to both
the test_kmods and libarena sub-makes so that clean removes from the
correct location.
Signed-off-by: Ricardo B. Marlière (SUSE) <ricardo@marliere.net>
---
tools/testing/selftests/bpf/Makefile | 16 ++++++++++------
tools/testing/selftests/bpf/test_kmods/Makefile | 3 +++
2 files changed, 13 insertions(+), 6 deletions(-)
diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
index 7d42632f9d42..b150a66f3c25 100644
--- a/tools/testing/selftests/bpf/Makefile
+++ b/tools/testing/selftests/bpf/Makefile
@@ -135,6 +135,9 @@ TEST_PROGS_EXTENDED := \
TEST_KMODS := bpf_testmod.ko bpf_test_no_cfi.ko bpf_test_modorder_x.ko \
bpf_test_modorder_y.ko bpf_test_rqspinlock.ko
TEST_KMOD_TARGETS = $(addprefix $(OUTPUT)/,$(TEST_KMODS))
+# Build directory for kernel modules: routed to $(OUTPUT)/test_kmods when
+# OUTPUT is set so that kbuild intermediates stay out of the source tree.
+TEST_KMODS_OUTDIR := $(if $(OUTPUT),$(OUTPUT)/test_kmods,test_kmods)
# Compile but not part of 'make run_tests'
TEST_GEN_PROGS_EXTENDED = \
@@ -163,8 +166,8 @@ override define CLEAN
$(Q)$(RM) -r $(TEST_GEN_FILES)
$(Q)$(RM) -r $(TEST_KMODS)
$(Q)$(RM) -r $(EXTRA_CLEAN)
- $(Q)$(MAKE) -C test_kmods clean
- $(Q)$(MAKE) -C libarena clean
+ $(Q)$(MAKE) -C test_kmods $(if $(OUTPUT),OUTPUT=$(OUTPUT)/test_kmods) clean
+ $(Q)$(MAKE) -C libarena $(if $(OUTPUT),OUTPUT=$(OUTPUT)/libarena) clean
$(Q)$(MAKE) docs-clean
endef
@@ -301,17 +304,18 @@ $(OUTPUT)/sign-file: ../../../../scripts/sign-file.c
# support that for regular rules. However, pattern matching rules are implicitly
# treated as grouped even with older versions of make, so as a workaround, the
# subst() turns the rule into a pattern matching rule
-$(addprefix test_kmods/,$(subst .ko,%ko,$(TEST_KMODS))): $(VMLINUX_BTF) $(RESOLVE_BTFIDS) $(wildcard test_kmods/Makefile test_kmods/*.[ch])
- $(Q)$(RM) test_kmods/*.ko test_kmods/*.mod.o # force re-compilation
+$(addprefix $(TEST_KMODS_OUTDIR)/,$(subst .ko,%ko,$(TEST_KMODS))): $(VMLINUX_BTF) $(RESOLVE_BTFIDS) $(wildcard test_kmods/Makefile test_kmods/*.[ch])
+ $(Q)$(RM) $(TEST_KMODS_OUTDIR)/*.ko $(TEST_KMODS_OUTDIR)/*.mod.o # force re-compilation
$(Q)$(MAKE) $(submake_extras) -C test_kmods \
$(if $(O),O=$(abspath $(O))) \
$(if $(KBUILD_OUTPUT),KBUILD_OUTPUT=$(abspath $(KBUILD_OUTPUT)))\
+ $(if $(OUTPUT),OUTPUT=$(OUTPUT)/test_kmods) \
RESOLVE_BTFIDS=$(RESOLVE_BTFIDS) \
EXTRA_CFLAGS='' EXTRA_LDFLAGS=''
-$(TEST_KMOD_TARGETS): $(addprefix test_kmods/,$(TEST_KMODS))
+$(TEST_KMOD_TARGETS): $(addprefix $(TEST_KMODS_OUTDIR)/,$(TEST_KMODS))
$(call msg,MOD,,$@)
- $(Q)$(if $(PERMISSIVE),if [ -f test_kmods/$(@F) ]; then )cp test_kmods/$(@F) $@$(if $(PERMISSIVE),; fi)
+ $(Q)$(if $(PERMISSIVE),if [ -f $(TEST_KMODS_OUTDIR)/$(@F) ]; then )cp $(TEST_KMODS_OUTDIR)/$(@F) $@$(if $(PERMISSIVE),; fi)
DEFAULT_BPFTOOL := $(HOST_SCRATCH_DIR)/sbin/bpftool
diff --git a/tools/testing/selftests/bpf/test_kmods/Makefile b/tools/testing/selftests/bpf/test_kmods/Makefile
index 031c7454ce65..53e47e715ec4 100644
--- a/tools/testing/selftests/bpf/test_kmods/Makefile
+++ b/tools/testing/selftests/bpf/test_kmods/Makefile
@@ -32,14 +32,17 @@ PERMISSIVE := $(filter 0,$(BPF_STRICT_BUILD))
all:
ifeq ($(PERMISSIVE),)
$(Q)$(MAKE) -C $(KDIR) $(if $(KMOD_O_VALID),O=$(KMOD_O_VALID) KBUILD_OUTPUT=$(KMOD_O_VALID),KBUILD_OUTPUT=) \
+ $(if $(OUTPUT),MO=$(OUTPUT)) \
M=$(TEST_KMOD_DIR) modules
else ifneq ("$(wildcard $(KDIR))", "")
$(Q)$(MAKE) -C $(KDIR) $(if $(KMOD_O_VALID),O=$(KMOD_O_VALID) KBUILD_OUTPUT=$(KMOD_O_VALID),KBUILD_OUTPUT=) \
+ $(if $(OUTPUT),MO=$(OUTPUT)) \
M=$(TEST_KMOD_DIR) modules
endif
clean:
ifneq ("$(wildcard $(KDIR))", "")
$(Q)$(MAKE) -C $(KDIR) $(if $(KMOD_O_VALID),O=$(KMOD_O_VALID) KBUILD_OUTPUT=$(KMOD_O_VALID),KBUILD_OUTPUT=) \
+ $(if $(OUTPUT),MO=$(OUTPUT)) \
M=$(TEST_KMOD_DIR) clean
endif
--
2.55.0
^ permalink raw reply related [flat|nested] 6+ messages in thread