All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kenny Yu <kennyyu@fb.com>
To: <kennyyu@fb.com>
Cc: <andrii@kernel.org>, <ast@kernel.org>, <bpf@vger.kernel.org>,
	<daniel@iogearbox.net>, <yhs@fb.com>,
	<alexei.starovoitov@gmail.com>, <andrii.nakryiko@gmail.com>,
	<phoenix1987@gmail.com>
Subject: [PATCH v7 bpf-next 0/4] Add bpf_copy_from_user_task helper and sleepable bpf iterator programs
Date: Mon, 24 Jan 2022 10:53:59 -0800	[thread overview]
Message-ID: <20220124185403.468466-1-kennyyu@fb.com> (raw)
In-Reply-To: <20220113233158.1582743-1-kennyyu@fb.com>

This patch series makes the following changes:
* Adds a new bpf helper `bpf_copy_from_user_task` to read user space
  memory from a different task.
* Adds the ability to create sleepable bpf iterator programs.

As an example of how this will be used, at Meta we are using bpf task
iterator programs and this new bpf helper to read C++ async stack traces of
a running process for debugging C++ binaries in production.

Changes since v6:
* Split first patch into two patches: first patch to add support
  for bpf iterators to use sleepable helpers, and the second to add
  the new bpf helper.
* Simplify implementation of `bpf_copy_from_user_task` based on feedback.
* Add to docs that the destination buffer will be zero-ed on error.

Changes since v5:
* Rename `bpf_access_process_vm` to `bpf_copy_from_user_task`.
* Change return value to be all-or-nothing. If we get a partial read,
  memset all bytes to 0 and return -EFAULT.
* Add to docs that the helper can only be used by sleepable BPF programs.
* Fix nits in selftests.

Changes since v4:
* Make `flags` into u64.
* Use `user_ptr` arg name to be consistent with `bpf_copy_from_user`.
* Add an extra check in selftests to verify access_process_vm calls
  succeeded.

Changes since v3:
* Check if `flags` is 0 and return -EINVAL if not.
* Rebase on latest bpf-next branch and fix merge conflicts.

Changes since v2:
* Reorder arguments in `bpf_access_process_vm` to match existing related
  bpf helpers (e.g. `bpf_probe_read_kernel`, `bpf_probe_read_user`,
  `bpf_copy_from_user`).
* `flags` argument is provided for future extensibility and is not
  currently used, and we always invoke `access_process_vm` with no flags.
* Merge bpf helper patch and `bpf_iter_run_prog` patch together for better
  bisectability in case of failures.
* Clean up formatting and comments in selftests.

Changes since v1:
* Fixed "Invalid wait context" issue in `bpf_iter_run_prog` by using
  `rcu_read_lock_trace()` for sleepable bpf iterator programs.

Kenny Yu (4):
  bpf: Add support for bpf iterator programs to use sleepable helpers
  bpf: Add bpf_copy_from_user_task() helper
  libbpf: Add "iter.s" section for sleepable bpf iterator programs
  selftests/bpf: Add test for sleepable bpf iterator programs

 include/linux/bpf.h                           |  1 +
 include/uapi/linux/bpf.h                      | 11 ++++
 kernel/bpf/bpf_iter.c                         | 20 +++++--
 kernel/bpf/helpers.c                          | 34 ++++++++++++
 kernel/trace/bpf_trace.c                      |  2 +
 tools/include/uapi/linux/bpf.h                | 11 ++++
 tools/lib/bpf/libbpf.c                        |  1 +
 .../selftests/bpf/prog_tests/bpf_iter.c       | 20 +++++++
 .../selftests/bpf/progs/bpf_iter_task.c       | 54 +++++++++++++++++++
 9 files changed, 149 insertions(+), 5 deletions(-)

-- 
2.30.2


  parent reply	other threads:[~2022-01-24 18:57 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
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 ` Kenny Yu [this message]
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=20220124185403.468466-1-kennyyu@fb.com \
    --to=kennyyu@fb.com \
    --cc=alexei.starovoitov@gmail.com \
    --cc=andrii.nakryiko@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.