Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp274954ybi; Wed, 29 May 2019 21:10:16 -0700 (PDT) X-Google-Smtp-Source: APXvYqwu6oAEmQzqF2srw/GN4gbVaur2xHUoTbM/AsiKhYZ6cq5JyFNdHwkPnKVS3gz1+jz7ZxtV X-Received: by 2002:a63:eb01:: with SMTP id t1mr1848000pgh.385.1559189416624; Wed, 29 May 2019 21:10:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559189416; cv=none; d=google.com; s=arc-20160816; b=Hj5xAh9cyCzJOu3pJA5f8kiLdZqIkikNSG2vmrT4K7RQzpA6jn+Bi3eg+0xssNPhjj cK4RdswCDfaj//u3yFW2TL7wvYbOVi2UAaxoEFcpNhUfJTc7sVZdUVP0a7AiqEzMNUgq seVEKDMFa+nzZGnqYa4XgfmzYrigTdBFF6pnelPgtmzTlDwFw7Zn8XB+n5iBc4J8x6+k O2XDHpmfRdVIi8q7liQAEcSBz8tw/lYN6LCIaEjR+m+hkA6On6xGG4nEHDlmZJLb3xRN Rd8NxAtwLBnKpZO1QVMRHR7y1EMmN+gRVW1kgY3AcImhfV/tA3G05XTD2KTOaM8BD9gx YxbQ== 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=g6AnKD7rmE02h2MN79yjQnwUCvC11J/8kXnEG3HPOEc=; b=ooUcETxxjH9g/E9aN+RDfXTq3L3CY7x5LiLE5uFCqZX+XiioWSnPf1pMP2Z+ARrfsL MVFUv6DU6WqiItbY0Zuw0Dc+YCoazm9+CL0djHTeY8mMj9Yc9/Vd2iYFJ73r3FZJPVsh ZKwzbOfZet55jXHI8ZglU2ig/kKc6OML2FOT5G9XJSv20SC4W0brAAfRTXBGG6vP1wIp 7gYYOSTVD5l7HaB600H8GKQ28hRp8HWTkAoyJuFcXxMDbpH8ddbT/3e3QD8ihszNdw6m LlYwsKlZ9FEFw6XIt17RGD1wgOCBGw+9JYe7G00q2ziLoenRdfT1qhdAxlR5wVrRLMpq mxFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="Tt7ICHx/"; 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 r4si1932646pgv.195.2019.05.29.21.10.00; Wed, 29 May 2019 21:10:16 -0700 (PDT) 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="Tt7ICHx/"; 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 S1727092AbfE3EI6 (ORCPT + 99 others); Thu, 30 May 2019 00:08:58 -0400 Received: from mail.kernel.org ([198.145.29.99]:45724 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729604AbfE3DRQ (ORCPT ); Wed, 29 May 2019 23:17:16 -0400 Received: from localhost (ip67-88-213-2.z213-88-67.customer.algx.net [67.88.213.2]) (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 E91072469A; Thu, 30 May 2019 03:17:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1559186236; bh=hxuXXHTvzgUj7YqUKc0PqJtHCFmn+Jx2bJpcqbbrPys=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Tt7ICHx/sj8OLG4uNWzDecOiH1Vzoc4UUEsLEN3viYMZeQ6HaRAx+gaBzlcIrFMD9 plnz2Z6wem5nahJWsv2BW2/9FAvku0/1cMSfo8TaF+sXMrn6WMTHIuu60uAZp7NM58 vIJJXsTAmD7Wqrpsx4vG9dLxKjQILJ8TycmXI1Pk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Alan Stern , Kento Kobayashi , Bart Van Assche , "Martin K. Petersen" , Jacky Cao , Sasha Levin Subject: [PATCH 4.19 144/276] USB: core: Dont unbind interfaces following device reset failure Date: Wed, 29 May 2019 20:05:02 -0700 Message-Id: <20190530030534.660095891@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190530030523.133519668@linuxfoundation.org> References: <20190530030523.133519668@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 [ Upstream commit 381419fa720060ba48b7bbc483be787d5b1dca6f ] The SCSI core does not like to have devices or hosts unregistered while error recovery is in progress. Trying to do so can lead to self-deadlock: Part of the removal code tries to obtain a lock already held by the error handler. This can cause problems for the usb-storage and uas drivers, because their error handler routines perform a USB reset, and if the reset fails then the USB core automatically goes on to unbind all drivers from the device's interfaces -- all while still in the context of the SCSI error handler. As it turns out, practically all the scenarios leading to a USB reset failure end up causing a device disconnect (the main error pathway in usb_reset_and_verify_device(), at the end of the routine, calls hub_port_logical_disconnect() before returning). As a result, the hub_wq thread will soon become aware of the problem and will unbind all the device's drivers in its own context, not in the error-handler's context. This means that usb_reset_device() does not need to call usb_unbind_and_rebind_marked_interfaces() in cases where usb_reset_and_verify_device() has returned an error, because hub_wq will take care of everything anyway. This particular problem was observed in somewhat artificial circumstances, by using usbfs to tell a hub to power-down a port connected to a USB-3 mass storage device using the UAS protocol. With the port turned off, the currently executing command timed out and the error handler started running. The USB reset naturally failed, because the hub port was off, and the error handler deadlocked as described above. Not carrying out the call to usb_unbind_and_rebind_marked_interfaces() fixes this issue. Signed-off-by: Alan Stern Reported-by: Kento Kobayashi Tested-by: Kento Kobayashi CC: Bart Van Assche CC: Martin K. Petersen CC: Jacky Cao Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/usb/core/hub.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c index bbcfa63d0233b..eb24ec0e160d4 100644 --- a/drivers/usb/core/hub.c +++ b/drivers/usb/core/hub.c @@ -5823,7 +5823,10 @@ int usb_reset_device(struct usb_device *udev) cintf->needs_binding = 1; } } - usb_unbind_and_rebind_marked_interfaces(udev); + + /* If the reset failed, hub_wq will unbind drivers later */ + if (ret == 0) + usb_unbind_and_rebind_marked_interfaces(udev); } usb_autosuspend_device(udev); -- 2.20.1