From: Yonghong Song <yhs@fb.com>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: bpf <bpf@vger.kernel.org>, Alexei Starovoitov <ast@kernel.org>,
Andrii Nakryiko <andrii@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Kernel Team <kernel-team@fb.com>
Subject: Re: [PATCH bpf-next v4 2/8] bpf: x86: Support in-register struct arguments in trampoline programs
Date: Wed, 7 Sep 2022 11:04:51 -0700 [thread overview]
Message-ID: <d9f6ddaa-1180-a635-1179-7381671b8d7a@fb.com> (raw)
In-Reply-To: <CAADnVQKb4Js-57c69Ryfdf3Tu3=Ray_Ovqjm7_2ZHw1LX3qgxg@mail.gmail.com>
On 9/6/22 8:00 PM, Alexei Starovoitov wrote:
> On Wed, Aug 31, 2022 at 8:26 AM Yonghong Song <yhs@fb.com> wrote:
>>
>> 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>
>> ---
>> arch/x86/net/bpf_jit_comp.c | 68 +++++++++++++++++++++++++++----------
>> 1 file changed, 51 insertions(+), 17 deletions(-)
>>
>> diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
>> index c1f6c1c51d99..ae89f4143eb4 100644
>> --- a/arch/x86/net/bpf_jit_comp.c
>> +++ b/arch/x86/net/bpf_jit_comp.c
>> @@ -1751,34 +1751,60 @@ st: if (is_imm8(insn->off))
>> static void save_regs(const struct btf_func_model *m, u8 **prog, int nr_args,
>> int stack_size)
>> {
>> - int i;
>> + int i, j, arg_size, nr_regs;
>> /* Store function arguments to stack.
>> * For a function that accepts two pointers the sequence will be:
>> * mov QWORD PTR [rbp-0x10],rdi
>> * mov QWORD PTR [rbp-0x8],rsi
>> */
>> - for (i = 0; i < min(nr_args, 6); i++)
>> - emit_stx(prog, bytes_to_bpf_size(m->arg_size[i]),
>> - BPF_REG_FP,
>> - i == 5 ? X86_REG_R9 : BPF_REG_1 + i,
>> - -(stack_size - i * 8));
>> + for (i = 0, j = 0; i < min(nr_args, 6); i++) {
>> + if (m->arg_flags[i] & BTF_FMODEL_STRUCT_ARG) {
>> + nr_regs = (m->arg_size[i] + 7) / 8;
>> + arg_size = 8;
>> + } else {
>> + nr_regs = 1;
>> + arg_size = m->arg_size[i];
>> + }
>
> This bit begs for a common helper, but I'm not sure
> whether it will look better, so applied as-is.
>
> BPF_PROG2 also feels unusual as an API macro name.
> We probably should bikeshed a bit and follow up
> if a better name is found.
I didn't come up with a better name either. But happy
to change to a different name if we agreed on one.
next prev parent reply other threads:[~2022-09-07 18:05 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-31 15:26 [PATCH bpf-next v4 0/8] bpf: Support struct argument for trampoline base progs Yonghong Song
2022-08-31 15:26 ` [PATCH bpf-next v4 1/8] bpf: Allow struct argument in trampoline based programs Yonghong Song
2022-08-31 15:26 ` [PATCH bpf-next v4 2/8] bpf: x86: Support in-register struct arguments in trampoline programs Yonghong Song
2022-09-06 16:40 ` Kui-Feng Lee
2022-09-06 19:30 ` Yonghong Song
2022-09-07 3:00 ` Alexei Starovoitov
2022-09-07 18:04 ` Yonghong Song [this message]
2022-08-31 15:26 ` [PATCH bpf-next v4 3/8] bpf: Update descriptions for helpers bpf_get_func_arg[_cnt]() Yonghong Song
2022-09-02 7:56 ` Jiri Olsa
2022-09-06 16:12 ` Yonghong Song
2022-08-31 15:27 ` [PATCH bpf-next v4 4/8] bpf: arm64: No support of struct argument in trampoline programs Yonghong Song
2022-08-31 15:27 ` [PATCH bpf-next v4 5/8] libbpf: Add new BPF_PROG2 macro Yonghong Song
2022-09-09 0:11 ` Andrii Nakryiko
2022-09-09 16:31 ` Yonghong Song
2022-09-09 18:07 ` Andrii Nakryiko
2022-08-31 15:27 ` [PATCH bpf-next v4 6/8] selftests/bpf: Add struct argument tests with fentry/fexit programs Yonghong Song
2022-08-31 15:27 ` [PATCH bpf-next v4 7/8] selftests/bpf: Use BPF_PROG2 for some fentry programs without struct arguments Yonghong Song
2022-08-31 15:27 ` [PATCH bpf-next v4 8/8] selftests/bpf: Add tracing_struct test in DENYLIST.s390x Yonghong Song
2022-09-07 3:10 ` [PATCH bpf-next v4 0/8] bpf: Support struct argument for trampoline base progs patchwork-bot+netdevbpf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=d9f6ddaa-1180-a635-1179-7381671b8d7a@fb.com \
--to=yhs@fb.com \
--cc=alexei.starovoitov@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=kernel-team@fb.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox