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


Groups > linux.kernel > #1583647 > unrolled thread

[PATCH] driver core: unbind consumers before locking parent on device unbind

Started byLucas Stach <l.stach@pengutronix.de>
First post2017-02-17 19:40 +0100
Last post2017-02-17 19:50 +0100
Articles 3 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] driver core: unbind consumers before locking parent on device unbind Lucas Stach <l.stach@pengutronix.de> - 2017-02-17 19:40 +0100
    Re: [PATCH] driver core: unbind consumers before locking parent on  device unbind Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-02-17 19:50 +0100
      Re: [PATCH] driver core: unbind consumers before locking parent on  device unbind Lucas Stach <l.stach@pengutronix.de> - 2017-02-17 19:50 +0100

#1583647 — [PATCH] driver core: unbind consumers before locking parent on device unbind

FromLucas Stach <l.stach@pengutronix.de>
Date2017-02-17 19:40 +0100
Subject[PATCH] driver core: unbind consumers before locking parent on device unbind
Message-ID<tbVBM-7Rv-21@gated-at.bofh.it>
On forced unbind the parent lock is taken, as the device might be a USB
device. The device to be unbound might have active consumers, which
must be unbound before calling device_release_driver(), otherwise this
function might deadlock when trying to take the parent lock during
consumer unbind.

Signed-off-by: Lucas Stach <l.stach@pengutronix.de>
---
 drivers/base/bus.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index 6470eb8088f4..23df171a6a64 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -186,6 +186,9 @@ static ssize_t unbind_store(struct device_driver *drv, const char *buf,
 
 	dev = bus_find_device_by_name(bus, NULL, buf);
 	if (dev && dev->driver == drv) {
+		while (device_links_busy(dev)) {
+			device_links_unbind_consumers(dev);
+		}
 		if (dev->parent)	/* Needed for USB */
 			device_lock(dev->parent);
 		device_release_driver(dev);
-- 
2.11.0

[toc] | [next] | [standalone]


#1583648 — Re: [PATCH] driver core: unbind consumers before locking parent on device unbind

FromGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Date2017-02-17 19:50 +0100
SubjectRe: [PATCH] driver core: unbind consumers before locking parent on device unbind
Message-ID<tbVLs-7V6-11@gated-at.bofh.it>
In reply to#1583647
On Fri, Feb 17, 2017 at 07:36:29PM +0100, Lucas Stach wrote:
> On forced unbind the parent lock is taken, as the device might be a USB
> device. The device to be unbound might have active consumers, which
> must be unbound before calling device_release_driver(), otherwise this
> function might deadlock when trying to take the parent lock during
> consumer unbind.

Really?  What type of device does this fail on today?

thanks,

greg k-h

[toc] | [prev] | [next] | [standalone]


#1583650 — Re: [PATCH] driver core: unbind consumers before locking parent on device unbind

FromLucas Stach <l.stach@pengutronix.de>
Date2017-02-17 19:50 +0100
SubjectRe: [PATCH] driver core: unbind consumers before locking parent on device unbind
Message-ID<tbVLs-7V6-13@gated-at.bofh.it>
In reply to#1583648
Am Freitag, den 17.02.2017, 10:42 -0800 schrieb Greg Kroah-Hartman:
> On Fri, Feb 17, 2017 at 07:36:29PM +0100, Lucas Stach wrote:
> > On forced unbind the parent lock is taken, as the device might be a USB
> > device. The device to be unbound might have active consumers, which
> > must be unbound before calling device_release_driver(), otherwise this
> > function might deadlock when trying to take the parent lock during
> > consumer unbind.
> 
> Really?  What type of device does this fail on today?

Regular devices on a MMIO bus. __device_release_driver() will take the
parent lock unconditionally when it unbinds consumer devices. So if the
forced unbound device is on the same bus as the consumer we will
deadlock right there.

Regards,
Lucas

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web