Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1579314

[PATCH 2/2] mm: validate device_hotplug is held for memory hotplug

From Dan Williams <dan.j.williams@intel.com>
Newsgroups linux.kernel
Subject [PATCH 2/2] mm: validate device_hotplug is held for memory hotplug
Date 2017-02-12 23:40 +0100
Message-ID <taaYh-3zU-17@gated-at.bofh.it> (permalink)
References <taaYh-3zU-3@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


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.

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>
Reported-by: Ben Hutchings <ben@decadent.org.uk>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
---
 drivers/base/core.c    |    5 +++++
 include/linux/device.h |    1 +
 mm/memory_hotplug.c    |    2 ++
 3 files changed, 8 insertions(+)

diff --git a/drivers/base/core.c b/drivers/base/core.c
index 8c25e68e67d7..3050e6f99403 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -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)
 {
diff --git a/include/linux/device.h b/include/linux/device.h
index bd684fc8ec1d..a48a7ff70164 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -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);
diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
index 19b460acb5e1..0ab3dd6cc2a4 100644
--- a/mm/memory_hotplug.c
+++ b/mm/memory_hotplug.c
@@ -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();

Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH 0/2] fix devm_memremap_pages() mem hotplug locking Dan Williams <dan.j.williams@intel.com> - 2017-02-12 23:40 +0100
  [PATCH 2/2] mm: validate device_hotplug is held for memory hotplug Dan Williams <dan.j.williams@intel.com> - 2017-02-12 23:40 +0100
  [PATCH 1/2] mm, devm_memremap_pages: hold device_hotplug lock over  mem_hotplug_{begin, done} Dan Williams <dan.j.williams@intel.com> - 2017-02-12 23:40 +0100
  Re: [PATCH 0/2] fix devm_memremap_pages() mem hotplug locking Masayoshi Mizuma <m.mizuma@jp.fujitsu.com> - 2017-02-13 02:40 +0100
    Re: [PATCH 0/2] fix devm_memremap_pages() mem hotplug locking Dan Williams <dan.j.williams@intel.com> - 2017-02-13 02:40 +0100

csiph-web