Re: [PATCH v4 bpf-next 1/3] bpf: Add bpf_access_process_vm() helper

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

 





On 1/19/22 2:59 PM, Kenny Yu wrote:
This adds a helper for bpf programs to access the memory of other
tasks. This also adds the ability for bpf iterator programs to
be sleepable.

This changes `bpf_iter_run_prog` to use the appropriate synchronization for
sleepable bpf programs. With sleepable bpf iterator programs, we can no
longer use `rcu_read_lock()` and must use `rcu_read_lock_trace()` instead
to protect the bpf program.

As an example use case at Meta, we are using a bpf task iterator program
and this new helper to print C++ async stack traces for all threads of
a given process.

Signed-off-by: Kenny Yu <kennyyu@xxxxxx>
---
  include/linux/bpf.h            |  1 +
  include/uapi/linux/bpf.h       | 11 +++++++++++
  kernel/bpf/bpf_iter.c          | 20 +++++++++++++++-----
  kernel/bpf/helpers.c           | 23 +++++++++++++++++++++++
  kernel/trace/bpf_trace.c       |  2 ++
  tools/include/uapi/linux/bpf.h | 11 +++++++++++
  6 files changed, 63 insertions(+), 5 deletions(-)

diff --git a/include/linux/bpf.h b/include/linux/bpf.h
index dce54eb0aae8..29f174c08126 100644
--- a/include/linux/bpf.h
+++ b/include/linux/bpf.h
@@ -2220,6 +2220,7 @@ extern const struct bpf_func_proto bpf_kallsyms_lookup_name_proto;
  extern const struct bpf_func_proto bpf_find_vma_proto;
  extern const struct bpf_func_proto bpf_loop_proto;
  extern const struct bpf_func_proto bpf_strncmp_proto;
+extern const struct bpf_func_proto bpf_access_process_vm_proto;
const struct bpf_func_proto *tracing_prog_func_proto(
    enum bpf_func_id func_id, const struct bpf_prog *prog);
diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
index fe2272defcd9..38a85e6756b2 100644
--- a/include/uapi/linux/bpf.h
+++ b/include/uapi/linux/bpf.h
@@ -5049,6 +5049,16 @@ union bpf_attr {
   *		This helper is currently supported by cgroup programs only.
   *	Return
   *		0 on success, or a negative error in case of failure.
+ *
+ * long bpf_access_process_vm(void *dst, u32 size, const void *unsafe_ptr, struct task_struct *tsk, u32 flags)

Maybe we can change 'flags' type to u64? This will leave more room for future potential extensions. In all recent helpers with added 'flags', most of them are u64.

+ *	Description
+ *		Read *size* bytes from user space address *unsafe_ptr* in *tsk*'s
+ *		address space, and stores the data in *dst*. *flags* is not
+ *		used yet and is provided for future extensibility. This is a
+ *		wrapper of **access_process_vm**\ ().
+ *	Return
+ *		The number of bytes written to the buffer, or a negative error
+ *		in case of failure.
   */
  #define __BPF_FUNC_MAPPER(FN)		\
  	FN(unspec),			\
@@ -5239,6 +5249,7 @@ union bpf_attr {
  	FN(get_func_arg_cnt),		\
  	FN(get_retval),			\
  	FN(set_retval),			\
+	FN(access_process_vm),		\
  	/* */
[...]



[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