Commit a455aa72 authored by Dan Williams's avatar Dan Williams Committed by Linus Torvalds

device-dax/kmem: fix resource release

The conversion to request_mem_region() is broken because it assumes that
the range is marked busy prior to release.  However, due to the way that
the kmem driver manipulates the IORESOURCE_BUSY flag (clears it to let
{add,remove}_memory() handle busy) it requires a manual release_resource()
to perform cleanup.

Given that the actual 'struct resource *' needs to be recalled, not just
the range, add that tracking to the kmem driver-data.

Fixes: 0513bd5b ("device-dax/kmem: replace release_resource() with release_mem_region()")
Reported-by: default avatarDavid Hildenbrand <david@redhat.com>
Signed-off-by: default avatarDan Williams <dan.j.williams@intel.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Reviewed-by: default avatarDavid 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: 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>
Link: https://lkml.kernel.org/r/160272252925.3136502.17220638073995895400.stgit@dwillia2-desk3.amr.corp.intel.comSigned-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 578a7155
...@@ -35,11 +35,17 @@ static int dax_kmem_range(struct dev_dax *dev_dax, int i, struct range *r) ...@@ -35,11 +35,17 @@ static int dax_kmem_range(struct dev_dax *dev_dax, int i, struct range *r)
return 0; return 0;
} }
struct dax_kmem_data {
const char *res_name;
struct resource *res[];
};
static int dev_dax_kmem_probe(struct dev_dax *dev_dax) static int dev_dax_kmem_probe(struct dev_dax *dev_dax)
{ {
struct device *dev = &dev_dax->dev; struct device *dev = &dev_dax->dev;
struct dax_kmem_data *data;
int rc = -ENOMEM;
int i, mapped = 0; int i, mapped = 0;
char *res_name;
int numa_node; int numa_node;
/* /*
...@@ -55,14 +61,17 @@ static int dev_dax_kmem_probe(struct dev_dax *dev_dax) ...@@ -55,14 +61,17 @@ static int dev_dax_kmem_probe(struct dev_dax *dev_dax)
return -EINVAL; return -EINVAL;
} }
res_name = kstrdup(dev_name(dev), GFP_KERNEL); data = kzalloc(sizeof(*data) + sizeof(struct resource *) * dev_dax->nr_range, GFP_KERNEL);
if (!res_name) if (!data)
return -ENOMEM; return -ENOMEM;
data->res_name = kstrdup(dev_name(dev), GFP_KERNEL);
if (!data->res_name)
goto err_res_name;
for (i = 0; i < dev_dax->nr_range; i++) { for (i = 0; i < dev_dax->nr_range; i++) {
struct resource *res; struct resource *res;
struct range range; struct range range;
int rc;
rc = dax_kmem_range(dev_dax, i, &range); rc = dax_kmem_range(dev_dax, i, &range);
if (rc) { if (rc) {
...@@ -72,7 +81,7 @@ static int dev_dax_kmem_probe(struct dev_dax *dev_dax) ...@@ -72,7 +81,7 @@ static int dev_dax_kmem_probe(struct dev_dax *dev_dax)
} }
/* Region is permanently reserved if hotremove fails. */ /* Region is permanently reserved if hotremove fails. */
res = request_mem_region(range.start, range_len(&range), res_name); res = request_mem_region(range.start, range_len(&range), data->res_name);
if (!res) { if (!res) {
dev_warn(dev, "mapping%d: %#llx-%#llx could not reserve region\n", dev_warn(dev, "mapping%d: %#llx-%#llx could not reserve region\n",
i, range.start, range.end); i, range.start, range.end);
...@@ -82,9 +91,10 @@ static int dev_dax_kmem_probe(struct dev_dax *dev_dax) ...@@ -82,9 +91,10 @@ static int dev_dax_kmem_probe(struct dev_dax *dev_dax)
*/ */
if (mapped) if (mapped)
continue; continue;
kfree(res_name); rc = -EBUSY;
return -EBUSY; goto err_request_mem;
} }
data->res[i] = res;
/* /*
* Set flags appropriate for System RAM. Leave ..._BUSY clear * Set flags appropriate for System RAM. Leave ..._BUSY clear
...@@ -104,18 +114,25 @@ static int dev_dax_kmem_probe(struct dev_dax *dev_dax) ...@@ -104,18 +114,25 @@ static int dev_dax_kmem_probe(struct dev_dax *dev_dax)
if (rc) { if (rc) {
dev_warn(dev, "mapping%d: %#llx-%#llx memory add failed\n", dev_warn(dev, "mapping%d: %#llx-%#llx memory add failed\n",
i, range.start, range.end); i, range.start, range.end);
release_mem_region(range.start, range_len(&range)); release_resource(res);
kfree(res);
data->res[i] = NULL;
if (mapped) if (mapped)
continue; continue;
kfree(res_name); goto err_request_mem;
return rc;
} }
mapped++; mapped++;
} }
dev_set_drvdata(dev, res_name); dev_set_drvdata(dev, data);
return 0; return 0;
err_request_mem:
kfree(data->res_name);
err_res_name:
kfree(data);
return rc;
} }
#ifdef CONFIG_MEMORY_HOTREMOVE #ifdef CONFIG_MEMORY_HOTREMOVE
...@@ -123,7 +140,7 @@ static int dev_dax_kmem_remove(struct dev_dax *dev_dax) ...@@ -123,7 +140,7 @@ static int dev_dax_kmem_remove(struct dev_dax *dev_dax)
{ {
int i, success = 0; int i, success = 0;
struct device *dev = &dev_dax->dev; struct device *dev = &dev_dax->dev;
const char *res_name = dev_get_drvdata(dev); struct dax_kmem_data *data = dev_get_drvdata(dev);
/* /*
* We have one shot for removing memory, if some memory blocks were not * We have one shot for removing memory, if some memory blocks were not
...@@ -142,7 +159,9 @@ static int dev_dax_kmem_remove(struct dev_dax *dev_dax) ...@@ -142,7 +159,9 @@ static int dev_dax_kmem_remove(struct dev_dax *dev_dax)
rc = remove_memory(dev_dax->target_node, range.start, rc = remove_memory(dev_dax->target_node, range.start,
range_len(&range)); range_len(&range));
if (rc == 0) { if (rc == 0) {
release_mem_region(range.start, range_len(&range)); release_resource(data->res[i]);
kfree(data->res[i]);
data->res[i] = NULL;
success++; success++;
continue; continue;
} }
...@@ -153,7 +172,8 @@ static int dev_dax_kmem_remove(struct dev_dax *dev_dax) ...@@ -153,7 +172,8 @@ static int dev_dax_kmem_remove(struct dev_dax *dev_dax)
} }
if (success >= dev_dax->nr_range) { if (success >= dev_dax->nr_range) {
kfree(res_name); kfree(data->res_name);
kfree(data);
dev_set_drvdata(dev, NULL); dev_set_drvdata(dev, NULL);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment