mirror of https://lore.kernel.org/lkml/
 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>
Cc: "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 2/5] arm64: Use STZGM in __mte_tag_clear_page()
Date: Tue, 01 Dec 2026 16:00:53 +0100	[thread overview]
Message-ID: <20261201-mte-page-optim-v1-2-322b9e4096c7@google.com> (raw)
In-Reply-To: <20261201-mte-page-optim-v1-0-322b9e4096c7@google.com>

Prefer STZGM over STZ2G when DC GZVA isn't available (DCZID_EL0.DZP=1).

This speeds up mte_clear_page() by ~1.7-2.0x on Cortex-A7xx and C1-Pro
and ~1.85-1.95x on Cortex-X3/X4 with warm caches. With cold caches,
STZGM stalls seem to be slightly worse (~0.90-0.96x) on these.

The big gains are with the C1-Ultra: ~8.15x (!!) with warm caches and
~4-5x (!) when cold, probably because it now enters streaming mode.

Unfortunately, there is a non-negligible regression on Cortex-A5xx of
~0.68-0.75x (warm) and ~0.85-1.03x (cold) but this seems to be worth the
gains on the larger cores.

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

diff --git a/arch/arm64/include/asm/mte-tagging.h b/arch/arm64/include/asm/mte-tagging.h
index f491682ba418..9c8b39d2dd97 100644
--- a/arch/arm64/include/asm/mte-tagging.h
+++ b/arch/arm64/include/asm/mte-tagging.h
@@ -24,13 +24,13 @@ static __always_inline void mte_tag_pages(void *addr, unsigned long npages,
 	} while (--npages);
 }
 
-void __mte_tag_clear_page(void *p);
+void __mte_tag_clear_page(void *p, u64 t);
 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);
+		__mte_tag_clear_page(addr, tag);
 		addr += PAGE_SIZE;
 	} while (--npages);
 }
diff --git a/arch/arm64/lib/mte.S b/arch/arm64/lib/mte.S
index 1b1b76472f62..0b753db99114 100644
--- a/arch/arm64/lib/mte.S
+++ b/arch/arm64/lib/mte.S
@@ -67,15 +67,13 @@ SYM_FUNC_END(__mte_tag_page)
 /*
  * Tag a page and clear its data.
  *	x0 - page address (pre-tagged)
+ *	x1 - tag
  */
 SYM_FUNC_START(__mte_tag_clear_page)
 	dczid_bs x5, x6, x7, 1f
 	blk_ops	dc, gzva, x0, x5
 1:
-	stz2g	x0, [x0], #(MTE_GRANULE_SIZE * 2)
-	tst	x0, #(PAGE_SIZE - 1)
-	b.ne	1b
-	ret
+	blk_ops	stzgm, x1, x0, x5
 SYM_FUNC_END(__mte_tag_clear_page)
 
 /*

-- 
2.56.1.839.g22a8290db9-goog


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

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01 15:00 [PATCH 0/5] Optimize the MTE page tagging API Pierre-Clément Tosi
2026-12-01 15:00 ` [PATCH 1/5] arm64: Factor out macros in MTE assembly routines Pierre-Clément Tosi
2026-12-01 15:00 ` Pierre-Clément Tosi [this message]
2026-12-01 15:00 ` [PATCH 3/5] arm64: Unroll 2x and align mte_tag_*pages() loops Pierre-Clément Tosi
2026-12-01 15:00 ` [PATCH 4/5] arm64: cpufeature: Add cpucap for DCZID_EL0.DZP Pierre-Clément Tosi
2026-12-01 15:00 ` [PATCH 5/5] arm64: Use ARM64_HAS_DC_ZVA for MTE page tagging 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-optim-v1-2-322b9e4096c7@google.com \
    --to=ptosi@google.com \
    --cc=catalin.marinas@arm.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=ryan.roberts@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®