From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796257679; b=2B5+zT4Vh9hkzygJTNuCTRhLiymjsqK1vl1nsj9LRtc/DQ3sPqZYtR/6XcYqZ1L2yKvC NnzOBUKnZTVyZWpscDzIQkhHLbnD3+rgIt6rKS6qOUaPKl/Seml6Ol694hbSgR7xbe+Up Ha+eW5CpIJTLJXj5VqoPsyniOizZc3vfxoqiLsJNPKEk2gH5nwdILewrVOvC1mIDJguvm 07McZMoDY9s76ZE0izS3DJq6B4GRkYxf4s2An94OSL2xxHWDynfemM5fBAo75o+WiGCxw /v7cFoFiw5q0kOCETVh7V43CqTSq9kMwV/xbaSsxW0v1GB7grYSss19pjV5ViUfEIQw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796257679; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=fkj+Nnk9apMOwKoq4jrWMIRPWthE2Aou2uSkaVSASpI=; b=wBIaUopEJs3rjFB3+Br1anWajJ4U69wWlHk189pbP4pOl1h/1yjH6r3PY0FcLv/a0/J7 9qy1sbGErOSXeReZ0j4pR9KpKVZjhjeWXngPm/KVjNpU1vapzViXjpTP4eSg9Dj2ZQViM mhwr9DSl739VodyOUgSwPJk9zDyugKS5mEJmp7IAi30ou76SLA60hiLW9jqz+U8TN0T/F xFY/QU5OpcVKK5i8RQrNbBG9J9KxK4QH/gCD2WqbbHvtfYc/M4SIDBoOYFsGEZWLLosV6 Epp2D/0l6AFMAgV9LCJ0sfZiAib5YQs1QlXQvVcCH6rfSy/IBjpqnkXkWomdrKtE3Ug== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=ShW876pp; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4C775606A322; Thu, 3 Dec 2026 00:27:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=ShW876pp Received: by smtp.kernel.org (Postfix) with ESMTPSA id A75371F00896; Thu, 3 Dec 2026 00:27:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796257678; bh=fkj+Nnk9apMOwKoq4jrWMIRPWthE2Aou2uSkaVSASpI=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=ShW876ppZqjxcuyTc6swRpJ57vzpP0T+N2rjog/OgNSKPYZbZB5ZjwW6nYGrqYo+E nWLRKa0RqgZe2408qLnUTa1dEySQtrRbNe+e2AoECGJlGoGClz6PFYdAzYwj4mfLll GqkN9V6PSO3pt/IzR7PUh6W6oPGI0X3yHC2VKs42O+joJ5uGKbFA+i6LyvsLPE/Mv1 rqbSsF1CIl+MJEZnVg7g4CSE0PVw70yJ6hphTP3v4dybODUBaaDskyKA7CtNCkflkv OyAwAVc88dui/NoDlcLtUt+2MxRUN50EtSqo4UrEbJpd1CUfGlD6H3zwdH8k1M5GMV nxQVAljZHr1uw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [RFC PATCH 05/11] mm/extmem: add architecture-neutral external memory subsystem Reply-To: sashiko-reviews@lists.linux.dev To: "Suseendran Bhaskaran" , "Andrew Morton" , "Mike Rapoport" , "Dan Williams" , "David Hildenbrand" Cc: "Alexander Graf" , "Alison Schofield" , "Andy Lutomirski" , "Borislav Petkov" , "Catalin Marinas" , "Changyuan Lyu" , "Dave Hansen" , "Dave Jiang" , "David Rientjes" , "Frank van der Linden" , "H. Peter Anvin" , "Ingo Molnar" , "Ira Weiny" , "Jonathan Corbet" , "Liam R. Howlett" , "Mark Rutland" , "Michal Hocko" , "Oscar Salvador" , "Pasha Tatashin" , "Peter Zijlstra" , "Pratyush Yadav" , "Randy Dunlap" , "Shuah Khan" , "Thomas Gleixner" , "Vishal Verma" , "Vlastimil Babka" , "Will Deacon" , kexec@lists.infradead.org, linux-cxl@vger.kernel.org, linux-mm@kvack.org, nvdimm@lists.linux.dev, x86@kernel.org In-Reply-To: <20261202001946.1226273-6-suseendranb@google.com> References: <20261202001946.1226273-1-suseendranb@google.com> <20261202001946.1226273-6-suseendranb@google.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Thu, 03 Dec 2026 00:27:57 +0000 X-Mailing-List: linux-cxl@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Medium] mm/extmem: premature memblock_phys_free() before memblock_remove() - [Medium] mm/extmem: unreleased System RAM iomem resource on unmap failure -- commit 832cde3acb6d693441f2a529f057ca782a706be9 Author: Suseendran Bhaskaran mm/extmem: add architecture-neutral external memory subsystem This commit adds CONFIG_EXTMEM and the extmem=3D early boot parameter to carve NUMA-aware physical memory regions out of memblock, unmap them from the direct map, and register them as "extmem" platform devices. > diff --git a/mm/extmem.c b/mm/extmem.c > new file mode 100644 > index 0000000000000..e5be9fcb6bbd6 > --- /dev/null > +++ b/mm/extmem.c [ ... ] > +static void __init extmem_carve_node(int nid, const struct extmem_rule *= rule) > +{ [ ... ] > + nr =3D memblock_reserve_contig_multi(rule->size, rule->align, rule->ali= gn, > + high_min, nid, flags, cands, > + max_ranges); > + if (nr < 0) { > + pr_err("failed to carve on %s above %pa (%pe)\n", > + scope, &high_min, ERR_PTR(nr)); > + return; > + } > + if (!nr) { > + pr_info("%s has no carvable memory above %pa\n", > + scope, &high_min); > + return; > + } > + > + for (k =3D 0; k < nr; k++) { > + memblock_phys_free(cands[k].base, cands[k].size); > + extmem_regions[extmem_nr_regions + k] =3D (struct extmem_region) { > + .base =3D cands[k].base, > + .size =3D cands[k].size, > + .align =3D rule->align, > + .nid =3D cands[k].nid, > + }; > + } > + > + if (extmem_commit_regions(nr, "carved")) > + pr_err("failed to remove carved range on %s\n", scope); > +} > + > +void __init extmem_init(void) > +{ > + unsigned long orig_end_pfn, new_end_pfn; > + unsigned int i, j; > + int nid; > + > + if (!extmem_nr_rules) > + return; > + > + orig_end_pfn =3D PFN_DOWN(memblock_end_of_DRAM()); > + memblock_set_bottom_up(false); [Severity: Medium] Can memblock_double_array() allocate the new memblock.memory.regions array inside a carved range? extmem_init() restores top-down allocation before the carving loop, and extmem_carve_node() frees all cands[] from memblock.reserved before extmem_commit_regions() calls memblock_remove(). If memblock_remove() -> memblock_isolate_range() triggers memblock_double_array(&memblock.memory, ...), the new array is allocated top-down from the highest unreserved address in memblock.memory, which is inside the unreserved cands[] range being removed (or at the top of a node to be carved by a subsequent rule). That range will then be removed from memblock.memory and unmapped from the direct map by extmem_unmap_regions(), causing a page fault or memory corruption when memblock.memory.regions is accessed. Keeping each candidate reserved in memblock.reserved until after memblock_remove() succeeds and deferring memblock_set_bottom_up(false) until the rule loop finishes would avoid this. [ ... ] > +void __init extmem_unmap_regions(void) > +{ > + unsigned int i, dst =3D 0; > + > + for (i =3D 0; i < extmem_nr_regions; i++) { > + struct extmem_region *reg =3D &extmem_regions[i]; > + phys_addr_t end =3D reg->base + reg->size - 1; > + int err; > + > + err =3D arch_boot_carveout_unmap(reg->base, reg->size); > + if (err) { > + pr_err("failed to unmap [%pa-%pa]: %pe\n", > + ®->base, &end, ERR_PTR(err)); > + continue; > + } > + > + extmem_regions[dst++] =3D *reg; > + } > + extmem_nr_regions =3D dst; > +} [Severity: Medium] If arch_boot_carveout_unmap() fails, does dropping reg from extmem_regions[] leave its range registered as System RAM in iomem_resource? release_mem_region_adjustable() is only called later in extmem_publish_regions() for entries that remain in extmem_regions[]. A region that fails to unmap was already removed from memblock.memory before sparse_init() and has no struct pages, so leaving it as System RAM in iomem_resource on x86_64 allows walk_system_ram_range() consumers to dereference unmapped struct page pointers. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261202001946.1226= 273-1-suseendranb@google.com?part=3D5