From: "Kumar Kartikeya Dwivedi" <memxor@gmail.com>
To: "Amery Hung" <ameryhung@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>,
"Eduard Zingerman" <eddyz87@gmail.com>,
"Emil Tsalapatis" <emil@etsalapatis.com>, <kkd@meta.com>,
<kernel-team@meta.com>
Subject: Re: [PATCH bpf-next v4 04/13] bpf: Support __arena and __arena__nullable kfunc argument suffixes
Date: Thu, 06 Aug 2026 21:20:47 +0200 [thread overview]
Message-ID: <DKI3RW4DNSJZ.3LPBJ6YJHOTHY@gmail.com> (raw)
In-Reply-To: <CAMB2axOdf7jXcF2+esZqwUVXY407yu7XnkioJXnSU3b0ZsPzUg@mail.gmail.com>
On Thu Aug 6, 2026 at 7:22 PM CEST, Amery Hung wrote:
> On Wed, Aug 5, 2026 at 2:05 PM Kumar Kartikeya Dwivedi <memxor@gmail.com> wrote:
>>
>> From: Tejun Heo <tj@kernel.org>
>>
>> Passing an arena pointer to a kfunc takes two steps today. There is no
>> arena pointer argument type, so the pointer crosses the boundary as a
>> bare scalar, and the kfunc then offsets it by the arena base and casts
>> it before it can touch the memory. Every such kfunc open-codes the same
>> translation.
>>
>> Add the __arena and __arena__nullable argument suffixes to make this more
>> convenient. The kfunc declares the parameter by its real pointer type
>> and dereferences it directly, with the JIT rebasing the value at the
>> call site, rN = kern_vm_start + (u32)rN. No bounds check is needed: the
>> u32 offset stays within the guard-padded arena kernel mapping, and a
>> fault on an unpopulated page recovers through the per-arena scratch
>> page. A suffixed argument accepts a PTR_TO_ARENA or scalar register,
>> matching global subprog arena arguments.
>>
>> __arena rebases unconditionally, so the kfunc never sees NULL and a
>> value with zero in the low 32 bits arrives as the arena base.
>> __arena__nullable preserves NULL for optional arguments by skipping the
>> rebase when the truncated value, arena offset 0, is zero. Keeping the
>> plain form NULL-free saves the NULL test on every call.
>>
>> The double separator makes the annotations composable:
>> __arena__nullable also ends in __nullable. Match the composite suffix
>> first when classifying kfunc arguments and function-model flags so it
>> retains arena semantics while carrying the nullable flag.
>
> Since __arena__nullable will match is_kfunc_arg_arena() case and go
> through JIT + regno check, and get its PTR_MAYBE_NULL anyway. How
> about just keep it as __arena_nullable to simplify the patch?
>
> 1. No need to introudce is_kfunc_arg_arena_nullable() and changes in
> is_kfunc_arg_nullable()
For consistency, would you prefer that I don't manually set | PTR_MAYBE_NULL and
let is_kfunc_arg_nullable() handle that? That would be another way to address
this.
In some sense, __arena includes __nullable for the purposes of type checking, so
it might make sense to add it to the predicate that determines NULL-ness, then
it will acquire PTR_MAYBE_NULL automatically.
We will still drop is_kfunc_arg_arena_nullable() though.
Anyhow, I don't have any strong preference one way or the other, but thought I'd
float this as an alternative since it appears to fit better, and details are
hidden the predicates.
> 2. is_kfunc_arg_arena() returns btf_param_match_suffix(btf, arg,
> "__arena_nullable") || btf_param_match_suffix(btf, arg, "__arena");
>
Yeah, makes sense.
> [...]
>
>> diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
>> index b62e77949542..2b7f6f6bbe76 100644
>> --- a/kernel/bpf/verifier.c
>> +++ b/kernel/bpf/verifier.c
>> @@ -10909,9 +10909,16 @@ static bool is_kfunc_arg_refcounted_kptr(const struct btf *btf, const struct btf
>> return btf_param_match_suffix(btf, arg, "__refcounted_kptr");
>> }
>>
>> +static bool is_kfunc_arg_arena_nullable(const struct btf *btf,
>> + const struct btf_param *arg)
>> +{
>> + return btf_param_match_suffix(btf, arg, "__arena__nullable");
>> +}
>> +
>> static bool is_kfunc_arg_nullable(const struct btf *btf, const struct btf_param *arg)
>> {
>> - return btf_param_match_suffix(btf, arg, "__nullable");
>> + return !is_kfunc_arg_arena_nullable(btf, arg) &&
>> + btf_param_match_suffix(btf, arg, "__nullable");
>> }
>
> No need for the changes above.
>
>>
>> static bool is_kfunc_arg_nonown_allowed(const struct btf *btf, const struct btf_param *arg)
>> @@ -10929,6 +10936,12 @@ static bool is_kfunc_arg_irq_flag(const struct btf *btf, const struct btf_param
>> return btf_param_match_suffix(btf, arg, "__irq_flag");
>> }
>>
>> +static bool is_kfunc_arg_arena(const struct btf *btf, const struct btf_param *arg)
>> +{
>> + return is_kfunc_arg_arena_nullable(btf, arg) ||
>> + btf_param_match_suffix(btf, arg, "__arena");
>
> return btf_param_match_suffix(btf, arg, "__arena_nullable") ||
> btf_param_match_suffix(btf, arg, "__arena");
>
Ack, I'll adjust this bit.
> [...]
next prev parent reply other threads:[~2026-08-06 19:20 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-05 21:04 [PATCH bpf-next v4 00/13] Add arena argument support to kfuncs and struct_ops Kumar Kartikeya Dwivedi
2026-08-05 21:04 ` [PATCH bpf-next v4 01/13] bpf: Rename 'early' BTF checking as a preparation phase Kumar Kartikeya Dwivedi
2026-08-06 16:29 ` Amery Hung
2026-08-05 21:04 ` [PATCH bpf-next v4 02/13] bpf: Split subprogram and kfunc collection Kumar Kartikeya Dwivedi
2026-08-05 21:49 ` bot+bpf-ci
2026-08-06 16:31 ` Amery Hung
2026-08-05 21:04 ` [PATCH bpf-next v4 03/13] bpf: Collect kfuncs after resolving program resources Kumar Kartikeya Dwivedi
2026-08-06 16:37 ` Amery Hung
2026-08-05 21:04 ` [PATCH bpf-next v4 04/13] bpf: Support __arena and __arena__nullable kfunc argument suffixes Kumar Kartikeya Dwivedi
2026-08-06 17:22 ` Amery Hung
2026-08-06 19:20 ` Kumar Kartikeya Dwivedi [this message]
2026-08-06 19:23 ` Kumar Kartikeya Dwivedi
2026-08-06 19:31 ` Amery Hung
2026-08-07 0:51 ` Eduard Zingerman
2026-08-05 21:04 ` [PATCH bpf-next v4 05/13] bpf: Support __arena and __arena__nullable on struct_ops arguments Kumar Kartikeya Dwivedi
2026-08-05 21:18 ` sashiko-bot
2026-08-07 0:51 ` Eduard Zingerman
2026-08-05 21:04 ` [PATCH bpf-next v4 06/13] bpf, x86: JIT __arena kfunc argument rebasing Kumar Kartikeya Dwivedi
2026-08-05 21:04 ` [PATCH bpf-next v4 07/13] bpf, x86: Convert struct_ops arena arguments in the trampoline Kumar Kartikeya Dwivedi
2026-08-07 4:09 ` Eduard Zingerman
2026-08-05 21:04 ` [PATCH bpf-next v4 08/13] selftests/bpf: Add kfunc __arena and __arena__nullable argument tests Kumar Kartikeya Dwivedi
2026-08-07 4:44 ` Eduard Zingerman
2026-08-05 21:04 ` [PATCH bpf-next v4 09/13] selftests/bpf: Add JIT-sequence tests for __arena kfunc arguments Kumar Kartikeya Dwivedi
2026-08-07 4:45 ` Eduard Zingerman
2026-08-05 21:04 ` [PATCH bpf-next v4 10/13] selftests/bpf: Add struct_ops __arena and __arena__nullable argument tests Kumar Kartikeya Dwivedi
2026-08-05 21:15 ` sashiko-bot
2026-08-05 21:04 ` [PATCH bpf-next v4 11/13] bpf, x86: Fix stack-passed arguments for indirect trampolines Kumar Kartikeya Dwivedi
2026-08-05 21:15 ` sashiko-bot
2026-08-05 21:04 ` [PATCH bpf-next v4 12/13] selftests/bpf: Test stack-passed struct_ops arena arguments Kumar Kartikeya Dwivedi
2026-08-05 21:04 ` [PATCH bpf-next v4 13/13] bpf: Reject tracing progs for struct_ops with arena args Kumar Kartikeya Dwivedi
2026-08-05 22:02 ` bot+bpf-ci
2026-08-07 4:51 ` 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=DKI3RW4DNSJZ.3LPBJ6YJHOTHY@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