Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp947598rdb; Tue, 30 Jan 2024 03:40:03 -0800 (PST) X-Google-Smtp-Source: AGHT+IG8DW8JppNY7ZqMHzwhxn0Q5gUfYVeiaiIiG3iacAs+Jf27rTo24uyoHKEUkkMDD0Ji8qLU X-Received: by 2002:a81:4318:0:b0:5ef:902b:7c60 with SMTP id q24-20020a814318000000b005ef902b7c60mr7020324ywa.25.1706614802838; Tue, 30 Jan 2024 03:40:02 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706614802; cv=pass; d=google.com; s=arc-20160816; b=0JVi+gwr+xnipBfRZN1WKyqgQJ9oQzuvnFmPkKxQfqflRLXRG60iEDUFU7zFk4Fpjb r/IYq8AZOMlriooNuUPhNLzqM/IbO6MgQWNBb0ynU1M/z3vUS0Sl22cP6Q3UeTkEuxEU pc7GiTutKI7UHm54teV5yIu3mTRgF6SO4a98GdT5tkupfmxe2XufTxrR0j/GvAkLCrks egS9CEuyauTEXcKIjCJ9Xmo7JWWRs2kkl3CcKkIMj6Pp14pxGQ4Jsg1gig89QpLwRn2T IcTtqDIDuPBjrQXhkXS5lQhG6LmWwqDppYv9fz+QxDJYI4h1I+uHiFw3w8oEtAIuTkXk elnQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:subject:cc:to:from:date; bh=ogig7Q8KDTVrRhwsL87GPNKiUj3+j3EuOUkoIhvkBp8=; fh=kiFa6QFgiDV9fTIRXvv7bZ3FmftpxgjwL8zUt1AKL6k=; b=F8LkM6uMKuAKVR2ZfEh7Aik12u76rkOcgwnuv/LXCH+2U61rZ6FQzlwPEFFnO8ps5G szBQ5fdyHPT/QBqMRnMv5wGLDWGv4LE5qsLymBKALJHB6FFrc3SqjtS77qo8IfOydU+6 31HPfLN0aDg1jpzvS/iH+cLyZNhjNUHrB0y4tI31aJOfmL4w4K09Tri7eJ6Mhg93IIBo 9rSd0VHpRbom9AJId5I/LTho1yucCtKg4l3lg7k4GAZdHfp1lHJDuPdBaHgGBByep9WH 706MzPMPcO/f/TXCsNLTlEBfWYGjh4p0o9CfBFNJeO+6jYHO0sUJjvSMWQxq5mYCrH0y rdow== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-44530-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-44530-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id i7-20020a37c207000000b007833f16015esi9835412qkm.620.2024.01.30.03.40.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 03:40:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-44530-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-44530-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-44530-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 945531C245A1 for ; Tue, 30 Jan 2024 11:40:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BAEA66A038; Tue, 30 Jan 2024 11:38:13 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 005506A01E; Tue, 30 Jan 2024 11:38:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706614693; cv=none; b=DPPlGDJh0TjlAAwwHM06nLNXg+zeqL9sduAEhJTWFbEOiN2+qxEVqb+QsXfOTb0VC1Qgwx+cVTvGs9mZ2H86MUryW/CM7Lecq3Du+QJwfIn48UGmekXsX5GaMob08P8qOL0v2jdhA1o6NErNJ5tUHZ0H5k8Y3WXi/zl453I123o= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706614693; c=relaxed/simple; bh=/DsBAHX8HTlca+Vpy4zDg5DsZ5AAjetwE7nEWjeRix8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=psG7XgZC/QZh+3TWfF6WlwUnle3O6N5nNOWS6ZaT5EgH7ZJi98iLDHnMqtOqLJXN9uTW5nxVUR53EgA/dhTpaP5REhbX7ZVvU4xPeKvIIWwzmGRIOKimtrI1312qj/p75kHv+83+8KM4MzIVD0RjK21dVsTE8ODeZqccmekg4PM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 2F6CEDA7; Tue, 30 Jan 2024 03:38:54 -0800 (PST) Received: from raptor (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 070733F5A1; Tue, 30 Jan 2024 03:38:04 -0800 (PST) Date: Tue, 30 Jan 2024 11:38:02 +0000 From: Alexandru Elisei To: Peter Collingbourne Cc: catalin.marinas@arm.com, will@kernel.org, oliver.upton@linux.dev, maz@kernel.org, james.morse@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, arnd@arndb.de, akpm@linux-foundation.org, mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, bristot@redhat.com, vschneid@redhat.com, mhiramat@kernel.org, rppt@kernel.org, hughd@google.com, steven.price@arm.com, anshuman.khandual@arm.com, vincenzo.frascino@arm.com, david@redhat.com, eugenis@google.com, kcc@google.com, hyesoo.yu@samsung.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kvmarm@lists.linux.dev, linux-fsdevel@vger.kernel.org, linux-arch@vger.kernel.org, linux-mm@kvack.org, linux-trace-kernel@vger.kernel.org Subject: Re: [PATCH RFC v3 23/35] arm64: mte: Try to reserve tag storage in arch_alloc_page() Message-ID: References: <20240125164256.4147-1-alexandru.elisei@arm.com> <20240125164256.4147-24-alexandru.elisei@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: Hi Peter, On Mon, Jan 29, 2024 at 04:04:18PM -0800, Peter Collingbourne wrote: > On Thu, Jan 25, 2024 at 8:45 AM Alexandru Elisei > wrote: > > > > Reserve tag storage for a page that is being allocated as tagged. This > > is a best effort approach, and failing to reserve tag storage is > > allowed. > > > > When all the associated tagged pages have been freed, return the tag > > storage pages back to the page allocator, where they can be used again for > > data allocations. > > > > Signed-off-by: Alexandru Elisei > > --- > > > > Changes since rfc v2: > > > > * Based on rfc v2 patch #16 ("arm64: mte: Manage tag storage on page > > allocation"). > > * Fixed calculation of the number of associated tag storage blocks (Hyesoo > > Yu). > > * Tag storage is reserved in arch_alloc_page() instead of > > arch_prep_new_page(). > > > > arch/arm64/include/asm/mte.h | 16 +- > > arch/arm64/include/asm/mte_tag_storage.h | 31 +++ > > arch/arm64/include/asm/page.h | 5 + > > arch/arm64/include/asm/pgtable.h | 19 ++ > > arch/arm64/kernel/mte_tag_storage.c | 234 +++++++++++++++++++++++ > > arch/arm64/mm/fault.c | 7 + > > fs/proc/page.c | 1 + > > include/linux/kernel-page-flags.h | 1 + > > include/linux/page-flags.h | 1 + > > include/trace/events/mmflags.h | 3 +- > > mm/huge_memory.c | 1 + > > 11 files changed, 316 insertions(+), 3 deletions(-) > > > > diff --git a/arch/arm64/include/asm/mte.h b/arch/arm64/include/asm/mte.h > > index 8034695b3dd7..6457b7899207 100644 > > --- a/arch/arm64/include/asm/mte.h > > +++ b/arch/arm64/include/asm/mte.h > > @@ -40,12 +40,24 @@ void mte_free_tag_buf(void *buf); > > #ifdef CONFIG_ARM64_MTE > > > > /* track which pages have valid allocation tags */ > > -#define PG_mte_tagged PG_arch_2 > > +#define PG_mte_tagged PG_arch_2 > > /* simple lock to avoid multiple threads tagging the same page */ > > -#define PG_mte_lock PG_arch_3 > > +#define PG_mte_lock PG_arch_3 > > +/* Track if a tagged page has tag storage reserved */ > > +#define PG_tag_storage_reserved PG_arch_4 > > + > > +#ifdef CONFIG_ARM64_MTE_TAG_STORAGE > > +DECLARE_STATIC_KEY_FALSE(tag_storage_enabled_key); > > +extern bool page_tag_storage_reserved(struct page *page); > > +#endif > > > > static inline void set_page_mte_tagged(struct page *page) > > { > > +#ifdef CONFIG_ARM64_MTE_TAG_STORAGE > > + /* Open code mte_tag_storage_enabled() */ > > + WARN_ON_ONCE(static_branch_likely(&tag_storage_enabled_key) && > > + !page_tag_storage_reserved(page)); > > +#endif > > /* > > * Ensure that the tags written prior to this function are visible > > * before the page flags update. > > diff --git a/arch/arm64/include/asm/mte_tag_storage.h b/arch/arm64/include/asm/mte_tag_storage.h > > index 7b3f6bff8e6f..09f1318d924e 100644 > > --- a/arch/arm64/include/asm/mte_tag_storage.h > > +++ b/arch/arm64/include/asm/mte_tag_storage.h > > @@ -5,6 +5,12 @@ > > #ifndef __ASM_MTE_TAG_STORAGE_H > > #define __ASM_MTE_TAG_STORAGE_H > > > > +#ifndef __ASSEMBLY__ > > + > > +#include > > + > > +#include > > + > > #ifdef CONFIG_ARM64_MTE_TAG_STORAGE > > > > DECLARE_STATIC_KEY_FALSE(tag_storage_enabled_key); > > @@ -15,6 +21,15 @@ static inline bool tag_storage_enabled(void) > > } > > > > void mte_init_tag_storage(void); > > + > > +static inline bool alloc_requires_tag_storage(gfp_t gfp) > > +{ > > + return gfp & __GFP_TAGGED; > > +} > > +int reserve_tag_storage(struct page *page, int order, gfp_t gfp); > > +void free_tag_storage(struct page *page, int order); > > + > > +bool page_tag_storage_reserved(struct page *page); > > #else > > static inline bool tag_storage_enabled(void) > > { > > @@ -23,6 +38,22 @@ static inline bool tag_storage_enabled(void) > > static inline void mte_init_tag_storage(void) > > { > > } > > +static inline bool alloc_requires_tag_storage(struct page *page) > > This function should take a gfp_t to match the > CONFIG_ARM64_MTE_TAG_STORAGE case. Ah, yes, it should, nice catch, the compiler didn't throw an error. Will fix, thanks! Alex