[PATCH 3/4] arm64: Introduce mte_tag_page[s]()
From: Pierre-Clément Tosi
Date: Tue Dec 01 2026 - 09:50:35 EST
The MTE ISA provides two fundamental categories of bulk operations:
1. setting allocation tags (DC GVA, STGM, ST2G) and
2. setting allocation tags while zeroing data (DC GZVA, STZGM, STZ2G)
such that it is natural to have 2 core C primitives, one for each.
Introduce the former, with support for arbitrary tags and multi-page
ranges, implemented through the reworked mte_clear_page_tags() asm
routine, with a C wrapper for argument prepping.
Provide a single-page variant, mte_tag_page(), for convenience.
Define a temporary compatibility wrapper for mte_clear_page_tags().
Note that the new name is now more consistent with PG_mte_tagged and
related helpers set_page_mte_tagged() or folio_set_hugetlb_mte_tagged().
Signed-off-by: Pierre-Clément Tosi <ptosi@xxxxxxxxxx>
---
arch/arm64/include/asm/mte-tagging.h | 26 ++++++++++++++++++++++++++
arch/arm64/include/asm/mte.h | 1 -
arch/arm64/lib/mte.S | 15 ++++++++-------
3 files changed, 34 insertions(+), 8 deletions(-)
diff --git a/arch/arm64/include/asm/mte-tagging.h b/arch/arm64/include/asm/mte-tagging.h
index 5da9c6433fb8..f66e606969c8 100644
--- a/arch/arm64/include/asm/mte-tagging.h
+++ b/arch/arm64/include/asm/mte-tagging.h
@@ -10,4 +10,30 @@
#include <asm/mte.h>
+#ifdef CONFIG_ARM64_MTE
+
+void __mte_tag_page(void *p, u64 t);
+static __always_inline void mte_tag_pages(void *addr, unsigned long npages,
+ u8 tag)
+{
+ u64 tags = 0x1111111111111111ULL * tag;
+
+ do {
+ __mte_tag_page(addr, tags);
+ addr += PAGE_SIZE;
+ } while (--npages);
+}
+
+#else /* CONFIG_ARM64_MTE */
+
+static inline void mte_tag_pages(void *addr, unsigned long n, u8 tag) { }
+
+#endif /* CONFIG_ARM64_MTE */
+
+#define mte_clear_page_tags(p) mte_tag_page(p, 0)
+static __always_inline void mte_tag_page(void *addr, u8 tag)
+{
+ mte_tag_pages(addr, 1, tag);
+}
+
#endif /* __ASM_MTE_TAGGING_H */
diff --git a/arch/arm64/include/asm/mte.h b/arch/arm64/include/asm/mte.h
index ff3d78329be0..3d98d5b8768f 100644
--- a/arch/arm64/include/asm/mte.h
+++ b/arch/arm64/include/asm/mte.h
@@ -18,7 +18,6 @@
#include <asm/pgtable-types.h>
-void mte_clear_page_tags(void *addr);
unsigned long mte_copy_tags_from_user(void *to, const void __user *from,
unsigned long n);
unsigned long mte_copy_tags_to_user(void __user *to, void *from,
diff --git a/arch/arm64/lib/mte.S b/arch/arm64/lib/mte.S
index 5018ac03b6bf..2bd59b877ab6 100644
--- a/arch/arm64/lib/mte.S
+++ b/arch/arm64/lib/mte.S
@@ -24,17 +24,18 @@
.endm
/*
- * Clear the tags in a page
- * x0 - address of the page to be cleared
+ * Tag a page.
+ * x0 - page address
+ * x1 - tags (pre-populated for every granule in a GMID_EL1.BS block)
*/
-SYM_FUNC_START(mte_clear_page_tags)
- multitag_transfer_size x1, x2
-1: stgm xzr, [x0]
- add x0, x0, x1
+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
-SYM_FUNC_END(mte_clear_page_tags)
+SYM_FUNC_END(__mte_tag_page)
/*
* Zero the page and tags at the same time
--
2.56.1.839.g22a8290db9-goog