[v5,03/17] device-dax/kmem: move resource name tracking to drvdata
diff mbox series

Message ID 160106111639.30709.17624822766862009183.stgit@dwillia2-desk3.amr.corp.intel.com
State Superseded
Headers show
Series
  • device-dax: support sub-dividing soft-reserved ranges
Related show

Commit Message

Dan Williams Sept. 25, 2020, 7:11 p.m. UTC
Towards removing the mode specific @dax_kmem_res attribute from the
generic 'struct dev_dax', and preparing for multi-range support, move
resource name tracking to driver data.  The memory for the resource name
needs to have its own lifetime separate from the device bind lifetime
for cases where the driver is unbound, but the kmem range could not be
unplugged from the page allocator.

Cc: David Hildenbrand <david@redhat.com>
Cc: Vishal Verma <vishal.l.verma@intel.com>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Pavel Tatashin <pasha.tatashin@soleen.com>
Cc: Brice Goglin <Brice.Goglin@inria.fr>
Cc: Dave Jiang <dave.jiang@intel.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: Ira Weiny <ira.weiny@intel.com>
Cc: Jia He <justin.he@arm.com>
Cc: Joao Martins <joao.m.martins@oracle.com>
Cc: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
---
 drivers/dax/kmem.c |   16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

Comments

David Hildenbrand Sept. 30, 2020, 4:19 p.m. UTC | #1
On 25.09.20 21:11, Dan Williams wrote:
> Towards removing the mode specific @dax_kmem_res attribute from the
> generic 'struct dev_dax', and preparing for multi-range support, move
> resource name tracking to driver data.  The memory for the resource name
> needs to have its own lifetime separate from the device bind lifetime
> for cases where the driver is unbound, but the kmem range could not be
> unplugged from the page allocator.
> 
> Cc: David Hildenbrand <david@redhat.com>
> Cc: Vishal Verma <vishal.l.verma@intel.com>
> Cc: Dave Hansen <dave.hansen@linux.intel.com>
> Cc: Pavel Tatashin <pasha.tatashin@soleen.com>
> Cc: Brice Goglin <Brice.Goglin@inria.fr>
> Cc: Dave Jiang <dave.jiang@intel.com>
> Cc: David Hildenbrand <david@redhat.com>
> Cc: Ira Weiny <ira.weiny@intel.com>
> Cc: Jia He <justin.he@arm.com>
> Cc: Joao Martins <joao.m.martins@oracle.com>
> Cc: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> Signed-off-by: Dan Williams <dan.j.williams@intel.com>
> ---
>  drivers/dax/kmem.c |   16 +++++++++-------
>  1 file changed, 9 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/dax/kmem.c b/drivers/dax/kmem.c
> index b0d6a99cf12d..6fe2cb1c5f7c 100644
> --- a/drivers/dax/kmem.c
> +++ b/drivers/dax/kmem.c
> @@ -34,7 +34,7 @@ int dev_dax_kmem_probe(struct device *dev)
>  	struct dev_dax *dev_dax = to_dev_dax(dev);
>  	struct range range = dax_kmem_range(dev_dax);
>  	struct resource *new_res;
> -	const char *new_res_name;
> +	char *res_name;

I wonder why that change ...

>  	int numa_node;
>  	int rc;
>  
> @@ -51,15 +51,15 @@ int dev_dax_kmem_probe(struct device *dev)
>  		return -EINVAL;
>  	}
>  
> -	new_res_name = kstrdup(dev_name(dev), GFP_KERNEL);
> -	if (!new_res_name)
> +	res_name = kstrdup(dev_name(dev), GFP_KERNEL);
> +	if (!res_name)
>  		return -ENOMEM;
>  
>  	/* Region is permanently reserved if hotremove fails. */
> -	new_res = request_mem_region(range.start, range_len(&range), new_res_name);
> +	new_res = request_mem_region(range.start, range_len(&range), res_name);
>  	if (!new_res) {
>  		dev_warn(dev, "could not reserve region [%#llx-%#llx]\n", range.start, range.end);
> -		kfree(new_res_name);
> +		kfree(res_name);
>  		return -EBUSY;
>  	}
>  
> @@ -80,9 +80,11 @@ int dev_dax_kmem_probe(struct device *dev)
>  	if (rc) {
>  		release_resource(new_res);
>  		kfree(new_res);
> -		kfree(new_res_name);
> +		kfree(res_name);
>  		return rc;
>  	}
> +
> +	dev_set_drvdata(dev, res_name);
>  	dev_dax->dax_kmem_res = new_res;
>  
>  	return 0;
> @@ -94,7 +96,7 @@ static int dev_dax_kmem_remove(struct device *dev)
>  	struct dev_dax *dev_dax = to_dev_dax(dev);
>  	struct range range = dax_kmem_range(dev_dax);
>  	struct resource *res = dev_dax->dax_kmem_res;
> -	const char *res_name = res->name;
> +	const char *res_name = dev_get_drvdata(dev);

... because here you're back to "const".

>  	int rc;
>  
>  	/*
> 

I do wonder if it wouldn't all be easier to just have some

struct {
	const char *res_name;
	struct resource *res;
};

allocating that and storing it as drvdata. But let's see what the next
patch brings :)

Patch
diff mbox series

diff --git a/drivers/dax/kmem.c b/drivers/dax/kmem.c
index b0d6a99cf12d..6fe2cb1c5f7c 100644
--- a/drivers/dax/kmem.c
+++ b/drivers/dax/kmem.c
@@ -34,7 +34,7 @@  int dev_dax_kmem_probe(struct device *dev)
 	struct dev_dax *dev_dax = to_dev_dax(dev);
 	struct range range = dax_kmem_range(dev_dax);
 	struct resource *new_res;
-	const char *new_res_name;
+	char *res_name;
 	int numa_node;
 	int rc;
 
@@ -51,15 +51,15 @@  int dev_dax_kmem_probe(struct device *dev)
 		return -EINVAL;
 	}
 
-	new_res_name = kstrdup(dev_name(dev), GFP_KERNEL);
-	if (!new_res_name)
+	res_name = kstrdup(dev_name(dev), GFP_KERNEL);
+	if (!res_name)
 		return -ENOMEM;
 
 	/* Region is permanently reserved if hotremove fails. */
-	new_res = request_mem_region(range.start, range_len(&range), new_res_name);
+	new_res = request_mem_region(range.start, range_len(&range), res_name);
 	if (!new_res) {
 		dev_warn(dev, "could not reserve region [%#llx-%#llx]\n", range.start, range.end);
-		kfree(new_res_name);
+		kfree(res_name);
 		return -EBUSY;
 	}
 
@@ -80,9 +80,11 @@  int dev_dax_kmem_probe(struct device *dev)
 	if (rc) {
 		release_resource(new_res);
 		kfree(new_res);
-		kfree(new_res_name);
+		kfree(res_name);
 		return rc;
 	}
+
+	dev_set_drvdata(dev, res_name);
 	dev_dax->dax_kmem_res = new_res;
 
 	return 0;
@@ -94,7 +96,7 @@  static int dev_dax_kmem_remove(struct device *dev)
 	struct dev_dax *dev_dax = to_dev_dax(dev);
 	struct range range = dax_kmem_range(dev_dax);
 	struct resource *res = dev_dax->dax_kmem_res;
-	const char *res_name = res->name;
+	const char *res_name = dev_get_drvdata(dev);
 	int rc;
 
 	/*