Re: [PATCHv2 bpf-next 4/6] selftests/bpf: Use bpf_link__destroy in fill_link_info tests

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Nov 9, 2023 at 5:29 PM Jiri Olsa <jolsa@xxxxxxxxxx> wrote:
>
> 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@xxxxxxxxxx>

I've just realized that we can use a local link for this particular scenario :)
Feel free to add:

Acked-by: Yafang Shao <laoar.shao@xxxxxxxxx>

> ---
>  .../selftests/bpf/prog_tests/fill_link_info.c | 44 ++++++++++---------
>  1 file changed, 23 insertions(+), 21 deletions(-)
>
> diff --git a/tools/testing/selftests/bpf/prog_tests/fill_link_info.c b/tools/testing/selftests/bpf/prog_tests/fill_link_info.c
> index 97142a4db374..9294cb8d7743 100644
> --- a/tools/testing/selftests/bpf/prog_tests/fill_link_info.c
> +++ b/tools/testing/selftests/bpf/prog_tests/fill_link_info.c
> @@ -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)
> @@ -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)
> @@ -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)
> --
> 2.41.0
>


-- 
Regards
Yafang





[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux