Skip to contentSkip to conversation

selftests/bpf: A few edge case fixes

PATCH Applied Ricardo B. Marlière 3 participants 6 messages Jul 20 – Jul 21

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

v2 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

---
Changes in v2:
- Squashed first 2 commits
- Removed redundant copy of bpftool due to TEST_GEN_PROGS_EXTENDED
- Installed *.BTF instead of only resolve_btfids.test.o.BTF
- Link to v1: https://patch.msgid.link/[email protected]

To: Andrii Nakryiko <[email protected]>
To: Eduard Zingerman <[email protected]>
To: Alexei Starovoitov <[email protected]>
To: Daniel Borkmann <[email protected]>
To: Kumar Kartikeya Dwivedi <[email protected]>
To: Martin KaFai Lau <[email protected]>
To: Song Liu <[email protected]>
To: Yonghong Song <[email protected]>
To: Jiri Olsa <[email protected]>
To: Emil Tsalapatis <[email protected]>
To: Shuah Khan <[email protected]>
To: "Alexis Lothoré (eBPF Foundation)" <[email protected]>
To: Ihor Solodrai <[email protected]>
To: Christian Brauner <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]

---
Ricardo B. Marlière (3):
selftests/bpf: Fix make install target 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              | 7 ++++---
 tools/testing/selftests/bpf/prog_tests/lsm_bdev.c | 3 ++-
 3 files changed, 8 insertions(+), 5 deletions(-)

---
base-commit: 1590cf0329716306e948a8fc29f1d3ee87d3989f
change-id: 20260710-selftests-bpf_fixes-06e9a2eb3c67

Best regards,

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

PATCH v2 1/3 selftests/bpf: Fix make install target

After "make install", test_progs fails because two files end up in the wrong place:

- bpftool: TEST_GEN_PROGS_EXTENDED flattens it into $(INSTALL_PATH), losing the tools/sbin/ prefix that detect_bpftool_path() expects. Remove it from TEST_GEN_PROGS_EXTENDED and install it explicitly under tools/sbin/ instead.

- *.BTF: resolve_btfids writes resolve_btfids.test.o.BTF as a side-effect of the build but INSTALL_RULE never copies it over. Install all *.BTF files alongside the rest of the per-flavor output.

Fixes f21fae577446 ("selftests/bpf: Add a few helpers for bpftool testing")
Fixes 522397d05e7d ("resolve_btfids: Change in-place update with raw binary output")
---
 tools/testing/selftests/bpf/Makefile | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
tools/testing/selftests/bpf/Makefile +4 -3
index b642ee489ea6..55d394438705 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
@@ -1055,10 +1053,13 @@ 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/
+	@rsync -a $(if $(PERMISSIVE),--ignore-missing-args) $(OUTPUT)/*.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/*.BTF \
 			$(INSTALL_PATH)/$$DIR;				  \
 	done
 endef
Signature · 1 line
2.55.0
reviewer Acked-by on v2 1/3
#2 lore raw

Re: [PATCH v2 1/3] selftests/bpf: Fix make install target

Quoted 8 lines · Ricardo B. Marlière

After "make install", test_progs fails because two files end up in the wrong place:

- bpftool: TEST_GEN_PROGS_EXTENDED flattens it into $(INSTALL_PATH), losing the tools/sbin/ prefix that detect_bpftool_path() expects. Remove it from TEST_GEN_PROGS_EXTENDED and install it explicitly under tools/sbin/ instead.

Quoted 7 lines

- *.BTF: resolve_btfids writes resolve_btfids.test.o.BTF as a side-effect of the build but INSTALL_RULE never copies it over. Install all *.BTF files alongside the rest of the per-flavor output.

Fixes f21fae577446 ("selftests/bpf: Add a few helpers for bpftool testing")
Fixes 522397d05e7d ("resolve_btfids: Change in-place update with raw binary output")

Thanks!

Quoted 33 lines
---
  tools/testing/selftests/bpf/Makefile | 7 ++++---
  1 file changed, 4 insertions(+), 3 deletions(-)
tools/testing/selftests/bpf/Makefile +4 -3
index b642ee489ea6..55d394438705 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
@@ -1055,10 +1053,13 @@ 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/
+	@rsync -a $(if $(PERMISSIVE),--ignore-missing-args) $(OUTPUT)/*.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/*.BTF \
  			$(INSTALL_PATH)/$$DIR;				  \
  	done
  endef
#3 lore raw

PATCH v2 2/3 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.55.0
#4 lore raw

PATCH v2 3/3 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.

Fixes 1ce3a60e3c28 ("libbpf: auto-resolve programs/libraries when necessary for uprobes")
---
 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.55.0
#5 lore raw
In reply to Ricardo B. Marlière
This series was applied to bpf/bpf-next.git (master) by Kumar Kartikeya Dwivedi <[email protected]>:

Hello:

This series was applied to bpf/bpf-next.git (master) by Kumar Kartikeya Dwivedi <[email protected]>:

Quoted 8 lines · On Mon, 20 Jul 2026 08:13:06 -0300 you wrote:

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

[...]

Here is the summary with links:
- [v2,1/3] selftests/bpf: Fix make install target

    https://git.kernel.org/bpf/bpf-next/c/0b236ac75d04
  - [v2,2/3] selftests/bpf: Fix lsm_bdev dev_t encoding mismatch
    https://git.kernel.org/bpf/bpf-next/c/71cf3f3275e5
  - [v2,3/3] libbpf: Search /lib64 and /lib in resolve_full_path()
    https://git.kernel.org/bpf/bpf-next/c/7b5ae0481efd

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html