Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp1180241ybf; Thu, 27 Feb 2020 06:25:06 -0800 (PST) X-Google-Smtp-Source: APXvYqwxX7CN2S25jqEA2rzo8B9oKbmAwREsznh24wYGksZ7WUPo5id8iGbNPOZeAQe4Z6PMDPkY X-Received: by 2002:a05:6830:2159:: with SMTP id r25mr3463077otd.352.1582813506274; Thu, 27 Feb 2020 06:25:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582813506; cv=none; d=google.com; s=arc-20160816; b=Zy64T6fUWkJeS4n6Pbqlv93bAdo6zBSkhA5ZOhLWLPgxCkTTPruarpHKLQYoD+jiAe IiNw3zjRCV3MQnPRhhDbA0dD/tq/t/N0CLaB4j7Kmx6VXUaxkshe8dHEK9HBmkfybukQ qiI1nn95czT3rt2eJqcVkDzoaallXzp4XeZlFkHqpPwORPz5Cd6rkFWZQyFEeQ6s4q08 tMnOVo4fblfK2NkNFA5MqBuDa/kD5b1wWN+dgyN9fRjcIZft1iegWlg8sOYoX5qqulDT ILrbtr1XxYPcUHuM5HkzT63zDuAZ681OlCWQJMzrxJs+jHK4nuifrM37b0nvHA5kTto6 GqZw== 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=Dc8Pvnv/XOBs8T6G4VdUziZkD1yBrUwgPl/Q/W4aR+I=; b=l3P9ozCsGteTup+YYf2ltp/BS4xfgE0pjqhJ06rWEnNzCKiGdVNNlLlKY+frmjEV9D 2oH5fYZQHVJhzj8dvgmDIFCSsMLoaDmzEIY0QD1RyJjidUX50ywfWiDTF0f6I0mcsS57 lRvNcZEcOr56hsjnmx3IFjN3PHlpbHprQbj+xFBjkAtd+FTzz1SNAHPcg4C4UyV5ks/U VZYYejOrHuXyODz+jNPHTmWkTcGpkmCOUBVjUXDqpdttP+L0fG+CXj2mzch3b1dUjR5j Be7jCQAXU/0gJogsV0vnH9mh03J10B7okCxyHENVuB0UMtvIKKU/vq/zlTVJJ/WWNxSN 5c3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=SUTSps8K; 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 d125si1273747oia.86.2020.02.27.06.24.53; Thu, 27 Feb 2020 06:25:06 -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=SUTSps8K; 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 S2389064AbgB0OOD (ORCPT + 99 others); Thu, 27 Feb 2020 09:14:03 -0500 Received: from mail.kernel.org ([198.145.29.99]:53082 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389056AbgB0OOB (ORCPT ); Thu, 27 Feb 2020 09:14:01 -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 80D9220801; Thu, 27 Feb 2020 14:14:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1582812841; bh=PdxD+UsOCm92zdrHfwVzToyI5Itmc/7U/eA+Aed9TJE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SUTSps8KEvndpazxbjdyuHNCjc0TdvKHhC8wRWwgD7rp+NmcdNF4rhefHFfXhixKL S0xjR0asFNhfxher4Fz87WkkwKiIHA2TkvQJOGUXL11b7v2VqHylRZh94xbXpUaL8q Y/N8rbLA4HINQ9PHstnbHnNb1n7cf+EX6gINS+8o= 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.5 037/150] usb: uas: fix a plug & unplug racing Date: Thu, 27 Feb 2020 14:36:14 +0100 Message-Id: <20200227132238.261820299@linuxfoundation.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200227132232.815448360@linuxfoundation.org> References: <20200227132232.815448360@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; @@ -982,6 +994,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) @@ -998,7 +1011,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: @@ -1166,6 +1181,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);