[PATCH 5/6] dax/hmem: Reintroduce Soft Reserved ranges back into the iomem tree

Smita Koralahalli posted 6 patches 1 month, 1 week ago
There is a newer version of this series
[PATCH 5/6] dax/hmem: Reintroduce Soft Reserved ranges back into the iomem tree
Posted by Smita Koralahalli 1 month, 1 week ago
Reworked from a patch by Alison Schofield <alison.schofield@intel.com>

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.schofield@intel.com/
Co-developed-by: Alison Schofield <alison.schofield@intel.com>
Signed-off-by: Alison Schofield <alison.schofield@intel.com>
Signed-off-by: Smita Koralahalli <Smita.KoralahalliChannabasappa@amd.com>
---
 drivers/dax/hmem/hmem.c | 38 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)

diff --git a/drivers/dax/hmem/hmem.c b/drivers/dax/hmem/hmem.c
index 90978518e5f4..24a6e7e3d916 100644
--- a/drivers/dax/hmem/hmem.c
+++ b/drivers/dax/hmem/hmem.c
@@ -93,6 +93,40 @@ static void process_defer_work(struct work_struct *_work)
 	walk_hmem_resources(&pdev->dev, handle_deferred_cxl);
 }
 
+static void remove_soft_reserved(void *data)
+{
+	struct resource *r = data;
+
+	remove_resource(r);
+	kfree(r);
+}
+
+static int add_soft_reserve_into_iomem(struct device *host,
+				       const struct resource *res)
+{
+	struct resource *soft = 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) {
+		kfree(soft);
+		return rc;
+	}
+
+	rc = devm_add_action_or_reset(host, remove_soft_reserved, soft);
+	if (rc)
+		return rc;
+
+	return 0;
+}
+
 static int hmem_register_device(struct device *host, int target_nid,
 				const struct resource *res)
 {
@@ -125,6 +159,10 @@ static int hmem_register_device(struct device *host, int target_nid,
 					    IORES_DESC_SOFT_RESERVED);
 	if (rc != REGION_INTERSECTS)
 		return 0;
+
+	rc = add_soft_reserve_into_iomem(host, res);
+	if (rc)
+		return rc;
 #else
 	rc = region_intersects(res->start, resource_size(res), IORESOURCE_MEM,
 			       IORES_DESC_SOFT_RESERVED);
-- 
2.17.1
Re: [PATCH 5/6] dax/hmem: Reintroduce Soft Reserved ranges back into the iomem tree
Posted by Jonathan Cameron 3 weeks, 2 days ago
On Fri, 22 Aug 2025 03:42:01 +0000
Smita Koralahalli <Smita.KoralahalliChannabasappa@amd.com> wrote:

> Reworked from a patch by Alison Schofield <alison.schofield@intel.com>
> 
> 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.schofield@intel.com/
> Co-developed-by: Alison Schofield <alison.schofield@intel.com>
> Signed-off-by: Alison Schofield <alison.schofield@intel.com>
> Signed-off-by: Smita Koralahalli <Smita.KoralahalliChannabasappa@amd.com>
A few trivial things inline. Not are important enough to need a change though.

Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com>

> ---
>  drivers/dax/hmem/hmem.c | 38 ++++++++++++++++++++++++++++++++++++++
>  1 file changed, 38 insertions(+)
> 
> diff --git a/drivers/dax/hmem/hmem.c b/drivers/dax/hmem/hmem.c
> index 90978518e5f4..24a6e7e3d916 100644
> --- a/drivers/dax/hmem/hmem.c
> +++ b/drivers/dax/hmem/hmem.c
> @@ -93,6 +93,40 @@ static void process_defer_work(struct work_struct *_work)
>  	walk_hmem_resources(&pdev->dev, handle_deferred_cxl);
>  }
>  
> +static void remove_soft_reserved(void *data)
> +{
> +	struct resource *r = data;
> +
> +	remove_resource(r);

Type doesn't really help us here so why not skip the local variable.
	remove_resource(data);
	kfree(data);

Though I'd rename data to r.

> +	kfree(r);
> +}
> +
> +static int add_soft_reserve_into_iomem(struct device *host,
> +				       const struct resource *res)
> +{
> +	struct resource *soft = 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) {
> +		kfree(soft);

Could use __free() magic here and steal the pointer when you setup the
devm action below.  Only a small simplification in this case, so up to
you.

> +		return rc;
> +	}
> +
> +	rc = devm_add_action_or_reset(host, remove_soft_reserved, soft);
> +	if (rc)
> +		return rc;
> +
> +	return 0;

Trivial:

	return dev_add_action_or_reset(host...)

> +}
Re: [PATCH 5/6] dax/hmem: Reintroduce Soft Reserved ranges back into the iomem tree
Posted by Koralahalli Channabasappa, Smita 3 days, 20 hours ago
Hi Jonathan,

