From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 31DFCC3DA7F for ; Mon, 5 Aug 2024 14:42:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=jXD94eK81SzpKGOoHJLQZUWayMa9lAkTG7KF/K0fyvE=; b=G+jYDzXBZOyuNfC/y3O/7xisx5 gXJzWyrmqRimD/L4wh1JbqltSqH/mt2a3Hft2LQo1PRZdiPbW3aTzB9UwZnep9aMg/P1KEGSLSiNm rycfzPqYu/A6gdwmoScbAdwHejGnic0n80Ps/clQEDamjwFndct10LRh5KlF3/X0GB9X+etOlvFIY 9YvvNp6ZO9zKx2Q7vW214CimDFCZn4KlAQOH3Y6cPHr83ygI2neKUhcE6IvloqIAZI24DizyvtWXq FNpa2NYcUuwQvw8JORUO3XccYvehHXmNP2SPJ0PI9pLs8hakctExcBjl3MvYGN7L0S6qNL7Qind9t cC0YnOyQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sayux-0000000GBIF-1h0I; Mon, 05 Aug 2024 14:42:35 +0000 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sayuR-0000000GB9w-16uv; Mon, 05 Aug 2024 14:42:04 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 0C63B60C5E; Mon, 5 Aug 2024 14:42:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4F5ADC4AF0C; Mon, 5 Aug 2024 14:41:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722868921; bh=KAAzyiSgI5VUznoplq6rpjnO/fNKSFt30uf+NxUGEms=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=QeZVbyPBXcN5TPefvaZdSJjjdX4y6Cq/DxczfJ+Znju3yHvNTlO4aXvamUiVWCNfm dJFw3BUgSadYOQ78s/G2NFZdYqOSMyUBf2zL4pLaMFZ2EewzmNmJ9Rhn37EaPRg84N 9/e8uP7RFruygWPGM1gHiLdkGIBlGPcbSW51E1iNan8BRdokqw6NeOBGxu0KFh/Qks mRAvGlnoK48IZtmY+61J7iNsk0pg1002E708O3v+oVXriGyhI/7ytWZoPV2JtIBVsT FjMUFjm01xX837WqtfHRuVUblGy21ffay5yDOackY6gR8nnfP4nTbw6GxA72f9QZSb FucTO3UZRmE+A== Date: Mon, 5 Aug 2024 17:39:41 +0300 From: Mike Rapoport To: Jonathan Cameron Cc: Andrew Morton , linux-kernel@vger.kernel.org, Alexander Gordeev , Andreas Larsson , Arnd Bergmann , Borislav Petkov , Catalin Marinas , Christophe Leroy , Dan Williams , Dave Hansen , David Hildenbrand , "David S. Miller" , Davidlohr Bueso , Greg Kroah-Hartman , Heiko Carstens , Huacai Chen , Ingo Molnar , Jiaxun Yang , John Paul Adrian Glaubitz , Jonathan Corbet , Michael Ellerman , Palmer Dabbelt , "Rafael J. Wysocki" , Rob Herring , Samuel Holland , Thomas Bogendoerfer , Thomas Gleixner , Vasily Gorbik , Will Deacon , Zi Yan , devicetree@vger.kernel.org, linux-acpi@vger.kernel.org, linux-arch@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-cxl@vger.kernel.org, linux-doc@vger.kernel.org, linux-mips@vger.kernel.org, linux-mm@kvack.org, linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org, linux-sh@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, loongarch@lists.linux.dev, nvdimm@lists.linux.dev, sparclinux@vger.kernel.org, x86@kernel.org Subject: Re: [PATCH v3 07/26] mm: drop CONFIG_HAVE_ARCH_NODEDATA_EXTENSION Message-ID: References: <20240801060826.559858-1-rppt@kernel.org> <20240801060826.559858-8-rppt@kernel.org> <20240802104922.000051a0@Huawei.com> <20240803115813.809f808f1afbe9f9feaae129@linux-foundation.org> <20240804161119.00003a02@Huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240804161119.00003a02@Huawei.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240805_074203_413433_01E287E1 X-CRM114-Status: GOOD ( 41.43 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Sun, Aug 04, 2024 at 04:11:19PM +0100, Jonathan Cameron wrote: > On Sun, 4 Aug 2024 10:24:15 +0300 > Mike Rapoport wrote: > > > On Sat, Aug 03, 2024 at 11:58:13AM -0700, Andrew Morton wrote: > > > On Fri, 2 Aug 2024 10:49:22 +0100 Jonathan Cameron wrote: > > > > > > > > --- a/mm/mm_init.c > > > > > +++ b/mm/mm_init.c > > > > > @@ -1838,11 +1838,10 @@ void __init free_area_init(unsigned long *max_zone_pfn) > > > > > > > > > > if (!node_online(nid)) { > > > > > /* Allocator not initialized yet */ > > > > > - pgdat = arch_alloc_nodedata(nid); > > > > > + pgdat = memblock_alloc(sizeof(*pgdat), SMP_CACHE_BYTES); > > > > > if (!pgdat) > > > > > panic("Cannot allocate %zuB for node %d.\n", > > > > > sizeof(*pgdat), nid); > > > > > - arch_refresh_nodedata(nid, pgdat); > > > > > > > > This allocates pgdat but never sets node_data[nid] to it > > > > and promptly leaks it on the line below. > > > > > > > > Just to sanity check this I spun up a qemu machine with no memory > > > > initially present on some nodes and it went boom as you'd expect. > > > > > > > > I tested with addition of > > > > NODE_DATA(nid) = pgdat; > > > > and it all seems to work as expected. > > > > > > Thanks, I added that. It blew up on x86_64 allnoconfig because > > > node_data[] (and hence NODE_DATA()) isn't an lvalue when CONFIG_NUMA=n. > > > > > > I'll put some #ifdef CONFIG_NUMAs in there for now but > > > > > > a) NODE_DATA() is upper-case. Implies "constant". Shouldn't be assigned to. > > > > > > b) NODE_DATA() should be non-lvalue when CONFIG_NUMA=y also. But no, > > > we insist on implementing things in cpp instead of in C. > > > > This looks like a candidate for a separate tree-wide cleanup. > > > > > c) In fact assigning to anything which ends in "()" is nuts. Please > > > clean up my tempfix. > > > > > > c) Mike, generally I'm wondering if there's a bunch of code here > > > which isn't needed on CONFIG_NUMA=n. Please check all of this for > > > unneeded bloatiness. > > > > I believe the patch addresses your concerns, just with this the commit log > > needs update. Instead of > > > > Replace the call to arch_alloc_nodedata() in free_area_init() with > > memblock_alloc(), remove arch_refresh_nodedata() and cleanup > > include/linux/memory_hotplug.h from the associated ifdefery. > > > > it should be > > > > Replace the call to arch_alloc_nodedata() in free_area_init() with a > > new helper alloc_offline_node_data(), remove arch_refresh_nodedata() > > and cleanup include/linux/memory_hotplug.h from the associated > > ifdefery. > > > > I can send an updated patch if you prefer. > This solution looks good to me - except for a Freudian typo that means it won't > compile :) Right :) I'll post v4 after kbuild confirms it compiles :) > Jonathan > > > > > diff --git a/include/linux/numa.h b/include/linux/numa.h > > index 3b12d8ca0afd..5a749fd67f39 100644 > > --- a/include/linux/numa.h > > +++ b/include/linux/numa.h > > @@ -34,6 +34,7 @@ extern struct pglist_data *node_data[]; > > #define NODE_DATA(nid) (node_data[nid]) > > > > void __init alloc_node_data(int nid); > > +void __init alloc_offline_node_data(int nit); > > > > /* Generic implementation available */ > > int numa_nearest_node(int node, unsigned int state); > > @@ -62,6 +63,8 @@ static inline int phys_to_target_node(u64 start) > > { > > return 0; > > } > > + > > +static inline void alloc_offline_node_data(int nit) {} > nid > > #endif > > > > #define numa_map_to_online_node(node) numa_nearest_node(node, N_ONLINE) > > diff --git a/mm/mm_init.c b/mm/mm_init.c > > index bcc2f2dd8021..2785be04e7bb 100644 > > --- a/mm/mm_init.c > > +++ b/mm/mm_init.c > > @@ -1836,13 +1836,8 @@ void __init free_area_init(unsigned long *max_zone_pfn) > > for_each_node(nid) { > > pg_data_t *pgdat; > > > > - if (!node_online(nid)) { > > - /* Allocator not initialized yet */ > > - pgdat = memblock_alloc(sizeof(*pgdat), SMP_CACHE_BYTES); > > - if (!pgdat) > > - panic("Cannot allocate %zuB for node %d.\n", > > - sizeof(*pgdat), nid); > > - } > > + if (!node_online(nid)) > > + alloc_offline_node_data(nid); > > > > pgdat = NODE_DATA(nid); > > free_area_init_node(nid); > > diff --git a/mm/numa.c b/mm/numa.c > > index da27eb151dc5..07e486a977c7 100644 > > --- a/mm/numa.c > > +++ b/mm/numa.c > > @@ -34,6 +34,18 @@ void __init alloc_node_data(int nid) > > memset(NODE_DATA(nid), 0, sizeof(pg_data_t)); > > } > > > > +void __init alloc_offline_node_data(int nit) > > nid > > > +{ > > + pg_data_t *pgdat; > > + > > + pgdat = memblock_alloc(sizeof(*pgdat), SMP_CACHE_BYTES); > > + if (!pgdat) > > + panic("Cannot allocate %zuB for node %d.\n", > > + sizeof(*pgdat), nid); > > + > > + node_data[nid] = pgdat; > > +} > > + > > /* Stub functions: */ > > > > #ifndef memory_add_physaddr_to_nid > > > > > > > > -- Sincerely yours, Mike.