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 5/5] arm64: Use ARM64_HAS_DC_ZVA for MTE page tagging
Date: Tue, 01 Dec 2026 16:00:56 +0100 [thread overview]
Message-ID: <20261201-mte-page-optim-v1-5-322b9e4096c7@google.com> (raw)
In-Reply-To: <20261201-mte-page-optim-v1-0-322b9e4096c7@google.com>
Use ARM64_HAS_DC_ZVA to static branch to either the STZGM- or DC-based
backend of mte_tag_clear_pages() and split __mte_tag_clear_pages
accordingly.
Do this from the thin mte-tagging.h inline wrapper so that clients
directly call into the appropriate routine. This gives an always-safe
mte_tag_clear_pages() since alternative_has_cap_likely() defaults to
false i.e. STZGM, which is always available when MTE2 is supported.
Note that we still read DCZID_EL0 to extract the block size, which a
later commit will optimize out.
Signed-off-by: Pierre-Clément Tosi <ptosi@google.com>
---
arch/arm64/include/asm/mte-tagging.h | 7 ++++++-
arch/arm64/lib/mte.S | 26 +++++++++++++++++---------
2 files changed, 23 insertions(+), 10 deletions(-)
diff --git a/arch/arm64/include/asm/mte-tagging.h b/arch/arm64/include/asm/mte-tagging.h
index 944636ef3559..eb93e4c44db6 100644
--- a/arch/arm64/include/asm/mte-tagging.h
+++ b/arch/arm64/include/asm/mte-tagging.h
@@ -8,6 +8,7 @@
#ifndef __ASM_MTE_TAGGING_H
#define __ASM_MTE_TAGGING_H
+#include <asm/alternative-macros.h>
#include <asm/mte.h>
#ifdef CONFIG_ARM64_MTE
@@ -22,10 +23,14 @@ static __always_inline void mte_tag_pages(void *addr, unsigned long npages,
}
void __mte_tag_clear_pages(void *p, unsigned long n, u64 t);
+void __mte_tag_clear_pages_dc(void *p, unsigned long n);
static __always_inline void mte_tag_clear_pages(void *addr,
unsigned long npages, u8 tag)
{
- __mte_tag_clear_pages(mte_tagged(addr, tag), npages, tag);
+ if (alternative_has_cap_likely(ARM64_HAS_DC_ZVA))
+ __mte_tag_clear_pages_dc(mte_tagged(addr, tag), npages);
+ else
+ __mte_tag_clear_pages(addr, npages, tag);
}
#else /* CONFIG_ARM64_MTE */
diff --git a/arch/arm64/lib/mte.S b/arch/arm64/lib/mte.S
index 7d971dd1a36e..962a8f4eb63c 100644
--- a/arch/arm64/lib/mte.S
+++ b/arch/arm64/lib/mte.S
@@ -25,14 +25,13 @@
.endm
/*
- * dczid_bs - set \bs to DCZID_EL0.BS and branch to \dzp_label when DZP=1.
+ * dczid_bs - set \bs to DCZID_EL0.BS.
*/
- .macro dczid_bs, bs, tmp, dczid, dzp_label
- mrs \dczid, dczid_el0
- and \bs, \dczid, #DCZID_EL0_BS_MASK
+ .macro dczid_bs, bs, tmp
+ mrs \tmp, dczid_el0
+ and \bs, \tmp, #DCZID_EL0_BS_MASK
mov \tmp, #4
lsl \bs, \tmp, \bs
- tbnz \dczid, #DCZID_EL0_DZP_SHIFT, \dzp_label
.endm
/*
@@ -73,18 +72,27 @@ SYM_FUNC_END(__mte_tag_pages)
/*
* Tag a page-aligned region and clear its data.
- * x0 - region start (pre-tagged)
+ * x0 - region start
* x1 - number of pages
* x2 - tag
*/
.p2align L1_CACHE_SHIFT
SYM_FUNC_START(__mte_tag_clear_pages)
- dczid_bs x5, x6, x7, 1f
- blk_ops dc, gzva, x0, x1, x5, x6
-1:
+ dczid_bs x5, x6
blk_ops stzgm, x2, x0, x1, x5, x6
SYM_FUNC_END(__mte_tag_clear_pages)
+/*
+ * Tag a page-aligned region and clear its data (requires DCZID_EL0.DZP=0).
+ * x0 - region start (pre-tagged)
+ * x1 - number of pages
+ */
+ .p2align L1_CACHE_SHIFT
+SYM_FUNC_START(__mte_tag_clear_pages_dc)
+ dczid_bs x5, x6
+ blk_ops dc, gzva, x0, x1, x5, x6
+SYM_FUNC_END(__mte_tag_clear_pages_dc)
+
/*
* Copy the tags from the source page to the destination one
* x0 - address of the destination page
--
2.56.1.839.g22a8290db9-goog
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 ` [PATCH 1/5] arm64: Factor out macros in MTE assembly routines Pierre-Clément Tosi
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 ` Pierre-Clément Tosi [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=20261201-mte-page-optim-v1-5-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®