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 3/4] arm64: Introduce mte_tag_page[s]()
Date: Tue, 01 Dec 2026 15:49:19 +0100	[thread overview]
Message-ID: <20261201-mte-page-api-v1-3-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 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@google.com>
---
 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



      parent reply	other threads:[~2026-12-01 14:50 UTC|newest]

Thread overview: 4+ 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 ` 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-3-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