From mboxrd@z Thu Jan 1 00:00:00 1970 From: marek.vasut@gmail.com (Marek Vasut) Date: Sun, 18 Dec 2011 15:06:13 +0100 Subject: [PATCH] MXS: Convert mutexes in clock.c to spinlocks Message-ID: <1324217174-6574-1-git-send-email-marek.vasut@gmail.com> To: linux-arm-kernel@lists.infradead.org List-Id: linux-arm-kernel.lists.infradead.org The mutexes can't be safely used under certain circumstances. I noticed this issue during some network instability at home: 1) I received information about duplicate ipv6 address 2) I use amba-pl011 driver for console output Backtrace produced (not 80-per-line aligned): eth0: IPv6 duplicate address XXXX::YYYY:ZZZZ:WWWW:0 detected! ------------[ cut here ]------------ WARNING: at kernel/mutex.c:198 mutex_lock_nested+0x284/0x2c0() Modules linked in: [] (unwind_backtrace+0x0/0xf0) from [] (warn_slowpath_common+0x4c/0x64) [] (warn_slowpath_common+0x4c/0x64) from [] (warn_slowpath_null+0x1c/0x24) [] (warn_slowpath_null+0x1c/0x24) from [] (mutex_lock_nested+0x284/0x2c0) [] (mutex_lock_nested+0x284/0x2c0) from [] (clk_enable+0x20/0x48) [] (clk_enable+0x20/0x48) from [] (pl011_console_write+0x20/0x74) [] (pl011_console_write+0x20/0x74) from [] (__call_console_drivers+0x7c/0x94) [] (__call_console_drivers+0x7c/0x94) from [] (console_unlock+0xf8/0x244) [] (console_unlock+0xf8/0x244) from [] (vprintk+0x29c/0x484) [] (vprintk+0x29c/0x484) from [] (printk+0x20/0x30) [] (printk+0x20/0x30) from [] (addrconf_dad_failure+0x148/0x158) [] (addrconf_dad_failure+0x148/0x158) from [] (ndisc_rcv+0xb38/0xdb0) [] (ndisc_rcv+0xb38/0xdb0) from [] (icmpv6_rcv+0x6ec/0x9c4) [] (icmpv6_rcv+0x6ec/0x9c4) from [] (ip6_input_finish+0x144/0x4e0) [] (ip6_input_finish+0x144/0x4e0) from [] (ip6_mc_input+0xb8/0x154) [] (ip6_mc_input+0xb8/0x154) from [] (ipv6_rcv+0x300/0x53c) [] (ipv6_rcv+0x300/0x53c) from [] (__netif_receive_skb+0x240/0x420) [] (__netif_receive_skb+0x240/0x420) from [] (process_backlog+0x90/0x150) [] (process_backlog+0x90/0x150) from [] (net_rx_action+0xc0/0x264) [] (net_rx_action+0xc0/0x264) from [] (__do_softirq+0xa8/0x214) [] (__do_softirq+0xa8/0x214) from [] (irq_exit+0x8c/0x94) [] (irq_exit+0x8c/0x94) from [] (handle_IRQ+0x34/0x84) [] (handle_IRQ+0x34/0x84) from [] (__irq_usr+0x38/0x80) ---[ end trace 32eab6a8dcdca9c0 ]--- So the problem summary: 1) ICMPv6 packet is received 2) Interrupt is produced, packet is actually received 3) Packet processing goes on (in tasklet) 4) Duplicate ipv6 address detected, warning produced 5) printk() called, calls pl011_console_write() 6) pl011_console_write() calls clk_enable() 7) clk_enable() for mxs does a mutex_lock(), which is wrong in this context Signed-off-by: Marek Vasut Cc: Wolfgang Denk Cc: Stefano Babic Cc: Shawn Guo Cc: Huang Shijie Cc: Sascha Hauer --- arch/arm/mach-mxs/clock.c | 25 +++++++++++++++---------- 1 files changed, 15 insertions(+), 10 deletions(-) diff --git a/arch/arm/mach-mxs/clock.c b/arch/arm/mach-mxs/clock.c index a7093c8..677ecff 100644 --- a/arch/arm/mach-mxs/clock.c +++ b/arch/arm/mach-mxs/clock.c @@ -32,7 +32,7 @@ #include #include #include -#include +#include #include #include #include @@ -41,7 +41,7 @@ #include static LIST_HEAD(clocks); -static DEFINE_MUTEX(clocks_mutex); +static DEFINE_SPINLOCK(clocks_lock); /*------------------------------------------------------------------------- * Standard clock functions defined in include/linux/clk.h @@ -80,13 +80,14 @@ static int __clk_enable(struct clk *clk) int clk_enable(struct clk *clk) { int ret = 0; + unsigned long flags; if (clk == NULL || IS_ERR(clk)) return -EINVAL; - mutex_lock(&clocks_mutex); + spin_lock_irqsave(&clocks_lock, flags); ret = __clk_enable(clk); - mutex_unlock(&clocks_mutex); + spin_unlock_irqrestore(&clocks_lock, flags); return ret; } @@ -98,12 +99,14 @@ EXPORT_SYMBOL(clk_enable); */ void clk_disable(struct clk *clk) { + unsigned long flags; + if (clk == NULL || IS_ERR(clk)) return; - mutex_lock(&clocks_mutex); + spin_lock_irqsave(&clocks_lock, flags); __clk_disable(clk); - mutex_unlock(&clocks_mutex); + spin_unlock_irqrestore(&clocks_lock, flags); } EXPORT_SYMBOL(clk_disable); @@ -142,14 +145,15 @@ EXPORT_SYMBOL(clk_round_rate); */ int clk_set_rate(struct clk *clk, unsigned long rate) { + unsigned long flags; int ret = -EINVAL; if (clk == NULL || IS_ERR(clk) || clk->set_rate == NULL || rate == 0) return ret; - mutex_lock(&clocks_mutex); + spin_lock_irqsave(&clocks_lock, flags); ret = clk->set_rate(clk, rate); - mutex_unlock(&clocks_mutex); + spin_unlock_irqrestore(&clocks_lock, flags); return ret; } @@ -160,6 +164,7 @@ int clk_set_parent(struct clk *clk, struct clk *parent) { int ret = -EINVAL; struct clk *old; + unsigned long flags; if (clk == NULL || IS_ERR(clk) || parent == NULL || IS_ERR(parent) || clk->set_parent == NULL) @@ -168,7 +173,7 @@ int clk_set_parent(struct clk *clk, struct clk *parent) if (clk->usecount) clk_enable(parent); - mutex_lock(&clocks_mutex); + spin_lock_irqsave(&clocks_lock, flags); ret = clk->set_parent(clk, parent); if (ret == 0) { old = clk->parent; @@ -176,7 +181,7 @@ int clk_set_parent(struct clk *clk, struct clk *parent) } else { old = parent; } - mutex_unlock(&clocks_mutex); + spin_unlock_irqrestore(&clocks_lock, flags); if (clk->usecount) clk_disable(old); -- 1.7.6.4