From: Pu Lehui <pulehui@huaweicloud.com>
To: "Björn Töpel" <bjorn@kernel.org>,
bpf@vger.kernel.org, linux-riscv@lists.infradead.org,
linux-kernel@vger.kernel.org
Cc: Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>,
Eduard Zingerman <eddyz87@gmail.com>,
Kumar Kartikeya Dwivedi <memxor@gmail.com>,
Martin KaFai Lau <martin.lau@linux.dev>,
Song Liu <song@kernel.org>,
Yonghong Song <yonghong.song@linux.dev>,
Jiri Olsa <jolsa@kernel.org>,
Emil Tsalapatis <emil@etsalapatis.com>,
Ihor Solodrai <ihor.solodrai@linux.dev>,
Puranjay Mohan <puranjay@kernel.org>,
Paul Walmsley <pjw@kernel.org>,
Palmer Dabbelt <palmer@dabbelt.com>,
Alexandre Ghiti <alex@ghiti.fr>, Pu Lehui <pulehui@huawei.com>
Subject: [PATCH bpf-next 1/5] bpf, riscv: Fix stack-passed arguments for indirect trampolines
Date: Tue, 29 Sep 2026 08:39:20 +0000 [thread overview]
Message-ID: <20260929083924.1851840-2-pulehui@huaweicloud.com> (raw)
In-Reply-To: <20260929083924.1851840-1-pulehui@huaweicloud.com>
From: Kumar Kartikeya Dwivedi <memxor@gmail.com>
store_args() reads stack-passed arguments relative to FP assuming the
trampoline was entered through the fentry call from a traced function. In
that path, the trampoline pushes the parent frame before establishing its
final FP, so the incoming stack arguments start at FP + 16.
An indirect trampoline for a struct_ops callback is called through a
function pointer. Its prologue allocates only the trampoline frame and sets
FP to the incoming SP. The RISC-V ABI places the first stack argument at
that incoming SP, so the arguments start at FP, not FP + 16. Every
stack-passed argument of a callback with more than eight argument slots is
therefore read two slots late.
Pass the prologue-dependent offset to store_args(), using zero for a direct
struct_ops trampoline and 16 for the fentry path.
Fixes: 6801b0aef79d ("riscv, bpf: Add 12-argument support for RV64 bpf trampoline")
Cc: Björn Töpel <bjorn@kernel.org>
Cc: Pu Lehui <pulehui@huawei.com>
Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Reviewed-by: Pu Lehui <pulehui@huawei.com>
---
arch/riscv/net/bpf_jit_comp64.c | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/arch/riscv/net/bpf_jit_comp64.c b/arch/riscv/net/bpf_jit_comp64.c
index ed0a6f871dea..b5fa6338e5eb 100644
--- a/arch/riscv/net/bpf_jit_comp64.c
+++ b/arch/riscv/net/bpf_jit_comp64.c
@@ -895,7 +895,8 @@ 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, struct rv_jit_context *ctx)
+static void store_args(int nr_arg_slots, int args_off, int stack_args_off,
+ struct rv_jit_context *ctx)
{
int i;
@@ -903,8 +904,8 @@ static void store_args(int nr_arg_slots, int args_off, struct rv_jit_context *ct
if (i < RV_MAX_REG_ARGS) {
emit_sd(RV_REG_FP, -args_off, RV_REG_A0 + i, ctx);
} else {
- /* skip slots for T0 and FP of traced function */
- emit_ld(RV_REG_T1, 16 + (i - RV_MAX_REG_ARGS) * 8, RV_REG_FP, ctx);
+ emit_ld(RV_REG_T1, stack_args_off +
+ (i - RV_MAX_REG_ARGS) * 8, RV_REG_FP, ctx);
emit_sd(RV_REG_FP, -args_off, RV_REG_T1, ctx);
}
args_off -= 8;
@@ -1190,7 +1191,12 @@ static int __arch_prepare_bpf_trampoline(struct bpf_tramp_image *im,
func_meta = nr_arg_slots;
emit_store_stack_imm64(RV_REG_T1, -func_meta_off, func_meta, ctx);
- store_args(nr_arg_slots, args_off, ctx);
+ /*
+ * A direct struct_ops call has its first stack argument at the incoming
+ * SP, which the trampoline keeps as FP. The fentry path pushes the
+ * parent frame first, so its incoming stack arguments start at FP + 16.
+ */
+ store_args(nr_arg_slots, args_off, is_struct_ops ? 0 : 16, ctx);
if (bpf_fsession_cnt(tnodes)) {
/* clear all session cookies' value */
--
2.34.1
next prev parent reply other threads:[~2026-09-29 8:35 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-29 8:39 [PATCH bpf-next 0/5] riscv, bpf: Prepare for upcoming daily CI Pu Lehui
2026-09-29 8:39 ` Pu Lehui [this message]
2026-09-29 16:28 ` [PATCH bpf-next 1/5] bpf, riscv: Fix stack-passed arguments for indirect trampolines Alexei Starovoitov
2026-09-29 8:39 ` [PATCH bpf-next 2/5] selftests/bpf: Set CONFIG_HZ_100 for riscv64 Pu Lehui
2026-09-29 16:29 ` Alexei Starovoitov
2026-09-29 8:39 ` [PATCH bpf-next 3/5] selftests/bpf: Use /tmp for temporary file in d_path Pu Lehui
2026-09-29 16:29 ` Alexei Starovoitov
2026-09-30 6:24 ` Pu Lehui
2026-10-05 22:54 ` Ihor Solodrai
2026-10-06 17:09 ` Ihor Solodrai
2026-09-29 8:39 ` [PATCH bpf-next 4/5] selftests/bpf: Update qemu config for riscv64 in vmtest.sh Pu Lehui
2026-09-29 8:39 ` [PATCH bpf-next 5/5] selftests/bpf: Update DENYLIST.riscv64 Pu Lehui
2026-09-29 16:29 ` Alexei Starovoitov
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=20260929083924.1851840-2-pulehui@huaweicloud.com \
--to=pulehui@huaweicloud.com \
--cc=alex@ghiti.fr \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bjorn@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=emil@etsalapatis.com \
--cc=ihor.solodrai@linux.dev \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=martin.lau@linux.dev \
--cc=memxor@gmail.com \
--cc=palmer@dabbelt.com \
--cc=pjw@kernel.org \
--cc=pulehui@huawei.com \
--cc=puranjay@kernel.org \
--cc=song@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®