Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp485046rdb; Thu, 30 Nov 2023 09:43:23 -0800 (PST) X-Google-Smtp-Source: AGHT+IFfHasVnnzkzoKpgoFuyhkq4uzjgr5IBq8J+l54zBqA1JKpktoOvAq4vOOK5gzat2dpuln+ X-Received: by 2002:a17:902:f54c:b0:1cf:b47f:a9a6 with SMTP id h12-20020a170902f54c00b001cfb47fa9a6mr19597817plf.41.1701366203186; Thu, 30 Nov 2023 09:43:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701366203; cv=none; d=google.com; s=arc-20160816; b=oTyxknhmO2f1WGMhAZnEYMKCg2xo/DrOKcvvHxVv4Yrygg+UYAPiaJFlf18sec/+fr 9u+52SDoAvVOsvbel592h2s+GVgokyfDqiTnUAf+syRhWSDvEgy345J2UfiovWMAzGyl I5n5jaYjkojqkIZBoqRH6vxRK4wH1aLntOyAJG9TIsUKpAAtBO7HhWdpMRt4AiyVfg4D xQz6BILOcmWQR4hqDUpPpdkcZRBnSpam6s8d+1/RNQWSYAbc/dHJzbBRRs7Umm1XuPzm O0meqzYou1aLdAt9rQ2qZJOJHflrs7BSYrFqp5xKpLy33eOo4+PvHBRgrBjgX6dZIOJ6 5FnQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=QZC2LHHmw4nzD0yHmjuZPyvBNvpTXO82fEe1JqW2iQw=; fh=kiFa6QFgiDV9fTIRXvv7bZ3FmftpxgjwL8zUt1AKL6k=; b=W2VMTAyiZ/acXw6komFg38iUQN7SOEBS/GLLTQBNZ6lT+XxqvQD8IUIZgkkJdinXbn BsmBm51S34d+hVxnsxhXGV4YaRAcYFC7jeJuaHCadj37w4l5gojXRbgrLhLN1xzKkq+Z u624iWs5lO7Zj5giJ+2u3XD6uY0UO7YyvVPlMpzUuy+u1VBs7u2zGVLpiBBfwzuM2rul ILPrBZHO1u4wkBP3H7exyLQmar5qkZXLxqbW9vaoEP4A4i05CTIG70WzLAgxLot+kiCW snezMpKrZdYXoMl1/8+V7cJOI1eoMTL0+T1D0rXoq3jb42Sbj2buzlYU6gw+vyO7uxi3 hU4g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id d4-20020a170902728400b001cc2853bfe6si1580469pll.192.2023.11.30.09.43.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 09:43:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 2D8FA802573E; Thu, 30 Nov 2023 09:43:22 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235246AbjK3RnI (ORCPT + 99 others); Thu, 30 Nov 2023 12:43:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37698 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235227AbjK3RnE (ORCPT ); Thu, 30 Nov 2023 12:43:04 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A1EE4131; Thu, 30 Nov 2023 09:43:09 -0800 (PST) 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 0867A1756; Thu, 30 Nov 2023 09:43:56 -0800 (PST) Received: from raptor (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 526A93F6C4; Thu, 30 Nov 2023 09:43:04 -0800 (PST) Date: Thu, 30 Nov 2023 17:43:01 +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 v2 21/27] mm: arm64: Handle tag storage pages mapped before mprotect(PROT_MTE) Message-ID: References: <20231119165721.9849-1-alexandru.elisei@arm.com> <20231119165721.9849-22-alexandru.elisei@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Thu, 30 Nov 2023 09:43:22 -0800 (PST) Hi Peter, On Mon, Nov 27, 2023 at 09:39:17PM -0800, Peter Collingbourne wrote: > Hi Alexandru, > > On Sun, Nov 19, 2023 at 8:59 AM Alexandru Elisei > wrote: > > > > Signed-off-by: Alexandru Elisei > > --- > > arch/arm64/include/asm/mte_tag_storage.h | 1 + > > arch/arm64/kernel/mte_tag_storage.c | 15 +++++++ > > arch/arm64/mm/fault.c | 55 ++++++++++++++++++++++++ > > include/linux/migrate.h | 8 +++- > > include/linux/migrate_mode.h | 1 + > > mm/internal.h | 6 --- > > 6 files changed, 78 insertions(+), 8 deletions(-) > > > > diff --git a/arch/arm64/include/asm/mte_tag_storage.h b/arch/arm64/include/asm/mte_tag_storage.h > > index b97406d369ce..6a8b19a6a758 100644 > > --- a/arch/arm64/include/asm/mte_tag_storage.h > > +++ b/arch/arm64/include/asm/mte_tag_storage.h > > @@ -33,6 +33,7 @@ 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); > > +bool page_is_tag_storage(struct page *page); > > > > vm_fault_t handle_page_missing_tag_storage(struct vm_fault *vmf); > > vm_fault_t handle_huge_page_missing_tag_storage(struct vm_fault *vmf); > > diff --git a/arch/arm64/kernel/mte_tag_storage.c b/arch/arm64/kernel/mte_tag_storage.c > > index a1cc239f7211..5096ce859136 100644 > > --- a/arch/arm64/kernel/mte_tag_storage.c > > +++ b/arch/arm64/kernel/mte_tag_storage.c > > @@ -500,6 +500,21 @@ bool page_tag_storage_reserved(struct page *page) > > return test_bit(PG_tag_storage_reserved, &page->flags); > > } > > > > +bool page_is_tag_storage(struct page *page) > > +{ > > + unsigned long pfn = page_to_pfn(page); > > + struct range *tag_range; > > + int i; > > + > > + for (i = 0; i < num_tag_regions; i++) { > > + tag_range = &tag_regions[i].tag_range; > > + if (tag_range->start <= pfn && pfn <= tag_range->end) > > + return true; > > + } > > + > > + return false; > > +} > > + > > int reserve_tag_storage(struct page *page, int order, gfp_t gfp) > > { > > unsigned long start_block, end_block; > > diff --git a/arch/arm64/mm/fault.c b/arch/arm64/mm/fault.c > > index 6730a0812a24..964c5ae161a3 100644 > > --- a/arch/arm64/mm/fault.c > > +++ b/arch/arm64/mm/fault.c > > @@ -12,6 +12,7 @@ > > #include > > #include > > #include > > +#include > > #include > > #include > > #include > > @@ -956,6 +957,50 @@ void tag_clear_highpage(struct page *page) > > } > > > > #ifdef CONFIG_ARM64_MTE_TAG_STORAGE > > + > > +#define MR_TAGGED_TAG_STORAGE MR_ARCH_1 > > + > > +extern bool isolate_lru_page(struct page *page); > > +extern void putback_movable_pages(struct list_head *l); > > Could we move these declarations to a non-mm-internal header and > #include it instead of manually declaring them here? Yes, that's better than this hackish way of doing it. > > > + > > +/* Returns with the page reference dropped. */ > > +static void migrate_tag_storage_page(struct page *page) > > +{ > > + struct migration_target_control mtc = { > > + .nid = NUMA_NO_NODE, > > + .gfp_mask = GFP_HIGHUSER_MOVABLE | __GFP_TAGGED, > > + }; > > + unsigned long i, nr_pages = compound_nr(page); > > + LIST_HEAD(pagelist); > > + int ret, tries; > > + > > + lru_cache_disable(); > > + > > + for (i = 0; i < nr_pages; i++) { > > + if (!isolate_lru_page(page + i)) { > > + ret = -EAGAIN; > > + goto out; > > + } > > + /* Isolate just grabbed another reference, drop ours. */ > > + put_page(page + i); > > + list_add_tail(&(page + i)->lru, &pagelist); > > + } > > + > > + tries = 5; > > + while (tries--) { > > + ret = migrate_pages(&pagelist, alloc_migration_target, NULL, (unsigned long)&mtc, > > + MIGRATE_SYNC, MR_TAGGED_TAG_STORAGE, NULL); > > + if (ret == 0 || ret != -EBUSY) > > This could be simplified to: > > if (ret != -EBUSY) Indeed! I can do the same thing in reserve_tag_storage(), in the loop where I call alloc_contig_range(). Thanks, Alex