Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "Pierre-Clément Tosi" <ptosi@google.com>
To: Catalin Marinas <catalin.marinas@arm.com>,
	Will Deacon <will@kernel.org>,
	 "Lorenzo Stoakes (ARM)" <ljs@kernel.org>,
	Vincenzo Frascino <vincenzo.frascino@arm.com>
Cc: "Marc Zyngier" <maz@kernel.org>,
	"Fuad Tabba" <fuad.tabba@linux.dev>,
	"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 4/4] arm64: Introduce mte_[tag_]clear_page[s]()
Date: Tue, 01 Dec 2026 15:49:20 +0100	[thread overview]
Message-ID: <20261201-mte-page-api-v1-4-5e38d19462ea@google.com> (raw)
In-Reply-To: <20261201-mte-page-api-v1-0-5e38d19462ea@google.com>

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 latter, with support for arbitrary tags and multi-page
ranges, implemented through the reworked mte_zero_clear_page_tags() asm
routine, with a C wrapper for argument prepping.

Provide a single-page variant, mte_tag_clear_page(), for convenience.

Since these functions have the combined effects of mte_tag_page[s]() and
clear_page[s](), name them mte_tag_clear_page[s](). This aligns with
the arch-agnostic tag_clear_highpages() and keeps the term "clear" for
data (instead of "zero"), similarly to common kernel mm APIs such as
clear_page[s](), clear_highpage(), clear_user_page(), etc.

Provide concise and convenient "clear-all" helpers: mte_clear_page[s]().

In total, this results in the following API and effects:

                      function                 data       tags
       --------------------------------      ------     ------
               clear_page[s](p[, n])           0          -
           mte_clear_page[s](p[, n])           0          0
       mte_tag_clear_page[s](p[, n], t)        0          t
             mte_tag_page[s](p[, n], 0)        -          0
             mte_tag_page[s](p[, n], t)        -          t

Define a temporary compatibility wrapper for mte_zero_clear_page_tags().

Signed-off-by: Pierre-Clément Tosi <ptosi@google.com>
---
 arch/arm64/include/asm/mte-tagging.h | 28 ++++++++++++++++++++++++++++
 arch/arm64/include/asm/mte.h         |  4 ----
 arch/arm64/lib/mte.S                 | 11 ++++-------
 arch/arm64/mm/proc.S                 |  8 ++++----
 4 files changed, 36 insertions(+), 15 deletions(-)

diff --git a/arch/arm64/include/asm/mte-tagging.h b/arch/arm64/include/asm/mte-tagging.h
index f66e606969c8..f491682ba418 100644
--- a/arch/arm64/include/asm/mte-tagging.h
+++ b/arch/arm64/include/asm/mte-tagging.h
@@ -24,16 +24,44 @@ static __always_inline void mte_tag_pages(void *addr, unsigned long npages,
 	} while (--npages);
 }
 
+void __mte_tag_clear_page(void *p);
+static __always_inline void mte_tag_clear_pages(void *addr,
+						unsigned long npages, u8 tag)
+{
+	addr = mte_tagged(addr, tag);
+	do {
+		__mte_tag_clear_page(addr);
+		addr += PAGE_SIZE;
+	} while (--npages);
+}
+
 #else /* CONFIG_ARM64_MTE */
 
 static inline void mte_tag_pages(void *addr, unsigned long n, u8 tag) { }
+static inline void mte_tag_clear_pages(void *addr, unsigned long n, u8 tag) { }
 
 #endif /* CONFIG_ARM64_MTE */
 
+static __always_inline void mte_clear_pages(void *addr, unsigned long npages)
+{
+	mte_tag_clear_pages(addr, npages, 0);
+}
+
 #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);
 }
 
+static __always_inline void mte_tag_clear_page(void *addr, u8 tag)
+{
+	mte_tag_clear_pages(addr, 1, tag);
+}
+
+#define mte_zero_clear_page_tags(p)	mte_clear_page(p)
+static __always_inline void mte_clear_page(void *addr)
+{
+	mte_clear_pages(addr, 1);
+}
+
 #endif /* __ASM_MTE_TAGGING_H */
