From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 73CC7606A6A2 for ; Wed, 2 Dec 2026 00:20:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=NHv+6AWT; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=piv+T/65 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:Cc:To:From: Subject:Message-ID:Mime-Version:Date:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Unsubscribe-Post:List-Owner; bh=Hv98t1Fb91UVL1RlN+9jTo1Nuc2GltKfxtYHxVzYacU=; b=NHv+6AWT7d57GhIM+3/HXGPmLE A2oT1s9jqHGHJ6M8WXP72xSpLHNYEL5e0Rg539gmXY7jBTduxoSSZD6modySmu/bTqb6r+SLR/C86 HzSWg1tIudfKKNKUchP/V5yqvUqAX7s5X1FN8MoWzkNdYV+kecNpAafjGkwWdUF6PJe4Lqaxw0BkW k/yCzUD9aFABA+Mcf7nXqGl6GtWCzIts+ii6bqLBuVCZrdRT04PE6rS03+KnfXiDfLXpSmXO8TfFn /eu0RnUQ2lZjHfMfOu5e+WZGTtFgBNy42l0Kwz7yhnRnerjIdJJCznC0aCOmHO6L6GiNIiQqOnDcR SDgU/+Gw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYY4q-00000009j62-0lEp; Wed, 02 Dec 2026 00:20:04 +0000 Received: from mail-pf1-x448.google.com ([2607:f8b0:4864:20::448]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYY4l-00000009j50-3YZj for linux-arm-kernel@lists.infradead.org; Wed, 02 Dec 2026 00:20:01 +0000 Received: by mail-pf1-x448.google.com with SMTP id d2e1a72fcca58-8b930598cf0so23964009b3a.1 for ; Tue, 01 Dec 2026 16:19:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796170798; x=1796775598; darn=lists.infradead.org; h=content-type:cc:to:from:subject:message-id:mime-version:date:from :to:cc:subject:date:message-id:reply-to:content-type; bh=Hv98t1Fb91UVL1RlN+9jTo1Nuc2GltKfxtYHxVzYacU=; b=piv+T/65VxnvpbJanoGFFo/PZTvxgRxcKbrZvIsiuCY/OLcCSNWJJ9Hw1Z1P1+hD6w B5TcyhdAY2dzJI64gOPucusjSpnW/fnWvXUG3TCOoOKKyB1tgcF/bQ1G539/DmaxuWY1 GHow8kua3aZacmBnXr7lrsePESuZUMcZem/0X0i/rK2fo1sSX8xf+uLJ24MUw+9OEPrX SyQ8EEyL1JEyeg7jWY2Nw6Rn0k5zmdtl7JvXgJqymye7xZF6njxZqh765HVBHrnmN3Bn S68gtdajAOhRQKOVWDu2cFkRmQytKWsaJHj51jwdrY9dB5zcfSjY5bhhgWEodsxI5+6w TLjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796170798; x=1796775598; h=content-type:cc:to:from:subject:message-id:mime-version:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=Hv98t1Fb91UVL1RlN+9jTo1Nuc2GltKfxtYHxVzYacU=; b=ReKf4QLkMMl122JDRS8zyPMlfOrLx2oy+X69Vi/1REvj+wMjCUWZQA0D+g5raJwFOr 4/lWqg/tz94cQBCjfNNF+3cgkpiSad+V2KrHoj5BXRkTSe1kfvWqDOWGbogHKq30PNVi 5NxMwJ+y9esNsCqsCg6PGc4nEevn8Qic1k4jGlC75esBcG6cZVvcZORo9PeHS5KmZbrH Njf1BVHamGbMqW8fP7mNISFB/dwL9DsdzwORJIKdYHh0/Fn5blK2jaRu5QqJ7TH0ilg9 ai2lkJsBmQnNN7Uneyv/DdnY5BTt82S1MbZKMR6Z5zcJly5ZB0cKXPenpQWEUrTGhYV+ 9BUA== X-Forwarded-Encrypted: i=1; AL+hErENrJ6XXU35BjEf3DhI1SuJN2kEo7s9o4mKtOCS1K1LJ7Mc16GcODqI2iVRg+RhikbT0MrdPi2MJWwADcPnsGx2@lists.infradead.org X-Gm-Message-State: APuU4Z9D9LOxK6kK1ritNWIfjlTwRol6YJKkLP578BZGdiPnRgBUdPCG +i5Qu8RBNgTRqsKsdlWfEUxv7+lIDfhfLjtQJkTNzBWon84WfErNranm1meoBr+MFDEiaXHdh40 Hi74DhBkSWTvDD8HUE4/5lvc5cg== X-Received: from pfob25.prod.google.com ([2002:aa7:8719:0:b0:8a0:91b7:e7b9]) (user=suseendranb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:493:b0:3db:4e0a:df51 with SMTP id adf61e73a8af0-4014b65da7dmr43226017637.22.1796170798131; Tue, 01 Dec 2026 16:19:58 -0800 (PST) Date: Wed, 2 Dec 2026 00:19:35 +0000 X-Archived-By: Mime-Version: 1.0 X-Mailer: git-send-email 2.56.1.911.g883d8bcb20-goog Message-ID: <20261202001946.1226273-1-suseendranb@google.com> Subject: [RFC PATCH 00/11] mm: NUMA-aware boot memory carving (extmem) From: Suseendran Bhaskaran 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@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-cxl@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, nvdimm@lists.linux.dev, x86@kernel.org, Suseendran Bhaskaran Content-Type: text/plain; charset="UTF-8" X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261201_161959_904090_56746582 X-CRM114-Status: GOOD ( 21.20 ) X-Spam-Score: -9.5 (---------) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" X-Spam-Status: No, score=-21.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIMWL_WL_MED,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 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=[|all:][:][:keep=][,...] |all target node, every node with RAM, or any node if omitted bytes to carve (multiple of ), or "max" for all available aligned RAM above 4 GiB and keep= power-of-two alignment >= section size (default: 128M on 4K/16K pages, 512M on 64K pages) keep= 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= 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