Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp6200848rdb; Thu, 14 Dec 2023 10:55:56 -0800 (PST) X-Google-Smtp-Source: AGHT+IHZb9I9cMwq9OlbOI4LgnfCNCLpbswmltX52R1rcoYz1fogJeicUGVdQHZieJ7Kjz8O3hRv X-Received: by 2002:a17:902:d487:b0:1d3:7bec:18e1 with SMTP id c7-20020a170902d48700b001d37bec18e1mr537597plg.121.1702580155727; Thu, 14 Dec 2023 10:55:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702580155; cv=none; d=google.com; s=arc-20160816; b=iBNt7WfBkThgopO9HChgPlcZJo61hZ06++MBqvYOT13iqpktqOAaAY/55pAagIGOEX 8XbJvjKI6Vci0A5oTo0sdLB2Z/RfqY35Mbv9ouUloH3EefhEXCbIMj3j4dgCx/exp+ea xywPIo3BaL7z7nGPgaIiCpFlAha8cxqK6GP8XRfEbpxRQyFDwSl+7nEhD7KjoNXH0ZdX 6XHgw2A6sQjsQW+a+p0p3gNzhJbumBa1I62rj5V1deCPkWe7pamF3/wE1ppyoMsXs+Br a20Vejj0N9D8Y4Veu1LyvYKHDaroCro4kDPWVKHErxpsw2x7QOn3B3CXxlMuiEjjIT6v vUsQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=whUVc6PuMubWbdcjltNO6UQDuVItLHqVHlctgOM4h7o=; fh=Ec5RhzHTMEEKj/X/gkLEoXglicTn4H/vwymGVTsgQvw=; b=jIh3Cr+yItuhTpUTVgoyOlyYzV65Tdni42rKXafUDIKZaXrvhFm0ZTzOdd5F1CqCeA rjy+UXiHKMUOHVOgGMFfL9vqQn/19AGoTlWIrzBoSSwR9h0YYUO7dkv52TgOfEW4zf2m FZfUidVy7iq2iMCKRJLV5zeDNRdIsUn6DVBPFcHZuWDYIy0K1Paix5J23OMxU5HfkDz+ mfFPc3llGuukG+SFZI1TfnXR2CPLXJtEzx9MJ3yBhcT5usskq/MBRmEbx7crbbi3OeHV ufkxFabJZwf4CpDdp89Whs2WQUq9q5966E40ObEUxPxk6EkbcqkQiWqsWQT9U4GeY9As 6LBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=gNQWZJxL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id x4-20020a170902ec8400b001c88fc3c593si12383655plg.560.2023.12.14.10.55.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 10:55:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=gNQWZJxL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id E3442827033E; Thu, 14 Dec 2023 10:55:45 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1573132AbjLNSzY (ORCPT + 99 others); Thu, 14 Dec 2023 13:55:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50788 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229519AbjLNSzY (ORCPT ); Thu, 14 Dec 2023 13:55:24 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B1321A0 for ; Thu, 14 Dec 2023 10:55:29 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 50A97C433CA; Thu, 14 Dec 2023 18:55:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1702580129; bh=nci52wgEP29pe93sJfvh7z3E961dOjZ6XELoPwO7AJ0=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=gNQWZJxLGAyg3thh8sppsdtne0S14JwyQcivHbHv7WO114nKNzDxo48NPc6NwYych LICtIuEwziEeq/jC1lhaXr9ngYWoZaqo8fUMS/56euTdwBx/kPmE7C+R0ZGJ1IKzrC tVwMMIGyAkxdOTcUZeHtX/oH7Bydean26t2VSLflEoxoggGkGn/iOrGO8984m5MjWF 6g6HOVwqpoozuR4ruL1FZairOzZ7r/I7gsRUbrIno5RR1LH/MvdqsoVIm43vGmBRJL vDwFwwCLWushNGNgEe0Jm42brbIwAIz/lHY9dFRME70eLb5XNXSRgbJ4ah8tKyaXMg S4KZ7ptfgHhzQ== Received: by mail-lf1-f41.google.com with SMTP id 2adb3069b0e04-50bf32c0140so9612505e87.1; Thu, 14 Dec 2023 10:55:29 -0800 (PST) X-Gm-Message-State: AOJu0YxiTCAhY2AQ5BIIh/0VUE3tqq/dEH7sH5AZSHS4ZPq4T1cnOoUl 5RhUfBRWtEf53n4Cfx0PVrbTm5G1zO+vPPMMhA== X-Received: by 2002:ac2:51b0:0:b0:50b:fd52:e629 with SMTP id f16-20020ac251b0000000b0050bfd52e629mr4153621lfk.125.1702580127399; Thu, 14 Dec 2023 10:55:27 -0800 (PST) MIME-Version: 1.0 References: <20231119165721.9849-12-alexandru.elisei@arm.com> In-Reply-To: From: Rob Herring Date: Thu, 14 Dec 2023 12:55:14 -0600 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH RFC v2 11/27] arm64: mte: Reserve tag storage memory To: Alexandru Elisei 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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 groat.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 (groat.vger.email [0.0.0.0]); Thu, 14 Dec 2023 10:55:46 -0800 (PST) On Thu, Dec 14, 2023 at 9:45=E2=80=AFAM Alexandru Elisei wrote: > > Hi, > > On Wed, Dec 13, 2023 at 02:30:42PM -0600, Rob Herring wrote: > > On Wed, Dec 13, 2023 at 11:44=E2=80=AFAM Alexandru Elisei > > wrote: > > > > > > On Wed, Dec 13, 2023 at 11:22:17AM -0600, Rob Herring wrote: > > > > On Wed, Dec 13, 2023 at 8:51=E2=80=AFAM 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=E2=80=AFAM 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=E2=80=AFAM 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 wro= te: > > > > > > > > > > On Sun, Nov 19, 2023 at 10:59=E2=80=AFAM Alexandru Elis= ei > > > > > > > > > > wrote: > > > > > > > > > > > > > > > > > > > > > > Allow the kernel to get the size and location of the = MTE tag storage > > > > > > > > > > > regions from the DTB. This memory is marked as reserv= ed for now. > > > > > > > > > > > > > > > > > > > > > > The DTB node for the tag storage region is defined as= : > > > > > > > > > > > > > > > > > > > > > > tags0: tag-storage@8f8000000 { > > > > > > > > > > > compatible =3D "arm,mte-tag-storage"; > > > > > > > > > > > reg =3D <0x08 0xf8000000 0x00 0x40000= 00>; > > > > > > > > > > > block-size =3D <0x1000>; > > > > > > > > > > > memory =3D <&memory0>; // Associat= ed tagged memory node > > > > > > > > > > > }; > > > > > > > > > > > > > > > > > > > > I skimmed thru the discussion some. If this memory rang= e is within > > > > > > > > > > main RAM, then it definitely belongs in /reserved-memor= y. > > > > > > > > > > > > > > > > > > Ok, will do that. > > > > > > > > > > > > > > > > > > If you don't mind, why do you say that it definitely belo= ngs in > > > > > > > > > reserved-memory? I'm not trying to argue otherwise, I'm c= urious about the > > > > > > > > > motivation. > > > > > > > > > > > > > > > > Simply so that /memory nodes describe all possible memory a= nd > > > > > > > > /reserved-memory is just adding restrictions. It's also bec= ause > > > > > > > > /reserved-memory is what gets handled early, and we don't n= eed > > > > > > > > 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 eithe= r. The > > > > > > > > reasoning long ago was the kernel didn't do a good job of m= oving and > > > > > > > > reclaiming contiguous space, but that's supposed to be bett= er now (and > > > > > > > > most h/w figured out they need IOMMUs). > > > > > > > > > > > > > > > > But for tag storage you know the size as it is a function o= f the > > > > > > > > memory size, right? After all, you are validating the size = is correct. > > > > > > > > I guess there is still the aspect of whether you want enabl= e MTE or > > > > > > > > not which could be done in a variety of ways. > > > > > > > > > > > > > > Oh, sorry, my bad, I should have been clearer about this. I d= on't want to > > > > > > > put it in the DT as a "linux,cma" node. But I want it to be m= anaged by CMA. > > > > > > > > > > > > Yes, I understand, but my point remains. Why do you need this i= n DT? > > > > > > If the location doesn't matter and you can calculate the size f= rom the > > > > > > memory size, what else is there to add to the DT? > > > > > > > > > > I am afraid there has been a misunderstanding. What do you mean b= y > > > > > "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 mayb= e > > > > you meant the h/w platform can hard code it to be anywhere in memor= y? > > > > If so, then yes, DT is needed. > > > > > > Ah, I see, sorry for not being clear enough, you are correct: tag sto= rage > > > 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 memor= y for > > > > > data. Tag storage cannot be described as a regular memory node be= cause 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-memo= ry > > > > 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 it= s > 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 associat= ed > 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 fr= om > 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 i= ts > own allocation, which would make that tags storage memory unmovable, and > thus unusable for storing tags. No, because the tag storage would be reserved in /reserved-memory. Of course, the arch code could do something between scanning /memory nodes and /reserved-memory, but that would be broken arch code. Ideally, there wouldn't be any arch code in between those 2 points, but it's complicated. It used to mainly be powerpc, but we keep adding to the complexity on arm64. > 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 straightfowar= d > to implement. But better to just not reserve the region in the first place. Also, it needs to be simple enough to back port. Also, does free_reserved_page() work on ranges outside of memblock range (e.g. beyond end_of_DRAM())? If the tag storage happened to live at the end of DRAM and you shorten the /memory node size to remove tag storage, is it still going to work? Rob