Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Jirka Hladky <jhladky@redhat.com>
To: will@kernel.org
Cc: catalin.marinas@arm.com, kristina.martsenko@arm.com,
	luyang@redhat.com, dockseed@proton.me, jmario@redhat.com,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: [PATCH v4] arm64: clear_user: keep alignment padding out of the zeroing loop
Date: Thu, 26 Nov 2026 17:15:26 +0100	[thread overview]
Message-ID: <20261126161526.1745191-1-jhladky@redhat.com> (raw)
In-Reply-To: <CAL2CeByu46f48j8O9=237fvhpPUCsKjOZkFuuHU3xrr3wVF5Eg@mail.gmail.com>

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
needlessly executes the padding NOPs. The NOP count is fixed at
assembly time (the assembler aligns the .text section of clear_user.o
to 16 bytes), so the NOPs have been executed on every iteration since
the MOPS update. What link-time layout can change is the position of
the function, in 16-byte increments, and with it whether the NOPs and
the first sttr straddle a cache-line boundary: an irqbypass
reorganisation in 6.17 [1] moved the function, and the loop's cost
showed up as a ~30% /dev/zero read throughput regression on affected
builds.

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@google.com/

Fixes: fe59e0358d9b ("arm64: lib: Use MOPS for usercopy routines")
Reported-by: Luke Yang <luyang@redhat.com>
Suggested-by: Norman Herms <dockseed@proton.me>
Reviewed-by: Kristina Martšenko <kristina.martsenko@arm.com>
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
Cc: stable@vger.kernel.org
Signed-off-by: Jirka Hladky <jhladky@redhat.com>
---
Changes since v3 (commit message only, no code change since v2):

- reworded the explanation per Catalin Marinas: the padding NOP
  count is fixed by the assembler rather than by link-time layout,
  and the NOPs have been in the loop since the MOPS update (the
  irqbypass rework only moved the function)
- dropped the Co-Authored-By trailer per Catalin; for the record,
  this patch and its verification were prepared with the help of an
  AI assistant
- added Cc: stable
---
 arch/arm64/lib/clear_user.S | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/arch/arm64/lib/clear_user.S b/arch/arm64/lib/clear_user.S
index de9a303..143d2f7 100644
--- a/arch/arm64/lib/clear_user.S
+++ b/arch/arm64/lib/clear_user.S
@@ -37,7 +37,8 @@ USER(6f, setet	[x0]!, x1!, xzr)
 	subs	x1, x1, #8
 	b.mi	2f
 
-1:	.p2align 4
+	.p2align 4
+1:
 USER(9f, sttr	xzr, [x0])
 	add	x0, x0, #8
 	subs	x1, x1, #8
-- 
2.56.1



      parent reply	other threads:[~2026-11-26 16:16 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-21  5:04 [PATCH] arm64: clear_user: align __arch_clear_user() to 128B for I-cache efficiency Luke Yang
2025-11-24 13:38 ` Will Deacon
2025-11-25  3:45   ` Luke Yang
2026-11-24 23:30 ` [PATCH v2] arm64: clear_user: keep alignment padding out of the zeroing loop Jirka Hladky
2026-11-25  1:56   ` Jirka Hladky
2026-11-26 12:28   ` Kristina Martšenko
2026-11-26 12:49     ` Jirka Hladky
2026-11-26 12:50 ` [PATCH v3] " Jirka Hladky
2026-11-26 15:24   ` Catalin Marinas
2026-11-26 16:15 ` Jirka Hladky [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=20261126161526.1745191-1-jhladky@redhat.com \
    --to=jhladky@redhat.com \
    --cc=catalin.marinas@arm.com \
    --cc=dockseed@proton.me \
    --cc=jmario@redhat.com \
    --cc=kristina.martsenko@arm.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luyang@redhat.com \
    --cc=stable@vger.kernel.org \
    --cc=will@kernel.org \
    /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