Re: [PATCH v5 7/7] dax/hmem: Reintroduce Soft Reserved ranges back into the iomem tree

From: Koralahalli Channabasappa, Smita

Date: Wed Jan 28 2026 - 17:08:17 EST


On 1/22/2026 8:39 AM, Jonathan Cameron wrote:
On Thu, 22 Jan 2026 04:55:43 +0000
Smita Koralahalli <Smita.KoralahalliChannabasappa@xxxxxxx> wrote:

Reworked from a patch by Alison Schofield <alison.schofield@xxxxxxxxx>

Reintroduce Soft Reserved range into the iomem_resource tree for HMEM
to consume.

This restores visibility in /proc/iomem for ranges actively in use, while
avoiding the early-boot conflicts that occurred when Soft Reserved was
published into iomem before CXL window and region discovery.

Link: https://lore.kernel.org/linux-cxl/29312c0765224ae76862d59a17748c8188fb95f1.1692638817.git.alison.schofield@xxxxxxxxx/
Co-developed-by: Alison Schofield <alison.schofield@xxxxxxxxx>
Signed-off-by: Alison Schofield <alison.schofield@xxxxxxxxx>
Co-developed-by: Zhijian Li <lizhijian@xxxxxxxxxxx>
Signed-off-by: Zhijian Li <lizhijian@xxxxxxxxxxx>
Signed-off-by: Smita Koralahalli <Smita.KoralahalliChannabasappa@xxxxxxx>
Reviewed-by: Dave Jiang <dave.jiang@xxxxxxxxx>
Reviewed-by: Jonathan Cameron <jonathan.cameron@xxxxxxxxxx>
Reviewed-by: Dan Williams <dan.j.williams@xxxxxxxxx>
A few minor things from a fresh read.
---
drivers/dax/hmem/hmem.c | 32 +++++++++++++++++++++++++++++++-
1 file changed, 31 insertions(+), 1 deletion(-)

diff --git a/drivers/dax/hmem/hmem.c b/drivers/dax/hmem/hmem.c
index bcb57d8678d7..f3ef4faf158f 100644
--- a/drivers/dax/hmem/hmem.c
+++ b/drivers/dax/hmem/hmem.c
@@ -64,6 +64,34 @@ struct dax_defer_work {
struct work_struct work;
};
+static void remove_soft_reserved(void *r)
+{
+ remove_resource(r);
+ kfree(r);
+}
+
+static int add_soft_reserve_into_iomem(struct device *host,
+ const struct resource *res)
+{
+ struct resource *soft __free(kfree) =
+ kzalloc(sizeof(*soft), GFP_KERNEL);

On one line. I think it's exactly 80 chars.

+ int rc;
+
The declaration and check should be together. For __free stuff inline declarations
are preferred.

You fully assign it so kmalloc is all that's needed.


struct resource *soft __free(kfree) = kzalloc(sizeof(*soft), GFP_KERNEL);
if (!soft)

If not, just switch the two declarations.

Sure, I will make the changes.

Thanks
Smita

+ if (!soft)
+ return -ENOMEM;
+
+ *soft = DEFINE_RES_NAMED_DESC(res->start, (res->end - res->start + 1),
+ "Soft Reserved", IORESOURCE_MEM,
+ IORES_DESC_SOFT_RESERVED);
+
+ rc = insert_resource(&iomem_resource, soft);
+ if (rc)
+ return rc;
+
+ return devm_add_action_or_reset(host, remove_soft_reserved,
+ no_free_ptr(soft));
+}
+
static int hmem_register_device(struct device *host, int target_nid,
const struct resource *res)
{
@@ -94,7 +122,9 @@ static int hmem_register_device(struct device *host, int target_nid,
if (rc != REGION_INTERSECTS)
return 0;
- /* TODO: Add Soft-Reserved memory back to iomem */
+ rc = add_soft_reserve_into_iomem(host, res);
+ if (rc)
+ return rc;
id = memregion_alloc(GFP_KERNEL);
if (id < 0) {