From: Yonghong Song <yhs@fb.com>
To: Jiri Olsa <olsajiri@gmail.com>
Cc: bpf@vger.kernel.org, Alexei Starovoitov <ast@kernel.org>,
Andrii Nakryiko <andrii@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
kernel-team@fb.com
Subject: Re: [RFC PATCH bpf-next 4/7] bpf: x86: Support in-register struct arguments
Date: Sun, 31 Jul 2022 10:00:39 -0700 [thread overview]
Message-ID: <25dbc437-e84c-548f-1809-d266da709ea7@fb.com> (raw)
In-Reply-To: <YuPALUYnHcZ1drB5@krava>
On 7/29/22 4:10 AM, Jiri Olsa wrote:
> On Tue, Jul 26, 2022 at 10:11:51AM -0700, Yonghong Song wrote:
>
> SNIP
>
>>
>> -static void restore_regs(const struct btf_func_model *m, u8 **prog, int nr_args,
>> - int regs_off)
>> +static void __save_struct_arg_regs(u8 **prog, int curr_reg_idx, int nr_regs,
>> + int struct_val_off, int stack_start_idx)
>> {
>> - int i;
>> + int i, reg_idx;
>> +
>> + /* Save struct registers to stack.
>> + * For example, argument 1 (second argument) size is 16 which occupies two
>> + * registers, these two register values will be saved in stack.
>> + * mov QWORD PTR [rbp-0x40],rsi
>> + * mov QWORD PTR [rbp-0x38],rdx
>> + */
>> + for (i = 0; i < nr_regs; i++) {
>> + reg_idx = curr_reg_idx + i;
>> + emit_stx(prog, bytes_to_bpf_size(8),
>> + BPF_REG_FP,
>> + reg_idx == 5 ? X86_REG_R9 : BPF_REG_1 + reg_idx,
>> + -(struct_val_off - stack_start_idx * 8));
>> + stack_start_idx++;
>> + }
>> +}
>> +
>> +static void save_regs(const struct btf_func_model *m, u8 **prog, int nr_args,
>> + int regs_off, int struct_val_off)
>> +{
>> + int curr_arg_idx, curr_reg_idx, curr_s_stack_off;
>> + int s_size, s_arg_idx, s_arg_nregs;
>> +
>> + curr_arg_idx = curr_reg_idx = curr_s_stack_off = 0;
>> + for (int i = 0; i < MAX_BPF_FUNC_STRUCT_ARGS; i++) {
>> + s_size = m->struct_arg_bsize[i];
>> + if (!s_size)
>> + return __save_normal_arg_regs(m, prog, curr_arg_idx, nr_args - curr_arg_idx,
>> + curr_reg_idx, regs_off);
>
> could we just do break in here instead?
Thanks for pointing out. Yes, we can just do break and later call
__save_normal_arg_regs(...) will handle this automatically.
The same for another place you pointed below.
>
> SNIP
>
>> +
>> +static void restore_regs(const struct btf_func_model *m, u8 **prog, int nr_args,
>> + int regs_off, int struct_val_off)
>> +{
>> + int curr_arg_idx, curr_reg_idx, curr_s_stack_off;
>> + int s_size, s_arg_idx, s_arg_nregs;
>> +
>> + curr_arg_idx = curr_reg_idx = curr_s_stack_off = 0;
>> + for (int i = 0; i < MAX_BPF_FUNC_STRUCT_ARGS; i++) {
>> + s_size = m->struct_arg_bsize[i];
>> + if (!s_size)
>> + return __restore_normal_arg_regs(m, prog, curr_arg_idx,
>> + nr_args - curr_arg_idx,
>> + curr_reg_idx, regs_off);
>
> same here
>
> jirka
>
>> +
>> + s_arg_idx = m->struct_arg_idx[i];
>> + s_arg_nregs = (s_size + 7) / 8;
>> +
>> + __restore_normal_arg_regs(m, prog, curr_arg_idx, s_arg_idx - curr_arg_idx,
>> + curr_reg_idx, regs_off);
>> + __restore_struct_arg_regs(prog, curr_reg_idx + s_arg_idx - curr_arg_idx,
>> + s_arg_nregs, struct_val_off, curr_s_stack_off);
>> + curr_reg_idx += s_arg_idx - curr_arg_idx + s_arg_nregs;
>> + curr_s_stack_off += s_arg_nregs;
>> + curr_arg_idx = s_arg_idx + 1;
>> + }
>> +
>> + __restore_normal_arg_regs(m, prog, curr_arg_idx, nr_args - curr_arg_idx, curr_reg_idx,
>> + regs_off);
>> }
>>
>
> SNIP
next prev parent reply other threads:[~2022-07-31 17:01 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-26 17:11 [RFC PATCH bpf-next 0/7] bpf: Support struct value argument for trampoline base progs Yonghong Song
2022-07-26 17:11 ` [RFC PATCH bpf-next 1/7] bpf: Always return corresponding btf_type in __get_type_size() Yonghong Song
2022-07-26 17:11 ` [RFC PATCH bpf-next 2/7] bpf: Add struct argument info in btf_func_model Yonghong Song
2022-08-09 0:02 ` Andrii Nakryiko
2022-08-09 17:38 ` Yonghong Song
2022-08-10 0:25 ` Andrii Nakryiko
2022-08-11 6:24 ` Yonghong Song
2022-07-26 17:11 ` [RFC PATCH bpf-next 3/7] bpf: x86: Rename stack_size to regs_off in {save,restore}_regs() Yonghong Song
2022-07-26 17:11 ` [RFC PATCH bpf-next 4/7] bpf: x86: Support in-register struct arguments Yonghong Song
2022-07-29 11:10 ` Jiri Olsa
2022-07-31 17:00 ` Yonghong Song [this message]
2022-07-26 17:11 ` [RFC PATCH bpf-next 5/7] bpf: arm64: No support of struct value argument Yonghong Song
2022-07-26 17:12 ` [RFC PATCH bpf-next 6/7] bpf: Populate struct value info in btf_func_model Yonghong Song
2022-07-26 17:12 ` [RFC PATCH bpf-next 7/7] selftests/bpf: Add struct value tests with fentry programs Yonghong Song
2022-07-28 15:46 ` [RFC PATCH bpf-next 0/7] bpf: Support struct value argument for trampoline base progs Kui-Feng Lee
2022-07-28 17:46 ` Yonghong Song
2022-07-28 19:57 ` Kui-Feng Lee
2022-07-28 23:30 ` Yonghong Song
2022-07-29 18:04 ` Kui-Feng Lee
2022-08-02 23:46 ` Yonghong Song
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=25dbc437-e84c-548f-1809-d266da709ea7@fb.com \
--to=yhs@fb.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=kernel-team@fb.com \
--cc=olsajiri@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.