From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.208.70 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796137276; b=WxPmzytapQzG8rITyi8HlYPnR2bKNB12YC6RCTxpcYd6dtUlBsgnR+r6JcpwJmQtzeoc aaRMHg32d4cE40FDeqf3ny1JHXQgDZs2s+49sDnmyxx+giDh55tZ9d8FUJxMIY0BBXlDb QKpSghM4oYYU6yTHd1Sz4jwEuCbHzqmfUMu6oNbEvM5nhCTc9uWXRFz7/VqLWsrS32IsZ VXNrsiLXoejSv1K/3xpbVUP5Hql7n2yIjHjt0TSL8UiLWsh9mR2xE0I/adWLLX6DXxL4F PaEmRQgcQ72BPx224XB+dH18yNSz51uE3MfshJCbKd3TsgXmkcgAHLKhdcjZih8W5gw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796137276; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:Date:Mime-Version: X-B4-Tracking:X-Change-Id:X-Mailer:Message-ID:Subject:From:To:Cc: Content-Type:Content-Transfer-Encoding; bh=w+hzEz8AfesVrdqn7M5bmcmMAkyxafPDU8mkQXk13Jw=; b=D+HslJZY/YL+6RDaKPkPtYxkMjMFA9f85nyn5TSmM+FGzsQYpGxOCWBYbsDbXwO91yz3 VXZ0j653P2Ek8jG7HeIfOHM8/JfBTDTLBxiWvpjNYr21UMHwrc47W+HNZqhn8NzIA15Jd ni1y933N3v3HEkQpCH/K4UB6l+lbvcNYLW5DNOSQQz6pficKeUhfIBYQlIZQm2oizKAap 6+hnVGUp4Z0+VOw3qM0AvaF+zkMCkK1EewXZLfGQJzhKqdCcBgCUcf3g2EKUqpXQn+I4k 44R4NCZa1mc1cHSel1PEzXyztgRCf5IWpDgNJWyBgqccC8poJGsK7EbC2ZjXqt+p4RA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=flex--ptosi.bounces.google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b="JcP11pE/"; arc=none smtp.remote-ip=209.85.208.70 Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EFE54606A31A for ; Tue, 1 Dec 2026 15:01:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org EFE54606A31A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--ptosi.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=JcP11pE/ Received: by mail-ed1-f70.google.com with SMTP id 4fb4d7f45d1cf-6b8b0fffdb9so2133502a12.2 for ; Tue, 01 Dec 2026 07:01:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796137274; x=1796742074; darn=vger.kernel.org; h=content-transfer-encoding:content-type:cc:to:from:subject :message-id:mime-version:date:from:to:cc:subject:date:message-id :reply-to:content-type; bh=w+hzEz8AfesVrdqn7M5bmcmMAkyxafPDU8mkQXk13Jw=; b=JcP11pE/+hj6nsPZJ2Fpsv7rjQwJkmT59fc9+5CIhBf9sudmOXGVrsXM8iShCHFbyI hOv5Z0PfGBcXxYJm7VOypQ+ZIbAuPvZ6DNeg1Xu8wKjhHGrSKM5zeCmTKr2wWCxLkLo0 ZeI3NZtTi3s9MRJDu2pLiCw50EHxv/51RoTFX6VkEpk54BU85cEolwrO+Z+DzAtSmyHD DKPq9kxsk/khwZ+69WfaHae1mvCeaWdtAvJI5bLh48naIk0CISIJUPKHKHlDA3/5B09a VxzjkVulsm/pkLP58bxL6AJtJ5Rb5uQobs6heZLott21zxJQvu/AwQ0iLvjaYzVFoq7J Mnqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796137274; x=1796742074; h=content-transfer-encoding:content-type:cc:to:from:subject :message-id:mime-version:date:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to:content-type; bh=w+hzEz8AfesVrdqn7M5bmcmMAkyxafPDU8mkQXk13Jw=; b=biUGN9yfrSaqZF4wj7CS9EZD17XuLg0ELzHgRTRJmLib83xShY6uJCycYin1sCueEj YL8y741wontOlwouncKDYwqEC71EAjwrbLpHy25CbUFzRi9cB5WZQr/RysVSzSGVeOzk HrQNU3rNUQLH1HoK8CJjScar7pHbAxh2RVAVkB9GIZOAW0aY2lBeR/4w17AS3iQ9ZU6X mWhzXcS/n9OZq8rzDTPwCCGlsKtK/uDjMnFQTXb4TTC2t/l0jV3vAwyC5tZNBTeitFLQ PMfEz8w6H3cRDjW8HZ8eAqv6M7+D3GDAqjP6456rDCGcgZLxzK7+y/tAsnGjL1+3SVcR vB2A== X-Forwarded-Encrypted: i=1; AL+hErHywUXTSKiZbpHyJGow7XmN48nBphTLF2BMZSPHv1FcUNCOUQwNJZo2d8ZKiT+6KrhTp1bU7w1mm8O5Uqw=@vger.kernel.org X-Gm-Message-State: APuU4Z/kv5JRoGFv3PzaLrgryAKW00YCtzvMi+yR1g2Tz8uYPjh0JL3g +oYnWWAxT3ggkp4MQg8408U7U1ME3DJq0nLy7Ys2Xo8OgxPWaJ+1/ULM8ul2S7wdvZ+IxCm/NTz WLQ== X-Received: from edqv25.prod.google.com ([2002:aa7:d819:0:b0:6bb:6d68:fcc8]) (user=ptosi job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6402:4407:b0:6bb:b89:8ee1 with SMTP id 4fb4d7f45d1cf-6bb0b899014mr17100801a12.41.1796137263848; Tue, 01 Dec 2026 07:01:03 -0800 (PST) Date: Tue, 01 Dec 2026 16:00:51 +0100 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 X-B4-Tracking: v=1; b=H4sIACPhDmsC/2XMQQ7CIBCF4asQ1pIw0FLlKqYLaKc6C1oEbEya3 l20Cxcu/5e8b+MZE2Hmlm084UqZlrkGnBgf7m6+oaCxNldSGQB1EaGgiK7uSywUhDfG6M5L36i O11NMONHrC177oxM+ntUtx/hjLftHXSQxqXPrWmgmcKNd4aN6l1EMSwhULJOgsPGDBNSa9/v+B r1iVyHEAAAA X-Change-Id: 20261129-mte-page-optim-b66637b0b427 X-Mailer: b4 0.14.3 Message-ID: <20261201-mte-page-optim-v1-0-322b9e4096c7@google.com> Subject: [PATCH 0/5] Optimize the MTE page tagging API From: "=?utf-8?q?Pierre-Cl=C3=A9ment_Tosi?=" To: Catalin Marinas , Will Deacon Cc: Mark Rutland , Ryan Roberts , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, "=?utf-8?q?Pierre-Cl=C3=A9ment_Tosi?=" , Marc Zyngier Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable (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=3D1, 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=3Dwarm) mte_tag_pages(1) mte_clear_pages(1) =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D [SoC:CPU]Model DZP=3D0 DZP=3D1 DZP=3D0 DZP=3D1 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D [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.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.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 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D 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=3D1 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=3D0 so the DZP=3D1 fallbacks were tested b= y 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-5e= 38d19462ea@google.com Signed-off-by: Pierre-Cl=C3=A9ment Tosi --- Pierre-Cl=C3=A9ment 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, --=20 Pierre-Cl=C3=A9ment Tosi