Re: [PATCH bpf-next v4 07/13] bpf, x86: Convert struct_ops arena arguments in the trampoline

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]>
> 
> Implement the struct_ops arena argument conversion on x86. save_args()
> receives the arena base from bpf_tramp_arena_base() and consults the
> btf_func_model argument flags as it copies each native argument into the
> BPF ctx, routing a marked argument through RAX:
> 
>   movl %esrc, %eax      /* truncate and clear the upper 32 bits */
>   subl $base_lo, %eax
>   movq %rax, ctx_slot
> 
> A nullable argument tests the full 64-bit kernel pointer first:
> 
>   movq  %rsrc, %rax
>   testq %rax, %rax
>   jz    1f
>   subl  $base_lo, %eax
> 1:
>   movq  %rax, ctx_slot
> 
> The 32-bit subtraction is sufficient since (u32)(kaddr - base) ==
> (u32)kaddr - (u32)base, and it clears the upper half as the JITs require
> of arena pointer registers. Stack-passed arguments already reload
> through RAX, so only the subtraction (and the NULL test) is inserted
> there.
> 
> Keeping arena and nullable classification in btf_func_model avoids a
> parallel trampoline slot bitmap. bpf_tramp_arena_base() returns a base
> only for a single-program struct_ops indirect trampoline; other
> trampolines pass zero and perform no conversion. The size probe reruns
> the same emission with the same model and nodes, so the image size
> matches by construction.
> 
> With both the kfunc and struct_ops directions implemented, flip
> bpf_jit_supports_arena_args() on for x86.
> 
> Signed-off-by: Tejun Heo <[email protected]>
> Signed-off-by: Kumar Kartikeya Dwivedi <[email protected]>
> ---

[But please fix the botched squash discussed earlier]

Acked-by: Eduard Zingerman <[email protected]>

...
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.