From patchwork Tue Jan 3 19:52:33 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 89729 Delivered-To: patches@linaro.org Received: by 10.140.20.101 with SMTP id 92csp8169805qgi; Tue, 3 Jan 2017 11:52:43 -0800 (PST) X-Received: by 10.84.176.131 with SMTP id v3mr138538488plb.51.1483473162968; Tue, 03 Jan 2017 11:52:42 -0800 (PST) Return-Path: Received: from mail-pg0-x22d.google.com (mail-pg0-x22d.google.com. [2607:f8b0:400e:c05::22d]) by mx.google.com with ESMTPS id f17si69902897pge.120.2017.01.03.11.52.42 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 03 Jan 2017 11:52:42 -0800 (PST) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 2607:f8b0:400e:c05::22d as permitted sender) client-ip=2607:f8b0:400e:c05::22d; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: domain of john.stultz@linaro.org designates 2607:f8b0:400e:c05::22d as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: by mail-pg0-x22d.google.com with SMTP id y62so165994498pgy.1 for ; Tue, 03 Jan 2017 11:52:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=CGWJB9tV6domlZ20QTlVKy5bUsmbtZOFLTclo1ImMDU=; b=PmRKH7n7B3SCktI3uw43PUHTAII5Fb0KuplL9a7e/a7Gos3p5cQXs33U0w6YnPQ7zc egZNLzUmsGyls1CKbdh7pZES0IeDMlBBsQdOndSa+GgaQJAOR7KTXEMJiInhWRmWbouo QZUXZWDqueeskT8D3Dd/KzxlP9qTssK7EWabA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=CGWJB9tV6domlZ20QTlVKy5bUsmbtZOFLTclo1ImMDU=; b=qa1JI7f5BUflyTbA99xpM66JPccobuu1ozrflle2RIbBL+lxKJebfLCpvSutXNO+VE 4AhxBGIc9LX4gUbMGPEA9swtsdaD4k+yT7lHEdbXo4s1XwBPvcNRzO2Jk7li3kic1VQH jR+aU1A1qggQsEmh+28T9GAcEzqKpbTI9YY3M+zRddIObaQuEbgRbkpT3IVe9qknfliH Wi8WgX8R34AuLvwNKWuEG6IpkfroHlWGmU9SvsJWf0XXbD7n2KMp+j1owky8bHXWOPmd JpSelsfNsi/NFQpZmpxvQtDVqGSfw9n8EmaXpaJC5pC7y0/pDNa/jfQ3UE7l/fst8Cu+ K8QA== X-Gm-Message-State: AIkVDXIOlQT3ffooivxHO5AdbmbQ7tP28PP+uLsyuKaN12I4VMZRLb2uA3FOGcdoOr//HReNZ1o= X-Received: by 10.99.51.76 with SMTP id z73mr116541020pgz.173.1483473162664; Tue, 03 Jan 2017 11:52:42 -0800 (PST) Return-Path: Received: from localhost.localdomain ([2601:1c2:1002:83f0:4e72:b9ff:fe99:466a]) by smtp.gmail.com with ESMTPSA id r1sm93771794pgn.48.2017.01.03.11.52.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 03 Jan 2017 11:52:41 -0800 (PST) From: John Stultz To: lkml Cc: John Stultz , Wei Xu , Guodong Xu , Amit Pundir , Rob Herring , John Youn , Douglas Anderson , Chen Yu , Vardan Mikayelyan , Kishon Vijay Abraham I , Felipe Balbi , Greg Kroah-Hartman , linux-usb@vger.kernel.org Subject: [PATCH 1/5 v2] usb: dwc2: Avoid sleeping while holding hsotg->lock Date: Tue, 3 Jan 2017 11:52:33 -0800 Message-Id: <1483473157-16678-2-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1483473157-16678-1-git-send-email-john.stultz@linaro.org> References: <1483473157-16678-1-git-send-email-john.stultz@linaro.org> Basically when plugging in various cables in different orders, I'm occasionally seeing the following BUG splat: [ 86.215403] BUG: scheduling while atomic: kworker/u16:2/53/0x00000002 [ 86.219164] usb 1-1: USB disconnect, device number 9 [ 86.226845] Preemption disabled at:[ 86.230218] [] dwc2_conn_id_status_change+0x120/0x250 [ 86.236894] CPU: 0 PID: 53 Comm: kworker/u16:2 Tainted: G W 4.9.0-rc8-00051-gd5a7979-dirty #1702 [ 86.246836] Hardware name: HiKey Development Board (DT) [ 86.252100] Workqueue: dwc2 dwc2_conn_id_status_change [ 86.257279] Call trace: [ 86.259771] [] dump_backtrace+0x0/0x1a0 [ 86.265210] [] show_stack+0x14/0x20 [ 86.270308] [] dump_stack+0x90/0xb0 [ 86.275401] [] __schedule_bug+0x6c/0xb8 [ 86.280841] [] __schedule+0x4f8/0x5b0 [ 86.286099] [] schedule+0x38/0xa0 [ 86.291017] [] schedule_hrtimeout_range_clock+0x8c/0xf0 [ 86.297846] [] schedule_hrtimeout_range+0x10/0x18 [ 86.304150] [] usleep_range+0x50/0x58 [ 86.309418] [] dwc2_wait_for_mode.isra.4+0x54/0xd0 [ 86.315815] [] dwc2_core_reset+0xe0/0x168 [ 86.321431] [] dwc2_hsotg_core_init_disconnected+0x2c/0x310 [ 86.328602] [] dwc2_conn_id_status_change+0x130/0x250 [ 86.335254] [] process_one_work+0x118/0x370 [ 86.341035] [] worker_thread+0x48/0x498 [ 86.346473] [] kthread+0xd0/0xe8 [ 86.351299] [] ret_from_fork+0x10/0x50 This seems to be caused by the dwc2_wait_for_mode() calling usleep_range() while the hstog->lock spinlock is held, since we take that before calling dwc2_hsotg_core_init_disconnected(). This patch avoids the issue by adding an extra argument to dwc2_core_reset(), as suggested by John Youn, which allows us to skip the waiting, which should be unnecessary when calling from dwc2_hsotg_core_init_disconnected(). Cc: Wei Xu Cc: Guodong Xu Cc: Amit Pundir Cc: Rob Herring Cc: John Youn Cc: Douglas Anderson Cc: Chen Yu Cc: Vardan Mikayelyan Cc: Kishon Vijay Abraham I Cc: Felipe Balbi Cc: Greg Kroah-Hartman Cc: linux-usb@vger.kernel.org Signed-off-by: John Stultz --- drivers/usb/dwc2/core.c | 6 +++--- drivers/usb/dwc2/core.h | 2 +- drivers/usb/dwc2/gadget.c | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) -- 2.7.4 diff --git a/drivers/usb/dwc2/core.c b/drivers/usb/dwc2/core.c index 11d8ae9..2d0dac2 100644 --- a/drivers/usb/dwc2/core.c +++ b/drivers/usb/dwc2/core.c @@ -313,7 +313,7 @@ static bool dwc2_iddig_filter_enabled(struct dwc2_hsotg *hsotg) * Do core a soft reset of the core. Be careful with this because it * resets all the internal state machines of the core. */ -int dwc2_core_reset(struct dwc2_hsotg *hsotg) +int dwc2_core_reset(struct dwc2_hsotg *hsotg, bool skip_wait) { u32 greset; int count = 0; @@ -369,7 +369,7 @@ int dwc2_core_reset(struct dwc2_hsotg *hsotg) } } while (!(greset & GRSTCTL_AHBIDLE)); - if (wait_for_host_mode) + if (wait_for_host_mode && !skip_wait) dwc2_wait_for_mode(hsotg, true); return 0; @@ -500,7 +500,7 @@ int dwc2_core_reset_and_force_dr_mode(struct dwc2_hsotg *hsotg) { int retval; - retval = dwc2_core_reset(hsotg); + retval = dwc2_core_reset(hsotg, false); if (retval) return retval; diff --git a/drivers/usb/dwc2/core.h b/drivers/usb/dwc2/core.h index 9548d3e..eb2d628 100644 --- a/drivers/usb/dwc2/core.h +++ b/drivers/usb/dwc2/core.h @@ -1101,7 +1101,7 @@ static inline bool dwc2_is_hs_iot(struct dwc2_hsotg *hsotg) * The following functions support initialization of the core driver component * and the DWC_otg controller */ -extern int dwc2_core_reset(struct dwc2_hsotg *hsotg); +extern int dwc2_core_reset(struct dwc2_hsotg *hsotg, bool skip_wait); extern int dwc2_core_reset_and_force_dr_mode(struct dwc2_hsotg *hsotg); extern int dwc2_enter_hibernation(struct dwc2_hsotg *hsotg); extern int dwc2_exit_hibernation(struct dwc2_hsotg *hsotg, bool restore); diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c index c55db4a..cbba471 100644 --- a/drivers/usb/dwc2/gadget.c +++ b/drivers/usb/dwc2/gadget.c @@ -3158,7 +3158,7 @@ void dwc2_hsotg_core_init_disconnected(struct dwc2_hsotg *hsotg, kill_all_requests(hsotg, hsotg->eps_out[0], -ECONNRESET); if (!is_usb_reset) - if (dwc2_core_reset(hsotg)) + if (dwc2_core_reset(hsotg, true)) return; /*