All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Alexei Starovoitov" <alexei.starovoitov@gmail.com>
To: "Yonghong Song" <yonghong.song@linux.dev>
Cc: "bpf" <bpf@vger.kernel.org>,
	"Alexei Starovoitov" <ast@kernel.org>,
	"Andrii Nakryiko" <andrii@kernel.org>,
	"Daniel Borkmann" <daniel@iogearbox.net>,
	"Eduard Zingerman" <eddyz87@gmail.com>,
	"Kernel Team" <kernel-team@fb.com>
Subject: Re: [PATCH bpf-next 07/12] bpf, x86: Place kfunc arguments per the SysV calling convention
Date: Tue, 08 Sep 2026 18:59:26 -0700	[thread overview]
Message-ID: <DLAEX3NMK5GW.C82FXVYWQTMB@gmail.com> (raw)
In-Reply-To: <1eef259d-e0d2-4b73-99eb-c7fb736a7846@linux.dev>

On Tue Sep 8, 2026 at 11:43 AM PDT, Yonghong Song wrote:
>
>
> On 9/8/26 8:24 AM, Alexei Starovoitov wrote:
>> On Mon, Sep 7, 2026 at 10:02 PM Yonghong Song <yonghong.song@linux.dev> wrote:
>>>
>>> The following is what I was suggested:
>>>
>>> llvm: no change,
>>>
>>> x86_64 jit:
>>>
>>> +bool bpf_jit_supports_kfunc_arg_slot(u32 slots_used, u32 nslots, u32 align)
>>> +{
>>> +       if (slots_used >= 6)
>>> +               return IS_ALIGNED((slots_used - 6) * sizeof(u64), align);
>>> +
>>> +       return slots_used + nslots <= 6;
>>> +}
>>>
>>> arm64 jit:
>>>
>>> +bool bpf_jit_supports_kfunc_arg_slot(u32 slots_used, u32 nslots, u32 align)
>>> +{
>>> +       if (slots_used >= 8)
>>> +               return IS_ALIGNED((slots_used - 8) * sizeof(u64), align);
>>> +
>>> +       if (!IS_ALIGNED(slots_used * sizeof(u64), align))
>>> +               return false;
>>> +
>>> +       return slots_used + nslots <= 8;
>>> +}
>>>
>>> The above x86_64 and arm64 will reject for certain cases as in the above.
>> If such rejection applies to bpf2bpf calls then we cannot use this approach.
>> rust-bpf is using i128 here and there and we cannot change standard rust
>> crates to shift arguments to satisfy JITs.
>
> The above bpf_jit_supports_kfunc_arg_slot() is for jit, so this is not
> related to bpf2bpf calls. bpf2bpf calls work fine.
>
>>
>>> The alternative solution is to change llvm's. Let us say we want to have
>>> arm64 calling convention. We may have
>>>
>>>      slot 0: int
>>>      slot 1: empty
>>>      slot 2: first64 in int128
>>>      slot 3: second64 in int128
>>>      slot 4: int
>>>      slot 5: empty
>>>      slot 6: first64 in int128
>>>      slot 7: second64 int int128
>>>      slot 8: int
>>>
>>> in llvm and it matches to arm64
>>> but it has some issues in kernel as some slot is empty. (slot 1, slot 5).
>>> and it needs calling convention change for x86_64.
>> Are you saying that x86 won't have slot 1 and 5 empty?
>> and first i128 will be in slot 1 and 2.
>
> Yes. For x86, it looks like
>      slot 0: int
>      slot 1: first64 in int128
>      slot 2: second64 in int128
>      slot 3: int
>      slot 4: first64 in int128
>      slot 5: second64 int int128
>      slot 6: int
>
>> So if we go with arm64 convention the x86 jit would still need to shift.
>
> Yes.
>
>> If we go with x86 convention then arm64 jit would need to introduce holes?
>
> Yes.
>
>>
>> While current bpf convention forces both x86 and arm64 to shift slots?
>
> The current bpf convention assigned arguments in order without any gaps.
> So yes, it will force both x86 and arm64 to shift slots.
>
>>
>> I think it's better to align bpf with either x86 or arm64.
>
> I did some investigation. Looks like pretty hard.
> If we want to align bpf with x86 calling convention, we will need
> 6 register arguments, alignment requirement for stack (__int128)
> and register backfilling as the *common* calling convention.
> This will make arm64 harder.

