Skip to contentSkip to conversation

driver core: Add missing dev->bus->need_parent_lock checks

PATCH In review Rafael J. Wysocki 3 participants 3 messages Dec 13, 2018 Driver core

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 driver core: Add missing dev->bus->need_parent_lock checks

From: Rafael J. Wysocki <[email protected]>

__device_release_driver() has to check dev->bus->need_parent_lock before dropping the parent lock and acquiring it again as it may attempt to drop a lock that hasn't been acquired or lock a device that shouldn't be locked and create a lock imbalance.

Fixes 8c97a46af04b (driver core: hold dev's parent lock when needed)

---

This should go into -stable for everything over 4.18 methinks.

---
 drivers/base/dd.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/base/dd.c +2 -2
Index: linux-pm/drivers/base/dd.c
===================================================================
@@ -933,11 +933,11 @@ static void __device_release_driver(stru
 
 		while (device_links_busy(dev)) {
 			device_unlock(dev);
-			if (parent)
+			if (parent && dev->bus->need_parent_lock)
 				device_unlock(parent);
 
 			device_links_unbind_consumers(dev);
-			if (parent)
+			if (parent && dev->bus->need_parent_lock)
 				device_lock(parent);
 
 			device_lock(dev);
#1 lore raw
Quoted 7 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

__device_release_driver() has to check dev->bus->need_parent_lock before dropping the parent lock and acquiring it again as it may attempt to drop a lock that hasn't been acquired or lock a device that shouldn't be locked and create a lock imbalance.

Quoted 5 lines
Fixes 8c97a46af04b (driver core: hold dev's parent lock when needed)

---

This should go into -stable for everything over 4.18 methinks.

Does this fix Daniel's lockdep splat?

thanks,

greg k-h

Reviewed-by
#2 lore raw
Quoted 9 lines · Greg Kroah-Hartman
Quoted 7 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

__device_release_driver() has to check dev->bus->need_parent_lock before dropping the parent lock and acquiring it again as it may attempt to drop a lock that hasn't been acquired or lock a device that shouldn't be locked and create a lock imbalance.

Quoted 7 lines
Quoted 5 lines
Fixes 8c97a46af04b (driver core: hold dev's parent lock when needed)

---

This should go into -stable for everything over 4.18 methinks.

Does this fix Daniel's lockdep splat?

Nah, separate issue. Afaiui bus->need_parent_lock is only set for usb, I'm unbinding pci devices. I guess the combination of someone unbinding an usb device through sysfs which also has some device links attached doesn't happen.

Since I've dug around in this, for this patch here from Rafael:

Cheers, Daniel

Quoted 4 lines

thanks,

greg k-h

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch