Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp1186618ybf; Thu, 27 Feb 2020 06:30:50 -0800 (PST) X-Google-Smtp-Source: APXvYqy6Y3WFOWikE0z0+iE3wW5MOmK7C775MZ3mNqCQfwTB+tIVBeeYlzXYjDAliO+xU8OOzysV X-Received: by 2002:a54:4106:: with SMTP id l6mr3478695oic.76.1582813850603; Thu, 27 Feb 2020 06:30:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582813850; cv=none; d=google.com; s=arc-20160816; b=eh0bS5Jx3n/ZJCun4SP3h0i+eeBTEGh0BUaieyXgzCX7kdmncrw11Ub/FvRAI+7IiL yiRx7MYw0O7xTYLVBTpdrz9x/BaIIZUfBkraGdu6TnyI8Gjeblxv4MJmN0lioFrSyHFI iKQeOjeDN1dlHHWm/UmvGlPzG4CWeIKWkpVQoiuPjqjz3cdT1FM3FbZ6y9pyqQjHXDDe eUEHjR6oPW+q6zDd7OcPut2dmJe3yi6COrwmXppNNMIegkyUMllqs4JJ1RLpT24wNtof 9nDhZkKNlt2JPmiMZ93rt7Ize3Ma+hRL6hnXF2GXLJ3TCWOdR79Ifu1uq6grMysyZzNL yrDQ== 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=nPUKfKZyhRtJUCUU/3XnemmhP90CJdoQDCNwZ7pSh4g=; b=KgjN/SC1GhHBSJ8e+8gz9P48djAKLgROe3nfWPYaOYul0TkvwWwNY3r81xCPn9b9VM PKv0TPruSpL8BorAoAzPneEV/5zuKcazybz2kLUzEkd1REX1lwxkPwWMSrLxq3pIhZd9 HDsalNOP8K/S5EyelpT7lGIaVfJfsfNYtws2dg3VKADIfLcP3oRy8Mjmiyl4e+DYGNZZ TpsnQN6gg0Ayx+kfSzmSRnNPCuGU+RvAASvk/ha+3RDGB1xOBcqoZ+HX2ZgeUKk3BmFb nW3svDHxiVEWhcH1FYNDklkoAH0nDU+R+HRRklEqUKFeHA+nm9vDK05e3Dr9xt5so2tg ZNyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=T+HrSZPh; 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 p130si1337208oic.121.2020.02.27.06.30.37; Thu, 27 Feb 2020 06:30:50 -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=T+HrSZPh; 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 S2388139AbgB0Oab (ORCPT + 99 others); Thu, 27 Feb 2020 09:30:31 -0500 Received: from mail.kernel.org ([198.145.29.99]:41538 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387681AbgB0OFC (ORCPT ); Thu, 27 Feb 2020 09:05:02 -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 2374221556; Thu, 27 Feb 2020 14:05:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1582812301; bh=CBMXw+38mqPuPcQ9A4DFjWNoaR2m8fqUgC/cv4EKKWg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=T+HrSZPh9ynUWb4/+8BSSEnmZiYw29hONfdNE7FL+PrnWSm/VdXi730t5XIbz0/RV tdOTUJCw1cCGHthURtouX2kWqY33MkJAp35pQa+ITAJ1WjKwpaNwkmSgwgSiTIKDO2 TIs6CyVG0eVtzUeqoKBO61n5NWW2Kx0f8+o2by5A= 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.19 25/97] usb: uas: fix a plug & unplug racing Date: Thu, 27 Feb 2020 14:36:33 +0100 Message-Id: <20200227132218.714023705@linuxfoundation.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200227132214.553656188@linuxfoundation.org> References: <20200227132214.553656188@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; @@ -989,6 +1001,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) @@ -1005,7 +1018,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: @@ -1173,6 +1188,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);