Patch "LoongArch: BPF: Refactor jump offset calculation in tail call" has been added to the 6.6-stable tree
A message that is not in the archive (sent off-list or not yet received): [email protected]
Hi, Sasha,
Quoted 8 lines · Sasha Levin
This is a note to let you know that I've just added the patch titled
LoongArch: BPF: Refactor jump offset calculation in tail call
to the 6.6-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary
Quoted 7 lines
The filename of the patch is:
loongarch-bpf-refactor-jump-offset-calculation-in-ta.patch
and it can be found in the queue-6.6 subdirectory.If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.
I think this patch is not necessary for 6.6/6.12 because the commit it fixes is not in 6.6/6.12.
Tiezhu, what's your opinion?
Huacai
Quoted 88 lines
commit
a0d511d60c584afdc0fb206d070abd1f2d5464afAuthor: Tiezhu Yang <[email protected]> Date: Mon Aug 17 22:07:23 2026 +0800LoongArch: BPF: Refactor jump offset calculation in tail call
[ Upstream commit
37d545d12f21c4d50612ecaebd7ae1e5bf91b2d8]The old macro-based
jmp_offsetcalculation derives the jump distance from a stale prior-pass code stride, which can lead to wrong branch offsets and soft lockups under extra JIT passes.Fix this by calculating the offset directly on the absolute target:
"ctx->offset[insn + 1] -ctx->idx".To avoid a false 16-bit range check abort during size estimation, add a "
ctx->image== NULL" guard to inject a safe dummy offset.Fixes cd39d9e6b7e4 ("LoongArch: BPF: Fix jump offset calculation in tailcall")Signed-off-by Tiezhu Yang <[email protected]>Signed-off-by Huacai Chen <[email protected]>Signed-off-by Sasha Levin <[email protected]>arch/loongarch/net/bpf_jit.c +4
-8@@ -205,17 +205,13 @@ bool bpf_jit_supports_kfunc_call(void)static int emit_bpf_tail_call (struct jit_ctx *ctx,int insn) { -int off, tc_ninsn =0 ; +int off, jmp_offset;u8 tcc =tail_call_reg (ctx);u8 a1 =LOONGARCH_GPR_A1 ;u8 a2 =LOONGARCH_GPR_A2 ;u8 t1 =LOONGARCH_GPR_T1 ;u8 t2 =LOONGARCH_GPR_T2 ;u8 t3 =LOONGARCH_GPR_T3 ; -const int idx0 = ctx->idx; - -#define cur_offset (ctx->idx - idx0) -#define jmp_offset (tc_ninsn - (cur_offset))/* * a0: &ctx @@ -225,12 +221,12 @@ static int emit_bpf_tail_call(struct jit_ctx *ctx, int insn)* if (index >= array->map.max_entries) * goto out; */ - tc_ninsn = insn ? ctx->offset[insn+1 ] - ctx->offset[insn] : ctx->offset[0 ];emit_zext_32 (ctx, a2, true); off = offsetof(struct bpf_array, map.max_entries);emit_insn (ctx, ldwu, t1, a1, off);/* bgeu $a2, $t1, jmp_offset */ + jmp_offset = ctx->image ? (ctx->offset[insn +1 ] - ctx->idx) :0 ;if (emit_tailcall_jmp (ctx,BPF_JGE , a2, t1, jmp_offset) <0 ) goto toofar;@@ -239,6 +235,7 @@ static int emit_bpf_tail_call(struct jit_ctx *ctx, int insn)* goto out; */ emit_insn (ctx, addid,REG_TCC , tcc,-1 ); + jmp_offset = ctx->image ? (ctx->offset[insn +1 ] - ctx->idx) :0 ;if (emit_tailcall_jmp (ctx,BPF_JSLT ,REG_TCC ,LOONGARCH_GPR_ZERO , jmp_offset) <0 ) goto toofar;@@ -251,6 +248,7 @@ static int emit_bpf_tail_call(struct jit_ctx *ctx, int insn) off = offsetof(struct bpf_array , ptrs);emit_insn (ctx, ldd, t2, t2, off);/* beq $t2, $zero, jmp_offset */ + jmp_offset = ctx->image ? (ctx->offset[insn +1 ] - ctx->idx) :0 ;if (emit_tailcall_jmp (ctx,BPF_JEQ , t2,LOONGARCH_GPR_ZERO , jmp_offset) <0 ) goto toofar;@@ -264,8 +262,6 @@ static int emit_bpf_tail_call(struct jit_ctx *ctx, int insn) toofar:pr_info_once ("tail_call: jump too far\n" );return -1 ; -#undef cur_offset -#undef jmp_offset }static void emit_atomic (const struct bpf_insn *insn,struct jit_ctx *ctx)