From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.218.72 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796137313; b=cjeOsNz94pCamaktsDVL5eArWVLZlav/0GPmMJWSAhuEBq8aHK1ovaOZeONSK/7hSTnU xhteoS3IBNQDCHkRWa50f1a80JAOaNmasXH+whVgDbqJ6irkJDFJ4mMqMdiSGaLrxP/hW qkcgGwpGUGXLCPUgA2hF0/CjjkPd5tZk7OIlVud1BIA2e5RajAzydL39UfftlZaQEE1iE 6rnPPLc8rfatZ8r07VY35xGdWHpDX7sxBuLeNRwR+GHNgHqeZCOYnCMS44cWVEPKJj2xN uWtbrfhZKcafeOKIPB4JobLXxfTGX64vs68V1BcftpyRg3Eyz5lQH5NK5Ya0BOds44w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796137313; 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=gm5aVTxKW+/Xhv/f3n8F5HwdpXU/juwsUz385Qj6XuU=; b=0Yz+iylHDiGP86FNA6ygFFUdPrEmpJWetIRaosWuLwStE+7z08Q/a62QRCoQQkA5NO17 xQrPwlysS9WamemNF+2JTNgah7D1E6W6hQ7gwT3sTI8YUwoijLGkGA3Il55oYdmKF9V++ 8UZ7Awsyaguj92c9lSsJyS1CmHRZH4Z0kV7qbiFa0tjCIQmx351Y4tGYwmsWeA7cky7fw vh5H5okYC7hhOtcQVGfILyse4NfenkPCY0dwA5/GSr0dtiZ7hftQmSLTcBCskzQDN1nk5 xaONooFR+aigZjOFfpr7ebSLNHCxbY8EtkAXpUZhZk+WNty8repVVE04KExzv48lp+w== 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=OA4istTW; arc=none smtp.remote-ip=209.85.218.72 Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) (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 92375606A33D for ; Tue, 1 Dec 2026 15:01:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 92375606A33D 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=OA4istTW Received: by mail-ej1-f72.google.com with SMTP id a640c23a62f3a-c4d4d318759so301663166b.2 for ; Tue, 01 Dec 2026 07:01:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796137311; x=1796742111; 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=gm5aVTxKW+/Xhv/f3n8F5HwdpXU/juwsUz385Qj6XuU=; b=OA4istTWgSpph4zB1HWPEpDmxLCcZZNr/31HOfQT2s4R4Qo6p/WUp8EzbcM2GgOpif EbQzPl9ZW7zJSWeIKO45Rzt70efPkKqd1QZYxuMIm2rkss5SlXRL33ImKVnLpxtCOX7d 5ZT/kH8w30yMSqeTWjXULK3XpI+zb5eRTPDecOQYP3hoC2J1vXprZ62OqS75Kr0g6mr3 aB3UXz38lnK2sw6hmXArhAy30aXe9L+UQGV54GWocQdwO09oMV5Sp+yK1xJ24UgmVoIG xDTNJOx50viWBXuuUsYb4fTA+7RwxlJWxHW/x2oszk4YFz3ufnZ90OcRRe6Dr3JCIc7H A1+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796137311; x=1796742111; 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=gm5aVTxKW+/Xhv/f3n8F5HwdpXU/juwsUz385Qj6XuU=; b=R9qzlf544LRqXJ7tEwiQ4SL2Yzcw9QNW9f+gams3zwvHbQ6mutHd6ts8Bz8MRQjxDH ahoIrGr7xSA1EOno5Dh2AvTeWYkONoa+fG8HJS6PHH5er6e54+eZ/mGr+R2HW7XG2CoR 95xM1JGEfLty/MRbBOVfe58rEGeeFntdgpagT9BSwS2zp/Ooog1C8qeT4p8wvQhGsJBP nE2ezfcVcXrXXOvu/VYDb8jsHNOSPpYd/N0/oaYiP2R1KieyYEpgiRFihSkOYWdzA/15 uKmqz5SEd2KQu7sG3fyu0payKZcghI5jlGveivPOOhUJOOPxySAhzTwauRtwszB5AVut nm9g== X-Forwarded-Encrypted: i=1; AL+hErFJ3SIxbrECk4Lu+MuM1YRw+9+gn+K+BTB+ConOfV2MaGmjozwFBzfApiEyWtYfhaN5Hrx08bhthrDTIuQ=@vger.kernel.org X-Gm-Message-State: APuU4Z+DCI4zyd75AziVdd+Udrp7B09jJBoM98O0KViCev1NhDK+IFfc /o+J5M9N4MxGUYWbh405fAIO8FK2tXTrrPA+oa2V++FFgQ/KGMhz1Gkv5H9AO6cns3eqe+mP7HT c7g== X-Received: from ejbdv22.prod.google.com ([2002:a17:906:b816:b0:c51:f2fd:e1a]) (user=ptosi job=prod-delivery.src-stubby-dispatcher) by 2002:a17:906:eec2:b0:c51:f757:12ec with SMTP id a640c23a62f3a-c51f7574663mr857532766b.8.1796137303654; Tue, 01 Dec 2026 07:01:43 -0800 (PST) Date: Tue, 01 Dec 2026 16:00:56 +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-5-322b9e4096c7@google.com> Subject: [PATCH 5/5] arm64: Use ARM64_HAS_DC_ZVA for MTE page tagging 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 Use ARM64_HAS_DC_ZVA to static branch to either the STZGM- or DC-based backend of mte_tag_clear_pages() and split __mte_tag_clear_pages accordingly. Do this from the thin mte-tagging.h inline wrapper so that clients directly call into the appropriate routine. This gives an always-safe mte_tag_clear_pages() since alternative_has_cap_likely() defaults to false i.e. STZGM, which is always available when MTE2 is supported. Note that we still read DCZID_EL0 to extract the block size, which a later commit will optimize out. Signed-off-by: Pierre-Cl=C3=A9ment Tosi --- arch/arm64/include/asm/mte-tagging.h | 7 ++++++- arch/arm64/lib/mte.S | 26 +++++++++++++++++--------- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/arch/arm64/include/asm/mte-tagging.h b/arch/arm64/include/asm/= mte-tagging.h index 944636ef3559..eb93e4c44db6 100644 --- a/arch/arm64/include/asm/mte-tagging.h +++ b/arch/arm64/include/asm/mte-tagging.h @@ -8,6 +8,7 @@ #ifndef __ASM_MTE_TAGGING_H #define __ASM_MTE_TAGGING_H =20 +#include #include =20 #ifdef CONFIG_ARM64_MTE @@ -22,10 +23,14 @@ static __always_inline void mte_tag_pages(void *addr, u= nsigned long npages, } =20 void __mte_tag_clear_pages(void *p, unsigned long n, u64 t); +void __mte_tag_clear_pages_dc(void *p, unsigned long n); static __always_inline void mte_tag_clear_pages(void *addr, unsigned long npages, u8 tag) { - __mte_tag_clear_pages(mte_tagged(addr, tag), npages, tag); + if (alternative_has_cap_likely(ARM64_HAS_DC_ZVA)) + __mte_tag_clear_pages_dc(mte_tagged(addr, tag), npages); + else + __mte_tag_clear_pages(addr, npages, tag); } =20 #else /* CONFIG_ARM64_MTE */ diff --git a/arch/arm64/lib/mte.S b/arch/arm64/lib/mte.S index 7d971dd1a36e..962a8f4eb63c 100644 --- a/arch/arm64/lib/mte.S +++ b/arch/arm64/lib/mte.S @@ -25,14 +25,13 @@ .endm =20 /* - * dczid_bs - set \bs to DCZID_EL0.BS and branch to \dzp_label when DZP=3D= 1. + * dczid_bs - set \bs to DCZID_EL0.BS. */ - .macro dczid_bs, bs, tmp, dczid, dzp_label - mrs \dczid, dczid_el0 - and \bs, \dczid, #DCZID_EL0_BS_MASK + .macro dczid_bs, bs, tmp + mrs \tmp, dczid_el0 + and \bs, \tmp, #DCZID_EL0_BS_MASK mov \tmp, #4 lsl \bs, \tmp, \bs - tbnz \dczid, #DCZID_EL0_DZP_SHIFT, \dzp_label .endm =20 /* @@ -73,18 +72,27 @@ SYM_FUNC_END(__mte_tag_pages) =20 /* * Tag a page-aligned region and clear its data. - * x0 - region start (pre-tagged) + * x0 - region start * x1 - number of pages * x2 - tag */ .p2align L1_CACHE_SHIFT SYM_FUNC_START(__mte_tag_clear_pages) - dczid_bs x5, x6, x7, 1f - blk_ops dc, gzva, x0, x1, x5, x6 -1: + dczid_bs x5, x6 blk_ops stzgm, x2, x0, x1, x5, x6 SYM_FUNC_END(__mte_tag_clear_pages) =20 +/* + * Tag a page-aligned region and clear its data (requires DCZID_EL0.DZP=3D= 0). + * x0 - region start (pre-tagged) + * x1 - number of pages + */ + .p2align L1_CACHE_SHIFT +SYM_FUNC_START(__mte_tag_clear_pages_dc) + dczid_bs x5, x6 + blk_ops dc, gzva, x0, x1, x5, x6 +SYM_FUNC_END(__mte_tag_clear_pages_dc) + /* * Copy the tags from the source page to the destination one * x0 - address of the destination page --=20 2.56.1.839.g22a8290db9-goog