linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: EJ Hsu <ejh@nvidia.com>
To: Oliver Neukum <oneukum@suse.com>, Alan Stern <stern@rowland.harvard.edu>
Cc: "linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>
Subject: RE: [PATCH] usb: uas: fix a plug & unplug racing
Date: Wed, 15 Jan 2020 15:54:06 +0000	[thread overview]
Message-ID: <MN2PR12MB41262435500D3FC463DBFC32CF370@MN2PR12MB4126.namprd12.prod.outlook.com> (raw)
In-Reply-To: <1579080683.15925.24.camel@suse.com>

Oliver Neukum wrote:

> Am Dienstag, den 14.01.2020, 10:04 -0500 schrieb Alan Stern:
> >
> > No.  The discussion has gotten a little confused.  EJ's point is that
> > if SCSI scanning takes place in the context of the hub worker thread,
> > then that thread won't be available to process a disconnect
> > notification.  The device will be unplugged, but the kernel won't
> > realize it until the SCSI scanning is finished.
> 
> OK, I think we have two possible code paths at least
> 
> First:
> uas_queuecommand_lck() -> uas_submit_urbs() -> -ENODEV -> return
> SCSI_MLQUEUE_DEVICE_BUSY
> 
> That looks wrong to me.
> 
> Second:
> The submission actually works and we eventually terminate the URB with an
> error. In that case nothing happens and eventually SCSI core retries, times out
> and does error handling.
> 
Actually, the second case might happen when we connect uas disk directly to 
root hub. In this case, the root hub thread got stuck waiting for the completion
of the scsi command. It might not be able to handle the disconnection event
and set uas disk state to USB_STATE_NOTATTACHED accordingly.

So, the URB submission in uas driver works but nothing happens, and scsi layer
will time out this operation and retry it several times. Eventually the root hub 
thread will continue to run when it got the result from scsi layer. But the whole
process might take about 60 seconds.

That's another reason why I would like to run scsi_scan_host() asynchronously
and keep the hub thread free.

> > In my opinion, if scsi_scan_host() will be run asynchronously, this 
> > interface needs to be guarded against runtime PM between uas_probe() & uas_scan_work().
> Yes it does. But it has a child, the SCSI host, which has an elevated count. It is already guarded.

I just checked the code, and the reference count will be incremented in scsi_scan_host(), 
precisely speaking, in scsi_autopm_get_host().
So, I still think we need to manually add reference count of interface here.
Please correct me if there is anything wrong.

Thanks,
EJ
-----------------------------------------------------------------------------------
This email message is for the sole use of the intended recipient(s) and may contain
confidential information.  Any unauthorized review, use, disclosure or distribution
is prohibited.  If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.
-----------------------------------------------------------------------------------

  parent reply	other threads:[~2020-01-15 15:54 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-13  3:30 [PATCH] usb: uas: fix a plug & unplug racing EJ Hsu
2020-01-13  9:44 ` Oliver Neukum
2020-01-13 15:21   ` Alan Stern
2020-01-14  3:28   ` EJ Hsu
2020-01-14 14:41     ` Oliver Neukum
2020-01-14 15:04       ` Alan Stern
2020-01-15  9:31         ` Oliver Neukum
2020-01-15 15:17           ` Alan Stern
2020-01-15 15:54           ` EJ Hsu [this message]
2020-01-20  9:38             ` Oliver Neukum
2020-01-21 11:29               ` EJ Hsu
2020-01-22  9:52                 ` EJ Hsu

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=MN2PR12MB41262435500D3FC463DBFC32CF370@MN2PR12MB4126.namprd12.prod.outlook.com \
    --to=ejh@nvidia.com \
    --cc=linux-usb@vger.kernel.org \
    --cc=oneukum@suse.com \
    --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).