Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp263880ybi; Wed, 29 May 2019 20:57:13 -0700 (PDT) X-Google-Smtp-Source: APXvYqxFf3n9At7pYGg2JYW7cSkzYcZsv58I36MJbfSmvve2g26XfppUUprnGGgaFhZdZVLbjdpu X-Received: by 2002:a17:902:a5ca:: with SMTP id t10mr1688213plq.98.1559188633016; Wed, 29 May 2019 20:57:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559188633; cv=none; d=google.com; s=arc-20160816; b=vsGr3kb5BOJhz7MOzZ9xZ/E1eKnvn6q4eW2/2EpxvVVcTiRN2uoNV8SeIct76Mu6pD VmkNvLxiQPfEI9LsOXU0utSfY0z1zMQtjk+6NjJiwsdNoHdZZVfIdZLi09wCUvMx9XOZ s1eJduXc2O7mujJarxkM9VbyvBz+iQfyoZw/QXBiMb6oYoWsPtR6/EEqffazf3uKUQ3H sPOnYQWHF+Qsy3Tste9WpXsXC2MTbKC1b9I1Ld0/vmQCBRWpQAUnMJ803xBfMxBf/cY4 N3BZdFq3laXU6HKTg0sCKnRrfSK3VHZ25HsefXOGlVmeRKcl/Tcj+RCTsxdAmq1UVDMu 4BUQ== 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=JEc5/t4Yo4g8q1QBdP0aITm3WURBGNqXiwqLF81XxCg=; b=VrQQj9sUcCjv6HJErBJ2DxuCwEseZwa91z3Fu+SNAFWvW/FEopgXtCDn59rgIWW3Ft sLpI/KNp9iC/2SzKijK1bXLVELFFAplOi8FiltUFdzroa3gaiqlVpLgkk14DmoU2y1uj 1827awekqVqsiro2+CECJ8/xTXsAq2/KZm72HlZVHlZUU72mLTbMN9Mo7/pzM03uJ26r yWeoHazqzzbf0V8lx7rfC4WpSfxctGDERvbbg8OKA1Ka7qJU4Tqozy3AvM+u5uroEfz8 2vs32Nr99furppoPNG5lOKUruyTPrVoKrZO21uf1eRXojA6JfmeZhNW+hbo1oDqNLdeJ ZaLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=19d8Jc1n; 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 d80si2231032pfd.9.2019.05.29.20.56.57; Wed, 29 May 2019 20:57:13 -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=19d8Jc1n; 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 S1732035AbfE3Dyc (ORCPT + 99 others); Wed, 29 May 2019 23:54:32 -0400 Received: from mail.kernel.org ([198.145.29.99]:54748 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731863AbfE3DTU (ORCPT ); Wed, 29 May 2019 23:19:20 -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 6A3FC2486D; Thu, 30 May 2019 03:19:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1559186359; bh=T62nimrfho7/Zd63oRzR74QHvwGRUWxmwpd5aJPNKnQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=19d8Jc1nnZ7FKahioDwGql7stJlqhwcy9k3bxHaClRunQCsFtvJD5ewxLU+qebn4W hlzY9htAgpbTck1hbvbAGWZS9zHALsSafEQgn9n2smPxBfxjZSVs+Vx8ncI/nB98Mn 3TV23kwVxINrE8Z30ShwYy+hp85SBqExruK9NNNM= 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.14 104/193] USB: core: Dont unbind interfaces following device reset failure Date: Wed, 29 May 2019 20:05:58 -0700 Message-Id: <20190530030503.307630282@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190530030446.953835040@linuxfoundation.org> References: <20190530030446.953835040@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 a9541525ea4f0..eddecaf1f0b20 100644 --- a/drivers/usb/core/hub.c +++ b/drivers/usb/core/hub.c @@ -5713,7 +5713,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