Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp256651ybi; Wed, 29 May 2019 20:47:17 -0700 (PDT) X-Google-Smtp-Source: APXvYqypWtglUjLq8K07azaumDi3aR0VwoOmdi/1MRsbaYym0NEFk8og4gU6q5Jd6EOud1I8co1h X-Received: by 2002:a63:1f55:: with SMTP id q21mr1772712pgm.51.1559188037658; Wed, 29 May 2019 20:47:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559188037; cv=none; d=google.com; s=arc-20160816; b=j9YBEzj09I0nAWndLrm/5HgK3YBVYOuFEN0WIjhAadhncd2ojwtN8WhMwfkbqFIv8z Sz5iPlf8Sruie/nYNuHcnKBgGwKYvw7sppZWNgzOSCQ0BgPfw1wOXLJb0D4Vi/pAoMHd 9LcB34kh9tZgA285JOudawRGxSBBVLxHQI9tqBbHnLV5KRDRscwSkgvpyPD3cW2Sd15w +B9BVODiAc73Ja0CMpySSbV9pgIeQqxCFtl0Y8rcHzgmKZgLQP5Q6eAhS3Ocv5vdSTCE LLxWhdvpsZWgIfZawYKQGNLOpLLj3QZJspWOq9LRadQUv2QF/ZJ5pXQGfCU8+O/oTdXd PQBw== 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=HeSvMUS3sT/huH0l+bx7CVYe0CBTj19LZbAhPkZk0pw=; b=TLUfldCh5M8jopV/6xXzfWpQILreQTCbabHnHDQy0JaNRPU3yKhAw6gZv2/9K0r0/9 YznTZEpuD+mgySp3u7BMtUCCWZEFqDjM/nmR0Tje3P4a9tK37jzE/Q9FR0d/y68FvHpZ MeO0G9GJtpYCtgn1ywf1U2kPaJmMB+TwG05yDeXnoQDHC6uFwjRsdyFiEhOWfmWaq8fg G8YRXi4Syu9xfB4KY2VKFuI3fMkKiOYHYT796OUhtKIaX8PQaf0WepcB5921UdkUg0sQ bGISee/yBdujKAYoFnfgiOg00zbKSUsy6CX1aS/Rra3iBWQAmugn6BggXpCDhZAH/g+F UBhg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="aLuwkq4/"; 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 ci5si1921440plb.433.2019.05.29.20.47.02; Wed, 29 May 2019 20:47:17 -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="aLuwkq4/"; 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 S1730550AbfE3Dor (ORCPT + 99 others); Wed, 29 May 2019 23:44:47 -0400 Received: from mail.kernel.org ([198.145.29.99]:60312 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731191AbfE3DUz (ORCPT ); Wed, 29 May 2019 23:20:55 -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 B9F502497E; Thu, 30 May 2019 03:20:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1559186454; bh=/dSK9AgPfdU0lveu62+guLWcxnrlupug61U9I5J2Eag=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aLuwkq4/6x2SiJONSm3ia5QoBGgWy6JNPQeoAX2KFOrfuIKdS7Jt3lT7W1FzDdvmr gHIRO1yeg/jdA5dhDofh8OsycplOkpxIHn5UkOfV2r3dj6anyCjeiHXylbs/UmIJPZ SA4cN2ghH1kvpbQ/YG1zttuAWoU5lVfTMyFbaCVU= 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.9 067/128] USB: core: Dont unbind interfaces following device reset failure Date: Wed, 29 May 2019 20:06:39 -0700 Message-Id: <20190530030446.850476206@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190530030432.977908967@linuxfoundation.org> References: <20190530030432.977908967@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 8fddb94f1874e..3941df076ccac 100644 --- a/drivers/usb/core/hub.c +++ b/drivers/usb/core/hub.c @@ -5703,7 +5703,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