mirror of
https://github.com/nxp-imx/linux-imx.git
synced 2025-07-18 15:19:38 +02:00
selftests/bpf: Add cookies check for perf_event fill_link_info test
[ Upstream commitd741797084
] Now that we get cookies for perf_event probes, adding tests for cookie for kprobe/uprobe/tracepoint. The perf_event test needs to be added completely and is coming in following change. Signed-off-by: Jiri Olsa <jolsa@kernel.org> Acked-by: Song Liu <song@kernel.org> Link: https://lore.kernel.org/r/20240119110505.400573-6-jolsa@kernel.org Signed-off-by: Alexei Starovoitov <ast@kernel.org> Stable-dep-of:4538a38f65
("selftests/bpf: fix perf_event link info name_len assertion") Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
parent
e909258d41
commit
0ce2018197
|
@ -30,6 +30,8 @@ static noinline void uprobe_func(void)
|
||||||
asm volatile ("");
|
asm volatile ("");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define PERF_EVENT_COOKIE 0xdeadbeef
|
||||||
|
|
||||||
static int verify_perf_link_info(int fd, enum bpf_perf_event_type type, long addr,
|
static int verify_perf_link_info(int fd, enum bpf_perf_event_type type, long addr,
|
||||||
ssize_t offset, ssize_t entry_offset)
|
ssize_t offset, ssize_t entry_offset)
|
||||||
{
|
{
|
||||||
|
@ -61,6 +63,8 @@ again:
|
||||||
ASSERT_EQ(info.perf_event.kprobe.addr, addr + entry_offset,
|
ASSERT_EQ(info.perf_event.kprobe.addr, addr + entry_offset,
|
||||||
"kprobe_addr");
|
"kprobe_addr");
|
||||||
|
|
||||||
|
ASSERT_EQ(info.perf_event.kprobe.cookie, PERF_EVENT_COOKIE, "kprobe_cookie");
|
||||||
|
|
||||||
if (!info.perf_event.kprobe.func_name) {
|
if (!info.perf_event.kprobe.func_name) {
|
||||||
ASSERT_EQ(info.perf_event.kprobe.name_len, 0, "name_len");
|
ASSERT_EQ(info.perf_event.kprobe.name_len, 0, "name_len");
|
||||||
info.perf_event.kprobe.func_name = ptr_to_u64(&buf);
|
info.perf_event.kprobe.func_name = ptr_to_u64(&buf);
|
||||||
|
@ -80,6 +84,8 @@ again:
|
||||||
goto again;
|
goto again;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ASSERT_EQ(info.perf_event.tracepoint.cookie, PERF_EVENT_COOKIE, "tracepoint_cookie");
|
||||||
|
|
||||||
err = strncmp(u64_to_ptr(info.perf_event.tracepoint.tp_name), TP_NAME,
|
err = strncmp(u64_to_ptr(info.perf_event.tracepoint.tp_name), TP_NAME,
|
||||||
strlen(TP_NAME));
|
strlen(TP_NAME));
|
||||||
ASSERT_EQ(err, 0, "cmp_tp_name");
|
ASSERT_EQ(err, 0, "cmp_tp_name");
|
||||||
|
@ -95,6 +101,8 @@ again:
|
||||||
goto again;
|
goto again;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ASSERT_EQ(info.perf_event.uprobe.cookie, PERF_EVENT_COOKIE, "uprobe_cookie");
|
||||||
|
|
||||||
err = strncmp(u64_to_ptr(info.perf_event.uprobe.file_name), UPROBE_FILE,
|
err = strncmp(u64_to_ptr(info.perf_event.uprobe.file_name), UPROBE_FILE,
|
||||||
strlen(UPROBE_FILE));
|
strlen(UPROBE_FILE));
|
||||||
ASSERT_EQ(err, 0, "cmp_file_name");
|
ASSERT_EQ(err, 0, "cmp_file_name");
|
||||||
|
@ -138,6 +146,7 @@ static void test_kprobe_fill_link_info(struct test_fill_link_info *skel,
|
||||||
DECLARE_LIBBPF_OPTS(bpf_kprobe_opts, opts,
|
DECLARE_LIBBPF_OPTS(bpf_kprobe_opts, opts,
|
||||||
.attach_mode = PROBE_ATTACH_MODE_LINK,
|
.attach_mode = PROBE_ATTACH_MODE_LINK,
|
||||||
.retprobe = type == BPF_PERF_EVENT_KRETPROBE,
|
.retprobe = type == BPF_PERF_EVENT_KRETPROBE,
|
||||||
|
.bpf_cookie = PERF_EVENT_COOKIE,
|
||||||
);
|
);
|
||||||
ssize_t entry_offset = 0;
|
ssize_t entry_offset = 0;
|
||||||
struct bpf_link *link;
|
struct bpf_link *link;
|
||||||
|
@ -162,10 +171,13 @@ static void test_kprobe_fill_link_info(struct test_fill_link_info *skel,
|
||||||
|
|
||||||
static void test_tp_fill_link_info(struct test_fill_link_info *skel)
|
static void test_tp_fill_link_info(struct test_fill_link_info *skel)
|
||||||
{
|
{
|
||||||
|
DECLARE_LIBBPF_OPTS(bpf_tracepoint_opts, opts,
|
||||||
|
.bpf_cookie = PERF_EVENT_COOKIE,
|
||||||
|
);
|
||||||
struct bpf_link *link;
|
struct bpf_link *link;
|
||||||
int link_fd, err;
|
int link_fd, err;
|
||||||
|
|
||||||
link = bpf_program__attach_tracepoint(skel->progs.tp_run, TP_CAT, TP_NAME);
|
link = bpf_program__attach_tracepoint_opts(skel->progs.tp_run, TP_CAT, TP_NAME, &opts);
|
||||||
if (!ASSERT_OK_PTR(link, "attach_tp"))
|
if (!ASSERT_OK_PTR(link, "attach_tp"))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -178,13 +190,17 @@ static void test_tp_fill_link_info(struct test_fill_link_info *skel)
|
||||||
static void test_uprobe_fill_link_info(struct test_fill_link_info *skel,
|
static void test_uprobe_fill_link_info(struct test_fill_link_info *skel,
|
||||||
enum bpf_perf_event_type type)
|
enum bpf_perf_event_type type)
|
||||||
{
|
{
|
||||||
|
DECLARE_LIBBPF_OPTS(bpf_uprobe_opts, opts,
|
||||||
|
.retprobe = type == BPF_PERF_EVENT_URETPROBE,
|
||||||
|
.bpf_cookie = PERF_EVENT_COOKIE,
|
||||||
|
);
|
||||||
struct bpf_link *link;
|
struct bpf_link *link;
|
||||||
int link_fd, err;
|
int link_fd, err;
|
||||||
|
|
||||||
link = bpf_program__attach_uprobe(skel->progs.uprobe_run,
|
link = bpf_program__attach_uprobe_opts(skel->progs.uprobe_run,
|
||||||
type == BPF_PERF_EVENT_URETPROBE,
|
|
||||||
0, /* self pid */
|
0, /* self pid */
|
||||||
UPROBE_FILE, uprobe_offset);
|
UPROBE_FILE, uprobe_offset,
|
||||||
|
&opts);
|
||||||
if (!ASSERT_OK_PTR(link, "attach_uprobe"))
|
if (!ASSERT_OK_PTR(link, "attach_uprobe"))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user