From: "Nico Pache (Red Hat)" <nico.pache@linux.dev>
To: "Ricardo B. Marlière (SUSE)" <ricardo@marliere.net>,
ihor.solodrai@linux.dev, nickolay.lysenko@gmail.com
Cc: bpf@vger.kernel.org, linux-kselftest@vger.kernel.org,
Emil Tsalapatis <emil@etsalapatis.com>,
Jiri Olsa <jolsa@kernel.org>,
Yonghong Song <yonghong.song@linux.dev>,
Song Liu <song@kernel.org>, Eduard Zingerman <eddyz87@gmail.com>,
Andrii Nakryiko <andrii@kernel.org>,
Shuah Khan <shuah@kernel.org>,
linux-kernel@vger.kernel.org,
Kumar Kartikeya Dwivedi <memxor@gmail.com>,
Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Martin KaFai Lau <martin.lau@linux.dev>
Subject: Re: [PATCH 0/3] selftests/bpf: Fixes for out-of-tree builds
Date: Mon, 21 Sep 2026 14:40:15 -0600 [thread overview]
Message-ID: <6f95ec90-194a-4304-9673-c7bb50065223@linux.dev> (raw)
In-Reply-To: <20260728-selftests-bpf_oot-v1-0-05feb15d94db@marliere.net>
On 7/28/26 6:06 PM, Ricardo B. Marlière (SUSE) wrote:
> Hello,
>
Hello! Thanks for posting this.
The Fedora build system is rather complex, especially around selftests BPF. We
are also discovering we need these changes.
Due to some other oddities in our build system, we would also like to specify a
precompiled vmlinux, rather than defaulting to $(objtree)/vmlinux.
I developed the following commit on top of these changes, and was finally able
to get a successful build in our env.
commit 616e12baf39ac44680c1dc22d31dbeea63e196b7
Author: Nico Pache <npache@redhat.com>
Date: Fri Aug 7 12:37:36 2026 -0600
kbuild, selftests/bpf: allow overriding the module BTF base
scripts/Makefile.modfinal currently hard-codes $(objtree)/vmlinux as the
BTF base used for module BTF generation. That works for in-tree builds,
but selftests/bpf/test_kmods may need to reuse a vmlinux resolved from a
prepared build tree or from /sys/kernel/btf/vmlinux.
Add a VMLINUX_BTF_BASE override so module BTF generation can use that
pre-resolved vmlinux instead.
Signed-off-by: Nico Pache <npache@redhat.com>
diff --git a/scripts/Makefile.modfinal b/scripts/Makefile.modfinal
index 01a37ec872b9..fd16e66aa156 100644
--- a/scripts/Makefile.modfinal
+++ b/scripts/Makefile.modfinal
@@ -38,16 +38,19 @@ quiet_cmd_ld_ko_o = LD [M] $@
$(KBUILD_LDFLAGS_MODULE) $(LDFLAGS_MODULE) \
-T $(objtree)/scripts/module.lds -o $@ $(filter %.o, $^)
+VMLINUX_BTF_BASE ?= $(objtree)/vmlinux
+VMLINUX_BTF_BASE_PREREQ := $(wildcard $(VMLINUX_BTF_BASE))
+
quiet_cmd_btf_ko = BTF [M] $@
cmd_btf_ko = \
- if [ ! -f $(objtree)/vmlinux ]; then \
- printf "Skipping BTF generation for %s due to unavailability of vmlinux\n" $@ 1>&2; \
+ if [ ! -f $(VMLINUX_BTF_BASE) ]; then \
+ printf "Skipping BTF generation for %s due to unavailability of %s\n" $@ $(VMLINUX_BTF_BASE) 1>&2; \
else \
- $(CONFIG_SHELL) $(srctree)/scripts/gen-btf.sh --btf_base $(objtree)/vmlinux $@; \
+ $(CONFIG_SHELL) $(srctree)/scripts/gen-btf.sh --btf_base $(VMLINUX_BTF_BASE) $@; \
fi;
-# Re-generate module BTFs if either module's .ko or vmlinux changed
-%.ko: %.o %.mod.o .module-common.o $(objtree)/scripts/module.lds $(and $(CONFIG_DEBUG_INFO_BTF_MODULES),$(KBUILD_BUILTIN),$(objtree)/vmlinux) FORCE
+# Re-generate module BTFs if either module's .ko or BTF base changed
+%.ko: %.o %.mod.o .module-common.o $(objtree)/scripts/module.lds $(and $(CONFIG_DEBUG_INFO_BTF_MODULES),$(VMLINUX_BTF_BASE_PREREQ)) FORCE
+$(call if_changed,ld_ko_o)
ifdef CONFIG_DEBUG_INFO_BTF_MODULES
+$(if $(newer-prereqs),$(call cmd,btf_ko))
diff --git a/tools/testing/selftests/bpf/test_kmods/Makefile b/tools/testing/selftests/bpf/test_kmods/Makefile
index 53e47e715ec4..8580eee34f32 100644
--- a/tools/testing/selftests/bpf/test_kmods/Makefile
+++ b/tools/testing/selftests/bpf/test_kmods/Makefile
@@ -11,6 +11,8 @@ KMOD_O_VALID := $(if $(KMOD_O),$(if $(wildcard $(KMOD_O)/Module.symvers),$(KMOD_
KDIR ?= $(if $(KMOD_O_VALID),$(SRCTREE_KDIR), \
$(if $(wildcard $(SRCTREE_KDIR)/Module.symvers),$(SRCTREE_KDIR), \
/lib/modules/$(shell uname -r)/build))
+# The parent bpf/Makefile may already have resolved a usable BTF base.
+VMLINUX_BTF_BASE_ARG := $(if $(VMLINUX_BTF),VMLINUX_BTF_BASE=$(abspath $(VMLINUX_BTF)))
ifeq ($(V),1)
Q =
@@ -32,10 +34,12 @@ 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=) \
+ $(VMLINUX_BTF_BASE_ARG) \
$(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=) \
+ $(VMLINUX_BTF_BASE_ARG) \
$(if $(OUTPUT),MO=$(OUTPUT)) \
M=$(TEST_KMOD_DIR) modules
endif
Given your series was defferred, and there is a "rewrite" coming, what would
be the best approach to working together (between us three) to get these
fixes in that series too.
Cheers,
-- Nico
> When doing a simple out-of-tree build, e.g.:
>
> $ git clean -fdx
> $ mkdir ../build
> $ make defconfig O=../build
> $ scripts/kconfig/merge_config.sh -O ../build ../build/.config tools/testing/selftests/bpf/{config,config.x86_64}
> $ make O=../build
> $ make -C tools/testing/selftests install O=$PWD/../build SKIP_TARGETS= TARGETS=bpf
>
> Will leave behind several build artifacts:
>
> $ git clean -fdx
> Removing tools/testing/selftests/bpf/libarena/asan.bpf.o
> Removing tools/testing/selftests/bpf/libarena/asan_asan.bpf.o
> Removing tools/testing/selftests/bpf/libarena/buddy.bpf.o
> Removing tools/testing/selftests/bpf/libarena/buddy_asan.bpf.o
> Removing tools/testing/selftests/bpf/libarena/common.bpf.o
> Removing tools/testing/selftests/bpf/libarena/common_asan.bpf.o
> Removing tools/testing/selftests/bpf/libarena/libarena.bpf.o
> Removing tools/testing/selftests/bpf/libarena/libarena.skel.h
> Removing tools/testing/selftests/bpf/libarena/libarena_asan.bpf.o
> Removing tools/testing/selftests/bpf/libarena/libarena_asan.skel.h
> Removing tools/testing/selftests/bpf/libarena/rbtree.bpf.o
> Removing tools/testing/selftests/bpf/libarena/rbtree_asan.bpf.o
> Removing tools/testing/selftests/bpf/libarena/spmc.bpf.o
> Removing tools/testing/selftests/bpf/libarena/spmc_asan.bpf.o
> Removing tools/testing/selftests/bpf/libarena/st_asan_buddy.bpf.o
> Removing tools/testing/selftests/bpf/libarena/st_asan_buddy_asan.bpf.o
> Removing tools/testing/selftests/bpf/libarena/st_buddy.bpf.o
> Removing tools/testing/selftests/bpf/libarena/st_buddy_asan.bpf.o
> Removing tools/testing/selftests/bpf/libarena/test_parallel_spmc.bpf.o
> Removing tools/testing/selftests/bpf/libarena/test_parallel_spmc_asan.bpf.o
> Removing tools/testing/selftests/bpf/libarena/test_rbtree.bpf.o
> Removing tools/testing/selftests/bpf/libarena/test_rbtree_asan.bpf.o
> Removing tools/testing/selftests/bpf/libarena/test_spmc.bpf.o
> Removing tools/testing/selftests/bpf/libarena/test_spmc_asan.bpf.o
> Removing tools/testing/selftests/bpf/map_tests/tests.h
> Removing tools/testing/selftests/bpf/prog_tests/tests.h
> Removing tools/testing/selftests/bpf/test_kmods/..module-common.o.cmd
> Removing tools/testing/selftests/bpf/test_kmods/.Module.symvers.cmd
> Removing tools/testing/selftests/bpf/test_kmods/.bpf_test_modorder_x.ko.cmd
> Removing tools/testing/selftests/bpf/test_kmods/.bpf_test_modorder_x.mod.cmd
> Removing tools/testing/selftests/bpf/test_kmods/.bpf_test_modorder_x.mod.o.cmd
> Removing tools/testing/selftests/bpf/test_kmods/.bpf_test_modorder_x.o.cmd
> Removing tools/testing/selftests/bpf/test_kmods/.bpf_test_modorder_y.ko.cmd
> Removing tools/testing/selftests/bpf/test_kmods/.bpf_test_modorder_y.mod.cmd
> Removing tools/testing/selftests/bpf/test_kmods/.bpf_test_modorder_y.mod.o.cmd
> Removing tools/testing/selftests/bpf/test_kmods/.bpf_test_modorder_y.o.cmd
> Removing tools/testing/selftests/bpf/test_kmods/.bpf_test_no_cfi.ko.cmd
> Removing tools/testing/selftests/bpf/test_kmods/.bpf_test_no_cfi.mod.cmd
> Removing tools/testing/selftests/bpf/test_kmods/.bpf_test_no_cfi.mod.o.cmd
> Removing tools/testing/selftests/bpf/test_kmods/.bpf_test_no_cfi.o.cmd
> Removing tools/testing/selftests/bpf/test_kmods/.bpf_test_rqspinlock.ko.cmd
> Removing tools/testing/selftests/bpf/test_kmods/.bpf_test_rqspinlock.mod.cmd
> Removing tools/testing/selftests/bpf/test_kmods/.bpf_test_rqspinlock.mod.o.cmd
> Removing tools/testing/selftests/bpf/test_kmods/.bpf_test_rqspinlock.o.cmd
> Removing tools/testing/selftests/bpf/test_kmods/.bpf_testmod.ko.cmd
> Removing tools/testing/selftests/bpf/test_kmods/.bpf_testmod.mod.cmd
> Removing tools/testing/selftests/bpf/test_kmods/.bpf_testmod.mod.o.cmd
> Removing tools/testing/selftests/bpf/test_kmods/.bpf_testmod.o.cmd
> Removing tools/testing/selftests/bpf/test_kmods/.bpf_testmod.o.d
> Removing tools/testing/selftests/bpf/test_kmods/.module-common.o
> Removing tools/testing/selftests/bpf/test_kmods/.modules.order.cmd
> Removing tools/testing/selftests/bpf/test_kmods/Module.symvers
> Removing tools/testing/selftests/bpf/test_kmods/bpf_test_modorder_x.ko
> Removing tools/testing/selftests/bpf/test_kmods/bpf_test_modorder_x.mod
> Removing tools/testing/selftests/bpf/test_kmods/bpf_test_modorder_x.mod.c
> Removing tools/testing/selftests/bpf/test_kmods/bpf_test_modorder_x.mod.o
> Removing tools/testing/selftests/bpf/test_kmods/bpf_test_modorder_x.o
> Removing tools/testing/selftests/bpf/test_kmods/bpf_test_modorder_y.ko
> Removing tools/testing/selftests/bpf/test_kmods/bpf_test_modorder_y.mod
> Removing tools/testing/selftests/bpf/test_kmods/bpf_test_modorder_y.mod.c
> Removing tools/testing/selftests/bpf/test_kmods/bpf_test_modorder_y.mod.o
> Removing tools/testing/selftests/bpf/test_kmods/bpf_test_modorder_y.o
> Removing tools/testing/selftests/bpf/test_kmods/bpf_test_no_cfi.ko
> Removing tools/testing/selftests/bpf/test_kmods/bpf_test_no_cfi.mod
> Removing tools/testing/selftests/bpf/test_kmods/bpf_test_no_cfi.mod.c
> Removing tools/testing/selftests/bpf/test_kmods/bpf_test_no_cfi.mod.o
> Removing tools/testing/selftests/bpf/test_kmods/bpf_test_no_cfi.o
> Removing tools/testing/selftests/bpf/test_kmods/bpf_test_rqspinlock.ko
> Removing tools/testing/selftests/bpf/test_kmods/bpf_test_rqspinlock.mod
> Removing tools/testing/selftests/bpf/test_kmods/bpf_test_rqspinlock.mod.c
> Removing tools/testing/selftests/bpf/test_kmods/bpf_test_rqspinlock.mod.o
> Removing tools/testing/selftests/bpf/test_kmods/bpf_test_rqspinlock.o
> Removing tools/testing/selftests/bpf/test_kmods/bpf_testmod.ko
> Removing tools/testing/selftests/bpf/test_kmods/bpf_testmod.mod
> Removing tools/testing/selftests/bpf/test_kmods/bpf_testmod.mod.c
> Removing tools/testing/selftests/bpf/test_kmods/bpf_testmod.mod.o
> Removing tools/testing/selftests/bpf/test_kmods/bpf_testmod.o
> Removing tools/testing/selftests/bpf/test_kmods/modules.order
> Removing tools/testing/selftests/bpf/verification_cert.h
> Removing tools/testing/selftests/bpf/verifier/tests.h
>
> This series fixes this.
>
> Assisted-by: claude sonnet
> Signed-off-by: Ricardo B. Marlière (SUSE) <ricardo@marliere.net>
> ---
> Ricardo B. Marlière (SUSE) (3):
> selftests/bpf: Route generated test headers to OUTPUT
> selftests/bpf: Route libarena build artifacts to OUTPUT
> selftests/bpf: Route test_kmods build artifacts to OUTPUT
>
> tools/testing/selftests/bpf/Makefile | 45 ++++++++++++++-----------
> tools/testing/selftests/bpf/libarena/Makefile | 24 +++++++------
> tools/testing/selftests/bpf/test_kmods/Makefile | 3 ++
> 3 files changed, 42 insertions(+), 30 deletions(-)
> ---
> base-commit: 62cc90241548d5570ee68e01aaba6506964e9811
> change-id: 20260728-selftests-bpf_oot-da8b59be69fc
>
> Best regards,
> --
> Ricardo B. Marlière (SUSE) <ricardo@marliere.net>
>
>
next prev parent reply other threads:[~2026-09-21 20:40 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-29 0:06 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-08-06 20:32 ` Ihor Solodrai
2026-07-29 0:06 ` [PATCH 2/3] selftests/bpf: Route libarena build artifacts " Ricardo B. Marlière (SUSE)
2026-08-06 20:33 ` Ihor Solodrai
2026-07-29 0:06 ` [PATCH 3/3] selftests/bpf: Route test_kmods " Ricardo B. Marlière (SUSE)
2026-08-06 20:35 ` Ihor Solodrai
2026-08-06 20:29 ` [PATCH 0/3] selftests/bpf: Fixes for out-of-tree builds Ihor Solodrai
2026-08-06 20:47 ` Ricardo B. Marlière
2026-09-21 20:40 ` Nico Pache (Red Hat) [this message]
2026-09-21 21:04 ` Eduard Zingerman
2026-09-21 21:15 ` Nico Pache (Red Hat)
2026-09-21 21:42 ` Eduard Zingerman
2026-09-21 21:42 ` Alexei Starovoitov
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=6f95ec90-194a-4304-9673-c7bb50065223@linux.dev \
--to=nico.pache@linux.dev \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=emil@etsalapatis.com \
--cc=ihor.solodrai@linux.dev \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=memxor@gmail.com \
--cc=nickolay.lysenko@gmail.com \
--cc=ricardo@marliere.net \
--cc=shuah@kernel.org \
--cc=song@kernel.org \
--cc=yonghong.song@linux.dev \
/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
all inboxes | Powered by JetHome®