Skip to content

Commit b8574f8

Browse files
chenhengqiKernel Patches Daemon
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, let's use move_addr() instead to prevent subtle bugs. (I observed this while debugging other issues with printk.) Signed-off-by: Hengqi Chen <[email protected]>
1 parent 45f4134 commit b8574f8

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
@@ -1599,7 +1599,7 @@ static int __arch_prepare_bpf_trampoline(struct jit_ctx *ctx, struct bpf_tramp_i
15991599
orig_call += LOONGARCH_BPF_FENTRY_NBYTES;
16001600

16011601
if (flags & BPF_TRAMP_F_CALL_ORIG) {
1602-
move_imm(ctx, LOONGARCH_GPR_A0, (const s64)im, false);
1602+
move_addr(ctx, LOONGARCH_GPR_A0, (const u64)im);
16031603
ret = emit_call(ctx, (const u64)__bpf_tramp_enter);
16041604
if (ret)
16051605
return ret;
@@ -1649,7 +1649,7 @@ static int __arch_prepare_bpf_trampoline(struct jit_ctx *ctx, struct bpf_tramp_i
16491649

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

0 commit comments

Comments
 (0)