From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A8B07606A31A for ; Tue, 1 Dec 2026 17:34:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=N5oItB2l; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=DzHF+Qkj DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: Content-Type:Cc:To:From:Subject:Message-ID:References:Mime-Version: In-Reply-To:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Unsubscribe-Post:List-Owner; bh=7A3xrvBUk+SYpxbw0pyX4x8tZZfeUeczaBQGrRPE04Y=; b=N5oItB2lODIju6ALsbXreleO7H Ooa3KmVdWDC+1DTT88J7ekYqMYumamKwV0gPe1EuAtMRxlYtQwglOL1kzQ0J7b4+sTTfrthTWp5Cg 0bW0p/68omS3QccUR+o+wsgW618sPaaEqTIqcin7HXbcnEbQVmV8191CTgkLe6MLZT3/0zoBmv/sD KiLEHq05zDDuNiR/l8btCVoXsdWpjIWQD+e6283a2Ou9QegXaJH0K/MzUmFvMlGnT14y4CY+Hpfo6 TqfOpFx0Kas0zqAJR2k5tg6rixcf1qChuSFlAGtvIw6lCQxT50UnILD6IFPYplR56Bpd++tzUyaGT bqfnWjmg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYPBM-00000008Qts-2Iew; Tue, 01 Dec 2026 14:50:12 +0000 Received: from mail-ej1-x647.google.com ([2a00:1450:4864:20::647]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYPBJ-00000008QrU-2LoR for linux-arm-kernel@lists.infradead.org; Tue, 01 Dec 2026 14:50:11 +0000 Received: by mail-ej1-x647.google.com with SMTP id a640c23a62f3a-c41dae9db9dso290465666b.2 for ; Tue, 01 Dec 2026 06:50:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796136607; x=1796741407; darn=lists.infradead.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=7A3xrvBUk+SYpxbw0pyX4x8tZZfeUeczaBQGrRPE04Y=; b=DzHF+QkjyeibQvzCk0Q6Gvx5BOnm9gLtp2b/gRzZ+5jxlnUyJCZa+kiU0Mp+Pzx9Q0 L+wMx7fyLaxv1jcBKFD1KfUi3gEvlH4jZgU2g4dQ21zLLdYvKp7DELhCqfOG3M9+iSeu +CsrOB5L51xCsXpIgb6setHqU2koKOFCpct2vhzHyYWh259KlxyTKGkvwmKSChBhPfzx fU40QPMaqfRzXvvcbEZMgRARDP3g8yAYj3CPfA3WWTXBhG9IkrrJ7ZRXMSkltqUwep29 nogRpk31Ls4AUfHW084YG6kTyHYXksnIUCW0w4B25/kO4NUdgsNEqSxbWQk4Bu7Y/sSU 51Hg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796136607; x=1796741407; 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=7A3xrvBUk+SYpxbw0pyX4x8tZZfeUeczaBQGrRPE04Y=; b=gnH9VBxiP2orONw2oYsYtYHVh5j1DSwXsrn+/OjrkBf1QQH47CO2XLMnb3So1MaV0Z EP+4I6CYQJvj1RJgRmI2OUahCx84sgGjcQoWrXSil6wdeRyGnZ07zQPddMpEPzHoWbKe Nd2HMsM6+/qIJ0WogQ8keFLL/Y51DorlYoCDIK07liKRsgoUApO7bcCoegdZSNHzUpmT EeQK5Yt/nMzga6wNgCgSbpaw5rT7fTR3jDAohXpdbgJ9OnGd394zVMCEn4h30CE7cTvz 3dmYmDyxBG40nQdLiTqiiefyxbFhEMR8FO5kYbZZgTAIFxlS2ou8w7u9LCuB9dATQ3HE leLA== X-Forwarded-Encrypted: i=1; AL+hErGZzf39WFSLahCazBt0CqcPhRVehrPnHuxwxJlJSq8imJCK/RqnEYfj8B9GjiueS8NdzdArW6/e9E3sut2ltRbJ@lists.infradead.org X-Gm-Message-State: APuU4Z8Amf7JbiRci8QMBOAo1eoOMOBgfjG6EqF2W9yKknhmlHY8zv0l ZaV4WfbL6/T+ryDjC3h2FVnFDyZh4joTGLr2RSKjsSf15YY9wNriE89lNzG82c6tuym0geiGp98 h6A== X-Received: from ejis5.prod.google.com ([2002:a17:906:2ec5:b0:c4d:1fbc:e718]) (user=ptosi job=prod-delivery.src-stubby-dispatcher) by 2002:a17:907:9693:b0:c52:1f8a:6597 with SMTP id a640c23a62f3a-c521f8a67c1mr321449766b.4.1796136606542; Tue, 01 Dec 2026 06:50:06 -0800 (PST) Date: Tue, 01 Dec 2026 15:49:20 +0100 In-Reply-To: <20261201-mte-page-api-v1-0-5e38d19462ea@google.com> X-Archived-By: Mime-Version: 1.0 References: <20261201-mte-page-api-v1-0-5e38d19462ea@google.com> X-Mailer: b4 0.14.3 Message-ID: <20261201-mte-page-api-v1-4-5e38d19462ea@google.com> Subject: [PATCH 4/4] arm64: Introduce mte_[tag_]clear_page[s]() From: "=?utf-8?q?Pierre-Cl=C3=A9ment_Tosi?=" To: Catalin Marinas , Will Deacon , "Lorenzo Stoakes (ARM)" , Vincenzo Frascino Cc: Marc Zyngier , Fuad Tabba , 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261201_065009_652662_53626B19 X-CRM114-Status: GOOD ( 16.86 ) X-Spam-Score: -9.5 (---------) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" X-Spam-Status: No, score=-26.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIMWL_WL_MED,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT, USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 The MTE ISA provides two fundamental categories of bulk operations: 1. setting allocation tags (DC GVA, STGM, ST2G) and 2. setting allocation tags while zeroing data (DC GZVA, STZGM, STZ2G) such that it is natural to have 2 core C primitives, one for each. Introduce the latter, with support for arbitrary tags and multi-page ranges, implemented through the reworked mte_zero_clear_page_tags() asm routine, with a C wrapper for argument prepping. Provide a single-page variant, mte_tag_clear_page(), for convenience. Since these functions have the combined effects of mte_tag_page[s]() and clear_page[s](), name them mte_tag_clear_page[s](). This aligns with the arch-agnostic tag_clear_highpages() and keeps the term "clear" for data (instead of "zero"), similarly to common kernel mm APIs such as clear_page[s](), clear_highpage(), clear_user_page(), etc. Provide concise and convenient "clear-all" helpers: mte_clear_page[s](). In total, this results in the following API and effects: function data tags -------------------------------- ------ ------ clear_page[s](p[, n]) 0 - mte_clear_page[s](p[, n]) 0 0 mte_tag_clear_page[s](p[, n], t) 0 t mte_tag_page[s](p[, n], 0) - 0 mte_tag_page[s](p[, n], t) - t Define a temporary compatibility wrapper for mte_zero_clear_page_tags(). Signed-off-by: Pierre-Cl=C3=A9ment Tosi --- arch/arm64/include/asm/mte-tagging.h | 28 ++++++++++++++++++++++++++++ arch/arm64/include/asm/mte.h | 4 ---- arch/arm64/lib/mte.S | 11 ++++------- arch/arm64/mm/proc.S | 8 ++++---- 4 files changed, 36 insertions(+), 15 deletions(-) diff --git a/arch/arm64/include/asm/mte-tagging.h b/arch/arm64/include/asm/= mte-tagging.h index f66e606969c8..f491682ba418 100644 --- a/arch/arm64/include/asm/mte-tagging.h +++ b/arch/arm64/include/asm/mte-tagging.h @@ -24,16 +24,44 @@ static __always_inline void mte_tag_pages(void *addr, u= nsigned long npages, } while (--npages); } =20 +void __mte_tag_clear_page(void *p); +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); + addr +=3D PAGE_SIZE; + } while (--npages); +} + #else /* CONFIG_ARM64_MTE */ =20 static inline void mte_tag_pages(void *addr, unsigned long n, u8 tag) { } +static inline void mte_tag_clear_pages(void *addr, unsigned long n, u8 tag= ) { } =20 #endif /* CONFIG_ARM64_MTE */ =20 +static __always_inline void mte_clear_pages(void *addr, unsigned long npag= es) +{ + mte_tag_clear_pages(addr, npages, 0); +} + #define mte_clear_page_tags(p) mte_tag_page(p, 0) static __always_inline void mte_tag_page(void *addr, u8 tag) { mte_tag_pages(addr, 1, tag); } =20 +static __always_inline void mte_tag_clear_page(void *addr, u8 tag) +{ + mte_tag_clear_pages(addr, 1, tag); +} + +#define mte_zero_clear_page_tags(p) mte_clear_page(p) +static __always_inline void mte_clear_page(void *addr) +{ + mte_clear_pages(addr, 1); +} + #endif /* __ASM_MTE_TAGGING_H */ diff --git a/arch/arm64/include/asm/mte.h b/arch/arm64/include/asm/mte.h index 3d98d5b8768f..d84f12f20277 100644 --- a/arch/arm64/include/asm/mte.h +++ b/arch/arm64/include/asm/mte.h @@ -92,7 +92,6 @@ static inline bool try_page_mte_tagging(struct page *page= ) return false; } =20 -void mte_zero_clear_page_tags(void *addr); void mte_clear_folio_tags(struct folio *folio); void mte_sync_tags(pte_t pte, unsigned int nr_pages); void mte_copy_page_tags(void *kto, const void *kfrom); @@ -123,9 +122,6 @@ static inline bool try_page_mte_tagging(struct page *pa= ge) { return false; } -static inline void mte_zero_clear_page_tags(void *addr) -{ -} static inline void mte_clear_folio_tags(struct folio *folio) { } diff --git a/arch/arm64/lib/mte.S b/arch/arm64/lib/mte.S index 2bd59b877ab6..012577641b6b 100644 --- a/arch/arm64/lib/mte.S +++ b/arch/arm64/lib/mte.S @@ -38,13 +38,10 @@ SYM_FUNC_START(__mte_tag_page) SYM_FUNC_END(__mte_tag_page) =20 /* - * Zero the page and tags at the same time - * - * Parameters: - * x0 - address to the beginning of the page + * Tag a page and clear its data. + * x0 - page address (pre-tagged) */ -SYM_FUNC_START(mte_zero_clear_page_tags) - and x0, x0, #(1 << MTE_TAG_SHIFT) - 1 // clear the tag +SYM_FUNC_START(__mte_tag_clear_page) mrs x1, dczid_el0 tbnz x1, #4, 2f // Branch if DC GZVA is prohibited and w1, w1, #0xf @@ -61,7 +58,7 @@ SYM_FUNC_START(mte_zero_clear_page_tags) tst x0, #(PAGE_SIZE - 1) b.ne 2b ret -SYM_FUNC_END(mte_zero_clear_page_tags) +SYM_FUNC_END(__mte_tag_clear_page) =20 /* * Copy the tags from the source page to the destination one diff --git a/arch/arm64/mm/proc.S b/arch/arm64/mm/proc.S index 12aacc74f764..85b8be719a1e 100644 --- a/arch/arm64/mm/proc.S +++ b/arch/arm64/mm/proc.S @@ -50,10 +50,10 @@ =20 #ifdef CONFIG_ARM64_MTE /* - * The mte_zero_clear_page_tags() implementation uses DC GZVA, which relie= s on - * TBI being enabled at EL1. TCMA1 is needed to treat accesses with the - * match-all tag (0xF) as Tag Unchecked, irrespective of the SCTLR_EL1.TCF - * setting. + * MTE tagging routines pass tagged kernel addresses to DC G(Z)VA, which w= ould + * trigger TTBR1 level 0 translation faults unless we set TBI1. TCMA1 is n= eeded + * to treat accesses with the match-all tag (0xF) as Tag Unchecked, irresp= ective + * of the SCTLR_EL1.TCF setting. */ #define TCR_MTE_FLAGS TCR_EL1_TCMA1 | TCR_EL1_TBI1 | TCR_EL1_TBID1 #else --=20 2.56.1.839.g22a8290db9-goog