summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHengqi Chen <hengqi.chen@gmail.com>2026-04-23 12:49:36 +0800
committerHuacai Chen <chenhuacai@loongson.cn>2026-04-23 12:49:36 +0800
commit6ef04707e8eee09360f70812c0ac63c712460bd0 (patch)
tree04554b4f10d5d3515f5576e7944d502626fa8d49
parentc9ebe2016de967b47ce99d5af9bc791939c955f4 (diff)
LoongArch: BPF: Introduce emit_store_stack_imm64() helper
Introduce a helper to store 64-bit immediate on the trampoline stack. The helper will be used in the next patch. Also refactor the existing code to use this helper. Tested-by: Vincent Li <vincent.mc.li@gmail.com> Reviewed-by: Menglong Dong <menglong8.dong@gmail.com> Signed-off-by: Hengqi Chen <hengqi.chen@gmail.com> Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
-rw-r--r--arch/loongarch/net/bpf_jit.c24
1 files changed, 13 insertions, 11 deletions
diff --git a/arch/loongarch/net/bpf_jit.c b/arch/loongarch/net/bpf_jit.c
index 215c5fb339b0..a6c001583083 100644
--- a/arch/loongarch/net/bpf_jit.c
+++ b/arch/loongarch/net/bpf_jit.c
@@ -344,6 +344,12 @@ toofar:
#undef jmp_offset
}
+static void emit_store_stack_imm64(struct jit_ctx *ctx, int reg, int stack_off, u64 imm64)
+{
+ move_imm(ctx, reg, imm64, false);
+ emit_insn(ctx, std, reg, LOONGARCH_GPR_FP, stack_off);
+}
+
static int emit_atomic_rmw(const struct bpf_insn *insn, struct jit_ctx *ctx)
{
const u8 t1 = LOONGARCH_GPR_T1;
@@ -1676,12 +1682,11 @@ static int invoke_bpf_prog(struct jit_ctx *ctx, struct bpf_tramp_link *l,
struct bpf_prog *p = l->link.prog;
int cookie_off = offsetof(struct bpf_tramp_run_ctx, bpf_cookie);
- if (l->cookie) {
- move_imm(ctx, LOONGARCH_GPR_T1, l->cookie, false);
- emit_insn(ctx, std, LOONGARCH_GPR_T1, LOONGARCH_GPR_FP, -run_ctx_off + cookie_off);
- } else {
+ if (l->cookie)
+ emit_store_stack_imm64(ctx, LOONGARCH_GPR_T1,
+ -run_ctx_off + cookie_off, l->cookie);
+ else
emit_insn(ctx, std, LOONGARCH_GPR_ZERO, LOONGARCH_GPR_FP, -run_ctx_off + cookie_off);
- }
/* arg1: prog */
move_imm(ctx, LOONGARCH_GPR_A0, (const s64)p, false);
@@ -1920,14 +1925,11 @@ static int __arch_prepare_bpf_trampoline(struct jit_ctx *ctx, struct bpf_tramp_i
emit_insn(ctx, std, LOONGARCH_GPR_S1, LOONGARCH_GPR_FP, -sreg_off);
/* store ip address of the traced function */
- if (flags & BPF_TRAMP_F_IP_ARG) {
- move_imm(ctx, LOONGARCH_GPR_T1, (const s64)func_addr, false);
- emit_insn(ctx, std, LOONGARCH_GPR_T1, LOONGARCH_GPR_FP, -ip_off);
- }
+ if (flags & BPF_TRAMP_F_IP_ARG)
+ emit_store_stack_imm64(ctx, LOONGARCH_GPR_T1, -ip_off, (u64)func_addr);
/* store arg regs count */
- move_imm(ctx, LOONGARCH_GPR_T1, nr_arg_slots, false);
- emit_insn(ctx, std, LOONGARCH_GPR_T1, LOONGARCH_GPR_FP, -nregs_off);
+ emit_store_stack_imm64(ctx, LOONGARCH_GPR_T1, -nregs_off, nr_arg_slots);
store_args(ctx, nr_arg_slots, args_off);