All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Tiezhu Yang" <yangtiezhu@loongson.cn>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH v1 3/4] LoongArch: BPF: Refactor jump offset calculation in tail call
Date: Tue, 30 Jun 2026 02:40:01 +0000	[thread overview]
Message-ID: <20260630024002.26F4D1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260630022705.11536-4-yangtiezhu@loongson.cn>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Spurious JIT compilation failure for large BPF programs with tail calls due to invalid jump offset calculation in the first JIT pass.
--

commit c7d3e2cbf4a615b76ec73b1fff169ff7f13381b9
Author: Tiezhu Yang <yangtiezhu@loongson.cn>

LoongArch: BPF: Refactor jump offset calculation in tail call

This patch modifies the jump offset calculation in emit_bpf_tail_call()
to use an absolute target reference anchor based on the next instruction
offset, ensuring immediate offsets land precisely on instruction boundaries.

> diff --git a/arch/loongarch/net/bpf_jit.c b/arch/loongarch/net/bpf_jit.c
> --- a/arch/loongarch/net/bpf_jit.c
> +++ b/arch/loongarch/net/bpf_jit.c
[ ... ]
> @@ -310,12 +306,12 @@ static int emit_bpf_tail_call(struct jit_ctx *ctx, int insn)
[ ... ]
>  	off = offsetof(struct bpf_array, map.max_entries);
>  	emit_insn(ctx, ldwu, t1, a1, off);
>  	/* bgeu $a2, $t1, jmp_offset */
> +	jmp_offset = ctx->offset[insn + 1] - ctx->idx;
>  	if (emit_tailcall_jmp(ctx, BPF_JGE, a2, t1, jmp_offset) < 0)
>  		goto toofar;

[Severity: High]
Does this calculation cause large BPF programs to fail JIT compilation during
the first pass?

During the first JIT pass, ctx->offset[insn + 1] is not yet populated and will
be 0. As a result, jmp_offset evaluates to -ctx->idx. 

If ctx->idx exceeds 32767 for a large program, jmp_offset will fail the 16-bit
bounds check inside emit_tailcall_jmp(), causing JIT compilation to abort
prematurely.

Previously, jmp_offset used a small relative offset which safely fit within
the 16-bit limit during the initial pass.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260630022705.11536-1-yangtiezhu@loongson.cn?part=3

  reply	other threads:[~2026-06-30  2:40 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-30  2:27 [PATCH v1 0/4] Optimize BPF tailcall for LoongArch Tiezhu Yang
2026-06-30  2:27 ` [PATCH v1 1/4] LoongArch: BPF: Optimize redundant TCC loads in epilogue Tiezhu Yang
2026-06-30  2:27 ` [PATCH v1 2/4] LoongArch: BPF: Move arena register slot below TCC context Tiezhu Yang
2026-06-30  2:27 ` [PATCH v1 3/4] LoongArch: BPF: Refactor jump offset calculation in tail call Tiezhu Yang
2026-06-30  2:40   ` sashiko-bot [this message]
2026-06-30  3:20     ` Tiezhu Yang
2026-06-30  2:27 ` [PATCH v1 4/4] LoongArch: BPF: Implement branchless conditional move for TCC Tiezhu Yang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260630024002.26F4D1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=yangtiezhu@loongson.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.