From: "Kumar Kartikeya Dwivedi" <memxor@gmail.com>
To: "Amery Hung" <ameryhung@gmail.com>,
"Eduard Zingerman" <eddyz87@gmail.com>
Cc: <bpf@vger.kernel.org>, "Tejun Heo" <tj@kernel.org>,
"Alexei Starovoitov" <ast@kernel.org>,
"Andrii Nakryiko" <andrii@kernel.org>,
"Daniel Borkmann" <daniel@iogearbox.net>,
"Emil Tsalapatis" <emil@etsalapatis.com>, <kkd@meta.com>,
<kernel-team@meta.com>
Subject: Re: [PATCH bpf-next v3 2/9] bpf: Support __arena and __arena_nullable on struct_ops arguments
Date: Wed, 05 Aug 2026 19:36:22 +0200 [thread overview]
Message-ID: <DKH6XESU7740.UUEKH0WNCM29@gmail.com> (raw)
In-Reply-To: <CAMB2axP4Wjmm45r4ku=D3ZRRy1JiEBfkLr5R7NJRD0Ca3w8UpQ@mail.gmail.com>
On Wed Aug 5, 2026 at 7:31 PM CEST, Amery Hung wrote:
> On Tue, Aug 4, 2026 at 10:14 PM Eduard Zingerman <eddyz87@gmail.com> wrote:
>>
>> On Tue, 2026-08-04 at 16:55 -0700, Eduard Zingerman wrote:
>> > On Mon, 2026-08-03 at 14:51 +0200, Kumar Kartikeya Dwivedi wrote:
>> >
>> > Lgtm except for several nits below.
>> >
>> > ...
>> >
>> > > diff --git a/kernel/bpf/bpf_struct_ops.c b/kernel/bpf/bpf_struct_ops.c
>> >
>> > ...
>> >
>> > > @@ -226,26 +229,30 @@ static int prepare_arg_info(struct btf *btf,
>> > > info = info_buf;
>> > > for (arg_no = 0; arg_no < nargs; arg_no++) {
>> > > /* Skip arguments that is not suffixed with
>> > > - * "__nullable or __ref".
>> > > + * "__nullable", "__ref", "__arena" or "__arena_nullable".
>> > > */
>> > > is_nullable = btf_param_match_suffix(btf, &stub_args[arg_no],
>> > > MAYBE_NULL_SUFFIX);
>> > > is_refcounted = btf_param_match_suffix(btf, &stub_args[arg_no],
>> > > REFCOUNTED_SUFFIX);
>> > > + is_arena_nullable = btf_param_match_suffix(btf, &stub_args[arg_no],
>> > > + ARENA_MAYBE_NULL_SUFFIX);
>> > > + is_arena = btf_param_match_suffix(btf, &stub_args[arg_no], ARENA_SUFFIX);
>> > >
>> > > if (is_nullable)
>> > > suffix = MAYBE_NULL_SUFFIX;
>> > > else if (is_refcounted)
>> > > suffix = REFCOUNTED_SUFFIX;
>> > > + else if (is_arena_nullable)
>> > > + suffix = ARENA_MAYBE_NULL_SUFFIX;
>> > > + else if (is_arena)
>> > > + suffix = ARENA_SUFFIX;
>> >
>> > As discussed already, that's unfortunate that p__arena and p__nullable
>> > are valid, but p__arena__nullable is not, substituted by
>> > p__arena_nullable. Same goes for global subprogs.
>> >
>> > > else
>> > > continue;
>> > >
>> > > - /* Should be a pointer to struct */
>> > > - pointed_type = btf_type_resolve_ptr(btf,
>> > > - args[arg_no].type,
>> > > - &arg_btf_id);
>> > > - if (!pointed_type ||
>> > > - !btf_type_is_struct(pointed_type)) {
>> > > + /* Should be a pointer to struct, or any pointer for __arena/__arena_nullable */
>> > > + pointed_type = btf_type_resolve_ptr(btf, args[arg_no].type, &arg_btf_id);
>> > > + if (!pointed_type || (!is_arena && !is_arena_nullable && !btf_type_is_struct(pointed_type))) {
>> > > pr_warn("stub function %s has %s tagging to an unsupported type\n",
>> > > stub_fname, suffix);
>> > > goto err_out;
>> >
>> > ...
>> >
>> > > diff --git a/kernel/bpf/trampoline.c b/kernel/bpf/trampoline.c
>> > > index ed7999ad6c66..d2d7a2904345 100644
>> > > --- a/kernel/bpf/trampoline.c
>> > > +++ b/kernel/bpf/trampoline.c
>> >
>> > ...
>> >
>> > > @@ -695,6 +743,22 @@ static int bpf_trampoline_update(struct bpf_trampoline *tr, bool lock_direct_mut
>> > > goto out;
>> > > }
>> > >
>> > > + /*
>> > > + * Arena ctx args are converted only by the struct_ops indirect
>> > > + * trampoline, which dispatches to a single known prog. Generic
>> > > + * trampolines can mix progs with different arenas, so no conversion
>> > > + * is possible here. Not reachable today: only struct_ops progs get
>> > > + * arena ctx args and they never ride generic trampolines.
>> > > + */
>> > > + for (kind = 0; kind < BPF_TRAMP_MAX; kind++) {
>> > > + for (i = 0; i < tnodes[kind].nr_nodes; i++) {
>> > > + if (bpf_prog_has_arena_ctx_arg(tnodes[kind].nodes[i]->link->prog)) {
>> > > + err = -ENOTSUPP;
>> > > + goto out;
>> > > + }
>> > > + }
>> > > + }
>> >
>> > Nit: should this be done in __bpf_trampoline_link_prog() or
>> > bpf_trampoline_add_prog()? To avoid doing the same check on unlink.
>> > Since this is an invariant violation, do we want to add WARN_ONCE?
>> >
>> > > +
>> > > /* clear all bits except SHARE_IPMODIFY and TAIL_CALL_CTX */
>> > > tr->flags &= (BPF_TRAMP_F_SHARE_IPMODIFY | BPF_TRAMP_F_TAIL_CALL_CTX);
>> > >
>> >
>> > ...
>>
>> Thinking a bit more about this. Since kfuncs already use flags in
>> btf_func_model, I think it would be nice to use them for struct_ops as
>> well. E.g. as in the patch attached (applied on top of this series).
>> Wdyt?
>
> I like that it relies on existing annotations instead of yet another
> auxiliary field.
>
> The mapping for arena args to different function models can be confusing though.
>
> For the verfication purpose: both __arena and __arena_nullable maps to
> KF_ARG_PTR_TO_ARENA | PTR_MAYBE_NULL.
> For the JIT purpose: __arena maps to BTF_FMODEL_ARENA_ARG;
> __arena_nullable maps to BTF_FMODEL_ARENA_ARG |
> BTF_FMODEL_NULLABLE_ARG.
>
> It might deserve a brief inline comment in get_kfunc_arg_type() saying
> why both tags map to KF_ARG_PTR_TO_ARENA | PTR_MAYBE_NULL.
Yeah I will add comments for this. I adopted Eduard's diff (w/ his SoB) on top
of the stack.
next prev parent reply other threads:[~2026-08-05 17:36 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-03 12:51 [PATCH bpf-next v3 0/9] Add arena argument support to kfuncs and struct_ops Kumar Kartikeya Dwivedi
2026-08-03 12:51 ` [PATCH bpf-next v3 1/9] bpf: Support __arena and __arena_nullable kfunc argument suffixes Kumar Kartikeya Dwivedi
2026-08-03 13:19 ` sashiko-bot
2026-08-04 17:42 ` Amery Hung
2026-08-05 15:53 ` Kumar Kartikeya Dwivedi
2026-08-05 17:07 ` Amery Hung
2026-08-05 17:16 ` Kumar Kartikeya Dwivedi
2026-08-05 15:55 ` Kumar Kartikeya Dwivedi
2026-08-03 12:51 ` [PATCH bpf-next v3 2/9] bpf: Support __arena and __arena_nullable on struct_ops arguments Kumar Kartikeya Dwivedi
2026-08-03 14:19 ` sashiko-bot
2026-08-04 23:55 ` Eduard Zingerman
2026-08-05 5:14 ` Eduard Zingerman
2026-08-05 17:31 ` Amery Hung
2026-08-05 17:36 ` Kumar Kartikeya Dwivedi [this message]
2026-08-03 12:51 ` [PATCH bpf-next v3 3/9] bpf, x86: JIT __arena kfunc argument rebasing Kumar Kartikeya Dwivedi
2026-08-05 0:40 ` Eduard Zingerman
2026-08-03 12:51 ` [PATCH bpf-next v3 4/9] bpf, x86: Convert struct_ops arena arguments in the trampoline Kumar Kartikeya Dwivedi
2026-08-03 12:51 ` [PATCH bpf-next v3 5/9] selftests/bpf: Add kfunc __arena and __arena_nullable argument tests Kumar Kartikeya Dwivedi
2026-08-03 13:35 ` sashiko-bot
2026-08-04 20:01 ` Eduard Zingerman
2026-08-04 20:14 ` Kumar Kartikeya Dwivedi
2026-08-04 20:24 ` Eduard Zingerman
2026-08-04 20:26 ` Eduard Zingerman
2026-08-04 20:28 ` Kumar Kartikeya Dwivedi
2026-08-04 20:33 ` Eduard Zingerman
2026-08-04 20:36 ` Eduard Zingerman
2026-08-03 12:51 ` [PATCH bpf-next v3 6/9] selftests/bpf: Add JIT-sequence tests for __arena kfunc arguments Kumar Kartikeya Dwivedi
2026-08-03 13:35 ` sashiko-bot
2026-08-05 5:43 ` Eduard Zingerman
2026-08-03 12:51 ` [PATCH bpf-next v3 7/9] selftests/bpf: Add struct_ops __arena and __arena_nullable argument tests Kumar Kartikeya Dwivedi
2026-08-03 13:39 ` sashiko-bot
2026-08-05 6:52 ` Eduard Zingerman
2026-08-03 12:51 ` [PATCH bpf-next v3 8/9] bpf, x86: Fix stack-passed arguments for indirect trampolines Kumar Kartikeya Dwivedi
2026-08-03 13:42 ` sashiko-bot
2026-08-05 8:00 ` Eduard Zingerman
2026-08-03 12:51 ` [PATCH bpf-next v3 9/9] selftests/bpf: Test stack-passed struct_ops arena arguments Kumar Kartikeya Dwivedi
2026-08-05 8:00 ` Eduard Zingerman
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=DKH6XESU7740.UUEKH0WNCM29@gmail.com \
--to=memxor@gmail.com \
--cc=ameryhung@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=emil@etsalapatis.com \
--cc=kernel-team@meta.com \
--cc=kkd@meta.com \
--cc=tj@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