[PATCH 0/5] Optimize the MTE page tagging API
From: Pierre-Clément Tosi
Date: Tue Dec 01 2026 - 10:01:21 EST
(Based on my previous generalization of the API [1])
This series aims to speed up the MTE page-tagging functions, to improve
performance of tagged memory allocation and, once it starts using it,
page-based KASAN poisoning.
It achieves this as follows:
- patch 2 replaces STZ2G with STZGM when DCZID_EL0.DZP=1, which behaves
better on every MTE-capable Tensor core, expect for older Cortex-A5xx
- patch 3 unrolls the loops 2x and removes the branch-per-page by moving
the per-page loop into the ASM routines. This helps the in-order cores
- patch 5 selects between the DC and always-available altertive with a
static branch
Note that DC GVA is not used by this series, as it introduces great
gains on the little cores but also regressions. I'll do that in a
separate series once the mitigations to the regressions have also been
merged. At that point, the tag-only routine will also make use of the
ARM64_HAS_DC_ZVA cpucap introduced for patch 5.
Here are the per-call speedups I measure, when called on a single page:
(cache=warm) mte_tag_pages(1) mte_clear_pages(1)
============== ========================== ==========================
[SoC:CPU]Model DZP=0 DZP=1 DZP=0 DZP=1
============== ============ ============ ============ ============
[G3:3]A510 1.31-1.32x 1.31x 0.94-0.96x 0.97x
[G4:3]A520 1.73x 1.73x 0.96x ~
[G5:1]A520 1.72-1.76x 1.73-1.77x 0.93-1.00x 1.02-1.04x
[G3:7]A715 1.28x 1.28x 1.17-1.18x 2.35-2.37x
[G4:6]A720 1.37-1.42x 1.39-1.46x 1.22-1.32x 2.46-2.48x
[G5:4]A725 1.30-1.35x 1.29-1.36x 1.24-1.29x 2.36-2.37x
[G5:6]A725 1.32-1.34x 1.31-1.38x 1.26-1.30x 2.38-2.41x
[G6:1]C1-Pro 1.20-1.23x 1.18-1.22x 1.10-1.17x 2.09-2.15x
[G6:5]C1-Pro 1.20-1.24x 1.18-1.21x 1.08-1.13x 2.11-2.20x
[G3:8]X3 1.16x 1.15-1.17x 1.16x 2.31-2.33x
[G4:7]X4 1.17-1.18x 1.16-1.18x 1.16-1.17x 2.09x
[G5:7]X4 1.15-1.18x 1.16-1.17x 1.15-1.17x 2.08-2.09x
[G6:6]C1-Ultra 1.14-1.22x 1.16-1.18x 1.15-1.23x 9.56-9.57x
============== ============ ============ ============ ============
(cache=cold) mte_tag_pages(1) mte_clear_pages(1)
============== ========================== ==========================
[SoC:CPU]Model DZP=0 DZP=1 DZP=0 DZP=1
============== ============ ============ ============ ============
[G3:3]A510 1.10x 1.10x ~ 0.91x
[G4:3]A520 1.11x 1.11x 1.03x 0.94x
[G5:1]A520 1.02-1.03x 1.03x ~ ~
[G3:7]A715 ~ ~ ~ ~
[G4:6]A720 ~ ~ ~ ~
[G5:4]A725 1.02-1.03x ~ ~ 0.93-0.94x
[G5:6]A725 1.03x 1.02-1.03x 1.02-1.03x 0.93-0.95x
[G6:1]C1-Pro ~ ~ 0.96-1.02x 0.93-0.95x
[G6:5]C1-Pro ~ ~ 0.97-0.99x 0.94-0.96x
[G3:8]X3 0.88-0.90x 0.87-0.91x 1.01-1.05x 0.96-0.99x
[G4:7]X4 1.39-1.45x 1.35-1.40x 1.32-1.50x 1.33-1.50x
[G5:7]X4 1.02-1.03x 1.03x ~ ~
[G6:6]C1-Ultra 3.59-3.81x 2.88-4.22x ~ 4.88-5.04x
============== ============ ============ ============ ============
At higher page counts, the Cortex-A5xx keep their gains from the unroll
on warm pages (~1.15-1.60x at 4x4K pages) and assymptotically reach
~1.10x gains on larger (or cold) ranges, measure up to 512x4k pages.
On the Cortex-A7xx/X3/X4 and C1-Pro, the STZGM gains remain at ~1.6-2.2x
for 4x4k warm pages, and ~1.3-1.6x for Cortex-A7xx/X3 and ~1.9-2.6x for
Cortex-X4 at 512x4k "warm" (non-L1) pages.
The gains on the C1-Ultra from both unrolling and STZGM are spectacular,
likely because it now reliably enters write streaming mode and stops
stalling on cache misses: mte_tag_pages() is still ~1.1-1.15x faster on
4x4k cold pages but most impressive is mte_clear_pages() under DZP=1
being ~10x faster on 4x4k warm pages, ~23x on 512x4k "warm" pages, ~25x
on 4x4k cold pages and ~29x on 512x4k cold pages.
Methodology for measuring function-level speedups:
- This series was profiled on Google Tensor G3 through G6, running the
Android Common Kernel (branch android16-6.12). Unfortunately, all were
pre-production devices. Although I am fairly confident in the 'warm'
results, I recommend taking some 'cold' results with a grain of salt,
as they might not accurately represent actual production devices. It's
worth noting that all of the evaluated CPUs were Arm designs and I
would appreciate confirmation that the results presented here carry
over to other microarchitectures.
- Per-commit improvements were measured by loading variants of the
functions with and without the change under test. They were called
repeatedly and their execution timed, each iteration interleaving them
at random and using one of 16 separately allocated tagged buffers
(assumed scattered around memory, to alleviate channel interference).
Before each run, the D-cache entries for the buffer were populated
through accesses ("warm") or tags and data invalidated ("cold"). These
were measured across multiple insmods (to reduce code placement
impact), with the task pinned, IRQs masked, the CPU pinned to the
mid-point of its OPP range, while DSU and DDR were pinned at 100%.
- Every device had DCZID_EL0.DZP=0 so the DZP=1 fallbacks were tested by
adding a mask to each MRS, provided to the module at insmod (i.e. not
optimizable by the compiler), with only one value passed per insmod,
as the branch predictors were otherwise impacting the measurements.
- Function execution time is measured through PMCCNTR_EL0 samples.
Specifically, the execution included no DSB before the post-run sample
(only ISB). This is because I wanted to measure function-level CPU
latency, not HW properties. In real-world scenarios, I am assuming
that the code after the execution of these high-bandwidth calls will
statistically have a significantly lower store rate. Therefore, under
these conditions, implementations that manage to "pack" the CPU
writeback queue are favored as they permit the CPU to already execute
what follows. A DSB would add an artificial stall to that execution.
- Most commits in this series (and the tables above) report speedup
ranges; those represent one standard deviation around the mean of the
paired-observation speedup ratios (old over new version) between their
interquartile means (IQM), measured across 10 insmods each of 2000
executions, interleaved as described above.
[1]: https://lore.kernel.org/linux-arm-kernel/20261201-mte-page-api-v1-0-5e38d19462ea@xxxxxxxxxx
Signed-off-by: Pierre-Clément Tosi <ptosi@xxxxxxxxxx>
---
Pierre-Clément Tosi (5):
arm64: Factor out macros in MTE assembly routines
arm64: Use STZGM in __mte_tag_clear_page()
arm64: Unroll 2x and align mte_tag_*pages() loops
arm64: cpufeature: Add cpucap for DCZID_EL0.DZP
arm64: Use ARM64_HAS_DC_ZVA for MTE page tagging
arch/arm64/include/asm/mte-tagging.h | 20 ++++----
arch/arm64/kernel/cpufeature.c | 14 ++++++
arch/arm64/lib/mte.S | 91 ++++++++++++++++++++++++------------
arch/arm64/tools/cpucaps | 1 +
4 files changed, 86 insertions(+), 40 deletions(-)
---
base-commit: 012e4bc01e339a65dc7c59181b5efb33b171d12c
change-id: 20261129-mte-page-optim-b66637b0b427
prerequisite-change-id: 20261129-mte-page-api-f285a514f1ad:v1
prerequisite-patch-id: fc2943d14606f01e9594700b3b8e616a4e66d1d7
prerequisite-patch-id: 87fc04e73de4eaf7d0d5ab4be5718e362dc47409
prerequisite-patch-id: 0925d5cf3e744a9d6a71462a7198cfea73bb737c
prerequisite-patch-id: 1ef6c57e30b209f30577f98d8e289e77977964ed
Best regards,
--
Pierre-Clément Tosi <ptosi@xxxxxxxxxx>