From: Eduard Zingerman <eddyz87@gmail.com>
To: Kumar Kartikeya Dwivedi <memxor@gmail.com>, bpf@vger.kernel.org
Cc: 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 v1 3/9] bpf, x86: JIT __arena kfunc argument rebasing
Date: Fri, 17 Jul 2026 18:33:23 -0700 [thread overview]
Message-ID: <bbf82d80eb0dc307d09a6c7cc33c23063a55a90f.camel@gmail.com> (raw)
In-Reply-To: <20260715220052.1590783-4-memxor@gmail.com>
On Thu, 2026-07-16 at 00:00 +0200, Kumar Kartikeya Dwivedi wrote:
> From: Tejun Heo <tj@kernel.org>
>
> Implement arena argument rebasing for kfunc calls on x86. R12 already
> holds kern_vm_start whenever the prog has an arena, so each tagged
> argument costs two instructions emitted right before the call:
>
> movl %eN, %eN /* truncate, clear the upper 32 bits */
> addq %r12, %rN
>
> A nullable argument tests the truncated value and jumps over the add:
>
> movl %eN, %eN
> testl %eN, %eN
> jz 1f
> addq %r12, %rN
> 1:
>
> addq carries a REX prefix for every argument register and is always
> three bytes, so the jz displacement is constant. The sequence is native
> code generated after constant blinding has run on the BPF instruction
> stream, so blinding never sees the rebase and needs no special handling.
>
> bpf_jit_supports_arena_args() is not flipped yet; that happens when the
> struct_ops trampoline side is in place as well.
>
> Signed-off-by: Tejun Heo <tj@kernel.org>
> Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
> ---
> arch/x86/net/bpf_jit_comp.c | 49 +++++++++++++++++++++++++++++++++++++
> 1 file changed, 49 insertions(+)
Hi Kumar, Tejun,
Sorry for the delayed response.
I'd like to push back on the JIT based approach.
As far as I understand, it saves a 64-immediate move per callsite,
for jits that have dedicated arena registers (all but s390),
but it puts implementation burden on each jit.
There is an easy workaround regarding 64-immediate move:
use R0 as in the original patch-set by default,
add a jit_has_dedicated_arena_register() predicate +
and encoding to address this register from __internal__
bpf instruction, say BPF_REG_12.
I'd prefer to keep the bulk of the implementation in one place instead
of verifier.c + 6 jits.
===
Tangential to this, I think that __arena vs __arena_nullable is a footgun.
Is it really so performance critical to avoid this null check?
===
On more tangential, these flags would represent a third way to encode
arena arguments we already have:
- KF_ARENA_ARG{1,2} for kfuncs
- ARG_TAG_ARENA for global functions.
Any ideas on how to unify these?
next prev parent reply other threads:[~2026-07-18 1:33 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-15 22:00 [PATCH bpf-next v1 0/9] Add arena argument support to kfuncs and struct_ops Kumar Kartikeya Dwivedi
2026-07-15 22:00 ` [PATCH bpf-next v1 1/9] bpf: Support __arena and __arena_nullable kfunc argument suffixes Kumar Kartikeya Dwivedi
2026-07-15 23:05 ` bot+bpf-ci
2026-07-16 11:31 ` Kumar Kartikeya Dwivedi
2026-07-15 22:00 ` [PATCH bpf-next v1 2/9] bpf: Support __arena and __arena_nullable on struct_ops stub arguments Kumar Kartikeya Dwivedi
2026-07-15 22:22 ` sashiko-bot
2026-07-15 22:00 ` [PATCH bpf-next v1 3/9] bpf, x86: JIT __arena kfunc argument rebasing Kumar Kartikeya Dwivedi
2026-07-18 1:33 ` Eduard Zingerman [this message]
2026-07-18 7:16 ` Kumar Kartikeya Dwivedi
2026-07-15 22:00 ` [PATCH bpf-next v1 4/9] bpf, x86: Convert struct_ops arena arguments in the trampoline Kumar Kartikeya Dwivedi
2026-07-15 22:00 ` [PATCH bpf-next v1 5/9] selftests/bpf: Add kfunc __arena and __arena_nullable argument tests Kumar Kartikeya Dwivedi
2026-07-15 22:00 ` [PATCH bpf-next v1 6/9] selftests/bpf: Add JIT-sequence tests for __arena kfunc arguments Kumar Kartikeya Dwivedi
2026-07-15 22:00 ` [PATCH bpf-next v1 7/9] selftests/bpf: Add struct_ops __arena and __arena_nullable argument tests Kumar Kartikeya Dwivedi
2026-07-15 22:00 ` [PATCH bpf-next v1 8/9] bpf, x86: Fix stack-passed arguments for indirect trampolines Kumar Kartikeya Dwivedi
2026-07-15 22:14 ` sashiko-bot
2026-07-16 11:32 ` Kumar Kartikeya Dwivedi
2026-07-15 22:51 ` bot+bpf-ci
2026-07-15 22:00 ` [PATCH bpf-next v1 9/9] selftests/bpf: Test stack-passed struct_ops arena arguments Kumar Kartikeya Dwivedi
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=bbf82d80eb0dc307d09a6c7cc33c23063a55a90f.camel@gmail.com \
--to=eddyz87@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=emil@etsalapatis.com \
--cc=kernel-team@meta.com \
--cc=kkd@meta.com \
--cc=memxor@gmail.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