All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/4] selftests/bpf: A few edge case fixes
@ 2026-07-10 22:09 Ricardo B. Marlière
  2026-07-10 22:09 ` [PATCH 1/4] selftests/bpf: Install bpftool where test_progs expects to find it Ricardo B. Marlière
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Ricardo B. Marlière @ 2026-07-10 22:09 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Eduard Zingerman, Kumar Kartikeya Dwivedi, Martin KaFai Lau,
	Song Liu, Yonghong Song, Jiri Olsa, Emil Tsalapatis, Shuah Khan,
	Alexis Lothoré (eBPF Foundation), Ihor Solodrai,
	Christian Brauner
  Cc: bpf, linux-kselftest, linux-kernel, 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
Signed-off-by: Ricardo B. Marlière <rbm@suse.com>
---
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,
--  
Ricardo B. Marlière <rbm@suse.com>


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/4] selftests/bpf: Install bpftool where test_progs expects to find it
  2026-07-10 22:09 [PATCH 0/4] selftests/bpf: A few edge case fixes Ricardo B. Marlière
@ 2026-07-10 22:09 ` Ricardo B. Marlière
  2026-07-13 15:32   ` Alexis Lothoré
  2026-07-10 22:09 ` [PATCH 2/4] selftests/bpf: Install resolve_btfids.test.o.BTF where the test expects it Ricardo B. Marlière
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 7+ messages in thread
From: Ricardo B. Marlière @ 2026-07-10 22:09 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Eduard Zingerman, Kumar Kartikeya Dwivedi, Martin KaFai Lau,
	Song Liu, Yonghong Song, Jiri Olsa, Emil Tsalapatis, Shuah Khan,
	Alexis Lothoré (eBPF Foundation), Ihor Solodrai,
	Christian Brauner
  Cc: bpf, linux-kselftest, linux-kernel, 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.

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")
Signed-off-by: Ricardo B. Marlière <rbm@suse.com>
---
 tools/testing/selftests/bpf/Makefile | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
index b642ee489ea6..47911c9b4977 100644
--- a/tools/testing/selftests/bpf/Makefile
+++ b/tools/testing/selftests/bpf/Makefile
@@ -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)	  \

-- 
2.54.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/4] selftests/bpf: Install resolve_btfids.test.o.BTF where the test expects it
  2026-07-10 22:09 [PATCH 0/4] selftests/bpf: A few edge case fixes Ricardo B. Marlière
  2026-07-10 22:09 ` [PATCH 1/4] selftests/bpf: Install bpftool where test_progs expects to find it Ricardo B. Marlière
@ 2026-07-10 22:09 ` Ricardo B. Marlière
  2026-07-10 22:09 ` [PATCH 3/4] selftests/bpf: Fix lsm_bdev dev_t encoding mismatch Ricardo B. Marlière
  2026-07-10 22:09 ` [PATCH 4/4] libbpf: Search /lib64 and /lib in resolve_full_path() Ricardo B. Marlière
  3 siblings, 0 replies; 7+ messages in thread
From: Ricardo B. Marlière @ 2026-07-10 22:09 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Eduard Zingerman, Kumar Kartikeya Dwivedi, Martin KaFai Lau,
	Song Liu, Yonghong Song, Jiri Olsa, Emil Tsalapatis, Shuah Khan,
	Alexis Lothoré (eBPF Foundation), Ihor Solodrai,
	Christian Brauner
  Cc: bpf, linux-kselftest, linux-kernel, 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")
Signed-off-by: Ricardo B. Marlière <rbm@suse.com>
---
 tools/testing/selftests/bpf/Makefile | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
index 47911c9b4977..7260d672acf7 100644
--- a/tools/testing/selftests/bpf/Makefile
+++ b/tools/testing/selftests/bpf/Makefile
@@ -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

-- 
2.54.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 3/4] selftests/bpf: Fix lsm_bdev dev_t encoding mismatch
  2026-07-10 22:09 [PATCH 0/4] selftests/bpf: A few edge case fixes Ricardo B. Marlière
  2026-07-10 22:09 ` [PATCH 1/4] selftests/bpf: Install bpftool where test_progs expects to find it Ricardo B. Marlière
  2026-07-10 22:09 ` [PATCH 2/4] selftests/bpf: Install resolve_btfids.test.o.BTF where the test expects it Ricardo B. Marlière
@ 2026-07-10 22:09 ` Ricardo B. Marlière
  2026-07-10 22:09 ` [PATCH 4/4] libbpf: Search /lib64 and /lib in resolve_full_path() Ricardo B. Marlière
  3 siblings, 0 replies; 7+ messages in thread
From: Ricardo B. Marlière @ 2026-07-10 22:09 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Eduard Zingerman, Kumar Kartikeya Dwivedi, Martin KaFai Lau,
	Song Liu, Yonghong Song, Jiri Olsa, Emil Tsalapatis, Shuah Khan,
	Alexis Lothoré (eBPF Foundation), Ihor Solodrai,
	Christian Brauner
  Cc: bpf, linux-kselftest, linux-kernel, 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")
