]> git.baikalelectronics.ru Git - kernel.git/commit
bpf: Add get_func_[arg|ret|arg_cnt] helpers
authorJiri Olsa <jolsa@redhat.com>
Wed, 8 Dec 2021 19:32:44 +0000 (20:32 +0100)
committerAlexei Starovoitov <ast@kernel.org>
Mon, 13 Dec 2021 17:25:59 +0000 (09:25 -0800)
commit9c504d8add063dcba36f08aa01dbe37f4866e280
tree6c75f634ad049e353506e2b9dd8c4c221363a35f
parent9c571d0956a5dc75a8f03695ffd14b326074cc2f
bpf: Add get_func_[arg|ret|arg_cnt] helpers

Adding following helpers for tracing programs:

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 function:
  long bpf_get_func_arg_cnt(void *ctx)

The trampoline now stores number of arguments on ctx-8
address, so it's easy to verify argument index and find
return value argument's position.

Moving function ip address on the trampoline stack behind
the number of functions arguments, so it's now stored on
ctx-16 address if it's needed.

All helpers above are inlined by verifier.

Also bit unrelated small change - using newly added function
bpf_prog_has_trampoline in check_get_func_ip.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20211208193245.172141-5-jolsa@kernel.org
arch/x86/net/bpf_jit_comp.c
include/linux/bpf.h
include/uapi/linux/bpf.h
kernel/bpf/trampoline.c
kernel/bpf/verifier.c
kernel/trace/bpf_trace.c
tools/include/uapi/linux/bpf.h