Skip to content

Commit

Permalink
selftests/bpf: Use bpf_link__destroy in fill_link_info tests
Browse files Browse the repository at this point in the history
The fill_link_info test keeps skeleton open and just creates
various links. We are wrongly calling bpf_link__detach after
each test to close them, we need to call bpf_link__destroy.

Acked-by: Yafang Shao <laoar.shao@gmail.com>
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
  • Loading branch information
olsajiri authored and Kernel Patches Daemon committed Nov 20, 2023
1 parent 44efe44 commit ff19b32
Showing 1 changed file with 23 additions and 21 deletions.
44 changes: 23 additions & 21 deletions tools/testing/selftests/bpf/prog_tests/fill_link_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,14 @@ static void test_kprobe_fill_link_info(struct test_fill_link_info *skel,
.retprobe = type == BPF_PERF_EVENT_KRETPROBE,
);
ssize_t entry_offset = 0;
struct bpf_link *link;
int link_fd, err;

skel->links.kprobe_run = bpf_program__attach_kprobe_opts(skel->progs.kprobe_run,
KPROBE_FUNC, &opts);
if (!ASSERT_OK_PTR(skel->links.kprobe_run, "attach_kprobe"))
link = bpf_program__attach_kprobe_opts(skel->progs.kprobe_run, KPROBE_FUNC, &opts);
if (!ASSERT_OK_PTR(link, "attach_kprobe"))
return;

link_fd = bpf_link__fd(skel->links.kprobe_run);
link_fd = bpf_link__fd(link);
if (!invalid) {
/* See also arch_adjust_kprobe_addr(). */
if (skel->kconfig->CONFIG_X86_KERNEL_IBT)
Expand All @@ -157,39 +157,41 @@ static void test_kprobe_fill_link_info(struct test_fill_link_info *skel,
} else {
kprobe_fill_invalid_user_buffer(link_fd);
}
bpf_link__detach(skel->links.kprobe_run);
bpf_link__destroy(link);
}

static void test_tp_fill_link_info(struct test_fill_link_info *skel)
{
struct bpf_link *link;
int link_fd, err;

skel->links.tp_run = bpf_program__attach_tracepoint(skel->progs.tp_run, TP_CAT, TP_NAME);
if (!ASSERT_OK_PTR(skel->links.tp_run, "attach_tp"))
link = bpf_program__attach_tracepoint(skel->progs.tp_run, TP_CAT, TP_NAME);
if (!ASSERT_OK_PTR(link, "attach_tp"))
return;

link_fd = bpf_link__fd(skel->links.tp_run);
link_fd = bpf_link__fd(link);
err = verify_perf_link_info(link_fd, BPF_PERF_EVENT_TRACEPOINT, 0, 0, 0);
ASSERT_OK(err, "verify_perf_link_info");
bpf_link__detach(skel->links.tp_run);
bpf_link__destroy(link);
}

static void test_uprobe_fill_link_info(struct test_fill_link_info *skel,
enum bpf_perf_event_type type)
{
struct bpf_link *link;
int link_fd, err;

skel->links.uprobe_run = bpf_program__attach_uprobe(skel->progs.uprobe_run,
type == BPF_PERF_EVENT_URETPROBE,
0, /* self pid */
UPROBE_FILE, uprobe_offset);
if (!ASSERT_OK_PTR(skel->links.uprobe_run, "attach_uprobe"))
link = bpf_program__attach_uprobe(skel->progs.uprobe_run,
type == BPF_PERF_EVENT_URETPROBE,
0, /* self pid */
UPROBE_FILE, uprobe_offset);
if (!ASSERT_OK_PTR(link, "attach_uprobe"))
return;

link_fd = bpf_link__fd(skel->links.uprobe_run);
link_fd = bpf_link__fd(link);
err = verify_perf_link_info(link_fd, type, 0, uprobe_offset, 0);
ASSERT_OK(err, "verify_perf_link_info");
bpf_link__detach(skel->links.uprobe_run);
bpf_link__destroy(link);
}

static int verify_kmulti_link_info(int fd, bool retprobe)
Expand Down Expand Up @@ -278,24 +280,24 @@ static void test_kprobe_multi_fill_link_info(struct test_fill_link_info *skel,
bool retprobe, bool invalid)
{
LIBBPF_OPTS(bpf_kprobe_multi_opts, opts);
struct bpf_link *link;
int link_fd, err;

opts.syms = kmulti_syms;
opts.cnt = KMULTI_CNT;
opts.retprobe = retprobe;
skel->links.kmulti_run = bpf_program__attach_kprobe_multi_opts(skel->progs.kmulti_run,
NULL, &opts);
if (!ASSERT_OK_PTR(skel->links.kmulti_run, "attach_kprobe_multi"))
link = bpf_program__attach_kprobe_multi_opts(skel->progs.kmulti_run, NULL, &opts);
if (!ASSERT_OK_PTR(link, "attach_kprobe_multi"))
return;

link_fd = bpf_link__fd(skel->links.kmulti_run);
link_fd = bpf_link__fd(link);
if (!invalid) {
err = verify_kmulti_link_info(link_fd, retprobe);
ASSERT_OK(err, "verify_kmulti_link_info");
} else {
verify_kmulti_invalid_user_buffer(link_fd);
}
bpf_link__detach(skel->links.kmulti_run);
bpf_link__destroy(link);
}

void test_fill_link_info(void)
Expand Down

0 comments on commit ff19b32

Please sign in to comment.