Linux CXL
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Suseendran Bhaskaran" <suseendranb@google.com>,
	"Andrew Morton" <akpm@linux-foundation.org>,
	"Mike Rapoport" <rppt@kernel.org>,
	"Dan Williams" <djbw@kernel.org>,
	"David Hildenbrand" <david@kernel.org>
Cc: "Alexander Graf" <graf@amazon.com>,
	"Alison Schofield" <alison.schofield@intel.com>,
	"Andy Lutomirski" <luto@kernel.org>,
	"Borislav Petkov" <bp@alien8.de>,
	"Catalin Marinas" <catalin.marinas@arm.com>,
	"Changyuan Lyu" <changyuanl@google.com>,
	"Dave Hansen" <dave.hansen@linux.intel.com>,
	"Dave Jiang" <dave.jiang@intel.com>,
	"David Rientjes" <rientjes@google.com>,
	"Frank van der Linden" <fvdl@google.com>,
	"H. Peter Anvin" <hpa@zytor.com>,
	"Ingo Molnar" <mingo@redhat.com>, "Ira Weiny" <iweiny@kernel.org>,
	"Jonathan Corbet" <corbet@lwn.net>,
	"Liam R. Howlett" <liam@infradead.org>,
	"Mark Rutland" <mark.rutland@arm.com>,
	"Michal Hocko" <mhocko@suse.com>,
	"Oscar Salvador" <osalvador@suse.de>,
	"Pasha Tatashin" <pasha.tatashin@soleen.com>,
	"Peter Zijlstra" <peterz@infradead.org>,
	"Pratyush Yadav" <pratyush@kernel.org>,
	"Randy Dunlap" <rdunlap@infradead.org>,
	"Shuah Khan" <skhan@linuxfoundation.org>,
	"Thomas Gleixner" <tglx@kernel.org>,
	"Vishal Verma" <vishal.l.verma@intel.com>,
	"Vlastimil Babka" <vbabka@kernel.org>,
	"Will Deacon" <will@kernel.org>,
	kexec@lists.infradead.org, linux-cxl@vger.kernel.org,
	linux-mm@kvack.org, nvdimm@lists.linux.dev, x86@kernel.org
Subject: Re: [RFC PATCH 05/11] mm/extmem: add architecture-neutral external memory subsystem
Date: Thu, 03 Dec 2026 00:27:57 +0000	[thread overview]
Message-ID: <sashiko-outbox-246842@kernel.org> (raw)
In-Reply-To: <20261202001946.1226273-6-suseendranb@google.com>

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 <suseendranb@google.com>

mm/extmem: add architecture-neutral external memory subsystem

This commit adds CONFIG_EXTMEM and the extmem= 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 = memblock_reserve_contig_multi(rule->size, rule->align, rule->align,
> +					   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 = 0; k < nr; k++) {
> +		memblock_phys_free(cands[k].base, cands[k].size);
> +		extmem_regions[extmem_nr_regions + k] = (struct extmem_region) {
> +			.base = cands[k].base,
> +			.size = cands[k].size,
> +			.align = rule->align,
> +			.nid = 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 = 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 = 0;
> +
> +	for (i = 0; i < extmem_nr_regions; i++) {
> +		struct extmem_region *reg = &extmem_regions[i];
> +		phys_addr_t end = reg->base + reg->size - 1;
> +		int err;
> +
> +		err = arch_boot_carveout_unmap(reg->base, reg->size);
> +		if (err) {
> +			pr_err("failed to unmap [%pa-%pa]: %pe\n",
> +			       &reg->base, &end, ERR_PTR(err));
> +			continue;
> +		}
> +
> +		extmem_regions[dst++] = *reg;
> +	}
> +	extmem_nr_regions = 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.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261202001946.1226273-1-suseendranb@google.com?part=5

  reply	other threads:[~2026-12-03  0:27 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02  0:19 [RFC PATCH 00/11] mm: NUMA-aware boot memory carving (extmem) Suseendran Bhaskaran
2026-12-02  0:19 ` [RFC PATCH 01/11] mm/cma: clamp multi-range search to 4G and honor memblock flags Suseendran Bhaskaran
2026-12-02  0:19 ` [RFC PATCH 02/11] mm/memblock: factor out multi-range contiguous reservation helper from CMA Suseendran Bhaskaran
2026-12-02  0:19 ` [RFC PATCH 03/11] x86/mm: add early direct-map unmap helpers for boot carveouts Suseendran Bhaskaran
2026-12-02  0:19 ` [RFC PATCH 04/11] arm64/mm: support unmapping boot carveouts from the linear map Suseendran Bhaskaran
2026-12-02  0:19 ` [RFC PATCH 05/11] mm/extmem: add architecture-neutral external memory subsystem Suseendran Bhaskaran
2026-12-03  0:27   ` sashiko-bot [this message]
2026-12-02  0:19 ` [RFC PATCH 06/11] dax/hmem: bind extmem platform devices with per-region alignment Suseendran Bhaskaran
2026-12-02  0:19 ` [RFC PATCH 07/11] nvdimm/ramdax: manage bus and DIMM allocations with devres Suseendran Bhaskaran
2026-12-02  0:19 ` [RFC PATCH 08/11] nvdimm/ramdax: harden probe checks and select NUMA_KEEP_MEMINFO Suseendran Bhaskaran
2026-12-02  0:19 ` [RFC PATCH 09/11] nvdimm/ramdax: support binding extmem platform devices Suseendran Bhaskaran
2026-12-02  0:19 ` [RFC PATCH 10/11] x86/kaslr: avoid placing kernel in carvable high memory when extmem= is set Suseendran Bhaskaran
2026-12-02  0:19 ` [RFC PATCH 11/11] mm/extmem: preserve carved regions across KHO kexec Suseendran Bhaskaran
2026-12-03  0:27   ` sashiko-bot
2026-12-02 14:45 ` [RFC PATCH 00/11] mm: NUMA-aware boot memory carving (extmem) Mike Rapoport
2026-12-02 15:10   ` David Hildenbrand (Arm)
2026-12-03  0:24     ` Suseendran Bhaskaran
2026-12-03  0:34 ` Dave Hansen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-246842@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=alison.schofield@intel.com \
    --cc=bp@alien8.de \
    --cc=catalin.marinas@arm.com \
    --cc=changyuanl@google.com \
    --cc=corbet@lwn.net \
    --cc=dave.hansen@linux.intel.com \
    --cc=dave.jiang@intel.com \
    --cc=david@kernel.org \
    --cc=djbw@kernel.org \
    --cc=fvdl@google.com \
    --cc=graf@amazon.com \
    --cc=hpa@zytor.com \
    --cc=iweiny@kernel.org \
    --cc=kexec@lists.infradead.org \
    --cc=liam@infradead.org \
    --cc=linux-cxl@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=luto@kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mhocko@suse.com \
    --cc=mingo@redhat.com \
    --cc=nvdimm@lists.linux.dev \
    --cc=osalvador@suse.de \
    --cc=pasha.tatashin@soleen.com \
    --cc=peterz@infradead.org \
    --cc=pratyush@kernel.org \
    --cc=rdunlap@infradead.org \
    --cc=rientjes@google.com \
    --cc=rppt@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=skhan@linuxfoundation.org \
    --cc=suseendranb@google.com \
    --cc=tglx@kernel.org \
    --cc=vbabka@kernel.org \
    --cc=vishal.l.verma@intel.com \
    --cc=will@kernel.org \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox