linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Dan Williams <dan.j.williams@intel.com>
To: akpm@linux-foundation.org
Cc: David Hildenbrand <david@redhat.com>,
	Vishal Verma <vishal.l.verma@intel.com>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	Pavel Tatashin <pasha.tatashin@soleen.com>,
	Brice Goglin <Brice.Goglin@inria.fr>,
	Dave Jiang <dave.jiang@intel.com>,
	David Hildenbrand <david@redhat.com>,
	Ira Weiny <ira.weiny@intel.com>, Jia He <justin.he@arm.com>,
	Joao Martins <joao.m.martins@oracle.com>,
	Jonathan Cameron <Jonathan.Cameron@huawei.com>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	linux-nvdimm@lists.01.org, david@redhat.com,
	joao.m.martins@oracle.com
Subject: [PATCH v6 03/11] device-dax/kmem: move resource tracking to drvdata
Date: Mon, 05 Oct 2020 23:55:02 -0700	[thread overview]
Message-ID: <160196730203.2166475.10332959995680506711.stgit@dwillia2-desk3.amr.corp.intel.com> (raw)
In-Reply-To: <160196728453.2166475.12832711415715687418.stgit@dwillia2-desk3.amr.corp.intel.com>

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@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/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;
 }



  parent reply	other threads:[~2020-10-06  7:13 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-06  6:54 [PATCH v6 00/11] device-dax: support sub-dividing soft-reserved ranges Dan Williams
2020-10-06  6:54 ` [PATCH v6 01/11] device-dax: make pgmap optional for instance creation Dan Williams
2020-10-06  6:54 ` [PATCH v6 02/11] device-dax/kmem: introduce dax_kmem_range() Dan Williams
2020-10-06  6:55 ` Dan Williams [this message]
2020-10-06  8:14   ` [PATCH v6 03/11] device-dax/kmem: move resource tracking to drvdata David Hildenbrand
2020-10-06  6:55 ` [PATCH v6 04/11] device-dax: add an allocation interface for device-dax instances Dan Williams
2020-10-06  6:55 ` [PATCH v6 05/11] device-dax: introduce 'struct dev_dax' typed-driver operations Dan Williams
2020-10-06  6:55 ` [PATCH v6 06/11] device-dax: introduce 'seed' devices Dan Williams
2020-10-06  6:55 ` [PATCH v6 07/11] drivers/base: make device_find_child_by_name() compatible with sysfs inputs Dan Williams
2020-10-06  6:55 ` [PATCH v6 08/11] device-dax: add resize support Dan Williams
2020-10-06  6:55 ` [PATCH v6 09/11] mm/memremap_pages: convert to 'struct range' Dan Williams
2020-10-08 19:52   ` boris.ostrovsky
2020-10-06  6:55 ` [PATCH v6 10/11] mm/memremap_pages: support multiple ranges per invocation Dan Williams
2020-10-06  6:55 ` [PATCH v6 11/11] device-dax: add dis-contiguous resource support Dan Williams

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=160196730203.2166475.10332959995680506711.stgit@dwillia2-desk3.amr.corp.intel.com \
    --to=dan.j.williams@intel.com \
    --cc=Brice.Goglin@inria.fr \
    --cc=Jonathan.Cameron@huawei.com \
    --cc=akpm@linux-foundation.org \
    --cc=dave.hansen@linux.intel.com \
    --cc=dave.jiang@intel.com \
    --cc=david@redhat.com \
    --cc=ira.weiny@intel.com \
    --cc=joao.m.martins@oracle.com \
    --cc=justin.he@arm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux-nvdimm@lists.01.org \
    --cc=pasha.tatashin@soleen.com \
    --cc=vishal.l.verma@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).