Thread (27 messages) 27 messages, 7 authors, 2024-05-07

Re: [PATCHv4 bpf-next 6/7] selftests/bpf: Add uretprobe compat test

From: Andrii Nakryiko <hidden>
Date: 2024-05-02 16:35:24
Also in: linux-api, linux-man, linux-trace-kernel, lkml

On Thu, May 2, 2024 at 5:24 AM Jiri Olsa [off-list ref] wrote:
quoted hunk ↗ jump to hunk
Adding test that adds return uprobe inside 32-bit task
and verify the return uprobe and attached bpf programs
get properly executed.

Reviewed-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/testing/selftests/bpf/.gitignore        |  1 +
 tools/testing/selftests/bpf/Makefile          |  7 ++-
 .../selftests/bpf/prog_tests/uprobe_syscall.c | 60 +++++++++++++++++++
 3 files changed, 67 insertions(+), 1 deletion(-)
diff --git a/tools/testing/selftests/bpf/.gitignore b/tools/testing/selftests/bpf/.gitignore
index f1aebabfb017..69d71223c0dd 100644
--- a/tools/testing/selftests/bpf/.gitignore
+++ b/tools/testing/selftests/bpf/.gitignore
@@ -45,6 +45,7 @@ test_cpp
 /veristat
 /sign-file
 /uprobe_multi
+/uprobe_compat
 *.ko
 *.tmp
 xskxceiver
diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
index 82247aeef857..a94352162290 100644
--- a/tools/testing/selftests/bpf/Makefile
+++ b/tools/testing/selftests/bpf/Makefile
@@ -133,7 +133,7 @@ TEST_GEN_PROGS_EXTENDED = test_sock_addr test_skb_cgroup_id_user \
        xskxceiver xdp_redirect_multi xdp_synproxy veristat xdp_hw_metadata \
        xdp_features bpf_test_no_cfi.ko

-TEST_GEN_FILES += liburandom_read.so urandom_read sign-file uprobe_multi
+TEST_GEN_FILES += liburandom_read.so urandom_read sign-file uprobe_multi uprobe_compat

 ifneq ($(V),1)
 submake_extras := feature_display=0
@@ -631,6 +631,7 @@ TRUNNER_EXTRA_FILES := $(OUTPUT)/urandom_read $(OUTPUT)/bpf_testmod.ko      \
                       $(OUTPUT)/xdp_synproxy                           \
                       $(OUTPUT)/sign-file                              \
                       $(OUTPUT)/uprobe_multi                           \
+                      $(OUTPUT)/uprobe_compat                          \
                       ima_setup.sh                                     \
                       verify_sig_setup.sh                              \
                       $(wildcard progs/btf_dump_test_case_*.c)         \
@@ -752,6 +753,10 @@ $(OUTPUT)/uprobe_multi: uprobe_multi.c
        $(call msg,BINARY,,$@)
        $(Q)$(CC) $(CFLAGS) -O0 $(LDFLAGS) $^ $(LDLIBS) -o $@

+$(OUTPUT)/uprobe_compat:
+       $(call msg,BINARY,,$@)
+       $(Q)echo "int main() { return 0; }" | $(CC) $(CFLAGS) -xc -m32 -O0 - -o $@
+
 EXTRA_CLEAN := $(SCRATCH_DIR) $(HOST_SCRATCH_DIR)                      \
        prog_tests/tests.h map_tests/tests.h verifier/tests.h           \
        feature bpftool                                                 \
diff --git a/tools/testing/selftests/bpf/prog_tests/uprobe_syscall.c b/tools/testing/selftests/bpf/prog_tests/uprobe_syscall.c
index c6fdb8c59ea3..bfea9a0368a4 100644
--- a/tools/testing/selftests/bpf/prog_tests/uprobe_syscall.c
+++ b/tools/testing/selftests/bpf/prog_tests/uprobe_syscall.c
@@ -5,6 +5,7 @@
 #ifdef __x86_64__

 #include <unistd.h>
+#include <stdlib.h>
 #include <asm/ptrace.h>
 #include <linux/compiler.h>
 #include <linux/stringify.h>
@@ -297,6 +298,58 @@ static void test_uretprobe_syscall_call(void)
        close(go[1]);
        close(go[0]);
 }
+
+static void test_uretprobe_compat(void)
+{
+       LIBBPF_OPTS(bpf_uprobe_multi_opts, opts,
+               .retprobe = true,
+       );
+       struct uprobe_syscall_executed *skel;
+       int err, go[2], pid, c, status;
+
+       if (pipe(go))
+               return;
ASSERT_OK() missing, like in the previous patch

Thanks for switching to pipe() + global variable instead of using trace_pipe.

Acked-by: Andrii Nakryiko <andrii@kernel.org>
+
+       skel = uprobe_syscall_executed__open_and_load();
+       if (!ASSERT_OK_PTR(skel, "uprobe_syscall_executed__open_and_load"))
+               goto cleanup;
+
[...]
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help