public inbox for linux-usb@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH V1 1/1] usb: hub: introduce delay after usb hub mutex release
@ 2021-12-01  0:58 Sanjeev Chugh
  2021-12-03 12:51 ` Greg KH
  0 siblings, 1 reply; 9+ messages in thread
From: Sanjeev Chugh @ 2021-12-01  0:58 UTC (permalink / raw)
  To: gregkh, linux-usb; +Cc: sanjeev_chugh

Rogue usb sticks can cause endless port connect change events
due to unstable electric connection between usb chip and
the port. Port connect change will cause device enumeration for
the new device connection and new device processing is done with
the usb hub mutex acquired. This can cause very short time gap
between unlock/lock of hub device mutex. So if some thread is
running at low priority than hub_thread, it can face hub device
mutex starvation.

This commit introduces a sleep of 25ms after the hub device mutex is
unlocked in hub_events so that if hub_thread is stuck in a
endless loop, all other threads will get fair amount of chance
to acquire the usb hub mutex.

Signed-off-by: Sanjeev Chugh <sanjeev_chugh@mentor.com>
---
 drivers/usb/core/hub.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index 00070a8..0be2acc 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -5763,6 +5763,17 @@ static void hub_event(struct work_struct *work)
 out_hdev_lock:
 	usb_unlock_device(hdev);
 
+	/*
+	 * Rogue usb sticks can cause endless device connection
+	 * events due to unstable electric connection. This
+	 * can cause very short time gap between unlock/lock
+	 * of hub device mutex thus causing mutex starvation
+	 * for some other lower priority thread. Thus sleep
+	 * would give fair chance to all other threads to
+	 * acquire the usb hub mutex.
+	 */
+	msleep(25);
+
 	/* Balance the stuff in kick_hub_wq() and allow autosuspend */
 	usb_autopm_put_interface(intf);
 	kref_put(&hub->kref, hub_release);
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2021-12-08 11:44 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-12-01  0:58 [PATCH V1 1/1] usb: hub: introduce delay after usb hub mutex release Sanjeev Chugh
2021-12-03 12:51 ` Greg KH
2021-12-07  5:54   ` Chugh, Sanjeev
2021-12-07 15:15     ` Greg KH
2021-12-08  6:58       ` Chugh, Sanjeev
2021-12-08  7:04         ` Greg KH
2021-12-08  7:26           ` Chugh, Sanjeev
2021-12-08  9:10             ` Greg KH
2021-12-08 11:44               ` Chugh, Sanjeev

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox