All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Chugh, Sanjeev" <Sanjeev_Chugh@mentor.com>
To: Greg KH <gregkh@linuxfoundation.org>
Cc: "linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>
Subject: RE: [PATCH V1 1/1] usb: hub: introduce delay after usb hub mutex release
Date: Tue, 7 Dec 2021 05:54:06 +0000	[thread overview]
Message-ID: <361b7459f1d64f5e8b7bccaa2dd536e5@svr-ies-mbx-01.mgc.mentorg.com> (raw)
In-Reply-To: <YaoS3RoqkGkf6NFa@kroah.com>

Hello Greg,

> -----Original Message-----
> From: Greg KH [mailto:gregkh@linuxfoundation.org]
> Sent: Friday, December 3, 2021 6:22 PM
> To: Chugh, Sanjeev <Sanjeev_Chugh@mentor.com>
> Cc: linux-usb@vger.kernel.org
> Subject: Re: [PATCH V1 1/1] usb: hub: introduce delay after usb hub mutex
> release
> 
> On Wed, Dec 01, 2021 at 06:28:08AM +0530, Sanjeev Chugh wrote:
> > 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.
> 
> What is a "usb stick"?  Any usb device could cause this, right?

In my test case, I have used a usb pen drive of Sandisk Make of 32 GB capacity. But yes, any faulty usb device or even faulty usb cable used for the usb device connection can cause this issue.
> 
> > 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);
> 
> What normal code path did you just slow down here?  Why not slow down the
> disconnect path instead of the connect path?
> 
In case of faulty usb device, USB device enumeration doesn't succeed at all and comes out of hub_port_init() from a failure path. There is no device disconnection path in this flow. Therefore, this delay is added after hub_port_connect_change() is done trying to handle the port connect change event.

> thanks,
> 
> greg k-h

Thanks !

-Sanjeev

  reply	other threads:[~2021-12-07  6:01 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=361b7459f1d64f5e8b7bccaa2dd536e5@svr-ies-mbx-01.mgc.mentorg.com \
    --to=sanjeev_chugh@mentor.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-usb@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.