I see. Because of 6th reg on x86 the JIT would still need to do the work.
Ok. let's keep bpf calling convention as-is then.

> I think we can do a better job by having common struct for the above info:
>     nr_arg_regs          // 6 for x86_64 and 8 for arm64
>     even_reg_align       // true for arm64
>     backfill_after_stack // true for x86_64
>     pad_stack_to_align   // true for both arm64 and x86_64
>     others if needed
>
> With such information, we can calculate position in verifier.c.
> So we have minimum change in JIT.

That makes sense to me.


  reply	other threads:[~2026-09-09  1:59 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-04  5:09 [PATCH bpf-next 00/12] bpf: Support by-value struct and __int128 arguments Yonghong Song
2026-09-04  5:10 ` [PATCH bpf-next 01/12] selftests/bpf: Add a test for an __int128 by-value argument Yonghong Song
2026-09-04  5:10 ` [PATCH bpf-next 02/12] bpf: Index global function arguments by argument slot Yonghong Song
2026-09-04  5:10 ` [PATCH bpf-next 03/12] bpf: Support by-value struct arguments up to 16 bytes Yonghong Song
2026-09-04  5:23   ` sashiko-bot
2026-09-08  4:17     ` Yonghong Song
2026-09-04  6:09   ` bot+bpf-ci
2026-09-08  4:19     ` Yonghong Song
2026-09-04  5:10 ` [PATCH bpf-next 04/12] bpf: Support __int128 as a by-value function argument Yonghong Song
2026-09-04  5:32   ` sashiko-bot
2026-09-08  4:20     ` Yonghong Song
2026-09-04  6:09   ` bot+bpf-ci
2026-09-08  4:21     ` Yonghong Song
2026-09-04  5:10 ` [PATCH bpf-next 05/12] bpf: Support by-value struct and __int128 kfunc arguments Yonghong Song
2026-09-04  6:18   ` sashiko-bot
2026-09-08  4:22     ` Yonghong Song
2026-09-04  6:24   ` bot+bpf-ci
2026-09-08  4:23     ` Yonghong Song
2026-09-04  5:10 ` [PATCH bpf-next 06/12] bpf: Add a JIT helper for the outgoing stack of kfunc calls Yonghong Song
2026-09-04  5:25   ` sashiko-bot
2026-09-08  4:26     ` Yonghong Song
2026-09-04  5:10 ` [PATCH bpf-next 07/12] bpf, x86: Place kfunc arguments per the SysV calling convention Yonghong Song
2026-09-04  5:36   ` sashiko-bot
2026-09-08  4:27     ` Yonghong Song
2026-09-04 23:58   ` Alexei Starovoitov
2026-09-06 20:15     ` Yonghong Song
2026-09-08  4:33       ` Alexei Starovoitov
2026-09-08  5:02         ` Yonghong Song
2026-09-08  5:10           ` Yonghong Song
2026-09-08 15:24           ` Alexei Starovoitov
2026-09-08 18:43             ` Yonghong Song
2026-09-09  1:59               ` Alexei Starovoitov [this message]
2026-09-04  5:10 ` [PATCH bpf-next 08/12] bpf: Record a 16-byte argument alignment in the function model Yonghong Song
2026-09-04  6:09   ` bot+bpf-ci
2026-09-08  4:28     ` Yonghong Song
2026-09-04  5:10 ` [PATCH bpf-next 09/12] bpf, arm64: Place kfunc arguments per AAPCS64 Yonghong Song
2026-09-04  6:09   ` bot+bpf-ci
2026-09-04  5:10 ` [PATCH bpf-next 10/12] selftests/bpf: Add C tests for by-value arguments up to 16 bytes Yonghong Song
2026-09-04  5:19   ` sashiko-bot
2026-09-08  4:33     ` Yonghong Song
2026-09-04  6:09   ` bot+bpf-ci
2026-09-08  4:34     ` Yonghong Song
2026-09-04  5:10 ` [PATCH bpf-next 11/12] selftests/bpf: Add inline-asm tests for by-value arguments Yonghong Song
2026-09-04  6:09   ` bot+bpf-ci
2026-09-08  4:35     ` Yonghong Song
2026-09-04  5:11 ` [PATCH bpf-next 12/12] selftests/bpf: Add tests for by-value kfunc arguments 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=DLAEX3NMK5GW.C82FXVYWQTMB@gmail.com \
    --to=alexei.starovoitov@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=kernel-team@fb.com \
    --cc=yonghong.song@linux.dev \
    /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.