Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp4003451rdb; Mon, 11 Dec 2023 06:23:16 -0800 (PST) X-Google-Smtp-Source: AGHT+IEDcatILv0QDF/fb4OabNfJJaWVJEsJ/J9Gqt4gnlemWuEVUVpH/97Ng1LlZT8NJxwNus1c X-Received: by 2002:a05:6a00:b51:b0:6ce:4fdd:9d32 with SMTP id p17-20020a056a000b5100b006ce4fdd9d32mr1890211pfo.69.1702304595731; Mon, 11 Dec 2023 06:23:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702304595; cv=none; d=google.com; s=arc-20160816; b=p8XgImpXxFT60zE1lwkDfzYXSJrTNzguIxgxzVFa2o1UCcpIYLIcm3PqHTTdVdxgKQ i5UdIf8dF0tBmq/NQUorlvwJ/6EU8qXnwp7+0PpBh/Gv9kxaD38rfImzYgfvNJGNp+jD 3cEXIZ24SFmhwEmmIR3oaB7mIKbAURWs3sDjR2cqy5iqGufvNl+n44EvRvGmaNmnPVAP r2p3vNzL+BjQyYZzvurjLRbuhSRpcAtj69jgcZ6bPDOtn6xzGCPDFoS+TVJTP1vwO6kZ DQHuTATeKAft72fpBTwfHiPtFCjJdCmWmQTmF7kf5dNM3g8M5vbES3ngYVPXJgGDQsFS z2Qg== 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-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=yvXN0QYJYRneuzO+deLrBP5+glsRKP10hBVb2RGuxcY=; fh=662FnxvaMUPpGpbpQaKOb5FYDcM6B26e8RC2ZBxI39o=; b=LN/G6U0pf9KaCjCzEFDhFcd838M3SJ7jCzqYhXORhYETlfRYP+CGfOjtPBBhEnUw2o A7VD/zG1W+Rahj92zSvL0fbSwBAC7uedtI7WPYG1eLdcrgfSFh/vRH+I26+xNhkA2jaH uZZvjjo5UTn7iT/azA6MN80W01C6FNq+lOS8hicbPCCf/FcM2rWpyZ9DpBQ6OM+wYD2z TSHLEjHlgBxW3zPDvUlaMm9+KPe2EU8C7LQs5YhgrLSfZHmRlS6JU9RwiEFKpwGoUREa xYRN3x/8slCmc/m/DKUtiGItrKkBppvcgVV4RS+bsz318Q02zOJhIV0mFGunAQxnK4ik SvzA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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 lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id b10-20020a056a00114a00b006ce4de73f9bsi6040612pfm.117.2023.12.11.06.23.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 06:23:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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 lipwig.vger.email (Postfix) with ESMTP id 14BA08098AEB; Mon, 11 Dec 2023 06:23:12 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235061AbjLKOWw (ORCPT + 99 others); Mon, 11 Dec 2023 09:22:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37738 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343850AbjLKOWk (ORCPT ); Mon, 11 Dec 2023 09:22:40 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 366931BF6; Mon, 11 Dec 2023 06:21:45 -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 2C2ECFEC; Mon, 11 Dec 2023 06:22:31 -0800 (PST) Received: from raptor (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 613B73F738; Mon, 11 Dec 2023 06:21:39 -0800 (PST) Date: Mon, 11 Dec 2023 14:21:36 +0000 From: Alexandru Elisei To: Hyesoo Yu 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, pcc@google.com, steven.price@arm.com, anshuman.khandual@arm.com, vincenzo.frascino@arm.com, david@redhat.com, eugenis@google.com, kcc@google.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 15/27] arm64: mte: Check that tag storage blocks are in the same zone Message-ID: References: <20231119165721.9849-1-alexandru.elisei@arm.com> <20231119165721.9849-16-alexandru.elisei@arm.com> <20231129085744.GB2988384@tiffany> <20231208052739.GB1359878@tiffany> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231208052739.GB1359878@tiffany> X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email 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 (lipwig.vger.email [0.0.0.0]); Mon, 11 Dec 2023 06:23:12 -0800 (PST) Hi, On Fri, Dec 08, 2023 at 02:27:39PM +0900, Hyesoo Yu wrote: > Hi~ > > On Thu, Nov 30, 2023 at 12:00:11PM +0000, Alexandru Elisei wrote: > > Hi, > > > > On Wed, Nov 29, 2023 at 05:57:44PM +0900, Hyesoo Yu wrote: > > > On Sun, Nov 19, 2023 at 04:57:09PM +0000, Alexandru Elisei wrote: > > > > alloc_contig_range() requires that the requested pages are in the same > > > > zone. Check that this is indeed the case before initializing the tag > > > > storage blocks. > > > > > > > > Signed-off-by: Alexandru Elisei > > > > --- > > > > arch/arm64/kernel/mte_tag_storage.c | 33 +++++++++++++++++++++++++++++ > > > > 1 file changed, 33 insertions(+) > > > > > > > > diff --git a/arch/arm64/kernel/mte_tag_storage.c b/arch/arm64/kernel/mte_tag_storage.c > > > > index 8b9bedf7575d..fd63430d4dc0 100644 > > > > --- a/arch/arm64/kernel/mte_tag_storage.c > > > > +++ b/arch/arm64/kernel/mte_tag_storage.c > > > > @@ -265,6 +265,35 @@ void __init mte_tag_storage_init(void) > > > > } > > > > } > > > > > > > > +/* alloc_contig_range() requires all pages to be in the same zone. */ > > > > +static int __init mte_tag_storage_check_zone(void) > > > > +{ > > > > + struct range *tag_range; > > > > + struct zone *zone; > > > > + unsigned long pfn; > > > > + u32 block_size; > > > > + int i, j; > > > > + > > > > + for (i = 0; i < num_tag_regions; i++) { > > > > + block_size = tag_regions[i].block_size; > > > > + if (block_size == 1) > > > > + continue; > > > > + > > > > + tag_range = &tag_regions[i].tag_range; > > > > + for (pfn = tag_range->start; pfn <= tag_range->end; pfn += block_size) { > > > > + zone = page_zone(pfn_to_page(pfn)); > > > > > > Hello. > > > > > > Since the blocks within the tag_range must all be in the same zone, can we move the "page_zone" > > > out of the loop ? > > ` > > Hmm.. why do you say that the pages in a tag_range must be in the same > > zone? I am not very familiar with how the memory management code puts pages > > into zones, but I would imagine that pages in a tag range straddling the > > 4GB limit (so, let's say, from 3GB to 5GB) will end up in both ZONE_DMA and > > ZONE_NORMAL. > > > > Thanks, > > Alex > > > > Oh, I see that reserve_tag_storage only calls alloc_contig_rnage in units of block_size, > I thought it could be called for the entire range the page needed at once. > (Maybe it could be a bit faster ? It doesn't seem like unnecessary drain and > other operation are repeated.) Yes, that might be useful to do. Worth keeping in mind is that: - a number of block size pages at the start and end of the range might already be reserved for other tagged pages, so the actual range that is being reserved might end up being smaller that what we are expecting. - the most common allocation order is smaller or equal to PAGE_ALLOC_COSTLY_ORDER, which is 3, which means that the most common case is that reserve_tag_storage reserves only one tag storage block. I will definitely keep this optimization in mind, but I would prefer to get the series into a more stable shape before looking at performance optimizations. > > If we use the cma code when activating the tag storage, it will be error if the > entire area of tag region is not in the same zone, so there should be a constraint > that it must be in the same zone when defining the tag region on device tree. I don't think that's the best approach, because the device tree describes the hardware, which does not change, and this is a software limitation (i.e, CMA doesn't work if a CMA region spans different zones), which might get fixed in a future version of Linux. In my opinion, the simplest solution would be to check that all tag storage regions have been activated successfully by CMA before enabling tag storage. Another alternative would be to split the tag storage region into several CMA regions at a zone boundary, and add it as distinct CMA regions. Thanks, Alex > > Thanks, > Regards. > > > > > > > Thanks, > > > Regards. > > > > > > > + for (j = 1; j < block_size; j++) { > > > > + if (page_zone(pfn_to_page(pfn + j)) != zone) { > > > > + pr_err("Tag storage block pages in different zones"); > > > > + return -EINVAL; > > > > + } > > > > + } > > > > + } > > > > + } > > > > + > > > > + return 0; > > > > +} > > > > + > > > > static int __init mte_tag_storage_activate_regions(void) > > > > { > > > > phys_addr_t dram_start, dram_end; > > > > @@ -321,6 +350,10 @@ static int __init mte_tag_storage_activate_regions(void) > > > > goto out_disabled; > > > > } > > > > > > > > + ret = mte_tag_storage_check_zone(); > > > > + if (ret) > > > > + goto out_disabled; > > > > + > > > > for (i = 0; i < num_tag_regions; i++) { > > > > tag_range = &tag_regions[i].tag_range; > > > > for (pfn = tag_range->start; pfn <= tag_range->end; pfn += pageblock_nr_pages) > > > > -- > > > > 2.42.1 > > > > > > > > > > > > > >