From: "Pierre-Clément Tosi" <ptosi@google.com>
To: Catalin Marinas <catalin.marinas@arm.com>, Will Deacon <will@kernel.org>
Cc: "Mark Rutland" <mark.rutland@arm.com>,
"Ryan Roberts" <ryan.roberts@arm.com>,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org,
"Pierre-Clément Tosi" <ptosi@google.com>
Subject: [PATCH 1/5] arm64: Factor out macros in MTE assembly routines
Date: Tue, 01 Dec 2026 16:00:52 +0100 [thread overview]
Message-ID: <20261201-mte-page-optim-v1-1-322b9e4096c7@google.com> (raw)
In-Reply-To: <20261201-mte-page-optim-v1-0-322b9e4096c7@google.com>
Factor out extraction of DCZID_EL0.BS and jumping to a DZP=1 fallback
into a helper macro, dczid_bs.
Introduce blk_ops (and its blk_op abstraction) to centralize the single
instruction loop pattern used to implement each of the sub-routines.
This will allow future changes to be limited that macro.
No functional change intended.
Signed-off-by: Pierre-Clément Tosi <ptosi@google.com>
---
arch/arm64/lib/mte.S | 56 ++++++++++++++++++++++++++++++++++------------------
1 file changed, 37 insertions(+), 19 deletions(-)
diff --git a/arch/arm64/lib/mte.S b/arch/arm64/lib/mte.S
index 012577641b6b..1b1b76472f62 100644
--- a/arch/arm64/lib/mte.S
+++ b/arch/arm64/lib/mte.S
@@ -23,18 +23,45 @@
lsl \reg, \tmp, \reg
.endm
+/*
+ * dczid_bs - set \bs to DCZID_EL0.BS and branch to \dzp_label when DZP=1.
+ */
+ .macro dczid_bs, bs, tmp, dczid, dzp_label
+ mrs \dczid, dczid_el0
+ and \bs, \dczid, #DCZID_EL0_BS_MASK
+ mov \tmp, #4
+ lsl \bs, \tmp, \bs
+ tbnz \dczid, #DCZID_EL0_DZP_SHIFT, \dzp_label
+ .endm
+
+/*
+ * blk_ops - execute \insn \arg every \bs over the page at \addr.
+ */
+ .macro blk_op, insn, arg, addr, step:vararg
+ .ifc \insn, dc
+ dc \arg, \addr
+ .else
+ \insn \arg, [\addr]
+ .endif
+ add \addr, \addr, \step
+ .endm
+
+ .macro blk_ops, insn, arg, addr, bs
+.Lblk_loop_\@:
+ blk_op \insn, \arg, \addr, \bs
+ tst \addr, #(PAGE_SIZE - 1)
+ b.ne .Lblk_loop_\@
+ ret
+ .endm
+
/*
* Tag a page.
* x0 - page address
* x1 - tags (pre-populated for every granule in a GMID_EL1.BS block)
*/
SYM_FUNC_START(__mte_tag_page)
- multitag_transfer_size x2, x3
-1: stgm x1, [x0]
- add x0, x0, x2
- tst x0, #(PAGE_SIZE - 1)
- b.ne 1b
- ret
+ multitag_transfer_size x5, x6
+ blk_ops stgm, x1, x0, x5
SYM_FUNC_END(__mte_tag_page)
/*
@@ -42,22 +69,13 @@ SYM_FUNC_END(__mte_tag_page)
* x0 - page address (pre-tagged)
*/
SYM_FUNC_START(__mte_tag_clear_page)
- mrs x1, dczid_el0
- tbnz x1, #4, 2f // Branch if DC GZVA is prohibited
- and w1, w1, #0xf
- mov x2, #4
- lsl x1, x2, x1
-
-1: dc gzva, x0
- add x0, x0, x1
+ dczid_bs x5, x6, x7, 1f
+ blk_ops dc, gzva, x0, x5
+1:
+ stz2g x0, [x0], #(MTE_GRANULE_SIZE * 2)
tst x0, #(PAGE_SIZE - 1)
b.ne 1b
ret
-
-2: stz2g x0, [x0], #(MTE_GRANULE_SIZE * 2)
- tst x0, #(PAGE_SIZE - 1)
- b.ne 2b
- ret
SYM_FUNC_END(__mte_tag_clear_page)
/*
--
2.56.1.839.g22a8290db9-goog
next prev parent reply other threads:[~2026-12-01 15:01 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-01 15:00 [PATCH 0/5] Optimize the MTE page tagging API Pierre-Clément Tosi
2026-12-01 15:00 ` Pierre-Clément Tosi [this message]
2026-12-01 15:00 ` [PATCH 2/5] arm64: Use STZGM in __mte_tag_clear_page() Pierre-Clément Tosi
2026-12-01 15:00 ` [PATCH 3/5] arm64: Unroll 2x and align mte_tag_*pages() loops Pierre-Clément Tosi
2026-12-01 15:00 ` [PATCH 4/5] arm64: cpufeature: Add cpucap for DCZID_EL0.DZP Pierre-Clément Tosi
2026-12-01 15:00 ` [PATCH 5/5] arm64: Use ARM64_HAS_DC_ZVA for MTE page tagging Pierre-Clément Tosi
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=20261201-mte-page-optim-v1-1-322b9e4096c7@google.com \
--to=ptosi@google.com \
--cc=catalin.marinas@arm.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=ryan.roberts@arm.com \
--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
all inboxes | Powered by JetHome®