David Hildenbrand 8df1d0e4a2 mm/memory_hotplug: make add_memory() take the device_hotplug_lock
add_memory() currently does not take the device_hotplug_lock, however
is aleady called under the lock from
	arch/powerpc/platforms/pseries/hotplug-memory.c
	drivers/acpi/acpi_memhotplug.c
to synchronize against CPU hot-remove and similar.

In general, we should hold the device_hotplug_lock when adding memory to
synchronize against online/offline request (e.g.  from user space) - which
already resulted in lock inversions due to device_lock() and
mem_hotplug_lock - see 30467e0b3be ("mm, hotplug: fix concurrent memory
hot-add deadlock").  add_memory()/add_memory_resource() will create memory
block devices, so this really feels like the right thing to do.

Holding the device_hotplug_lock makes sure that a memory block device
can really only be accessed (e.g. via .online/.state) from user space,
once the memory has been fully added to the system.

The lock is not held yet in
	drivers/xen/balloon.c
	arch/powerpc/platforms/powernv/memtrace.c
	drivers/s390/char/sclp_cmd.c
	drivers/hv/hv_balloon.c
So, let's either use the locked variants or take the lock.

Don't export add_memory_resource(), as it once was exported to be used by
XEN, which is never built as a module.  If somebody requires it, we also
have to export a locked variant (as device_hotplug_lock is never
exported).

Link: http://lkml.kernel.org/r/20180925091457.28651-3-david@redhat.com
Signed-off-by: David Hildenbrand <david@redhat.com>
Reviewed-by: Pavel Tatashin <pavel.tatashin@microsoft.com>
Reviewed-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Rashmica Gupta <rashmica.g@gmail.com>
Reviewed-by: Oscar Salvador <osalvador@suse.de>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: "Rafael J. Wysocki" <rjw@rjwysocki.net>
Cc: Len Brown <lenb@kernel.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: Nathan Fontenot <nfont@linux.vnet.ibm.com>
Cc: John Allen <jallen@linux.vnet.ibm.com>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: Mathieu Malaterre <malat@debian.org>
Cc: Pavel Tatashin <pavel.tatashin@microsoft.com>
Cc: YASUAKI ISHIMATSU <yasu.isimatu@gmail.com>
Cc: Balbir Singh <bsingharora@gmail.com>
Cc: Haiyang Zhang <haiyangz@microsoft.com>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Kate Stewart <kstewart@linuxfoundation.org>
Cc: "K. Y. Srinivasan" <kys@microsoft.com>
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
Cc: Michael Neuling <mikey@neuling.org>
Cc: Philippe Ombredanne <pombredanne@nexb.com>
Cc: Stephen Hemminger <sthemmin@microsoft.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2018-10-31 08:54:17 -07:00
..
2018-10-16 11:13:50 +02:00
2018-10-26 10:50:10 -07:00
2018-10-25 17:57:35 -07:00
2018-10-26 07:38:19 -07:00
2018-10-23 01:09:22 +01:00
2018-10-26 08:14:13 -07:00
2018-10-26 07:38:19 -07:00
2018-10-26 13:05:26 -07:00
2018-10-26 08:14:13 -07:00
2018-10-25 06:50:48 -07:00
2018-05-26 09:16:44 +02:00
2018-06-15 18:10:01 -03:00
2018-10-25 11:17:40 -06:00
2018-10-19 13:24:31 -07:00
2018-10-19 13:24:31 -07:00
2018-05-09 17:25:13 +02:00
2018-09-06 15:12:24 -06:00
2018-10-26 16:26:32 -07:00
2018-10-26 16:26:32 -07:00
2018-06-15 18:10:01 -03:00
2018-06-19 10:06:29 -07:00
2018-06-19 10:06:29 -07:00
2018-10-28 13:26:45 -07:00
2018-08-14 13:12:24 -07:00
2018-08-23 13:44:43 -07:00
2018-08-22 10:52:48 -07:00
2018-08-21 18:19:09 -07:00
2018-10-26 08:42:25 -07:00
2018-08-25 13:40:38 -07:00
2018-09-11 14:11:54 +02:00
2018-07-12 10:04:29 -04:00
\n
2018-10-29 09:19:53 -07:00
2018-06-11 10:16:13 -07:00
2018-06-11 10:16:13 -07:00
2018-07-27 09:57:23 +10:00
2018-10-01 08:58:57 -06:00
2018-06-28 20:32:51 +09:00
2018-06-04 10:58:12 -07:00
2018-10-21 10:46:33 -04:00
2018-10-09 07:50:41 +02:00
2018-06-22 13:43:27 +09:00
2018-08-18 11:44:53 -07:00
2018-06-21 12:33:21 +02:00
2018-07-12 21:35:28 +02:00
2018-06-05 08:50:16 -04:00
2018-06-07 17:34:35 -07:00
2018-10-31 08:54:15 -07:00
2018-10-31 08:54:14 -07:00
2018-06-07 17:34:39 -07:00
2018-10-17 13:56:58 -07:00
2018-08-23 16:03:58 -07:00
2018-08-22 10:52:45 -07:00
2018-07-10 17:22:35 +02:00
2018-10-29 10:42:20 -07:00
2018-06-07 17:34:36 -07:00
2018-10-21 10:46:39 -04:00
2018-09-18 17:52:15 -05:00
2018-10-25 06:50:48 -07:00
2018-07-19 11:34:23 +01:00
2018-10-25 06:50:48 -07:00
2018-10-26 16:26:35 -07:00
2018-10-01 23:14:10 -07:00
2018-07-21 10:43:12 -05:00
2018-10-08 22:53:10 +11:00
2018-08-22 10:52:46 -07:00
2018-10-26 16:26:32 -07:00
2018-05-31 00:13:56 +08:00
2018-07-20 01:11:45 +02:00
2018-08-02 17:33:06 -04:00
2018-05-11 17:28:45 -07:00
2018-07-17 09:27:43 +02:00
2018-09-28 14:20:59 +02:00
2018-09-25 20:17:35 -07:00
2018-06-29 08:48:06 -06:00
2018-10-26 16:26:33 -07:00
2018-06-07 17:34:35 -07:00
2018-07-07 17:25:23 +02:00
2018-07-03 09:20:44 +02:00
2018-08-16 12:14:42 -07:00
2018-06-20 11:35:56 +02:00
2018-09-29 22:47:49 -04:00
2018-08-18 11:44:53 -07:00
2018-10-11 09:16:44 -07:00
2018-09-25 20:33:24 +02:00
2018-09-11 14:11:51 +02:00
2018-10-21 10:46:46 -04:00
2018-05-14 09:51:34 -04:00