lkml.org 
[lkml]   [2013]   [Dec]   [31]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Date
Subject[PATCH] usb: hub: Avoid tight loop holding hdev lock
Hi All,

I was facing an issue bad usb device which was affecting other system. Kernel was trying to enumerate the device but it was failing continuously. Unfortunately that device was on mounted onboard in the platform so I cannot remove it.
The continuous re-enumeration of the device causing other application malfunctioning which were using libusb. I found that usb_find_devices() call was stuck in usb_open for very long time. It was stuck in getting device lock which was taken in hub_event thread.
Solution was to add msleep in the loop to prevent is spinning tightly.

---------------------------------------------------------------------------
usb: hub: Avoid tight loop holding hdev lock

Other system call(like usb_open) to root port device
starved in getting device lock when the while loop
in hub_event loops tightly because of misbehaving device.

Adding a small msleep provides chance to system calls to
schedule.

The issue was returning -EPROTO and re-enumerating with
continuous hub_events. That was makes the while loop in
hub_event to spin tightly.

usb_find_devices call from libusb tries to open all devices
including root hub. The call to usb_open stuck for very
long time(sometimes forever) because the priority of
kernel thread is higher than that system call in this case.

Signed-off-by: Manoj Chourasia <mchourasia@nvidia.com>

diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index c5c3667..b968fd5 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -4899,6 +4899,9 @@ static void hub_events(void)
usb_unlock_device(hdev);
kref_put(&hub->kref, hub_release);

+ /* preventing tight loop holding hdev lock */
+ msleep(20);
+
} /* end while (1) */
}

-Regards
Manoj


\
 
 \ /
  Last update: 2013-12-31 10:21    [W:0.096 / U:0.104 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site