bpf: x86: Support in-register struct arguments in trampoline programs
authorYonghong Song <yhs@fb.com>
Wed, 31 Aug 2022 15:26:52 +0000 (08:26 -0700)
committerAlexei Starovoitov <ast@kernel.org>
Wed, 7 Sep 2022 02:51:14 +0000 (19:51 -0700)
commita9c5ad31fbdc4dec6d266fe22e51de1ad6d1bcf2
treed048234fe685efd2e0bdedb4a62d6ed40f916ae6
parent720e6a435194fb5237833a4a7ec6aa60a78964a8
bpf: x86: Support in-register struct arguments in trampoline programs

In C, struct value can be passed as a function argument.
For small structs, struct value may be passed in
one or more registers. For trampoline based bpf programs,
this would cause complication since one-to-one mapping between
function argument and arch argument register is not valid
any more.

The latest llvm16 added bpf support to pass by values
for struct up to 16 bytes ([1]). This is also true for
x86_64 architecture where two registers will hold
the struct value if the struct size is >8 and <= 16.
This may not be true if one of struct member is 'double'
type but in current linux source code we don't have
such instance yet, so we assume all >8 && <= 16 struct
holds two general purpose argument registers.

Also change on-stack nr_args value to the number
of registers holding the arguments. This will
permit bpf_get_func_arg() helper to get all
argument values.

 [1] https://reviews.llvm.org/D132144

Signed-off-by: Yonghong Song <yhs@fb.com>
Link: https://lore.kernel.org/r/20220831152652.2078600-1-yhs@fb.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
arch/x86/net/bpf_jit_comp.c