selftests/bpf: Add bpf_get_func_ip tests for uprobe on function entry
authorJiri Olsa <jolsa@kernel.org>
Mon, 7 Aug 2023 08:59:55 +0000 (10:59 +0200)
committerMartin KaFai Lau <martin.lau@kernel.org>
Mon, 7 Aug 2023 23:42:58 +0000 (16:42 -0700)
Adding get_func_ip tests for uprobe on function entry that
validates that bpf_get_func_ip returns proper values from
both uprobe and return uprobe.

Tested-by: Alan Maguire <alan.maguire@oracle.com>
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Acked-by: Yonghong Song <yonghong.song@linux.dev>
Link: https://lore.kernel.org/r/20230807085956.2344866-3-jolsa@kernel.org
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
tools/testing/selftests/bpf/prog_tests/get_func_ip_test.c
tools/testing/selftests/bpf/progs/get_func_ip_test.c

index fede8ef..114cdbc 100644 (file)
@@ -1,6 +1,11 @@
 // SPDX-License-Identifier: GPL-2.0
 #include <test_progs.h>
 #include "get_func_ip_test.skel.h"
+#include "get_func_ip_uprobe_test.skel.h"
+
+static noinline void uprobe_trigger(void)
+{
+}
 
 static void test_function_entry(void)
 {
@@ -20,6 +25,8 @@ static void test_function_entry(void)
        if (!ASSERT_OK(err, "get_func_ip_test__attach"))
                goto cleanup;
 
+       skel->bss->uprobe_trigger = (unsigned long) uprobe_trigger;
+
        prog_fd = bpf_program__fd(skel->progs.test1);
        err = bpf_prog_test_run_opts(prog_fd, &topts);
        ASSERT_OK(err, "test_run");
@@ -30,11 +37,15 @@ static void test_function_entry(void)
 
        ASSERT_OK(err, "test_run");
 
+       uprobe_trigger();
+
        ASSERT_EQ(skel->bss->test1_result, 1, "test1_result");
        ASSERT_EQ(skel->bss->test2_result, 1, "test2_result");
        ASSERT_EQ(skel->bss->test3_result, 1, "test3_result");
        ASSERT_EQ(skel->bss->test4_result, 1, "test4_result");
        ASSERT_EQ(skel->bss->test5_result, 1, "test5_result");
+       ASSERT_EQ(skel->bss->test7_result, 1, "test7_result");
+       ASSERT_EQ(skel->bss->test8_result, 1, "test8_result");
 
 cleanup:
        get_func_ip_test__destroy(skel);
index 8559e69..8956eb7 100644 (file)
@@ -1,8 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0
-#include <linux/bpf.h>
+#include "vmlinux.h"
 #include <bpf/bpf_helpers.h>
 #include <bpf/bpf_tracing.h>
-#include <stdbool.h>
 
 char _license[] SEC("license") = "GPL";
 
@@ -83,3 +82,25 @@ int test6(struct pt_regs *ctx)
        test6_result = (const void *) addr == 0;
        return 0;
 }
+
+unsigned long uprobe_trigger;
+
+__u64 test7_result = 0;
+SEC("uprobe//proc/self/exe:uprobe_trigger")
+int BPF_UPROBE(test7)
+{
+       __u64 addr = bpf_get_func_ip(ctx);
+
+       test7_result = (const void *) addr == (const void *) uprobe_trigger;
+       return 0;
+}
+
+__u64 test8_result = 0;
+SEC("uretprobe//proc/self/exe:uprobe_trigger")
+int BPF_URETPROBE(test8, int ret)
+{
+       __u64 addr = bpf_get_func_ip(ctx);
+
+       test8_result = (const void *) addr == (const void *) uprobe_trigger;
+       return 0;
+}