Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp2418452ybi; Sun, 9 Jun 2019 11:15:50 -0700 (PDT) X-Google-Smtp-Source: APXvYqyZwgHNbQwgzRewxECye/cQLVHsP7JNgzvTdE+Q84g8i8LwoFXdZst+J2V/WJX08adXxcHc X-Received: by 2002:a63:5726:: with SMTP id l38mr12919705pgb.344.1560104149807; Sun, 09 Jun 2019 11:15:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560104149; cv=none; d=google.com; s=arc-20160816; b=BjSe2FLnstSKic9tpHbOBnNYXpgrVnZeQpSj/ZWdt6OkR0HvgCF0sTkXs/E+1kpTkW CU2tsd2skFv4MMSXSvHVDANc6Zh+Cy/o3hLuOhdJneTVhg15d+feHfVU+1XQjn0ffIny SFsR9g+vBsbkxu9hQM8e1QwBLer8imxilTax9FIAQQIuJ/QZj3bedMokP92pnKN+mcQL szsowkB/nVKP9WPDNRecQ9RynyO/ZT10xEuxss435sUw0DWDPZCx3w630Is16uS+xMEl kjpVtWc4/rOKD8i/L3WYpCBk4iAhQp9pL2NvD7JpkLZ9flFLXkR84tp7WiFP107Z3ci/ Mxig== 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=RzfSJZImv2G+x7hgBGAsy9+UZSbVQWS0s3pHiiBiYP4=; b=lMmLIrIzKbtt7dCISNGfNEOiwypwy89KqUu0nDhROGAlzjX6XEujrEzf8PQUkT4tb8 V8Cx1lDSkC8T1qJL4I4ZDE5S9Vq+40lZRBq2CKPTBQAmLu1GjAmOeKb78EjUAFILgicQ gX/8RmX+u+8OWLU1UHQdd4Ox1w/fnnQngpcBITmT4uIYohZNvs1LfjGk5X27Sh7td99W akKuoBgWrQfg/BzcxxMwKM9eMF7T0r6JT0wLwU78YZEaIIMlSMGtp08GuJAZ10g4fjqA LeLp20FSu1kDuHgIE5V0Pn5FwILWwPQ1A6Y4rLzDgfyOUPsP6zPcC3N42A25bj18wO6L xrtA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=OMbsgL4F; 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 z61si8391440plb.19.2019.06.09.11.15.34; Sun, 09 Jun 2019 11:15:49 -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=OMbsgL4F; 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 S2388069AbfFIRB3 (ORCPT + 99 others); Sun, 9 Jun 2019 13:01:29 -0400 Received: from mail.kernel.org ([198.145.29.99]:38690 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387657AbfFIRB0 (ORCPT ); Sun, 9 Jun 2019 13:01:26 -0400 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 55F54207E0; Sun, 9 Jun 2019 17:01:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1560099685; bh=MtbLinRgkMzVjwPmdVUg+4Tqzcjum6jVMV5tYNf8ze4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OMbsgL4FCriLtk7loT6xIAeURVasLThzXGDPtKdmuHUebXCOIY7EHniOwm97dk/HA d2480vf/IMe4t4MKvXa0oeeHgu/k+XOFzB56zMu0LD4KwSeL3hASbPx9RLcBubNNqX tOrI19pYGAGRbWP6UbVlZcymQxJqN8CPr4y2xsEI= 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.4 128/241] USB: core: Dont unbind interfaces following device reset failure Date: Sun, 9 Jun 2019 18:41:10 +0200 Message-Id: <20190609164151.495165077@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190609164147.729157653@linuxfoundation.org> References: <20190609164147.729157653@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 7c87c0b38bcfa..6e307de251630 100644 --- a/drivers/usb/core/hub.c +++ b/drivers/usb/core/hub.c @@ -5637,7 +5637,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