Skip to content

Commit 93fd420

Browse files
image-dragonAlexei Starovoitov
authored andcommitted
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@chinatelecom.cn> Tested-by: Björn Töpel <bjorn@kernel.org> Acked-by: Björn Töpel <bjorn@kernel.org> Link: https://lore.kernel.org/r/20260208053311.698352-2-dongml2@chinatelecom.cn Signed-off-by: Alexei Starovoitov <ast@kernel.org> Reviewed-by: Pu Lehui <pulehui@huawei.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org>
1 parent 2669dde commit 93fd420

1 file changed

Lines changed: 14 additions & 11 deletions

File tree

arch/riscv/net/bpf_jit_comp64.c

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -926,19 +926,25 @@ static void restore_stack_args(int nr_stack_args, int args_off, int stk_arg_off,
926926
}
927927
}
928928

929+
static void emit_store_stack_imm64(u8 reg, int stack_off, u64 imm64,
930+
struct rv_jit_context *ctx)
931+
{
932+
/* Load imm64 into reg and store it at [FP + stack_off]. */
933+
emit_imm(reg, (s64)imm64, ctx);
934+
emit_sd(RV_REG_FP, stack_off, reg, ctx);
935+
}
936+
929937
static int invoke_bpf_prog(struct bpf_tramp_link *l, int args_off, int retval_off,
930938
int run_ctx_off, bool save_ret, struct rv_jit_context *ctx)
931939
{
932940
int ret, branch_off;
933941
struct bpf_prog *p = l->link.prog;
934942
int cookie_off = offsetof(struct bpf_tramp_run_ctx, bpf_cookie);
935943

936-
if (l->cookie) {
937-
emit_imm(RV_REG_T1, l->cookie, ctx);
938-
emit_sd(RV_REG_FP, -run_ctx_off + cookie_off, RV_REG_T1, ctx);
939-
} else {
944+
if (l->cookie)
945+
emit_store_stack_imm64(RV_REG_T1, -run_ctx_off + cookie_off, l->cookie, ctx);
946+
else
940947
emit_sd(RV_REG_FP, -run_ctx_off + cookie_off, RV_REG_ZERO, ctx);
941-
}
942948

943949
/* arg1: prog */
944950
emit_imm(RV_REG_A0, (const s64)p, ctx);
@@ -1123,13 +1129,10 @@ static int __arch_prepare_bpf_trampoline(struct bpf_tramp_image *im,
11231129
emit_sd(RV_REG_FP, -sreg_off, RV_REG_S1, ctx);
11241130

11251131
/* store ip address of the traced function */
1126-
if (flags & BPF_TRAMP_F_IP_ARG) {
1127-
emit_imm(RV_REG_T1, (const s64)func_addr, ctx);
1128-
emit_sd(RV_REG_FP, -ip_off, RV_REG_T1, ctx);
1129-
}
1132+
if (flags & BPF_TRAMP_F_IP_ARG)
1133+
emit_store_stack_imm64(RV_REG_T1, -ip_off, (u64)func_addr, ctx);
11301134

1131-
emit_li(RV_REG_T1, nr_arg_slots, ctx);
1132-
emit_sd(RV_REG_FP, -nregs_off, RV_REG_T1, ctx);
1135+
emit_store_stack_imm64(RV_REG_T1, -nregs_off, nr_arg_slots, ctx);
11331136

11341137
store_args(nr_arg_slots, args_off, ctx);
11351138

0 commit comments

Comments
 (0)