selftests/bpf: A few edge case fixes
Subsystems (4)
cover selftests/bpf: A few edge case fixes
Hi,
Please consider merging the following fixes, found by means of targeting BPF selftests through openQA [1].
[1]: e.g. https://openqa.opensuse.org/tests/6087703
1/4 ("libbpf: Search /lib64 and /lib in resolve_full_path()")
- Hit by testing an older SLES root filesystem.
2/4 ("selftests/bpf: Fix lsm_bdev dev_t encoding mismatch")
- https://openqa.opensuse.org/tests/6087703/logfile?filename=test_progs.tap.txt#line-2706
3/4 ("selftests/bpf: Install resolve_btfids.test.o.BTF where the test expects it")
- https://openqa.opensuse.org/tests/6087703/logfile?filename=test_progs.tap.txt#line-3332
4/4 ("selftests/bpf: Install bpftool where test_progs expects to find it")
- https://openqa.opensuse.org/tests/6087703/logfile?filename=test_progs.tap.txt#line-806
- https://openqa.opensuse.org/tests/6087703#step/test_bpftool_build_sh/1
- https://openqa.opensuse.org/tests/6087703#step/test_doc_build_sh/1
The build process is done at runtime with BPF_STRICT_BUILD=0:
https://openqa.opensuse.org/tests/6087703/logfile?filename=serial_terminal.txt#line-1937
---
Ricardo B. Marlière (4):
selftests/bpf: Install bpftool where test_progs expects to find it selftests/bpf: Install resolve_btfids.test.o.BTF where the test expects it selftests/bpf: Fix lsm_bdev dev_t encoding mismatch
libbpf: Search /lib64 and /lib in resolve_full_path()
tools/lib/bpf/libbpf.c | 3 ++- tools/testing/selftests/bpf/Makefile | 5 ++++- tools/testing/selftests/bpf/prog_tests/lsm_bdev.c | 3 ++- 3 files changed, 8 insertions(+), 3 deletions(-)
---
base-commit: a635d6748234582ea287c5ffeae28b9b23f91c7e
change-id: 20260710-selftests-bpf_fixes-06e9a2eb3c67
Best regards,
Signature · 1 line
Ricardo B. Marlière <[email protected]>
PATCH 1/4 selftests/bpf: Install bpftool where test_progs expects to find it
bpftool_helpers.c looks for bpftool at "tools/sbin/bpftool" or "../tools/sbin/bpftool" relative to the running test_progs binary, matching the build directory layout where bpftool sits at $(OUTPUT)/tools/sbin/bpftool.
INSTALL_RULE installs bpftool through the generic TEST_GEN_PROGS_EXTENDED mechanism, which flattens it straight into $(INSTALL_PATH) and loses the tools/sbin/ prefix. After "make install", every flavor of test_progs, including the default one, fails to locate bpftool, and bpftool_maps_access and bpftool_metadata error out with "Failed to detect bpftool path", even though bpftool itself built and installed fine.
Explicitly install bpftool under tools/sbin/ in the installed tree so its relative location matches what detect_bpftool_path() already expects, restoring the pre-install layout instead of introducing a new one.
--- tools/testing/selftests/bpf/Makefile | 2 ++ 1 file changed, 2 insertions(+)
tools/testing/selftests/bpf/Makefile +2 -0
@@ -1055,6 +1055,8 @@ endif DEFAULT_INSTALL_RULE := $(INSTALL_RULE) override define INSTALL_RULE $(DEFAULT_INSTALL_RULE) + @mkdir -p $(INSTALL_PATH)/tools/sbin + @rsync -a $(if $(PERMISSIVE),--ignore-missing-args) $(TRUNNER_BPFTOOL) $(INSTALL_PATH)/tools/sbin/ @for DIR in $(TEST_INST_SUBDIRS); do \ mkdir -p $(INSTALL_PATH)/$$DIR; \ rsync -a $(if $(PERMISSIVE),--ignore-missing-args) \
Signature · 1 line
2.54.0
Re: [PATCH 1/4] selftests/bpf: Install bpftool where test_progs expects to find it
Hi,
Quoted 12 lines · Ricardo B. Marlière
bpftool_helpers.clooks for bpftool at "tools/sbin/bpftool" or "../tools/sbin/bpftool" relative to the runningtest_progsbinary, matching the build directory layout where bpftool sits at $(OUTPUT)/tools/sbin/bpftool.
INSTALL_RULEinstalls bpftool through the genericTEST_GEN_PROGS_EXTENDEDmechanism, which flattens it straight into $(INSTALL_PATH) and loses thetools/sbin/prefix. After "make install", every flavor oftest_progs, including the default one, fails to locate bpftool, andbpftool_maps_accessandbpftool_metadataerror out with "Failed to detect bpftool path", even though bpftool itself built and installed fine.
Quoted 7 lines
Explicitly install bpftool under
tools/sbin/in the installed tree so its relative location matches whatdetect_bpftool_path()already expects, restoring the pre-install layout instead of introducing a new one.Fixes f21fae577446 ("selftests/bpf: Add a few helpers for bpftool testing")Signed-off-by Ricardo B. Marlière <[email protected]>
I did not face the issue because I am running the selftests in-tree, and the CI seems to do the same, but for users using selftests after running make install, I guess the change makes sense.
That's not the first fix aiming to improve bpftool detection/installation (eg the BPFTOOL env variable, see [1]), so it makes me wonder if we shouldn't just make bpftool part of TRUNNER_EXTRA_FILES for all flavours of test_progs, similarly to other binaries needed during tests (eg: urandom_read), instead of just adding some bpftool-specific details in this generic install rule, and just make the test runners assume that the needed binary is in the same directory.
Alexis
[1] https://lore.kernel.org/all/[email protected]/
Quoted 17 lines
--- tools/testing/selftests/bpf/Makefile | 2 ++ 1 file changed, 2 insertions(+)tools/testing/selftests/bpf/Makefile +2
-0@@ -1055,6 +1055,8 @@ endif DEFAULT_INSTALL_RULE := $(INSTALL_RULE) override define INSTALL_RULE $(DEFAULT_INSTALL_RULE) + @mkdir -p $(INSTALL_PATH)/tools/sbin + @rsync -a $(if $(PERMISSIVE),--ignore-missing-args) $(TRUNNER_BPFTOOL) $(INSTALL_PATH)/tools/sbin/ @for DIR in $(TEST_INST_SUBDIRS); do \ mkdir -p $(INSTALL_PATH)/$$DIR; \ rsync -a $(if $(PERMISSIVE),--ignore-missing-args) \
Signature · 3 lines
Alexis Lothoré, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
Re: [PATCH 1/4] selftests/bpf: Install bpftool where test_progs expects to find it
Quoted 27 lines · Alexis Lothoré
Hi,
Quoted 12 lines · Ricardo B. Marlière
bpftool_helpers.clooks for bpftool at "tools/sbin/bpftool" or "../tools/sbin/bpftool" relative to the runningtest_progsbinary, matching the build directory layout where bpftool sits at $(OUTPUT)/tools/sbin/bpftool.
INSTALL_RULEinstalls bpftool through the genericTEST_GEN_PROGS_EXTENDEDmechanism, which flattens it straight into $(INSTALL_PATH) and loses thetools/sbin/prefix. After "make install", every flavor oftest_progs, including the default one, fails to locate bpftool, andbpftool_maps_accessandbpftool_metadataerror out with "Failed to detect bpftool path", even though bpftool itself built and installed fine.Quoted 7 lines
Explicitly install bpftool under
tools/sbin/in the installed tree so its relative location matches whatdetect_bpftool_path()already expects, restoring the pre-install layout instead of introducing a new one.Fixes f21fae577446 ("selftests/bpf: Add a few helpers for bpftool testing")Signed-off-by Ricardo B. Marlière <[email protected]>I did not face the issue because I am running the selftests in-tree, and the CI seems to do the same, but for users using selftests after running
make install, I guess the change makes sense.
Quoted 8 lines
That's not the first fix aiming to improve bpftool detection/installation (eg the BPFTOOL env variable, see [1]), so it makes me wonder if we shouldn't just make bpftool part of
TRUNNER_EXTRA_FILESfor all flavours oftest_progs, similarly to other binaries needed during tests (eg:urandom_read), instead of just adding some bpftool-specific details in this generic install rule, and just make the test runners assume that the needed binary is in the same directory.
I'm not sure TRUNNER_EXTRA_FILES can be used like that, because it gets reset in test_maps definition. But maybe we can use a symlink like what's done in $(USE_BOOTSTRAP)bpftool
Quoted 22 lines
Alexis
[1] https://lore.kernel.org/all/[email protected]/
Quoted 17 lines
--- tools/testing/selftests/bpf/Makefile | 2 ++ 1 file changed, 2 insertions(+)tools/testing/selftests/bpf/Makefile +2
-0@@ -1055,6 +1055,8 @@ endif DEFAULT_INSTALL_RULE := $(INSTALL_RULE) override define INSTALL_RULE $(DEFAULT_INSTALL_RULE) + @mkdir -p $(INSTALL_PATH)/tools/sbin + @rsync -a $(if $(PERMISSIVE),--ignore-missing-args) $(TRUNNER_BPFTOOL) $(INSTALL_PATH)/tools/sbin/ @for DIR in $(TEST_INST_SUBDIRS); do \ mkdir -p $(INSTALL_PATH)/$$DIR; \ rsync -a $(if $(PERMISSIVE),--ignore-missing-args) \
Ihor Solodrai
reviewerRe: [PATCH 1/4] selftests/bpf: Install bpftool where test_progs expects to find it
In reply to Alexis LothoréQuoted 27 lines · Alexis Lothoré
Hi,
Quoted 12 lines · Ricardo B. Marlière
bpftool_helpers.clooks for bpftool at "tools/sbin/bpftool" or "../tools/sbin/bpftool" relative to the runningtest_progsbinary, matching the build directory layout where bpftool sits at $(OUTPUT)/tools/sbin/bpftool.
INSTALL_RULEinstalls bpftool through the genericTEST_GEN_PROGS_EXTENDEDmechanism, which flattens it straight into $(INSTALL_PATH) and loses thetools/sbin/prefix. After "make install", every flavor oftest_progs, including the default one, fails to locate bpftool, andbpftool_maps_accessandbpftool_metadataerror out with "Failed to detect bpftool path", even though bpftool itself built and installed fine.Quoted 7 lines
Explicitly install bpftool under
tools/sbin/in the installed tree so its relative location matches whatdetect_bpftool_path()already expects, restoring the pre-install layout instead of introducing a new one.Fixes f21fae577446 ("selftests/bpf: Add a few helpers for bpftool testing")Signed-off-by Ricardo B. Marlière <[email protected]>I did not face the issue because I am running the selftests in-tree, and the CI seems to do the same, but for users using selftests after running
make install, I guess the change makes sense.
Quoted 8 lines
That's not the first fix aiming to improve bpftool detection/installation (eg the BPFTOOL env variable, see [1]), so it makes me wonder if we shouldn't just make bpftool part of
TRUNNER_EXTRA_FILESfor all flavours oftest_progs, similarly to other binaries needed during tests (eg:urandom_read), instead of just adding some bpftool-specific details in this generic install rule, and just make the test runners assume that the needed binary is in the same directory.
Alexis, using TRUNNER_EXTRA_FILES is a bit worse because that would copy bpftool into every flavor subdir. I think just doing a single rsync on install is fine.
Quoted 9 lines
Alexis
[1] https://lore.kernel.org/all/[email protected]/
Quoted 4 lines
--- tools/testing/selftests/bpf/Makefile | 2 ++ 1 file changed, 2 insertions(+)
Quoted 10 lines
tools/testing/selftests/bpf/Makefile endif · line 1059
Quoted 10 lines
tools/testing/selftests/bpf/Makefile +2
-0@@ -1055,6 +1055,8 @@ endif DEFAULT_INSTALL_RULE := $(INSTALL_RULE) override define INSTALL_RULE $(DEFAULT_INSTALL_RULE) + @mkdir -p $(INSTALL_PATH)/tools/sbin + @rsync -a $(if $(PERMISSIVE),--ignore-missing-args) $(TRUNNER_BPFTOOL) $(INSTALL_PATH)/tools/sbin/
It looks like we still have a redundant copy of bpftool because of:
selftests/bpf/Makefile:327
TEST_GEN_PROGS_EXTENDED += $(TRUNNER_BPFTOOL)
selftets/lib.mk:153
$(eval INSTALL_LIST = $(TEST_GEN_PROGS_EXTENDED)) $(INSTALL_SINGLE_RULE)
Ricardo, does it makes sense to remove it with your fix?
tools/testing/selftests/bpf/Makefile +0 -2
@@ -324,8 +324,6 @@ TRUNNER_BPFTOOL := $(DEFAULT_BPFTOOL) USE_BOOTSTRAP := "bootstrap/" endif -TEST_GEN_PROGS_EXTENDED += $(TRUNNER_BPFTOOL) - $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED): $(BPFOBJ) TESTING_HELPERS := $(OUTPUT)/testing_helpers.o
Quoted 7 lines
Quoted 3 lines
tools/testing/selftests/bpf/Makefile +0
-0@for DIR in $(TEST_INST_SUBDIRS); do \ mkdir -p $(INSTALL_PATH)/$$DIR; \ rsync -a $(if $(PERMISSIVE),--ignore-missing-args) \
Re: [PATCH 1/4] selftests/bpf: Install bpftool where test_progs expects to find it
Quoted 66 lines · Ihor Solodrai
Quoted 27 lines · Alexis Lothoré
Hi,
Quoted 12 lines · Ricardo B. Marlière
bpftool_helpers.clooks for bpftool at "tools/sbin/bpftool" or "../tools/sbin/bpftool" relative to the runningtest_progsbinary, matching the build directory layout where bpftool sits at $(OUTPUT)/tools/sbin/bpftool.
INSTALL_RULEinstalls bpftool through the genericTEST_GEN_PROGS_EXTENDEDmechanism, which flattens it straight into $(INSTALL_PATH) and loses thetools/sbin/prefix. After "make install", every flavor oftest_progs, including the default one, fails to locate bpftool, andbpftool_maps_accessandbpftool_metadataerror out with "Failed to detect bpftool path", even though bpftool itself built and installed fine.Quoted 7 lines
Explicitly install bpftool under
tools/sbin/in the installed tree so its relative location matches whatdetect_bpftool_path()already expects, restoring the pre-install layout instead of introducing a new one.Fixes f21fae577446 ("selftests/bpf: Add a few helpers for bpftool testing")Signed-off-by Ricardo B. Marlière <[email protected]>I did not face the issue because I am running the selftests in-tree, and the CI seems to do the same, but for users using selftests after running
make install, I guess the change makes sense.Quoted 8 lines
That's not the first fix aiming to improve bpftool detection/installation (eg the BPFTOOL env variable, see [1]), so it makes me wonder if we shouldn't just make bpftool part of
TRUNNER_EXTRA_FILESfor all flavours oftest_progs, similarly to other binaries needed during tests (eg:urandom_read), instead of just adding some bpftool-specific details in this generic install rule, and just make the test runners assume that the needed binary is in the same directory.Alexis, using
TRUNNER_EXTRA_FILESis a bit worse because that would copy bpftool into every flavor subdir. I think just doing a single rsync on install is fine.Quoted 9 lines
Alexis
[1] https://lore.kernel.org/all/[email protected]/
Quoted 4 lines
--- tools/testing/selftests/bpf/Makefile | 2 ++ 1 file changed, 2 insertions(+)Quoted 10 lines
tools/testing/selftests/bpf/Makefile endif · line 1059
Quoted 10 lines
tools/testing/selftests/bpf/Makefile +2
-0@@ -1055,6 +1055,8 @@ endif DEFAULT_INSTALL_RULE := $(INSTALL_RULE) override define INSTALL_RULE $(DEFAULT_INSTALL_RULE) + @mkdir -p $(INSTALL_PATH)/tools/sbin + @rsync -a $(if $(PERMISSIVE),--ignore-missing-args) $(TRUNNER_BPFTOOL) $(INSTALL_PATH)/tools/sbin/It looks like we still have a redundant copy of bpftool because of:
selftests/bpf/Makefile:327
Quoted 7 lines
TEST_GEN_PROGS_EXTENDED += $(TRUNNER_BPFTOOL)
selftets/lib.mk:153$(eval INSTALL_LIST = $(TEST_GEN_PROGS_EXTENDED)) $(INSTALL_SINGLE_RULE)Ricardo, does it makes sense to remove it with your fix?
I'll check and send v2 accordingly
Quoted 22 lines
tools/testing/selftests/bpf/Makefile +0
-2@@ -324,8 +324,6 @@ TRUNNER_BPFTOOL := $(DEFAULT_BPFTOOL) USE_BOOTSTRAP := "bootstrap/" endif -TEST_GEN_PROGS_EXTENDED += $(TRUNNER_BPFTOOL) - $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED): $(BPFOBJ) TESTING_HELPERS := $(OUTPUT)/testing_helpers.oQuoted 8 lines
Quoted 4 lines
tools/testing/selftests/bpf/Makefile +0
-0@for DIR in $(TEST_INST_SUBDIRS); do \ mkdir -p $(INSTALL_PATH)/$$DIR; \ rsync -a $(if $(PERMISSIVE),--ignore-missing-args) \
Re: [PATCH 1/4] selftests/bpf: Install bpftool where test_progs expects to find it
In reply to Ihor SolodraiQuoted 37 lines · Ihor Solodrai
Quoted 27 lines · Alexis Lothoré
Hi,
Quoted 12 lines · Ricardo B. Marlière
bpftool_helpers.clooks for bpftool at "tools/sbin/bpftool" or "../tools/sbin/bpftool" relative to the runningtest_progsbinary, matching the build directory layout where bpftool sits at $(OUTPUT)/tools/sbin/bpftool.
INSTALL_RULEinstalls bpftool through the genericTEST_GEN_PROGS_EXTENDEDmechanism, which flattens it straight into $(INSTALL_PATH) and loses thetools/sbin/prefix. After "make install", every flavor oftest_progs, including the default one, fails to locate bpftool, andbpftool_maps_accessandbpftool_metadataerror out with "Failed to detect bpftool path", even though bpftool itself built and installed fine.Quoted 7 lines
Explicitly install bpftool under
tools/sbin/in the installed tree so its relative location matches whatdetect_bpftool_path()already expects, restoring the pre-install layout instead of introducing a new one.Fixes f21fae577446 ("selftests/bpf: Add a few helpers for bpftool testing")Signed-off-by Ricardo B. Marlière <[email protected]>I did not face the issue because I am running the selftests in-tree, and the CI seems to do the same, but for users using selftests after running
make install, I guess the change makes sense.Quoted 8 lines
That's not the first fix aiming to improve bpftool detection/installation (eg the BPFTOOL env variable, see [1]), so it makes me wonder if we shouldn't just make bpftool part of
TRUNNER_EXTRA_FILESfor all flavours oftest_progs, similarly to other binaries needed during tests (eg:urandom_read), instead of just adding some bpftool-specific details in this generic install rule, and just make the test runners assume that the needed binary is in the same directory.
Quoted 3 lines
Alexis, using
TRUNNER_EXTRA_FILESis a bit worse because that would copy bpftool into every flavor subdir. I think just doing a single rsync on install is fine.
Indeed, ok then :)
Thanks,
Alexis
Quoted 4 lines
Quoted 4 lines
Alexis
Signature · 3 lines
Alexis Lothoré, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
PATCH 2/4 selftests/bpf: Install resolve_btfids.test.o.BTF where the test expects it
In reply to Ricardo B. Marlièreprog_tests/resolve_btfids.c looks for "resolve_btfids.test.o.BTF" relative to the running test_progs binary. resolve_btfids always writes <obj.path>.BTF next to the object it processes, so building resolve_btfids.test.o also produces resolve_btfids.test.o.BTF in the build output directory as a side effect.
INSTALL_RULE never carries it over: it is not part of TEST_FILES, TEST_GEN_FILES or TRUNNER_EXTRA_FILES, and it is not copied by the *.bpf.o rsync used for TEST_INST_SUBDIRS. After "make install", every flavor of test_progs, including the default one, fails with "Failed to load BTF from resolve_btfids.test.o.BTF", even though the file built fine and BTF ID resolution itself works correctly.
Install it next to the rest of the per-flavor build output, using an explicit rsync in INSTALL_RULE like the one already used for bpftool.
--- tools/testing/selftests/bpf/Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
tools/testing/selftests/bpf/Makefile +2 -1
@@ -1057,10 +1057,11 @@ override define INSTALL_RULE $(DEFAULT_INSTALL_RULE) @mkdir -p $(INSTALL_PATH)/tools/sbin @rsync -a $(if $(PERMISSIVE),--ignore-missing-args) $(TRUNNER_BPFTOOL) $(INSTALL_PATH)/tools/sbin/ + @rsync -a $(if $(PERMISSIVE),--ignore-missing-args) $(OUTPUT)/resolve_btfids.test.o.BTF $(INSTALL_PATH)/ @for DIR in $(TEST_INST_SUBDIRS); do \ mkdir -p $(INSTALL_PATH)/$$DIR; \ rsync -a $(if $(PERMISSIVE),--ignore-missing-args) \ - $(OUTPUT)/$$DIR/*.bpf.o \ + $(OUTPUT)/$$DIR/*.bpf.o $(OUTPUT)/$$DIR/resolve_btfids.test.o.BTF \ $(INSTALL_PATH)/$$DIR; \ done endef
Signature · 1 line
2.54.0
Ihor Solodrai
reviewerRe: [PATCH 2/4] selftests/bpf: Install resolve_btfids.test.o.BTF where the test expects it
Quoted 27 lines · Ricardo B. Marlière
prog_tests/resolve_btfids.clooks for "resolve_btfids.test.o.BTF" relative to the runningtest_progsbinary.resolve_btfidsalways writes <obj.path>.BTF next to the object it processes, so building resolve_btfids.test.o also produces resolve_btfids.test.o.BTF in the build output directory as a side effect.
INSTALL_RULEnever carries it over: it is not part ofTEST_FILES,TEST_GEN_FILESorTRUNNER_EXTRA_FILES, and it is not copied by the *.bpf.o rsync used forTEST_INST_SUBDIRS. After "make install", every flavor oftest_progs, including the default one, fails with "Failed to load BTF from resolve_btfids.test.o.BTF", even though the file built fine and BTF ID resolution itself works correctly.Install it next to the rest of the per-flavor build output, using an explicit rsync in
INSTALL_RULElike the one already used for bpftool.Fixes 522397d05e7d ("resolve_btfids: Change in-place update with raw binary output")Signed-off-by Ricardo B. Marlière <[email protected]>--- tools/testing/selftests/bpf/Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)tools/testing/selftests/bpf/Makefile +0
-0
tools/testing/selftests/bpf/Makefile override define INSTALL_RULE · line 1060
Quoted 4 lines
tools/testing/selftests/bpf/Makefile +1
-0@@ -1057,10 +1057,11 @@ override define INSTALL_RULE $(DEFAULT_INSTALL_RULE) @mkdir -p $(INSTALL_PATH)/tools/sbin @rsync -a $(if $(PERMISSIVE),--ignore-missing-args) $(TRUNNER_BPFTOOL) $(INSTALL_PATH)/tools/sbin/ + @rsync -a $(if $(PERMISSIVE),--ignore-missing-args) $(OUTPUT)/resolve_btfids.test.o.BTF $(INSTALL_PATH)/
I think you can squash patches #1 and #2 into a single "Fix make install target" patch.
pw-bot: cr
nit: This hardcodes the filename, and even though we only have one test that needs .BTF currently, you could add *.BTF to the loop:
$(OUTPUT)/$$DIR/*.bpf.o $(OUTPUT)/$$DIR/*.BTF
Then any future test that consumes a raw .BTF gets installed for free.
Quoted 9 lines
tools/testing/selftests/bpf/Makefile +1
-1@for DIR in $(TEST_INST_SUBDIRS); do \ mkdir -p $(INSTALL_PATH)/$$DIR; \ rsync -a $(if $(PERMISSIVE),--ignore-missing-args) \ - $(OUTPUT)/$$DIR/*.bpf.o \ + $(OUTPUT)/$$DIR/*.bpf.o $(OUTPUT)/$$DIR/resolve_btfids.test.o.BTF \ $(INSTALL_PATH)/$$DIR; \ done endef
Re: [PATCH 2/4] selftests/bpf: Install resolve_btfids.test.o.BTF where the test expects it
Quoted 36 lines · Ihor Solodrai
Quoted 27 lines · Ricardo B. Marlière
prog_tests/resolve_btfids.clooks for "resolve_btfids.test.o.BTF" relative to the runningtest_progsbinary.resolve_btfidsalways writes <obj.path>.BTF next to the object it processes, so building resolve_btfids.test.o also produces resolve_btfids.test.o.BTF in the build output directory as a side effect.
INSTALL_RULEnever carries it over: it is not part ofTEST_FILES,TEST_GEN_FILESorTRUNNER_EXTRA_FILES, and it is not copied by the *.bpf.o rsync used forTEST_INST_SUBDIRS. After "make install", every flavor oftest_progs, including the default one, fails with "Failed to load BTF from resolve_btfids.test.o.BTF", even though the file built fine and BTF ID resolution itself works correctly.Install it next to the rest of the per-flavor build output, using an explicit rsync in
INSTALL_RULElike the one already used for bpftool.Fixes 522397d05e7d ("resolve_btfids: Change in-place update with raw binary output")Signed-off-by Ricardo B. Marlière <[email protected]>--- tools/testing/selftests/bpf/Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)tools/testing/selftests/bpf/Makefile +0
-0tools/testing/selftests/bpf/Makefile override define INSTALL_RULE · line 1060
Quoted 4 lines
tools/testing/selftests/bpf/Makefile +1
-0@@ -1057,10 +1057,11 @@ override define INSTALL_RULE $(DEFAULT_INSTALL_RULE) @mkdir -p $(INSTALL_PATH)/tools/sbin @rsync -a $(if $(PERMISSIVE),--ignore-missing-args) $(TRUNNER_BPFTOOL) $(INSTALL_PATH)/tools/sbin/ + @rsync -a $(if $(PERMISSIVE),--ignore-missing-args) $(OUTPUT)/resolve_btfids.test.o.BTF $(INSTALL_PATH)/I think you can squash patches #1 and #2 into a single "Fix make install target" patch.
Quoted 8 lines
pw-bot: cr
nit: This hardcodes the filename, and even though we only have one test that needs .BTF currently, you could add *.BTF to the loop:
$(OUTPUT)/$$DIR/*.bpf.o $(OUTPUT)/$$DIR/*.BTFThen any future test that consumes a raw .BTF gets installed for free.
Good call! I'll prepare v2. Thanks for the review :)
Quoted 10 lines
Quoted 10 lines
tools/testing/selftests/bpf/Makefile +1
-1@for DIR in $(TEST_INST_SUBDIRS); do \ mkdir -p $(INSTALL_PATH)/$$DIR; \ rsync -a $(if $(PERMISSIVE),--ignore-missing-args) \ - $(OUTPUT)/$$DIR/*.bpf.o \ + $(OUTPUT)/$$DIR/*.bpf.o $(OUTPUT)/$$DIR/resolve_btfids.test.o.BTF \ $(INSTALL_PATH)/$$DIR; \ done endef
PATCH 3/4 selftests/bpf: Fix lsm_bdev dev_t encoding mismatch
In reply to Ricardo B. Marlièreprogs/lsm_bdev.c keys its verity_devices hashmap with the raw kernel dev_t read straight off bdev->bd_dev, i.e. MKDEV(major, minor) = (major << 20) | minor. prog_tests/lsm_bdev.c instead builds its lookup key with dev_key = (__u32)st.st_rdev from stat(2), but the stat(2) syscall fills st_rdev via the kernel's new_encode_dev(), a different bit layout: (minor & 0xff) | (major << 8) | ((minor & ~0xff) << 12).
For any device with a non-trivial major these two values differ, so the lookup can never find what the BPF program stored, and test_lsm_bdev() always fails with:
test_lsm_bdev:FAIL:map lookup unexpected error: -2 (errno 2)
Reconstruct the raw kernel dev_t from the decoded major/minor instead of casting st_rdev directly, restoring the layout the BPF program actually reads.
--- tools/testing/selftests/bpf/prog_tests/lsm_bdev.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
tools/testing/selftests/bpf/prog_tests/lsm_bdev.c +2 -1
@@ -17,6 +17,7 @@#include <stdlib.h> #include <string.h> #include <sys/stat.h> +#include <sys/sysmacros.h> #include <sys/types.h> #include <unistd.h> #include "lsm_bdev.skel.h"
@@ -172,7 +173,7 @@ void test_lsm_bdev(void)if (!ASSERT_OK (stat (DM_DEV_PATH , &st),"stat dm dev" )) goto remove_dm; - dev_key = (__u32 )st.st_rdev; + dev_key = (major (st.st_rdev) <<20 ) |minor (st.st_rdev);/* Look up the device in the BPF map and verify. */ err = bpf_map__lookup_elem(skel->maps.verity_devices,
Signature · 1 line
2.54.0
Re: [PATCH 3/4] selftests/bpf: Fix lsm_bdev dev_t encoding mismatch
Quoted 36 lines · Ricardo B. Marlière
progs/lsm_bdev.ckeys itsverity_deviceshashmap with the raw kerneldev_tread straight offbdev->bd_dev, i.e.MKDEV(major, minor)= (major << 20) | minor.prog_tests/lsm_bdev.cinstead builds its lookup key withdev_key= (__u32)st.st_rdev from stat(2), but the stat(2) syscall fillsst_rdevvia the kernel'snew_encode_dev(), a different bit layout: (minor &0xff) | (major << 8) | ((minor & ~0xff) << 12).For any device with a non-trivial major these two values differ, so the lookup can never find what the BPF program stored, and
test_lsm_bdev()always fails with:test_lsm_bdev:FAIL:map lookup unexpected error: -2 (errno 2)
Reconstruct the raw kernel
dev_tfrom the decoded major/minor instead of castingst_rdevdirectly, restoring the layout the BPF program actually reads.Fixes 96f4c251a087 ("selftests/bpf: add block device management selftests")Signed-off-by Ricardo B. Marlière <[email protected]>--- tools/testing/selftests/bpf/prog_tests/lsm_bdev.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)tools/testing/selftests/bpf/prog_tests/lsm_bdev.c +1
-0@@ -17,6 +17,7 @@#include <stdlib.h> #include <string.h> #include <sys/stat.h> +#include <sys/sysmacros.h> #include <sys/types.h> #include <unistd.h> #include "lsm_bdev.skel.h"
tools/testing/selftests/bpf/prog_tests/lsm_bdev.c void test_lsm_bdev(void) · line 176
Quoted 5 lines
tools/testing/selftests/bpf/prog_tests/lsm_bdev.c +1
-1@@ -172,7 +173,7 @@ void test_lsm_bdev(void)if (!ASSERT_OK (stat (DM_DEV_PATH , &st),"stat dm dev" )) goto remove_dm; - dev_key = (__u32 )st.st_rdev; + dev_key = (major (st.st_rdev) <<20 ) |minor (st.st_rdev);
nit: I wonder if there are other tests with this bug. Have you checked?
Quoted 4 lines
tools/testing/selftests/bpf/prog_tests/lsm_bdev.c +0
-0/* Look up the device in the BPF map and verify. */ err = bpf_map__lookup_elem(skel->maps.verity_devices,
Re: [PATCH 3/4] selftests/bpf: Fix lsm_bdev dev_t encoding mismatch
Quoted 40 lines · Ihor Solodrai
Quoted 39 lines · Ricardo B. Marlière
progs/lsm_bdev.ckeys itsverity_deviceshashmap with the raw kerneldev_tread straight offbdev->bd_dev, i.e.MKDEV(major, minor)= (major << 20) | minor.prog_tests/lsm_bdev.cinstead builds its lookup key withdev_key= (__u32)st.st_rdev from stat(2), but the stat(2) syscall fillsst_rdevvia the kernel'snew_encode_dev(), a different bit layout: (minor &0xff) | (major << 8) | ((minor & ~0xff) << 12).For any device with a non-trivial major these two values differ, so the lookup can never find what the BPF program stored, and
test_lsm_bdev()always fails with:test_lsm_bdev:FAIL:map lookup unexpected error: -2 (errno 2)
Reconstruct the raw kernel
dev_tfrom the decoded major/minor instead of castingst_rdevdirectly, restoring the layout the BPF program actually reads.Fixes 96f4c251a087 ("selftests/bpf: add block device management selftests")Signed-off-by Ricardo B. Marlière <[email protected]>--- tools/testing/selftests/bpf/prog_tests/lsm_bdev.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)tools/testing/selftests/bpf/prog_tests/lsm_bdev.c +1
-0@@ -17,6 +17,7 @@#include <stdlib.h> #include <string.h> #include <sys/stat.h> +#include <sys/sysmacros.h> #include <sys/types.h> #include <unistd.h> #include "lsm_bdev.skel.h" @@ -172,7 +173,7 @@ void test_lsm_bdev(void)if (!ASSERT_OK (stat (DM_DEV_PATH , &st),"stat dm dev" )) goto remove_dm;
Quoted 6 lines
tools/testing/selftests/bpf/prog_tests/lsm_bdev.c void test_lsm_bdev(void) · line 176
Quoted 2 lines
tools/testing/selftests/bpf/prog_tests/lsm_bdev.c +1
-1- dev_key = (__u32 )st.st_rdev; + dev_key = (major (st.st_rdev) <<20 ) |minor (st.st_rdev);Acked-by Ihor Solodrai <[email protected]>nit: I wonder if there are other tests with this bug. Have you checked?
I don't think there are.
grepping for "map lookup unexpected error" in
https://openqa.opensuse.org/tests/6106285/logfile?filename=test_progs.tap.txt
shows only lsm_bdev.
Tumbleweed is 7.1.3
Quoted 5 lines
Quoted 5 lines
tools/testing/selftests/bpf/prog_tests/lsm_bdev.c +0
-0/* Look up the device in the BPF map and verify. */ err = bpf_map__lookup_elem(skel->maps.verity_devices,
PATCH 4/4 libbpf: Search /lib64 and /lib in resolve_full_path()
In reply to Ricardo B. Marlièreattach_probe/uprobe-lib and uprobe_autoattach selftests fail with "failed to resolve full path for libc.so.6" on older non-usrmerged distros, where libc.so.6 lives under a top-level /lib64 or /lib rather than /usr/lib64 or /usr/lib. Add /lib64:/lib to the search paths, alongside the existing /usr/lib64:/usr/lib and Debian multiarch entries.
--- tools/lib/bpf/libbpf.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
tools/lib/bpf/libbpf.c +2 -1
@@ -12973,13 +12973,14 @@ static const char *arch_specific_lib_paths(void)/* Get full path to program/shared library. */ static int resolve_full_path (const char *file,char *result,size_t result_sz) { -const char *search_paths[3 ] = {}; +const char *search_paths[4 ] = {};int i, perm;if (str_has_sfx (file,".so" ) ||strstr (file,".so." )) { search_paths[0 ] =getenv ("LD_LIBRARY_PATH" ); search_paths[1 ] ="/usr/lib64:/usr/lib" ; search_paths[2 ] =arch_specific_lib_paths (); + search_paths[3 ] ="/lib64:/lib" ; perm =R_OK ; }else { search_paths[0 ] =getenv ("PATH" );
Signature · 1 line
2.54.0
[email protected]
AI reviewRe: [PATCH 4/4] libbpf: Search /lib64 and /lib in resolve_full_path()
This looks like a bug fix for the shared-library search path. Should this include a Fixes: tag?
Quoted 9 lines
libbpf: Search /lib64 and /lib in
resolve_full_path()attach_probe/uprobe-lib and
uprobe_autoattachselftests fail with "failed to resolve full path for libc.so.6" on older non-usrmerged distros, where libc.so.6 lives under a top-level /lib64 or /lib rather than/usr/lib64or/usr/lib. Add /lib64:/lib to the search paths, alongside the existing /usr/lib64:/usr/lib and Debian multiarch entries.Signed-off-by Ricardo B. Marlière <[email protected]>
This looks like a bug fix for the shared-library search path. Should this include a Fixes: tag?
resolve_full_path() was introduced with a search-path list of only LD_LIBRARY_PATH and "/usr/lib64:/usr/lib", which omitted the top-level /lib64 and /lib directories from the start. The later addition of the Debian multiarch /lib/<triple> paths did not add /lib64:/lib either, so the omission has existed since the function was created:
---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md
CI run summary: https://github.com/kernel-patches/bpf/actions/runs/29127668708
Re: [PATCH 4/4] libbpf: Search /lib64 and /lib in resolve_full_path()
In reply to Ricardo B. MarlièreQuoted 18 lines · Ricardo B. Marlière
attach_probe/uprobe-lib and
uprobe_autoattachselftests fail with "failed to resolve full path for libc.so.6" on older non-usrmerged distros, where libc.so.6 lives under a top-level /lib64 or /lib rather than/usr/lib64or/usr/lib. Add /lib64:/lib to the search paths, alongside the existing /usr/lib64:/usr/lib and Debian multiarch entries.Signed-off-by Ricardo B. Marlière <[email protected]>--- tools/lib/bpf/libbpf.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)tools/lib/bpf/libbpf.c +0
-0@@ -12973,13 +12973,14 @@ static const char *arch_specific_lib_paths(void)/* Get full path to program/shared library. */ static int resolve_full_path (const char *file,char *result,size_t result_sz)
tools/lib/bpf/libbpf.c static const char *arch_specific_lib_paths(void) · line 12983
Quoted 10 lines
tools/lib/bpf/libbpf.c +2
-1{ -const char *search_paths[3 ] = {}; +const char *search_paths[4 ] = {};int i, perm;if (str_has_sfx (file,".so" ) ||strstr (file,".so." )) { search_paths[0 ] =getenv ("LD_LIBRARY_PATH" ); search_paths[1 ] ="/usr/lib64:/usr/lib" ; search_paths[2 ] =arch_specific_lib_paths (); + search_paths[3 ] ="/lib64:/lib" ;
Quoted 4 lines
tools/lib/bpf/libbpf.c +0
-0perm =R_OK ; }else { search_paths[0 ] =getenv ("PATH" );
Ihor Solodrai
reviewerQuoted 33 lines · Ricardo B. Marlière
Hi,
Please consider merging the following fixes, found by means of targeting BPF selftests through openQA [1].
[1]: e.g. https://openqa.opensuse.org/tests/6087703
1/4 ("libbpf: Search /lib64 and /lib in
resolve_full_path()")
- Hit by testing an older SLES root filesystem.2/4 ("selftests/bpf: Fix
lsm_bdevdev_tencoding mismatch")
- https://openqa.opensuse.org/tests/6087703/logfile?filename=test_progs.tap.txt#line-27063/4 ("selftests/bpf: Install resolve_btfids.test.o.BTF where the test expects it")
- https://openqa.opensuse.org/tests/6087703/logfile?filename=test_progs.tap.txt#line-33324/4 ("selftests/bpf: Install bpftool where
test_progsexpects to find it")
- https://openqa.opensuse.org/tests/6087703/logfile?filename=test_progs.tap.txt#line-806
- https://openqa.opensuse.org/tests/6087703#step/test_bpftool_build_sh/1
- https://openqa.opensuse.org/tests/6087703#step/test_doc_build_sh/1The build process is done at runtime with BPF_STRICT_BUILD=0:
https://openqa.opensuse.org/tests/6087703/logfile?filename=serial_terminal.txt#line-1937Assisted-by Claude Sonnet 5Signed-off-by Ricardo B. Marlière <[email protected]>---
Ricardo B. Marlière (4):
selftests/bpf: Install bpftool wheretest_progsexpects to find it selftests/bpf: Install resolve_btfids.test.o.BTF where the test expects it selftests/bpf: Fixlsm_bdevdev_tencoding mismatch
libbpf: Search /lib64 and /lib inresolve_full_path()
Quoted 4 lines
tools/lib/bpf/libbpf.c | 3 ++- tools/testing/selftests/bpf/Makefile | 5 ++++- tools/testing/selftests/bpf/prog_tests/lsm_bdev.c | 3 ++- 3 files changed, 8 insertions(+), 3 deletions(-)
Hi Ricardo,
Thank you for the patches, it's a good set of fixes. We don't use make install on CI, so it's not tested regularly.
I have a couple of comments, sending in a bit.
Quoted 8 lines
---
base-commit:a635d6748234582ea287c5ffeae28b9b23f91c7e
change-id: 20260710-selftests-bpf_fixes-06e9a2eb3c67Best regards,
Signature · 1 line
Ricardo B. Marlière <[email protected]>