Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp1163270ybf; Thu, 27 Feb 2020 06:10:16 -0800 (PST) X-Google-Smtp-Source: APXvYqypbsyaRIFOlVbvhTXShrXV9SvQpU3sBFr3dUvKuCpaaKV1y+M9K3EuktFD4JLBqpfiGJE5 X-Received: by 2002:aca:1a05:: with SMTP id a5mr3458920oia.97.1582812616153; Thu, 27 Feb 2020 06:10:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582812616; cv=none; d=google.com; s=arc-20160816; b=VKMjkojxkdPwpUectWqJ9xDNqvwpXpqYicZ4xBdfJIw0uRe9UjT+YrosJyKoupP4fV GBvSsF1cFIgtXTzetoOT1Xh+j1uGn3/RETPIbH1QT5Su9gkr4W9w3dVpFQokpSj6Wd8A uQVTYOzkbLB7P2pzIRmHV9kVczc1YWgXAKZUJ3YyijW2i2trKljuBL9vd3XW5gA5AjWA /uhlIVKBYtlmsFzUeDmfQmGayqCVyRLa/I6KRaax24c0Of5Skzxy7T9IxsgqqIUSuyQo lNavHVcRUEVmDPTc44n9hIRuIXf3jb3JIx3gvGDU8aR0ZCT1yXoRqpdZf5bqGFZU7xeh U89g== 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=+urOqnHzFbSb4X9HKyly777fm2ornqo0Y/7sopH1cTA=; b=iBRzWjqpw7T8HKR0NWCwDvg7fKG8C4BJrYS8Ftqz5x78OO9pYrAyi0w6zE0uF4GRii f9xe+BWITVQxelYg9jIRlSlmo7kPf/0LfcHiajINuj8fCYLQng7Ypv0xNJjp3FAbLNnz H6RrPmc99TvtkWoQd9r9KtXg+Yhmqc7g4kxEK+/o5zZG55pyjWif8DG60gSXf8v5viR0 vGYe1kzlPPZdqxA/j8PgI5jtCSxuX324c/VRp+Wq6is+20Jlm8te8hmCKBHEvlt7oYZD CJqQWeMsyq3L5zF11x6wMZniKg78qvA41sC3EF/LlwyQluxbk57rUrqXrsL0xBeB9Jbk gTtw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=mTb8exi3; 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 j143si1324656oib.16.2020.02.27.06.09.33; Thu, 27 Feb 2020 06:10:16 -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=mTb8exi3; 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 S2388155AbgB0OHu (ORCPT + 99 others); Thu, 27 Feb 2020 09:07:50 -0500 Received: from mail.kernel.org ([198.145.29.99]:45430 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388142AbgB0OHt (ORCPT ); Thu, 27 Feb 2020 09:07: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 353BA24691; Thu, 27 Feb 2020 14:07:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1582812468; bh=C0X1eN/mQTcLrfe+YatQD403Tc0+xjgrfS0IoDO4LpY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mTb8exi3jyu/l1LAEDQIraKc2YG4nPKMX1v81vOdlBi2r7rZfE+bOAPrHJIOY5A6B P+41lf/4bpuy69DD3IIGEz8at5zDrS32MdYiVZcZkdCK21K92HSQIc/XI4HEVKcDRV cpLA4i6vQI2oK0jZd49D5mBJOWIK7Y106ye8x/Nc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, EJ Hsu , Oliver Neukum Subject: [PATCH 5.4 030/135] usb: uas: fix a plug & unplug racing Date: Thu, 27 Feb 2020 14:36:10 +0100 Message-Id: <20200227132233.626897855@linuxfoundation.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200227132228.710492098@linuxfoundation.org> References: <20200227132228.710492098@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 @@ -45,6 +45,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 { @@ -114,6 +115,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; @@ -983,6 +995,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) @@ -999,7 +1012,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: @@ -1167,6 +1182,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);