bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrii Nakryiko <andrii.nakryiko@gmail.com>
To: Kenny Yu <kennyyu@fb.com>
Cc: Alexei Starovoitov <alexei.starovoitov@gmail.com>,
	Andrii Nakryiko <andrii@kernel.org>,
	Alexei Starovoitov <ast@kernel.org>, bpf <bpf@vger.kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Gabriele <phoenix1987@gmail.com>, Yonghong Song <yhs@fb.com>
Subject: Re: [PATCH v5 bpf-next 3/3] selftests/bpf: Add test for sleepable bpf iterator programs
Date: Thu, 20 Jan 2022 14:48:03 -0800	[thread overview]
Message-ID: <CAEf4BzYD-f0g8_zo-wet1Rdz=hKEaOa0NZ=_GjRFntPw2FnbRA@mail.gmail.com> (raw)
In-Reply-To: <20220120172942.246805-4-kennyyu@fb.com>

On Thu, Jan 20, 2022 at 9:30 AM Kenny Yu <kennyyu@fb.com> wrote:
>
> This adds a test for bpf iterator programs to make use of sleepable
> bpf helpers.
>
> Signed-off-by: Kenny Yu <kennyyu@fb.com>
> ---
>  .../selftests/bpf/prog_tests/bpf_iter.c       | 19 ++++++++
>  .../selftests/bpf/progs/bpf_iter_task.c       | 47 +++++++++++++++++++
>  2 files changed, 66 insertions(+)
>
> diff --git a/tools/testing/selftests/bpf/prog_tests/bpf_iter.c b/tools/testing/selftests/bpf/prog_tests/bpf_iter.c
> index b84f859b1267..f6fb4f95513d 100644
> --- a/tools/testing/selftests/bpf/prog_tests/bpf_iter.c
> +++ b/tools/testing/selftests/bpf/prog_tests/bpf_iter.c
> @@ -138,6 +138,23 @@ static void test_task(void)
>         bpf_iter_task__destroy(skel);
>  }
>
> +static void test_task_sleepable(void)
> +{
> +       struct bpf_iter_task *skel;
> +
> +       skel = bpf_iter_task__open_and_load();
> +       if (CHECK(!skel, "bpf_iter_task__open_and_load",
> +                 "skeleton open_and_load failed\n"))

Please use ASSERT_OK_PTR() instead.

> +               return;
> +
> +       do_dummy_read(skel->progs.dump_task_sleepable);
> +
> +       ASSERT_GT(skel->bss->num_success_access_process_vm, 0,
> +                 "num_success_access_process_vm");
> +
> +       bpf_iter_task__destroy(skel);
> +}
> +
>  static void test_task_stack(void)
>  {
>         struct bpf_iter_task_stack *skel;
> @@ -1252,6 +1269,8 @@ void test_bpf_iter(void)
>                 test_bpf_map();
>         if (test__start_subtest("task"))
>                 test_task();
> +       if (test__start_subtest("task_sleepable"))
> +               test_task_sleepable();
>         if (test__start_subtest("task_stack"))
>                 test_task_stack();
>         if (test__start_subtest("task_file"))
> diff --git a/tools/testing/selftests/bpf/progs/bpf_iter_task.c b/tools/testing/selftests/bpf/progs/bpf_iter_task.c
> index c86b93f33b32..3fa735af96f7 100644
> --- a/tools/testing/selftests/bpf/progs/bpf_iter_task.c
> +++ b/tools/testing/selftests/bpf/progs/bpf_iter_task.c
> @@ -2,6 +2,7 @@
>  /* Copyright (c) 2020 Facebook */
>  #include "bpf_iter.h"
>  #include <bpf/bpf_helpers.h>
> +#include <bpf/bpf_tracing.h>
>
>  char _license[] SEC("license") = "GPL";
>
> @@ -23,3 +24,49 @@ int dump_task(struct bpf_iter__task *ctx)
>         BPF_SEQ_PRINTF(seq, "%8d %8d\n", task->tgid, task->pid);
>         return 0;
>  }
> +
> +int num_success_access_process_vm = 0;
> +
> +SEC("iter.s/task")
> +int dump_task_sleepable(struct bpf_iter__task *ctx)
> +{
> +       struct seq_file *seq = ctx->meta->seq;
> +       struct task_struct *task = ctx->task;
> +       static const char info[] = "    === END ===";
> +       struct pt_regs *regs;
> +       void *ptr;
> +       uint32_t user_data = 0;
> +       int numread;
> +
> +       if (task == (void *)0) {
> +               BPF_SEQ_PRINTF(seq, "%s\n", info);
> +               return 0;
> +       }
> +
> +       regs = (struct pt_regs *)bpf_task_pt_regs(task);
> +       if (regs == (void *)0) {
> +               BPF_SEQ_PRINTF(seq, "%s\n", info);
> +               return 0;
> +       }
> +       ptr = (void *)PT_REGS_IP(regs);
> +
> +       /* Try to read the contents of the task's instruction pointer from the
> +        * remote task's address space.
> +        */
> +       numread = bpf_access_process_vm(&user_data,
> +                                       sizeof(uint32_t),
> +                                       ptr,
> +                                       task,
> +                                       0);

nit: keep it on one line (up to 100 characters is ok)


> +       if (numread != sizeof(uint32_t)) {
> +               BPF_SEQ_PRINTF(seq, "%s\n", info);
> +               return 0;
> +       }
> +       ++num_success_access_process_vm;
> +
> +       if (ctx->meta->seq_num == 0)
> +               BPF_SEQ_PRINTF(seq, "    tgid      gid     data\n");
> +
> +       BPF_SEQ_PRINTF(seq, "%8d %8d %8d\n", task->tgid, task->pid, user_data);
> +       return 0;
> +}
> --
> 2.30.2
>

  reply	other threads:[~2022-01-20 22:48 UTC|newest]

