Re: [PATCH v1 3/3] LoongArch: BPF: Split unconditional branch JA paths statically

Hengqi Chen <[email protected]> Sun, 26 Jul 2026 16:51:01 +0800
Newsgroups dev.linux.lists.loongarch,org.kernel.vger.bpf,org.kernel.vger.linux-kernel
Message-ID <CAEyhmHRPsBC-XUzkrvpCf896yzZF3fxV_AvrDZW4200qrqhi7w@mail.gmail.com>
On Sat, Jul 11, 2026 at 6:10=E2=80=AFPM Tiezhu Yang <[email protected]=
> wrote:
>
> In build_insn(), both 32-bit and 64-bit unconditional branch JA paths
> currently share a single case block. It relies on a runtime condition
> check to multiplex between the 'off' and 'imm' fields.
>
> Since the instruction classes are already resolved at compile-time via
> distinct switch-case labels, this runtime check is redundant.
>
> Split the two paths into individual case blocks to remove the redundant
> runtime check.
>

Though no big deal, someone would argue that the emit_uncond_jmp() is
duplicated.

> Signed-off-by: Tiezhu Yang <[email protected]>
> ---
>  arch/loongarch/net/bpf_jit.c | 9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/arch/loongarch/net/bpf_jit.c b/arch/loongarch/net/bpf_jit.c
> index 5f32b205a6ac..69bc30f88c44 100644
> --- a/arch/loongarch/net/bpf_jit.c
> +++ b/arch/loongarch/net/bpf_jit.c
> @@ -1150,11 +1150,12 @@ static int build_insn(const struct bpf_insn *insn=
, struct jit_ctx *ctx, bool ext
>
>         /* PC +=3D off */
>         case BPF_JMP | BPF_JA:
> +               jmp_offset =3D bpf2la_offset(i, off, ctx);
> +               if (emit_uncond_jmp(ctx, jmp_offset) < 0)
> +                       goto toofar;
> +               break;
>         case BPF_JMP32 | BPF_JA:
> -               if (BPF_CLASS(code) =3D=3D BPF_JMP)
> -                       jmp_offset =3D bpf2la_offset(i, off, ctx);
> -               else
> -                       jmp_offset =3D bpf2la_offset(i, imm, ctx);
> +               jmp_offset =3D bpf2la_offset(i, imm, ctx);
>                 if (emit_uncond_jmp(ctx, jmp_offset) < 0)
>                         goto toofar;
>                 break;
> --

Acked-by: Hengqi Chen <[email protected]>

> 2.42.0
>
>