[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20260203055231.1088479-2-dongml2@chinatelecom.cn>
Date: Tue, 3 Feb 2026 13:52:29 +0800
From: Menglong Dong <menglong8.dong@...il.com>
To: ast@...nel.org
Cc: daniel@...earbox.net,
andrii@...nel.org,
martin.lau@...ux.dev,
eddyz87@...il.com,
song@...nel.org,
yonghong.song@...ux.dev,
john.fastabend@...il.com,
kpsingh@...nel.org,
sdf@...ichev.me,
haoluo@...gle.com,
jolsa@...nel.org,
bjorn@...nel.org,
pulehui@...wei.com,
puranjay@...nel.org,
pjw@...nel.org,
palmer@...belt.com,
aou@...s.berkeley.edu,
alex@...ti.fr,
jiang.biao@...ux.dev,
bpf@...r.kernel.org,
linux-riscv@...ts.infradead.org,
linux-kernel@...r.kernel.org
Subject: [PATCH bpf-next 1/3] bpf, riscv: introduce emit_store_stack_imm64() for trampoline
Introduce a helper to store 64-bit immediate on the trampoline stack with
a help of a register.
Signed-off-by: Menglong Dong <dongml2@...natelecom.cn>
---
arch/riscv/net/bpf_jit_comp64.c | 25 ++++++++++++++-----------
1 file changed, 14 insertions(+), 11 deletions(-)
diff --git a/arch/riscv/net/bpf_jit_comp64.c b/arch/riscv/net/bpf_jit_comp64.c
index 37888abee70c..e4f45e2e7e2f 100644
--- a/arch/riscv/net/bpf_jit_comp64.c
+++ b/arch/riscv/net/bpf_jit_comp64.c
@@ -926,6 +926,14 @@ static void restore_stack_args(int nr_stack_args, int args_off, int stk_arg_off,
}
}
+static void emit_store_stack_imm64(u8 reg, int stack_off, u64 imm64,
+ struct rv_jit_context *ctx)
+{
+ /* Load imm64 into reg and store it at [FP + stack_off]. */
+ emit_imm(reg, (s64)imm64, ctx);
+ emit_sd(RV_REG_FP, stack_off, reg, ctx);
+}
+
static int invoke_bpf_prog(struct bpf_tramp_link *l, int args_off, int retval_off,
int run_ctx_off, bool save_ret, struct rv_jit_context *ctx)
{
@@ -933,12 +941,10 @@ static int invoke_bpf_prog(struct bpf_tramp_link *l, int args_off, int retval_of
struct bpf_prog *p = l->link.prog;
int cookie_off = offsetof(struct bpf_tramp_run_ctx, bpf_cookie);
- if (l->cookie) {
- emit_imm(RV_REG_T1, l->cookie, ctx);
- emit_sd(RV_REG_FP, -run_ctx_off + cookie_off, RV_REG_T1, ctx);
- } else {
+ if (l->cookie)
+ emit_store_stack_imm64(RV_REG_T1, -run_ctx_off + cookie_off, l->cookie, ctx);
+ else
emit_sd(RV_REG_FP, -run_ctx_off + cookie_off, RV_REG_ZERO, ctx);
- }
/* arg1: prog */
emit_imm(RV_REG_A0, (const s64)p, ctx);
@@ -1123,13 +1129,10 @@ static int __arch_prepare_bpf_trampoline(struct bpf_tramp_image *im,
emit_sd(RV_REG_FP, -sreg_off, RV_REG_S1, ctx);
/* store ip address of the traced function */
- if (flags & BPF_TRAMP_F_IP_ARG) {
- emit_imm(RV_REG_T1, (const s64)func_addr, ctx);
- emit_sd(RV_REG_FP, -ip_off, RV_REG_T1, ctx);
- }
+ if (flags & BPF_TRAMP_F_IP_ARG)
+ emit_store_stack_imm64(RV_REG_T1, -ip_off, (u64)func_addr, ctx);
- emit_li(RV_REG_T1, nr_arg_slots, ctx);
- emit_sd(RV_REG_FP, -nregs_off, RV_REG_T1, ctx);
+ emit_store_stack_imm64(RV_REG_T1, -nregs_off, nr_arg_slots, ctx);
store_args(nr_arg_slots, args_off, ctx);
--
2.52.0
Powered by blists - more mailing lists