Thread overview: 62+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-13 23:31 [PATCH bpf-next 0/3] Add bpf_access_process_vm helper and sleepable bpf iterator programs Kenny Yu
2022-01-13 23:31 ` [PATCH bpf-next 1/3] bpf: Add bpf_access_process_vm() helper Kenny Yu
2022-01-13 23:31 ` [PATCH bpf-next 2/3] libbpf: Add "iter.s" section for sleepable bpf iterator programs Kenny Yu
2022-01-13 23:31 ` [PATCH bpf-next 3/3] selftests/bpf: Add test " Kenny Yu
2022-01-14  0:48 ` [PATCH v2 bpf-next 0/4] Add bpf_access_process_vm helper and " Kenny Yu
2022-01-14  0:48   ` [PATCH v2 bpf-next 1/4] bpf: Add bpf_access_process_vm() helper Kenny Yu
2022-01-14  0:48   ` [PATCH v2 bpf-next 2/4] bpf: Add support for sleepable programs in bpf_iter_run_prog Kenny Yu
2022-01-14  2:50     ` Alexei Starovoitov
2022-01-14 23:15       ` Kenny Yu
2022-01-14  0:48   ` [PATCH v2 bpf-next 3/4] libbpf: Add "iter.s" section for sleepable bpf iterator programs Kenny Yu
2022-01-14  0:49   ` [PATCH v2 bpf-next 4/4] selftests/bpf: Add test " Kenny Yu
2022-01-14  2:39     ` Alexei Starovoitov
2022-01-14 23:14       ` Kenny Yu
2022-01-15  1:38         ` Andrii Nakryiko
2022-01-15  4:30           ` Kenny Yu
2022-01-15 16:27           ` Gabriele
2022-01-19 16:56             ` Kenny Yu
2022-01-19 18:02 ` [PATCH v3 bpf-next 0/3] Add bpf_access_process_vm helper and " Kenny Yu
2022-01-19 18:02   ` [PATCH v3 bpf-next 1/3] bpf: Add bpf_access_process_vm() helper Kenny Yu
2022-01-19 20:16     ` Alexei Starovoitov
2022-01-19 22:51       ` Kenny Yu
2022-01-19 18:02   ` [PATCH v3 bpf-next 2/3] libbpf: Add "iter.s" section for sleepable bpf iterator programs Kenny Yu
2022-01-19 18:02   ` [PATCH v3 bpf-next 3/3] selftests/bpf: Add test " Kenny Yu
2022-01-19 22:59 ` [PATCH v4 bpf-next 0/3] Add bpf_access_process_vm helper and " Kenny Yu
2022-01-19 22:59   ` [PATCH v4 bpf-next 1/3] bpf: Add bpf_access_process_vm() helper Kenny Yu
2022-01-20  3:45     ` Yonghong Song
2022-01-20 17:11       ` Kenny Yu
2022-01-19 22:59   ` [PATCH v4 bpf-next 2/3] libbpf: Add "iter.s" section for sleepable bpf iterator programs Kenny Yu
2022-01-19 22:59   ` [PATCH v4 bpf-next 3/3] selftests/bpf: Add test " Kenny Yu
2022-01-20 17:29 ` [PATCH v5 bpf-next 0/3] Add bpf_access_process_vm helper and " Kenny Yu
2022-01-20 17:29   ` [PATCH v5 bpf-next 1/3] bpf: Add bpf_access_process_vm() helper Kenny Yu
2022-01-20 22:45     ` Andrii Nakryiko
2022-01-21  2:27       ` Alexei Starovoitov
2022-01-21 17:20         ` Andrii Nakryiko
2022-01-21 17:41           ` Kenny Yu
2022-01-21 17:47             ` Alexei Starovoitov
2022-01-21 18:30               ` Kenny Yu
2022-01-20 17:29   ` [PATCH v5 bpf-next 2/3] libbpf: Add "iter.s" section for sleepable bpf iterator programs Kenny Yu
2022-01-20 17:29   ` [PATCH v5 bpf-next 3/3] selftests/bpf: Add test " Kenny Yu
2022-01-20 22:48     ` Andrii Nakryiko [this message]
2022-01-21 19:30 ` [PATCH v6 bpf-next 0/3] Add bpf_copy_from_user_task helper and " Kenny Yu
2022-01-21 19:30   ` [PATCH v6 bpf-next 1/3] bpf: Add bpf_copy_from_user_task() helper Kenny Yu
2022-01-21 19:53     ` Andrii Nakryiko
2022-01-21 20:04       ` Yonghong Song
2022-01-21 20:07         ` Andrii Nakryiko
2022-01-21 21:15           ` Yonghong Song
2022-01-24 17:30             ` Kenny Yu
2022-01-22  9:58       ` Gabriele
2022-01-22 10:08         ` Gabriele
2022-01-21 19:30   ` [PATCH v6 bpf-next 2/3] libbpf: Add "iter.s" section for sleepable bpf iterator programs Kenny Yu
2022-01-21 19:54     ` Andrii Nakryiko
2022-01-21 19:30   ` [PATCH v6 bpf-next 3/3] selftests/bpf: Add test " Kenny Yu
2022-01-21 19:55     ` Andrii Nakryiko
2022-01-24 18:53 ` [PATCH v7 bpf-next 0/4] Add bpf_copy_from_user_task helper and " Kenny Yu
2022-01-24 18:54   ` [PATCH v7 bpf-next 1/4] bpf: Add support for bpf iterator programs to use sleepable helpers Kenny Yu
2022-01-24 22:19     ` Andrii Nakryiko
2022-01-24 18:54   ` [PATCH v7 bpf-next 2/4] bpf: Add bpf_copy_from_user_task() helper Kenny Yu
2022-01-24 22:18     ` Andrii Nakryiko
2022-01-25  4:06       ` Alexei Starovoitov
2022-01-24 18:54   ` [PATCH v7 bpf-next 3/4] libbpf: Add "iter.s" section for sleepable bpf iterator programs Kenny Yu
2022-01-24 18:54   ` [PATCH v7 bpf-next 4/4] selftests/bpf: Add test " Kenny Yu
2022-01-25  4:10   ` [PATCH v7 bpf-next 0/4] Add bpf_copy_from_user_task helper and " patchwork-bot+netdevbpf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAEf4BzYD-f0g8_zo-wet1Rdz=hKEaOa0NZ=_GjRFntPw2FnbRA@mail.gmail.com' \
    --to=andrii.nakryiko@gmail.com \
    --cc=alexei.starovoitov@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=kennyyu@fb.com \
    --cc=phoenix1987@gmail.com \
    --cc=yhs@fb.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).