Reworked from a patch by Alison Schofield <[email protected]>
Reintroduce Soft Reserved range into the iomem_resource tree for dax_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.schofi...@intel.com/ Co-developed-by: Alison Schofield <[email protected]> Signed-off-by: Alison Schofield <[email protected]> Co-developed-by: Zhijian Li <[email protected]> Signed-off-by: Zhijian Li <[email protected]> Signed-off-by: Smita Koralahalli <[email protected]> Reviewed-by: Dave Jiang <[email protected]> Reviewed-by: Jonathan Cameron <[email protected]> --- 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 0498cb234c06..9dc6eb15c4d2 100644 --- a/drivers/dax/hmem/hmem.c +++ b/drivers/dax/hmem/hmem.c @@ -93,6 +93,34 @@ static void process_defer_work(struct work_struct *_work) walk_hmem_resources(&pdev->dev, handle_deferred_cxl); } +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); + int rc; + + 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) { @@ -125,7 +153,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) { -- 2.17.1

