Skip to content

Commit ea645cf

Browse files
chenhengqichenhuacai
authored andcommitted
LoongArch: BPF: Make trampoline size stable
When attach fentry/fexit BPF programs, __arch_prepare_bpf_trampoline() is called twice with different `struct bpf_tramp_image *im`: bpf_trampoline_update() -> arch_bpf_trampoline_size() -> __arch_prepare_bpf_trampoline() -> arch_prepare_bpf_trampoline() -> __arch_prepare_bpf_trampoline() Use move_imm() will emit unstable instruction sequences, so let's use move_addr() instead to prevent subtle bugs. (I observed this while debugging other issues with printk.) Cc: [email protected] Tested-by: Vincent Li <[email protected]> Signed-off-by: Hengqi Chen <[email protected]> Signed-off-by: Huacai Chen <[email protected]>
1 parent a04731c commit ea645cf

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

arch/loongarch/net/bpf_jit.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1595,7 +1595,7 @@ static int __arch_prepare_bpf_trampoline(struct jit_ctx *ctx, struct bpf_tramp_i
15951595
orig_call += LOONGARCH_BPF_FENTRY_NBYTES;
15961596

15971597
if (flags & BPF_TRAMP_F_CALL_ORIG) {
1598-
move_imm(ctx, LOONGARCH_GPR_A0, (const s64)im, false);
1598+
move_addr(ctx, LOONGARCH_GPR_A0, (const u64)im);
15991599
ret = emit_call(ctx, (const u64)__bpf_tramp_enter);
16001600
if (ret)
16011601
return ret;
@@ -1645,7 +1645,7 @@ static int __arch_prepare_bpf_trampoline(struct jit_ctx *ctx, struct bpf_tramp_i
16451645

16461646
if (flags & BPF_TRAMP_F_CALL_ORIG) {
16471647
im->ip_epilogue = ctx->ro_image + ctx->idx;
1648-
move_imm(ctx, LOONGARCH_GPR_A0, (const s64)im, false);
1648+
move_addr(ctx, LOONGARCH_GPR_A0, (const u64)im);
16491649
ret = emit_call(ctx, (const u64)__bpf_tramp_exit);
16501650
if (ret)
16511651
goto out;

0 commit comments

Comments
 (0)