Signed-off-by: Ricardo B. Marlière <rbm@suse.com>
---
 tools/testing/selftests/bpf/prog_tests/lsm_bdev.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/bpf/prog_tests/lsm_bdev.c b/tools/testing/selftests/bpf/prog_tests/lsm_bdev.c
index a970798e1173..28bc4b117f41 100644
--- a/tools/testing/selftests/bpf/prog_tests/lsm_bdev.c
+++ b/tools/testing/selftests/bpf/prog_tests/lsm_bdev.c
@@ -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,

-- 
2.54.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 4/4] libbpf: Search /lib64 and /lib in resolve_full_path()
  2026-07-10 22:09 [PATCH 0/4] selftests/bpf: A few edge case fixes Ricardo B. Marlière
                   ` (2 preceding siblings ...)
  2026-07-10 22:09 ` [PATCH 3/4] selftests/bpf: Fix lsm_bdev dev_t encoding mismatch Ricardo B. Marlière
@ 2026-07-10 22:09 ` Ricardo B. Marlière
  2026-07-10 22:58   ` bot+bpf-ci
  3 siblings, 1 reply; 7+ messages in thread
From: Ricardo B. Marlière @ 2026-07-10 22:09 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Eduard Zingerman, Kumar Kartikeya Dwivedi, Martin KaFai Lau,
	Song Liu, Yonghong Song, Jiri Olsa, Emil Tsalapatis, Shuah Khan,
	Alexis Lothoré (eBPF Foundation), Ihor Solodrai,
	Christian Brauner
  Cc: bpf, linux-kselftest, linux-kernel, 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.

Signed-off-by: Ricardo B. Marlière <rbm@suse.com>
---
 tools/lib/bpf/libbpf.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 1368752aa13c..1ab939dfb7f0 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -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");

-- 
2.54.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 4/4] libbpf: Search /lib64 and /lib in resolve_full_path()
  2026-07-10 22:09 ` [PATCH 4/4] libbpf: Search /lib64 and /lib in resolve_full_path() Ricardo B. Marlière
@ 2026-07-10 22:58   ` bot+bpf-ci
  0 siblings, 0 replies; 7+ messages in thread
From: bot+bpf-ci @ 2026-07-10 22:58 UTC (permalink / raw)
  To: rbm, ast, daniel, andrii, eddyz87, memxor, martin.lau, song,
	yonghong.song, jolsa, emil, shuah, alexis.lothore, ihor.solodrai,
	brauner
  Cc: bpf, linux-kselftest, linux-kernel, rbm, ast, andrii, daniel,
	martin.lau, eddyz87, yonghong.song, clm, ihor.solodrai

[-- Attachment #1: Type: text/plain, Size: 1266 bytes --]

>     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.
>
>     Signed-off-by: Ricardo B. Marlière <rbm@suse.com>

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/4] selftests/bpf: Install bpftool where test_progs expects to find it
  2026-07-10 22:09 ` [PATCH 1/4] selftests/bpf: Install bpftool where test_progs expects to find it Ricardo B. Marlière
@ 2026-07-13 15:32   ` Alexis Lothoré
  0 siblings, 0 replies; 7+ messages in thread
From: Alexis Lothoré @ 2026-07-13 15:32 UTC (permalink / raw)
  To: Ricardo B. Marlière, Alexei Starovoitov, Daniel Borkmann,
	Andrii Nakryiko, Eduard Zingerman, Kumar Kartikeya Dwivedi,
	Martin KaFai Lau, Song Liu, Yonghong Song, Jiri Olsa,
	Emil Tsalapatis, Shuah Khan,
	Alexis Lothoré (eBPF Foundation), Ihor Solodrai,
	Christian Brauner
  Cc: bpf, linux-kselftest, linux-kernel

Hi,

On Sat Jul 11, 2026 at 12:09 AM CEST, Ricardo B. Marlière wrote:
> 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")
> Signed-off-by: Ricardo B. Marlière <rbm@suse.com>

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/20260223191118.655185-2-ihor.solodrai@linux.dev/

> ---
>  tools/testing/selftests/bpf/Makefile | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
> index b642ee489ea6..47911c9b4977 100644
> --- a/tools/testing/selftests/bpf/Makefile
> +++ b/tools/testing/selftests/bpf/Makefile
> @@ -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)	  \




-- 
Alexis Lothoré, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-07-13 15:33 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-10 22:09 [PATCH 0/4] selftests/bpf: A few edge case fixes Ricardo B. Marlière
2026-07-10 22:09 ` [PATCH 1/4] selftests/bpf: Install bpftool where test_progs expects to find it Ricardo B. Marlière
2026-07-13 15:32   ` Alexis Lothoré
2026-07-10 22:09 ` [PATCH 2/4] selftests/bpf: Install resolve_btfids.test.o.BTF where the test expects it Ricardo B. Marlière
2026-07-10 22:09 ` [PATCH 3/4] selftests/bpf: Fix lsm_bdev dev_t encoding mismatch Ricardo B. Marlière
2026-07-10 22:09 ` [PATCH 4/4] libbpf: Search /lib64 and /lib in resolve_full_path() Ricardo B. Marlière
2026-07-10 22:58   ` bot+bpf-ci

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.