[PATCH 7/9] dax/kmem: actually perform memory hotplug

From: Dave Hansen
Date: Mon Oct 22 2018 - 16:18:51 EST



This is the meat of this whole series. When the "kmem" device's
probe function is called and we know we have a good persistent
memory device, hotplug the memory back into the main kernel.

Cc: Dan Williams <dan.j.williams@xxxxxxxxx>
Cc: Dave Jiang <dave.jiang@xxxxxxxxx>
Cc: Ross Zwisler <zwisler@xxxxxxxxxx>
Cc: Vishal Verma <vishal.l.verma@xxxxxxxxx>
Cc: Tom Lendacky <thomas.lendacky@xxxxxxx>
Cc: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
Cc: Michal Hocko <mhocko@xxxxxxxx>
Cc: linux-nvdimm@xxxxxxxxxxxx
Cc: linux-kernel@xxxxxxxxxxxxxxx
Cc: linux-mm@xxxxxxxxx
Cc: Huang Ying <ying.huang@xxxxxxxxx>
Cc: Fengguang Wu <fengguang.wu@xxxxxxxxx>

---

b/drivers/dax/kmem.c | 28 +++++++++++++++++++++++++---
1 file changed, 25 insertions(+), 3 deletions(-)

diff -puN drivers/dax/kmem.c~dax-kmem-hotplug drivers/dax/kmem.c
--- a/drivers/dax/kmem.c~dax-kmem-hotplug 2018-10-22 13:12:24.069930387 -0700
+++ b/drivers/dax/kmem.c 2018-10-22 13:12:24.072930387 -0700
@@ -55,10 +55,12 @@ static void dax_kmem_percpu_kill(void *d
static int dax_kmem_probe(struct device *dev)
{
void *addr;
+ int numa_node;
struct resource res;
int rc, id, region_id;
struct nd_pfn_sb *pfn_sb;
struct dev_dax *dev_dax;
+ struct resource *new_res;
struct dax_kmem *dax_kmem;
struct nd_namespace_io *nsio;
struct dax_region *dax_region;
@@ -86,13 +88,30 @@ static int dax_kmem_probe(struct device

pfn_sb = nd_pfn->pfn_sb;

- if (!devm_request_mem_region(dev, nsio->res.start,
- resource_size(&nsio->res),
- dev_name(&ndns->dev))) {
+ new_res = devm_request_mem_region(dev, nsio->res.start,
+ resource_size(&nsio->res),
+ "System RAM (pmem)");
+ if (!new_res) {
dev_warn(dev, "could not reserve region %pR\n", &nsio->res);
return -EBUSY;
}

+ /*
+ * Set flags appropriate for System RAM. Leave ..._BUSY clear
+ * so that add_memory() can add a child resource.
+ */
+ new_res->flags = IORESOURCE_SYSTEM_RAM;
+
+ numa_node = dev_to_node(dev);
+ if (numa_node < 0) {
+ pr_warn_once("bad numa_node: %d, forcing to 0\n", numa_node);
+ numa_node = 0;
+ }
+
+ rc = add_memory(numa_node, nsio->res.start, resource_size(&nsio->res));
+ if (rc)
+ return rc;
+
dax_kmem->dev = dev;
init_completion(&dax_kmem->cmp);
rc = percpu_ref_init(&dax_kmem->ref, dax_kmem_percpu_release, 0,
@@ -106,6 +125,9 @@ static int dax_kmem_probe(struct device
return rc;

dax_kmem->pgmap.ref = &dax_kmem->ref;
+
+ dax_kmem->pgmap.res.name = "name_kmem_override2";
+
addr = devm_memremap_pages(dev, &dax_kmem->pgmap);
if (IS_ERR(addr))
return PTR_ERR(addr);
_