aboutsummaryrefslogtreecommitdiffstats
path: root/tools/testing/selftests/bpf/prog_tests
diff options
context:
space:
mode:
authorYonghong Song <yhs@fb.com>2022-08-31 08:27:07 -0700
committerAlexei Starovoitov <ast@kernel.org>2022-09-06 19:51:14 -0700
commit34586d29f8dfc4ae30642c5b9a4db8a4a7af6869 (patch)
treeda4d206ab2cdfc9655b3e66fda380bf8067272d1 /tools/testing/selftests/bpf/prog_tests
parentbpf: arm64: No support of struct argument in trampoline programs (diff)
downloadlinux-dev-34586d29f8dfc4ae30642c5b9a4db8a4a7af6869.tar.xz
linux-dev-34586d29f8dfc4ae30642c5b9a4db8a4a7af6869.zip
libbpf: Add new BPF_PROG2 macro
To support struct arguments in trampoline based programs, existing BPF_PROG doesn't work any more since the type size is needed to find whether a parameter takes one or two registers. So this patch added a new BPF_PROG2 macro to support such trampoline programs. The idea is suggested by Andrii. For example, if the to-be-traced function has signature like typedef struct { void *x; int t; } sockptr; int blah(sockptr x, char y); In the new BPF_PROG2 macro, the argument can be represented as __bpf_prog_call( ({ union { struct { __u64 x, y; } ___z; sockptr x; } ___tmp = { .___z = { ctx[0], ctx[1] }}; ___tmp.x; }), ({ union { struct { __u8 x; } ___z; char y; } ___tmp = { .___z = { ctx[2] }}; ___tmp.y; })); In the above, the values stored on the stack are properly assigned to the actual argument type value by using 'union' magic. Note that the macro also works even if no arguments are with struct types. Note that new BPF_PROG2 works for both llvm16 and pre-llvm16 compilers where llvm16 supports bpf target passing value with struct up to 16 byte size and pre-llvm16 will pass by reference by storing values on the stack. With static functions with struct argument as always inline, the compiler is able to optimize and remove additional stack saving of struct values. Signed-off-by: Yonghong Song <yhs@fb.com> Link: https://lore.kernel.org/r/20220831152707.2079473-1-yhs@fb.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Diffstat (limited to 'tools/testing/selftests/bpf/prog_tests')
0 files changed, 0 insertions, 0 deletions