Skip to content

Commit 9f960da

Browse files
soleentorvalds
authored andcommitted
device-dax: "Hotremove" persistent memory that is used like normal RAM
It is now allowed to use persistent memory like a regular RAM, but currently there is no way to remove this memory until machine is rebooted. This work expands the functionality to also allows hotremoving previously hotplugged persistent memory, and recover the device for use for other purposes. To hotremove persistent memory, the management software must first offline all memory blocks of dax region, and than unbind it from device-dax/kmem driver. So, operations should look like this: echo offline > /sys/devices/system/memory/memoryN/state ... echo dax0.0 > /sys/bus/dax/drivers/kmem/unbind Note: if unbind is done without offlining memory beforehand, it won't be possible to do dax0.0 hotremove, and dax's memory is going to be part of System RAM until reboot. Link: http://lkml.kernel.org/r/20190517215438.6487-4-pasha.tatashin@soleen.com Signed-off-by: Pavel Tatashin <pasha.tatashin@soleen.com> Reviewed-by: David Hildenbrand <david@redhat.com> Cc: James Morris <jmorris@namei.org> Cc: Sasha Levin <sashal@kernel.org> Cc: Michal Hocko <mhocko@suse.com> Cc: Dave Hansen <dave.hansen@linux.intel.com> Cc: Dan Williams <dan.j.williams@intel.com> Cc: Keith Busch <keith.busch@intel.com> Cc: Vishal Verma <vishal.l.verma@intel.com> Cc: Dave Jiang <dave.jiang@intel.com> Cc: Ross Zwisler <zwisler@kernel.org> Cc: Tom Lendacky <thomas.lendacky@amd.com> Cc: Huang Ying <ying.huang@intel.com> Cc: Fengguang Wu <fengguang.wu@intel.com> Cc: Borislav Petkov <bp@suse.de> Cc: Bjorn Helgaas <bhelgaas@google.com> Cc: Yaowei Bai <baiyaowei@cmss.chinamobile.com> Cc: Takashi Iwai <tiwai@suse.de> Cc: Jérôme Glisse <jglisse@redhat.com> Cc: Dave Hansen <dave.hansen@intel.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent eca499a commit 9f960da

2 files changed

Lines changed: 39 additions & 4 deletions

File tree

‎drivers/dax/dax-private.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,15 @@ struct dax_region {
4343
* @target_node: effective numa node if dev_dax memory range is onlined
4444
* @dev - device core
4545
* @pgmap - pgmap for memmap setup / lifetime (driver owned)
46+
* @dax_mem_res: physical address range of hotadded DAX memory
4647
*/
4748
struct dev_dax {
4849
struct dax_region *region;
4950
struct dax_device *dax_dev;
5051
int target_node;
5152
struct device dev;
5253
struct dev_pagemap pgmap;
54+
struct resource *dax_kmem_res;
5355
};
5456

5557
static inline struct dev_dax *to_dev_dax(struct device *dev)

‎drivers/dax/kmem.c‎

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,21 +71,54 @@ int dev_dax_kmem_probe(struct device *dev)
7171
kfree(new_res);
7272
return rc;
7373
}
74+
dev_dax->dax_kmem_res = new_res;
7475

7576
return 0;
7677
}
7778

79+
#ifdef CONFIG_MEMORY_HOTREMOVE
80+
static int dev_dax_kmem_remove(struct device *dev)
81+
{
82+
struct dev_dax *dev_dax = to_dev_dax(dev);
83+
struct resource *res = dev_dax->dax_kmem_res;
84+
resource_size_t kmem_start = res->start;
85+
resource_size_t kmem_size = resource_size(res);
86+
int rc;
87+
88+
/*
89+
* We have one shot for removing memory, if some memory blocks were not
90+
* offline prior to calling this function remove_memory() will fail, and
91+
* there is no way to hotremove this memory until reboot because device
92+
* unbind will succeed even if we return failure.
93+
*/
94+
rc = remove_memory(dev_dax->target_node, kmem_start, kmem_size);
95+
if (rc) {
96+
dev_err(dev,
97+
"DAX region %pR cannot be hotremoved until the next reboot\n",
98+
res);
99+
return rc;
100+
}
101+
102+
/* Release and free dax resources */
103+
release_resource(res);
104+
kfree(res);
105+
dev_dax->dax_kmem_res = NULL;
106+
107+
return 0;
108+
}
109+
#else
78110
static int dev_dax_kmem_remove(struct device *dev)
79111
{
80112
/*
81-
* Purposely leak the request_mem_region() for the device-dax
82-
* range and return '0' to ->remove() attempts. The removal of
83-
* the device from the driver always succeeds, but the region
84-
* is permanently pinned as reserved by the unreleased
113+
* Without hotremove purposely leak the request_mem_region() for the
114+
* device-dax range and return '0' to ->remove() attempts. The removal
115+
* of the device from the driver always succeeds, but the region is
116+
* permanently pinned as reserved by the unreleased
85117
* request_mem_region().
86118
*/
87119
return 0;
88120
}
121+
#endif /* CONFIG_MEMORY_HOTREMOVE */
89122

90123
static struct dax_device_driver device_dax_kmem_driver = {
91124
.drv = {

0 commit comments

Comments
 (0)