mbox series

[bpf-next,0/4] Move BPF_PROG, BPF_KPROBE, and BPF_KRETPROBE to libbpf

Message ID 20200229231112.1240137-1-andriin@fb.com
Headers show
Series Move BPF_PROG, BPF_KPROBE, and BPF_KRETPROBE to libbpf | expand

Message

Andrii Nakryiko Feb. 29, 2020, 11:11 p.m. UTC
Move BPF_PROG, BPF_KPROBE, and BPF_KRETPROBE helper macros from private
selftests helpers to public libbpf ones. These helpers are extremely helpful
for writing tracing BPF applications and have been requested to be exposed for
easy use (e.g., [0]).

As part of this move, fix up BPF_KRETPROBE to not allow for capturing input
arguments (as it's unreliable and they will be often clobbered). Also, add
vmlinux.h header guard to allow multi-time inclusion, if necessary; but also
to let PT_REGS_PARM do proper detection of struct pt_regs field names on x86
arch. See relevant patches for more details.

  [0] https://github.com/iovisor/bcc/pull/2778#issue-381642907

Andrii Nakryiko (4):
  bpftool: add header guards to generated vmlinux.h
  libbpf: fix use of PT_REGS_PARM macros with vmlinux.h
  selftests/bpf: fix BPF_KRETPROBE macro and use it in attach_probe test
  libbpf: merge selftests' bpf_trace_helpers.h into libbpf's
    bpf_tracing.h

 tools/bpf/bpftool/btf.c                       |   5 +
 tools/lib/bpf/bpf_tracing.h                   | 120 +++++++++++++++++-
 tools/testing/selftests/bpf/bpf_tcp_helpers.h |   2 +-
 .../testing/selftests/bpf/bpf_trace_helpers.h | 120 ------------------
 tools/testing/selftests/bpf/progs/bpf_dctcp.c |   2 +-
 .../testing/selftests/bpf/progs/fentry_test.c |   2 +-
 .../selftests/bpf/progs/fexit_bpf2bpf.c       |   2 +-
 .../bpf/progs/fexit_bpf2bpf_simple.c          |   2 +-
 .../testing/selftests/bpf/progs/fexit_test.c  |   2 +-
 tools/testing/selftests/bpf/progs/kfree_skb.c |   2 +-
 .../selftests/bpf/progs/test_attach_probe.c   |   3 +-
 .../selftests/bpf/progs/test_overhead.c       |   7 +-
 .../selftests/bpf/progs/test_perf_branches.c  |   2 +-
 .../selftests/bpf/progs/test_perf_buffer.c    |   2 +-
 .../selftests/bpf/progs/test_probe_user.c     |   1 -
 .../bpf/progs/test_trampoline_count.c         |   3 +-
 .../selftests/bpf/progs/test_xdp_bpf2bpf.c    |   2 +-
 17 files changed, 140 insertions(+), 139 deletions(-)
 delete mode 100644 tools/testing/selftests/bpf/bpf_trace_helpers.h

Comments

Alexei Starovoitov March 3, 2020, 12:30 a.m. UTC | #1
On Sat, Feb 29, 2020 at 03:11:08PM -0800, Andrii Nakryiko wrote:
> Move BPF_PROG, BPF_KPROBE, and BPF_KRETPROBE helper macros from private
> selftests helpers to public libbpf ones. These helpers are extremely helpful
> for writing tracing BPF applications and have been requested to be exposed for
> easy use (e.g., [0]).
> 
> As part of this move, fix up BPF_KRETPROBE to not allow for capturing input
> arguments (as it's unreliable and they will be often clobbered). Also, add
> vmlinux.h header guard to allow multi-time inclusion, if necessary; but also
> to let PT_REGS_PARM do proper detection of struct pt_regs field names on x86
> arch. See relevant patches for more details.
> 
>   [0] https://github.com/iovisor/bcc/pull/2778#issue-381642907

Looks like folks started to copy paste this macro into different places.
So definitely makes sense to move it.
Applied. Thanks