linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: martin_liu <liumartin@google.com>
To: Alan Stern <stern@rowland.harvard.edu>
Cc: gregkh@linuxfoundation.org, linux-usb@vger.kernel.org,
	linux-kernel@vger.kernel.org, jenhaochen@google.com
Subject: [RFC] driver core: don't hold dev's parent lock when using async probe
Date: Fri, 25 May 2018 00:05:32 +0800	[thread overview]
Message-ID: <20180524160532.GA4803@google.com> (raw)

On Thu, May 24, 2018 at 11:02:57AM -0400, Alan Stern wrote:
> On Thu, 24 May 2018, Martin Liu wrote:
> 
> > On Tue, May 22, 2018 at 01:09:44PM -0400, Alan Stern wrote:
> > > On Tue, 22 May 2018, martin_liu wrote:
> > > 
> > > > not sure if we still need 'bf74ad5bc417 ("[PATCH] Hold the
> > > > device's parent's lock during probe and remove")' since it has
> > > > been there over 10 years. If we still need it and hard to fix it
> > > > , the simple way is to find a place not to allow USB subsystem
> > > > drivers to have async probe capability. Any suggestion is welcome.
> > > 
> > > I don't think the "allows_async_probing" attribute is the best way to 
> > > attack this.  Some other approach, like a special-purpose flag, might 
> > > be better.
> > > 
> > > Yes, USB still needs to have parent's locks held during probing.  
> > > Here's the reason.  A USB device can have multiple interfaces, each
> > > bound to its own driver.  A driver may sometimes need to issue a reset,
> > > but in USB there's no way to reset a single interface.  Only the entire
> > > device can be reset, and of course this affects all the interfaces.  
> > > Therefore a driver needs to acquire the device lock before it can issue
> > > a reset.
> > > 
> > > The problem is that the driver's thread may already hold the device
> > > lock.  During a normal probe sequence, for example, the interfaces get
> > > probed by the hub driver while it owns the device lock.  But for probes
> > > under other circumstances (for example, if the user writes to the
> > > driver's "bind" attribute in sysfs), the device lock might not be held.
> > > 
> > > A driver cannot tell these two cases apart.  The only way to make it
> > > work all the time is to have the caller _always_ hold the device lock
> > > while the driver is probed (or the removed, for that matter).
> > > 
> > > Alan Stern
> > 
> > Thanks for the reply and more detail about the backgroud. I'd like to
> > have a conclusion about it. Please kindly correct me if my understanding
> > is wrong. Regarding to the "special-purpose flag", do you mean we could
> > find a place in USB subsystem to have the flag set (not sure if it's
> > easy to find it). Driver core would be base on the flag to decide if we
> > need to hold the device's parent's lock.
> 
> Yes, except that the flag would not be in the USB subsystem.  It would 
> be in the device, device_type, or bus_type structure, so that the 
> driver core could access it.
> 
> Alan Stern

Thanks for the quick feedback and the suggestion. will try to figure out how
it works.

Martin
---
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

             reply	other threads:[~2018-05-24 16:05 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-24 16:05 martin_liu [this message]
  -- strict thread matches above, loose matches on Subject: below --
2018-05-24 15:02 [RFC] driver core: don't hold dev's parent lock when using async probe Alan Stern
2018-05-24 14:00 martin_liu
2018-05-22 17:09 Alan Stern
2018-05-22 14:12 martin_liu

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=20180524160532.GA4803@google.com \
    --to=liumartin@google.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jenhaochen@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=stern@rowland.harvard.edu \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).