From: sashiko-bot@kernel.org
To: "Kumar Kartikeya Dwivedi" <memxor@gmail.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next v1 04/14] bpf, riscv: Convert struct_ops arena arguments in the trampoline
Date: Fri, 21 Aug 2026 23:44:33 +0000 [thread overview]
Message-ID: <20260821234433.C85691F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260821233516.3426127-5-memxor@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Unaligned memory access in JIT instruction patching
--
--- Patch [4]: [PATCH bpf-next v1 04/14] bpf, riscv: Convert struct_ops arena arguments in the trampoline ---
commit 0283a3765a698e09bc666805ea8cb746cf58f299
Author: Kumar Kartikeya Dwivedi <memxor@gmail.com>
bpf, riscv: Convert struct_ops arena arguments in the trampoline
This commit converts struct_ops callback arena arguments into the arena pointer
form when copied into the BPF context. It walks the function model by argument,
adjusts the pointers via bpf_tramp_arena_base(), and handles nullable arguments.
> diff --git a/arch/riscv/net/bpf_jit_comp64.c b/arch/riscv/net/bpf_jit_comp64.c
> index c97d13a3eae4e..8db992a285f6a 100644
> --- a/arch/riscv/net/bpf_jit_comp64.c
> +++ b/arch/riscv/net/bpf_jit_comp64.c
[ ... ]
> @@ -888,20 +888,75 @@ int bpf_arch_text_poke(void *ip, enum bpf_text_poke_type old_t,
> return ret;
> }
>
> -static void store_args(int nr_arg_slots, int args_off, int stack_args_off,
> +/*
> + * Convert an arena kernel address into the arena pointer form on its way
> + * into the BPF ctx, dst = (u32)(src - kern_vm_start). A nullable arg
> + * preserves NULL, tested on the full 64-bit kernel pointer. The final
> + * zero-extension makes the stored value satisfy the JIT invariant for arena
> + * pointer registers.
> + */
> +static void emit_arena_arg_conv(u8 dst, u8 src, bool nullable, u8 base,
> + struct rv_jit_context *ctx)
> +{
> + int branch_off = 0;
> +
> + if (nullable) {
> + if (dst != src)
> + emit_mv(dst, src, ctx);
> + branch_off = ctx->ninsns;
> + /* Patched below once the variable-length conversion is emitted. */
> + emit(rv_nop(), ctx);
> + src = dst;
> + }
> +
> + emit_sub(dst, src, base, ctx);
> + emit_zextw(dst, dst, ctx);
> +
> + if (nullable && ctx->insns) {
> + u32 insn = rv_beq(dst, RV_REG_ZERO, ctx->ninsns - branch_off);
> +
> + *(u32 *)(ctx->insns + branch_off) = insn;
[Severity: High]
This is a pre-existing issue, but does this direct 32-bit store cause an
unaligned memory access trap?
If earlier instructions in the JIT context use 16-bit compressed instructions,
ctx->ninsns (and therefore branch_off) becomes an odd number. In that case,
ctx->insns + branch_off points to a 2-byte aligned address, not a 4-byte
aligned one.
On RISC-V hardware that does not support unaligned memory accesses, casting an
unaligned u16 pointer to a u32 pointer and performing a 32-bit store triggers
a CPU exception.
Could this be safely written as two sequential 16-bit writes to avoid the trap?
> + }
> +}
[ ... ]
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260821233516.3426127-1-memxor@gmail.com?part=4
next prev parent reply other threads:[~2026-08-21 23:44 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-21 23:34 [PATCH bpf-next v1 00/14] Retire KF_ARENA_ARG kfunc flags Kumar Kartikeya Dwivedi
2026-08-21 23:34 ` [PATCH bpf-next v1 01/14] bpf: Split arena kfunc and struct_ops JIT capabilities Kumar Kartikeya Dwivedi
2026-08-22 0:46 ` bot+bpf-ci
2026-08-24 22:28 ` Eduard Zingerman
2026-08-24 22:37 ` Kumar Kartikeya Dwivedi
2026-08-26 19:52 ` Ihor Solodrai
2026-08-21 23:34 ` [PATCH bpf-next v1 02/14] bpf, riscv: Fix stack-passed arguments for indirect trampolines Kumar Kartikeya Dwivedi
2026-08-24 6:21 ` Pu Lehui
2026-08-21 23:34 ` [PATCH bpf-next v1 03/14] bpf, riscv: JIT arena kfunc argument rebasing Kumar Kartikeya Dwivedi
2026-08-24 6:36 ` Pu Lehui
2026-08-21 23:34 ` [PATCH bpf-next v1 04/14] bpf, riscv: Convert struct_ops arena arguments in the trampoline Kumar Kartikeya Dwivedi
2026-08-21 23:44 ` sashiko-bot [this message]
2026-08-24 6:38 ` Pu Lehui
2026-08-21 23:34 ` [PATCH bpf-next v1 05/14] bpf, s390: JIT arena kfunc argument rebasing Kumar Kartikeya Dwivedi
2026-08-21 23:35 ` [PATCH bpf-next v1 06/14] bpf, s390: Convert struct_ops arena arguments Kumar Kartikeya Dwivedi
2026-08-22 0:46 ` bot+bpf-ci
2026-08-21 23:35 ` [PATCH bpf-next v1 07/14] bpf, loongarch: Fix stack arguments for indirect trampolines Kumar Kartikeya Dwivedi
2026-08-22 0:46 ` bot+bpf-ci
2026-08-28 4:33 ` Tiezhu Yang
2026-08-28 4:55 ` Kumar Kartikeya Dwivedi
2026-08-28 8:19 ` Tiezhu Yang
2026-08-21 23:35 ` [PATCH bpf-next v1 08/14] bpf, loongarch: JIT arena kfunc argument rebasing Kumar Kartikeya Dwivedi
2026-08-21 23:46 ` sashiko-bot
2026-08-21 23:35 ` [PATCH bpf-next v1 09/14] bpf, loongarch: Convert struct_ops arena arguments in trampolines Kumar Kartikeya Dwivedi
2026-08-21 23:51 ` sashiko-bot
2026-08-21 23:35 ` [PATCH bpf-next v1 10/14] bpf, powerpc: JIT arena kfunc argument rebasing Kumar Kartikeya Dwivedi
2026-08-22 0:46 ` bot+bpf-ci
2026-08-21 23:35 ` [PATCH bpf-next v1 11/14] bpf: Replace arena kfunc argument flags with suffixes Kumar Kartikeya Dwivedi
2026-08-21 23:58 ` sashiko-bot
2026-08-22 0:46 ` bot+bpf-ci
2026-08-24 22:15 ` Eduard Zingerman
2026-08-24 22:52 ` Kumar Kartikeya Dwivedi
2026-08-26 20:42 ` Ihor Solodrai
2026-08-28 5:07 ` Kumar Kartikeya Dwivedi
2026-08-21 23:35 ` [PATCH bpf-next v1 12/14] resolve_btfids: Drop KF_ARENA_ARG flag support Kumar Kartikeya Dwivedi
2026-08-22 0:46 ` bot+bpf-ci
2026-08-24 22:25 ` Eduard Zingerman
2026-08-24 22:53 ` Kumar Kartikeya Dwivedi
2026-08-26 20:47 ` Ihor Solodrai
2026-08-21 23:35 ` [PATCH bpf-next v1 13/14] selftests/bpf: Exercise arena arguments on every capable JIT Kumar Kartikeya Dwivedi
2026-08-22 0:46 ` bot+bpf-ci
2026-08-26 20:50 ` Ihor Solodrai
2026-08-28 5:00 ` Kumar Kartikeya Dwivedi
2026-08-21 23:35 ` [PATCH bpf-next v1 14/14] docs/bpf: Document split arena argument JIT capabilities 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=20260821234433.C85691F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=memxor@gmail.com \
--cc=sashiko-reviews@lists.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.