diff mbox

[1/2] mm, devm_memremap_pages: hold device_hotplug lock over mem_hotplug_{begin, done}

Message ID 148693885680.16345.17802627926777862337.stgit@dwillia2-desk3.amr.corp.intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Dan Williams Feb. 12, 2017, 10:34 p.m. UTC
The mem_hotplug_{begin,done} lock coordinates with
{get,put}_online_mems() to hold off "readers" of the current state of
memory from new hotplug actions. mem_hotplug_begin() expects exclusive
access, via the device_hotplug lock, to set mem_hotplug.active_writer.
Calling mem_hotplug_begin() without locking device_hotplug can lead to
corrupting mem_hotplug.refcount and missed wakeups / soft lockups.

Cc: <stable@vger.kernel.org>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Toshi Kani <toshi.kani@hpe.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: Logan Gunthorpe <logang@deltatee.com>
Fixes: f931ab479dd2 ("mm: fix devm_memremap_pages crash, use mem_hotplug_{begin, done}")
Reported-by: Ben Hutchings <ben@decadent.org.uk>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
 kernel/memremap.c |    5 +++++
 1 file changed, 5 insertions(+)
diff mbox


diff --git a/kernel/memremap.c b/kernel/memremap.c
index e6476a8e8b6a..16640415c150 100644
--- a/kernel/memremap.c
+++ b/kernel/memremap.c
@@ -264,9 +264,12 @@  static void devm_memremap_pages_release(struct device *dev, void *data)
 	/* pages are dead and unused, undo the arch mapping */
+	lock_device_hotplug();
 	arch_remove_memory(res->start, resource_size(res));
+	unlock_device_hotplug();
 	untrack_pfn(NULL, PHYS_PFN(res->start), resource_size(res));
 	dev_WARN_ONCE(dev, pgmap->altmap && pgmap->altmap->alloc,
@@ -374,9 +377,11 @@  void *devm_memremap_pages(struct device *dev, struct resource *res,
 	if (error)
 		goto err_pfn_remap;
+	lock_device_hotplug();
 	error = arch_add_memory(nid, res->start, resource_size(res), true);
+	unlock_device_hotplug();
 	if (error)
 		goto err_add_memory;