selftests/bpf: Use bpf_link__destroy in fill_link_info tests

[ Upstream commit 1703612885723869064f18e8816c6f3f87987748 ]

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.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Acked-by: Yonghong Song <yonghong.song@linux.dev>
Acked-by: Yafang Shao <laoar.shao@gmail.com>
Link: https://lore.kernel.org/bpf/20231125193130.834322-5-jolsa@kernel.org
Stable-dep-of: 4538a38f654a ("selftests/bpf: fix perf_event link info name_len assertion")
Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
Jiri Olsa 2023-11-25 20:31:28 +01:00 committed by Greg Kroah-Hartman
parent e5c2b971db
commit e909258d41
1 changed files with 23 additions and 21 deletions

View File

@ -140,14 +140,14 @@ static void test_kprobe_fill_link_info(struct test_fill_link_info *skel,
.retprobe = type == BPF_PERF_EVENT_KRETPROBE, .retprobe = type == BPF_PERF_EVENT_KRETPROBE,
); );
ssize_t entry_offset = 0; ssize_t entry_offset = 0;
struct bpf_link *link;
int link_fd, err; int link_fd, err;
skel->links.kprobe_run = bpf_program__attach_kprobe_opts(skel->progs.kprobe_run, link = bpf_program__attach_kprobe_opts(skel->progs.kprobe_run, KPROBE_FUNC, &opts);
KPROBE_FUNC, &opts); if (!ASSERT_OK_PTR(link, "attach_kprobe"))
if (!ASSERT_OK_PTR(skel->links.kprobe_run, "attach_kprobe"))
return; return;
link_fd = bpf_link__fd(skel->links.kprobe_run); link_fd = bpf_link__fd(link);
if (!invalid) { if (!invalid) {
/* See also arch_adjust_kprobe_addr(). */ /* See also arch_adjust_kprobe_addr(). */
if (skel->kconfig->CONFIG_X86_KERNEL_IBT) if (skel->kconfig->CONFIG_X86_KERNEL_IBT)
@ -157,39 +157,41 @@ static void test_kprobe_fill_link_info(struct test_fill_link_info *skel,
} else { } else {
kprobe_fill_invalid_user_buffer(link_fd); 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) static void test_tp_fill_link_info(struct test_fill_link_info *skel)
{ {
struct bpf_link *link;
int link_fd, err; int link_fd, err;
skel->links.tp_run = bpf_program__attach_tracepoint(skel->progs.tp_run, TP_CAT, TP_NAME); link = bpf_program__attach_tracepoint(skel->progs.tp_run, TP_CAT, TP_NAME);
if (!ASSERT_OK_PTR(skel->links.tp_run, "attach_tp")) if (!ASSERT_OK_PTR(link, "attach_tp"))
return; 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); err = verify_perf_link_info(link_fd, BPF_PERF_EVENT_TRACEPOINT, 0, 0, 0);
ASSERT_OK(err, "verify_perf_link_info"); 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, 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)
{ {
struct bpf_link *link;
int link_fd, err; int link_fd, err;
skel->links.uprobe_run = bpf_program__attach_uprobe(skel->progs.uprobe_run, link = bpf_program__attach_uprobe(skel->progs.uprobe_run,
type == BPF_PERF_EVENT_URETPROBE, type == BPF_PERF_EVENT_URETPROBE,
0, /* self pid */ 0, /* self pid */
UPROBE_FILE, uprobe_offset); UPROBE_FILE, uprobe_offset);
if (!ASSERT_OK_PTR(skel->links.uprobe_run, "attach_uprobe")) if (!ASSERT_OK_PTR(link, "attach_uprobe"))
return; 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); err = verify_perf_link_info(link_fd, type, 0, uprobe_offset, 0);
ASSERT_OK(err, "verify_perf_link_info"); 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) static int verify_kmulti_link_info(int fd, bool retprobe)
@ -278,24 +280,24 @@ static void test_kprobe_multi_fill_link_info(struct test_fill_link_info *skel,
bool retprobe, bool invalid) bool retprobe, bool invalid)
{ {
LIBBPF_OPTS(bpf_kprobe_multi_opts, opts); LIBBPF_OPTS(bpf_kprobe_multi_opts, opts);
struct bpf_link *link;
int link_fd, err; int link_fd, err;
opts.syms = kmulti_syms; opts.syms = kmulti_syms;
opts.cnt = KMULTI_CNT; opts.cnt = KMULTI_CNT;
opts.retprobe = retprobe; opts.retprobe = retprobe;
skel->links.kmulti_run = bpf_program__attach_kprobe_multi_opts(skel->progs.kmulti_run, link = bpf_program__attach_kprobe_multi_opts(skel->progs.kmulti_run, NULL, &opts);
NULL, &opts); if (!ASSERT_OK_PTR(link, "attach_kprobe_multi"))
if (!ASSERT_OK_PTR(skel->links.kmulti_run, "attach_kprobe_multi"))
return; return;
link_fd = bpf_link__fd(skel->links.kmulti_run); link_fd = bpf_link__fd(link);
if (!invalid) { if (!invalid) {
err = verify_kmulti_link_info(link_fd, retprobe); err = verify_kmulti_link_info(link_fd, retprobe);
ASSERT_OK(err, "verify_kmulti_link_info"); ASSERT_OK(err, "verify_kmulti_link_info");
} else { } else {
verify_kmulti_invalid_user_buffer(link_fd); verify_kmulti_invalid_user_buffer(link_fd);
} }
bpf_link__detach(skel->links.kmulti_run); bpf_link__destroy(link);
} }
void test_fill_link_info(void) void test_fill_link_info(void)