Skip to content

bpf: Add helpers to access traced function arguments

Jiri Olsa bpf netdev 2 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest5 patches 1 replyIn review
  2. v13 patches 12 repliesSuperseded

Changes in v2 from the cover letter

- added acks
- updated stack diagram
- return -EOPNOTSUPP instead of -EINVAL in bpf_get_func_ret
- removed gpl_only for all helpers
- added verifier fix to allow proper arguments checks,
Andrii asked for checking also 'int *b' argument in bpf_modify_return_test programs and it turned out that it's currently not supported by verifier - we can't read argument that is int pointer, so I had to add verifier change to allow that + adding verifier selftest
- checking all arguments in bpf_modify_return_test test programs
- moved helpers proto gets in tracing_prog_func_proto with attach type check

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/5bpf: Allow access to int pointer arguments in tracing programskernel/bpf/btf.c+3 -40 replies
2/5selftests/bpf: Add test to access int ptr argument in tracing programtools/testing/selftests/bpf/verifier/btf_ctx_access.c+12 -00 replies
3/5bpf, x64: Replace some stack_size usage with offset variablesarch/x86/net/bpf_jit_comp.c+28 -140 replies
4/5bpf: Add get_func_[arg|ret|arg_cnt] helpersarch/x86/net/bpf_jit_comp.c include/linux/bpf.h include/uapi/linux/bpf.h +4 more+209 -71 reply
5/5selftests/bpf: Add tests for get_func_[arg|ret|arg_cnt] helperstools/testing/selftests/bpf/prog_tests/get_func_args_test.c tools/testing/selftests/bpf/progs/get_func_args_test.c+167 -00 replies

Reviews trailers per patch

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

PatchJohn FastabendAndrii Nakryiko
1/5
2/5
3/5A-b A-b
4/5
5/5

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

Read the v2 thread

Cover letter [PATCHv2 bpf-next 0/5] bpf: Add helpers to access traced function arguments

hi,
adding new helpers to access traced function arguments that came out of the trampoline batch changes [1].

Get n-th argument of the traced function:

    long bpf_get_func_arg(void *ctx, u32 n, u64 *value)

Get return value of the traced function:
long bpf_get_func_ret(void *ctx, u64 *value)

Get arguments count of the traced funtion:
long bpf_get_func_arg_cnt(void *ctx)

v2 changes:
- added acks
- updated stack diagram
- return -EOPNOTSUPP instead of -EINVAL in bpf_get_func_ret
- removed gpl_only for all helpers
- added verifier fix to allow proper arguments checks,
Andrii asked for checking also 'int *b' argument in bpf_modify_return_test programs and it turned out that it's currently not supported by verifier - we can't read argument that is int pointer, so I had to add verifier change to allow that + adding verifier selftest
- checking all arguments in bpf_modify_return_test test programs
- moved helpers proto gets in tracing_prog_func_proto with attach type check

thanks,
jirka

[1] https://lore.kernel.org/bpf/[email protected]/
---
Jiri Olsa (5):
bpf: Allow access to int pointer arguments in tracing programs selftests/bpf: Add test to access int ptr argument in tracing program bpf, x64: Replace some stack_size usage with offset variables
bpf: Add get_func_[arg|ret|arg_cnt] helpers selftests/bpf: Add tests for get_func_[arg|ret|arg_cnt] helpers

 arch/x86/net/bpf_jit_comp.c                                 |  55 ++++++++++++++++++++++++++++++-----------
 include/linux/bpf.h                                         |   5 ++++
 include/uapi/linux/bpf.h                                    |  28 +++++++++++++++++++++
 kernel/bpf/btf.c                                            |   7 +++---
 kernel/bpf/trampoline.c                                     |   8 ++++++
 kernel/bpf/verifier.c                                       |  77 +++++++++++++++++++++++++++++++++++++++++++++++++++++----
 kernel/trace/bpf_trace.c                                    |  55 ++++++++++++++++++++++++++++++++++++++++-
 tools/include/uapi/linux/bpf.h                              |  28 +++++++++++++++++++++
 tools/testing/selftests/bpf/prog_tests/get_func_args_test.c |  44 +++++++++++++++++++++++++++++++++
 tools/testing/selftests/bpf/progs/get_func_args_test.c      | 123 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 tools/testing/selftests/bpf/verifier/btf_ctx_access.c       |  12 +++++++++
 11 files changed, 418 insertions(+), 24 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/prog_tests/get_func_args_test.c
 create mode 100644 tools/testing/selftests/bpf/progs/get_func_args_test.c
 create mode 100644 tools/testing/selftests/bpf/verifier/btf_ctx_access.c