Skip to contentSkip to conversation

selftests/bpf: A few edge case fixes

PATCH Superseded Ricardo B. Marlière 4 participants 17 messages Jul 10 – Jul 20

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

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

Assisted-by Claude Sonnet 5

---
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]>
#1 lore raw

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.

Fixes f21fae577446 ("selftests/bpf: Add a few helpers for bpftool testing")
---
 tools/testing/selftests/bpf/Makefile | 2 ++
 1 file changed, 2 insertions(+)
tools/testing/selftests/bpf/Makefile +2 -0
index b642ee489ea6..47911c9b4977 100644
@@ -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
#2 lore raw

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.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.

Quoted 7 lines

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.

Fixes f21fae577446 ("selftests/bpf: Add a few helpers for bpftool testing")

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
index b642ee489ea6..47911c9b4977 100644
@@ -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
#3 lore raw

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.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.

Quoted 7 lines

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.

Fixes f21fae577446 ("selftests/bpf: Add a few helpers for bpftool testing")

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_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.

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
index b642ee489ea6..47911c9b4977 100644
@@ -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)	  \
reviewer
#4 lore raw

Re: [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.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.

Quoted 7 lines

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.

Fixes f21fae577446 ("selftests/bpf: Add a few helpers for bpftool testing")

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_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, 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
index b642ee489ea6..47911c9b4977 100644
@@ -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
index 7260d672acf7..c776913bc32f 100644
@@ -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)	  \
#5 lore raw

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.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.

Quoted 7 lines

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.

Fixes f21fae577446 ("selftests/bpf: Add a few helpers for bpftool testing")

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_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, 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
index b642ee489ea6..47911c9b4977 100644
@@ -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
index 7260d672acf7..c776913bc32f 100644
@@ -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 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)	  \
#6 lore raw

Re: [PATCH 1/4] selftests/bpf: Install bpftool where test_progs expects to find it

In reply to Ihor Solodrai
Quoted 37 lines · Ihor Solodrai
Quoted 27 lines · Alexis Lothoré

Hi,

Quoted 12 lines · Ricardo B. Marlière

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.

Quoted 7 lines

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.

Fixes f21fae577446 ("selftests/bpf: Add a few helpers for bpftool testing")

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_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.

Quoted 3 lines

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.

Indeed, ok then :)

Thanks,

Alexis

Quoted 4 lines
Quoted 4 lines

Alexis

[1] https://lore.kernel.org/all/[email protected]/

Signature · 3 lines
Alexis Lothoré, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
#7 lore raw

PATCH 2/4 selftests/bpf: Install resolve_btfids.test.o.BTF where the test expects it

In reply to Ricardo B. Marlière

prog_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.

Fixes 522397d05e7d ("resolve_btfids: Change in-place update with raw binary output")
---
 tools/testing/selftests/bpf/Makefile | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tools/testing/selftests/bpf/Makefile +2 -1
index 47911c9b4977..7260d672acf7 100644
@@ -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
reviewer
#8 lore raw

Re: [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.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.

Fixes 522397d05e7d ("resolve_btfids: Change in-place update with raw binary output")
---
 tools/testing/selftests/bpf/Makefile | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tools/testing/selftests/bpf/Makefile +0 -0
index 47911c9b4977..7260d672acf7 100644

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
#9 lore raw

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.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.

Fixes 522397d05e7d ("resolve_btfids: Change in-place update with raw binary output")
---
 tools/testing/selftests/bpf/Makefile | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tools/testing/selftests/bpf/Makefile +0 -0
index 47911c9b4977..7260d672acf7 100644

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.

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/*.BTF

Then 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
#10 lore raw

PATCH 3/4 selftests/bpf: Fix lsm_bdev dev_t encoding mismatch

In reply to Ricardo B. Marlière

progs/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.

Fixes 96f4c251a087 ("selftests/bpf: add block device management selftests")
---
 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
index a970798e1173..28bc4b117f41 100644
@@ -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
reviewer Acked-by on v1 3/4
#11 lore raw

Re: [PATCH 3/4] selftests/bpf: Fix lsm_bdev dev_t encoding mismatch

Quoted 36 lines · Ricardo B. Marlière

progs/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.

Fixes 96f4c251a087 ("selftests/bpf: add block device management selftests")
---
 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
index a970798e1173..28bc4b117f41 100644
@@ -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,
 
#12 lore raw

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.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.

Fixes 96f4c251a087 ("selftests/bpf: add block device management selftests")
---
 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
index a970798e1173..28bc4b117f41 100644
@@ -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);

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,
 
#13 lore raw

PATCH 4/4 libbpf: Search /lib64 and /lib in resolve_full_path()

In reply to Ricardo B. Marlière

attach_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
index 1368752aa13c..1ab939dfb7f0 100644
@@ -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
#14 lore raw

Re: [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_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.

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:

Fixes 1ce3a60e3c28 ("libbpf: auto-resolve programs/libraries when necessary for uprobes")

---
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

reviewer Acked-by on v1 4/4
#15 lore raw

Re: [PATCH 4/4] libbpf: Search /lib64 and /lib in resolve_full_path()

In reply to Ricardo B. Marlière
Quoted 18 lines · Ricardo B. Marlière

attach_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 +0 -0
index 1368752aa13c..1ab939dfb7f0 100644
@@ -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 -0
 		perm = R_OK;
 	} else {
 		search_paths[0] = getenv("PATH");
reviewer
#16 lore raw
In reply to Ricardo B. Marlière
Quoted 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_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

Assisted-by Claude Sonnet 5

---
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()

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-06e9a2eb3c67

Best regards,

Signature · 1 line
Ricardo B. Marlière <[email protected]>