Re: [PATCH bpf-next v4 04/13] bpf: Support __arena and __arena__nullable kfunc argument suffixes
Eduard Zingerman <[email protected]>
| Newsgroups | org.kernel.vger.bpf |
|---|---|
| Message-ID | <[email protected]> |
On Wed, 2026-08-05 at 23:04 +0200, Kumar Kartikeya Dwivedi wrote: > From: Tejun Heo <[email protected]> > > 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. > > This patch adds the verifier side: the suffixes are recognized in > check_kfunc_args() and distilled into argument flags in the function > model stored in the kfunc descriptor. JITs retrieve the model while > emitting the call, avoiding per-call state in insn_aux_data. > > JITs declare support with bpf_jit_supports_arena_args() and verification > fails with -ENOTSUPP elsewhere. > > Signed-off-by: Tejun Heo <[email protected]> > Co-developed-by: Kumar Kartikeya Dwivedi <[email protected]> > Signed-off-by: Kumar Kartikeya Dwivedi <[email protected]> > --- Acked-by: Eduard Zingerman <[email protected]>