BPF List
 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 2/2] LoongArch: BPF: Eliminate zero-extension for memory load operations
Date: Tue, 28 Jul 2026 03:41:48 +0000	[thread overview]
Message-ID: <20260728034149.524171F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260728031615.9389-3-yangtiezhu@loongson.cn>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] The patch introduces redundant double-zero-extension instructions for all 32-bit ALU and atomic RMW operations, significantly bloating the JIT image size rather than reducing it.
--

--- Patch [2]: [PATCH v1 2/2] LoongArch: BPF: Eliminate zero-extension for memory load operations ---
commit 0efa0ea6d44efe5e18fb08bd07d86b901c2332ec
Author: Tiezhu Yang <yangtiezhu@loongson.cn>

LoongArch: BPF: Eliminate zero-extension for memory load operations

This commit overwrites bpf_jit_needs_zext() to return true, causing the
verifier to explicitly insert zero-extension instructions. It then adds
look-ahead logic to skip these verifier-inserted instructions for memory
loads that naturally zero-extend, aiming to reduce the JITted image size.

> diff --git a/arch/loongarch/net/bpf_jit.c b/arch/loongarch/net/bpf_jit.c
> index 4c54e57455ae3..417b69b7ec4a0 100644
> --- a/arch/loongarch/net/bpf_jit.c
> +++ b/arch/loongarch/net/bpf_jit.c

[ ... ]

> @@ -2383,6 +2399,11 @@ bool bpf_jit_supports_subprog_tailcalls(void)
>  	return true;
>  }
>  
> +bool bpf_jit_needs_zext(void)
> +{
> +	return true;
> +}
> +

[Severity: High]
Does returning true here cause the verifier to insert zext instructions for
all 32-bit operations globally, rather than just memory loads?

If the verifier now inserts a zext instruction after every ALU32 operation,
and the JIT still unconditionally calls emit_zext_32() for ALU32 ops:

arch/loongarch/net/bpf_jit.c:build_insn() {
	case BPF_ALU | BPF_ADD | BPF_X:
	case BPF_ALU64 | BPF_ADD | BPF_X:
		emit_insn(ctx, addd, dst, dst, src);
		emit_zext_32(ctx, dst, is32);
		break;
}

Will this cause the JIT to emit double zero-extensions (one internally, and
one when processing the verifier's injected instruction) for all 32-bit ALU
and atomic RMW operations? This seems like it could bloat the JIT image size
rather than reducing it, as the look-ahead skip logic was only added for
memory loads.

>  bool bpf_jit_inlines_helper_call(s32 imm)
>  {
>  	switch (imm) {

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

      reply	other threads:[~2026-07-28  3:41 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-28  3:16 [PATCH v1 0/2] Refine move_imm() and optimize memory load Tiezhu Yang
2026-07-28  3:16 ` [PATCH v1 1/2] LoongArch: BPF: Clean up and decouple is32 parameter from move_imm() Tiezhu Yang
2026-07-28  3:16 ` [PATCH v1 2/2] LoongArch: BPF: Eliminate zero-extension for memory load operations Tiezhu Yang
2026-07-28  3:41   ` sashiko-bot [this message]

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=20260728034149.524171F000E9@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox