提交 49a96da1 编写于 作者: A Andrii Nakryiko 提交者: Zheng Zengkai

selftests/bpf: fix bpf_testmod.ko recompilation logic

mainline inclusion
from mainline-5.11-rc1
commit a67079b0
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I5EUVD
CVE: NA

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=a67079b03165a17f9aceab3dd26b1638af68e0fc

-------------------------------------------------

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.
Reported-by: NAlexei Starovoitov <ast@kernel.org>
Fixes: 9f7fa225 ("selftests/bpf: Add bpf_testmod kernel module for testing")
Signed-off-by: NAndrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/r/20201211015946.4062098-1-andrii@kernel.orgSigned-off-by: NAlexei Starovoitov <ast@kernel.org>
(cherry picked from commit a67079b0)
Signed-off-by: NWang Yufen <wangyufen@huawei.com>

Conflicts:
	tools/testing/selftests/bpf/Makefile
Signed-off-by: NWang Yufen <wangyufen@huawei.com>
上级 7f2c0811
...@@ -116,6 +116,16 @@ INCLUDE_DIR := $(SCRATCH_DIR)/include ...@@ -116,6 +116,16 @@ INCLUDE_DIR := $(SCRATCH_DIR)/include
BPFOBJ := $(BUILD_DIR)/libbpf/libbpf.a BPFOBJ := $(BUILD_DIR)/libbpf/libbpf.a
RESOLVE_BTFIDS := $(BUILD_DIR)/resolve_btfids/resolve_btfids RESOLVE_BTFIDS := $(BUILD_DIR)/resolve_btfids/resolve_btfids
VMLINUX_BTF_PATHS ?= $(if $(O),$(O)/vmlinux) \
$(if $(KBUILD_OUTPUT),$(KBUILD_OUTPUT)/vmlinux) \
../../../../vmlinux \
/sys/kernel/btf/vmlinux \
/boot/vmlinux-$(shell uname -r)
VMLINUX_BTF ?= $(abspath $(firstword $(wildcard $(VMLINUX_BTF_PATHS))))
ifeq ($(VMLINUX_BTF),)
$(error Cannot find a vmlinux for VMLINUX_BTF at any of "$(VMLINUX_BTF_PATHS)")
endif
# Define simple and short `make test_progs`, `make test_sysctl`, etc targets # Define simple and short `make test_progs`, `make test_sysctl`, etc targets
# to build individual tests. # to build individual tests.
# NOTE: Semicolon at the end is critical to override lib.mk's default static # NOTE: Semicolon at the end is critical to override lib.mk's default static
...@@ -140,6 +150,7 @@ $(OUTPUT)/urandom_read: urandom_read.c ...@@ -140,6 +150,7 @@ $(OUTPUT)/urandom_read: urandom_read.c
$(OUTPUT)/bpf_testmod.ko: $(VMLINUX_BTF) $(wildcard bpf_testmod/Makefile bpf_testmod/*.[ch]) $(OUTPUT)/bpf_testmod.ko: $(VMLINUX_BTF) $(wildcard bpf_testmod/Makefile bpf_testmod/*.[ch])
$(call msg,MOD,,$@) $(call msg,MOD,,$@)
$(Q)$(RM) bpf_testmod/bpf_testmod.ko # force re-compilation
$(Q)$(MAKE) $(submake_extras) -C bpf_testmod $(Q)$(MAKE) $(submake_extras) -C bpf_testmod
$(Q)cp bpf_testmod/bpf_testmod.ko $@ $(Q)cp bpf_testmod/bpf_testmod.ko $@
...@@ -147,16 +158,6 @@ $(OUTPUT)/test_stub.o: test_stub.c $(BPFOBJ) ...@@ -147,16 +158,6 @@ $(OUTPUT)/test_stub.o: test_stub.c $(BPFOBJ)
$(call msg,CC,,$@) $(call msg,CC,,$@)
$(Q)$(CC) -c $(CFLAGS) -o $@ $< $(Q)$(CC) -c $(CFLAGS) -o $@ $<
VMLINUX_BTF_PATHS ?= $(if $(O),$(O)/vmlinux) \
$(if $(KBUILD_OUTPUT),$(KBUILD_OUTPUT)/vmlinux) \
../../../../vmlinux \
/sys/kernel/btf/vmlinux \
/boot/vmlinux-$(shell uname -r)
VMLINUX_BTF ?= $(abspath $(firstword $(wildcard $(VMLINUX_BTF_PATHS))))
ifeq ($(VMLINUX_BTF),)
$(error Cannot find a vmlinux for VMLINUX_BTF at any of "$(VMLINUX_BTF_PATHS)")
endif
DEFAULT_BPFTOOL := $(SCRATCH_DIR)/sbin/bpftool DEFAULT_BPFTOOL := $(SCRATCH_DIR)/sbin/bpftool
$(OUTPUT)/runqslower: $(BPFOBJ) | $(DEFAULT_BPFTOOL) $(OUTPUT)/runqslower: $(BPFOBJ) | $(DEFAULT_BPFTOOL)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册