From: "Kumar Kartikeya Dwivedi" <memxor@gmail.com>
To: <bot+bpf-ci@kernel.org>, <bpf@vger.kernel.org>
Cc: <tj@kernel.org>, <ast@kernel.org>, <andrii@kernel.org>,
<daniel@iogearbox.net>, <eddyz87@gmail.com>,
<emil@etsalapatis.com>, <kkd@meta.com>, <kernel-team@meta.com>,
<martin.lau@kernel.org>, <yonghong.song@linux.dev>,
<clm@meta.com>, <ihor.solodrai@linux.dev>
Subject: Re: [PATCH bpf-next v2 3/9] bpf, x86: JIT __arena kfunc argument rebasing
Date: Sun, 26 Jul 2026 04:25:31 +0200 [thread overview]
Message-ID: <DK85AK3KBMGT.26YEC0E62HKCO@gmail.com> (raw)
In-Reply-To: <22f76e29c963794d5650486124e295ffc275c5e548dfc7fbae022f24c9d5d1ad@mail.kernel.org>
On Sun Jul 26, 2026 at 4:22 AM CEST, bot+bpf-ci wrote:
>> diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
>> index b2feec81e231..08013c2fcfaa 100644
>> --- a/arch/x86/net/bpf_jit_comp.c
>> +++ b/arch/x86/net/bpf_jit_comp.c
>> @@ -1678,6 +1678,50 @@ static int emit_spectre_bhb_barrier(u8 **pprog, u8 *ip,
>> return 0;
>> }
>>
>> +/*
>> + * Rebase the __arena args of a kfunc call to arena kernel addresses,
>> + * rN = kern_vm_start + (u32)rN, with R12 holding kern_vm_start. A nullable
>> + * arg preserves NULL by skipping the add, tested on the truncated value as
>> + * arena NULL is offset 0. Return the number of emitted bytes.
>> + */
>> +static int emit_kfunc_arena_args(struct bpf_prog *bpf_prog,
>> + const struct bpf_insn *insn, u8 **pprog)
>> +{
>> + const struct btf_func_model *fm;
>> + u8 *prog = *pprog;
>> + u8 *start = prog;
>> + int i;
>> +
>> + fm = bpf_jit_find_kfunc_model(bpf_prog, insn);
>> + if (!fm)
>> + return -EINVAL;
>> +
>> + for (i = 0; i < min_t(int, fm->nr_args, MAX_BPF_FUNC_REG_ARGS); i++) {
>> + u8 flags = fm->arg_flags[i];
>> + u32 reg = BPF_REG_1 + i;
>> +
>> + if (!(flags & BTF_FMODEL_ARENA_ARG))
>> + continue;
>> + if (WARN_ON_ONCE(!bpf_prog->aux->arena))
>> + return -EINVAL;
>> +
>> + /* mov eN, eN: truncate and clear the upper 32 bits */
>> + emit_mov_reg(&prog, false, reg, reg);
>> + if (flags & BTF_FMODEL_NULLABLE_ARG) {
>> + /* test eN, eN; jz over the 3-byte add */
>> + maybe_emit_mod(&prog, reg, reg, false);
>> + EMIT2(0x85, add_2reg(0xC0, reg, reg));
>> + EMIT2(X86_JE, 3);
>> + }
>> + /* add rN, r12 */
>> + maybe_emit_mod(&prog, reg, X86_REG_R12, true);
>> + EMIT2(0x01, add_2reg(0xC0, reg, X86_REG_R12));
>> + }
>> +
>> + *pprog = prog;
>> + return prog - start;
>> +}
>
> In v1 review, Eduard Zingerman raised a concern about the JIT-based
> implementation approach, suggesting that it spreads complexity across
> multiple JITs (verifier.c + 6 jits) instead of keeping the bulk of the
> implementation in one place. He proposed an alternative using R0 by default
> with a jit_has_dedicated_arena_register() predicate to avoid the
> 64-immediate move overhead while centralizing the logic in verifier.c.
>
> Kumar responded that while this approach is reasonable for kfuncs, struct_ops
> would require uglier code with reloading/translating/storing. The v2 patch
> retained the JIT-based approach.
>
Yes, it was discussed offlist, we'll move ahead with JIT-based approach.
> [...]
next prev parent reply other threads:[~2026-07-26 2:25 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-26 1:30 [PATCH bpf-next v2 0/9] Add arena argument support to kfuncs and struct_ops Kumar Kartikeya Dwivedi
2026-07-26 1:30 ` [PATCH bpf-next v2 1/9] bpf: Support __arena and __arena_nullable kfunc argument suffixes Kumar Kartikeya Dwivedi
2026-07-26 1:47 ` sashiko-bot
2026-07-26 2:01 ` Kumar Kartikeya Dwivedi
2026-07-26 1:30 ` [PATCH bpf-next v2 2/9] bpf: Support __arena and __arena_nullable on struct_ops arguments Kumar Kartikeya Dwivedi
2026-07-26 1:30 ` [PATCH bpf-next v2 3/9] bpf, x86: JIT __arena kfunc argument rebasing Kumar Kartikeya Dwivedi
2026-07-26 2:22 ` bot+bpf-ci
2026-07-26 2:25 ` Kumar Kartikeya Dwivedi [this message]
2026-07-26 1:30 ` [PATCH bpf-next v2 4/9] bpf, x86: Convert struct_ops arena arguments in the trampoline Kumar Kartikeya Dwivedi
2026-07-26 1:30 ` [PATCH bpf-next v2 5/9] selftests/bpf: Add kfunc __arena and __arena_nullable argument tests Kumar Kartikeya Dwivedi
2026-07-26 1:41 ` sashiko-bot
2026-07-26 2:02 ` Kumar Kartikeya Dwivedi
2026-07-26 1:30 ` [PATCH bpf-next v2 6/9] selftests/bpf: Add JIT-sequence tests for __arena kfunc arguments Kumar Kartikeya Dwivedi
2026-07-26 1:44 ` sashiko-bot
2026-07-26 1:31 ` [PATCH bpf-next v2 7/9] selftests/bpf: Add struct_ops __arena and __arena_nullable argument tests Kumar Kartikeya Dwivedi
2026-07-26 1:31 ` [PATCH bpf-next v2 8/9] bpf, x86: Fix stack-passed arguments for indirect trampolines Kumar Kartikeya Dwivedi
2026-07-26 1:51 ` sashiko-bot
2026-07-26 2:05 ` Kumar Kartikeya Dwivedi
2026-07-26 1:31 ` [PATCH bpf-next v2 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=DK85AK3KBMGT.26YEC0E62HKCO@gmail.com \
--to=memxor@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bot+bpf-ci@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=clm@meta.com \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=emil@etsalapatis.com \
--cc=ihor.solodrai@linux.dev \
--cc=kernel-team@meta.com \
--cc=kkd@meta.com \
--cc=martin.lau@kernel.org \
--cc=tj@kernel.org \
--cc=yonghong.song@linux.dev \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.