* [RFC PATCH 00/11] mm: NUMA-aware boot memory carving (extmem)
@ 2026-12-02 0:19 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
` (11 more replies)
0 siblings, 12 replies; 14+ messages in thread
From: Suseendran Bhaskaran @ 2026-12-02 0:19 UTC (permalink / raw)
To: 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, linux-arm-kernel, linux-cxl, linux-doc, linux-kernel,
linux-mm, nvdimm, x86, Suseendran Bhaskaran
Many server workloads need a portable, NUMA-aware way to carve out large
aligned regions of DRAM at boot -- keeping only a modest pool of System
RAM per NUMA node for the host kernel while handing the rest off to
external memory consumers outside the buddy allocator and boot vmemmap.
Common use cases include character DAX (/dev/daxX.Y) backing guest VMs
across KHO live updates, /dev/pmemX block devices backing fsdax
filesystems, and other driver-managed memory pools.
Today there is no portable way to establish that split at boot across
x86_64 and arm64:
- EFI_MEMORY_SP ("Soft Reserved") requires per-host firmware setup, is
absent on arm64 DeviceTree, and defaults in dax_hmem to routing via
dax_kmem (where onlining overwrites backed VM memory across KHO kexec).
- memmap=nn!ss is x86-only and ignores NUMA topology and firmware holes.
For example, booting a 2-node x86_64 host (512 GiB total, 256 GiB per
node) with memmap=448G!64G leaves NUMA node 1 with 0 kB of System RAM.
- cma=, hugetlb_cma=, and reserve_mem= keep pages in System RAM, paying
~16 MiB/GiB of boot struct page arrays upfront and preventing
ZONE_DEVICE or driver-managed attachment.
- Runtime memory offlining cannot guarantee 1 GiB physical contiguity
after early allocations (and boot RAM cannot be offlined on arm64).
Design
------
This series adds CONFIG_EXTMEM and a single boot parameter:
extmem=[<nid>|all:]<size|max>[:<align>][:keep=<size>][,...]
<nid>|all target node, every node with RAM, or any node if omitted
<size|max> bytes to carve (multiple of <align>), or "max" for all
available aligned RAM above 4 GiB and keep=<size>
<align> power-of-two alignment >= section size (default: 128M on
4K/16K pages, 512M on 64K pages)
keep=<size> minimum System RAM to leave uncarved on the target node(s)
The idea of extmem= is a software-defined, NUMA-aware counterpart to EFI
Soft Reserved memory that feeds existing DAX and libnvdimm drivers rather
than introducing a workload-specific allocator:
1. Early boot switches pre-NUMA allocations bottom-up (and prefers
cold-boot x86_64 physical KASLR slots below 4 GiB), then carves
aligned ranges per NUMA node right after SRAT/DT parsing -- before
NODE_DATA, vmemmap, or KASAN shadow allocation -- leaving at least
keep=<size> of System RAM on each node.
2. Before SMP bringup, carved ranges are unmapped from the direct/linear
map so runtime ZONE_DEVICE mapping and hotplug work unchanged.
3. Each carved range is split out of System RAM in /proc/iomem and
published as a neutral "extmem" platform device:
- dax_hmem binds it by default as device_dax (honoring 1 GiB PUD or
2 MiB PMD alignment without zeroing memory; dax_hmem.region_idle=1
leaves the DAX region unallocated for daxctl reconfiguration).
- Alternatively, unbinding hmem and binding ramdax via driver_override
exposes /dev/pmemX block devices for fsdax filesystems.
4. Across KHO kexec, extmem preserves its region table in a small KHO
subtree and revives the exact same physical ranges before
kho_memory_init_early() marks unpreserved RAM allocatable.
Series layout (11 patches)
--------------------------
- Patches 1-2: Fix 4 GiB clamping and memblock flag handling in
multi-range CMA search, then factor that range picker into memblock
so CMA and extmem share one implementation (plus memblock tests).
- Patches 3-4: Pre-SMP direct/linear-map unmap helpers on x86_64 and
arm64.
- Patch 5: Core extmem= parser, per-node carving, /proc/iomem split,
and "extmem" platform device registration.
- Patch 6: dax_hmem binding for "extmem" devices with per-region
alignment.
- Patches 7-9: Fix ramdax devres teardown and probe validation, then
support binding "extmem" devices via driver_override.
- Patch 10: Keep cold-boot x86_64 physical KASLR below 4 GiB when
extmem= is set.
- Patch 11: KHO kexec preservation and revival for carved regions.
Note on staging: patches 1, 7, and 8 are self-contained prerequisite
bugfixes included here so the RFC applies and runs cleanly as one series;
happy to send them separately for review if that is preferred.
Validation
----------
Tested on akpm/mm-new (872ceec1e3ca) + this series with zero kernel
warnings on bare-metal x86_64 (2-socket, 240-CPU Xeon Platinum 8581C,
768 GiB total, 2 NUMA nodes) and arm64 (64-CPU Ampere Altra, 256 GiB):
- Carving and vmemmap savings (extmem=all:max:1G:keep=32G):
* x86_64: carved 701 GiB (350 + 351 GiB), retaining 33.1 / 32.3 GiB
System RAM per node; boot reserved memory dropped 12.20 -> 1.25 GiB.
* arm64: carved 223 GiB; boot reserved memory dropped 4.84 -> 1.03 GiB.
- Direct/linear-map unmap and alignment:
* On x86_64, unbinding hmem (or booting with dax_hmem.region_idle=1)
dropped DirectMap1G by exactly 701 GiB; a 32 GiB, 128 MiB-aligned
carveout straddling 1 GiB boundaries dropped 31 GiB DirectMap1G +
1 GiB DirectMap2M with zero 4 KiB fragmentation.
* dax_hmem enforced 1 GiB PUD alignment on x86_64 and capped to 2 MiB
PMD on arm64; hugetlb_cma=2G coexisted cleanly on both.
- Driver handoff and KHO kexec:
* Verified hmem <-> ramdax switching (ext4 -o dax=always on /dev/pmemX)
and bare-metal KHO kexec byte-for-byte preservation on both
architectures.
Example output on the 2-node x86_64 host with extmem=all:max:1G:keep=32G:
dmesg:
extmem: carved [0x00000008c0000000-0x000000603fffffff] (358400 MiB) on node 0
extmem: carved [0x0000006880000000-0x000000c03fffffff] (359424 MiB) on node 1
/proc/iomem (above 4 GiB):
100000000-8bfffffff : System RAM
8c0000000-603fffffff : External Memory
8c0000000-603fffffff : dax0.0
6040000000-6075ffffff : System RAM
6080000000-687fffffff : System RAM
6880000000-c03fffffff : External Memory
6880000000-c03fffffff : dax1.0
c040000000-c077ffffff : System RAM
Things I would like feedback on:
--------------------------------
1. Driver binding: extmem registers neutral "extmem" platform devices
matched by dax_hmem by default and claimable by ramdax via
driver_override (like e820_pmem and pmem-region). Does this match
DAX/nvdimm expectations?
2. Direct map lifecycle: patches 3-4 unmap carved ranges pre-SMP so
runtime arch_add_memory() / arch_remove_memory() stay untouched. Do
x86 and arm64 maintainers prefer this over teaching runtime hotplug
to split/overwrite boot mappings?
3. Syntax and alignment: any concerns with the extmem= syntax or with
requiring at least sparsemem section alignment (128 MiB on 4K/16K
pages, 512 MiB on 64K pages)?
4. x86_64 physical KASLR: patch 10 prefers cold-boot physical KASLR
slots below 4 GiB (keeping virtual KASLR unchanged) to avoid
splitting a node's carved region around a random high kernel
placement. Would x86 maintainers prefer this, or accepting split
extmem regions around high KASLR slots?
Based on akpm/mm-new (872ceec1e3ca).
Suseendran Bhaskaran (11):
mm/cma: clamp multi-range search to 4G and honor memblock flags
mm/memblock: factor out multi-range contiguous reservation helper from
CMA
x86/mm: add early direct-map unmap helpers for boot carveouts
arm64/mm: support unmapping boot carveouts from the linear map
mm/extmem: add architecture-neutral external memory subsystem
dax/hmem: bind extmem platform devices with per-region alignment
nvdimm/ramdax: manage bus and DIMM allocations with devres
nvdimm/ramdax: harden probe checks and select NUMA_KEEP_MEMINFO
nvdimm/ramdax: support binding extmem platform devices
x86/kaslr: avoid placing kernel in carvable high memory when extmem=
is set
mm/extmem: preserve carved regions across KHO kexec
.../admin-guide/kernel-parameters.txt | 23 +
Documentation/core-api/kho/abi.rst | 5 +
MAINTAINERS | 8 +
arch/arm64/mm/init.c | 3 +
arch/arm64/mm/mmu.c | 56 ++-
arch/x86/boot/compressed/kaslr.c | 30 +-
arch/x86/mm/init_64.c | 87 ++++
arch/x86/mm/numa.c | 3 +
drivers/dax/Kconfig | 2 +-
drivers/dax/hmem/hmem.c | 27 +-
drivers/nvdimm/Kconfig | 15 +-
drivers/nvdimm/ramdax.c | 135 +++---
include/linux/extmem.h | 21 +
include/linux/kexec_handover.h | 6 +
include/linux/kho/abi/extmem.h | 55 +++
include/linux/memory_hotplug.h | 4 +
include/linux/memregion.h | 1 +
kernel/liveupdate/kexec_handover.c | 31 ++
mm/Kconfig | 12 +
mm/Makefile | 4 +
mm/arch_numa.c | 3 +
mm/cma.c | 102 ++---
mm/extmem.c | 424 ++++++++++++++++++
mm/extmem.h | 29 ++
mm/extmem_kho.c | 188 ++++++++
mm/memblock.c | 120 +++++
mm/mm_init.c | 2 +
mm/mm_init.h | 17 +
tools/testing/memblock/Makefile | 2 +-
tools/testing/memblock/main.c | 2 +
tools/testing/memblock/mm_init.h | 23 +-
.../testing/memblock/tests/alloc_multi_api.c | 103 +++++
.../testing/memblock/tests/alloc_multi_api.h | 9 +
33 files changed, 1373 insertions(+), 179 deletions(-)
create mode 100644 include/linux/extmem.h
create mode 100644 include/linux/kho/abi/extmem.h
create mode 100644 mm/extmem.c
create mode 100644 mm/extmem.h
create mode 100644 mm/extmem_kho.c
create mode 100644 tools/testing/memblock/tests/alloc_multi_api.c
create mode 100644 tools/testing/memblock/tests/alloc_multi_api.h
base-commit: 872ceec1e3caf227655a58f7407a9c8493dcf56f
^ permalink raw reply [flat|nested] 14+ messages in thread
* [RFC PATCH 01/11] mm/cma: clamp multi-range search to 4G and honor memblock flags
2026-12-02 0:19 [RFC PATCH 00/11] mm: NUMA-aware boot memory carving (extmem) Suseendran Bhaskaran
@ 2026-12-02 0:19 ` Suseendran Bhaskaran
2026-12-02 0:19 ` [RFC PATCH 02/11] mm/memblock: factor out multi-range contiguous reservation helper from CMA Suseendran Bhaskaran
` (10 subsequent siblings)
11 siblings, 0 replies; 14+ messages in thread
From: Suseendran Bhaskaran @ 2026-12-02 0:19 UTC (permalink / raw)
To: 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, linux-arm-kernel, linux-cxl, linux-doc, linux-kernel,
linux-mm, nvdimm, x86, Suseendran Bhaskaran
When single-range CMA allocation fails with -ENOMEM (for example, across
a memory hole) and falls back to cma_find_free_range(), any free memblock
span starting below 4 GiB is skipped outright (!upper_32_bits(start)). On
platforms without a hole just below 4 GiB (such as arm64 where DRAM can
cross 4 GiB contiguously), that discards the usable >= 4 GiB portion of
the first span and can fail with -ENOMEM.
It also passes MEMBLOCK_NONE to for_each_free_mem_range() instead of
choose_memblock_flags(). On KHO boots, hugetlb_cma_reserve() runs in
mm_core_init_early() while kho_noprsrv_only is active and before
kho_memory_init() reserves preserved pages in memblock.reserved, so
ignoring choose_memblock_flags() can place multi-range CMA areas directly
over KHO preserved memory.
To fix this:
- Clamp each candidate range's lower bound to 4 GiB before alignment
while guarding against address wraparound near the top of physical
memory.
- Honor the active memblock allocation flags so KHO preserved memory is
skipped, excluding mirror-only filtering since free-range iteration
does not fall back to non-mirrored RAM.
- Replace the runtime IS_ENABLED(CONFIG_PHYS_ADDR_T_64BIT) check with
#ifdef CONFIG_PHYS_ADDR_T_64BIT so clamping to SZ_4G does not truncate
on 32-bit phys_addr_t builds.
Found by code inspection.
Fixes: c009da4258f9 ("mm, cma: support multiple contiguous ranges, if requested")
Fixes: d59f43b57480 ("memblock: add support for scratch memory")
Signed-off-by: Suseendran Bhaskaran <suseendranb@google.com>
---
mm/cma.c | 21 ++++++++++-----------
mm/memblock.c | 2 +-
mm/mm_init.h | 2 ++
3 files changed, 13 insertions(+), 12 deletions(-)
diff --git a/mm/cma.c b/mm/cma.c
index 0c97aadcfea4..c0db52b4ae29 100644
--- a/mm/cma.c
+++ b/mm/cma.c
@@ -507,20 +507,16 @@ static int __init __cma_declare_contiguous_nid(phys_addr_t *basep,
static phys_addr_t __init cma_find_free_range(phys_addr_t align,
phys_addr_t size_align, int nid, phys_addr_t *basep)
{
- phys_addr_t start, end, size;
+#ifdef CONFIG_PHYS_ADDR_T_64BIT
+ enum memblock_flags flags = choose_memblock_flags() & ~MEMBLOCK_MIRROR;
+ phys_addr_t start, end, size, orig_start;
phys_addr_t max = 0;
u64 i;
- /* no point searching if the system can't address above 4G */
- if (!IS_ENABLED(CONFIG_PHYS_ADDR_T_64BIT))
- return 0;
-
- for_each_free_mem_range(i, nid, MEMBLOCK_NONE, &start, &end, NULL) {
- if (!upper_32_bits(start))
- continue;
-
- start = ALIGN(start, align);
- if (start >= end)
+ for_each_free_mem_range(i, nid, flags, &start, &end, NULL) {
+ orig_start = max_t(phys_addr_t, start, SZ_4G);
+ start = ALIGN(orig_start, align);
+ if (start < orig_start || start >= end)
continue;
size = ALIGN_DOWN(end - start, size_align);
@@ -531,6 +527,9 @@ static phys_addr_t __init cma_find_free_range(phys_addr_t align,
}
return max;
+#else
+ return 0;
+#endif
}
static int __init cma_range_cmp(const void *a, const void *b)
diff --git a/mm/memblock.c b/mm/memblock.c
index a450092a80fb..d81f2074e16e 100644
--- a/mm/memblock.c
+++ b/mm/memblock.c
@@ -172,7 +172,7 @@ bool __init_memblock memblock_has_mirror(void)
return system_has_some_mirror;
}
-static enum memblock_flags __init_memblock choose_memblock_flags(void)
+enum memblock_flags __init_memblock choose_memblock_flags(void)
{
/* only use KHO_NOPRSRV memory for kho early boot allocations */
if (kho_noprsrv_only)
diff --git a/mm/mm_init.h b/mm/mm_init.h
index 9ee9bcb8e672..245baa769add 100644
--- a/mm/mm_init.h
+++ b/mm/mm_init.h
@@ -10,6 +10,7 @@
#include <linux/types.h>
#include <linux/init.h>
+#include <linux/memblock.h>
#include <linux/mmzone.h>
#include <linux/jump_label.h>
#include <linux/printk.h>
@@ -99,6 +100,7 @@ static inline void mminit_verify_zonelist(void)
extern bool mirrored_kernelcore;
bool memblock_has_mirror(void);
+enum memblock_flags choose_memblock_flags(void);
void memblock_free_all(void);
void memmap_init_page(struct page *page, enum zone_type zone, int nid);
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [RFC PATCH 02/11] mm/memblock: factor out multi-range contiguous reservation helper from CMA
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 ` Suseendran Bhaskaran
2026-12-02 0:19 ` [RFC PATCH 03/11] x86/mm: add early direct-map unmap helpers for boot carveouts Suseendran Bhaskaran
` (9 subsequent siblings)
11 siblings, 0 replies; 14+ messages in thread
From: Suseendran Bhaskaran @ 2026-12-02 0:19 UTC (permalink / raw)
To: 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, linux-arm-kernel, linux-cxl, linux-doc, linux-kernel,
linux-mm, nvdimm, x86, Suseendran Bhaskaran
cma_declare_contiguous_multi() picks the largest free memblock ranges
above a minimum address, reserves each slice, and sorts the resulting
list by physical base address. Boot-time external memory carving needs
the same multi-range selection when firmware holes split a NUMA node,
plus optional top-down trimming, partial ("max") reservations, hotplug
range inclusion (MEMBLOCK_CONTIG_INCLUDE_HOTPLUG), and per-range node IDs.
Move this loop into memblock_reserve_contig_multi() in mm/memblock.c, run
accept_memory() once all ranges are reserved, and add unit tests in
tools/testing/memblock/. Single-range cma_alloc_mem() and its
CONFIG_HIGHMEM fallback stay in mm/cma.c.
Signed-off-by: Suseendran Bhaskaran <suseendranb@google.com>
---
mm/cma.c | 101 ++++-----------
mm/memblock.c | 122 +++++++++++++++++-
mm/mm_init.h | 19 ++-
tools/testing/memblock/Makefile | 2 +-
tools/testing/memblock/main.c | 2 +
tools/testing/memblock/mm_init.h | 23 +++-
.../testing/memblock/tests/alloc_multi_api.c | 103 +++++++++++++++
.../testing/memblock/tests/alloc_multi_api.h | 9 ++
8 files changed, 301 insertions(+), 80 deletions(-)
create mode 100644 tools/testing/memblock/tests/alloc_multi_api.c
create mode 100644 tools/testing/memblock/tests/alloc_multi_api.h
diff --git a/mm/cma.c b/mm/cma.c
index c0db52b4ae29..02865d5a10b5 100644
--- a/mm/cma.c
+++ b/mm/cma.c
@@ -24,7 +24,6 @@
#include <linux/slab.h>
#include <linux/string.h>
#include <linux/log2.h>
-#include <linux/sort.h>
#include <linux/cma.h>
#include <linux/highmem.h>
#include <linux/io.h>
@@ -500,46 +499,6 @@ static int __init __cma_declare_contiguous_nid(phys_addr_t *basep,
return 0;
}
-/*
- * Find the largest free range above 4G that can hold a part of a multi-range
- * CMA area.
- */
-static phys_addr_t __init cma_find_free_range(phys_addr_t align,
- phys_addr_t size_align, int nid, phys_addr_t *basep)
-{
-#ifdef CONFIG_PHYS_ADDR_T_64BIT
- enum memblock_flags flags = choose_memblock_flags() & ~MEMBLOCK_MIRROR;
- phys_addr_t start, end, size, orig_start;
- phys_addr_t max = 0;
- u64 i;
-
- for_each_free_mem_range(i, nid, flags, &start, &end, NULL) {
- orig_start = max_t(phys_addr_t, start, SZ_4G);
- start = ALIGN(orig_start, align);
- if (start < orig_start || start >= end)
- continue;
-
- size = ALIGN_DOWN(end - start, size_align);
- if (size > max) {
- max = size;
- *basep = start;
- }
- }
-
- return max;
-#else
- return 0;
-#endif
-}
-
-static int __init cma_range_cmp(const void *a, const void *b)
-{
- const struct cma_memrange *cmr_a = a;
- const struct cma_memrange *cmr_b = b;
-
- return cmp_int(cmr_a->base_pfn, cmr_b->base_pfn);
-}
-
/*
* Create CMA areas with a total size of @total_size. A normal allocation
* for one area is tried first. If that fails, the area is assembled from
@@ -550,12 +509,11 @@ int __init cma_declare_contiguous_multi(phys_addr_t total_size,
const char *name, struct cma **res_cma, int nid)
{
const unsigned long size_mb = (unsigned long)total_size / SZ_1M;
- phys_addr_t size, remaining, size_align;
+ struct memblock_contig_range ranges[CMA_MAX_RANGES];
struct cma_memrange *cmrp;
phys_addr_t start = 0;
struct cma *cma;
- int nr = 0;
- int ret;
+ int nr, i, ret;
/*
* First, try it the normal way, producing just one range.
@@ -569,6 +527,10 @@ int __init cma_declare_contiguous_multi(phys_addr_t total_size,
if (ret != -ENOMEM)
goto err;
+ /* no point searching if the system can't address above 4G */
+ if (!IS_ENABLED(CONFIG_PHYS_ADDR_T_64BIT))
+ goto err;
+
/*
* Couldn't find one range that fits our needs, so try multiple
* ranges.
@@ -589,38 +551,32 @@ int __init cma_declare_contiguous_multi(phys_addr_t total_size,
if (ret)
goto err;
+#ifdef CONFIG_PHYS_ADDR_T_64BIT
align = max_t(phys_addr_t, align, CMA_MIN_ALIGNMENT_BYTES);
- size_align = max_t(phys_addr_t, align, PAGE_SIZE << order_per_bit);
-
- remaining = total_size;
- while (remaining && nr < CMA_MAX_RANGES) {
- size = cma_find_free_range(align, size_align, nid, &start);
- if (!size)
- break;
-
- size = min(size, remaining);
- if (memblock_reserve(start, size))
- break;
- accept_memory(start, size);
+ nr = memblock_reserve_contig_multi(total_size, align,
+ max_t(phys_addr_t, align,
+ PAGE_SIZE << order_per_bit),
+ SZ_4G, nid, 0,
+ ranges, CMA_MAX_RANGES);
+#else
+ nr = -ENOMEM;
+#endif
+ if (nr < 0) {
+ ret = nr;
+ cma_drop_area(cma);
+ goto err;
+ }
+ for (i = 0; i < nr; i++) {
pr_debug("created region %d: %016llx - %016llx\n",
- nr, (u64)start, (u64)start + size);
- cmrp = &cma->ranges[nr++];
- cmrp->base_pfn = PHYS_PFN(start);
+ i, (u64)ranges[i].base,
+ (u64)ranges[i].base + ranges[i].size);
+ cmrp = &cma->ranges[i];
+ cmrp->base_pfn = PHYS_PFN(ranges[i].base);
cmrp->early_pfn = cmrp->base_pfn;
- cmrp->count = size >> PAGE_SHIFT;
-
- remaining -= size;
- }
-
- if (remaining) {
- ret = -ENOMEM;
- goto err_free_ranges;
+ cmrp->count = ranges[i].size >> PAGE_SHIFT;
}
- /* allocate from lower addresses first */
- sort(cma->ranges, nr, sizeof(cma->ranges[0]), cma_range_cmp, NULL);
-
cma->nranges = nr;
cma->nid = nid;
*res_cma = cma;
@@ -628,11 +584,6 @@ int __init cma_declare_contiguous_multi(phys_addr_t total_size,
pr_info("Reserved %lu MiB in %d ranges\n", size_mb, nr);
return 0;
-err_free_ranges:
- for (int i = 0; i < nr; i++)
- memblock_phys_free(PFN_PHYS(cma->ranges[i].base_pfn),
- PFN_PHYS(cma->ranges[i].count));
- cma_drop_area(cma);
err:
pr_err("Failed to reserve %lu MiB\n", size_mb);
return ret;
diff --git a/mm/memblock.c b/mm/memblock.c
index d81f2074e16e..f95f06412efa 100644
--- a/mm/memblock.c
+++ b/mm/memblock.c
@@ -6,6 +6,7 @@
* Copyright (C) 2001 Peter Bergner.
*/
+#include <linux/align.h>
#include <linux/kernel.h>
#include <linux/slab.h>
#include <linux/init.h>
@@ -172,7 +173,7 @@ bool __init_memblock memblock_has_mirror(void)
return system_has_some_mirror;
}
-enum memblock_flags __init_memblock choose_memblock_flags(void)
+static enum memblock_flags __init_memblock choose_memblock_flags(void)
{
/* only use KHO_NOPRSRV memory for kho early boot allocations */
if (kho_noprsrv_only)
@@ -1626,6 +1627,125 @@ phys_addr_t __init memblock_alloc_range_nid(phys_addr_t size,
return found;
}
+static phys_addr_t __init
+memblock_find_largest_free_range(phys_addr_t align, phys_addr_t size_align,
+ phys_addr_t min_addr, int nid,
+ enum memblock_flags mb_flags, bool top_down,
+ phys_addr_t *basep, int *out_nid)
+{
+ phys_addr_t start, end, orig_start, size, max_size = 0;
+ int rnid;
+ u64 i;
+
+ for_each_free_mem_range(i, nid, mb_flags, &start, &end, &rnid) {
+ orig_start = max(start, min_addr);
+ start = ALIGN(orig_start, align);
+ if (top_down)
+ end = ALIGN_DOWN(end, align);
+ if (start < orig_start || start >= end)
+ continue;
+
+ size = ALIGN_DOWN(end - start, size_align);
+ if (size > max_size || (top_down && size && size == max_size)) {
+ max_size = size;
+ *basep = top_down ? end - size : start;
+ *out_nid = rnid;
+ }
+ }
+
+ return max_size;
+}
+
+/**
+ * memblock_reserve_contig_multi - reserve a pool across multiple free ranges
+ * @total_size: total bytes to reserve (or cap for partial mode)
+ * @align: base address alignment (power of 2)
+ * @size_align: per-range size alignment (power of 2, >= @align)
+ * @min_addr: lower physical address bound
+ * @nid: target NUMA node ID, or %NUMA_NO_NODE for any node
+ * @flags: %MEMBLOCK_CONTIG_* modifiers
+ * @ranges: caller-allocated output array of length @max_ranges
+ * @max_ranges: maximum number of contiguous ranges to reserve
+ *
+ * Greedily selects up to @max_ranges of the largest free memblock ranges at or
+ * above @min_addr, reserves them, keeps @ranges sorted ascending by physical
+ * base, and accepts unaccepted memory once the reservation succeeds.
+ *
+ * Return: number of reserved ranges (>= 0) on success, or negative errno.
+ */
+int __init memblock_reserve_contig_multi(phys_addr_t total_size,
+ phys_addr_t align,
+ phys_addr_t size_align,
+ phys_addr_t min_addr, int nid,
+ unsigned int flags,
+ struct memblock_contig_range *ranges,
+ int max_ranges)
+{
+ bool allow_partial = flags & MEMBLOCK_CONTIG_ALLOW_PARTIAL;
+ bool top_down = flags & MEMBLOCK_CONTIG_TOP_DOWN;
+ phys_addr_t remaining, start, size, take;
+ enum memblock_flags mb_flags;
+ int nr = 0, i, rnid;
+
+ if (WARN_ON_ONCE(slab_is_available()))
+ return -EBUSY;
+ if (!ranges || max_ranges <= 0 ||
+ !align || (align & (align - 1)) ||
+ !size_align || (size_align & (size_align - 1)))
+ return -EINVAL;
+
+ size_align = max(size_align, align);
+ if (allow_partial)
+ total_size = ALIGN_DOWN(total_size, size_align);
+ if (!total_size || !IS_ALIGNED(total_size, size_align))
+ return -EINVAL;
+
+ min_addr = max_t(phys_addr_t, min_addr, PAGE_SIZE);
+ mb_flags = choose_memblock_flags() & ~MEMBLOCK_MIRROR;
+ if (flags & MEMBLOCK_CONTIG_INCLUDE_HOTPLUG)
+ mb_flags |= MEMBLOCK_HOTPLUG;
+
+ remaining = total_size;
+ while (remaining && nr < max_ranges) {
+ size = memblock_find_largest_free_range(align, size_align,
+ min_addr, nid, mb_flags,
+ top_down, &start,
+ &rnid);
+ if (!size)
+ break;
+
+ take = min(size, remaining);
+ if (top_down)
+ start += size - take;
+
+ if (memblock_reserve(start, take))
+ goto err_free;
+
+ for (i = nr; i > 0 && ranges[i - 1].base > start; i--)
+ ranges[i] = ranges[i - 1];
+ ranges[i] = (struct memblock_contig_range) {
+ .base = start,
+ .size = take,
+ .nid = rnid,
+ };
+ nr++;
+ remaining -= take;
+ }
+
+ if (remaining && !allow_partial)
+ goto err_free;
+
+ for (i = 0; i < nr; i++)
+ accept_memory(ranges[i].base, ranges[i].size);
+
+ return nr;
+
+err_free:
+ for (i = 0; i < nr; i++)
+ memblock_phys_free(ranges[i].base, ranges[i].size);
+ return -ENOMEM;
+}
+
/**
* memblock_phys_alloc_range - allocate a memory block inside specified range
* @size: size of memory block to be allocated in bytes
diff --git a/mm/mm_init.h b/mm/mm_init.h
index 245baa769add..5f6e4ac87fcd 100644
--- a/mm/mm_init.h
+++ b/mm/mm_init.h
@@ -9,8 +9,8 @@
#define __MM_MM_INIT_H
#include <linux/types.h>
+#include <linux/bits.h>
#include <linux/init.h>
-#include <linux/memblock.h>
#include <linux/mmzone.h>
#include <linux/jump_label.h>
#include <linux/printk.h>
@@ -100,9 +100,24 @@ static inline void mminit_verify_zonelist(void)
extern bool mirrored_kernelcore;
bool memblock_has_mirror(void);
-enum memblock_flags choose_memblock_flags(void);
void memblock_free_all(void);
+struct memblock_contig_range {
+ phys_addr_t base;
+ phys_addr_t size;
+ int nid;
+};
+
+#define MEMBLOCK_CONTIG_TOP_DOWN BIT(0)
+#define MEMBLOCK_CONTIG_ALLOW_PARTIAL BIT(1)
+#define MEMBLOCK_CONTIG_INCLUDE_HOTPLUG BIT(2)
+
+int memblock_reserve_contig_multi(phys_addr_t total_size, phys_addr_t align,
+ phys_addr_t size_align, phys_addr_t min_addr,
+ int nid, unsigned int flags,
+ struct memblock_contig_range *ranges,
+ int max_ranges);
+
void memmap_init_page(struct page *page, enum zone_type zone, int nid);
void __meminit memmap_init_compound_page(struct page *head, unsigned long pfn,
const struct zone *zone, unsigned int order);
diff --git a/tools/testing/memblock/Makefile b/tools/testing/memblock/Makefile
index 20524fcbe3c7..dbaf3c88547d 100644
--- a/tools/testing/memblock/Makefile
+++ b/tools/testing/memblock/Makefile
@@ -8,7 +8,7 @@ LDFLAGS += -fsanitize=address -fsanitize=undefined
TARGETS = main
TEST_OFILES = tests/alloc_nid_api.o tests/alloc_helpers_api.o tests/alloc_api.o \
tests/basic_api.o tests/common.o tests/alloc_exact_nid_api.o \
- tests/alloc_low_api.o
+ tests/alloc_low_api.o tests/alloc_multi_api.o
DEP_OFILES = memblock.o lib/slab.o mmzone.o slab.o cmdline.o
OFILES = main.o $(DEP_OFILES) $(TEST_OFILES)
EXTR_SRC = ../../../mm/memblock.c
diff --git a/tools/testing/memblock/main.c b/tools/testing/memblock/main.c
index 9a96e178551b..2c21d0485052 100644
--- a/tools/testing/memblock/main.c
+++ b/tools/testing/memblock/main.c
@@ -5,6 +5,7 @@
#include "tests/alloc_nid_api.h"
#include "tests/alloc_exact_nid_api.h"
#include "tests/alloc_low_api.h"
+#include "tests/alloc_multi_api.h"
#include "tests/common.h"
int main(int argc, char **argv)
@@ -16,6 +17,7 @@ int main(int argc, char **argv)
memblock_alloc_low_checks();
memblock_alloc_nid_checks();
memblock_alloc_exact_nid_checks();
+ memblock_alloc_multi_checks();
return 0;
}
diff --git a/tools/testing/memblock/mm_init.h b/tools/testing/memblock/mm_init.h
index 95bc5f2e8ed8..5b1cc957c9d7 100644
--- a/tools/testing/memblock/mm_init.h
+++ b/tools/testing/memblock/mm_init.h
@@ -2,7 +2,28 @@
#ifndef __MM_MM_INIT_H
#define __MM_MM_INIT_H
-void memblock_free_pages(unsigned long pfn, unsigned int order)
+#include <linux/bits.h>
+#include <linux/types.h>
+
+extern bool mirrored_kernelcore;
+
+struct memblock_contig_range {
+ phys_addr_t base;
+ phys_addr_t size;
+ int nid;
+};
+
+#define MEMBLOCK_CONTIG_TOP_DOWN BIT(0)
+#define MEMBLOCK_CONTIG_ALLOW_PARTIAL BIT(1)
+#define MEMBLOCK_CONTIG_INCLUDE_HOTPLUG BIT(2)
+
+int memblock_reserve_contig_multi(phys_addr_t total_size, phys_addr_t align,
+ phys_addr_t size_align, phys_addr_t min_addr,
+ int nid, unsigned int flags,
+ struct memblock_contig_range *ranges,
+ int max_ranges);
+
+static inline void memblock_free_pages(unsigned long pfn, unsigned int order)
{
}
diff --git a/tools/testing/memblock/tests/alloc_multi_api.c b/tools/testing/memblock/tests/alloc_multi_api.c
new file mode 100644
index 000000000000..5c125e638b4b
--- /dev/null
+++ b/tools/testing/memblock/tests/alloc_multi_api.c
@@ -0,0 +1,103 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+#include "alloc_multi_api.h"
+#include "../mm_init.h"
+#include <linux/align.h>
+
+static void setup_fragmented_32k(phys_addr_t base)
+{
+ reset_memblock_regions();
+ ASSERT_EQ(memblock_add(base, SZ_32K), 0);
+ ASSERT_EQ(memblock_reserve(base + SZ_4K, SZ_4K), 0);
+ ASSERT_EQ(memblock_reserve(base + 5 * SZ_4K, SZ_4K), 0);
+}
+
+static int alloc_multi_checks(void)
+{
+ struct memblock_contig_range ranges[4];
+ phys_addr_t base = ALIGN(dummy_physical_memory_base(), SZ_4K);
+ int nr;
+
+ PREFIX_PUSH();
+
+ /* Bottom-up trim across 4K, 12K, and 8K free spans, sorted by base. */
+ setup_fragmented_32k(base);
+ nr = memblock_reserve_contig_multi(SZ_16K, SZ_4K, SZ_4K, base,
+ NUMA_NO_NODE, 0, ranges, 4);
+ ASSERT_EQ(nr, 2);
+ ASSERT_EQ(ranges[0].base, base + SZ_8K);
+ ASSERT_EQ(ranges[0].size, 3 * SZ_4K);
+ ASSERT_EQ(ranges[1].base, base + 6 * SZ_4K);
+ ASSERT_EQ(ranges[1].size, SZ_4K);
+
+ /* Top-down trim on the same layout takes the upper 4K of [24K, 32K). */
+ setup_fragmented_32k(base);
+ nr = memblock_reserve_contig_multi(SZ_16K, SZ_4K, SZ_4K, base,
+ NUMA_NO_NODE,
+ MEMBLOCK_CONTIG_TOP_DOWN, ranges, 4);
+ ASSERT_EQ(nr, 2);
+ ASSERT_EQ(ranges[0].base, base + SZ_8K);
+ ASSERT_EQ(ranges[0].size, 3 * SZ_4K);
+ ASSERT_EQ(ranges[1].base, base + 7 * SZ_4K);
+ ASSERT_EQ(ranges[1].size, SZ_4K);
+
+ /* Range straddling min_addr is clamped at min_addr, not skipped. */
+ reset_memblock_regions();
+ ASSERT_EQ(memblock_add(base, SZ_32K), 0);
+ nr = memblock_reserve_contig_multi(SZ_16K, SZ_4K, SZ_4K, base + SZ_8K,
+ NUMA_NO_NODE, 0, ranges, 2);
+ ASSERT_EQ(nr, 1);
+ ASSERT_EQ(ranges[0].base, base + SZ_8K);
+ ASSERT_EQ(ranges[0].size, SZ_16K);
+
+ /* Unsatisfied strict request rolls back partial reservations. */
+ reset_memblock_regions();
+ ASSERT_EQ(memblock_add(base, SZ_32K), 0);
+ ASSERT_EQ(memblock_reserve(base + SZ_8K, SZ_8K), 0);
+ nr = memblock_reserve_contig_multi(7 * SZ_4K, SZ_4K, SZ_4K, base,
+ NUMA_NO_NODE, 0, ranges, 4);
+ ASSERT_EQ(nr, -ENOMEM);
+ ASSERT_EQ(memblock.reserved.cnt, 1);
+ ASSERT_EQ(memblock.reserved.total_size, SZ_8K);
+
+ /* ALLOW_PARTIAL reserves all aligned spans up to PHYS_ADDR_MAX. */
+ nr = memblock_reserve_contig_multi(PHYS_ADDR_MAX, SZ_4K, SZ_4K, base,
+ NUMA_NO_NODE,
+ MEMBLOCK_CONTIG_TOP_DOWN |
+ MEMBLOCK_CONTIG_ALLOW_PARTIAL,
+ ranges, 4);
+ ASSERT_EQ(nr, 2);
+ ASSERT_EQ(ranges[0].base, base);
+ ASSERT_EQ(ranges[0].size, SZ_8K);
+ ASSERT_EQ(ranges[1].base, base + SZ_16K);
+ ASSERT_EQ(ranges[1].size, SZ_16K);
+
+ /* Non-mirrored spans remain eligible under mirrored_kernelcore. */
+ reset_memblock_regions();
+ ASSERT_EQ(memblock_add(base, SZ_32K), 0);
+ mirrored_kernelcore = true;
+ ASSERT_EQ(memblock_mark_mirror(base, SZ_8K), 0);
+ nr = memblock_reserve_contig_multi(SZ_16K, SZ_4K, SZ_4K, base,
+ NUMA_NO_NODE, 0, ranges, 2);
+ ASSERT_EQ(nr, 1);
+ ASSERT_EQ(ranges[0].base, base + SZ_8K);
+ mirrored_kernelcore = false;
+
+ test_pass_pop();
+ return 0;
+}
+
+int memblock_alloc_multi_checks(void)
+{
+ prefix_reset();
+ prefix_push("memblock_reserve_contig_multi");
+ test_print("Running memblock_reserve_contig_multi tests...\n");
+
+ reset_memblock_attributes();
+ dummy_physical_memory_init();
+ run_top_down(alloc_multi_checks);
+ run_bottom_up(alloc_multi_checks);
+ dummy_physical_memory_cleanup();
+ prefix_pop();
+
+ return 0;
+}
diff --git a/tools/testing/memblock/tests/alloc_multi_api.h b/tools/testing/memblock/tests/alloc_multi_api.h
new file mode 100644
index 000000000000..d3c43fea680b
--- /dev/null
+++ b/tools/testing/memblock/tests/alloc_multi_api.h
@@ -0,0 +1,9 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+#ifndef _MEMBLOCK_ALLOC_MULTI_H
+#define _MEMBLOCK_ALLOC_MULTI_H
+
+#include "common.h"
+
+int memblock_alloc_multi_checks(void);
+
+#endif
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [RFC PATCH 03/11] x86/mm: add early direct-map unmap helpers for boot carveouts
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 ` Suseendran Bhaskaran
2026-12-02 0:19 ` [RFC PATCH 04/11] arm64/mm: support unmapping boot carveouts from the linear map Suseendran Bhaskaran
` (8 subsequent siblings)
11 siblings, 0 replies; 14+ messages in thread
From: Suseendran Bhaskaran @ 2026-12-02 0:19 UTC (permalink / raw)
To: 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, linux-arm-kernel, linux-cxl, linux-doc, linux-kernel,
linux-mm, nvdimm, x86, Suseendran Bhaskaran
init_mem_mapping() maps all memblock.memory ranges (populated from
E820_TYPE_RAM) into the direct map and records them in pfn_mapped[]
before NUMA discovery. Leaving memory carved out after SRAT setup in
pfn_mapped[] and the direct map causes three problems:
- With CONFIG_KASAN=y, kasan_init() allocates writable shadow RAM (1/8
of the carved size) from remaining System RAM and conflicts with
kasan_add_zero_shadow() on ZONE_DEVICE or memmap_on_memory hotplug.
- arch_add_memory() ignores non-PAGE_KERNEL attributes (such as
pgprot_decrypted() or pgprot_noncached()) when direct-map entries are
already present.
- Unbound ranges stay mapped in the host direct map until a driver binds
them.
Add arch_boot_carveout_early() to trim carved PFNs from pfn_mapped[]
before kasan_init(), arch_boot_carveout_unmap() to split straddling
1 GiB PUD leaves and unmap PMD-aligned carveouts before SMP bringup, and
an empty arch_boot_carveout_enable() stub for architecture parity.
Runtime arch_add_memory() and arch_remove_memory() remain unchanged.
Signed-off-by: Suseendran Bhaskaran <suseendranb@google.com>
---
arch/x86/mm/init_64.c | 85 ++++++++++++++++++++++++++++++++++
include/linux/memory_hotplug.h | 4 ++
2 files changed, 89 insertions(+)
diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
index 2a635b7f78ea..d027438c6bc8 100644
--- a/arch/x86/mm/init_64.c
+++ b/arch/x86/mm/init_64.c
@@ -31,6 +31,8 @@
#include <linux/memory_hotplug.h>
#include <linux/memremap.h>
#include <linux/nmi.h>
+#include <linux/overflow.h>
+#include <linux/range.h>
#include <linux/gfp.h>
#include <linux/kcore.h>
@@ -1281,6 +1283,89 @@ void __ref arch_remove_memory(u64 start, u64 size, struct vmem_altmap *altmap)
__remove_pages(start_pfn, nr_pages, altmap);
kernel_physical_mapping_remove(start, start + size);
}
+
+static int __init split_direct_map_pud_boundary(unsigned long vaddr)
+{
+ unsigned long base_pfn;
+ unsigned int i, level;
+ pmd_t *pmd_table;
+ pgprot_t prot;
+ pud_t *pud;
+
+ if (IS_ALIGNED(vaddr, PUD_SIZE))
+ return 0;
+
+ pud = (pud_t *)lookup_address(vaddr, &level);
+ if (!pud || level != PG_LEVEL_1G || !pud_present(*pud))
+ return 0;
+
+ base_pfn = pud_pfn(*pud);
+ prot = pud_pgprot(*pud);
+ pmd_table = pmd_alloc_one(&init_mm, vaddr & PUD_MASK);
+ if (!pmd_table)
+ return -ENOMEM;
+
+ for (i = 0; i < PTRS_PER_PMD; i++)
+ set_pmd(&pmd_table[i],
+ pfn_pmd(base_pfn + i * PTRS_PER_PTE, prot));
+
+ spin_lock(&init_mm.page_table_lock);
+ paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
+ set_pud(pud, __pud(__pa(pmd_table) | _KERNPG_TABLE));
+ spin_unlock(&init_mm.page_table_lock);
+
+ update_page_count(PG_LEVEL_1G, -1);
+ update_page_count(PG_LEVEL_2M, PTRS_PER_PMD);
+ flush_tlb_all();
+
+ return 0;
+}
+
+void __init arch_boot_carveout_enable(void)
+{
+}
+
+void __init arch_boot_carveout_early(phys_addr_t start, phys_addr_t size)
+{
+ unsigned long start_pfn = PFN_DOWN(start);
+ unsigned long end_pfn = PFN_UP(start + size);
+ unsigned long low = 1UL << (32 - PAGE_SHIFT);
+ int i;
+
+ if (start_pfn >= end_pfn)
+ return;
+
+ subtract_range(pfn_mapped, E820_MAX_ENTRIES, start_pfn, end_pfn);
+ nr_pfn_mapped = clean_sort_range(pfn_mapped, E820_MAX_ENTRIES);
+ max_pfn_mapped = nr_pfn_mapped ? pfn_mapped[nr_pfn_mapped - 1].end : 0;
+
+ if (start_pfn < low) {
+ max_low_pfn_mapped = 0;
+ for (i = 0; i < nr_pfn_mapped && pfn_mapped[i].start < low; i++)
+ max_low_pfn_mapped = min_t(u64, pfn_mapped[i].end, low);
+ }
+}
+
+int __init arch_boot_carveout_unmap(phys_addr_t start, phys_addr_t size)
+{
+ phys_addr_t end;
+ int err;
+
+ if (!size || check_add_overflow(start, size, &end) ||
+ !IS_ALIGNED(start | size, PMD_SIZE))
+ return -EINVAL;
+ if (WARN_ON_ONCE(!after_bootmem || num_online_cpus() > 1))
+ return -EBUSY;
+
+ err = split_direct_map_pud_boundary((unsigned long)__va(start));
+ if (!err)
+ err = split_direct_map_pud_boundary((unsigned long)__va(end));
+ if (err)
+ return err;
+
+ kernel_physical_mapping_remove(start, end);
+ return 0;
+}
#endif /* CONFIG_MEMORY_HOTPLUG */
static struct kcore_list kcore_vsyscall;
diff --git a/include/linux/memory_hotplug.h b/include/linux/memory_hotplug.h
index ec71debc0673..10527722057a 100644
--- a/include/linux/memory_hotplug.h
+++ b/include/linux/memory_hotplug.h
@@ -140,6 +140,10 @@ extern void arch_remove_memory(u64 start, u64 size, struct vmem_altmap *altmap);
extern void __remove_pages(unsigned long start_pfn, unsigned long nr_pages,
struct vmem_altmap *altmap);
+void arch_boot_carveout_enable(void);
+void arch_boot_carveout_early(phys_addr_t start, phys_addr_t size);
+int arch_boot_carveout_unmap(phys_addr_t start, phys_addr_t size);
+
/* reasonably generic interface to expand the physical pages */
extern int __add_pages(int nid, unsigned long start_pfn, unsigned long nr_pages,
struct mhp_params *params);
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [RFC PATCH 04/11] arm64/mm: support unmapping boot carveouts from the linear map
2026-12-02 0:19 [RFC PATCH 00/11] mm: NUMA-aware boot memory carving (extmem) Suseendran Bhaskaran
` (2 preceding siblings ...)
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 ` Suseendran Bhaskaran
2026-12-02 0:19 ` [RFC PATCH 05/11] mm/extmem: add architecture-neutral external memory subsystem Suseendran Bhaskaran
` (7 subsequent siblings)
11 siblings, 0 replies; 14+ messages in thread
From: Suseendran Bhaskaran @ 2026-12-02 0:19 UTC (permalink / raw)
To: 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, linux-arm-kernel, linux-cxl, linux-doc, linux-kernel,
linux-mm, nvdimm, x86, Suseendran Bhaskaran
paging_init() maps all initial mappable memblock RAM into swapper_pg_dir
before NUMA setup. If memory carved out after NUMA discovery stays mapped
in the linear map, __create_pgd_mapping() hits BUG_ON() when a driver
later calls arch_add_memory() across an existing block or contiguous leaf
(on FEAT_BBML3 CPUs or under rodata != full) or with incompatible
attributes (such as pgprot_noncached(), or pgprot_decrypted() in CCA
Realm guests).
Implement the boot carveout unmap hooks for arm64:
- Use PTE mappings in map_mem() when boot carveout unmapping is active
on a !FEAT_BBML3 boot CPU, leaving runtime arch_add_memory() block
mappings intact.
- Split straddling boundary leaves via split_kernel_leaf_mapping_locked()
when !force_pte_mapping() && cpu_supports_bbml3() (otherwise guarding
against unsplit leaves) and unmap carved ranges via
__remove_pgd_mapping() before SMP bringup.
- Free PG_reserved early page tables via free_reserved_page() in
free_hotplug_pgtable_page().
Signed-off-by: Suseendran Bhaskaran <suseendranb@google.com>
---
arch/arm64/mm/mmu.c | 54 +++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 52 insertions(+), 2 deletions(-)
diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c
index a61464cf7367..e99c8b21f603 100644
--- a/arch/arm64/mm/mmu.c
+++ b/arch/arm64/mm/mmu.c
@@ -19,6 +19,7 @@
#include <linux/memblock.h>
#include <linux/memremap.h>
#include <linux/memory.h>
+#include <linux/overflow.h>
#include <linux/fs.h>
#include <linux/io.h>
#include <linux/mm.h>
@@ -776,6 +777,8 @@ static int split_kernel_leaf_mapping_locked(unsigned long addr)
return ret;
}
+static bool linear_map_boot_unmap __initdata;
+
static inline bool force_pte_mapping(void)
{
const bool bbml3 = system_capabilities_finalized() ?
@@ -1205,7 +1208,8 @@ static void __init map_mem(void)
linear_map_requires_bbml3 = !force_pte_mapping() && can_set_direct_map();
- if (force_pte_mapping())
+ if (force_pte_mapping() ||
+ (linear_map_boot_unmap && !cpu_supports_bbml3()))
flags |= NO_BLOCK_MAPPINGS | NO_CONT_MAPPINGS;
/*
@@ -1495,7 +1499,10 @@ static void free_hotplug_page_range(struct page *page, size_t size,
static void free_hotplug_pgtable_page(struct page *page)
{
- pagetable_free(page_ptdesc(page));
+ if (PageReserved(page))
+ free_reserved_page(page);
+ else
+ pagetable_free(page_ptdesc(page));
}
static bool pgtable_range_aligned(unsigned long start, unsigned long end,
@@ -2147,6 +2154,49 @@ static bool addr_splits_kernel_leaf(unsigned long addr)
return !IS_ALIGNED(addr, PAGE_SIZE);
}
+void __init arch_boot_carveout_enable(void)
+{
+ linear_map_boot_unmap = true;
+}
+
+void __init arch_boot_carveout_early(phys_addr_t start, phys_addr_t size)
+{
+}
+
+int __init arch_boot_carveout_unmap(phys_addr_t start, phys_addr_t size)
+{
+ unsigned long vstart, vend;
+ phys_addr_t end;
+ int err = 0;
+
+ if (!size || check_add_overflow(start, size, &end) ||
+ !PAGE_ALIGNED(start | size))
+ return -EINVAL;
+ if (WARN_ON_ONCE(!page_alloc_available || num_online_cpus() > 1))
+ return -EBUSY;
+
+ vstart = __phys_to_virt(start);
+ vend = __phys_to_virt(end);
+
+ if (!force_pte_mapping() && cpu_supports_bbml3()) {
+ mutex_lock(&pgtable_split_lock);
+ lazy_mmu_mode_enable();
+ err = split_kernel_leaf_mapping_locked(vstart);
+ if (!err)
+ err = split_kernel_leaf_mapping_locked(vend);
+ lazy_mmu_mode_disable();
+ mutex_unlock(&pgtable_split_lock);
+ if (err)
+ return err;
+ } else if (WARN_ON_ONCE(addr_splits_kernel_leaf(vstart) ||
+ addr_splits_kernel_leaf(vend))) {
+ return -EBUSY;
+ }
+
+ __remove_pgd_mapping(swapper_pg_dir, vstart, size);
+ return 0;
+}
+
static bool can_unmap_without_split(unsigned long pfn, unsigned long nr_pages)
{
unsigned long phys_start, phys_end, start, end;
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [RFC PATCH 05/11] mm/extmem: add architecture-neutral external memory subsystem
2026-12-02 0:19 [RFC PATCH 00/11] mm: NUMA-aware boot memory carving (extmem) Suseendran Bhaskaran
` (3 preceding siblings ...)
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 ` Suseendran Bhaskaran
2026-12-02 0:19 ` [RFC PATCH 06/11] dax/hmem: bind extmem platform devices with per-region alignment Suseendran Bhaskaran
` (6 subsequent siblings)
11 siblings, 0 replies; 14+ messages in thread
From: Suseendran Bhaskaran @ 2026-12-02 0:19 UTC (permalink / raw)
To: 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, linux-arm-kernel, linux-cxl, linux-doc, linux-kernel,
linux-mm, nvdimm, x86, Suseendran Bhaskaran
Some virtualization and storage hosts keep only a small slice of RAM per
NUMA node for the kernel and expose the remaining DRAM as ZONE_DEVICE DAX
or PMEM devices. Existing boot options do not fit this model across
x86_64 and arm64:
- EFI_MEMORY_SP ("Soft Reserved") requires per-machine firmware changes
and defaults in dax_hmem to routing memory to dax_kmem for hot-adding
back into System RAM.
- memmap=nn!ss is x86-only and blind to firmware reserved holes and NUMA
node boundaries.
- cma=, hugetlb_cma=, and reserve_mem= leave memory in memblock.memory
and System RAM, paying ~16 MiB/GiB (on 4 KiB pages) in boot struct
page arrays upfront and blocking ZONE_DEVICE and driver-managed
hotplug consumers.
- Runtime offline_and_remove_memory() cannot remove boot RAM on arm64
and cannot guarantee 1 GiB contiguity after early allocations.
Add CONFIG_EXTMEM and the early boot parameter:
extmem=[<nid>|all:]<size|max>[:<align>][:keep=<size>][,...]
to carve section-aligned physical memory ranges above 4 GiB out of
memblock after NUMA setup and before NODE_DATA, sparse_init(), or
kasan_init() run:
- Switch pre-NUMA memblock allocations bottom-up so early page tables
stay out of the top of carvable nodes, then restore top-down order.
- Include MEMBLOCK_HOTPLUG so movable_node does not hide secondary
nodes, reuse memblock_reserve_contig_multi() across firmware holes,
and advise memory_block_advise_max_size() for hotplug consumers.
- Trim x86_64 pfn_mapped[] before kasan_init() and unmap carved ranges
from the direct/linear map before SMP bringup.
- Add per-region alignment to struct memregion_info, release carved
ranges from System RAM in /proc/iomem (needed on x86_64 where
e820__reserve_resources() populates iomem from e820_table rather than
memblock.memory), and register "extmem" platform devices with
IORESOURCE_MEM resources and region metadata.
Signed-off-by: Suseendran Bhaskaran <suseendranb@google.com>
---
.../admin-guide/kernel-parameters.txt | 15 +
MAINTAINERS | 7 +
arch/arm64/mm/init.c | 3 +
arch/x86/mm/init_64.c | 2 +
arch/x86/mm/numa.c | 3 +
include/linux/extmem.h | 13 +
include/linux/memregion.h | 1 +
mm/Kconfig | 11 +
mm/Makefile | 1 +
mm/arch_numa.c | 3 +
mm/extmem.c | 419 ++++++++++++++++++
mm/mm_init.c | 2 +
12 files changed, 480 insertions(+)
create mode 100644 include/linux/extmem.h
create mode 100644 mm/extmem.c
diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
index dce9b8f3ae98..c20667240080 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -1693,6 +1693,21 @@ Kernel parameters
might take longer, especially on systems with a lot of
memory. Available with CONFIG_PAGE_EXTENSION=y.
+ extmem= [KNL,MM,X86-64,ARM64,EARLY]
+ Format: [<nid>|all:]<size|max>[:<align>][:keep=<keep_size>][,...]
+ Carve NUMA-aware, aligned physical memory regions above
+ 4 GiB out of memblock after NUMA discovery and before
+ struct page allocation, unmap them from the kernel
+ direct/linear map, and expose them as "extmem" platform
+ devices (up to 8 contiguous ranges per node and 64
+ regions total).
+ <align> defaults to and must be at least the sparsemem
+ section size (128 MiB on 4K/16K pages, 512 MiB on 64K
+ pages), and <size> must be a multiple of <align>.
+ "max" carves all aligned memory above <keep_size> and
+ 4 GiB (or all memory above 4 GiB on an explicit
+ secondary node <nid> > 0).
+
failslab=
fail_usercopy=
fail_page_alloc=
diff --git a/MAINTAINERS b/MAINTAINERS
index 895c33a99acb..306707fdfd68 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -17562,6 +17562,13 @@ S: Maintained
F: include/linux/execmem.h
F: mm/execmem.c
+MEMORY MANAGEMENT - EXTMEM
+M: Suseendran Bhaskaran <suseendranb@google.com>
+L: linux-mm@kvack.org
+S: Maintained
+F: include/linux/extmem.h
+F: mm/extmem.c
+
MEMORY MANAGEMENT - GUP (GET USER PAGES)
M: David Hildenbrand <david@kernel.org>
R: Jason Gunthorpe <jgg@nvidia.com>
diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c
index 4e7682dfe366..802738e6c9d6 100644
--- a/arch/arm64/mm/init.c
+++ b/arch/arm64/mm/init.c
@@ -25,6 +25,7 @@
#include <linux/dma-direct.h>
#include <linux/dma-map-ops.h>
#include <linux/efi.h>
+#include <linux/extmem.h>
#include <linux/swiotlb.h>
#include <linux/vmalloc.h>
#include <linux/mm.h>
@@ -314,6 +315,8 @@ void __init bootmem_init(void)
min_low_pfn = min;
arch_numa_init();
+ if (!IS_ENABLED(CONFIG_NUMA))
+ extmem_init();
kvm_hyp_reserve();
dma_limits_init();
diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
index d027438c6bc8..d9f54c1dea4f 100644
--- a/arch/x86/mm/init_64.c
+++ b/arch/x86/mm/init_64.c
@@ -27,6 +27,7 @@
#include <linux/pfn.h>
#include <linux/poison.h>
#include <linux/dma-mapping.h>
+#include <linux/extmem.h>
#include <linux/memory.h>
#include <linux/memory_hotplug.h>
#include <linux/memremap.h>
@@ -824,6 +825,7 @@ kernel_physical_mapping_change(unsigned long paddr_start,
static __always_inline void x86_numa_init(void)
{
memblock_set_node(0, PHYS_ADDR_MAX, &memblock.memory, 0);
+ extmem_init();
}
#endif
diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
index ced66e68a68e..6d2943fd0b2e 100644
--- a/arch/x86/mm/numa.c
+++ b/arch/x86/mm/numa.c
@@ -14,6 +14,7 @@
#include <linux/topology.h>
#include <linux/sort.h>
#include <linux/numa_memblks.h>
+#include <linux/extmem.h>
#include <asm/e820/api.h>
#include <asm/proto.h>
@@ -130,6 +131,8 @@ static int __init numa_register_nodes(void)
if (!memblock_validate_numa_coverage(SZ_1M))
return -EINVAL;
+ extmem_init();
+
/* Finally register nodes. */
for_each_node_mask(nid, node_possible_map) {
unsigned long start_pfn, end_pfn;
diff --git a/include/linux/extmem.h b/include/linux/extmem.h
new file mode 100644
index 000000000000..88fde6f26e64
--- /dev/null
+++ b/include/linux/extmem.h
@@ -0,0 +1,13 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef _LINUX_EXTMEM_H
+#define _LINUX_EXTMEM_H
+
+#ifdef CONFIG_EXTMEM
+void extmem_init(void);
+void extmem_unmap_regions(void);
+#else
+static inline void extmem_init(void) { }
+static inline void extmem_unmap_regions(void) { }
+#endif
+
+#endif /* _LINUX_EXTMEM_H */
diff --git a/include/linux/memregion.h b/include/linux/memregion.h
index a55f62cc5266..b725948496ab 100644
--- a/include/linux/memregion.h
+++ b/include/linux/memregion.h
@@ -9,6 +9,7 @@
struct memregion_info {
int target_node;
struct range range;
+ unsigned int align;
};
#ifdef CONFIG_MEMREGION
diff --git a/mm/Kconfig b/mm/Kconfig
index 18925ccb4adc..95dfdd192909 100644
--- a/mm/Kconfig
+++ b/mm/Kconfig
@@ -1537,4 +1537,15 @@ config PTDUMP
source "mm/damon/Kconfig"
+config EXTMEM
+ bool "Architecture-neutral external memory carving (extmem)"
+ depends on MEMORY_HOTREMOVE && (X86_64 || ARM64)
+ select MEMREGION
+ select NUMA_KEEP_MEMINFO if NUMA_MEMBLKS
+ help
+ Allow carving out NUMA-aware, section- or huge-page-aligned
+ physical memory regions at boot via the "extmem=" kernel command
+ line parameter and exposing them as "extmem" platform devices
+ carrying memory-region metadata and IORESOURCE_MEM resources.
+
endmenu
diff --git a/mm/Makefile b/mm/Makefile
index f49994e61b03..0542953db072 100644
--- a/mm/Makefile
+++ b/mm/Makefile
@@ -151,3 +151,4 @@ obj-$(CONFIG_TMPFS_QUOTA) += shmem_quota.o
obj-$(CONFIG_LAZY_MMU_MODE_KUNIT_TEST) += tests/lazy_mmu_mode_kunit.o
obj-$(CONFIG_VMSTAT_KUNIT_TEST) += tests/vmstat_kunit.o
obj-$(CONFIG_MEM_ALLOC_PROFILING) += alloc_tag.o
+obj-$(CONFIG_EXTMEM) += extmem.o
diff --git a/mm/arch_numa.c b/mm/arch_numa.c
index 8125e9cf07b6..be434cf69d44 100644
--- a/mm/arch_numa.c
+++ b/mm/arch_numa.c
@@ -9,6 +9,7 @@
#define pr_fmt(fmt) "NUMA: " fmt
#include <linux/acpi.h>
+#include <linux/extmem.h>
#include <linux/memblock.h>
#include <linux/module.h>
#include <linux/of.h>
@@ -224,6 +225,8 @@ static int __init numa_register_nodes(void)
if (!memblock_validate_numa_coverage(0))
return -EINVAL;
+ extmem_init();
+
/* Finally register nodes. */
for_each_node_mask(nid, numa_nodes_parsed) {
unsigned long start_pfn, end_pfn;
diff --git a/mm/extmem.c b/mm/extmem.c
new file mode 100644
index 000000000000..e5be9fcb6bbd
--- /dev/null
+++ b/mm/extmem.c
@@ -0,0 +1,419 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Architecture-neutral external memory (extmem) boot carving.
+ */
+
+#define pr_fmt(fmt) "extmem: " fmt
+
+#include <linux/align.h>
+#include <linux/bitops.h>
+#include <linux/build_bug.h>
+#include <linux/ctype.h>
+#include <linux/err.h>
+#include <linux/extmem.h>
+#include <linux/init.h>
+#include <linux/ioport.h>
+#include <linux/kernel.h>
+#include <linux/limits.h>
+#include <linux/log2.h>
+#include <linux/memblock.h>
+#include <linux/memory.h>
+#include <linux/memory_hotplug.h>
+#include <linux/memregion.h>
+#include <linux/mm.h>
+#include <linux/mmzone.h>
+#include <linux/nodemask.h>
+#include <linux/numa.h>
+#include <linux/pgtable.h>
+#include <linux/platform_device.h>
+#include <linux/sizes.h>
+#include <linux/string.h>
+
+#include "mm_init.h"
+
+#define EXTMEM_MAX_RANGES 8
+#define EXTMEM_MAX_REGIONS 64
+#define EXTMEM_MIN_ALIGN BIT_ULL(SECTION_SIZE_BITS)
+#define EXTMEM_ALL_NODES MAX_NUMNODES
+
+struct extmem_rule {
+ int nid;
+ phys_addr_t size;
+ phys_addr_t align;
+ phys_addr_t keep;
+};
+
+struct extmem_region {
+ phys_addr_t base;
+ phys_addr_t size;
+ phys_addr_t align;
+ int nid;
+};
+
+static struct extmem_rule extmem_rules[EXTMEM_MAX_REGIONS] __initdata;
+static unsigned int extmem_nr_rules __initdata;
+
+static struct extmem_region extmem_regions[EXTMEM_MAX_REGIONS] __initdata;
+static unsigned int extmem_nr_regions __initdata;
+
+/*
+ * Parse [<nid>|all:]<size|max>[:<align>][:keep=<keep_size>]
+ */
+static int __init extmem_parse_one(char *s)
+{
+ struct extmem_rule rule = {
+ .nid = NUMA_NO_NODE,
+ .align = EXTMEM_MIN_ALIGN,
+ };
+ char *colon, *endp;
+
+ if (!*s)
+ return -EINVAL;
+ if (extmem_nr_rules >= ARRAY_SIZE(extmem_rules))
+ return -ENOSPC;
+
+ colon = isdigit(*s) ? strchr(s, ':') : NULL;
+ if (str_has_prefix(s, "all:")) {
+ rule.nid = EXTMEM_ALL_NODES;
+ s += 4;
+ } else if (colon) {
+ unsigned int nid;
+ int ret;
+
+ *colon = '\0';
+ ret = kstrtouint(s, 10, &nid);
+ *colon = ':';
+ if (!ret) {
+ if (nid < MAX_NUMNODES) {
+ rule.nid = (int)nid;
+ s = colon + 1;
+ } else if (nid < EXTMEM_MIN_ALIGN) {
+ return -EINVAL;
+ }
+ }
+ }
+
+ if (str_has_prefix(s, "max") && (s[3] == ':' || s[3] == '\0')) {
+ rule.size = PHYS_ADDR_MAX;
+ s += 3;
+ } else {
+ rule.size = memparse(s, &endp);
+ if (endp == s || !rule.size || rule.size == PHYS_ADDR_MAX)
+ return -EINVAL;
+ s = endp;
+ }
+
+ if (*s == ':' && !str_has_prefix(s + 1, "keep=")) {
+ s++;
+ rule.align = memparse(s, &endp);
+ if (endp == s || !is_power_of_2(rule.align) ||
+ rule.align < EXTMEM_MIN_ALIGN)
+ return -EINVAL;
+ s = endp;
+ }
+
+ if (str_has_prefix(s, ":keep=")) {
+ s += 6;
+ rule.keep = memparse(s, &endp);
+ if (endp == s || !rule.keep)
+ return -EINVAL;
+ s = endp;
+ }
+
+ if (*s != '\0')
+ return -EINVAL;
+ if (rule.size == PHYS_ADDR_MAX) {
+ if (!rule.keep &&
+ (rule.nid <= 0 || rule.nid == EXTMEM_ALL_NODES))
+ return -EINVAL;
+ } else if (!IS_ALIGNED(rule.size, rule.align)) {
+ return -EINVAL;
+ }
+
+ extmem_rules[extmem_nr_rules++] = rule;
+ return 0;
+}
+
+static int __init early_extmem(char *p)
+{
+ unsigned int orig_nr_rules = extmem_nr_rules;
+ char *tok;
+ int err;
+
+ if (!p)
+ return -EINVAL;
+
+ while ((tok = strsep(&p, ",")) != NULL) {
+ err = extmem_parse_one(tok);
+ if (err) {
+ extmem_nr_rules = orig_nr_rules;
+ pr_err("invalid extmem option '%s' (%pe)\n",
+ tok, ERR_PTR(err));
+ return err;
+ }
+ }
+
+ /*
+ * Place pre-SRAT memblock allocations bottom-up (like movable_node)
+ * so early page tables stay in low RAM rather than fragmenting the
+ * top of a NUMA node before extmem_init() runs.
+ */
+ if (extmem_nr_rules) {
+ memblock_set_bottom_up(true);
+ arch_boot_carveout_enable();
+ }
+
+ return 0;
+}
+early_param("extmem", early_extmem);
+
+static int __init extmem_find_keep_end(int nid, phys_addr_t keep,
+ phys_addr_t *keep_end)
+{
+ phys_addr_t start, end, rem = keep;
+ u64 i;
+
+ __for_each_mem_range(i, &memblock.memory, NULL, nid, MEMBLOCK_HOTPLUG,
+ &start, &end, NULL) {
+ if (rem <= end - start) {
+ *keep_end = start + rem;
+ return 0;
+ }
+ rem -= end - start;
+ }
+
+ return -ENOSPC;
+}
+
+static int __init extmem_commit_regions(unsigned int nr, const char *verb)
+{
+ struct extmem_region *regs = &extmem_regions[extmem_nr_regions];
+ struct memblock_region *r;
+ unsigned int i;
+ u64 hotplug = 0;
+
+ BUILD_BUG_ON(EXTMEM_MAX_REGIONS > BITS_PER_LONG_LONG);
+
+ for (i = 0; i < nr; i++) {
+ if (!numa_valid_node(regs[i].nid) ||
+ !node_possible(regs[i].nid))
+ regs[i].nid = max(phys_to_target_node(regs[i].base), 0);
+
+ for_each_mem_region(r) {
+ if (memblock_addrs_overlap(regs[i].base, regs[i].size,
+ r->base, r->size) &&
+ memblock_is_hotpluggable(r)) {
+ hotplug |= BIT_ULL(i);
+ break;
+ }
+ }
+
+ if (memblock_remove(regs[i].base, regs[i].size)) {
+ while (i--)
+ memblock_add_node(regs[i].base, regs[i].size,
+ regs[i].nid,
+ (hotplug & BIT_ULL(i)) ?
+ MEMBLOCK_HOTPLUG :
+ MEMBLOCK_NONE);
+ return -ENOMEM;
+ }
+ }
+
+ for (i = 0; i < nr; i++) {
+ phys_addr_t end = regs[i].base + regs[i].size - 1;
+
+ arch_boot_carveout_early(regs[i].base, regs[i].size);
+ memory_block_advise_max_size(BIT_ULL(__ffs64(regs[i].base |
+ regs[i].size)));
+ pr_info("%s [%pa-%pa] (%llu MiB) on node %d\n",
+ verb, ®s[i].base, &end,
+ (u64)(regs[i].size / SZ_1M), regs[i].nid);
+ }
+ extmem_nr_regions += nr;
+
+ return 0;
+}
+
+static void __init extmem_carve_node(int nid, const struct extmem_rule *rule)
+{
+ unsigned int flags = MEMBLOCK_CONTIG_TOP_DOWN |
+ MEMBLOCK_CONTIG_INCLUDE_HOTPLUG;
+ struct memblock_contig_range cands[EXTMEM_MAX_RANGES];
+ phys_addr_t high_min = SZ_4G, keep_end;
+ int max_ranges, nr, k;
+ char scope[16];
+
+ if (extmem_nr_regions >= EXTMEM_MAX_REGIONS)
+ return;
+ if (rule->size == PHYS_ADDR_MAX)
+ flags |= MEMBLOCK_CONTIG_ALLOW_PARTIAL;
+ max_ranges = min_t(unsigned int, EXTMEM_MAX_RANGES,
+ EXTMEM_MAX_REGIONS - extmem_nr_regions);
+
+ if (nid == NUMA_NO_NODE)
+ strscpy(scope, "system", sizeof(scope));
+ else
+ snprintf(scope, sizeof(scope), "node %d", nid);
+
+ if (rule->keep) {
+ if (extmem_find_keep_end(nid, rule->keep, &keep_end)) {
+ pr_info("%s has less than %llu MiB, skipping\n",
+ scope, (u64)(rule->keep / SZ_1M));
+ return;
+ }
+ high_min = max(high_min, keep_end);
+ }
+
+ 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);
+
+ for (i = 0; i < extmem_nr_rules; i++) {
+ struct extmem_rule *rule = &extmem_rules[i];
+
+ if (rule->nid != EXTMEM_ALL_NODES) {
+ if (rule->nid == NUMA_NO_NODE ||
+ node_possible(rule->nid))
+ extmem_carve_node(rule->nid, rule);
+ continue;
+ }
+
+ for_each_node_mask(nid, node_possible_map) {
+ unsigned long start_pfn, end_pfn;
+
+ get_pfn_range_for_nid(nid, &start_pfn, &end_pfn);
+ if (start_pfn >= end_pfn)
+ continue;
+
+ for (j = 0; j < extmem_nr_rules; j++)
+ if (extmem_rules[j].nid == nid)
+ break;
+ if (j == extmem_nr_rules)
+ extmem_carve_node(nid, rule);
+ }
+ }
+
+ if (!extmem_nr_regions)
+ return;
+ new_end_pfn = PFN_DOWN(memblock_end_of_DRAM());
+ if (new_end_pfn < orig_end_pfn) {
+ max_pfn = new_end_pfn;
+ max_low_pfn = new_end_pfn;
+ }
+}
+
+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",
+ ®->base, &end, ERR_PTR(err));
+ continue;
+ }
+
+ extmem_regions[dst++] = *reg;
+ }
+ extmem_nr_regions = dst;
+}
+
+static unsigned int __init extmem_region_align(phys_addr_t align)
+{
+ if (!has_transparent_hugepage())
+ return PAGE_SIZE;
+ if (IS_ENABLED(CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD) &&
+ align >= PUD_SIZE && (u64)PUD_SIZE <= UINT_MAX)
+ return (unsigned int)PUD_SIZE;
+ return PMD_SIZE;
+}
+
+static int __init extmem_publish_regions(void)
+{
+ unsigned int i;
+
+ for (i = 0; i < extmem_nr_regions; i++) {
+ struct extmem_region *reg = &extmem_regions[i];
+ struct resource res = DEFINE_RES_MEM_NAMED(reg->base, reg->size,
+ "External Memory");
+ struct memregion_info mri = {
+ .target_node = reg->nid,
+ .range = { .start = res.start, .end = res.end },
+ .align = extmem_region_align(reg->align),
+ };
+ struct platform_device *pdev;
+ int id, err;
+
+ release_mem_region_adjustable(reg->base, reg->size);
+
+ id = memregion_alloc(GFP_KERNEL);
+ if (id < 0) {
+ pr_err("failed to allocate memregion ID for %pr: %pe\n",
+ &res, ERR_PTR(id));
+ continue;
+ }
+
+ pdev = platform_device_alloc("extmem", id);
+ if (!pdev) {
+ memregion_free(id);
+ continue;
+ }
+
+ set_dev_node(&pdev->dev, numa_map_to_online_node(reg->nid));
+ err = platform_device_add_resources(pdev, &res, 1);
+ if (!err)
+ err = platform_device_add_data(pdev, &mri, sizeof(mri));
+ if (!err)
+ err = platform_device_add(pdev);
+ if (err) {
+ pr_err("failed to register extmem.%d for %pr: %pe\n",
+ id, &res, ERR_PTR(err));
+ platform_device_put(pdev);
+ memregion_free(id);
+ }
+ }
+
+ return 0;
+}
+core_initcall(extmem_publish_regions);
diff --git a/mm/mm_init.c b/mm/mm_init.c
index e66d3850e128..a0cc18d9d7c5 100644
--- a/mm/mm_init.c
+++ b/mm/mm_init.c
@@ -29,6 +29,7 @@
#include <linux/cma.h>
#include <linux/crash_dump.h>
#include <linux/execmem.h>
+#include <linux/extmem.h>
#include <linux/sizes.h>
#include <linux/vmstat.h>
#include <linux/kexec_handover.h>
@@ -2675,4 +2676,5 @@ void __init mm_core_init(void)
kmsan_init_runtime();
mm_cache_init();
execmem_init();
+ extmem_unmap_regions();
}
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [RFC PATCH 06/11] dax/hmem: bind extmem platform devices with per-region alignment
2026-12-02 0:19 [RFC PATCH 00/11] mm: NUMA-aware boot memory carving (extmem) Suseendran Bhaskaran
` (4 preceding siblings ...)
2026-12-02 0:19 ` [RFC PATCH 05/11] mm/extmem: add architecture-neutral external memory subsystem Suseendran Bhaskaran
@ 2026-12-02 0:19 ` Suseendran Bhaskaran
2026-12-02 0:19 ` [RFC PATCH 07/11] nvdimm/ramdax: manage bus and DIMM allocations with devres Suseendran Bhaskaran
` (5 subsequent siblings)
11 siblings, 0 replies; 14+ messages in thread
From: Suseendran Bhaskaran @ 2026-12-02 0:19 UTC (permalink / raw)
To: 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, linux-arm-kernel, linux-cxl, linux-doc, linux-kernel,
linux-mm, nvdimm, x86, Suseendran Bhaskaran
dax_hmem_probe() only matches "hmem" platform devices, hardcodes PMD_SIZE
alignment, and defaults to IORESOURCE_DAX_KMEM (unless region_idle is
set), without checking device identity or a non-NULL platform_data
pointer.
Boot memory carveouts published as "extmem" platform devices need a
default driver match without hardcoding "hmem" inside mm/, need PUD_SIZE
alignment (1 GiB on x86_64) when carved on PUD boundaries, and must
default to device_dax (flags = 0) instead of routing to dax_kmem (where
onlining into System RAM would overwrite memory preserved across Kexec
HandOver).
Allow CONFIG_DEV_DAX_HMEM with CONFIG_EXTMEM (using set_dev_node() for
!CONFIG_NUMA builds), match both "hmem" and "extmem" via
platform_device_id, honor mri->align in dax_hmem_probe() while keeping
PMD_SIZE and default IORESOURCE_DAX_KMEM (when !region_idle) for EFI Soft
Reserved devices, and reject driver_override binds from unrelated
platform devices.
Signed-off-by: Suseendran Bhaskaran <suseendranb@google.com>
---
.../admin-guide/kernel-parameters.txt | 6 ++++-
drivers/dax/Kconfig | 2 +-
drivers/dax/hmem/hmem.c | 27 +++++++++++++------
3 files changed, 25 insertions(+), 10 deletions(-)
diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
index c20667240080..e75b35d9a66b 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -1700,7 +1700,11 @@ Kernel parameters
struct page allocation, unmap them from the kernel
direct/linear map, and expose them as "extmem" platform
devices (up to 8 contiguous ranges per node and 64
- regions total).
+ regions total). When CONFIG_DEV_DAX_HMEM is enabled,
+ dax_hmem matches "extmem" devices by default, exposing
+ device_dax instances at PUD or PMD alignment (configurable
+ via daxctl, or left idle at boot with
+ dax_hmem.region_idle=1).
<align> defaults to and must be at least the sparsemem
section size (128 MiB on 4K/16K pages, 512 MiB on 64K
pages), and <size> must be a multiple of <align>.
diff --git a/drivers/dax/Kconfig b/drivers/dax/Kconfig
index 602f9a0839a9..834208398f4f 100644
--- a/drivers/dax/Kconfig
+++ b/drivers/dax/Kconfig
@@ -29,7 +29,7 @@ config DEV_DAX_PMEM
config DEV_DAX_HMEM
tristate "HMEM DAX: direct access to 'specific purpose' memory"
- depends on EFI_SOFT_RESERVE
+ depends on EFI_SOFT_RESERVE || EXTMEM
select NUMA_KEEP_MEMINFO if NUMA_MEMBLKS
default DEV_DAX
depends on CXL_ACPI || !CXL_ACPI
diff --git a/drivers/dax/hmem/hmem.c b/drivers/dax/hmem/hmem.c
index af21f66bf872..e82ffbadfe20 100644
--- a/drivers/dax/hmem/hmem.c
+++ b/drivers/dax/hmem/hmem.c
@@ -1,7 +1,9 @@
// SPDX-License-Identifier: GPL-2.0
#include <linux/platform_device.h>
+#include <linux/mod_devicetable.h>
#include <linux/memregion.h>
#include <linux/module.h>
+#include <linux/string.h>
#include <linux/dax.h>
#include "../../cxl/cxl.h"
#include "../bus.h"
@@ -11,24 +13,25 @@ module_param_named(region_idle, region_idle, bool, 0644);
static int dax_hmem_probe(struct platform_device *pdev)
{
- unsigned long flags = IORESOURCE_DAX_KMEM;
struct device *dev = &pdev->dev;
+ struct memregion_info *mri = dev->platform_data;
+ bool is_hmem = strcmp(pdev->name, "hmem") == 0;
struct dax_region *dax_region;
- struct memregion_info *mri;
struct dev_dax_data data;
+ if ((!is_hmem && strcmp(pdev->name, "extmem") != 0) || !mri)
+ return -EINVAL;
+
/*
* @region_idle == true indicates that an administrative agent
* wants to manipulate the range partitioning before the devices
* are created, so do not send them to the dax_kmem driver by
* default.
*/
- if (region_idle)
- flags = 0;
-
- mri = dev->platform_data;
dax_region = alloc_dax_region(dev, pdev->id, &mri->range,
- mri->target_node, PMD_SIZE, flags);
+ mri->target_node, mri->align ?: PMD_SIZE,
+ is_hmem && !region_idle ?
+ IORESOURCE_DAX_KMEM : 0);
if (!dax_region)
return -ENOMEM;
@@ -42,8 +45,16 @@ static int dax_hmem_probe(struct platform_device *pdev)
return PTR_ERR_OR_ZERO(devm_create_dev_dax(&data));
}
+static const struct platform_device_id dax_hmem_ids[] = {
+ { "hmem" },
+ { "extmem" },
+ { }
+};
+MODULE_DEVICE_TABLE(platform, dax_hmem_ids);
+
static struct platform_driver dax_hmem_driver = {
.probe = dax_hmem_probe,
+ .id_table = dax_hmem_ids,
.driver = {
.name = "hmem",
},
@@ -97,7 +108,7 @@ static int __hmem_register_device(struct device *host, int target_nid,
}
pdev->dev.parent = host;
- pdev->dev.numa_node = numa_map_to_online_node(target_nid);
+ set_dev_node(&pdev->dev, numa_map_to_online_node(target_nid));
info = (struct memregion_info) {
.target_node = target_nid,
.range = {
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [RFC PATCH 07/11] nvdimm/ramdax: manage bus and DIMM allocations with devres
2026-12-02 0:19 [RFC PATCH 00/11] mm: NUMA-aware boot memory carving (extmem) Suseendran Bhaskaran
` (5 preceding siblings ...)
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 ` Suseendran Bhaskaran
2026-12-02 0:19 ` [RFC PATCH 08/11] nvdimm/ramdax: harden probe checks and select NUMA_KEEP_MEMINFO Suseendran Bhaskaran
` (4 subsequent siblings)
11 siblings, 0 replies; 14+ messages in thread
From: Suseendran Bhaskaran @ 2026-12-02 0:19 UTC (permalink / raw)
To: 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, linux-arm-kernel, linux-cxl, linux-doc, linux-kernel,
linux-mm, nvdimm, x86, Suseendran Bhaskaran
ramdax_probe() inherited a static nvdimm_bus_descriptor from e820_pmem,
sharing a single descriptor across all probed pmem-region platform
devices (and omitting nd_desc->of_node). In addition,
ramdax_register_dimm() allocates dimm, nd_set, and the memremap()'d
label area without freeing or unmapping them in ramdax_remove() or when
a multi-resource probe fails partway through.
Allocate nd_desc, dimm, and nd_set with devm_kzalloc_obj() and map
dimm->label_area with devm_memremap() so each device owns its bus
descriptor and devres releases DIMM and region state after
nvdimm_bus_unregister() on unbind or failed probe.
Fixes: 43bc0aa19a21 ("nvdimm: allow exposing RAM carveouts as NVDIMM DIMM devices")
Signed-off-by: Suseendran Bhaskaran <suseendranb@google.com>
---
drivers/nvdimm/ramdax.c | 123 ++++++++++++++--------------------------
1 file changed, 44 insertions(+), 79 deletions(-)
diff --git a/drivers/nvdimm/ramdax.c b/drivers/nvdimm/ramdax.c
index e76fca736d76..cca470d071eb 100644
--- a/drivers/nvdimm/ramdax.c
+++ b/drivers/nvdimm/ramdax.c
@@ -11,7 +11,7 @@
#include <linux/libnvdimm.h>
#include <linux/module.h>
#include <linux/numa.h>
-#include <linux/slab.h>
+#include <linux/err.h>
#include <linux/io.h>
#include <linux/of.h>
@@ -31,16 +31,16 @@ static void ramdax_remove(struct platform_device *pdev)
nvdimm_bus_unregister(nvdimm_bus);
}
-static int ramdax_register_region(struct resource *res,
- struct nvdimm *nvdimm,
- struct nvdimm_bus *nvdimm_bus)
+static int ramdax_register_region(struct device *dev, struct resource *res,
+ struct nvdimm *nvdimm,
+ struct nvdimm_bus *nvdimm_bus)
{
struct nd_mapping_desc mapping;
struct nd_region_desc ndr_desc;
struct nd_interleave_set *nd_set;
int nid = phys_to_target_node(res->start);
- nd_set = kzalloc_obj(*nd_set);
+ nd_set = devm_kzalloc_obj(dev, *nd_set);
if (!nd_set)
return -ENOMEM;
@@ -62,34 +62,28 @@ static int ramdax_register_region(struct resource *res,
ndr_desc.nd_set = nd_set;
if (!nvdimm_pmem_region_create(nvdimm_bus, &ndr_desc))
- goto err_free_nd_set;
+ return -ENXIO;
return 0;
-
-err_free_nd_set:
- kfree(nd_set);
- return -ENXIO;
}
static int ramdax_register_dimm(struct resource *res, void *data)
{
+ struct device *dev = data;
+ struct nvdimm_bus *nvdimm_bus = dev_get_drvdata(dev);
resource_size_t start = res->start;
resource_size_t size = resource_size(res);
unsigned long flags = 0, cmd_mask = 0;
- struct nvdimm_bus *nvdimm_bus = data;
struct ramdax_dimm *dimm;
- int err;
- dimm = kzalloc_obj(*dimm);
+ dimm = devm_kzalloc_obj(dev, *dimm);
if (!dimm)
return -ENOMEM;
- dimm->label_area = memremap(start + size - LABEL_AREA_SIZE,
- LABEL_AREA_SIZE, MEMREMAP_WB);
- if (!dimm->label_area) {
- err = -ENOMEM;
- goto err_free_dimm;
- }
+ dimm->label_area = devm_memremap(dev, start + size - LABEL_AREA_SIZE,
+ LABEL_AREA_SIZE, MEMREMAP_WB);
+ if (IS_ERR(dimm->label_area))
+ return PTR_ERR(dimm->label_area);
set_bit(NDD_LABELING, &flags);
set_bit(NDD_REGISTER_SYNC, &flags);
@@ -99,24 +93,10 @@ static int ramdax_register_dimm(struct resource *res, void *data)
dimm->nvdimm = nvdimm_create(nvdimm_bus, dimm,
/* dimm_attribute_groups */ NULL,
flags, cmd_mask, 0, NULL);
- if (!dimm->nvdimm) {
- err = -ENOMEM;
- goto err_unmap_label;
- }
-
- err = ramdax_register_region(res, dimm->nvdimm, nvdimm_bus);
- if (err)
- goto err_remove_nvdimm;
-
- return 0;
+ if (!dimm->nvdimm)
+ return -ENOMEM;
-err_remove_nvdimm:
- nvdimm_delete(dimm->nvdimm);
-err_unmap_label:
- memunmap(dimm->label_area);
-err_free_dimm:
- kfree(dimm);
- return err;
+ return ramdax_register_region(dev, res, dimm->nvdimm, nvdimm_bus);
}
static int ramdax_get_config_size(struct nvdimm *nvdimm, int buf_len,
@@ -210,60 +190,45 @@ static const struct of_device_id ramdax_of_matches[] = {
};
#endif
-static int ramdax_probe_of(struct platform_device *pdev,
- struct nvdimm_bus *bus, struct device_node *np)
-{
- int err;
-
- if (!of_match_node(ramdax_of_matches, np))
- return -ENODEV;
-
- for (int i = 0; i < pdev->num_resources; i++) {
- err = ramdax_register_dimm(&pdev->resource[i], bus);
- if (err)
- goto err_unregister;
- }
-
- return 0;
-
-err_unregister:
- /*
- * FIXME: should we unregister the dimms that were registered
- * successfully
- */
- return err;
-}
-
static int ramdax_probe(struct platform_device *pdev)
{
- static struct nvdimm_bus_descriptor nd_desc;
struct device *dev = &pdev->dev;
+ struct device_node *np = dev_of_node(dev);
+ struct nvdimm_bus_descriptor *nd_desc;
struct nvdimm_bus *nvdimm_bus;
- struct device_node *np;
- int rc = -ENXIO;
+ int rc = -ENODEV;
+
+ if (np && !of_match_node(ramdax_of_matches, np))
+ return -ENODEV;
+
+ nd_desc = devm_kzalloc_obj(dev, *nd_desc);
+ if (!nd_desc)
+ return -ENOMEM;
- nd_desc.provider_name = "ramdax";
- nd_desc.module = THIS_MODULE;
- nd_desc.ndctl = ramdax_ctl;
- nvdimm_bus = nvdimm_bus_register(dev, &nd_desc);
+ nd_desc->provider_name = "ramdax";
+ nd_desc->module = THIS_MODULE;
+ nd_desc->of_node = np;
+ nd_desc->ndctl = ramdax_ctl;
+ nvdimm_bus = nvdimm_bus_register(dev, nd_desc);
if (!nvdimm_bus)
- goto err;
+ return -ENXIO;
- np = dev_of_node(&pdev->dev);
- if (np)
- rc = ramdax_probe_of(pdev, nvdimm_bus, np);
- else
+ platform_set_drvdata(pdev, nvdimm_bus);
+
+ if (np) {
+ for (unsigned int i = 0; i < pdev->num_resources; i++) {
+ rc = ramdax_register_dimm(&pdev->resource[i], dev);
+ if (rc)
+ break;
+ }
+ } else {
rc = walk_iomem_res_desc(IORES_DESC_PERSISTENT_MEMORY_LEGACY,
- IORESOURCE_MEM, 0, -1, nvdimm_bus,
+ IORESOURCE_MEM, 0, -1, dev,
ramdax_register_dimm);
+ }
if (rc)
- goto err;
+ nvdimm_bus_unregister(nvdimm_bus);
- platform_set_drvdata(pdev, nvdimm_bus);
-
- return 0;
-err:
- nvdimm_bus_unregister(nvdimm_bus);
return rc;
}
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [RFC PATCH 08/11] nvdimm/ramdax: harden probe checks and select NUMA_KEEP_MEMINFO
2026-12-02 0:19 [RFC PATCH 00/11] mm: NUMA-aware boot memory carving (extmem) Suseendran Bhaskaran
` (6 preceding siblings ...)
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 ` Suseendran Bhaskaran
2026-12-02 0:19 ` [RFC PATCH 09/11] nvdimm/ramdax: support binding extmem platform devices Suseendran Bhaskaran
` (3 subsequent siblings)
11 siblings, 0 replies; 14+ messages in thread
From: Suseendran Bhaskaran @ 2026-12-02 0:19 UTC (permalink / raw)
To: 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, linux-arm-kernel, linux-cxl, linux-doc, linux-kernel,
linux-mm, nvdimm, x86, Suseendran Bhaskaran
Fix three probe and NUMA lookup issues in ramdax:
- Select NUMA_KEEP_MEMINFO if NUMA_MEMBLKS in Kconfig so
phys_to_target_node() resolves the target NUMA node instead of
falling back to the stub in mm/numa.c that assumes node 0 (matching
DEV_DAX_HMEM and CXL_BUS).
- Reject resources with size <= LABEL_AREA_SIZE (128 KiB) before
subtracting LABEL_AREA_SIZE, and skip non-IORESOURCE_MEM platform
resources.
- Reject driver_override binds from non-OF platform devices other than
"e820_pmem" with -ENODEV instead of registering a bus and walking
legacy e820 PMEM ranges.
Fixes: 43bc0aa19a21 ("nvdimm: allow exposing RAM carveouts as NVDIMM DIMM devices")
Signed-off-by: Suseendran Bhaskaran <suseendranb@google.com>
---
drivers/nvdimm/Kconfig | 1 +
drivers/nvdimm/ramdax.c | 13 ++++++++++++-
2 files changed, 13 insertions(+), 1 deletion(-)
diff --git a/drivers/nvdimm/Kconfig b/drivers/nvdimm/Kconfig
index 44ab929a1ad5..33d83623bfc0 100644
--- a/drivers/nvdimm/Kconfig
+++ b/drivers/nvdimm/Kconfig
@@ -100,6 +100,7 @@ config OF_PMEM
config RAMDAX
tristate "Support persistent memory interfaces on RAM carveouts"
depends on X86_PMEM_LEGACY || OF || COMPILE_TEST
+ select NUMA_KEEP_MEMINFO if NUMA_MEMBLKS
default LIBNVDIMM
help
Allows creation of DAX devices on RAM carveouts.
diff --git a/drivers/nvdimm/ramdax.c b/drivers/nvdimm/ramdax.c
index cca470d071eb..4efffc3ee5a0 100644
--- a/drivers/nvdimm/ramdax.c
+++ b/drivers/nvdimm/ramdax.c
@@ -9,7 +9,9 @@
#include <linux/platform_device.h>
#include <linux/memory_hotplug.h>
#include <linux/libnvdimm.h>
+#include <linux/ioport.h>
#include <linux/module.h>
+#include <linux/string.h>
#include <linux/numa.h>
#include <linux/err.h>
#include <linux/io.h>
@@ -76,6 +78,9 @@ static int ramdax_register_dimm(struct resource *res, void *data)
unsigned long flags = 0, cmd_mask = 0;
struct ramdax_dimm *dimm;
+ if (size <= LABEL_AREA_SIZE)
+ return -EINVAL;
+
dimm = devm_kzalloc_obj(dev, *dimm);
if (!dimm)
return -ENOMEM;
@@ -198,8 +203,12 @@ static int ramdax_probe(struct platform_device *pdev)
struct nvdimm_bus *nvdimm_bus;
int rc = -ENODEV;
- if (np && !of_match_node(ramdax_of_matches, np))
+ if (np) {
+ if (!of_match_node(ramdax_of_matches, np))
+ return -ENODEV;
+ } else if (strcmp(pdev->name, "e820_pmem") != 0) {
return -ENODEV;
+ }
nd_desc = devm_kzalloc_obj(dev, *nd_desc);
if (!nd_desc)
@@ -217,6 +226,8 @@ static int ramdax_probe(struct platform_device *pdev)
if (np) {
for (unsigned int i = 0; i < pdev->num_resources; i++) {
+ if (resource_type(&pdev->resource[i]) != IORESOURCE_MEM)
+ continue;
rc = ramdax_register_dimm(&pdev->resource[i], dev);
if (rc)
break;
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [RFC PATCH 09/11] nvdimm/ramdax: support binding extmem platform devices
2026-12-02 0:19 [RFC PATCH 00/11] mm: NUMA-aware boot memory carving (extmem) Suseendran Bhaskaran
` (7 preceding siblings ...)
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 ` 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
` (2 subsequent siblings)
11 siblings, 0 replies; 14+ messages in thread
From: Suseendran Bhaskaran @ 2026-12-02 0:19 UTC (permalink / raw)
To: 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, linux-arm-kernel, linux-cxl, linux-doc, linux-kernel,
linux-mm, nvdimm, x86, Suseendran Bhaskaran
Block-backed fsdax filesystems (such as XFS or ext4 mounted with -o dax)
need /dev/pmemX block devices on the libnvdimm bus rather than character
drivers/dax devices.
Allow CONFIG_RAMDAX when CONFIG_EXTMEM is enabled (including x86_64
configs without X86_PMEM_LEGACY or OF) and match "extmem" platform
devices via driver_override alongside OF pmem-region and e820_pmem (also
enabling ACPI arm64 hosts), registering each IORESOURCE_MEM range as a
labeled NVDIMM DIMM.
Signed-off-by: Suseendran Bhaskaran <suseendranb@google.com>
---
Documentation/admin-guide/kernel-parameters.txt | 4 +++-
drivers/nvdimm/Kconfig | 14 +++++++-------
drivers/nvdimm/ramdax.c | 7 ++++---
3 files changed, 14 insertions(+), 11 deletions(-)
diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
index e75b35d9a66b..d25265bb0095 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -1704,7 +1704,9 @@ Kernel parameters
dax_hmem matches "extmem" devices by default, exposing
device_dax instances at PUD or PMD alignment (configurable
via daxctl, or left idle at boot with
- dax_hmem.region_idle=1).
+ dax_hmem.region_idle=1). Regions can also be bound to the
+ ramdax driver via driver_override to expose libnvdimm
+ /dev/pmemX block devices for fsdax filesystems.
<align> defaults to and must be at least the sparsemem
section size (128 MiB on 4K/16K pages, 512 MiB on 64K
pages), and <size> must be a multiple of <align>.
diff --git a/drivers/nvdimm/Kconfig b/drivers/nvdimm/Kconfig
index 33d83623bfc0..2a094ed1dba0 100644
--- a/drivers/nvdimm/Kconfig
+++ b/drivers/nvdimm/Kconfig
@@ -99,21 +99,21 @@ config OF_PMEM
config RAMDAX
tristate "Support persistent memory interfaces on RAM carveouts"
- depends on X86_PMEM_LEGACY || OF || COMPILE_TEST
+ depends on X86_PMEM_LEGACY || OF || EXTMEM || COMPILE_TEST
select NUMA_KEEP_MEMINFO if NUMA_MEMBLKS
default LIBNVDIMM
help
Allows creation of DAX devices on RAM carveouts.
Memory ranges that are manually specified by the
- 'memmap=nn[KMG]!ss[KMG]' kernel command line or defined by dummy
- pmem-region device tree nodes would be managed by this driver as DIMM
- devices with support for dynamic layout of namespaces.
- The driver steals 128K in the end of the memmap range for the
+ 'memmap=nn[KMG]!ss[KMG]' or 'extmem=' kernel command line or defined
+ by dummy pmem-region device tree nodes would be managed by this driver
+ as DIMM devices with support for dynamic layout of namespaces.
+ The driver steals 128K in the end of the range for the
namespace management. This allows supporting up to 509 namespaces
(see 'ndctl create-namespace --help').
- The driver should be force bound to e820_pmem or pmem-region platform
- devices using 'driver_override' device attribute.
+ The driver should be force bound to e820_pmem, extmem, or pmem-region
+ platform devices using 'driver_override' device attribute.
Select N if unsure.
diff --git a/drivers/nvdimm/ramdax.c b/drivers/nvdimm/ramdax.c
index 4efffc3ee5a0..4fb90e8cc018 100644
--- a/drivers/nvdimm/ramdax.c
+++ b/drivers/nvdimm/ramdax.c
@@ -206,7 +206,8 @@ static int ramdax_probe(struct platform_device *pdev)
if (np) {
if (!of_match_node(ramdax_of_matches, np))
return -ENODEV;
- } else if (strcmp(pdev->name, "e820_pmem") != 0) {
+ } else if (strcmp(pdev->name, "extmem") != 0 &&
+ strcmp(pdev->name, "e820_pmem") != 0) {
return -ENODEV;
}
@@ -224,7 +225,7 @@ static int ramdax_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, nvdimm_bus);
- if (np) {
+ if (np || strcmp(pdev->name, "extmem") == 0) {
for (unsigned int i = 0; i < pdev->num_resources; i++) {
if (resource_type(&pdev->resource[i]) != IORESOURCE_MEM)
continue;
@@ -253,6 +254,6 @@ static struct platform_driver ramdax_driver = {
module_platform_driver(ramdax_driver);
-MODULE_DESCRIPTION("NVDIMM support for e820 type-12 memory and OF pmem-region");
+MODULE_DESCRIPTION("NVDIMM support for e820 type-12, OF pmem-region, and extmem");
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Microsoft Corporation");
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [RFC PATCH 10/11] x86/kaslr: avoid placing kernel in carvable high memory when extmem= is set
2026-12-02 0:19 [RFC PATCH 00/11] mm: NUMA-aware boot memory carving (extmem) Suseendran Bhaskaran
` (8 preceding siblings ...)
2026-12-02 0:19 ` [RFC PATCH 09/11] nvdimm/ramdax: support binding extmem platform devices Suseendran Bhaskaran
@ 2026-12-02 0:19 ` Suseendran Bhaskaran
2026-12-02 0:19 ` [RFC PATCH 11/11] mm/extmem: preserve carved regions across KHO kexec Suseendran Bhaskaran
2026-12-02 14:45 ` [RFC PATCH 00/11] mm: NUMA-aware boot memory carving (extmem) Mike Rapoport
11 siblings, 0 replies; 14+ messages in thread
From: Suseendran Bhaskaran @ 2026-12-02 0:19 UTC (permalink / raw)
To: 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, linux-arm-kernel, linux-cxl, linux-doc, linux-kernel,
linux-mm, nvdimm, x86, Suseendran Bhaskaran
Cold-boot extmem= switches early memblock allocations bottom-up, placing
direct-map page tables right above the uncompressed kernel image.
Physical KASLR scans all RAM without checking extmem=, so placing the
kernel above 4 GiB lands the image and page tables inside carvable high
RAM -- breaking 1 GiB contiguity, preventing a clean max carve on
secondary nodes, or causing fixed-size carving to fail with -ENOMEM.
Prefer physical KASLR slots below SZ_4G on cold boot when CONFIG_EXTMEM
is enabled and extmem= is set, falling back to mem_limit if no slot
exists below 4 GiB. KHO bootmem placement and virtual KASLR are
unchanged.
Signed-off-by: Suseendran Bhaskaran <suseendranb@google.com>
---
arch/x86/boot/compressed/kaslr.c | 30 ++++++++++++++++++++++++++----
1 file changed, 26 insertions(+), 4 deletions(-)
diff --git a/arch/x86/boot/compressed/kaslr.c b/arch/x86/boot/compressed/kaslr.c
index 290153818d0f..73c672d6f2ae 100644
--- a/arch/x86/boot/compressed/kaslr.c
+++ b/arch/x86/boot/compressed/kaslr.c
@@ -33,6 +33,7 @@
#undef _SETUP
#include <asm/kexec_handover.h>
+#include <linux/sizes.h>
extern unsigned long get_cmd_line_ptr(void);
@@ -74,6 +75,7 @@ static unsigned long get_boot_seed(void)
#define MAX_MEMMAP_REGIONS 4
static bool memmap_too_large;
+static bool extmem_cmdline;
/*
@@ -271,6 +273,9 @@ static void handle_mem_options(void)
if (mem_size < mem_limit)
mem_limit = mem_size;
+ } else if (IS_ENABLED(CONFIG_EXTMEM) &&
+ !strcmp(param, "extmem") && val && *val) {
+ extmem_cmdline = true;
}
}
@@ -823,11 +828,28 @@ static unsigned long find_random_phys_addr(unsigned long minimum,
/*
* During kexec handover only process KHO bootmem areas that are known
- * not to contain any data that must be preserved.
+ * not to contain any data that must be preserved. On cold boot with
+ * extmem=, prefer slots below 4 GiB so neither the kernel image nor
+ * bottom-up direct-map page tables land in carvable high RAM, falling
+ * back to mem_limit if no usable slot exists below 4 GiB.
*/
- if (!process_kho_entries(minimum, image_size) &&
- !process_efi_entries(minimum, image_size))
- process_e820_entries(minimum, image_size);
+ if (!process_kho_entries(minimum, image_size)) {
+ unsigned long orig_gb_huge_pages = max_gb_huge_pages;
+ u64 orig_mem_limit = mem_limit;
+
+ if (extmem_cmdline && (u64)minimum + image_size <= SZ_4G)
+ mem_limit = min_t(u64, mem_limit, SZ_4G);
+
+ if (!process_efi_entries(minimum, image_size))
+ process_e820_entries(minimum, image_size);
+
+ if (!slot_max && mem_limit != orig_mem_limit) {
+ mem_limit = orig_mem_limit;
+ max_gb_huge_pages = orig_gb_huge_pages;
+ if (!process_efi_entries(minimum, image_size))
+ process_e820_entries(minimum, image_size);
+ }
+ }
phys_addr = slots_fetch_random();
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [RFC PATCH 11/11] mm/extmem: preserve carved regions across KHO kexec
2026-12-02 0:19 [RFC PATCH 00/11] mm: NUMA-aware boot memory carving (extmem) Suseendran Bhaskaran
` (9 preceding siblings ...)
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 ` Suseendran Bhaskaran
2026-12-02 14:45 ` [RFC PATCH 00/11] mm: NUMA-aware boot memory carving (extmem) Mike Rapoport
11 siblings, 0 replies; 14+ messages in thread
From: Suseendran Bhaskaran @ 2026-12-02 0:19 UTC (permalink / raw)
To: 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, linux-arm-kernel, linux-cxl, linux-doc, linux-kernel,
linux-mm, nvdimm, x86, Suseendran Bhaskaran
Across a Kexec HandOver (KHO) live update, ZONE_DEVICE DAX regions
backing guest VMs must keep the same physical ranges, alignments, and
contents without tracking payload pages in KHO's preserved-page radix
tree (extmem ranges are removed from memblock.memory and have no boot
struct page arrays).
Add KHO preservation in mm/extmem_kho.c and document the "extmem" subtree
ABI in include/linux/kho/abi/extmem.h:
- At late_initcall, reclaim any incoming preserved descriptor folio via
kho_restore_free(), then save each carved region's base, size, NUMA
node ID, and alignment shift into a kho_extmem_ser descriptor table
registered with kho_add_subtree().
- Add kho_early_has_subtree() using early_memremap() so arm64 map_mem()
enables boot carveout handling on KHO boots only when an "extmem"
subtree is present.
- Before kho_memory_init_early() runs kho_discover_noprsrv(), validate
the preserved table against mappable RAM and each region's bounds
against mappable RAM above 4 GiB, then remove revived ranges from
memblock via extmem_commit_regions().
- Ignore extmem= with a warning on KHO boots that have no preserved
"extmem" subtree instead of carving out of KHO bootmem or failing
under kho_noprsrv_only.
Signed-off-by: Suseendran Bhaskaran <suseendranb@google.com>
---
.../admin-guide/kernel-parameters.txt | 2 +
Documentation/core-api/kho/abi.rst | 5 +
MAINTAINERS | 3 +-
arch/arm64/mm/mmu.c | 4 +-
include/linux/extmem.h | 8 +
include/linux/kexec_handover.h | 6 +
include/linux/kho/abi/extmem.h | 55 +++++
kernel/liveupdate/kexec_handover.c | 31 +++
mm/Kconfig | 3 +-
mm/Makefile | 3 +
mm/extmem.c | 33 +--
mm/extmem.h | 29 +++
mm/extmem_kho.c | 188 ++++++++++++++++++
13 files changed, 353 insertions(+), 17 deletions(-)
create mode 100644 include/linux/kho/abi/extmem.h
create mode 100644 mm/extmem.h
create mode 100644 mm/extmem_kho.c
diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
index d25265bb0095..6c1738c3828d 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -1713,6 +1713,8 @@ Kernel parameters
"max" carves all aligned memory above <keep_size> and
4 GiB (or all memory above 4 GiB on an explicit
secondary node <nid> > 0).
+ When CONFIG_KEXEC_HANDOVER=y is active, carved regions
+ and alignments are preserved across KHO kexec.
failslab=
fail_usercopy=
diff --git a/Documentation/core-api/kho/abi.rst b/Documentation/core-api/kho/abi.rst
index edeb5b311963..e05e3eab8869 100644
--- a/Documentation/core-api/kho/abi.rst
+++ b/Documentation/core-api/kho/abi.rst
@@ -33,6 +33,11 @@ KHO serialization block ABI
.. kernel-doc:: include/linux/kho/abi/block.h
+extmem preservation ABI
+=======================
+
+.. kernel-doc:: include/linux/kho/abi/extmem.h
+
See Also
========
diff --git a/MAINTAINERS b/MAINTAINERS
index 306707fdfd68..3cf834dc15ed 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -17567,7 +17567,8 @@ M: Suseendran Bhaskaran <suseendranb@google.com>
L: linux-mm@kvack.org
S: Maintained
F: include/linux/extmem.h
-F: mm/extmem.c
+F: include/linux/kho/abi/extmem.h
+F: mm/extmem*
MEMORY MANAGEMENT - GUP (GET USER PAGES)
M: David Hildenbrand <david@kernel.org>
diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c
index e99c8b21f603..5e6acfee1994 100644
--- a/arch/arm64/mm/mmu.c
+++ b/arch/arm64/mm/mmu.c
@@ -10,6 +10,7 @@
#include <linux/export.h>
#include <linux/kernel.h>
#include <linux/errno.h>
+#include <linux/extmem.h>
#include <linux/init.h>
#include <linux/ioport.h>
#include <linux/kexec.h>
@@ -1209,7 +1210,8 @@ static void __init map_mem(void)
linear_map_requires_bbml3 = !force_pte_mapping() && can_set_direct_map();
if (force_pte_mapping() ||
- (linear_map_boot_unmap && !cpu_supports_bbml3()))
+ ((linear_map_boot_unmap || extmem_kho_early_active()) &&
+ !cpu_supports_bbml3()))
flags |= NO_BLOCK_MAPPINGS | NO_CONT_MAPPINGS;
/*
diff --git a/include/linux/extmem.h b/include/linux/extmem.h
index 88fde6f26e64..32e8f852e89b 100644
--- a/include/linux/extmem.h
+++ b/include/linux/extmem.h
@@ -2,6 +2,8 @@
#ifndef _LINUX_EXTMEM_H
#define _LINUX_EXTMEM_H
+#include <linux/types.h>
+
#ifdef CONFIG_EXTMEM
void extmem_init(void);
void extmem_unmap_regions(void);
@@ -10,4 +12,10 @@ static inline void extmem_init(void) { }
static inline void extmem_unmap_regions(void) { }
#endif
+#if defined(CONFIG_EXTMEM) && defined(CONFIG_KEXEC_HANDOVER)
+bool extmem_kho_early_active(void);
+#else
+static inline bool extmem_kho_early_active(void) { return false; }
+#endif
+
#endif /* _LINUX_EXTMEM_H */
diff --git a/include/linux/kexec_handover.h b/include/linux/kexec_handover.h
index ef2b188c8ed0..692a159d1b1c 100644
--- a/include/linux/kexec_handover.h
+++ b/include/linux/kexec_handover.h
@@ -32,6 +32,7 @@ void *kho_restore_vmalloc(const struct kho_vmalloc *preservation);
int kho_add_subtree(const char *name, void *blob, size_t size);
void kho_remove_subtree(void *blob);
int kho_retrieve_subtree(const char *name, phys_addr_t *phys, size_t *size);
+bool kho_early_has_subtree(const char *name);
void kho_memory_init(void);
void kho_memory_init_early(void);
@@ -118,6 +119,11 @@ static inline int kho_retrieve_subtree(const char *name, phys_addr_t *phys,
return -EOPNOTSUPP;
}
+static inline bool kho_early_has_subtree(const char *name)
+{
+ return false;
+}
+
static inline void kho_memory_init(void) { }
static inline void kho_memory_init_early(void) { }
diff --git a/include/linux/kho/abi/extmem.h b/include/linux/kho/abi/extmem.h
new file mode 100644
index 000000000000..513db284897a
--- /dev/null
+++ b/include/linux/kho/abi/extmem.h
@@ -0,0 +1,55 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Copyright (c) 2026, Google LLC.
+ */
+
+#ifndef _LINUX_KHO_ABI_EXTMEM_H
+#define _LINUX_KHO_ABI_EXTMEM_H
+
+#include <linux/build_bug.h>
+#include <linux/types.h>
+
+/**
+ * DOC: extmem kexec handover ABI
+ *
+ * The "extmem" KHO subtree preserves boot-carved external memory ranges across
+ * kexec so the target kernel removes the same physical ranges from memblock
+ * before page-allocator setup. Payload memory is omitted from KHO's preserved
+ * page radix tree; only &struct kho_extmem_ser is preserved. Any incompatible
+ * layout change requires bumping %KHO_EXTMEM_VERSION.
+ */
+
+#define EXTMEM_KHO_ENTRY_NAME "extmem"
+#define KHO_EXTMEM_VERSION 1
+
+/**
+ * struct kho_extmem_region_ser - Serialized descriptor for one extmem region
+ * @base: Physical start address
+ * @size: Size in bytes
+ * @nid: Target NUMA node ID
+ * @align_shift: Base-2 logarithm of region alignment in bytes
+ */
+struct kho_extmem_region_ser {
+ u64 base;
+ u64 size;
+ s32 nid;
+ u32 align_shift;
+};
+
+static_assert(sizeof(struct kho_extmem_region_ser) == 24);
+
+/**
+ * struct kho_extmem_ser - Root header for the "extmem" KHO subtree
+ * @version: ABI version (%KHO_EXTMEM_VERSION)
+ * @nr_regions: Number of entries in @regions
+ * @regions: Serialized region descriptors
+ */
+struct kho_extmem_ser {
+ u32 version;
+ u32 nr_regions;
+ struct kho_extmem_region_ser regions[];
+};
+
+static_assert(sizeof(struct kho_extmem_ser) == 8);
+
+#endif /* _LINUX_KHO_ABI_EXTMEM_H */
diff --git a/kernel/liveupdate/kexec_handover.c b/kernel/liveupdate/kexec_handover.c
index 42c6609a1766..9eb78e994d93 100644
--- a/kernel/liveupdate/kexec_handover.c
+++ b/kernel/liveupdate/kexec_handover.c
@@ -98,6 +98,7 @@ static struct kho_out kho_out = {
struct kho_in {
phys_addr_t fdt_phys;
+ u64 fdt_len;
phys_addr_t bootmem_phys;
char previous_release[__NEW_UTS_LEN + 1];
u32 kexec_count;
@@ -1694,6 +1695,35 @@ int kho_retrieve_subtree(const char *name, phys_addr_t *phys, size_t *size)
}
EXPORT_SYMBOL_GPL(kho_retrieve_subtree);
+/**
+ * kho_early_has_subtree - check if a preserved sub-blob exists early
+ * @name: the name of the sub-blob passed to kho_add_subtree().
+ *
+ * Inspects the incoming KHO FDT via early_memremap() before the linear map is
+ * established. May only be called after kho_populate() while early_memremap()
+ * is active.
+ *
+ * Return: true if a subnode named @name exists in the KHO FDT, false otherwise
+ */
+bool __init kho_early_has_subtree(const char *name)
+{
+ void *fdt;
+ int offset = -ENOENT;
+
+ if (!is_kho_boot() || kho_in.fdt_len < sizeof(struct fdt_header))
+ return false;
+
+ fdt = early_memremap(kho_in.fdt_phys, kho_in.fdt_len);
+ if (!fdt)
+ return false;
+
+ if (fdt_totalsize(fdt) <= kho_in.fdt_len)
+ offset = fdt_subnode_offset(fdt, 0, name);
+ early_memunmap(fdt, kho_in.fdt_len);
+
+ return offset >= 0;
+}
+
static void __init kho_mem_retrieve(void)
{
const struct kho_radix_walk_cb cb = {
@@ -2034,6 +2064,7 @@ void __init kho_populate(phys_addr_t fdt_phys, u64 fdt_len,
memblock_set_kho_noprsrv_only();
kho_in.fdt_phys = fdt_phys;
+ kho_in.fdt_len = fdt_len;
kho_in.bootmem_phys = bootmem_phys;
kho_bootmem_cnt = bootmem_cnt;
diff --git a/mm/Kconfig b/mm/Kconfig
index 95dfdd192909..3f4c0cc536fe 100644
--- a/mm/Kconfig
+++ b/mm/Kconfig
@@ -1546,6 +1546,7 @@ config EXTMEM
Allow carving out NUMA-aware, section- or huge-page-aligned
physical memory regions at boot via the "extmem=" kernel command
line parameter and exposing them as "extmem" platform devices
- carrying memory-region metadata and IORESOURCE_MEM resources.
+ carrying memory-region metadata and IORESOURCE_MEM resources,
+ with Kexec HandOver (KHO) preservation across kexec.
endmenu
diff --git a/mm/Makefile b/mm/Makefile
index 0542953db072..98ed50761d7a 100644
--- a/mm/Makefile
+++ b/mm/Makefile
@@ -152,3 +152,6 @@ obj-$(CONFIG_LAZY_MMU_MODE_KUNIT_TEST) += tests/lazy_mmu_mode_kunit.o
obj-$(CONFIG_VMSTAT_KUNIT_TEST) += tests/vmstat_kunit.o
obj-$(CONFIG_MEM_ALLOC_PROFILING) += alloc_tag.o
obj-$(CONFIG_EXTMEM) += extmem.o
+ifdef CONFIG_EXTMEM
+obj-$(CONFIG_KEXEC_HANDOVER) += extmem_kho.o
+endif
diff --git a/mm/extmem.c b/mm/extmem.c
index e5be9fcb6bbd..7e1bd3d2a511 100644
--- a/mm/extmem.c
+++ b/mm/extmem.c
@@ -13,6 +13,7 @@
#include <linux/extmem.h>
#include <linux/init.h>
#include <linux/ioport.h>
+#include <linux/kexec_handover.h>
#include <linux/kernel.h>
#include <linux/limits.h>
#include <linux/log2.h>
@@ -29,10 +30,10 @@
#include <linux/sizes.h>
#include <linux/string.h>
+#include "extmem.h"
#include "mm_init.h"
#define EXTMEM_MAX_RANGES 8
-#define EXTMEM_MAX_REGIONS 64
#define EXTMEM_MIN_ALIGN BIT_ULL(SECTION_SIZE_BITS)
#define EXTMEM_ALL_NODES MAX_NUMNODES
@@ -43,18 +44,11 @@ struct extmem_rule {
phys_addr_t keep;
};
-struct extmem_region {
- phys_addr_t base;
- phys_addr_t size;
- phys_addr_t align;
- int nid;
-};
-
static struct extmem_rule extmem_rules[EXTMEM_MAX_REGIONS] __initdata;
static unsigned int extmem_nr_rules __initdata;
-static struct extmem_region extmem_regions[EXTMEM_MAX_REGIONS] __initdata;
-static unsigned int extmem_nr_regions __initdata;
+struct extmem_region extmem_regions[EXTMEM_MAX_REGIONS] __initdata;
+unsigned int extmem_nr_regions __initdata;
/*
* Parse [<nid>|all:]<size|max>[:<align>][:keep=<keep_size>]
@@ -158,7 +152,7 @@ static int __init early_extmem(char *p)
* so early page tables stay in low RAM rather than fragmenting the
* top of a NUMA node before extmem_init() runs.
*/
- if (extmem_nr_rules) {
+ if (extmem_nr_rules && !is_kho_boot()) {
memblock_set_bottom_up(true);
arch_boot_carveout_enable();
}
@@ -185,7 +179,7 @@ static int __init extmem_find_keep_end(int nid, phys_addr_t keep,
return -ENOSPC;
}
-static int __init extmem_commit_regions(unsigned int nr, const char *verb)
+int __init extmem_commit_regions(unsigned int nr, const char *verb)
{
struct extmem_region *regs = &extmem_regions[extmem_nr_regions];
struct memblock_region *r;
@@ -294,14 +288,24 @@ static void __init extmem_carve_node(int nid, const struct extmem_rule *rule)
void __init extmem_init(void)
{
- unsigned long orig_end_pfn, new_end_pfn;
+ unsigned long orig_end_pfn = PFN_DOWN(memblock_end_of_DRAM());
+ unsigned long new_end_pfn;
unsigned int i, j;
int nid;
+ /*
+ * Must run before kho_memory_init_early() so revived extmem regions
+ * are removed from memblock before kho_discover_noprsrv() scans it.
+ */
+ if (is_kho_boot()) {
+ if (extmem_kho_revive() == -ENOENT && extmem_nr_rules)
+ pr_warn("ignoring extmem= on KHO boot without preserved state\n");
+ goto refresh_end;
+ }
+
if (!extmem_nr_rules)
return;
- orig_end_pfn = PFN_DOWN(memblock_end_of_DRAM());
memblock_set_bottom_up(false);
for (i = 0; i < extmem_nr_rules; i++) {
@@ -329,6 +333,7 @@ void __init extmem_init(void)
}
}
+refresh_end:
if (!extmem_nr_regions)
return;
new_end_pfn = PFN_DOWN(memblock_end_of_DRAM());
diff --git a/mm/extmem.h b/mm/extmem.h
new file mode 100644
index 000000000000..d73f3729745f
--- /dev/null
+++ b/mm/extmem.h
@@ -0,0 +1,29 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef __MM_EXTMEM_INTERNAL_H
+#define __MM_EXTMEM_INTERNAL_H
+
+#include <linux/errno.h>
+#include <linux/init.h>
+#include <linux/types.h>
+
+#define EXTMEM_MAX_REGIONS 64
+
+struct extmem_region {
+ phys_addr_t base;
+ phys_addr_t size;
+ phys_addr_t align;
+ int nid;
+};
+
+extern struct extmem_region extmem_regions[EXTMEM_MAX_REGIONS] __initdata;
+extern unsigned int extmem_nr_regions __initdata;
+
+int extmem_commit_regions(unsigned int nr, const char *verb);
+
+#ifdef CONFIG_KEXEC_HANDOVER
+int extmem_kho_revive(void);
+#else
+static inline int extmem_kho_revive(void) { return -EOPNOTSUPP; }
+#endif
+
+#endif /* __MM_EXTMEM_INTERNAL_H */
diff --git a/mm/extmem_kho.c b/mm/extmem_kho.c
new file mode 100644
index 000000000000..53d83fd8b84c
--- /dev/null
+++ b/mm/extmem_kho.c
@@ -0,0 +1,188 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Kexec HandOver (KHO) preservation for external memory (extmem) regions.
+ */
+
+#define pr_fmt(fmt) "extmem: " fmt
+
+#include <linux/align.h>
+#include <linux/bits.h>
+#include <linux/err.h>
+#include <linux/extmem.h>
+#include <linux/init.h>
+#include <linux/kexec_handover.h>
+#include <linux/kho/abi/extmem.h>
+#include <linux/log2.h>
+#include <linux/memblock.h>
+#include <linux/mm.h>
+#include <linux/mmzone.h>
+#include <linux/numa.h>
+#include <linux/overflow.h>
+#include <linux/printk.h>
+#include <linux/sizes.h>
+
+#include "extmem.h"
+
+static_assert(struct_size_t(struct kho_extmem_ser, regions,
+ EXTMEM_MAX_REGIONS) <= PAGE_SIZE);
+
+static phys_addr_t extmem_kho_in_ser_phys __initdata;
+
+bool __init extmem_kho_early_active(void)
+{
+ return kho_early_has_subtree(EXTMEM_KHO_ENTRY_NAME);
+}
+
+static bool __init extmem_kho_is_ram(phys_addr_t base, phys_addr_t size)
+{
+ phys_addr_t end, rstart, rend;
+ u64 i;
+
+ if (!size || check_add_overflow(base, size, &end))
+ return false;
+
+ __for_each_mem_range(i, &memblock.memory, NULL, NUMA_NO_NODE,
+ MEMBLOCK_HOTPLUG, &rstart, &rend, NULL) {
+ if (rstart > base)
+ break;
+ base = max(base, rend);
+ if (base >= end)
+ return true;
+ }
+
+ return false;
+}
+
+static int __init extmem_kho_validate_region(const struct kho_extmem_ser *ser,
+ unsigned int idx,
+ phys_addr_t ser_phys)
+{
+ const struct kho_extmem_region_ser *r = &ser->regions[idx];
+ u64 base = r->base, size = r->size;
+ unsigned int j;
+
+ if (r->align_shift < SECTION_SIZE_BITS ||
+ r->align_shift >= sizeof(phys_addr_t) * BITS_PER_BYTE ||
+ (r->nid != NUMA_NO_NODE && (r->nid < 0 || r->nid >= MAX_NUMNODES)))
+ return -EINVAL;
+
+ if (base < SZ_4G || !IS_ALIGNED(base | size, BIT_ULL(r->align_shift)) ||
+ !extmem_kho_is_ram(base, size))
+ return -EINVAL;
+ if (memblock_addrs_overlap(base, size, ser_phys, PAGE_SIZE) ||
+ memblock_is_region_reserved(base, size))
+ return -EBUSY;
+
+ for (j = 0; j < idx; j++) {
+ if (memblock_addrs_overlap(base, size, ser->regions[j].base,
+ ser->regions[j].size))
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
+/*
+ * Runs before kho_memory_init_early() -> kho_discover_noprsrv() so revived
+ * extmem ranges are removed from memblock before KHO marks unpreserved RAM as
+ * MEMBLOCK_KHO_NOPRSRV.
+ */
+int __init extmem_kho_revive(void)
+{
+ const struct kho_extmem_ser *ser;
+ phys_addr_t ser_phys;
+ size_t blob_size;
+ unsigned int i;
+ int err;
+
+ err = kho_retrieve_subtree(EXTMEM_KHO_ENTRY_NAME, &ser_phys,
+ &blob_size);
+ if (err == -ENOENT)
+ return -ENOENT;
+ if (err) {
+ pr_warn_once("failed to retrieve KHO subtree: %pe\n",
+ ERR_PTR(err));
+ return err;
+ }
+
+ if (!ser_phys || !PAGE_ALIGNED(ser_phys) || blob_size < sizeof(*ser) ||
+ blob_size > struct_size(ser, regions, EXTMEM_MAX_REGIONS) ||
+ !extmem_kho_is_ram(ser_phys, PAGE_SIZE)) {
+ err = -EINVAL;
+ goto err_warn;
+ }
+
+ ser = phys_to_virt(ser_phys);
+ if (ser->version != KHO_EXTMEM_VERSION || !ser->nr_regions ||
+ blob_size != struct_size(ser, regions, ser->nr_regions)) {
+ err = -EINVAL;
+ goto err_warn;
+ }
+
+ extmem_kho_in_ser_phys = ser_phys;
+
+ for (i = 0; i < ser->nr_regions; i++) {
+ err = extmem_kho_validate_region(ser, i, ser_phys);
+ if (err)
+ goto err_warn;
+
+ extmem_regions[i] = (struct extmem_region) {
+ .base = ser->regions[i].base,
+ .size = ser->regions[i].size,
+ .align = BIT_ULL(ser->regions[i].align_shift),
+ .nid = ser->regions[i].nid,
+ };
+ }
+
+ err = extmem_commit_regions(ser->nr_regions, "KHO revived");
+ if (err)
+ goto err_warn;
+
+ return 0;
+
+err_warn:
+ pr_warn_once("invalid KHO subtree: %pe\n", ERR_PTR(err));
+ return err;
+}
+
+static int __init extmem_kho_init(void)
+{
+ struct kho_extmem_ser *ser;
+ unsigned int i;
+ size_t size;
+ int err;
+
+ if (extmem_kho_in_ser_phys && is_kho_boot())
+ kho_restore_free(phys_to_virt(extmem_kho_in_ser_phys));
+
+ if (!kho_is_enabled() || !extmem_nr_regions)
+ return 0;
+
+ size = struct_size(ser, regions, extmem_nr_regions);
+ ser = kho_alloc_preserve(size);
+ if (IS_ERR(ser)) {
+ pr_err("failed to allocate KHO buffer: %pe\n", ser);
+ return PTR_ERR(ser);
+ }
+
+ ser->version = KHO_EXTMEM_VERSION;
+ ser->nr_regions = extmem_nr_regions;
+ for (i = 0; i < extmem_nr_regions; i++) {
+ ser->regions[i] = (struct kho_extmem_region_ser) {
+ .base = extmem_regions[i].base,
+ .size = extmem_regions[i].size,
+ .nid = extmem_regions[i].nid,
+ .align_shift = ilog2(extmem_regions[i].align),
+ };
+ }
+
+ err = kho_add_subtree(EXTMEM_KHO_ENTRY_NAME, ser, size);
+ if (err) {
+ pr_err("failed to register KHO subtree: %pe\n", ERR_PTR(err));
+ kho_unpreserve_free(ser);
+ return err;
+ }
+
+ return 0;
+}
+late_initcall(extmem_kho_init);
^ permalink raw reply related [flat|nested] 14+ messages in thread
* Re: [RFC PATCH 00/11] mm: NUMA-aware boot memory carving (extmem)
2026-12-02 0:19 [RFC PATCH 00/11] mm: NUMA-aware boot memory carving (extmem) Suseendran Bhaskaran
` (10 preceding siblings ...)
2026-12-02 0:19 ` [RFC PATCH 11/11] mm/extmem: preserve carved regions across KHO kexec Suseendran Bhaskaran
@ 2026-12-02 14:45 ` Mike Rapoport
2026-12-02 15:10 ` David Hildenbrand (Arm)
11 siblings, 1 reply; 14+ messages in thread
From: Mike Rapoport @ 2026-12-02 14:45 UTC (permalink / raw)
To: Suseendran Bhaskaran
Cc: Andrew Morton, Dan Williams, David Hildenbrand, 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,
linux-arm-kernel, linux-cxl, linux-doc, linux-kernel, linux-mm,
nvdimm, x86
Hi Suseendran,
On Wed, Dec 02, 2026 at 12:19:35AM +0000, Suseendran Bhaskaran wrote:
> Many server workloads need a portable, NUMA-aware way to carve out large
> aligned regions of DRAM at boot -- keeping only a modest pool of System
> RAM per NUMA node for the host kernel while handing the rest off to
> external memory consumers outside the buddy allocator and boot vmemmap.
> Common use cases include character DAX (/dev/daxX.Y) backing guest VMs
> across KHO live updates, /dev/pmemX block devices backing fsdax
> filesystems, and other driver-managed memory pools.
>
> Today there is no portable way to establish that split at boot across
> x86_64 and arm64:
>
> - EFI_MEMORY_SP ("Soft Reserved") requires per-host firmware setup, is
> absent on arm64 DeviceTree, and defaults in dax_hmem to routing via
> dax_kmem (where onlining overwrites backed VM memory across KHO kexec).
> - memmap=nn!ss is x86-only and ignores NUMA topology and firmware holes.
> For example, booting a 2-node x86_64 host (512 GiB total, 256 GiB per
> node) with memmap=448G!64G leaves NUMA node 1 with 0 kB of System RAM.
> - cma=, hugetlb_cma=, and reserve_mem= keep pages in System RAM, paying
> ~16 MiB/GiB of boot struct page arrays upfront and preventing
> ZONE_DEVICE or driver-managed attachment.
> - Runtime memory offlining cannot guarantee 1 GiB physical contiguity
> after early allocations (and boot RAM cannot be offlined on arm64).
>
> Design
> ------
> This series adds CONFIG_EXTMEM and a single boot parameter:
> extmem=[<nid>|all:]<size|max>[:<align>][:keep=<size>][,...]
>
> <nid>|all target node, every node with RAM, or any node if omitted
> <size|max> bytes to carve (multiple of <align>), or "max" for all
> available aligned RAM above 4 GiB and keep=<size>
> <align> power-of-two alignment >= section size (default: 128M on
> 4K/16K pages, 512M on 64K pages)
> keep=<size> minimum System RAM to leave uncarved on the target node(s)
I agree that we need a generic way to define memory carve-outs, but I doubt
that a command line parameter is the way to go.
> The idea of extmem= is a software-defined, NUMA-aware counterpart to EFI
> Soft Reserved memory that feeds existing DAX and libnvdimm drivers rather
> than introducing a workload-specific allocator:
>
> 1. Early boot switches pre-NUMA allocations bottom-up (and prefers
> cold-boot x86_64 physical KASLR slots below 4 GiB), then carves
> aligned ranges per NUMA node right after SRAT/DT parsing -- before
> NODE_DATA, vmemmap, or KASAN shadow allocation -- leaving at least
> keep=<size> of System RAM on each node.
> 2. Before SMP bringup, carved ranges are unmapped from the direct/linear
> map so runtime ZONE_DEVICE mapping and hotplug work unchanged.
That sounds backwards to me. These ranges should not be mapped from the
start.
> 3. Each carved range is split out of System RAM in /proc/iomem and
> published as a neutral "extmem" platform device:
> - dax_hmem binds it by default as device_dax (honoring 1 GiB PUD or
> 2 MiB PMD alignment without zeroing memory; dax_hmem.region_idle=1
> leaves the DAX region unallocated for daxctl reconfiguration).
> - Alternatively, unbinding hmem and binding ramdax via driver_override
> exposes /dev/pmemX block devices for fsdax filesystems.
> 4. Across KHO kexec, extmem preserves its region table in a small KHO
> subtree and revives the exact same physical ranges before
> kho_memory_init_early() marks unpreserved RAM allocatable.
>
> Series layout (11 patches)
> --------------------------
> - Patches 1-2: Fix 4 GiB clamping and memblock flag handling in
> multi-range CMA search, then factor that range picker into memblock
> so CMA and extmem share one implementation (plus memblock tests).
> - Patches 3-4: Pre-SMP direct/linear-map unmap helpers on x86_64 and
> arm64.
> - Patch 5: Core extmem= parser, per-node carving, /proc/iomem split,
> and "extmem" platform device registration.
> - Patch 6: dax_hmem binding for "extmem" devices with per-region
> alignment.
> - Patches 7-9: Fix ramdax devres teardown and probe validation, then
> support binding "extmem" devices via driver_override.
> - Patch 10: Keep cold-boot x86_64 physical KASLR below 4 GiB when
> extmem= is set.
> - Patch 11: KHO kexec preservation and revival for carved regions.
>
> Note on staging: patches 1, 7, and 8 are self-contained prerequisite
> bugfixes included here so the RFC applies and runs cleanly as one series;
> happy to send them separately for review if that is preferred.
>
> Validation
> ----------
> Tested on akpm/mm-new (872ceec1e3ca) + this series with zero kernel
> warnings on bare-metal x86_64 (2-socket, 240-CPU Xeon Platinum 8581C,
> 768 GiB total, 2 NUMA nodes) and arm64 (64-CPU Ampere Altra, 256 GiB):
>
> - Carving and vmemmap savings (extmem=all:max:1G:keep=32G):
> * x86_64: carved 701 GiB (350 + 351 GiB), retaining 33.1 / 32.3 GiB
> System RAM per node; boot reserved memory dropped 12.20 -> 1.25 GiB.
> * arm64: carved 223 GiB; boot reserved memory dropped 4.84 -> 1.03 GiB.
> - Direct/linear-map unmap and alignment:
> * On x86_64, unbinding hmem (or booting with dax_hmem.region_idle=1)
> dropped DirectMap1G by exactly 701 GiB; a 32 GiB, 128 MiB-aligned
> carveout straddling 1 GiB boundaries dropped 31 GiB DirectMap1G +
> 1 GiB DirectMap2M with zero 4 KiB fragmentation.
> * dax_hmem enforced 1 GiB PUD alignment on x86_64 and capped to 2 MiB
> PMD on arm64; hugetlb_cma=2G coexisted cleanly on both.
> - Driver handoff and KHO kexec:
> * Verified hmem <-> ramdax switching (ext4 -o dax=always on /dev/pmemX)
> and bare-metal KHO kexec byte-for-byte preservation on both
> architectures.
>
> Example output on the 2-node x86_64 host with extmem=all:max:1G:keep=32G:
>
> dmesg:
> extmem: carved [0x00000008c0000000-0x000000603fffffff] (358400 MiB) on node 0
> extmem: carved [0x0000006880000000-0x000000c03fffffff] (359424 MiB) on node 1
>
> /proc/iomem (above 4 GiB):
> 100000000-8bfffffff : System RAM
> 8c0000000-603fffffff : External Memory
> 8c0000000-603fffffff : dax0.0
> 6040000000-6075ffffff : System RAM
> 6080000000-687fffffff : System RAM
> 6880000000-c03fffffff : External Memory
> 6880000000-c03fffffff : dax1.0
> c040000000-c077ffffff : System RAM
>
> Things I would like feedback on:
> --------------------------------
>
> 1. Driver binding: extmem registers neutral "extmem" platform devices
> matched by dax_hmem by default and claimable by ramdax via
> driver_override (like e820_pmem and pmem-region). Does this match
> DAX/nvdimm expectations?
> 2. Direct map lifecycle: patches 3-4 unmap carved ranges pre-SMP so
> runtime arch_add_memory() / arch_remove_memory() stay untouched. Do
> x86 and arm64 maintainers prefer this over teaching runtime hotplug
> to split/overwrite boot mappings?
> 3. Syntax and alignment: any concerns with the extmem= syntax or with
> requiring at least sparsemem section alignment (128 MiB on 4K/16K
> pages, 512 MiB on 64K pages)?
> 4. x86_64 physical KASLR: patch 10 prefers cold-boot physical KASLR
> slots below 4 GiB (keeping virtual KASLR unchanged) to avoid
> splitting a node's carved region around a random high kernel
> placement. Would x86 maintainers prefer this, or accepting split
> extmem regions around high KASLR slots?
>
> Based on akpm/mm-new (872ceec1e3ca).
>
> Suseendran Bhaskaran (11):
> mm/cma: clamp multi-range search to 4G and honor memblock flags
> mm/memblock: factor out multi-range contiguous reservation helper from
> CMA
> x86/mm: add early direct-map unmap helpers for boot carveouts
> arm64/mm: support unmapping boot carveouts from the linear map
> mm/extmem: add architecture-neutral external memory subsystem
> dax/hmem: bind extmem platform devices with per-region alignment
> nvdimm/ramdax: manage bus and DIMM allocations with devres
> nvdimm/ramdax: harden probe checks and select NUMA_KEEP_MEMINFO
> nvdimm/ramdax: support binding extmem platform devices
> x86/kaslr: avoid placing kernel in carvable high memory when extmem=
> is set
> mm/extmem: preserve carved regions across KHO kexec
>
> .../admin-guide/kernel-parameters.txt | 23 +
> Documentation/core-api/kho/abi.rst | 5 +
> MAINTAINERS | 8 +
> arch/arm64/mm/init.c | 3 +
> arch/arm64/mm/mmu.c | 56 ++-
> arch/x86/boot/compressed/kaslr.c | 30 +-
> arch/x86/mm/init_64.c | 87 ++++
> arch/x86/mm/numa.c | 3 +
> drivers/dax/Kconfig | 2 +-
> drivers/dax/hmem/hmem.c | 27 +-
> drivers/nvdimm/Kconfig | 15 +-
> drivers/nvdimm/ramdax.c | 135 +++---
> include/linux/extmem.h | 21 +
> include/linux/kexec_handover.h | 6 +
> include/linux/kho/abi/extmem.h | 55 +++
> include/linux/memory_hotplug.h | 4 +
> include/linux/memregion.h | 1 +
> kernel/liveupdate/kexec_handover.c | 31 ++
> mm/Kconfig | 12 +
> mm/Makefile | 4 +
> mm/arch_numa.c | 3 +
> mm/cma.c | 102 ++---
> mm/extmem.c | 424 ++++++++++++++++++
> mm/extmem.h | 29 ++
> mm/extmem_kho.c | 188 ++++++++
> mm/memblock.c | 120 +++++
> mm/mm_init.c | 2 +
> mm/mm_init.h | 17 +
> tools/testing/memblock/Makefile | 2 +-
> tools/testing/memblock/main.c | 2 +
> tools/testing/memblock/mm_init.h | 23 +-
> .../testing/memblock/tests/alloc_multi_api.c | 103 +++++
> .../testing/memblock/tests/alloc_multi_api.h | 9 +
> 33 files changed, 1373 insertions(+), 179 deletions(-)
> create mode 100644 include/linux/extmem.h
> create mode 100644 include/linux/kho/abi/extmem.h
> create mode 100644 mm/extmem.c
> create mode 100644 mm/extmem.h
> create mode 100644 mm/extmem_kho.c
> create mode 100644 tools/testing/memblock/tests/alloc_multi_api.c
> create mode 100644 tools/testing/memblock/tests/alloc_multi_api.h
>
>
> base-commit: 872ceec1e3caf227655a58f7407a9c8493dcf56f
--
Sincerely yours,
Mike.
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [RFC PATCH 00/11] mm: NUMA-aware boot memory carving (extmem)
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)
0 siblings, 0 replies; 14+ messages in thread
From: David Hildenbrand (Arm) @ 2026-12-02 15:10 UTC (permalink / raw)
To: Mike Rapoport, Suseendran Bhaskaran
Cc: Andrew Morton, Dan Williams, 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, linux-arm-kernel, linux-cxl, linux-doc,
linux-kernel, linux-mm, nvdimm, x86
On 12/2/26 15:45, Mike Rapoport wrote:
> Hi Suseendran,
>
> On Wed, Dec 02, 2026 at 12:19:35AM +0000, Suseendran Bhaskaran wrote:
>> Many server workloads need a portable, NUMA-aware way to carve out large
>> aligned regions of DRAM at boot -- keeping only a modest pool of System
>> RAM per NUMA node for the host kernel while handing the rest off to
>> external memory consumers outside the buddy allocator and boot vmemmap.
>> Common use cases include character DAX (/dev/daxX.Y) backing guest VMs
>> across KHO live updates, /dev/pmemX block devices backing fsdax
>> filesystems, and other driver-managed memory pools.
>>
>> Today there is no portable way to establish that split at boot across
>> x86_64 and arm64:
>>
>> - EFI_MEMORY_SP ("Soft Reserved") requires per-host firmware setup, is
>> absent on arm64 DeviceTree, and defaults in dax_hmem to routing via
>> dax_kmem (where onlining overwrites backed VM memory across KHO kexec).
>> - memmap=nn!ss is x86-only and ignores NUMA topology and firmware holes.
>> For example, booting a 2-node x86_64 host (512 GiB total, 256 GiB per
>> node) with memmap=448G!64G leaves NUMA node 1 with 0 kB of System RAM.
>> - cma=, hugetlb_cma=, and reserve_mem= keep pages in System RAM, paying
>> ~16 MiB/GiB of boot struct page arrays upfront and preventing
>> ZONE_DEVICE or driver-managed attachment.
>> - Runtime memory offlining cannot guarantee 1 GiB physical contiguity
>> after early allocations (and boot RAM cannot be offlined on arm64).
>>
>> Design
>> ------
>> This series adds CONFIG_EXTMEM and a single boot parameter:
>> extmem=[<nid>|all:]<size|max>[:<align>][:keep=<size>][,...]
>>
>> <nid>|all target node, every node with RAM, or any node if omitted
>> <size|max> bytes to carve (multiple of <align>), or "max" for all
>> available aligned RAM above 4 GiB and keep=<size>
>> <align> power-of-two alignment >= section size (default: 128M on
>> 4K/16K pages, 512M on 64K pages)
>> keep=<size> minimum System RAM to leave uncarved on the target node(s)
>
> I agree that we need a generic way to define memory carve-outs, but I doubt
> that a command line parameter is the way to go.
+1
And I am also not convinced that we want more of special+weird core-mm
infrastructure KHO for ("mm/extmem: preserve carved regions across KHO kexec").
--
Cheers,
David
^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2026-12-02 15:36 UTC | newest]
Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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-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-02 14:45 ` [RFC PATCH 00/11] mm: NUMA-aware boot memory carving (extmem) Mike Rapoport
2026-12-02 15:10 ` David Hildenbrand (Arm)
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox