mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: bot+bpf-ci@kernel.org
To: yangtiezhu@loongson.cn,chenhuacai@kernel.org,hengqi.chen@gmail.com
Cc: loongarch@lists.linux.dev,bpf@vger.kernel.org,linux-kernel@vger.kernel.org,ast@kernel.org,andrii@kernel.org,daniel@iogearbox.net,martin.lau@kernel.org,eddyz87@gmail.com,yonghong.song@linux.dev,mason@kernel.org,ihor.solodrai@linux.dev
Subject: Re: [PATCH v1 2/2] LoongArch: BPF: Use beqz and bnez instructions for trampoline
Date: Mon,  2 Nov 2026 07:53:31 +0000 (UTC)	[thread overview]
Message-ID: <c3b8e6ae47164ab1a643a1730f0600993de03c8a30e35122a9812ac73d807697@mail.kernel.org> (raw)
In-Reply-To: <20261102072808.23080-3-yangtiezhu@loongson.cn>

[-- Attachment #1: Type: text/plain, Size: 3200 bytes --]

> LoongArch: BPF: Use beqz and bnez instructions for trampoline

TL;DR: Commit message only: the claimed branch-overflow risk looks impossible,
since trampolines fit in one page and the old code behaved identically, so the
Fixes: and Cc: stable tags may not be justified.

> LoongArch: BPF: Use beqz and bnez instructions for trampoline
>
> Currently, the implementation for BPF trampoline branches does not match
> the existing technical comments. The code uses larch_insn_gen_beq, where
> the comment indicates beqz should be used.
>
> Moreover, the beq instruction belongs to the reg2i16 format which limits
> the jump offset to 16 bits (+/-128KB). After using the beqz instruction
> which belongs to the reg1i21 format, the jump range will be extended to
> 21 bits (+/-4MB). This mitigates potential branch overflow risks in the
> complex BPF trampolines.
>
> While at it, also apply the same optimization to the bne instruction by
> replacing it with bnez and adding a corresponding comment.
>
> Fixes: f9b6b41f0cf3 ("LoongArch: BPF: Add basic bpf trampoline support")
> Cc: stable@vger.kernel.org
> Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>

The commit message says the new instructions "mitigate potential branch
overflow risks in the complex BPF trampolines", and the patch carries a
Fixes: tag and Cc: stable.  Can a beq/bne inside a LoongArch BPF trampoline
actually go out of range?

bpf_trampoline_update() in kernel/bpf/trampoline.c rejects any trampoline
larger than one page:

    size = arch_bpf_trampoline_size(&tr->func.model, tr->flags, tnodes,
                                    tr->func.addr);
    ...
    if (size > PAGE_SIZE) {
        err = -E2BIG;
        goto out;
    }

On LoongArch PAGE_SIZE is at most 64KB (the 64KB_2LEVEL and 64KB_3LEVEL
configs), while the beq/bne reg2i16 range is +/-128KB.  So no branch inside
a trampoline can get near that limit.

bpf_struct_ops_prepare_trampoline() puts a single node in
tnodes[BPF_TRAMP_FENTRY] and has no fmod_ret branches, so its only
conditional branch skips one call sequence.

Even if the range were exceeded, larch_insn_gen_beq() and
larch_insn_gen_bne() return INSN_BREAK, and validate_code() in
arch_prepare_bpf_trampoline() would then fail the trampoline with -EINVAL.
The old code could not silently emit a wrong branch.

The old and new instructions also test the same condition:

    larch_insn_gen_beq(LOONGARCH_GPR_A0, LOONGARCH_GPR_ZERO, offset)
        -> beq $zero, $a0
    larch_insn_gen_beqz(LOONGARCH_GPR_A0, offset)
        -> beqz $a0

and likewise bne $zero, $t1 versus bnez $t1, each replacing the same single
nop slot.  So the patch appears to change no behavior and only makes the
code match the existing "update branch with beqz" comment.

Could the changelog drop the overflow-risk wording, or describe the change
as a cleanup, and could the Fixes: and Cc: stable tags be reconsidered given
that stable-kernel-rules requires a fix for a real bug?


---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md

CI run summary: https://github.com/kernel-patches/bpf/actions/runs/41407991756

  reply	other threads:[~2026-11-02  7:53 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-02  7:28 [PATCH v1 0/2] LoongArch: BPF: Fix arena and trampoline Tiezhu Yang
2026-11-02  7:28 ` [PATCH v1 1/2] LoongArch: BPF: Make arena support depend on SCQ extension Tiezhu Yang
2026-11-02 14:20   ` Huacai Chen
2026-11-03  2:24     ` Tiezhu Yang
2026-11-04  4:29       ` Huacai Chen
2026-11-04  6:58         ` Tiezhu Yang
2026-11-04  9:54           ` Huacai Chen
2026-11-04 13:06             ` Tiezhu Yang
2026-11-04 10:17   ` George Guo
2026-11-02  7:28 ` [PATCH v1 2/2] LoongArch: BPF: Use beqz and bnez instructions for trampoline Tiezhu Yang
2026-11-02  7:53   ` bot+bpf-ci [this message]
2026-11-03  2:27     ` 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=c3b8e6ae47164ab1a643a1730f0600993de03c8a30e35122a9812ac73d807697@mail.kernel.org \
    --to=bot+bpf-ci@kernel.org \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=chenhuacai@kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=hengqi.chen@gmail.com \
    --cc=ihor.solodrai@linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=loongarch@lists.linux.dev \
    --cc=martin.lau@kernel.org \
    --cc=mason@kernel.org \
    --cc=yangtiezhu@loongson.cn \
    --cc=yonghong.song@linux.dev \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®