Re: [PATCH v3] arm64: clear_user: keep alignment padding out of the zeroing loop
From: Catalin Marinas
Date: Thu Nov 26 2026 - 10:24:38 EST
On Thu, Nov 26, 2026 at 01:50:33PM +0100, Jirka Hladky wrote:
> Commit fe59e0358d9b ("arm64: lib: Use MOPS for usercopy routines")
> restructured __arch_clear_user() and moved the loop alignment inside
> the function. In doing so, the loop label ended up in front of its
> own alignment directive:
>
> 1: .p2align 4
> USER(9f, sttr xzr, [x0])
> add x0, x0, #8
> subs x1, x1, #8
> b.hi 1b
>
> The backward branch at the bottom of the loop therefore lands in the
> alignment padding, and every iteration of the 8-byte zeroing loop
> executes however many padding NOPs the linker happened to need (0-3).
> Because that count depends on where the function lands, unrelated
> code changes anywhere in the kernel can shift /dev/zero read
> performance: an irqbypass reorganisation in 6.17 [1] left two NOPs
> in the loop and cost about 30% of /dev/zero read throughput on
> affected builds.
The NOPs don't change at link time. The assembler already ensures that
the .text section of clear_user.o is 16-byte aligned (due to the
.p2align 4). What can change though is the position of the function in
16-byte increments and the two NOPs inserted before the sttr can indeed
cross a cache-line boundary. The loop executes the NOPs unnecessarily.
The irqbypass rework only moved the function. The NOPs have been in the
loop since the MOPS update.
> Norman Herms diagnosed this and proposed moving the label below the
> directive, so the padding is executed only once on the fall-through
> path and the loop body starts 16-byte aligned as intended:
>
> .p2align 4
> 1:
> USER(9f, sttr xzr, [x0])
>
> Measured on Ampere Altra (Neoverse N1, no FEAT_MOPS), reading 4 GiB
> from /dev/zero, two otherwise identical kernels built from the same
> tree and toolchain, differing only in this change (two NOPs of
> padding in the unpatched loop):
>
> kernel instructions per MiB: 797.5k -> 536.4k
> throughput: 11.6 GB/s -> 22.3 GB/s (+92%)
>
> The instruction delta is exactly the two removed NOPs: 2 x 131072
> instructions per MiB at 8 bytes per iteration.
>
> [1] https://lore.kernel.org/all/20250516230734.2564775-6-seanjc@xxxxxxxxxx/
>
> Fixes: fe59e0358d9b ("arm64: lib: Use MOPS for usercopy routines")
> Reported-by: Luke Yang <luyang@xxxxxxxxxx>
> Suggested-by: Norman Herms <dockseed@xxxxxxxxx>
> Reviewed-by: Kristina Martšenko <kristina.martsenko@xxxxxxx>
> Signed-off-by: Jirka Hladky <jhladky@xxxxxxxxxx>
>
> Co-Authored-By: Claude Code <noreply@xxxxxxxxxxxxx>
Nit: empty line in the trailers block. Also we shouldn't really add
co-authored-by: claude. You can mention it the cover letter (if any) or
the text below ---.
And probably a Cc: stable.
The fix looks fine otherwise, so:
Reviewed-by: Catalin Marinas <catalin.marinas@xxxxxxx>