mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-09-29 05:44:11 +00:00
selftests/bpf: Add bpf_get_func_ip test for uprobe inside function
Adding get_func_ip test for uprobe inside function that validates the get_func_ip helper returns correct probe address value. 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-4-jolsa@kernel.org Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
This commit is contained in:
parent
e43163ed1c
commit
7febf573a5
2 changed files with 60 additions and 4 deletions
|
@ -51,11 +51,17 @@ static void test_function_entry(void)
|
|||
get_func_ip_test__destroy(skel);
|
||||
}
|
||||
|
||||
/* test6 is x86_64 specific because of the instruction
|
||||
* offset, disabling it for all other archs
|
||||
*/
|
||||
#ifdef __x86_64__
|
||||
static void test_function_body(void)
|
||||
extern void uprobe_trigger_body(void);
|
||||
asm(
|
||||
".globl uprobe_trigger_body\n"
|
||||
".type uprobe_trigger_body, @function\n"
|
||||
"uprobe_trigger_body:\n"
|
||||
" nop\n"
|
||||
" ret\n"
|
||||
);
|
||||
|
||||
static void test_function_body_kprobe(void)
|
||||
{
|
||||
struct get_func_ip_test *skel = NULL;
|
||||
LIBBPF_OPTS(bpf_test_run_opts, topts);
|
||||
|
@ -67,6 +73,9 @@ static void test_function_body(void)
|
|||
if (!ASSERT_OK_PTR(skel, "get_func_ip_test__open"))
|
||||
return;
|
||||
|
||||
/* test6 is x86_64 specific and is disabled by default,
|
||||
* enable it for body test.
|
||||
*/
|
||||
bpf_program__set_autoload(skel->progs.test6, true);
|
||||
|
||||
err = get_func_ip_test__load(skel);
|
||||
|
@ -90,6 +99,35 @@ static void test_function_body(void)
|
|||
bpf_link__destroy(link6);
|
||||
get_func_ip_test__destroy(skel);
|
||||
}
|
||||
|
||||
static void test_function_body_uprobe(void)
|
||||
{
|
||||
struct get_func_ip_uprobe_test *skel = NULL;
|
||||
int err;
|
||||
|
||||
skel = get_func_ip_uprobe_test__open_and_load();
|
||||
if (!ASSERT_OK_PTR(skel, "get_func_ip_uprobe_test__open_and_load"))
|
||||
return;
|
||||
|
||||
err = get_func_ip_uprobe_test__attach(skel);
|
||||
if (!ASSERT_OK(err, "get_func_ip_test__attach"))
|
||||
goto cleanup;
|
||||
|
||||
skel->bss->uprobe_trigger_body = (unsigned long) uprobe_trigger_body;
|
||||
|
||||
uprobe_trigger_body();
|
||||
|
||||
ASSERT_EQ(skel->bss->test1_result, 1, "test1_result");
|
||||
|
||||
cleanup:
|
||||
get_func_ip_uprobe_test__destroy(skel);
|
||||
}
|
||||
|
||||
static void test_function_body(void)
|
||||
{
|
||||
test_function_body_kprobe();
|
||||
test_function_body_uprobe();
|
||||
}
|
||||
#else
|
||||
#define test_function_body()
|
||||
#endif
|
||||
|
|
18
tools/testing/selftests/bpf/progs/get_func_ip_uprobe_test.c
Normal file
18
tools/testing/selftests/bpf/progs/get_func_ip_uprobe_test.c
Normal file
|
@ -0,0 +1,18 @@
|
|||
// SPDX-License-Identifier: GPL-2.0
|
||||
#include "vmlinux.h"
|
||||
#include <bpf/bpf_helpers.h>
|
||||
#include <bpf/bpf_tracing.h>
|
||||
|
||||
char _license[] SEC("license") = "GPL";
|
||||
|
||||
unsigned long uprobe_trigger_body;
|
||||
|
||||
__u64 test1_result = 0;
|
||||
SEC("uprobe//proc/self/exe:uprobe_trigger_body+1")
|
||||
int BPF_UPROBE(test1)
|
||||
{
|
||||
__u64 addr = bpf_get_func_ip(ctx);
|
||||
|
||||
test1_result = (const void *) addr == (const void *) uprobe_trigger_body + 1;
|
||||
return 0;
|
||||
}
|
Loading…
Reference in a new issue