From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.0 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,T_DKIMWL_WL_HIGH,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 63DA5C28EBD for ; Sun, 9 Jun 2019 17:01:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3DAC3204EC for ; Sun, 9 Jun 2019 17:01:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1560099690; bh=MtbLinRgkMzVjwPmdVUg+4Tqzcjum6jVMV5tYNf8ze4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=Qw0PUWyZEm4kyzNd3JVYoND4mXkDNkNeEu+4NDxR1tniD0xPffYMAL3V3LGImhzr5 8wkp4rwsOBPSBvZa8EohKVFqRLqYbm3MwTfs4MGnnNtvlA0lmLlskek5jeGrzQYzz6 10lPdIA63r2dy5w5pgbHdFoaFExEFARLIrAKgcVg= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388074AbfFIRB3 (ORCPT ); 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