On 9/10/2025 6:41 AM, Jonathan Cameron wrote:
> On Fri, 22 Aug 2025 03:42:01 +0000
> Smita Koralahalli <Smita.KoralahalliChannabasappa@amd.com> wrote:
> 
>> Reworked from a patch by Alison Schofield <alison.schofield@intel.com>
>>
>> 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.schofield@intel.com/
>> Co-developed-by: Alison Schofield <alison.schofield@intel.com>
>> Signed-off-by: Alison Schofield <alison.schofield@intel.com>
>> Signed-off-by: Smita Koralahalli <Smita.KoralahalliChannabasappa@amd.com>
> A few trivial things inline. Not are important enough to need a change though.
> 
> Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com>
> 
>> ---
>>   drivers/dax/hmem/hmem.c | 38 ++++++++++++++++++++++++++++++++++++++
>>   1 file changed, 38 insertions(+)
>>
>> diff --git a/drivers/dax/hmem/hmem.c b/drivers/dax/hmem/hmem.c
>> index 90978518e5f4..24a6e7e3d916 100644
>> --- a/drivers/dax/hmem/hmem.c
>> +++ b/drivers/dax/hmem/hmem.c
>> @@ -93,6 +93,40 @@ static void process_defer_work(struct work_struct *_work)
>>   	walk_hmem_resources(&pdev->dev, handle_deferred_cxl);
>>   }
>>   
>> +static void remove_soft_reserved(void *data)
>> +{
>> +	struct resource *r = data;
>> +
>> +	remove_resource(r);
> 
> Type doesn't really help us here so why not skip the local variable.
> 	remove_resource(data);
> 	kfree(data);
> 
> Though I'd rename data to r.
> 
>> +	kfree(r);

Fixed in v2.

>> +}
>> +
>> +static int add_soft_reserve_into_iomem(struct device *host,
>> +				       const struct resource *res)
>> +{
>> +	struct resource *soft = 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) {
>> +		kfree(soft);
> 
> Could use __free() magic here and steal the pointer when you setup the
> devm action below.  Only a small simplification in this case, so up to
> you.

Sure, I have incorporated.

> 
>> +		return rc;
>> +	}
>> +
>> +	rc = devm_add_action_or_reset(host, remove_soft_reserved, soft);
>> +	if (rc)
>> +		return rc;
>> +
>> +	return 0;
> 
> Trivial:
> 
> 	return dev_add_action_or_reset(host...)

Included.

Thanks,
Smita

> 
>> +}
>
Re: [PATCH 5/6] dax/hmem: Reintroduce Soft Reserved ranges back into the iomem tree
Posted by Dave Jiang 4 weeks, 1 day ago

On 8/21/25 8:42 PM, Smita Koralahalli wrote:
> Reworked from a patch by Alison Schofield <alison.schofield@intel.com>
> 
> 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.schofield@intel.com/
> Co-developed-by: Alison Schofield <alison.schofield@intel.com>
> Signed-off-by: Alison Schofield <alison.schofield@intel.com>
> Signed-off-by: Smita Koralahalli <Smita.KoralahalliChannabasappa@amd.com>

Reviewed-by: Dave Jiang <dave.jiang@intel.com>
> ---
>  drivers/dax/hmem/hmem.c | 38 ++++++++++++++++++++++++++++++++++++++
>  1 file changed, 38 insertions(+)
> 
> diff --git a/drivers/dax/hmem/hmem.c b/drivers/dax/hmem/hmem.c
> index 90978518e5f4..24a6e7e3d916 100644
> --- a/drivers/dax/hmem/hmem.c
> +++ b/drivers/dax/hmem/hmem.c
> @@ -93,6 +93,40 @@ static void process_defer_work(struct work_struct *_work)
>  	walk_hmem_resources(&pdev->dev, handle_deferred_cxl);
>  }
>  
> +static void remove_soft_reserved(void *data)
> +{
> +	struct resource *r = data;
> +
> +	remove_resource(r);
> +	kfree(r);
> +}
> +
> +static int add_soft_reserve_into_iomem(struct device *host,
> +				       const struct resource *res)
> +{
> +	struct resource *soft = 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) {
> +		kfree(soft);
> +		return rc;
> +	}
> +
> +	rc = devm_add_action_or_reset(host, remove_soft_reserved, soft);
> +	if (rc)
> +		return rc;
> +
> +	return 0;
> +}
> +
>  static int hmem_register_device(struct device *host, int target_nid,
>  				const struct resource *res)
>  {
> @@ -125,6 +159,10 @@ static int hmem_register_device(struct device *host, int target_nid,
>  					    IORES_DESC_SOFT_RESERVED);
>  	if (rc != REGION_INTERSECTS)
>  		return 0;
> +
> +	rc = add_soft_reserve_into_iomem(host, res);
> +	if (rc)
> +		return rc;
>  #else
>  	rc = region_intersects(res->start, resource_size(res), IORESOURCE_MEM,
>  			       IORES_DESC_SOFT_RESERVED);