2.6.15-mm4: sem2mutex problem in USB OHCI
Subsystems (5)
Hi,
I get this on the system startup (Asus L5D, x86-64, 1 CPU):
ACPI: PCI Interrupt Link [LUS1] enabled at IRQ 11
ACPI: PCI Interrupt 0000:00:02.1[B] -> Link [LUS1] -> GSI 11 (level, low) -> IRQ 11 ohci_hcd 0000:00:02.1: OHCI Host Controllerohci_hcd 0000:00:02.1: new USB bus registered, assigned bus number 2 ohci_hcd 0000:00:02.1: irq 11, io mem 0xfebfc000
usb usb2: Product: OHCI Host Controller
usb usb2: Manufacturer: Linux 2.6.15-mm4 ohci_hcd
Badness in __mutex_trylock_slowpath at kernel/mutex.c:281
Call Trace: <IRQ> <ffffffff80148d8d>{mutex_trylock+141}
<ffffffff880abaf0>{:ohci_hcd:ohci_hub_status_data+480}
<ffffffff802d25d0>{rh_timer_func+0} <ffffffff802d24c3>{usb_hcd_poll_rh_status+67}
<ffffffff802d25d0>{rh_timer_func+0} <ffffffff802d25d9>{rh_timer_func+9}
<ffffffff8013a3cc>{run_timer_softirq+396} <ffffffff801361c0>{__do_softirq+80}
<ffffffff8010fd12>{call_softirq+30} <ffffffff80111715>{do_softirq+53}
<ffffffff8013625f>{irq_exit+63} <ffffffff80111761>{do_IRQ+65}
<ffffffff8010f266>{ret_from_intr+0} <EOI> <ffffffff80130c1d>{release_console_sem+333}
<ffffffff801313f7>{vprintk+775} <ffffffff801314f2>{printk+162}
<ffffffff801314f2>{printk+162} <ffffffff802d5b0b>{usb_cache_string+139}
<ffffffff802cd170>{show_string+64} <ffffffff802ceec5>{usb_new_device+261}
<ffffffff802d3769>{usb_add_hcd+1433} <ffffffff802dce83>{usb_hcd_pci_probe+691}
<ffffffff8025a26a>{pci_device_probe+106} <ffffffff802b556c>{driver_probe_device+108}
<ffffffff802b5636>{__driver_attach+86} <ffffffff802b55e0>{__driver_attach+0}
<ffffffff802b4eef>{bus_for_each_dev+79} <ffffffff802b53fc>{driver_attach+28}
<ffffffff802b48e8>{bus_add_driver+136} <ffffffff802b57af>{driver_register+207}
<ffffffff8025a521>{__pci_register_driver+177} <ffffffff88012059>{:ohci_hcd:ohci_hcd_pci_init+89}
<ffffffff8014f7af>{sys_init_module+239} <ffffffff8010ec9e>{system_call+126}ohci_hcd 0000:00:02.0: suspend root hub
usb usb2: SerialNumber: 0000:00:02.1
usb usb2: uevent
usb usb2: device is self-powered
usb usb2: configuration #1 chosen from 1 choice
usb usb2: adding 2-0:1.0 (config #1, interface 0)
This happens every time the system starts and it sometimes leaves a dead khubd.
Greetings,
Rafael
Quoted 22 lines · Rafael J. Wysocki
I get this on the system startup (Asus L5D, x86-64, 1 CPU):
ACPI: PCI Interrupt Link [LUS1] enabled at IRQ 11
ACPI: PCI Interrupt 0000:00:02.1[B] -> Link [LUS1] -> GSI 11 (level, low) -> IRQ 11ohci_hcd0000:00:02.1: OHCI Host Controller
ohci_hcd0000:00:02.1: new USB bus registered, assigned bus number 2ohci_hcd0000:00:02.1: irq 11, io mem0xfebfc000
usb usb2: Product: OHCI Host Controller
usb usb2: Manufacturer: Linux 2.6.15-mm4ohci_hcd
Badness in__mutex_trylock_slowpathatkernel/mutex.c:281Call Trace: <IRQ> <ffffffff80148d8d>{mutex_trylock+141} <ffffffff880abaf0>{:ohci_hcd:ohci_hub_status_data+480} <ffffffff802d25d0>{rh_timer_func+0} <ffffffff802d24c3>{usb_hcd_poll_rh_status+67} <ffffffff802d25d0>{rh_timer_func+0} <ffffffff802d25d9>{rh_timer_func+9} <ffffffff8013a3cc>{run_timer_softirq+396} <ffffffff801361c0>{__do_softirq+80} <ffffffff8010fd12>{call_softirq+30} <ffffffff80111715>{do_softirq+53} <ffffffff8013625f>{irq_exit+63} <ffffffff80111761>{do_IRQ+65} <ffffffff8010f266>{ret_from_intr+0} <EOI> <ffffffff80130c1d>{release_console_sem+333} <ffffffff801313f7>{vprintk+775} <ffffffff801314f2>{printk+162} <ffffffff801314f2>{printk+162} <ffffffff802d5b0b>{usb_cache_string+139}
Quoted 8 lines
<ffffffff802cd170>{show_string+64} <ffffffff802ceec5>{usb_new_device+261}
<ffffffff802d3769>{usb_add_hcd+1433} <ffffffff802dce83>{usb_hcd_pci_probe+691}
<ffffffff8025a26a>{pci_device_probe+106} <ffffffff802b556c>{driver_probe_device+108}
<ffffffff802b5636>{__driver_attach+86} <ffffffff802b55e0>{__driver_attach+0}
<ffffffff802b4eef>{bus_for_each_dev+79} <ffffffff802b53fc>{driver_attach+28}
<ffffffff802b48e8>{bus_add_driver+136} <ffffffff802b57af>{driver_register+207}
<ffffffff8025a521>{__pci_register_driver+177} <ffffffff88012059>{:ohci_hcd:ohci_hcd_pci_init+89}
<ffffffff8014f7af>{sys_init_module+239} <ffffffff8010ec9e>{system_call+126}err, taking a mutex from softirq context.
Quoted 7 lines · Andrew Morton
Quoted 5 lines
Badness in
__mutex_trylock_slowpathatkernel/mutex.c:281Call Trace: <IRQ> <ffffffff80148d8d>{mutex_trylock+141} <ffffffff880abaf0>{:ohci_hcd:ohci_hub_status_data+480} <ffffffff802d25d0>{rh_timer_func+0} <ffffffff802d24c3>{usb_hcd_poll_rh_status+67}err, taking a mutex from softirq context.
hm. For now, the patch below undoes the struct device ->mutex conversion.
Ingo
--
undo struct device ->mutex conversion, the USB code uses it from softirq context.
----
drivers/base/bus.c | 16 ++++++++-------- drivers/base/core.c | 2 +- drivers/base/dd.c | 36 ++++++++++++++++++------------------ drivers/base/power/resume.c | 4 ++-- drivers/base/power/suspend.c | 4 ++-- drivers/usb/core/hub.c | 8 ++++---- include/linux/device.h | 2 +- include/linux/usb.h | 6 +++--- 8 files changed, 39 insertions(+), 39 deletions(-)
drivers/base/bus.c +8 -8
@@ -153,10 +153,10 @@ static ssize_t driver_unbind(struct devi dev =bus_find_device (bus,NULL , (void *)buf, driver_helper);if (dev && dev->driver == drv) {if (dev->parent)/* Needed for USB */ -mutex_lock (&dev->parent->mutex); +down (&dev->parent->sem);device_release_driver (dev);if (dev->parent) -mutex_unlock (&dev->parent->mutex); +up (&dev->parent->sem); err = count; }put_device (dev);
@@ -180,12 +180,12 @@ static ssize_t driver_bind(struct device dev =bus_find_device (bus,NULL , (void *)buf, driver_helper);if (dev && dev->driver ==NULL ) {if (dev->parent)/* Needed for USB */ -mutex_lock (&dev->parent->mutex); -mutex_lock (&dev->mutex); +down (&dev->parent->sem); +down (&dev->sem); err =driver_probe_device (drv, dev); -mutex_unlock (&dev->mutex); +up (&dev->sem);if (dev->parent) -mutex_unlock (&dev->parent->mutex); +up (&dev->parent->sem); }put_device (dev);put_bus (bus);
@@ -512,10 +512,10 @@ static int bus_rescan_devices_helper(str {if (!dev->driver) {if (dev->parent)/* Needed for USB */ -mutex_lock (&dev->parent->mutex); +down (&dev->parent->sem);device_attach (dev);if (dev->parent) -mutex_unlock (&dev->parent->mutex); +up (&dev->parent->sem); }return 0 ; }
drivers/base/core.c +1 -1
@@ -231,7 +231,7 @@ void device_initialize(struct device *deklist_init (&dev->klist_children, klist_children_get, klist_children_put);INIT_LIST_HEAD (&dev->dma_pools); -mutex_init (&dev->mutex); +init_MUTEX (&dev->sem);device_init_wakeup (dev,0 ); }
drivers/base/dd.c +18 -18
@@ -36,7 +36,7 @@* for before calling this. (It is ok to call with no other effort * from a driver's probe() method.) * -* This function must be called with @dev->mutex held. +* This function must be called with @dev->sem held. */ void device_bind_driver (struct device * dev) {
@@ -65,8 +65,8 @@ void device_bind_driver(struct device ** This function returns 1 if a match is found, an error if one * occurs (that is not -ENODEV or -ENXIO), and 0 otherwise. * -* This function must be called with @dev->mutex held. When called -* for a USB interface, @dev->parent->mutex must be held as well. +* This function must be called with @dev->sem held. When called +* for a USB interface, @dev->parent->sem must be held as well. */ int driver_probe_device (struct device_driver * drv,struct device * dev) {
@@ -131,19 +131,19 @@ static int __device_attach(struct device* Returns 1 if the device was bound to a driver; * 0 if no matching device was found; error code otherwise. * -* When called for a USB interface, @dev->parent->mutex must be held. +* When called for a USB interface, @dev->parent->sem must be held. */ int device_attach (struct device * dev) {int ret =0 ; -mutex_lock (&dev->mutex); +down (&dev->sem);if (dev->driver) {device_bind_driver (dev); ret =1 ; }else ret =bus_for_each_drv (dev->bus,NULL , dev, __device_attach); -mutex_unlock (&dev->mutex); +up (&dev->sem);return ret; }
@@ -162,13 +162,13 @@ static int __driver_attach(struct device*/ if (dev->parent)/* Needed for USB */ -mutex_lock (&dev->parent->mutex); -mutex_lock (&dev->mutex); +down (&dev->parent->sem); +down (&dev->sem);if (!dev->driver)driver_probe_device (drv, dev); -mutex_unlock (&dev->mutex); +up (&dev->sem);if (dev->parent) -mutex_unlock (&dev->parent->mutex); +up (&dev->parent->sem);return 0 ; }
@@ -193,8 +193,8 @@ void driver_attach(struct device_driver* * Manually detach device from driver. * -* __device_release_driver() must be called with @dev->mutex held. -* When called for a USB interface, @dev->parent->mutex must be held +* __device_release_driver() must be called with @dev->sem held. +* When called for a USB interface, @dev->parent->sem must be held * as well. */
@@ -225,9 +225,9 @@ void device_release_driver(struct device* within their ->remove callback for the same device, they * will deadlock right here. */ -mutex_lock (&dev->mutex); +down (&dev->sem);__device_release_driver (dev); -mutex_unlock (&dev->mutex); +up (&dev->sem); }
@@ -251,13 +251,13 @@ void driver_detach(struct device_driverspin_unlock (&drv->klist_devices.k_lock);if (dev->parent)/* Needed for USB */ -mutex_lock (&dev->parent->mutex); -mutex_lock (&dev->mutex); +down (&dev->parent->sem); +down (&dev->sem);if (dev->driver == drv)__device_release_driver (dev); -mutex_unlock (&dev->mutex); +up (&dev->sem);if (dev->parent) -mutex_unlock (&dev->parent->mutex); +up (&dev->parent->sem);put_device (dev); } }
drivers/base/power/resume.c +2 -2
@@ -24,7 +24,7 @@ int resume_device(struct device * dev) {int error =0 ; -mutex_lock (&dev->mutex); +down (&dev->sem);if (dev->power.pm_parent && dev->power.pm_parent->power.power_state.event) { dev_err(dev, "PM: resume from %d, parent %s still %d\n",
@@ -36,7 +36,7 @@ int resume_device(struct device * dev)dev_dbg (dev,"resuming\n" ); error = dev->bus->resume (dev); } -mutex_unlock (&dev->mutex); +up (&dev->sem);return error; }
drivers/base/power/suspend.c +2 -2
@@ -39,7 +39,7 @@ int suspend_device(struct device * dev, {int error =0 ; -mutex_lock (&dev->mutex); +down (&dev->sem);if (dev->power.power_state.event) {dev_dbg (dev,"PM: suspend %d-->%d\n" , dev->power.power_state.event, state.event);
@@ -59,7 +59,7 @@ int suspend_device(struct device * dev,dev_dbg (dev,"suspending\n" ); error = dev->bus->suspend (dev, state); } -mutex_unlock (&dev->mutex); +up (&dev->sem);return error; }
drivers/usb/core/hub.c +4 -4
@@ -33,8 +33,8 @@#include "hub.h" /* Protect struct usb_device->state and ->children members -* Note: Both are also protected by ->dev.mutex, except that ->state can -* change to USB_STATE_NOTATTACHED even when the mutex isn't held. */ +* Note: Both are also protected by ->dev.sem, except that ->state can +* change to USB_STATE_NOTATTACHED even when the semaphore isn't held. */ static DEFINE_SPINLOCK (device_state_lock);/* khubd's worklist and its lock */
@@ -1786,9 +1786,9 @@ static int finish_device_resume(struct ustruct device *dev = &udev->actconfig->interface[i]->dev; -mutex_lock (&dev->mutex); +down (&dev->sem); (void )resume (dev); -mutex_unlock (&dev->mutex); +up (&dev->sem); } status =0 ;
include/linux/device.h +1 -1
@@ -314,7 +314,7 @@ struct device {char bus_id[BUS_ID_SIZE ];/* position on parent bus */ struct device_attribute uevent_attr; -struct mutex mutex;/* semaphore to synchronize calls to +struct semaphore sem;/* semaphore to synchronize calls to * its driver. */
include/linux/usb.h +3 -3
@@ -379,9 +379,9 @@ extern struct usb_device *usb_get_dev(stextern void usb_put_dev (struct usb_device *dev);/* USB device locking */ -#define usb_lock_device (udev) mutex_lock(&(udev)->dev.mutex) -#define usb_unlock_device (udev) mutex_unlock(&(udev)->dev.mutex) -#define usb_trylock_device (udev) mutex_trylock(&(udev)->dev.mutex) +#define usb_lock_device (udev) down(&(udev)->dev.sem) +#define usb_unlock_device (udev) up(&(udev)->dev.sem) +#define usb_trylock_device (udev) down_trylock(&(udev)->dev.sem)extern int usb_lock_device_for_reset (struct usb_device *udev,struct usb_interface *iface);
Quoted 5 lines · Ingo Molnar
Quoted 2 lines · Andrew Morton
Quoted 2 lines
Badness in
__mutex_trylock_slowpathatkernel/mutex.c:281
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Call Trace: <IRQ> <ffffffff80148d8d>{mutex_trylock+141} <ffffffff880abaf0>{:ohci_hcd:ohci_hub_status_data+480} <ffffffff802d25d0>{rh_timer_func+0} <ffffffff802d24c3>{usb_hcd_poll_rh_status+67}err, taking a mutex from softirq context.
hm. For now, the patch below undoes the struct device ->mutex conversion.
That helps, thanks.
Rafael
Quoted 5 lines · Ingo Molnar
Quoted 2 lines · Andrew Morton
Quoted 2 lines
Badness in
__mutex_trylock_slowpathatkernel/mutex.c:281
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Call Trace: <IRQ> <ffffffff80148d8d>{mutex_trylock+141} <ffffffff880abaf0>{:ohci_hcd:ohci_hub_status_data+480} <ffffffff802d25d0>{rh_timer_func+0} <ffffffff802d24c3>{usb_hcd_poll_rh_status+67}err, taking a mutex from softirq context.
hm. For now, the patch below undoes the struct device ->mutex conversion.
I've dropped the whole driver mutex patch from my tree till stuff like this gets worked out.
thanks,
greg k-h
Quoted 10 lines · Andrew Morton
Quoted 8 lines
Badness in
__mutex_trylock_slowpathatkernel/mutex.c:281Call Trace: <IRQ> <ffffffff80148d8d>{mutex_trylock+141}<ffffffff880abaf0>{:ohci_hcd:ohci_hub_status_data+480} <ffffffff802d25d0>{rh_timer_func+0} <ffffffff802d24c3>{usb_hcd_poll_rh_status+67} <ffffffff802d25d0>{rh_timer_func+0} <ffffffff802d25d9>{rh_timer_func+9} <ffffffff8013a3cc>{run_timer_softirq+396}err, taking a mutex from softirq context.
btw., i'm wondering how the down_trylock() can be correct code: what guarantees progress if the trylock happens to fail all the time? (or just happens to fail frequently, due to some other, unrelated dev->mutex workload)
Shouldnt this code use some other solution to process these timed events more robustly?
Ingo