From patchwork Mon May 2 12:41:29 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roger Quadros X-Patchwork-Id: 67026 Delivered-To: patch@linaro.org Received: by 10.140.92.199 with SMTP id b65csp19443qge; Mon, 2 May 2016 05:41:51 -0700 (PDT) X-Received: by 10.98.92.66 with SMTP id q63mr13891858pfb.21.1462192911147; Mon, 02 May 2016 05:41:51 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id jh2si27654040pac.149.2016.05.02.05.41.50; Mon, 02 May 2016 05:41:51 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-omap-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-omap-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-omap-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753084AbcEBMlt (ORCPT + 3 others); Mon, 2 May 2016 08:41:49 -0400 Received: from bear.ext.ti.com ([192.94.94.41]:49948 "EHLO bear.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752231AbcEBMlr (ORCPT ); Mon, 2 May 2016 08:41:47 -0400 Received: from dflxv15.itg.ti.com ([128.247.5.124]) by bear.ext.ti.com (8.13.7/8.13.7) with ESMTP id u42CfXUT019514; Mon, 2 May 2016 07:41:33 -0500 Received: from DLEE71.ent.ti.com (dlee71.ent.ti.com [157.170.170.114]) by dflxv15.itg.ti.com (8.14.3/8.13.8) with ESMTP id u42CfX0H026391; Mon, 2 May 2016 07:41:33 -0500 Received: from dflp33.itg.ti.com (10.64.6.16) by DLEE71.ent.ti.com (157.170.170.114) with Microsoft SMTP Server id 14.3.224.2; Mon, 2 May 2016 07:41:32 -0500 Received: from [192.168.2.6] (ileax41-snat.itg.ti.com [10.172.224.153]) by dflp33.itg.ti.com (8.14.3/8.13.8) with ESMTP id u42CfULu004339; Mon, 2 May 2016 07:41:30 -0500 Subject: Re: BUG: spinlock vs. mutex in SyS_finit_module / usbhs_runtime_resume / omap_tll_enable / clk_prepare_lock To: "H. Nikolaus Schaller" , linux-omap , Mike Turquette , LKML References: <01E66DD1-5A58-434F-98E8-CB0F9F741810@goldelico.com> CC: , Discussions about the Letux Kernel From: Roger Quadros Message-ID: <57274AF9.1040205@ti.com> Date: Mon, 2 May 2016 15:41:29 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.7.2 MIME-Version: 1.0 In-Reply-To: <01E66DD1-5A58-434F-98E8-CB0F9F741810@goldelico.com> Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org Hi Nikolaus, On 30/04/16 20:24, H. Nikolaus Schaller wrote: > Hi, > I have observed this kernel oops on an omap5 board from time to time (approx. 1% of boot processes): > > [ 5.830970] ehci-omap: OMAP-EHCI Host Controller driver > [ 5.830974] driver_register 'ehci-omap' > [ 5.895849] driver_register 'wl1271_sdio' > [ 5.896870] BUG: scheduling while atomic: udevd/994/0x00000002 > [ 5.896876] 4 locks held by udevd/994: > [ 5.896904] #0: (&dev->mutex){......}, at: [] __driver_attach+0x60/0xac > [ 5.896923] #1: (&dev->mutex){......}, at: [] __driver_attach+0x70/0xac > [ 5.896946] #2: (tll_lock){+.+...}, at: [] omap_tll_enable+0x2c/0xd0 > [ 5.896966] #3: (prepare_lock){+.+...}, at: [] clk_prepare_lock+0x48/0xe0 > [ 5.897042] Modules linked in: wlcore_sdio(+) ehci_omap(+) dwc3_omap snd_soc_ts3a225e leds_is31fl319x bq27xxx_battery_i2c tsc2007 bq27xxx_battery bq2429x_charger ina2xx tca8418_keypad as5013 leds_tca6507 twl6040_vibra gpio_twl6040 bmp085_i2c(+) palmas_gpadc usb3503 palmas_pwrbutton bmg160_i2c(+) bmp085 bma150(+) bmg160_core bmp280 input_polldev snd_soc_omap_mcbsp snd_soc_omap_mcpdm snd_soc_omap snd_pcm_dmaengine > [ 5.897048] Preemption disabled at:[< (null)>] (null) > [ 5.897051] > [ 5.897059] CPU: 0 PID: 994 Comm: udevd Not tainted 4.6.0-rc5-letux+ #233 > [ 5.897062] Hardware name: Generic OMAP5 (Flattened Device Tree) > [ 5.897076] [] (unwind_backtrace) from [] (show_stack+0x10/0x14) > [ 5.897087] [] (show_stack) from [] (dump_stack+0x88/0xc0) > [ 5.897099] [] (dump_stack) from [] (__schedule_bug+0xac/0xd0) > [ 5.897111] [] (__schedule_bug) from [] (__schedule+0x88/0x7e4) > [ 5.897120] [] (__schedule) from [] (schedule+0x9c/0xc0) > [ 5.897129] [] (schedule) from [] (schedule_preempt_disabled+0x14/0x20) > [ 5.897140] [] (schedule_preempt_disabled) from [] (mutex_lock_nested+0x258/0x43c) > [ 5.897150] [] (mutex_lock_nested) from [] (clk_prepare_lock+0x48/0xe0) > [ 5.897160] [] (clk_prepare_lock) from [] (clk_prepare+0x10/0x28) > [ 5.897169] [] (clk_prepare) from [] (omap_tll_enable+0x64/0xd0) > [ 5.897180] [] (omap_tll_enable) from [] (usbhs_runtime_resume+0x18/0x17c) > [ 5.897192] [] (usbhs_runtime_resume) from [] (pm_generic_runtime_resume+0x2c/0x40) > [ 5.897202] [] (pm_generic_runtime_resume) from [] (__rpm_callback+0x38/0x68) > [ 5.897210] [] (__rpm_callback) from [] (rpm_callback+0x70/0x88) > [ 5.897218] [] (rpm_callback) from [] (rpm_resume+0x4ec/0x7ec) > [ 5.897227] [] (rpm_resume) from [] (__pm_runtime_resume+0x4c/0x64) > [ 5.897236] [] (__pm_runtime_resume) from [] (driver_probe_device+0x30/0x70) > [ 5.897246] [] (driver_probe_device) from [] (__driver_attach+0x88/0xac) > [ 5.897256] [] (__driver_attach) from [] (bus_for_each_dev+0x50/0x84) > [ 5.897267] [] (bus_for_each_dev) from [] (bus_add_driver+0xcc/0x1e4) > [ 5.897276] [] (bus_add_driver) from [] (driver_register+0xac/0xf4) > [ 5.897286] [] (driver_register) from [] (do_one_initcall+0x100/0x1b8) > [ 5.897296] [] (do_one_initcall) from [] (do_init_module+0x58/0x1c0) > [ 5.897304] [] (do_init_module) from [] (SyS_finit_module+0x88/0x90) > [ 5.897313] [] (SyS_finit_module) from [] (ret_fast_syscall+0x0/0x1c) > [ 5.912697] ------------[ cut here ]------------ > [ 5.912711] WARNING: CPU: 0 PID: 994 at kernel/sched/core.c:2996 _raw_spin_unlock+0x28/0x58 > [ 5.912717] DEBUG_LOCKS_WARN_ON(val > preempt_count()) > > A liitle analysis of the code shows me: > > * udevd tries to initialize some (usb driver?) module > * this calls usbhs_runtime_resume: http://lxr.free-electrons.com/source/drivers/mfd/omap-usb-host.c#L310 > * which calls omap_tll_enable: http://lxr.free-electrons.com/source/drivers/mfd/omap-usb-tll.c#L403 > * this does a spinlock: http://lxr.free-electrons.com/source/drivers/mfd/omap-usb-tll.c#L413 > * but calls clk_prepare_enable: http://lxr.free-electrons.com/source/include/linux/clk.h#L467 > * which calls: http://lxr.free-electrons.com/source/drivers/clk/clk.c#L658 > * and there is a another lock being tried in clk_prepare_lock: http://lxr.free-electrons.com/source/drivers/clk/clk.c#L91 > * and that is a mutex_try_lock > > So the lock dependency report is very valid. Inside a spinlock, there is a mutex_try_lock. > > It appears as if the spinlock was introduced in 2008 by 76a0775d46da052f123b8598a3dfc3b330b8de4f > And the mutex in 2013 by 533ddeb1e86f506129ee388a6cc13796dcf31311 > > Please fix. > > Thank you, > Nikolaus Does this patch fix it for you? -- cheers, -roger the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/mfd/omap-usb-tll.c b/drivers/mfd/omap-usb-tll.c index b7b3e8e..c30290f 100644 --- a/drivers/mfd/omap-usb-tll.c +++ b/drivers/mfd/omap-usb-tll.c @@ -269,6 +269,8 @@ static int usbtll_omap_probe(struct platform_device *pdev) if (IS_ERR(tll->ch_clk[i])) dev_dbg(dev, "can't get clock : %s\n", clkname); + else + clk_prepare(tll->ch_clk[i]); } pm_runtime_put_sync(dev); @@ -301,9 +303,12 @@ static int usbtll_omap_remove(struct platform_device *pdev) tll_dev = NULL; spin_unlock(&tll_lock); - for (i = 0; i < tll->nch; i++) - if (!IS_ERR(tll->ch_clk[i])) + for (i = 0; i < tll->nch; i++) { + if (!IS_ERR(tll->ch_clk[i])) { + clk_unprepare(tll->ch_clk[i]); clk_put(tll->ch_clk[i]); + } + } pm_runtime_disable(&pdev->dev); return 0; @@ -420,7 +425,7 @@ int omap_tll_enable(struct usbhs_omap_platform_data *pdata) if (IS_ERR(tll->ch_clk[i])) continue; - r = clk_prepare_enable(tll->ch_clk[i]); + r = clk_enable(tll->ch_clk[i]); if (r) { dev_err(tll_dev, "Error enabling ch %d clock: %d\n", i, r); @@ -448,7 +453,7 @@ int omap_tll_disable(struct usbhs_omap_platform_data *pdata) for (i = 0; i < tll->nch; i++) { if (omap_usb_mode_needs_tll(pdata->port_mode[i])) { if (!IS_ERR(tll->ch_clk[i])) - clk_disable_unprepare(tll->ch_clk[i]); + clk_disable(tll->ch_clk[i]); } } -- To unsubscribe from this list: send the line "unsubscribe linux-omap" in