From: "Alexei Starovoitov" <alexei.starovoitov@gmail.com>
To: "Ramin Moussavi" <ramin.moussavi@yacoub.de>,
"Russell King" <linux@armlinux.org.uk>,
"Puranjay Mohan" <puranjay@kernel.org>
Cc: "Daniel Borkmann" <daniel@iogearbox.net>,
"Andrii Nakryiko" <andrii@kernel.org>, <bpf@vger.kernel.org>,
<linux-arm-kernel@lists.infradead.org>,
<linux-kernel@vger.kernel.org>
Subject: Re: [PATCH bpf-next v2] bpf, arm32: build constants inline instead of using a literal pool
Date: Fri, 20 Nov 2026 19:12:28 +0000 [thread overview]
Message-ID: <DN09ZA2KX6CC.UVO7HNJWT0EO@gmail.com> (raw)
In-Reply-To: <20261120140147.166934-1-ramin.moussavi@yacoub.de>
On Fri, Nov 20, 2026 at 06:01 AM Ramin Moussavi <ramin.moussavi@yacoub.de> wrote:
> Commit 0b59d8806a31 ("ARM: net: delegate filter to kernel interpreter
> when imm_offset() return value can't fit into 12bits.") handles that by
> setting FLAG_IMM_OVERFLOW and dropping the whole program to the
> interpreter, and already noted that multiple pools "would better be done
> as a feature instead of fix".
Not always. imm is u16 in imm_offset():
imm = offset - (8 + ctx->idx * 4);
if (imm & ~0xfff) {
Take a classic filter that starts with 'div #3'.
Put 64 KB of code without hard constants after it:
offset - (8 + ctx->idx * 4) 0x10008
imm 0x8, the check passes
ldr ip, [pc, #8] loads an insn, not jit_udiv32
blx ip jumps to the value of that insn
So the patch fixes a crash too.
Pls say that in the log and add a Fixes tag for 0b59d8806a31.
> ARMv7 and later are unaffected, the MOVW/MOVT path is unchanged.
Only when the kernel is built without v6.
The v6 line wins in arch/arm/Makefile:
cpp-$(CONFIG_CPU_32v7) :=-D__LINUX_ARM_ARCH__=7
cpp-$(CONFIG_CPU_32v6) :=-D__LINUX_ARM_ARCH__=6
imx_v6_v7_defconfig and omap2plus_defconfig enable both.
With the JIT on, an i.MX6 runs the new code. Pls fix the log.
> + for (shift = 0; shift < 32; shift += 8) {
> + u32 part = val & (0xffU << shift);
> +
> + if (!part)
> + continue;
> + if (first)
> + emit(ARM_MOV_I(rd, imm8m(part)), ctx);
> + else
> + emit(ARM_ORR_I(rd, rd, imm8m(part)), ctx);
> + first = false;
> + }
> + if (first)
> + emit(ARM_MOV_I(rd, 0), ctx);
The log says that arm64 does the same. Not for small negative values.
arm64 emits one MOVN. Here they get the longest sequence.
For 'r2 += -264' val is 0xfffffef8 and ~val is 0x107, not an imm8m:
version insns for 0xfffffef8
----------- ---------------------------------
today ldr r8, [pc, #off]
patch mov, orr, orr, orr
diff below mvn r8, #0x7; bic r8, r8, #0x100
The last 'if (first)' is dead code.
emit_mov_i() is the only caller and imm8m(0) is 0.
Here is emit_mov_i_no8m() on top of your patch. I didn't compile it:
diff --git a/arch/arm/net/bpf_jit_32.c b/arch/arm/net/bpf_jit_32.c
index 58d066a..28a2c5e 100644
--- a/arch/arm/net/bpf_jit_32.c
+++ b/arch/arm/net/bpf_jit_32.c
@@ -411,30 +411,30 @@ static inline void emit_mov_i_no8m(const u8 rd, u32 val, struct jit_ctx *ctx)
{
#if __LINUX_ARM_ARCH__ < 7
/*
- * A single MVN if the inverted value is an imm8m, else one
- * MOV/ORR per non-zero byte -- a byte is always an imm8m.
+ * A single MVN if the inverted value is an imm8m. Else MOV + ORR set
+ * the bytes of val, or MVN + BIC clear the bytes of ~val.
*/
+ u32 op = ARM_MOV_I(rd, 0), next = ARM_ORR_I(rd, rd, 0);
int imm12 = imm8m(~val);
unsigned int shift;
- bool first = true;
if (imm12 >= 0) {
emit(ARM_MVN_I(rd, imm12), ctx);
return;
}
+ if (val >= 0xffff0000) {
+ op = ARM_MVN_I(rd, 0);
+ next = ARM_BIC_I(rd, rd, 0);
+ val = ~val;
+ }
for (shift = 0; shift < 32; shift += 8) {
u32 part = val & (0xffU << shift);
if (!part)
continue;
- if (first)
- emit(ARM_MOV_I(rd, imm8m(part)), ctx);
- else
- emit(ARM_ORR_I(rd, rd, imm8m(part)), ctx);
- first = false;
+ emit(op | imm8m(part), ctx);
+ op = next;
}
- if (first)
- emit(ARM_MOV_I(rd, 0), ctx);
#else
emit(ARM_MOVW(rd, val & 0xffff), ctx);
if (val > 0xffff)
pw-bot: cr
prev parent reply other threads:[~2026-11-20 19:12 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-11 12:16 [PATCH bpf-next] bpf, arm32: build constants inline instead of using a literal pool Ramin Moussavi
2026-11-11 12:23 ` sashiko-bot
2026-11-20 14:01 ` [PATCH bpf-next v2] " Ramin Moussavi
2026-11-20 19:12 ` Alexei Starovoitov [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=DN09ZA2KX6CC.UVO7HNJWT0EO@gmail.com \
--to=alexei.starovoitov@gmail.com \
--cc=andrii@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=puranjay@kernel.org \
--cc=ramin.moussavi@yacoub.de \
/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