[PATCH 5/5] arm64: Use ARM64_HAS_DC_ZVA for MTE page tagging
Pierre-Clément Tosi
ptosi at google.com
Tue Dec 1 07:00:56 PST 2026
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 at 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
More information about the linux-arm-kernel
mailing list