From: Yonghong Song <yonghong.song@linux.dev>
To: bot+bpf-ci@kernel.org, bpf@vger.kernel.org
Cc: ast@kernel.org, andrii@kernel.org, daniel@iogearbox.net,
eddyz87@gmail.com, kernel-team@fb.com, martin.lau@kernel.org,
mason@kernel.org, ihor.solodrai@linux.dev
Subject: Re: [PATCH bpf-next v2 03/12] bpf: Support by-value struct arguments up to 16 bytes
Date: Thu, 10 Sep 2026 21:29:25 -0700 [thread overview]
Message-ID: <ccb524ec-1438-4c31-90d5-c01c37b0e858@linux.dev> (raw)
In-Reply-To: <0a9ac5bad4c131e896916f00fe93d4d7c6accef6711d1ee477969a8a7d330ae9@mail.kernel.org>
On 9/9/26 12:13 AM, bot+bpf-ci@kernel.org wrote:
>> diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
>> index 104a91f5ffd5..4502b888b668 100644
>> --- a/kernel/bpf/btf.c
>> +++ b/kernel/bpf/btf.c
>> @@ -8125,6 +8125,9 @@ int btf_prepare_func_args(struct bpf_verifier_env *env, int subprog)
>> for (i = 0, slots_used = 0; i < nargs; i++) {
>> u32 tags = 0;
>>
>> + if (slots_used >= MAX_BPF_FUNC_ARGS)
>> + goto too_many_slots;
>> +
>> err = btf_scan_decl_tags(env, btf, fn_t, i, is_global, &tags);
>> if (err)
>> return err;
> [ ... ]
>
>> @@ -8253,6 +8256,33 @@ int btf_prepare_func_args(struct bpf_verifier_env *env, int subprog)
>> sub->args[slots_used++].arg_type = ARG_ANYTHING;
>> continue;
>> }
>> + if (btf_type_is_struct(t)) {
>> + u32 nslots;
>> +
>> + if (!t->size || t->size > 2 * BPF_REG_SIZE) {
>> + if (!is_global)
>> + return -EINVAL;
>> + bpf_log(log,
>> + "Arg#%d type %s in %s() has size %u, only 1 to %d bytes "
>> + "can be passed by value\n",
>> + i, btf_type_str(t), tname, t->size, 2 * BPF_REG_SIZE);
>> + return -EINVAL;
>> + }
>> + if (!btf_struct_is_composed_of(env, btf, t, BTF_MEMBER_SCALAR)) {
>> + if (!is_global)
>> + return -EINVAL;
>> + bpf_log(log, "Arg#%d type %s in %s() is not composed of scalars\n",
>> + i, btf_type_str(t), tname);
>> + return -EINVAL;
>> + }
>> +
>> + nslots = (t->size + BPF_REG_SIZE - 1) / BPF_REG_SIZE;
>> + if (slots_used + nslots > MAX_BPF_FUNC_ARGS)
>> + goto too_many_slots;
>> + while (nslots--)
>> + sub->args[slots_used++].arg_type = ARG_ANYTHING;
>> + continue;
>> + }
>> if (!is_global)
>> return -EINVAL;
>> bpf_log(log, "Arg#%d type %s in %s() is not supported yet.\n",
>> @@ -8260,11 +8290,33 @@ int btf_prepare_func_args(struct bpf_verifier_env *env, int subprog)
>> return -EINVAL;
>> }
>>
>> + if (slots_used > MAX_BPF_FUNC_REG_ARGS) {
>> + if (is_global) {
>> + bpf_log(log,
>> + "global function %s() needs %d > %d argument slots, "
>> + "stack args not supported\n",
>> + tname, slots_used, MAX_BPF_FUNC_REG_ARGS);
>> + return -EINVAL;
>> + }
>> + if (!bpf_jit_supports_stack_args()) {
>> + bpf_log(log, "JIT does not support function %s() with %d argument slots\n",
>> + tname, slots_used);
>> + return -EFAULT;
>> + }
>> + sub->stack_arg_cnt = slots_used - MAX_BPF_FUNC_REG_ARGS;
>> + }
>> sub->arg_cnt = slots_used;
> This isn't a bug, but now that slots_used is always >= nargs, is the
> pre-loop nargs-based block still needed? Looking earlier in the function:
>
> if (nargs > MAX_BPF_FUNC_REG_ARGS) {
> if (!bpf_jit_supports_stack_args()) {
> bpf_log(log, "JIT does not support function %s() with %d args\n",
> tname, nargs);
> return -EFAULT;
> }
> sub->stack_arg_cnt = nargs - MAX_BPF_FUNC_REG_ARGS;
> }
>
> if (is_global && nargs > MAX_BPF_FUNC_REG_ARGS) {
> bpf_log(log, "global function %s has %d > %d args, stack args not supported\n",
> tname, nargs, MAX_BPF_FUNC_REG_ARGS);
> return -EINVAL;
> }
>
> The new block above recomputes stack_arg_cnt from slots_used. Since every
> parameter consumes at least one slot, whenever nargs > MAX_BPF_FUNC_REG_ARGS,
> slots_used > MAX_BPF_FUNC_REG_ARGS as well, so the assignment
> `sub->stack_arg_cnt = nargs - MAX_BPF_FUNC_REG_ARGS` in the earlier block
> is always overwritten by the new `sub->stack_arg_cnt = slots_used -
> MAX_BPF_FUNC_REG_ARGS` assignment.
>
> Also, the two blocks order their tests differently. The earlier block tests
> bpf_jit_supports_stack_args() before is_global, while the new block tests
> is_global first. On an architecture without stack-arg JIT support, a global
> function needing stack args therefore fails with -EFAULT and "JIT does not
> support function f() with 6 args" when the sixth slot comes from a sixth
> parameter, but with -EINVAL and "global function f() needs 6 > 5 argument
> slots, stack args not supported" when it comes from a two-slot struct.
>
> Could this new block be the only place that sets stack_arg_cnt and applies
> the global/JIT checks, or does the earlier nargs-based block serve a
> purpose I'm missing?
As you mentioned, actually we do have some issues. The above nargs and is_global
chcking is before going through all arguments. So they works. But we should
check again after all arguments processing since some arguments may have
two registers.
>
>
> ---
> AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
> See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md
>
> CI run summary: https://github.com/kernel-patches/bpf/actions/runs/34320399441
next prev parent reply other threads:[~2026-09-11 4:29 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-09 6:25 [PATCH bpf-next v2 00/12] bpf: Support by-value struct and __int128 arguments Yonghong Song
2026-09-09 6:25 ` [PATCH bpf-next v2 01/12] selftests/bpf: Add a test for an __int128 by-value argument Yonghong Song
2026-09-09 7:13 ` bot+bpf-ci
2026-09-11 4:25 ` Yonghong Song
2026-09-09 6:25 ` [PATCH bpf-next v2 02/12] bpf: Index global function arguments by argument slot Yonghong Song
2026-09-09 7:13 ` bot+bpf-ci
2026-09-11 4:27 ` Yonghong Song
2026-09-09 6:25 ` [PATCH bpf-next v2 03/12] bpf: Support by-value struct arguments up to 16 bytes Yonghong Song
2026-09-09 7:13 ` bot+bpf-ci
2026-09-11 4:29 ` Yonghong Song [this message]
2026-09-09 6:25 ` [PATCH bpf-next v2 04/12] bpf: Support __int128 as a by-value function argument Yonghong Song
2026-09-09 6:25 ` [PATCH bpf-next v2 05/12] bpf: Rename bpf_call_summary::num_params to arg_slot_cnt Yonghong Song
2026-09-09 6:25 ` [PATCH bpf-next v2 06/12] bpf: Recognize by-value struct and __int128 kfunc arguments Yonghong Song
2026-09-09 6:46 ` sashiko-bot
2026-09-11 4:31 ` Yonghong Song
2026-09-09 6:25 ` [PATCH bpf-next v2 07/12] bpf: Prepare kfunc arguments for the JIT from an ABI description Yonghong Song
2026-09-09 6:46 ` sashiko-bot
2026-09-11 5:05 ` Yonghong Song
2026-09-09 6:26 ` [PATCH bpf-next v2 08/12] bpf, x86: Move kfunc arguments into the x86-64 calling convention Yonghong Song
2026-09-09 7:29 ` bot+bpf-ci
2026-09-11 5:32 ` Yonghong Song
2026-09-09 6:26 ` [PATCH bpf-next v2 09/12] bpf, arm64: Move kfunc arguments into the arm64 " Yonghong Song
2026-09-09 7:30 ` bot+bpf-ci
2026-09-11 5:34 ` Yonghong Song
2026-09-09 6:26 ` [PATCH bpf-next v2 10/12] selftests/bpf: Add C tests for by-value arguments up to 16 bytes Yonghong Song
2026-09-09 6:26 ` [PATCH bpf-next v2 11/12] selftests/bpf: Add inline-asm tests for by-value arguments Yonghong Song
2026-09-09 7:30 ` bot+bpf-ci
2026-09-11 5:37 ` Yonghong Song
2026-09-09 6:26 ` [PATCH bpf-next v2 12/12] selftests/bpf: Add tests for by-value kfunc arguments Yonghong Song
2026-09-09 7:30 ` bot+bpf-ci
2026-09-11 5:57 ` 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=ccb524ec-1438-4c31-90d5-c01c37b0e858@linux.dev \
--to=yonghong.song@linux.dev \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bot+bpf-ci@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=ihor.solodrai@linux.dev \
--cc=kernel-team@fb.com \
--cc=martin.lau@kernel.org \
--cc=mason@kernel.org \
/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