From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.218.69 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796137297; b=Nc2lv4+QgFRComzoYTfwzX+BD83MrVXRcfNlUaOQTdTsJh3bc8jV/W4y9B4CxqFHJ2xI xO6xKZKl/+JgkjWxuNT6y+/jZvSE8U0BqnS9RASejuuRp7Pgq58+oS+nyDWQqaf/ynKH3 52rWa+h6LApERfGToYXLDAAaHiAr13LMOyhnLsakDZ18Nrjxyj+wbjSDFWJHE2SnsE6Ca hqD6jmRnvn5h6zF38Wcsi1mcnEewRVbZy6Y/WgfXjJlk738H/P2luAoG0z9c0G6sTwKuW tBvXAVDYcxyFa5Md/uzHpkB70rpUDR/p3xz9jU0qv8t0SqMY2ChTFrK6QLCJbmyLDrA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796137297; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:Date:In-Reply-To: Mime-Version:References:X-Mailer:Message-ID:Subject:From:To:Cc: Content-Type:Content-Transfer-Encoding; bh=+TH4LOBRKff5sRpuWFehDTZQmtCbKFcj7wLQc2HHBqU=; b=114JUY9OmYaItKqi9TSad8plG/wrYxEVodnTXiBMVOq6YlnGzGUxJx8Q9cQ5jbq3/sM2 IOkpcfJ/geb5135JC9dLlxrsIyJ2xHquzx4S/fzRSOeFOonvRKrM8mTs4LQ/iGOEL0kY6 peuKjmDPYvq/b5lt9xOo4wjN69w3RTRd3uHk6qAIEEKsPXbEqEkWewpScbtPTeNBV9X9n 7R84wzHFhcYhdrBj2QpUt1jV+ZXKEC9eW4dCJm3IMrNWE6CpxbixIw10LJMPvW4WyQDH5 A17fQk0o7vwSwxK6YQ/Iv4SJ3DXEU5N1SmX+eopTVGm8EGyK3WpM1k/GnuEUz2IbfoA== 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=XDbZ9I4H; arc=none smtp.remote-ip=209.85.218.69 Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) (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 5B4F6606A322 for ; Tue, 1 Dec 2026 15:01:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 5B4F6606A322 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=XDbZ9I4H Received: by mail-ej1-f69.google.com with SMTP id a640c23a62f3a-c4d34d6082fso922377266b.0 for ; Tue, 01 Dec 2026 07:01:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796137295; x=1796742095; darn=vger.kernel.org; h=content-transfer-encoding:content-type:cc:to:from:subject :message-id:references:mime-version:in-reply-to:date:from:to:cc :subject:date:message-id:reply-to:content-type; bh=+TH4LOBRKff5sRpuWFehDTZQmtCbKFcj7wLQc2HHBqU=; b=XDbZ9I4HTScw0ygozsN+Ql91bWjiXrhDC4cUdDbzWHYJAy1Lwjy0y5jXml79CHlvXi HVBnTZD81WmLP43X59jbQvqZ1INr8luB4zRtLfqSlb1xt+nrIgh8EkknBm+bzxwvvRFg 69P0ZJZgf+T4xb1gDc7/D6rWlohyLrpaYG0IP/4rVjnqRu3JwbtsNQ6d9DLaYoW/Mm3e XZtIORi6COHttETjGDaSd0GYCntFOld32EqPWFNlwXdjnRD0/PFHpiWZENpGmliJIp5p By7AB3xBEsTepLnS/RVwAmSWpZHE4Z6KVVx/VMYJlOVoeqelq9LJ38dJOY8ova/xYSnb TXEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796137295; x=1796742095; h=content-transfer-encoding:content-type:cc:to:from:subject :message-id:references:mime-version:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=+TH4LOBRKff5sRpuWFehDTZQmtCbKFcj7wLQc2HHBqU=; b=BRSosvI2T5zLwWKdUgTTRFxle4yPpMRaxBQMIepHfnFWrXu8NTr/4ApKoqjGi6GrPM Wa/xhO6ZHEsny5gDmLqQYxUo2K3zlc81zyv7XZ5h31BJz4zVa7WwL7end6CCIMv2qLnr axygirHBfR1Yb3ODaplBI+THG9K+HM5Uw14fx9B3te21zi9CIz1/YUkJse3x48sjx8cG A9Twc61qjyaFI1ZuZC2tDcHaqyxGm9UJdd0AP07dY2QljG+4l3vKyFm39d0lfFq24kLv xEkdgUACj/foUYUZmhnpMYrxS8AVFXpC6gQD0SXMSL0FVsaYbWu4pW4VNBelD8owX4E3 cg7A== X-Forwarded-Encrypted: i=1; AL+hErHbHB384t9qxuBUTXaoriWgS9T7R6B2QAwP9eJi5XT1s70dErt7GLWT3sdp4vlOpGvtkjO/Jaos90DPNAw=@vger.kernel.org X-Gm-Message-State: APuU4Z9GPHydBKIXL3UECClX8ckuYb187+NwGqnmgpDe6qv9RC2mdh05 cLBzGbyfqsUSR2DU1/BPVlUd4ToVapCTlbrZgg3UPJ1uKIKTgmHdjRo9xSlzBsgQOJmRWyomd79 PJw== X-Received: from ejek12.prod.google.com ([2002:a17:906:2a4c:b0:c51:38cf:eb0a]) (user=ptosi job=prod-delivery.src-stubby-dispatcher) by 2002:a17:907:2d0e:b0:c51:e820:661b with SMTP id a640c23a62f3a-c51e8209357mr869863266b.27.1796137290180; Tue, 01 Dec 2026 07:01:30 -0800 (PST) Date: Tue, 01 Dec 2026 16:00:54 +0100 In-Reply-To: <20261201-mte-page-optim-v1-0-322b9e4096c7@google.com> 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 References: <20261201-mte-page-optim-v1-0-322b9e4096c7@google.com> X-Mailer: b4 0.14.3 Message-ID: <20261201-mte-page-optim-v1-3-322b9e4096c7@google.com> Subject: [PATCH 3/5] arm64: Unroll 2x and align mte_tag_*pages() loops 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?=" Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Move the outer loop to assembly, to keep it tightly coupled with the inner one, and align the result to L1_CACHE_SHIFT since every routine fits in a single I-cache line. Keep 2 loops instead of a single larger one so that trained branch predictors always guess correctly the PAGE_SIZEd inner one (4 KiB page at BS=3D64 means 32 iterations). Unroll the inner loop 2x using interleaved GRP accesses to minimize register-level dependencies and maximize writeback buffer load but preserve ascending address order to avoid disturbing write-streaming mode (e.g. C1-Ultra). Even with the largest block size (2 KiB) on the smallest PAGE_SIZE (4 KiB), a 2x unrolled loop can't overshoot. Note that 4x unrolling was attempted but regressed on Cortex-A7xx with a notable increase in STALL_BACKEND_{BUSY,CPUBOUND}. Unrolling 2x keeps the gains on Cortex-A5xx, Cortex-X and C1-Ultra. Signed-off-by: Pierre-Cl=C3=A9ment Tosi --- arch/arm64/include/asm/mte-tagging.h | 15 ++++--------- arch/arm64/lib/mte.S | 41 ++++++++++++++++++++++----------= ---- 2 files changed, 29 insertions(+), 27 deletions(-) diff --git a/arch/arm64/include/asm/mte-tagging.h b/arch/arm64/include/asm/= mte-tagging.h index 9c8b39d2dd97..944636ef3559 100644 --- a/arch/arm64/include/asm/mte-tagging.h +++ b/arch/arm64/include/asm/mte-tagging.h @@ -12,27 +12,20 @@ =20 #ifdef CONFIG_ARM64_MTE =20 -void __mte_tag_page(void *p, u64 t); +void __mte_tag_pages(void *p, unsigned long n, u64 t); static __always_inline void mte_tag_pages(void *addr, unsigned long npages= , u8 tag) { u64 tags =3D 0x1111111111111111ULL * tag; =20 - do { - __mte_tag_page(addr, tags); - addr +=3D PAGE_SIZE; - } while (--npages); + __mte_tag_pages(addr, npages, tags); } =20 -void __mte_tag_clear_page(void *p, u64 t); +void __mte_tag_clear_pages(void *p, unsigned long n, u64 t); static __always_inline void mte_tag_clear_pages(void *addr, unsigned long npages, u8 tag) { - addr =3D mte_tagged(addr, tag); - do { - __mte_tag_clear_page(addr, tag); - addr +=3D PAGE_SIZE; - } while (--npages); + __mte_tag_clear_pages(mte_tagged(addr, tag), npages, tag); } =20 #else /* CONFIG_ARM64_MTE */ diff --git a/arch/arm64/lib/mte.S b/arch/arm64/lib/mte.S index 0b753db99114..7d971dd1a36e 100644 --- a/arch/arm64/lib/mte.S +++ b/arch/arm64/lib/mte.S @@ -6,6 +6,7 @@ =20 #include #include +#include #include #include #include @@ -35,7 +36,7 @@ .endm =20 /* - * blk_ops - execute \insn \arg every \bs over the page at \addr. + * blk_ops - execute \insn \arg every \bs over \npages pages at \addr. */ .macro blk_op, insn, arg, addr, step:vararg .ifc \insn, dc @@ -46,35 +47,43 @@ add \addr, \addr, \step .endm =20 - .macro blk_ops, insn, arg, addr, bs + .macro blk_ops, insn, arg, addr, npages, bs, tmp + add \tmp, \addr, \bs .Lblk_loop_\@: - blk_op \insn, \arg, \addr, \bs + blk_op \insn, \arg, \addr, \bs, lsl #1 + blk_op \insn, \arg, \tmp, \bs, lsl #1 tst \addr, #(PAGE_SIZE - 1) b.ne .Lblk_loop_\@ + subs \npages, \npages, #1 + b.ne .Lblk_loop_\@ ret .endm =20 /* - * Tag a page. - * x0 - page address - * x1 - tags (pre-populated for every granule in a GMID_EL1.BS block) + * Tag a page-aligned region. + * x0 - region start + * x1 - number of pages + * x2 - tags (pre-populated for every granule in a GMID_EL1.BS block) */ -SYM_FUNC_START(__mte_tag_page) + .p2align L1_CACHE_SHIFT +SYM_FUNC_START(__mte_tag_pages) multitag_transfer_size x5, x6 - blk_ops stgm, x1, x0, x5 -SYM_FUNC_END(__mte_tag_page) + blk_ops stgm, x2, x0, x1, x5, x6 +SYM_FUNC_END(__mte_tag_pages) =20 /* - * Tag a page and clear its data. - * x0 - page address (pre-tagged) - * x1 - tag + * Tag a page-aligned region and clear its data. + * x0 - region start (pre-tagged) + * x1 - number of pages + * x2 - tag */ -SYM_FUNC_START(__mte_tag_clear_page) + .p2align L1_CACHE_SHIFT +SYM_FUNC_START(__mte_tag_clear_pages) dczid_bs x5, x6, x7, 1f - blk_ops dc, gzva, x0, x5 + blk_ops dc, gzva, x0, x1, x5, x6 1: - blk_ops stzgm, x1, x0, x5 -SYM_FUNC_END(__mte_tag_clear_page) + blk_ops stzgm, x2, x0, x1, x5, x6 +SYM_FUNC_END(__mte_tag_clear_pages) =20 /* * Copy the tags from the source page to the destination one --=20 2.56.1.839.g22a8290db9-goog