Re: [PATCH bpf-next v3 3/3] selftests/bpf: add test for legacy/perf kprobe/uprobe attach mode

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

 



On Tue, Feb 28, 2023 at 5:56 AM Andrii Nakryiko
<andrii.nakryiko@xxxxxxxxx> wrote:
>
> On Mon, Feb 20, 2023 at 6:54 PM <menglong8.dong@xxxxxxxxx> wrote:
> >
> > From: Menglong Dong <imagedong@xxxxxxxxxxx>
> >
> > Add the testing for kprobe/uprobe attaching in default, legacy, perf and
> > link mode. And the testing passed:
> >
> > ./test_progs -t attach_probe
> > $5/1     attach_probe/manual-default:OK
> > $5/2     attach_probe/manual-legacy:OK
> > $5/3     attach_probe/manual-perf:OK
> > $5/4     attach_probe/manual-link:OK
> > $5/5     attach_probe/auto:OK
> > $5/6     attach_probe/kprobe-sleepable:OK
> > $5/7     attach_probe/uprobe-lib:OK
> > $5/8     attach_probe/uprobe-sleepable:OK
> > $5/9     attach_probe/uprobe-ref_ctr:OK
> > $5       attach_probe:OK
> > Summary: 1/9 PASSED, 0 SKIPPED, 0 FAILED
> >
> > Reviewed-by: Biao Jiang <benbjiang@xxxxxxxxxxx>
> > Signed-off-by: Menglong Dong <imagedong@xxxxxxxxxxx>
> > Reviewed-by: Alan Maguire <alan.maguire@xxxxxxxxxx>
> > ---
> >  .../selftests/bpf/prog_tests/attach_probe.c   | 54 ++++++++++++++-----
> >  .../selftests/bpf/progs/test_attach_probe.c   | 32 -----------
> >  .../bpf/progs/test_attach_probe_manual.c      | 53 ++++++++++++++++++
> >  3 files changed, 93 insertions(+), 46 deletions(-)
> >  create mode 100644 tools/testing/selftests/bpf/progs/test_attach_probe_manual.c
> >
> > diff --git a/tools/testing/selftests/bpf/prog_tests/attach_probe.c b/tools/testing/selftests/bpf/prog_tests/attach_probe.c
> > index 8afd3e6066b8..e71cb44bf2e7 100644
> > --- a/tools/testing/selftests/bpf/prog_tests/attach_probe.c
> > +++ b/tools/testing/selftests/bpf/prog_tests/attach_probe.c
> > @@ -1,6 +1,7 @@
> >  // SPDX-License-Identifier: GPL-2.0
> >  #include <test_progs.h>
> >  #include "test_attach_kprobe_sleepable.skel.h"
> > +#include "test_attach_probe_manual.skel.h"
> >  #include "test_attach_probe.skel.h"
> >
> >  /* this is how USDT semaphore is actually defined, except volatile modifier */
> > @@ -33,33 +34,48 @@ static noinline void trigger_func4(void)
> >  static char test_data[] = "test_data";
> >
> >  /* manual attach kprobe/kretprobe/uprobe/uretprobe testings */
> > -static void test_attach_probe_manual(struct test_attach_probe *skel)
> > +static void test_attach_probe_manual(enum probe_attach_mode attach_mode)
> >  {
> >         DECLARE_LIBBPF_OPTS(bpf_uprobe_opts, uprobe_opts);
> > +       DECLARE_LIBBPF_OPTS(bpf_kprobe_opts, kprobe_opts);
> >         struct bpf_link *kprobe_link, *kretprobe_link;
> >         struct bpf_link *uprobe_link, *uretprobe_link;
> > +       struct test_attach_probe_manual *skel;
> >         ssize_t uprobe_offset;
> >
> > +       skel = test_attach_probe_manual__open();
> > +       if (!ASSERT_OK_PTR(skel, "skel_kprobe_manual_open"))
> > +               return;
> > +
> > +       if (!ASSERT_OK(test_attach_probe_manual__load(skel), "skel_manual_load"))
> > +               goto cleanup;
>
> use test_attach_probe_manual__open_and_load() ?
>

Yeah, sounds nice!

> > +       if (!ASSERT_OK_PTR(skel->bss, "manual_check_bss"))
> > +               goto cleanup;
> > +
>
> no need to test this, lots of other tests validate this already, BPF
> skeleton has been validated many times over, no need to add this in
> new tests
>
> >         uprobe_offset = get_uprobe_offset(&trigger_func);
> >         if (!ASSERT_GE(uprobe_offset, 0, "uprobe_offset"))
> > -               return;
> > +               goto cleanup;
>
> didn't you update all the `goto cleanup;` into `return;` in previous
> patch, and now updating it back to `goto cleanup;`? Maybe just keep an
> empty `cleanup:` label at the end to reduce churn?
>

OK!

Thanks!
Menglong Dong

> >
> >         /* manual-attach kprobe/kretprobe */
> > -       kprobe_link = bpf_program__attach_kprobe(skel->progs.handle_kprobe,
> > -                                                false /* retprobe */,
> > -                                                SYS_NANOSLEEP_KPROBE_NAME);
> > +       kprobe_opts.attach_mode = attach_mode;
> > +       kprobe_opts.retprobe = false;
> > +       kprobe_link = bpf_program__attach_kprobe_opts(skel->progs.handle_kprobe,
> > +                                                     SYS_NANOSLEEP_KPROBE_NAME,
> > +                                                     &kprobe_opts);
> >         if (!ASSERT_OK_PTR(kprobe_link, "attach_kprobe"))
> > -               return;
> > +               goto cleanup;
> >         skel->links.handle_kprobe = kprobe_link;
> >
> > -       kretprobe_link = bpf_program__attach_kprobe(skel->progs.handle_kretprobe,
> > -                                                   true /* retprobe */,
> > -                                                   SYS_NANOSLEEP_KPROBE_NAME);
> > +       kprobe_opts.retprobe = true;
> > +       kretprobe_link = bpf_program__attach_kprobe_opts(skel->progs.handle_kretprobe,
> > +                                                        SYS_NANOSLEEP_KPROBE_NAME,
> > +                                                        &kprobe_opts);
> >         if (!ASSERT_OK_PTR(kretprobe_link, "attach_kretprobe"))
> > -               return;
> > +               goto cleanup;
> >         skel->links.handle_kretprobe = kretprobe_link;
> >
> >         /* manual-attach uprobe/uretprobe */
> > +       uprobe_opts.attach_mode = attach_mode;
> >         uprobe_opts.ref_ctr_offset = 0;
> >         uprobe_opts.retprobe = false;
> >         uprobe_link = bpf_program__attach_uprobe_opts(skel->progs.handle_uprobe,
>
> [...]




[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