diff --git a/arch/arm64/include/asm/mte.h b/arch/arm64/include/asm/mte.h
index 3d98d5b8768f..d84f12f20277 100644
--- a/arch/arm64/include/asm/mte.h
+++ b/arch/arm64/include/asm/mte.h
@@ -92,7 +92,6 @@ static inline bool try_page_mte_tagging(struct page *page)
 	return false;
 }
 
-void mte_zero_clear_page_tags(void *addr);
 void mte_clear_folio_tags(struct folio *folio);
 void mte_sync_tags(pte_t pte, unsigned int nr_pages);
 void mte_copy_page_tags(void *kto, const void *kfrom);
@@ -123,9 +122,6 @@ static inline bool try_page_mte_tagging(struct page *page)
 {
 	return false;
 }
-static inline void mte_zero_clear_page_tags(void *addr)
-{
-}
 static inline void mte_clear_folio_tags(struct folio *folio)
 {
 }
diff --git a/arch/arm64/lib/mte.S b/arch/arm64/lib/mte.S
index 2bd59b877ab6..012577641b6b 100644
--- a/arch/arm64/lib/mte.S
+++ b/arch/arm64/lib/mte.S
@@ -38,13 +38,10 @@ SYM_FUNC_START(__mte_tag_page)
 SYM_FUNC_END(__mte_tag_page)
 
 /*
- * Zero the page and tags at the same time
- *
- * Parameters:
- *	x0 - address to the beginning of the page
+ * Tag a page and clear its data.
+ *	x0 - page address (pre-tagged)
  */
-SYM_FUNC_START(mte_zero_clear_page_tags)
-	and	x0, x0, #(1 << MTE_TAG_SHIFT) - 1	// clear the tag
+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
@@ -61,7 +58,7 @@ SYM_FUNC_START(mte_zero_clear_page_tags)
 	tst	x0, #(PAGE_SIZE - 1)
 	b.ne	2b
 	ret
-SYM_FUNC_END(mte_zero_clear_page_tags)
+SYM_FUNC_END(__mte_tag_clear_page)
 
 /*
  * Copy the tags from the source page to the destination one
diff --git a/arch/arm64/mm/proc.S b/arch/arm64/mm/proc.S
index 12aacc74f764..85b8be719a1e 100644
--- a/arch/arm64/mm/proc.S
+++ b/arch/arm64/mm/proc.S
@@ -50,10 +50,10 @@
 
 #ifdef CONFIG_ARM64_MTE
 /*
- * The mte_zero_clear_page_tags() implementation uses DC GZVA, which relies on
- * TBI being enabled at EL1.  TCMA1 is needed to treat accesses with the
- * match-all tag (0xF) as Tag Unchecked, irrespective of the SCTLR_EL1.TCF
- * setting.
+ * MTE tagging routines pass tagged kernel addresses to DC G(Z)VA, which would
+ * trigger TTBR1 level 0 translation faults unless we set TBI1. TCMA1 is needed
+ * to treat accesses with the match-all tag (0xF) as Tag Unchecked, irrespective
+ * of the SCTLR_EL1.TCF setting.
  */
 #define TCR_MTE_FLAGS TCR_EL1_TCMA1 | TCR_EL1_TBI1 | TCR_EL1_TBID1
 #else

-- 
2.56.1.839.g22a8290db9-goog



      parent reply	other threads:[~2026-12-01 17:34 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01 14:49 [PATCH 0/4] Expand MTE tagging API to multi-page and !0 tags Pierre-Clément Tosi
2026-12-01 14:49 ` [PATCH 1/4] arm64: Introduce mte_tag_of()/mte_tagged() helpers Pierre-Clément Tosi
2026-12-01 14:49 ` [PATCH 2/4] arm64: Introduce <asm/mte-tagging.h> Pierre-Clément Tosi
2026-12-01 14:49 ` [PATCH 3/4] arm64: Introduce mte_tag_page[s]() Pierre-Clément Tosi
2026-12-01 14:49 ` 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-api-v1-4-5e38d19462ea@google.com \
    --to=ptosi@google.com \
    --cc=catalin.marinas@arm.com \
    --cc=fuad.tabba@linux.dev \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ljs@kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=maz@kernel.org \
    --cc=ryan.roberts@arm.com \
    --cc=vincenzo.frascino@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