From patchwork Wed Dec 18 11:36:53 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Poddar, Sourav" X-Patchwork-Id: 302863 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 1DDB02C00AE for ; Wed, 18 Dec 2013 22:37:08 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752754Ab3LRLhF (ORCPT ); Wed, 18 Dec 2013 06:37:05 -0500 Received: from arroyo.ext.ti.com ([192.94.94.40]:44690 "EHLO arroyo.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751293Ab3LRLhD (ORCPT ); Wed, 18 Dec 2013 06:37:03 -0500 Received: from dflxv15.itg.ti.com ([128.247.5.124]) by arroyo.ext.ti.com (8.13.7/8.13.7) with ESMTP id rBIBb2VG005394; Wed, 18 Dec 2013 05:37:02 -0600 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 rBIBb2OF031526; Wed, 18 Dec 2013 05:37:02 -0600 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.2.342.3; Wed, 18 Dec 2013 05:37:02 -0600 Received: from a0131647.apr.dhcp.ti.com (ileax41-snat.itg.ti.com [10.172.224.153]) by dflp33.itg.ti.com (8.14.3/8.13.8) with ESMTP id rBIBaven009741; Wed, 18 Dec 2013 05:37:01 -0600 From: Sourav Poddar To: CC: , , , Sourav Poddar Subject: [PATCH 1/3] pwm: core: Rearrange pwm lock. Date: Wed, 18 Dec 2013 17:06:53 +0530 Message-ID: <1387366615-23182-2-git-send-email-sourav.poddar@ti.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1387366615-23182-1-git-send-email-sourav.poddar@ti.com> References: <1387366615-23182-1-git-send-email-sourav.poddar@ti.com> MIME-Version: 1.0 Sender: linux-pwm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pwm@vger.kernel.org When tiecap is used as a module, then while doing a rmmod I get the following dump. root@am437x-evm:/# rmmod pwm_tiecap [ 219.539245] [ 219.540771] ====================================================== [ 219.546936] [ INFO: possible circular locking dependency detected ] [ 219.553192] 3.12.4-01557-g9921cde-dirty #134 Not tainted [ 219.558471] ------------------------------------------------------- [ 219.564727] rmmod/1517 is trying to acquire lock: [ 219.569427] (s_active#35){++++.+}, at: [] sysfs_hash_and_remove+0x4c/0x8c [ 219.577239] [ 219.577239] but task is already holding lock: [ 219.583068] (pwm_lock){+.+.+.}, at: [] pwmchip_remove+0x14/0xf8 [ 219.589996] [ 219.589996] which lock already depends on the new lock. [ 219.589996] [ 219.598144] [ 219.598144] the existing dependency chain (in reverse order) is: [ 219.605590] -> #1 (pwm_lock){+.+.+.}: [ 219.609497] [] lock_acquire+0x9c/0x128 [ 219.614746] [] mutex_lock_nested+0x50/0x3dc [ 219.620391] [] pwm_request_from_chip+0x38/0x6c [ 219.626312] [] pwm_export_store+0x50/0x140 [ 219.631896] [] dev_attr_store+0x18/0x24 [ 219.637207] [] sysfs_write_file+0x16c/0x1a0 [ 219.642883] [] vfs_write+0xb0/0x188 [ 219.647857] [] SyS_write+0x3c/0x70 [ 219.652770] [] ret_fast_syscall+0x0/0x48 [ 219.658172] -> #0 (s_active#35){++++.+}: [ 219.662353] [] __lock_acquire+0x1b28/0x1b70 [ 219.667999] [] lock_acquire+0x9c/0x128 [ 219.673248] [] sysfs_addrm_finish+0xe8/0x158 [ 219.678985] [] sysfs_hash_and_remove+0x4c/0x8c [ 219.684906] [] remove_files+0x38/0x74 [ 219.690063] [] sysfs_remove_group+0x44/0x108 [ 219.695800] [] sysfs_remove_groups+0x24/0x34 [ 219.701538] [] device_del+0xec/0x178 [ 219.706604] [] device_unregister+0xc/0x18 [ 219.712097] [] pwmchip_remove+0xd4/0xf8 [ 219.717407] [] platform_drv_remove+0x18/0x1c [ 219.723175] [] __device_release_driver+0x70/0xc8 [ 219.729248] [] driver_detach+0xb4/0xb8 [ 219.734497] [] bus_remove_driver+0x8c/0xd0 [ 219.740081] [] SyS_delete_module+0x118/0x22c [ 219.745819] [] ret_fast_syscall+0x0/0x48 [ 219.751220] [ 219.751220] other info that might help us debug this: [ 219.751220] [ 219.759216] Possible unsafe locking scenario: [ 219.759216] [ 219.765106] CPU0 CPU1 [ 219.769622] ---- ---- [ 219.774139] lock(pwm_lock); [ 219.777130] lock(s_active#35); [ 219.782897] lock(pwm_lock); [ 219.788391] lock(s_active#35); [ 219.791656] [ 219.791656] *** DEADLOCK *** [ 219.791656] [ 219.797546] 3 locks held by rmmod/1517: [ 219.801391] #0: (&__lockdep_no_validate__){......}, at: [] driver_detach+0x44/0xb8 [ 219.810028] #1: (&__lockdep_no_validate__){......}, at: [] driver_detach+0x50/0xb8 [ 219.818695] #2: (pwm_lock){+.+.+.}, at: [] pwmchip_remove+0x14/0xf8 [ 219.826049] [ 219.826049] stack backtrace: [ 219.830413] CPU: 0 PID: 1517 Comm: rmmod Not tainted 3.12.4-01557-g9921cde-dirty #134 [ 219.838256] [] (unwind_backtrace+0x0/0xf0) from [] (show_stack+0x10/0x14) [ 219.846771] [] (show_stack+0x10/0x14) from [] (dump_stack+0x74/0xb4) [ 219.854858] [] (dump_stack+0x74/0xb4) from [] (print_circular_bug+0x284/0x2d8) [ 219.863830] [] (print_circular_bug+0x284/0x2d8) from [] (__lock_acquire+0x1b28/0x1b70) [ 219.873443] [] (__lock_acquire+0x1b28/0x1b70) from [] (lock_acquire+0x9c/0x128) [ 219.882476] [] (lock_acquire+0x9c/0x128) from [] (sysfs_addrm_finish+0xe8/0x158) [ 219.891601] [] (sysfs_addrm_finish+0xe8/0x158) from [] (sysfs_hash_and_remove+0x4c/0x8c) [ 219.901397] [] (sysfs_hash_and_remove+0x4c/0x8c) from [] (remove_files+0x38/0x74) [ 219.910614] [] (remove_files+0x38/0x74) from [] (sysfs_remove_group+0x44/0x108) [ 219.919647] [] (sysfs_remove_group+0x44/0x108) from [] (sysfs_remove_groups+0x24/0x34) [ 219.929260] [] (sysfs_remove_groups+0x24/0x34) from [] (device_del+0xec/0x178) [ 219.938201] [] (device_del+0xec/0x178) from [] (device_unregister+0xc/0x18) [ 219.946899] [] (device_unregister+0xc/0x18) from [] (pwmchip_remove+0xd4/0xf8) [ 219.955841] [] (pwmchip_remove+0xd4/0xf8) from [] (platform_drv_remove+0x18/0x1c) [ 219.965057] [] (platform_drv_remove+0x18/0x1c) from [] (__device_release_driver+0x70/0xc8) [ 219.975006] [] (__device_release_driver+0x70/0xc8) from [] (driver_detach+0xb4/0xb8) [ 219.984466] [] (driver_detach+0xb4/0xb8) from [] (bus_remove_driver+0x8c/0xd0) [ 219.993438] [] (bus_remove_driver+0x8c/0xd0) from [] (SyS_delete_module+0x118/0x22c) [ 220.002899] [] (SyS_delete_module+0x118/0x22c) from [] (ret_fast_syscall+0x0/0x48) Looks like s_active lock cannot be held while pwm lock is held. The patch fixes the above issue by unlocking the pwm lock before acquiring the sysfs lock. Signed-off-by: Sourav Poddar --- drivers/pwm/core.c | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-) diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c index 2ca9504..3e1d499 100644 --- a/drivers/pwm/core.c +++ b/drivers/pwm/core.c @@ -300,6 +300,7 @@ int pwmchip_remove(struct pwm_chip *chip) if (test_bit(PWMF_REQUESTED, &pwm->flags)) { ret = -EBUSY; + mutex_unlock(&pwm_lock); goto out; } } @@ -311,10 +312,11 @@ int pwmchip_remove(struct pwm_chip *chip) free_pwms(chip); + mutex_unlock(&pwm_lock); + pwmchip_sysfs_unexport(chip); out: - mutex_unlock(&pwm_lock); return ret; } EXPORT_SYMBOL_GPL(pwmchip_remove);