Skip to content

RFC kprobe/bpf: Add support to attach multiple kprobes

Jiri Olsa bpf lkml llvm netdev oe-kbuild-all 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 RFC Latest13 patches 22 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/13ftrace: Add ftrace_set_filter_ips functioninclude/linux/ftrace.h kernel/trace/ftrace.c+47 -90 replies
2/13kprobe: Keep traced function addressinclude/linux/kprobes.h kernel/kprobes.c kernel/trace/bpf_trace.c +1 more+18 -34 replies
3/13kprobe: Add support to register multiple ftrace kprobesarch/Kconfig arch/x86/Kconfig arch/x86/kernel/kprobes/ftrace.c +2 more+235 -461 reply
4/13kprobe: Add support to register multiple ftrace kretprobesinclude/linux/kprobes.h kernel/kprobes.c+37 -100 replies
5/13kprobe: Allow to get traced function address for multi ftrace kprobesarch/x86/kernel/kprobes/ftrace.c include/linux/kprobes.h kernel/kprobes.c +1 more+41 -11 reply
6/13samples/kprobes: Add support for multi kprobe interfacesamples/kprobes/kprobe_example.c+43 -40 replies
7/13samples/kprobes: Add support for multi kretprobe interfacesamples/kprobes/kretprobe_example.c+41 -20 replies
8/13bpf: Add kprobe link for attaching raw kprobesinclude/linux/bpf_types.h include/uapi/linux/bpf.h kernel/bpf/syscall.c +1 more+211 -54 replies
9/13libbpf: Add libbpf__kallsyms_parse functiontools/lib/bpf/libbpf.c tools/lib/bpf/libbpf_internal.h+43 -240 replies
10/13libbpf: Add bpf_link_create support for multi kprobestools/lib/bpf/bpf.c tools/lib/bpf/bpf.h+11 -10 replies
11/13libbpf: Add bpf_program__attach_kprobe_opts for multi kprobestools/lib/bpf/libbpf.c+123 -10 replies
12/13selftest/bpf: Add raw kprobe attach testtools/testing/selftests/bpf/prog_tests/raw_kprobe_test.c tools/testing/selftests/bpf/progs/raw_kprobe.c+150 -00 replies
13/13selftest/bpf: Add bpf_cookie test for raw_k[ret]probetools/testing/selftests/bpf/prog_tests/bpf_cookie.c tools/testing/selftests/bpf/progs/test_bpf_cookie.c+65 -10 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [RFC 00/13] kprobe/bpf: Add support to attach multiple kprobes

hi,
adding support to attach multiple kprobes within single syscall and speed up attachment of many kprobes.

The previous attempt [1] wasn't fast enough, so coming with new approach that adds new kprobe interface.

The attachment speed of of this approach (tested in bpftrace) is now comparable to ftrace tracer attachment speed.. fast ;-)

The limit of this approach is forced by using ftrace as attach layer, so it allows only kprobes on function's entry (plus return probes).

This patchset contains:
- kprobes support to register multiple kprobes with current kprobe API (patches 1 - 8)
- bpf support ot create new kprobe link allowing to attach multiple addresses (patches 9 - 14)

We don't need to care about multiple probes on same functions because it's taken care on the ftrace_ops layer.

Also available at:
https://git.kernel.org/pub/scm/linux/kernel/git/jolsa/perf.git
kprobe/multi

thanks,
jirka

[1] https://lore.kernel.org/bpf/[email protected]/

---
Jiri Olsa (13):
ftrace: Add ftrace_set_filter_ips function
kprobe: Keep traced function address
kprobe: Add support to register multiple ftrace kprobes
kprobe: Add support to register multiple ftrace kretprobes
kprobe: Allow to get traced function address for multi ftrace kprobes samples/kprobes: Add support for multi kprobe interface samples/kprobes: Add support for multi kretprobe interface
bpf: Add kprobe link for attaching raw kprobes
libbpf: Add libbpf__kallsyms_parse function
libbpf: Add bpf_link_create support for multi kprobes
libbpf: Add bpf_program__attach_kprobe_opts for multi kprobes selftest/bpf: Add raw kprobe attach test
selftest/bpf: Add bpf_cookie test for raw_k[ret]probe

 arch/Kconfig                                             |   3 ++
 arch/x86/Kconfig                                         |   1 +
 arch/x86/kernel/kprobes/ftrace.c                         |  51 +++++++++++++-----
 include/linux/bpf_types.h                                |   1 +
 include/linux/ftrace.h                                   |   3 ++
 include/linux/kprobes.h                                  |  55 ++++++++++++++++++++
 include/uapi/linux/bpf.h                                 |  12 +++++
 kernel/bpf/syscall.c                                     | 191 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 kernel/kprobes.c                                         | 264 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------
 kernel/trace/bpf_trace.c                                 |   7 ++-
 kernel/trace/ftrace.c                                    |  53 +++++++++++++++----
 samples/kprobes/kprobe_example.c                         |  47 +++++++++++++++--
 samples/kprobes/kretprobe_example.c                      |  43 +++++++++++++++-
 tools/include/uapi/linux/bpf.h                           |  12 +++++
 tools/lib/bpf/bpf.c                                      |   5 ++
 tools/lib/bpf/bpf.h                                      |   7 ++-
 tools/lib/bpf/libbpf.c                                   | 186 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------
 tools/lib/bpf/libbpf_internal.h                          |   5 ++
 tools/testing/selftests/bpf/prog_tests/bpf_cookie.c      |  42 +++++++++++++++
 tools/testing/selftests/bpf/prog_tests/raw_kprobe_test.c |  92 +++++++++++++++++++++++++++++++++
 tools/testing/selftests/bpf/progs/get_func_ip_test.c     |   4 +-
 tools/testing/selftests/bpf/progs/raw_kprobe.c           |  58 +++++++++++++++++++++
 tools/testing/selftests/bpf/progs/test_bpf_cookie.c      |  24 ++++++++-
 23 files changed, 1062 insertions(+), 104 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/prog_tests/raw_kprobe_test.c
 create mode 100644 tools/testing/selftests/bpf/progs/raw_kprobe.c