Skip to content

Commit ffd0a37

Browse files
anakryikoAlexei Starovoitov
authored andcommitted
selftests/bpf: Fix bpf_testmod.ko recompilation logic
bpf_testmod.ko build rule declared dependency on VMLINUX_BTF, but the variable itself was initialized after the rule was declared, which often caused bpf_testmod.ko to not be re-compiled. Fix by moving VMLINUX_BTF determination sooner. Also enforce bpf_testmod.ko recompilation when we detect that vmlinux image changed by removing bpf_testmod/bpf_testmod.ko. This is necessary to generate correct module's split BTF. Without it, Kbuild's module build logic might determine that nothing changed on the kernel side and thus bpf_testmod.ko shouldn't be rebuilt, so won't re-generate module BTF, which often leads to module's BTF with wrong string offsets against vmlinux BTF. Removing .ko file forces Kbuild to re-build the module. Fixes: 9f7fa22 ("selftests/bpf: Add bpf_testmod kernel module for testing") Reported-by: Alexei Starovoitov <[email protected]> Signed-off-by: Andrii Nakryiko <[email protected]> Signed-off-by: Alexei Starovoitov <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 092fde0 commit ffd0a37

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

tools/testing/selftests/bpf/Makefile

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,13 @@ INCLUDE_DIR := $(SCRATCH_DIR)/include
116116
BPFOBJ := $(BUILD_DIR)/libbpf/libbpf.a
117117
RESOLVE_BTFIDS := $(BUILD_DIR)/resolve_btfids/resolve_btfids
118118

119+
VMLINUX_BTF_PATHS ?= $(if $(O),$(O)/vmlinux) \
120+
$(if $(KBUILD_OUTPUT),$(KBUILD_OUTPUT)/vmlinux) \
121+
../../../../vmlinux \
122+
/sys/kernel/btf/vmlinux \
123+
/boot/vmlinux-$(shell uname -r)
124+
VMLINUX_BTF ?= $(abspath $(firstword $(wildcard $(VMLINUX_BTF_PATHS))))
125+
119126
# Define simple and short `make test_progs`, `make test_sysctl`, etc targets
120127
# to build individual tests.
121128
# NOTE: Semicolon at the end is critical to override lib.mk's default static
@@ -140,20 +147,14 @@ $(OUTPUT)/urandom_read: urandom_read.c
140147

141148
$(OUTPUT)/bpf_testmod.ko: $(VMLINUX_BTF) $(wildcard bpf_testmod/Makefile bpf_testmod/*.[ch])
142149
$(call msg,MOD,,$@)
150+
$(Q)$(RM) bpf_testmod/bpf_testmod.ko # force re-compilation
143151
$(Q)$(MAKE) $(submake_extras) -C bpf_testmod
144152
$(Q)cp bpf_testmod/bpf_testmod.ko $@
145153

146154
$(OUTPUT)/test_stub.o: test_stub.c $(BPFOBJ)
147155
$(call msg,CC,,$@)
148156
$(Q)$(CC) -c $(CFLAGS) -o $@ $<
149157

150-
VMLINUX_BTF_PATHS ?= $(if $(O),$(O)/vmlinux) \
151-
$(if $(KBUILD_OUTPUT),$(KBUILD_OUTPUT)/vmlinux) \
152-
../../../../vmlinux \
153-
/sys/kernel/btf/vmlinux \
154-
/boot/vmlinux-$(shell uname -r)
155-
VMLINUX_BTF ?= $(abspath $(firstword $(wildcard $(VMLINUX_BTF_PATHS))))
156-
157158
DEFAULT_BPFTOOL := $(SCRATCH_DIR)/sbin/bpftool
158159

159160
$(OUTPUT)/runqslower: $(BPFOBJ) | $(DEFAULT_BPFTOOL)

0 commit comments

Comments
 (0)