]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
mm: validate device_hotplug is held for memory hotplug
authorDan Williams <dan.j.williams@intel.com>
Fri, 24 Feb 2017 22:55:48 +0000 (14:55 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Sat, 25 Feb 2017 01:46:53 +0000 (17:46 -0800)
mem_hotplug_begin() assumes that it can set mem_hotplug.active_writer
and run the hotplug process without racing another thread.  Validate
this assumption with a lockdep assertion.

Link: http://lkml.kernel.org/r/148693886229.16345.1770484669403334689.stgit@dwillia2-desk3.amr.corp.intel.com
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: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Masayoshi Mizuma <m.mizuma@jp.fujitsu.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
drivers/base/core.c
include/linux/device.h
mm/memory_hotplug.c

index 8c25e68e67d7354005dc81a92342eb10519449ed..3050e6f994031ffb308976eb8dd19a6a07cb2b28 100644 (file)
@@ -638,6 +638,11 @@ int lock_device_hotplug_sysfs(void)
        return restart_syscall();
 }
 
+void assert_held_device_hotplug(void)
+{
+       lockdep_assert_held(&device_hotplug_lock);
+}
+
 #ifdef CONFIG_BLOCK
 static inline int device_is_not_partition(struct device *dev)
 {
index bd684fc8ec1d83b80f393e9b2e5dc5cfb0776ad6..a48a7ff70164beee58f086fa6dca79e88bb6344a 100644 (file)
@@ -1139,6 +1139,7 @@ static inline bool device_supports_offline(struct device *dev)
 extern void lock_device_hotplug(void);
 extern void unlock_device_hotplug(void);
 extern int lock_device_hotplug_sysfs(void);
+void assert_held_device_hotplug(void);
 extern int device_offline(struct device *dev);
 extern int device_online(struct device *dev);
 extern void set_primary_fwnode(struct device *dev, struct fwnode_handle *fwnode);
index d67787d10ff0e9c4e068beb819daf4761947be04..92a242af5a917cf3a4312785b259151bec83fb67 100644 (file)
@@ -126,6 +126,8 @@ void put_online_mems(void)
 
 void mem_hotplug_begin(void)
 {
+       assert_held_device_hotplug();
+
        mem_hotplug.active_writer = current;
 
        memhp_lock_acquire();