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

Oliver Neukum wrote:

> Am Sonntag, den 12.01.2020, 19:30 -0800 schrieb EJ Hsu:
> 
> Isn't that the bug? A command to a detached device should fail.
> Could you please elaborate? This issue would not be limited to uas.
> 
In the case I mentioned, the hub thread of external hub running 
uas_probe() will get stuck waiting for the completion of scsi scan. 

The scsi scan will try to probe a single LUN using a SCSI INQUIRY.
If the external hub has been unplugged before LUN probe, the device 
state of uas device will be set to USB_STATE_NOTATTACHED by the 
root hub thread. So, all the following calls to usb_submit_urb() in 
uas driver will return -NODEV, and accordingly uas_queuecommand_lck() 
will return SCSI_MLQUEUE_DEVICE_BUSY to scsi_request_fn().

scsi_request_fn() then puts this scsi command back into request queue.
Because this scsi device is just created and during LUN probe process, 
this scsi command is the only one in the request queue. So, it will be picked
up soon and dispatched to uas driver again. This cycle will continue until
uas_disconnect() is called and its "resetting" flag is set. However, the 
hub thread of external hub still got stuck waiting for the completion of
this scsi command, and may not be able to run uas_disconnect(). 
A deadlock happened.

> > +static void uas_scan_work(struct work_struct *work) {
> > +     struct uas_dev_info *devinfo =
> > +             container_of(work, struct uas_dev_info, scan_work);
> > +     struct Scsi_Host *shost = usb_get_intfdata(devinfo->intf);
> > +
> > +     dev_dbg(&devinfo->intf->dev, "starting scan\n");
> > +     scsi_scan_host(shost);
> > +     dev_dbg(&devinfo->intf->dev, "scan complete\n");
> > +
> > +     usb_autopm_put_interface(devinfo->intf);
> 
> scsi_scan_host() does runtime PM on the SCSI level. There is no need for us to
> duplicate that.
>

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().
 
> 
> It is not enough to do this in disconnect() We are guarded against runtime PM,
> but not against system sleep.
> You'd need to handle this in suspend() and resume(), too.
> And, unfortunately, the device could be reset from another interface.
> 

As Allen said, this is a copy of the way usb-storage works and I did not see any
related protection in usb-storage. But I will do more check on it. 

Thanks,
EJ
--nvpublic

  parent reply	other threads:[~2020-01-14  3:28 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 [this message]
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
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=MN2PR12MB4126334FBC97B5AC4CC442AECF340@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).