Skip to content

bpf, x86: Add bpf_get_func_ip helper

Jiri Olsa bpf netdev 4 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v4 Latest8 patches 7 repliesIn review
  2. v37 patches 14 repliesSuperseded
  3. v27 patches 2 repliesSuperseded
Earlier versions · 1
VersionPostedPatchesRepliesStatus
v1 RFC5 patches9 repliesSuperseded

Changes in v4 from the cover letter

- dropped jit/x86 check for get_func_ip tracing check [Alexei]
- added code to bpf_get_func_ip_tracing [Alexei]
and tested that it works without inlining [Alexei]
- changed has_get_func_ip to check_get_func_ip [Andrii]
- replaced test assert loop with explicit asserts [Andrii]
- adde bpf_program__attach_kprobe_opts function
and use it for offset setup [Andrii]
- used bpf_program__set_autoload(false) for test6 [Andrii]
- added Masami's ack

Patches in v4 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/8bpf, x86: Store caller's ip in trampoline stackarch/x86/net/bpf_jit_comp.c include/linux/bpf.h+24 -00 replies
2/8bpf: Enable BPF_TRAMP_F_IP_ARG for trampolines with call_get_func_ipinclude/linux/filter.h kernel/bpf/trampoline.c+11 -40 replies
3/8bpf: Add bpf_get_func_ip helper for tracing programsinclude/uapi/linux/bpf.h kernel/bpf/verifier.c kernel/trace/bpf_trace.c +1 more+72 -02 replies
4/8bpf: Add bpf_get_func_ip helper for kprobe programsinclude/uapi/linux/bpf.h kernel/bpf/verifier.c kernel/trace/bpf_trace.c +1 more+20 -20 replies
5/8selftests/bpf: Add test for bpf_get_func_ip helpertools/testing/selftests/bpf/prog_tests/get_func_ip_test.c tools/testing/selftests/bpf/progs/get_func_ip_test.c+101 -00 replies
6/8libbpf: Add bpf_program__attach_kprobe_opts functiontools/lib/bpf/libbpf.c+25 -93 replies
7/8libbpf: Allow specification of "kprobe/function+offset"tools/lib/bpf/libbpf.c+22 -22 replies
8/8selftests/bpf: Add test for bpf_get_func_ip in kprobe+offset probetools/testing/selftests/bpf/prog_tests/get_func_ip_test.c tools/testing/selftests/bpf/progs/get_func_ip_test.c+27 -20 replies

Reviews trailers per patch

1 of 8 patches has a Reviewed-by or Acked-by.

PatchMasami Hiramatsu
1/8
2/8
3/8
4/8R-b
5/8
6/8
7/8
8/8

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v4 thread

Cover letter [PATCHv4 bpf-next 0/8] bpf, x86: Add bpf_get_func_ip helper

hi,
adding bpf_get_func_ip helper that returns IP address of the caller function for trampoline and krobe programs.

There're 2 specific implementation of the bpf_get_func_ip helper, one for trampoline progs and one for kprobe/kretprobe progs.

The trampoline helper call is replaced/inlined by verifier with simple move instruction. The kprobe/kretprobe is actual helper call that returns prepared caller address.

Also available at:
https://git.kernel.org/pub/scm/linux/kernel/git/jolsa/perf.git
bpf/get_func_ip

v4 changes:
- dropped jit/x86 check for get_func_ip tracing check [Alexei]
- added code to bpf_get_func_ip_tracing [Alexei]
and tested that it works without inlining [Alexei]
- changed has_get_func_ip to check_get_func_ip [Andrii]
- replaced test assert loop with explicit asserts [Andrii]
- adde bpf_program__attach_kprobe_opts function
and use it for offset setup [Andrii]
- used bpf_program__set_autoload(false) for test6 [Andrii]
- added Masami's ack

v3 changes:
- resend with Masami in cc and v3 in each patch subject

v2 changes:
- use kprobe_running to get kprobe instead of cpu var [Masami]
- added support to add kprobe on function+offset
and test for that [Alan]

thanks,
jirka

---
Alan Maguire (1):
libbpf: Allow specification of "kprobe/function+offset"

Jiri Olsa (7):
bpf, x86: Store caller's ip in trampoline stack
bpf: Enable BPF_TRAMP_F_IP_ARG for trampolines with call_get_func_ip
bpf: Add bpf_get_func_ip helper for tracing programs
bpf: Add bpf_get_func_ip helper for kprobe programs selftests/bpf: Add test for bpf_get_func_ip helper
libbpf: Add bpf_program__attach_kprobe_opts function selftests/bpf: Add test for bpf_get_func_ip in kprobe+offset probe

 arch/x86/net/bpf_jit_comp.c                               | 19 +++++++++++++++++++
 include/linux/bpf.h                                       |  5 +++++
 include/linux/filter.h                                    |  3 ++-
 include/uapi/linux/bpf.h                                  |  7 +++++++
 kernel/bpf/trampoline.c                                   | 12 +++++++++---
 kernel/bpf/verifier.c                                     | 45 +++++++++++++++++++++++++++++++++++++++++++++
 kernel/trace/bpf_trace.c                                  | 31 +++++++++++++++++++++++++++++++
 tools/include/uapi/linux/bpf.h                            |  7 +++++++
 tools/lib/bpf/libbpf.c                                    | 56 ++++++++++++++++++++++++++++++++++++++++++++++----------
 tools/testing/selftests/bpf/prog_tests/get_func_ip_test.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 tools/testing/selftests/bpf/progs/get_func_ip_test.c      | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 11 files changed, 297 insertions(+), 14 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/prog_tests/get_func_ip_test.c
 create mode 100644 tools/testing/selftests/bpf/progs/get_func_ip_test.c