Re: [RFC/PATCH bpf-next 02/20] bpf: Add cookies support for uprobe_multi link

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

 





On 4/24/23 9:04 AM, Jiri Olsa wrote:
Adding support to specify cookies array for uprobe_multi link.

The cookies array share indexes and length with other uprobe_multi
arrays (paths/offsets/ref_ctr_offsets).

The cookies[i] value defines cookie for i-the uprobe and will be
returned by bpf_get_attach_cookie helper when called from ebpf
program hooked to that specific uprobe.

Signed-off-by: Jiri Olsa <jolsa@xxxxxxxxxx>
---
  include/uapi/linux/bpf.h |  1 +
  kernel/bpf/syscall.c     |  2 +-
  kernel/trace/bpf_trace.c | 46 +++++++++++++++++++++++++++++++++++++---
  3 files changed, 45 insertions(+), 4 deletions(-)

diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
index debc041c6ca5..77ce2159478d 100644
--- a/include/uapi/linux/bpf.h
+++ b/include/uapi/linux/bpf.h
@@ -1581,6 +1581,7 @@ union bpf_attr {
  				__aligned_u64	paths;
  				__aligned_u64	offsets;
  				__aligned_u64	ref_ctr_offsets;
+				__aligned_u64	cookies;
  			} uprobe_multi;
  		};
  	} link_create;
diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
index 0b789a33317b..5b2dc7ae8616 100644
--- a/kernel/bpf/syscall.c
+++ b/kernel/bpf/syscall.c
@@ -4566,7 +4566,7 @@ static int bpf_map_do_batch(const union bpf_attr *attr,
  	return err;
  }
-#define BPF_LINK_CREATE_LAST_FIELD link_create.kprobe_multi.cookies
+#define BPF_LINK_CREATE_LAST_FIELD link_create.uprobe_multi.cookies
  static int link_create(union bpf_attr *attr, bpfptr_t uattr)
  {
  	enum bpf_prog_type ptype;
diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
index b84a7d01abf4..f795cfc00e5f 100644
--- a/kernel/trace/bpf_trace.c
+++ b/kernel/trace/bpf_trace.c
@@ -87,6 +87,8 @@ static int bpf_btf_printf_prepare(struct btf_ptr *ptr, u32 btf_ptr_size,
  static u64 bpf_kprobe_multi_cookie(struct bpf_run_ctx *ctx);
  static u64 bpf_kprobe_multi_entry_ip(struct bpf_run_ctx *ctx);
+static u64 bpf_uprobe_multi_cookie(struct bpf_run_ctx *ctx);
+
  /**
   * trace_call_bpf - invoke BPF program
   * @call: tracepoint event
@@ -1089,6 +1091,18 @@ static const struct bpf_func_proto bpf_get_attach_cookie_proto_kmulti = {
  	.arg1_type	= ARG_PTR_TO_CTX,
  };
+BPF_CALL_1(bpf_get_attach_cookie_uprobe_multi, struct pt_regs *, regs)
+{
+	return bpf_uprobe_multi_cookie(current->bpf_ctx);
+}

the argument regs is not used here.
looks like we have the same issue for
  bpf_get_attach_cookie_kprobe_multi
  bpf_get_attach_cookie_trace
  bpf_get_attach_cookie_tracing

I think this probably for preserving uapi. So I am okay with
the above, just want to point it out.

+
+static const struct bpf_func_proto bpf_get_attach_cookie_proto_umulti = {
+	.func		= bpf_get_attach_cookie_uprobe_multi,
+	.gpl_only	= false,
+	.ret_type	= RET_INTEGER,
+	.arg1_type	= ARG_PTR_TO_CTX,
+};
+
[...]



[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