[RFC PATCH 06/11] dax/hmem: bind extmem platform devices with per-region alignment

From: Suseendran Bhaskaran

Date: Tue Dec 01 2026 - 19:20:34 EST


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@xxxxxxxxxx>
---
.../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 = {