From patchwork Wed Nov 21 15:45:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 151700 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp2091151ljp; Wed, 21 Nov 2018 07:45:23 -0800 (PST) X-Google-Smtp-Source: AFSGD/WZsfJDNUNcMb6y5RHyPzDklkQ5ZtbTAEsQoVQJCkW7klJLJaZDqBYuqATtvo85SVDz1X1h X-Received: by 2002:a62:33c1:: with SMTP id z184mr2057323pfz.104.1542815123507; Wed, 21 Nov 2018 07:45:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542815123; cv=none; d=google.com; s=arc-20160816; b=XEYcrDejhnJ57wpoez8YGyLlz3PZV6e4GipBheCcHs+rhDH2jVeAM9iuEIEPUiC1SM /E10NdmcbnUlLU2xFLleGo2QwIkHJuwj3bFlVUq7ltw7bC0UbCV4NG/QOcI80W/LYNXg pdpivNhVTrdZuYJLYTWNjECmdiDpJDUqeZ6sLSnqaJLRNra536VW2dGgAYeROK8DgKcw eYtk9VwtVYl8dd3cDuPIfy2YNRl6km0MB7D4rHgPIuHx5at/cMDaZ/pLeO7C2lOJdS90 uTQwalYeBn5vJ5UTv+9XwoAgJie2bz240NgSYz9KsS8ClZRiertmUP94nRgP818l1flH gWUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:cms-type:message-id:date :subject:cc:to:from:dkim-signature:dkim-filter; bh=ZDpHLELrYsVtA381WyXghy7lbPoJAuVimov4S92BukU=; b=iU3hWUgQdLjf3Cef84Qt+5CoYmAzuWcxYgxeDLHUPLOzMIjK+AGYDcWKWagF7heR0d dBliitV6swS3GUDEumyE66OdvXtmndYbuV3AfghbQx2mMieCAgOOdYbZcG6g7WmdvExP GXKxhBkQJSGdB9SLox/NqwYZ32sYa0fSecu6b4bOv6W+GjEwfZJcamf7le8j5zeT5fVl Pv/2XcxYlM8+/lMxPEJpgQBpQT0Npqhj/JPaWKWijauAQfxSNdi0/K9Q2R+R5mSlb9zd gn/UxLQ2LxtZ3fI6QyZlSDozw+flMLkve3VQEptULBdT/PuuituXQr0dzbtlqn99TAfP DeCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=J6GSGbJE; spf=pass (google.com: best guess record for domain of linux-usb-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-usb-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r22si16382542pgl.537.2018.11.21.07.45.23; Wed, 21 Nov 2018 07:45:23 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-usb-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=@samsung.com header.s=mail20170921 header.b=J6GSGbJE; spf=pass (google.com: best guess record for domain of linux-usb-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-usb-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731296AbeKVCUT (ORCPT + 5 others); Wed, 21 Nov 2018 21:20:19 -0500 Received: from mailout2.w1.samsung.com ([210.118.77.12]:58610 "EHLO mailout2.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728289AbeKVCUT (ORCPT ); Wed, 21 Nov 2018 21:20:19 -0500 Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20181121154520euoutp02d17fc921161d0faccc1f40c921bf0e7a~pLi1_3sJa1571915719euoutp023; Wed, 21 Nov 2018 15:45:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20181121154520euoutp02d17fc921161d0faccc1f40c921bf0e7a~pLi1_3sJa1571915719euoutp023 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1542815120; bh=ZDpHLELrYsVtA381WyXghy7lbPoJAuVimov4S92BukU=; h=From:To:Cc:Subject:Date:References:From; b=J6GSGbJE8Sr1RNTqFAHj4Ly8CIVi6uL8Omqd6qXucQMn2vlMyza8qXOkwtNmsU0GT clGR+0VYJ2g3Pa0827ZQ7FXytlBNljI8grY2slOiLj+EVM++ja103Gv/VQCFN3r7SV le4/1BrhWedVtkeVU9+44mFACnVbcv73WsSWtTo4= Received: from eusmges1new.samsung.com (unknown [203.254.199.242]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20181121154519eucas1p25b4250e996fd5c55647eee8f60a7d272~pLi1QHSa70093500935eucas1p2S; Wed, 21 Nov 2018 15:45:19 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges1new.samsung.com (EUCPMTA) with SMTP id EF.BC.04441.F8D75FB5; Wed, 21 Nov 2018 15:45:19 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20181121154518eucas1p2cc7ffd4d071ff420c747e1d0c387ee5d~pLi0ipU3g0464504645eucas1p2A; Wed, 21 Nov 2018 15:45:18 +0000 (GMT) X-AuditID: cbfec7f2-5e3ff70000001159-5d-5bf57d8f347d Received: from eusync1.samsung.com ( [203.254.199.211]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id D1.DD.04284.E8D75FB5; Wed, 21 Nov 2018 15:45:18 +0000 (GMT) Received: from AMDC2765.digital.local ([106.116.147.25]) by eusync1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0PIJ000DJVRDCG50@eusync1.samsung.com>; Wed, 21 Nov 2018 15:45:18 +0000 (GMT) From: Marek Szyprowski To: linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org Cc: Marek Szyprowski , Greg Kroah-Hartman , Minas Harutyunyan , Felipe Balbi , Geert Uytterhoeven , Dan Carpenter , Bartlomiej Zolnierkiewicz Subject: [PATCH] usb: dwc2: Revert "usb: dwc2: Disable all EP's on disconnect" Date: Wed, 21 Nov 2018 16:45:04 +0100 Message-id: <20181121154504.13052-1-m.szyprowski@samsung.com> X-Mailer: git-send-email 2.17.1 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrAIsWRmVeSWpSXmKPExsWy7djPc7r9tV+jDc4t4LPYOGM9q8Xrf9NZ LObfTLJ4dmsvk0Xz4vVsFo2/9rJbXN41h81i0bJWZou1R+6yO3B6HDrcwegx72Sgx/65a9g9 Pj69xeLRt2UVo8eW/Z8ZPT5vkgtgj+KySUnNySxLLdK3S+DKuHC7i62gU7fi/M/jTA2Mx9W6 GDk5JARMJPqPLmADsYUEVjBKND0u6WLkArI/M0p8b1rIDlP0sOsqK0RiGaPE+purmCGcBiaJ r5s+gLWzCRhKdL3tArNFBKwlbm87ClbELHCSSWL1gpcsIAlhgQCJe10/GUFsFgFViRdPO8Di vAK2EpcOz4daJy+xesMBsGYJgQ42iVX3nzJDJFwkGvZdhrKFJV4d3wLVICPR2XGQCaKhmVGi fcYsdginh1Fi65wdbBBV1hKHj19kBbGZBfgkJm2bDjSJAyjOK9HRJgRR4iGx9s92VkhoxEoc WLiLeQKjxAJGhlWM4qmlxbnpqcWGeanlesWJucWleel6yfm5mxiB8Xj63/FPOxi/Xko6xCjA wajEw6sR+TVaiDWxrLgy9xCjBAezkghvRxRQiDclsbIqtSg/vqg0J7X4EKM0B4uSOG81w4No IYH0xJLU7NTUgtQimCwTB6dUA+P+8lPPkzsXfTKtv7KT44LKi01iL26keZnKzDr5+s5UsbcS l6SKl7NNmdid//KjMWfDqp6aKwyPtrtnXY15+4BTV6dxInvlw4y9Ex3PrTQKTNJYnVK5K6Q4 oi5xd6KA3Xa2ur0xL+e6Wtg9crO42ZrMJNj8Qpt3h/Rn2diMg8YP2N4ufHCvbIoSS3FGoqEW c1FxIgDZoxIDwwIAAA== X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmpgluLIzCtJLcpLzFFi42I5/e/4Zd2+2q/RBpsWy1lsnLGe1eL1v+ks FvNvJlk8u7WXyaJ58Xo2i8Zfe9ktLu+aw2axaFkrs8XaI3fZHTg9Dh3uYPSYdzLQY//cNewe H5/eYvHo27KK0WPL/s+MHp83yQWwR3HZpKTmZJalFunbJXBlXLjdxVbQqVtx/udxpgbG42pd jJwcEgImEg+7rrJ2MXJxCAksYZS4uuEtlNPEJLGicR0LSBWbgKFE19suNhBbRMBa4va2o8wg NrPAWSaJLx9Duhg5OIQF/CRmnXACCbMIqEq8eNoB1sorYCtx6fB8dohl8hKrNxxgnsDItYCR YRWjSGppcW56brGhXnFibnFpXrpecn7uJkZguGw79nPzDsZLG4MPMQpwMCrx8GpEfo0WYk0s K67MPcQowcGsJMLbEQUU4k1JrKxKLcqPLyrNSS0+xCjNwaIkznveoDJKSCA9sSQ1OzW1ILUI JsvEwSnVwBjPvHZq+/3YNnFDuf3d/8w27vtbd3SfveOVxbPjDDNtNNocpfoC5Mt+LjwcbXRu zimFrbesQ1y28dk/6/7mn3/fav9Cp8tXk6RenUpdLlCwTz1Z8uoNydX79FlffljcdHUm64l9 7zrP7NyxTK15193/8xKLRPdxM0ZxTZKcsrRB50fsrcftqlVKLMUZiYZazEXFiQCrvWLzEwIA AA== X-CMS-MailID: 20181121154518eucas1p2cc7ffd4d071ff420c747e1d0c387ee5d X-Msg-Generator: CA CMS-TYPE: 201P X-CMS-RootMailID: 20181121154518eucas1p2cc7ffd4d071ff420c747e1d0c387ee5d References: Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org This reverts commit dccf1bad4be7eaa096c1f3697bd37883f9a08ecb. The reverted commit breaks locking in the DWC2 driver. It causes random crashes or memory corruption related issues on SMP machines. Here is an example of the observed reproducible issue (other are a bit more random): -- 2.17.1 ===================================== WARNING: bad unlock balance detected! 4.19.0-rc6-00027-gdccf1bad4be7-dirty #1119 Not tainted ------------------------------------- ip/1464 is trying to release lock (&(&hsotg->lock)->rlock) at: [] dwc2_hsotg_complete_request+0x84/0x218 but there are no more locks to release! other info that might help us debug this: 2 locks held by ip/1464: #0: d69babd3 (rtnl_mutex){+.+.}, at: rtnetlink_rcv_msg+0x224/0x488 #1: 5fb350d2 (&(&dev->lock)->rlock){-.-.}, at: eth_stop+0x24/0xa8 stack backtrace: CPU: 1 PID: 1464 Comm: ip Not tainted 4.19.0-rc6-00027-gdccf1bad4be7-dirty #1119 Hardware name: SAMSUNG EXYNOS (Flattened Device Tree) [] (unwind_backtrace) from [] (show_stack+0x10/0x14) [] (show_stack) from [] (dump_stack+0x90/0xc8) [] (dump_stack) from [] (print_unlock_imbalance_bug+0xb0/0xe0) [] (print_unlock_imbalance_bug) from [] (lock_release+0x1a4/0x374) [] (lock_release) from [] (_raw_spin_unlock+0x18/0x54) [] (_raw_spin_unlock) from [] (dwc2_hsotg_complete_request+0x84/0x218) [] (dwc2_hsotg_complete_request) from [] (kill_all_requests+0x44/0xb4) [] (kill_all_requests) from [] (dwc2_hsotg_ep_disable+0xf0/0x200) [] (dwc2_hsotg_ep_disable) from [] (usb_ep_disable+0xd0/0x1c8) [] (usb_ep_disable) from [] (eth_stop+0x68/0xa8) [] (eth_stop) from [] (__dev_close_many+0x94/0xfc) [] (__dev_close_many) from [] (__dev_change_flags+0xa0/0x198) [] (__dev_change_flags) from [] (dev_change_flags+0x18/0x48) [] (dev_change_flags) from [] (do_setlink+0x298/0x990) [] (do_setlink) from [] (rtnl_newlink+0x4a0/0x6fc) [] (rtnl_newlink) from [] (rtnetlink_rcv_msg+0x254/0x488) [] (rtnetlink_rcv_msg) from [] (netlink_rcv_skb+0xe0/0x118) [] (netlink_rcv_skb) from [] (netlink_unicast+0x180/0x1c8) [] (netlink_unicast) from [] (netlink_sendmsg+0x2bc/0x348) [] (netlink_sendmsg) from [] (sock_sendmsg+0x14/0x24) [] (sock_sendmsg) from [] (___sys_sendmsg+0x22c/0x248) [] (___sys_sendmsg) from [] (__sys_sendmsg+0x40/0x6c) [] (__sys_sendmsg) from [] (ret_fast_syscall+0x0/0x28) Exception stack(0xede65fa8 to 0xede65ff0) ... Signed-off-by: Marek Szyprowski --- The suspicious locking has been already pointed in the review of the first version of this patch, but sadly the v2 didn't change it and landed in v4.20-rc1. --- drivers/usb/dwc2/gadget.c | 30 +++++++----------------------- 1 file changed, 7 insertions(+), 23 deletions(-) diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c index 79189db4bf17..220c0f9b89b0 100644 --- a/drivers/usb/dwc2/gadget.c +++ b/drivers/usb/dwc2/gadget.c @@ -3109,8 +3109,6 @@ static void kill_all_requests(struct dwc2_hsotg *hsotg, dwc2_hsotg_txfifo_flush(hsotg, ep->fifo_index); } -static int dwc2_hsotg_ep_disable(struct usb_ep *ep); - /** * dwc2_hsotg_disconnect - disconnect service * @hsotg: The device state. @@ -3129,12 +3127,13 @@ void dwc2_hsotg_disconnect(struct dwc2_hsotg *hsotg) hsotg->connected = 0; hsotg->test_mode = 0; - /* all endpoints should be shutdown */ for (ep = 0; ep < hsotg->num_of_eps; ep++) { if (hsotg->eps_in[ep]) - dwc2_hsotg_ep_disable(&hsotg->eps_in[ep]->ep); + kill_all_requests(hsotg, hsotg->eps_in[ep], + -ESHUTDOWN); if (hsotg->eps_out[ep]) - dwc2_hsotg_ep_disable(&hsotg->eps_out[ep]->ep); + kill_all_requests(hsotg, hsotg->eps_out[ep], + -ESHUTDOWN); } call_gadget(hsotg, disconnect); @@ -3192,23 +3191,13 @@ void dwc2_hsotg_core_init_disconnected(struct dwc2_hsotg *hsotg, u32 val; u32 usbcfg; u32 dcfg = 0; - int ep; /* Kill any ep0 requests as controller will be reinitialized */ kill_all_requests(hsotg, hsotg->eps_out[0], -ECONNRESET); - if (!is_usb_reset) { + if (!is_usb_reset) if (dwc2_core_reset(hsotg, true)) return; - } else { - /* all endpoints should be shutdown */ - for (ep = 1; ep < hsotg->num_of_eps; ep++) { - if (hsotg->eps_in[ep]) - dwc2_hsotg_ep_disable(&hsotg->eps_in[ep]->ep); - if (hsotg->eps_out[ep]) - dwc2_hsotg_ep_disable(&hsotg->eps_out[ep]->ep); - } - } /* * we must now enable ep0 ready for host detection and then @@ -4004,7 +3993,6 @@ static int dwc2_hsotg_ep_disable(struct usb_ep *ep) unsigned long flags; u32 epctrl_reg; u32 ctrl; - int locked; dev_dbg(hsotg->dev, "%s(ep %p)\n", __func__, ep); @@ -4020,9 +4008,7 @@ static int dwc2_hsotg_ep_disable(struct usb_ep *ep) epctrl_reg = dir_in ? DIEPCTL(index) : DOEPCTL(index); - locked = spin_is_locked(&hsotg->lock); - if (!locked) - spin_lock_irqsave(&hsotg->lock, flags); + spin_lock_irqsave(&hsotg->lock, flags); ctrl = dwc2_readl(hsotg, epctrl_reg); @@ -4046,9 +4032,7 @@ static int dwc2_hsotg_ep_disable(struct usb_ep *ep) hs_ep->fifo_index = 0; hs_ep->fifo_size = 0; - if (!locked) - spin_unlock_irqrestore(&hsotg->lock, flags); - + spin_unlock_irqrestore(&hsotg->lock, flags); return 0; }