Re: [PATCH 08/13] bpf: Add kprobe link for attaching raw kprobes

From
Jiri Olsa <hidden>
Date
2022-01-06 08:41:54
Also in
bpf, lkml
Reply to
Andrii Nakryiko, 2022-01-06
On Wed, Jan 05, 2022 at 08:30:56PM -0800, Andrii Nakryiko wrote:
On Tue, Jan 4, 2022 at 12:10 AM Jiri Olsa [off-list ref] wrote:
quoted
Adding new link type BPF_LINK_TYPE_KPROBE to attach kprobes
directly through register_kprobe/kretprobe API.

Adding new attach type BPF_TRACE_RAW_KPROBE that enables
such link for kprobe program.

The new link allows to create multiple kprobes link by using
new link_create interface:

  struct {
    __aligned_u64   addrs;
    __u32           cnt;
    __u64           bpf_cookie;
I'm afraid bpf_cookie has to be different for each addr, otherwise
it's severely limiting. So it would be an array of cookies alongside
an array of addresses
ok
quoted
  } kprobe;

Plus new flag BPF_F_KPROBE_RETURN for link_create.flags to
create return probe.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 include/linux/bpf_types.h      |   1 +
 include/uapi/linux/bpf.h       |  12 +++
 kernel/bpf/syscall.c           | 191 ++++++++++++++++++++++++++++++++-
 tools/include/uapi/linux/bpf.h |  12 +++
 4 files changed, 211 insertions(+), 5 deletions(-)
[...]
quoted
@@ -1111,6 +1113,11 @@ enum bpf_link_type {
  */
 #define BPF_F_SLEEPABLE                (1U << 4)

+/* link_create flags used in LINK_CREATE command for BPF_TRACE_RAW_KPROBE
+ * attach type.
+ */
+#define BPF_F_KPROBE_RETURN    (1U << 0)
+
we have plenty of flexibility to have per-link type fields, so why not
add `bool is_retprobe` next to addrs and cnt?
well I thought if I do that, people would suggest to use the empty
flags field instead ;-) 

we can move it there as you suggest, but I wonder it's good idea to
use bool in uapi headers, because the bool size definition is vague

jirka
quoted
 /* When BPF ldimm64's insn[0].src_reg != 0 then this can have
  * the following extensions:
  *
@@ -1465,6 +1472,11 @@ union bpf_attr {
                                 */
                                __u64           bpf_cookie;
                        } perf_event;
+                       struct {
+                               __aligned_u64   addrs;
+                               __u32           cnt;
+                               __u64           bpf_cookie;
+                       } kprobe;
                };
        } link_create;
[...]
  
Thread (46 messages) 46 messages, 5 authors, last reply 2022-01-12
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help