diff options
author | Dan Williams <dan.j.williams@intel.com> | 2017-02-24 17:55:45 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2017-02-24 20:46:53 -0500 |
commit | b5d24fda9c3dce51fcb4eee459550a458eaaf1e2 (patch) | |
tree | aad811ffd2581cd9d29c5995615a8b77cfe2859b | |
parent | 299c517adb903ddd376dd103fcc9dcfff3d4728b (diff) |
mm, devm_memremap_pages: hold device_hotplug lock over mem_hotplug_{begin, done}
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.
[dan.j.williams@intel.com: v2]
Link: http://lkml.kernel.org/r/148728203365.38457.17804568297887708345.stgit@dwillia2-desk3.amr.corp.intel.com
Link: http://lkml.kernel.org/r/148693885680.16345.17802627926777862337.stgit@dwillia2-desk3.amr.corp.intel.com
Fixes: f931ab479dd2 ("mm: fix devm_memremap_pages crash, use mem_hotplug_{begin, done}")
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
Reported-by: Ben Hutchings <ben@decadent.org.uk>
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>
Cc: Masayoshi Mizuma <m.mizuma@jp.fujitsu.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | kernel/memremap.c | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/kernel/memremap.c b/kernel/memremap.c index 9ecedc28b928..06123234f118 100644 --- a/kernel/memremap.c +++ b/kernel/memremap.c | |||
@@ -246,9 +246,13 @@ static void devm_memremap_pages_release(struct device *dev, void *data) | |||
246 | /* pages are dead and unused, undo the arch mapping */ | 246 | /* pages are dead and unused, undo the arch mapping */ |
247 | align_start = res->start & ~(SECTION_SIZE - 1); | 247 | align_start = res->start & ~(SECTION_SIZE - 1); |
248 | align_size = ALIGN(resource_size(res), SECTION_SIZE); | 248 | align_size = ALIGN(resource_size(res), SECTION_SIZE); |
249 | |||
250 | lock_device_hotplug(); | ||
249 | mem_hotplug_begin(); | 251 | mem_hotplug_begin(); |
250 | arch_remove_memory(align_start, align_size); | 252 | arch_remove_memory(align_start, align_size); |
251 | mem_hotplug_done(); | 253 | mem_hotplug_done(); |
254 | unlock_device_hotplug(); | ||
255 | |||
252 | untrack_pfn(NULL, PHYS_PFN(align_start), align_size); | 256 | untrack_pfn(NULL, PHYS_PFN(align_start), align_size); |
253 | pgmap_radix_release(res); | 257 | pgmap_radix_release(res); |
254 | dev_WARN_ONCE(dev, pgmap->altmap && pgmap->altmap->alloc, | 258 | dev_WARN_ONCE(dev, pgmap->altmap && pgmap->altmap->alloc, |
@@ -360,9 +364,11 @@ void *devm_memremap_pages(struct device *dev, struct resource *res, | |||
360 | if (error) | 364 | if (error) |
361 | goto err_pfn_remap; | 365 | goto err_pfn_remap; |
362 | 366 | ||
367 | lock_device_hotplug(); | ||
363 | mem_hotplug_begin(); | 368 | mem_hotplug_begin(); |
364 | error = arch_add_memory(nid, align_start, align_size, true); | 369 | error = arch_add_memory(nid, align_start, align_size, true); |
365 | mem_hotplug_done(); | 370 | mem_hotplug_done(); |
371 | unlock_device_hotplug(); | ||
366 | if (error) | 372 | if (error) |
367 | goto err_add_memory; | 373 | goto err_add_memory; |
368 | 374 | ||