Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp1138409ybf; Thu, 27 Feb 2020 05:45:39 -0800 (PST) X-Google-Smtp-Source: APXvYqw1XR8esntRNMjgjQCekd7wtm3WAC9PI5c4fdhtvg+4NkOS3fh4z06hLT1I7XIEpfgAmozC X-Received: by 2002:a05:6830:1011:: with SMTP id a17mr3215059otp.45.1582811138849; Thu, 27 Feb 2020 05:45:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582811138; cv=none; d=google.com; s=arc-20160816; b=XSZ4eFtOP1aicsZRKtAfWD5dAR9FAo5OIfSXEsobSHqhiCV0mJmMVdg93HdJgYTnhq rjhe75KCL3pl58CXrHoWHouDNsxDirzIm9LDvi/9s8HO5pO09uL9Nwwg8Vd+6FNQkRd3 eoPXm6WLm5EBzZ8mXM/5Gdb5+KSCIZ6WigJnRJOJC3OoGt6NtUaIjUZRlb+M30ejE7wm MTCAKaYrphoi4QVI0Ma2ddBfXS0RQmmhgG+kj9m3jC49UnqrGt5IcQG1DOPpgrEPpaKW 2dg9Egr3f6egOBt4KD0+zVflFyXagaKS2ebHUb8mNp3iDgAIhY9/fZOjTXJ45LeqIk1K mPWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=GRPhwNAOT6LXonxP8bTQbi87SyF1z0jZ6hODR5B33A0=; b=H7fEblE6goDrIT2yv9Tq/H45twectRimYjy4nTzpba2UXvrH+q4HPKxEGiqI3VCqNm +YQysiMLivx4JGb4TxYU5yoErX6gekcpaXNrfwcKEdsc8U+nuxvblTbZe7zyYnmZNMh8 jUe3j485uJfV1r6jJelqz0PpqS/2annaZuKntcGi2i81eYOrZPW83mqwOh2C10ypVywB wPWvHiNWvO2z4nMrot+PJBcxAVWMgY+SnyLWsJ5UEEbiUQSqasbgfJgteZCeJDFU0wiR b6c78vJulrtnPsIQstKe8KIfBL9DtJN/JGhv2OL+lhvuFJkeR2Ad3sEwtRT1vBbi5R+B B5xQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="vKFRfA/I"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u12si1572730otq.51.2020.02.27.05.45.27; Thu, 27 Feb 2020 05:45:38 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="vKFRfA/I"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730055AbgB0Nnw (ORCPT + 99 others); Thu, 27 Feb 2020 08:43:52 -0500 Received: from mail.kernel.org ([198.145.29.99]:39138 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730035AbgB0Nnt (ORCPT ); Thu, 27 Feb 2020 08:43:49 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 86F5B20726; Thu, 27 Feb 2020 13:43:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1582811029; bh=PM8QjGQZ2ZJUFP66loWBfd2IIb6HmzMMvFumoNXypcY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vKFRfA/IjGit7f0iORwFTbJ4pdmY7upfCiCf2zXerVrrGB1I6B2v/Xxb7ipY55FzU K9XvGTzFGYJO0ukBn/vgiuNxiNCOuAse3tEg6H7NaQo+rYCZ+N+nTFtRQz0PcrHlfV +KSe8SzMcPzTv/dfGq/Wy1AkQHqXpqyYLMHnEYi0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, EJ Hsu , Oliver Neukum Subject: [PATCH 4.4 088/113] usb: uas: fix a plug & unplug racing Date: Thu, 27 Feb 2020 14:36:44 +0100 Message-Id: <20200227132225.839694024@linuxfoundation.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200227132211.791484803@linuxfoundation.org> References: <20200227132211.791484803@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: EJ Hsu commit 3e99862c05a9caa5a27969f41566b428696f5a9a upstream. When a uas disk is plugged into an external hub, uas_probe() will be called by the hub thread to do the probe. It will first create a SCSI host and then do the scan for this host. During the scan, it will probe the LUN using SCSI INQUERY command which will be packed in the URB and submitted to uas disk. There might be a chance that this external hub with uas disk attached is unplugged during the scan. In this case, uas driver will fail to submit the URB (due to the NOTATTACHED state of uas device) and try to put this SCSI command back to request queue waiting for next chance to run. In normal case, this cycle will terminate when hub thread gets disconnection event and calls into uas_disconnect() accordingly. But in this case, uas_disconnect() will not be called because hub thread of external hub gets stuck waiting for the completion of this SCSI command. A deadlock happened. In this fix, uas will call scsi_scan_host() asynchronously to avoid the blocking of hub thread. Signed-off-by: EJ Hsu Acked-by: Oliver Neukum Cc: stable Link: https://lore.kernel.org/r/20200130092506.102760-1-ejh@nvidia.com Signed-off-by: Greg Kroah-Hartman --- drivers/usb/storage/uas.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) --- a/drivers/usb/storage/uas.c +++ b/drivers/usb/storage/uas.c @@ -46,6 +46,7 @@ struct uas_dev_info { struct scsi_cmnd *cmnd[MAX_CMNDS]; spinlock_t lock; struct work_struct work; + struct work_struct scan_work; /* for async scanning */ }; enum { @@ -115,6 +116,17 @@ out: spin_unlock_irqrestore(&devinfo->lock, flags); } +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"); +} + static void uas_add_work(struct uas_cmd_info *cmdinfo) { struct scsi_pointer *scp = (void *)cmdinfo; @@ -929,6 +941,7 @@ static int uas_probe(struct usb_interfac init_usb_anchor(&devinfo->data_urbs); spin_lock_init(&devinfo->lock); INIT_WORK(&devinfo->work, uas_do_work); + INIT_WORK(&devinfo->scan_work, uas_scan_work); result = uas_configure_endpoints(devinfo); if (result) @@ -945,7 +958,9 @@ static int uas_probe(struct usb_interfac if (result) goto free_streams; - scsi_scan_host(shost); + /* Submit the delayed_work for SCSI-device scanning */ + schedule_work(&devinfo->scan_work); + return result; free_streams: @@ -1113,6 +1128,12 @@ static void uas_disconnect(struct usb_in usb_kill_anchored_urbs(&devinfo->data_urbs); uas_zap_pending(devinfo, DID_NO_CONNECT); + /* + * 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); uas_free_streams(devinfo); scsi_host_put(shost);