Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp6076328rdb; Thu, 14 Dec 2023 07:47:36 -0800 (PST) X-Google-Smtp-Source: AGHT+IGsn2Uc6oN+c4VN9Sf0H5DV/6bIYBV7JI1L6jsAwjBEq+kyjeHNYs7lbavpmlZVqjW/GnTw X-Received: by 2002:a05:6a00:b51:b0:6cb:cd66:2102 with SMTP id p17-20020a056a000b5100b006cbcd662102mr12163232pfo.4.1702568856602; Thu, 14 Dec 2023 07:47:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702568856; cv=none; d=google.com; s=arc-20160816; b=Em2htkD9SeHBFsJrFPZO5PZDbDWkg6xNXZ0fUAWDc2Rm9C/ic4XKFRTK6rJBNEko5F v+wcRBj6wu8qgKvvAC+kc+cOoF4JBJ8Gazh0UiealzInKMjXHk7WpFoAjw5smlB7pEL2 TA8jxfZbDTkVb6m+eGNTCHet9L0MxaKgrR15elgBaDGgGod4iD0xatXIYjrxF+TKjyb1 FLcn/vty/QjIr+M+g5Kopv3/pVx85tnBx2J6FscuyvnXF/a9qyj4dpNbMIukCqtZT8Ya a491EN+lI0IGf/VsiSXhZ4PfB5n4WH7NfesmV5wT+B5XUO4uZeqnVNMl+f067P5WS5Iv TNnw== 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=ZOSB1N0/kVoK5KC0zvX+4SiSJeaBimjyRiFK7tlWAl0=; fh=Dxhchp7NF0DUA7FI7KVeniDzkjyix/d7ETvu1rPCCSM=; b=tTApciT0ge2Si56//W6PFgjseXFtLa/phcx9e5Vgpq6HDBqPvAViHn4O34KsXKshp6 KtxrFI6+LDFuDq4IXpY9Jyw1iDJoqcLWr67SrYf89OeMWfJ0mcaK6f/5syp3jAUkbQLU OrUbcSnDy027pS218UCwubse3r8kWwxs6rwOuf4xqSftrAlT7xEiytMSTppKhBhAXK9G eecEdPQEZzx3jaFaFrzMhNb89JmC/57u9tveT2aIPr3ywL7Kh3T4YaPA9btMxnrU6BY2 vkm6tVDo/b6UfZzv3wD7AKsAqJcosu+DHH8rSufdGAjam4NsZHB6YOLsA7vUeUskjXET 1YkA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id x2-20020a62fb02000000b006ce91f9ff99si345188pfm.42.2023.12.14.07.47.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 07:47:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 BF85E80755FB; Thu, 14 Dec 2023 07:46:08 -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 S1573871AbjLNPpc (ORCPT + 99 others); Thu, 14 Dec 2023 10:45:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46114 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1573858AbjLNPpb (ORCPT ); Thu, 14 Dec 2023 10:45:31 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 6ADFB9A; Thu, 14 Dec 2023 07:45:37 -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 9BF2AC15; Thu, 14 Dec 2023 07:46:22 -0800 (PST) Received: from raptor (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id EA4D93F5A1; Thu, 14 Dec 2023 07:45:31 -0800 (PST) Date: Thu, 14 Dec 2023 15:45:25 +0000 From: Alexandru Elisei To: Rob Herring 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, 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 11/27] arm64: mte: Reserve tag storage memory Message-ID: References: <20231119165721.9849-12-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, 14 Dec 2023 07:46:08 -0800 (PST) Hi, On Wed, Dec 13, 2023 at 02:30:42PM -0600, Rob Herring wrote: > On Wed, Dec 13, 2023 at 11:44 AM Alexandru Elisei > wrote: > > > > On Wed, Dec 13, 2023 at 11:22:17AM -0600, Rob Herring wrote: > > > On Wed, Dec 13, 2023 at 8:51 AM Alexandru Elisei > > > wrote: > > > > > > > > Hi, > > > > > > > > On Wed, Dec 13, 2023 at 08:06:44AM -0600, Rob Herring wrote: > > > > > On Wed, Dec 13, 2023 at 7:05 AM Alexandru Elisei > > > > > wrote: > > > > > > > > > > > > Hi Rob, > > > > > > > > > > > > On Tue, Dec 12, 2023 at 12:44:06PM -0600, Rob Herring wrote: > > > > > > > On Tue, Dec 12, 2023 at 10:38 AM Alexandru Elisei > > > > > > > wrote: > > > > > > > > > > > > > > > > Hi Rob, > > > > > > > > > > > > > > > > Thank you so much for the feedback, I'm not very familiar with device tree, > > > > > > > > and any comments are very useful. > > > > > > > > > > > > > > > > On Mon, Dec 11, 2023 at 11:29:40AM -0600, Rob Herring wrote: > > > > > > > > > On Sun, Nov 19, 2023 at 10:59 AM Alexandru Elisei > > > > > > > > > wrote: > > > > > > > > > > > > > > > > > > > > Allow the kernel to get the size and location of the MTE tag storage > > > > > > > > > > regions from the DTB. This memory is marked as reserved for now. > > > > > > > > > > > > > > > > > > > > The DTB node for the tag storage region is defined as: > > > > > > > > > > > > > > > > > > > > tags0: tag-storage@8f8000000 { > > > > > > > > > > compatible = "arm,mte-tag-storage"; > > > > > > > > > > reg = <0x08 0xf8000000 0x00 0x4000000>; > > > > > > > > > > block-size = <0x1000>; > > > > > > > > > > memory = <&memory0>; // Associated tagged memory node > > > > > > > > > > }; > > > > > > > > > > > > > > > > > > I skimmed thru the discussion some. If this memory range is within > > > > > > > > > main RAM, then it definitely belongs in /reserved-memory. > > > > > > > > > > > > > > > > Ok, will do that. > > > > > > > > > > > > > > > > If you don't mind, why do you say that it definitely belongs in > > > > > > > > reserved-memory? I'm not trying to argue otherwise, I'm curious about the > > > > > > > > motivation. > > > > > > > > > > > > > > Simply so that /memory nodes describe all possible memory and > > > > > > > /reserved-memory is just adding restrictions. It's also because > > > > > > > /reserved-memory is what gets handled early, and we don't need > > > > > > > multiple things to handle early. > > > > > > > > > > > > > > > Tag storage is not DMA and can live anywhere in memory. > > > > > > > > > > > > > > Then why put it in DT at all? The only reason CMA is there is to set > > > > > > > the size. It's not even clear to me we need CMA in DT either. The > > > > > > > reasoning long ago was the kernel didn't do a good job of moving and > > > > > > > reclaiming contiguous space, but that's supposed to be better now (and > > > > > > > most h/w figured out they need IOMMUs). > > > > > > > > > > > > > > But for tag storage you know the size as it is a function of the > > > > > > > memory size, right? After all, you are validating the size is correct. > > > > > > > I guess there is still the aspect of whether you want enable MTE or > > > > > > > not which could be done in a variety of ways. > > > > > > > > > > > > Oh, sorry, my bad, I should have been clearer about this. I don't want to > > > > > > put it in the DT as a "linux,cma" node. But I want it to be managed by CMA. > > > > > > > > > > Yes, I understand, but my point remains. Why do you need this in DT? > > > > > If the location doesn't matter and you can calculate the size from the > > > > > memory size, what else is there to add to the DT? > > > > > > > > I am afraid there has been a misunderstanding. What do you mean by > > > > "location doesn't matter"? > > > > > > You said: > > > > Tag storage is not DMA and can live anywhere in memory. > > > > > > Which I took as the kernel can figure out where to put it. But maybe > > > you meant the h/w platform can hard code it to be anywhere in memory? > > > If so, then yes, DT is needed. > > > > Ah, I see, sorry for not being clear enough, you are correct: tag storage > > is a hardware property, and software needs a mechanism (in this case, the > > dt) to discover its properties. > > > > > > > > > At the very least, Linux needs to know the address and size of a memory > > > > region to use it. The series is about using the tag storage memory for > > > > data. Tag storage cannot be described as a regular memory node because it > > > > cannot be tagged (and normal memory can). > > > > > > If the tag storage lives in the middle of memory, then it would be > > > described in the memory node, but removed by being in reserved-memory > > > node. > > > > I don't follow. Would you mind going into more details? > > It goes back to what I said earlier about /memory nodes describing all > the memory. There's no reason to reserve memory if you haven't > described that range as memory to begin with. One could presumably > just have a memory node for each contiguous chunk and not need > /reserved-memory (ignoring the need to say what things are reserved > for). That would become very difficult to adjust. Note that the kernel > has a hardcoded limit of 64 reserved regions currently and that is not > enough for some people. Seems like a lot, but I have no idea how they > are (ab)using /reserved-memory. Ah, I see what you mean, reserved memory is about marking existing memory (from a /memory node) as special, not about adding new memory. After the memblock allocator is initialized, the kernel can use it for its own allocations. Kernel allocations are not movable. When a page is allocated as tagged, the associated tag storage cannot be used for data, otherwise the tags would corrupt that data. To avoid this, the requirement is that tag storage pages are only used for movable allocations. When a page is allocated as tagged, the data in the associated tag storage is migrated and the tag storage is taken from the page allocator (via alloc_contig_range()). My understanding is that the memblock allocator can use all the memory from a /memory node. If the tags storage memory is declared in a /memory node, there exists the possibility that Linux will use tag storage memory for its own allocation, which would make that tags storage memory unmovable, and thus unusable for storing tags. Looking at early_init_dt_scan_memory(), even if a /memory node if marked at hotpluggable, memblock will still use it, unless "movable_node" is set on the kernel command line. That's the reason why I'm not describing tag storage in a /memory node. Is there way to tell the memblock allocator not to use memory from a /memory node? > > Let me give an example. Presumably using MTE at all is configurable. > If you boot a kernel with MTE disabled (or older and not supporting > it), then I'd assume you'd want to use the tag storage for regular > memory. Well, If tag storage is already part of /memory, then all you > have to do is ignore the tag reserved-memory region. Tweaking the > memory nodes would be more work. Right now, memory is added via memblock_reserve(), and if MTE is disabled (for example, via the kernel command line), the code calls free_reserved_page() for each tag storage page. I find that straightfoward to implement. Thanks, Alex > > > Also, I should point out that /memory and /reserved-memory nodes are > not used for UEFI boot. > > Rob >