From: "Pierre-Clément Tosi" <ptosi@google.com>
To: Catalin Marinas <catalin.marinas@arm.com>,
Fuad Tabba <fuad.tabba@linux.dev>,
"Lorenzo Stoakes (ARM)" <ljs@kernel.org>,
Will Deacon <will@kernel.org>
Cc: "Vincenzo Frascino" <vincenzo.frascino@arm.com>,
"Mark Rutland" <mark.rutland@arm.com>,
"Marc Zyngier" <maz@kernel.org>,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, kvmarm@lists.linux.dev,
"Pierre-Clément Tosi" <ptosi@google.com>
Subject: [PATCH 2/3] arm64: Introduce mte_tag_[clear_]folio()
Date: Tue, 01 Dec 2026 15:56:24 +0100 [thread overview]
Message-ID: <20261201-mte-page-helpers-v1-2-5aab4a7a7ebc@google.com> (raw)
In-Reply-To: <20261201-mte-page-helpers-v1-0-5aab4a7a7ebc@google.com>
Add mte_tag_[clear_]page[s]() wrappers for struct folio *. This should
prevent issues like what commit cbf47fe57a56 ("KVM: arm64: Clear the
whole hugetlb folio when sanitising MTE tags") had to fix.
Use this API in place of the other ones where beneficial.
Signed-off-by: Pierre-Clément Tosi <ptosi@google.com>
---
arch/arm64/include/asm/mte-tagging.h | 15 +++++++++++++++
arch/arm64/include/asm/mte.h | 4 ----
arch/arm64/kernel/mte.c | 7 +------
arch/arm64/kvm/guest.c | 2 +-
arch/arm64/kvm/mmu.c | 2 +-
5 files changed, 18 insertions(+), 12 deletions(-)
diff --git a/arch/arm64/include/asm/mte-tagging.h b/arch/arm64/include/asm/mte-tagging.h
index 112ee5f3fe86..0b429f8104f7 100644
--- a/arch/arm64/include/asm/mte-tagging.h
+++ b/arch/arm64/include/asm/mte-tagging.h
@@ -67,6 +67,21 @@ static __always_inline void mte_clear_highpages(struct page *page,
mte_clear_pages(page_address(page), npages);
}
+static __always_inline void mte_tag_folio(struct folio *folio, u8 tag)
+{
+ mte_tag_pages(folio_address(folio), folio_nr_pages(folio), tag);
+}
+
+static __always_inline void mte_tag_clear_folio(struct folio *folio, u8 tag)
+{
+ mte_tag_clear_pages(folio_address(folio), folio_nr_pages(folio), tag);
+}
+
+static __always_inline void mte_clear_folio(struct folio *folio)
+{
+ mte_clear_pages(folio_address(folio), folio_nr_pages(folio));
+}
+
#define mte_clear_page_tags(p) mte_tag_page(p, 0)
static __always_inline void mte_tag_page(void *addr, u8 tag)
{
diff --git a/arch/arm64/include/asm/mte.h b/arch/arm64/include/asm/mte.h
index d84f12f20277..c63a077f50ca 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_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);
void mte_thread_init_user(void);
@@ -122,9 +121,6 @@ static inline bool try_page_mte_tagging(struct page *page)
{
return false;
}
-static inline void mte_clear_folio_tags(struct folio *folio)
-{
-}
static inline void mte_sync_tags(pte_t pte, unsigned int nr_pages)
{
}
diff --git a/arch/arm64/kernel/mte.c b/arch/arm64/kernel/mte.c
index f39f1025a5e9..fef26b574106 100644
--- a/arch/arm64/kernel/mte.c
+++ b/arch/arm64/kernel/mte.c
@@ -37,11 +37,6 @@ DEFINE_STATIC_KEY_FALSE(mte_async_or_asymm_mode);
EXPORT_SYMBOL_GPL(mte_async_or_asymm_mode);
#endif
-void mte_clear_folio_tags(struct folio *folio)
-{
- mte_tag_highpages(folio_page(folio, 0), folio_nr_pages(folio), 0);
-}
-
void mte_sync_tags(pte_t pte, unsigned int nr_pages)
{
struct page *page = pte_page(pte);
@@ -51,7 +46,7 @@ void mte_sync_tags(pte_t pte, unsigned int nr_pages)
if (folio_test_hugetlb(folio)) {
/* A hugetlb folio is marked tagged as a whole, so clear every page */
if (folio_try_hugetlb_mte_tagging(folio)) {
- mte_clear_folio_tags(folio);
+ mte_tag_folio(folio, 0);
folio_set_hugetlb_mte_tagged(folio);
}
diff --git a/arch/arm64/kvm/guest.c b/arch/arm64/kvm/guest.c
index fc6d067b97ef..78020e1abaa8 100644
--- a/arch/arm64/kvm/guest.c
+++ b/arch/arm64/kvm/guest.c
@@ -1065,7 +1065,7 @@ int kvm_vm_ioctl_mte_copy_tags(struct kvm *kvm,
*/
if (folio_test_hugetlb(folio)) {
if (folio_try_hugetlb_mte_tagging(folio))
- mte_clear_folio_tags(folio);
+ mte_tag_folio(folio, 0);
} else {
try_page_mte_tagging(page);
}
diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c
index e532ddb03963..f5e758d28b89 100644
--- a/arch/arm64/kvm/mmu.c
+++ b/arch/arm64/kvm/mmu.c
@@ -1620,7 +1620,7 @@ static void sanitise_mte_tags(struct kvm *kvm, kvm_pfn_t pfn,
if (folio_test_hugetlb(folio)) {
/* A hugetlb folio is marked tagged as a whole, so clear every page */
if (folio_try_hugetlb_mte_tagging(folio)) {
- mte_clear_folio_tags(folio);
+ mte_tag_folio(folio, 0);
folio_set_hugetlb_mte_tagged(folio);
}
return;
--
2.56.1.839.g22a8290db9-goog
next prev parent reply other threads:[~2026-12-01 14:56 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-01 14:56 [PATCH 0/3] Introduce MTE page tagging helper APIs Pierre-Clément Tosi
2026-12-01 14:56 ` [PATCH 1/3] arm64: Introduce mte_tag_[clear_]highpage[s]() Pierre-Clément Tosi
2026-12-01 14:56 ` Pierre-Clément Tosi [this message]
2026-12-01 14:56 ` [PATCH 3/3] arm64: Remove mte_clear_page_tags() Pierre-Clément Tosi
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-helpers-v1-2-5aab4a7a7ebc@google.com \
--to=ptosi@google.com \
--cc=catalin.marinas@arm.com \
--cc=fuad.tabba@linux.dev \
--cc=kvmarm@lists.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=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
all inboxes | Powered by JetHome®