Linux SCSI subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Jiayi Li" <lijiayi@kylinos.cn>
Cc: linux-scsi@vger.kernel.org
Subject: Re: [PATCH v2] usb: uas: quiesce SCSI before stopping endpoints on unbind
Date: Tue, 22 Sep 2026 03:21:56 +0000	[thread overview]
Message-ID: <20260922032156.E6AC01F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260922031102.141043-1-lijiayi@kylinos.cn>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] usb: uas: 30-second hang and 100% CPU livelock on physical unplug
--

commit fb8eab9b3967bb30e72e5cba65984f12ee6267cd
Author: Jiayi Li <lijiayi@kylinos.cn>

usb: uas: quiesce SCSI before stopping endpoints on unbind

This patch reorders the teardown sequence in uas_disconnect() to remove
the SCSI host and cancel scanning before setting the resetting flag and
killing anchored URBs. The goal is to quiesce SCSI before stopping endpoints
on unbind.

Link: https://lore.kernel.org/lkml/20260920012358.3362053-1-lijiayi@kylinos.cn/

> diff --git a/drivers/usb/storage/uas.c b/drivers/usb/storage/uas.c
> index 2651629812694..971a9dc012e9b 100644
> --- a/drivers/usb/storage/uas.c
> +++ b/drivers/usb/storage/uas.c
> @@ -1217,6 +1217,14 @@ static void uas_disconnect(struct usb_interface *intf)
>  	struct uas_dev_info *devinfo = (struct uas_dev_info *)shost->hostdata;
>  	unsigned long flags;
>  
> +	/*
> +	 * Prevent SCSI scanning (if it hasn't started yet)
> +	 * or wait for the SCSI-scanning routine to stop.
> +	 */
> +	cancel_work_sync(&devinfo->scan_work);
> +
> +	scsi_remove_host(shost);
> +

[Severity: High]
Will moving scsi_remove_host() before devinfo->resetting = 1 and
uas_zap_pending() cause a 30-second hang and 100% CPU livelock on
physical unplug?

On physical unplug, usbcore detects the disconnect and calls
usb_disable_device(), which kills all active URBs with status -ESHUTDOWN
before calling uas_disconnect().

URB completion handlers like uas_stat_cmplt() handle -ESHUTDOWN by jumping
to bail, intentionally bypassing the clearing of the COMMAND_INFLIGHT flag
and leaving the SCSI commands stuck in-flight:

drivers/usb/storage/uas.c:uas_stat_cmplt() {
    ...
    if (status) {
        if (status != -ENOENT && status != -ECONNRESET && status != -ESHUTDOWN)
            dev_err(&urb->dev->dev, "stat urb: status %d\n", status);
        goto bail;
    }
    ...
}

scsi_remove_host() synchronously waits for all in-flight SCSI commands to
complete. Because the commands are stuck in-flight until uas_zap_pending()
forcefully completes them, scsi_remove_host() will block indefinitely.

During this hang, any commands in IS_IN_WORK_LIST repeatedly trigger
uas_do_work(). Since the device is detached, uas_submit_urbs() fails.
Because devinfo->resetting is still 0 at this point, the work is
unconditionally requeued:

drivers/usb/storage/uas.c:uas_do_work() {
    ...
    err = uas_submit_urbs(cmnd, cmnd->device->hostdata);
    if (!err)
        cmdinfo->state &= ~IS_IN_WORK_LIST;
    else
        queue_work(workqueue, &devinfo->work);
    ...
}

Will this cause the workqueue thread to livelock, burning 100% CPU for
30 seconds until the SCSI error handler timeout finally aborts the commands?

>  	spin_lock_irqsave(&devinfo->lock, flags);
>  	devinfo->resetting = 1;
>  	spin_unlock_irqrestore(&devinfo->lock, flags);

[ ... ]

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260922031102.141043-1-lijiayi@kylinos.cn?part=1

  reply	other threads:[~2026-09-22  3:21 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-22  3:11 [PATCH v2] usb: uas: quiesce SCSI before stopping endpoints on unbind Jiayi Li
2026-09-22  3:21 ` sashiko-bot [this message]
2026-09-22 10:05   ` Jiayi Li
2026-09-22  8:34 ` Oliver Neukum
2026-09-30  1:33   ` Jiayi Li
2026-09-30  7:22     ` Oliver Neukum
2026-10-02 12:51       ` Michal Pecio
2026-10-05 14:09         ` Oliver Neukum
2026-10-08 10:49       ` Jiayi Li

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=20260922032156.E6AC01F000FF@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=lijiayi@kylinos.cn \
    --cc=linux-scsi@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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