lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <160196730203.2166475.10332959995680506711.stgit@dwillia2-desk3.amr.corp.intel.com>
Date:   Mon, 05 Oct 2020 23:55:02 -0700
From:   Dan Williams <dan.j.williams@...el.com>
To:     akpm@...ux-foundation.org
Cc:     David Hildenbrand <david@...hat.com>,
        Vishal Verma <vishal.l.verma@...el.com>,
        Dave Hansen <dave.hansen@...ux.intel.com>,
        Pavel Tatashin <pasha.tatashin@...een.com>,
        Brice Goglin <Brice.Goglin@...ia.fr>,
        Dave Jiang <dave.jiang@...el.com>,
        David Hildenbrand <david@...hat.com>,
        Ira Weiny <ira.weiny@...el.com>, Jia He <justin.he@....com>,
        Joao Martins <joao.m.martins@...cle.com>,
        Jonathan Cameron <Jonathan.Cameron@...wei.com>,
        linux-mm@...ck.org, linux-kernel@...r.kernel.org,
        linux-nvdimm@...ts.01.org, david@...hat.com,
        joao.m.martins@...cle.com
Subject: [PATCH v6 03/11] device-dax/kmem: move resource tracking to drvdata

Towards removing the mode specific @dax_kmem_res attribute from the
generic 'struct dev_dax', and preparing for multi-range support, move
resource 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.

The resource reservation also needs to be released manually via
release_resource() given the awkward manipulation of the
IORESOURCE_BUSY flag.

Cc: David Hildenbrand <david@...hat.com>
Cc: Vishal Verma <vishal.l.verma@...el.com>
Cc: Dave Hansen <dave.hansen@...ux.intel.com>
Cc: Pavel Tatashin <pasha.tatashin@...een.com>
Cc: Brice Goglin <Brice.Goglin@...ia.fr>
Cc: Dave Jiang <dave.jiang@...el.com>
Cc: David Hildenbrand <david@...hat.com>
Cc: Ira Weiny <ira.weiny@...el.com>
Cc: Jia He <justin.he@....com>
Cc: Joao Martins <joao.m.martins@...cle.com>
Cc: Jonathan Cameron <Jonathan.Cameron@...wei.com>
Signed-off-by: Dan Williams <dan.j.williams@...el.com>
---
 drivers/dax/dax-private.h |    3 --
 drivers/dax/kmem.c        |   55 +++++++++++++++++++++++++++++----------------
 2 files changed, 35 insertions(+), 23 deletions(-)

diff --git a/drivers/dax/dax-private.h b/drivers/dax/dax-private.h
index fbaea36938ae..0668b58c64aa 100644
--- a/drivers/dax/dax-private.h
+++ b/drivers/dax/dax-private.h
@@ -42,8 +42,6 @@ struct dax_region {
  * @dev - device core
  * @pgmap - pgmap for memmap setup / lifetime (driver owned)
  * @range: resource range for the instance
- * @dax_mem_res: physical address range of hotadded DAX memory
- * @dax_mem_name: name for hotadded DAX memory via add_memory_driver_managed()
  */
 struct dev_dax {
 	struct dax_region *region;
@@ -52,7 +50,6 @@ struct dev_dax {
 	struct device dev;
 	struct dev_pagemap *pgmap;
 	struct range range;
-	struct resource *dax_kmem_res;
 };
 
 static inline struct dev_dax *to_dev_dax(struct device *dev)
diff --git a/drivers/dax/kmem.c b/drivers/dax/kmem.c
index b0d6a99cf12d..a415bc239db4 100644
--- a/drivers/dax/kmem.c
+++ b/drivers/dax/kmem.c
@@ -29,14 +29,19 @@ static struct range dax_kmem_range(struct dev_dax *dev_dax)
 	return range;
 }
 
+struct dax_kmem_data {
+	const char *res_name;
+	struct resource *res;
+};
+
 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 dax_kmem_data *data;
 	struct resource *new_res;
-	const char *new_res_name;
+	int rc = -ENOMEM;
 	int numa_node;
-	int rc;
 
 	/*
 	 * Ensure good NUMA information for the persistent memory.
@@ -51,17 +56,22 @@ int dev_dax_kmem_probe(struct device *dev)
 		return -EINVAL;
 	}
 
-	new_res_name = kstrdup(dev_name(dev), GFP_KERNEL);
-	if (!new_res_name)
+	data = kzalloc(sizeof(*data), GFP_KERNEL);
+	if (!data)
 		return -ENOMEM;
 
+	data->res_name = kstrdup(dev_name(dev), GFP_KERNEL);
+	if (!data->res_name)
+		goto err_res_name;
+
 	/* 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), data->res_name);
 	if (!new_res) {
 		dev_warn(dev, "could not reserve region [%#llx-%#llx]\n", range.start, range.end);
-		kfree(new_res_name);
-		return -EBUSY;
+		rc = -EBUSY;
+		goto err_request_mem;
 	}
+	data->res = new_res;
 
 	/*
 	 * Set flags appropriate for System RAM.  Leave ..._BUSY clear
@@ -77,15 +87,21 @@ int dev_dax_kmem_probe(struct device *dev)
 	 */
 	rc = add_memory_driver_managed(numa_node, new_res->start,
 				       resource_size(new_res), kmem_name);
-	if (rc) {
-		release_resource(new_res);
-		kfree(new_res);
-		kfree(new_res_name);
-		return rc;
-	}
-	dev_dax->dax_kmem_res = new_res;
+	if (rc)
+		goto err_add_memory;
+
+	dev_set_drvdata(dev, data);
 
 	return 0;
+
+err_add_memory:
+	release_resource(data->res);
+	kfree(data->res);
+err_request_mem:
+	kfree(data->res_name);
+err_res_name:
+	kfree(data);
+	return rc;
 }
 
 #ifdef CONFIG_MEMORY_HOTREMOVE
@@ -93,8 +109,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;
+	struct dax_kmem_data *data = dev_get_drvdata(dev);
 	int rc;
 
 	/*
@@ -112,10 +127,10 @@ static int dev_dax_kmem_remove(struct device *dev)
 	}
 
 	/* Release and free dax resources */
-	release_resource(res);
-	kfree(res);
-	kfree(res_name);
-	dev_dax->dax_kmem_res = NULL;
+	release_resource(data->res);
+	kfree(data->res);
+	kfree(data->res_name);
+	kfree(data);
 
 	return 0;
 }

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