FlexCAN driver triggers kernel BUG in BUSOFF restart
Subsystems (3)
Hi,
I was asked by Freescale to post this kernel BUG to you and your email address appears in the kernel documentation, so please accept my apologies if you did not wish to see this.
A kernel BUG is triggered during a CAN send operation (kernel version 3.15.7, stack trace follows below). A simple program, such as the one included in the kernel's CAN documentation, will cause this problem, as will the can-utils programs 'cangen' and 'cansend'.
I have narrowed down the problem to restart timeouts after entering the BUSOFF state. My board is not yet physically connected to a CAN bus, so it goes into a BUSOFF state when sending. Normal CAN bus operation means that after the restart timeout, the driver should automatically come out of BUSOFF state. I can alter the timeout period and, no matter how long it is, the BUG is triggered immediately the timeout occurs. Clearly, the timeout code is being entered inappropriately from flexcan_chip_start() in flexcan.c.
So a short term workaround is to not let the CAN bus go into BUSOFF, but this is not a viable real world solution. Another workaround is to detect the BUSOFF in code, then to cloes and reopen the CAN socket (I haven't tried exactly this, but doing 'ifconfig can0 down' followed by 'ifconfig can0 up' clears the BUSOFF state and avoids the problem).
Thank you for reading this.
Typical stack trace:
BUG: scheduling while atomic: swapper/0/0/0x00000100
1 lock held by swapper/0/0:
#0: (((&priv->restart_timer))){+.-...}, at: [<8002fe60>] call_timer_fn+0x0/0xe8
Modules linked in:
CPU: 0 PID: 0 Comm: swapper/0 Tainted: G W 3.15.7 #5
Backtrace:
[<80011ba4>] (dump_backtrace) from [<80011d40>] (show_stack+0x18/0x1c)
r6:00000000 r5:00000000 r4:00000000 r3:00000000
[<80011d28>] (show_stack) from [<805de120>] (dump_stack+0x88/0xa4)
[<805de098>] (dump_stack) from [<805db3ec>] (__schedule_bug+0x64/0x7c)
r5:80867268 r4:80867268
[<805db388>] (__schedule_bug) from [<805e09b0>] (__schedule+0x540/0x5f8)
r4:bf7c7b00 r3:00000002
[<805e0470>] (__schedule) from [<805e0b5c>] (schedule+0x38/0x88)
r10:8085c000 r9:00000000 r8:00000001 r7:00000000 r6:00004e20 r5:00000000
r4:00002710
[<805e0b24>] (schedule) from [<805e03c4>] (schedule_hrtimeout_range_clock+0xe0/0x158)
[<805e02e4>] (schedule_hrtimeout_range_clock) from [<805e0450>] (schedule_hrtimeout_range+0x14/0x18)
r10:808644c4 r8:bf335e00 r7:00000000 r6:c09b8000 r5:c09b8000 r4:bf335800
[<805e043c>] (schedule_hrtimeout_range) from [<8002fb58>] (usleep_range+0x50/0x58)
[<8002fb08>] (usleep_range) from [<803f2964>] (flexcan_chip_start+0x7c/0x440)
[<803f28e8>] (flexcan_chip_start) from [<803f3994>] (flexcan_set_mode+0x28/0x54)
r10:bf335800 r9:803f1680 r8:803f1680 r7:00000100 r6:00000001 r5:bf335800
r4:bf335800
[<803f396c>] (flexcan_set_mode) from [<803f1718>] (can_restart+0x98/0xd4)
r5:8085c000 r4:bf335800
[<803f1680>] (can_restart) from [<8002fed0>] (call_timer_fn+0x70/0xe8)
r5:8085c000 r4:8085de00
[<8002fe60>] (call_timer_fn) from [<80030810>] (run_timer_softirq+0x1b0/0x24c)
r10:8085e0c0 r8:bf335800 r7:00000000 r6:8085de40 r5:808b3500 r4:bf335e74
[<80030660>] (run_timer_softirq) from [<8002a1bc>] (__do_softirq+0x128/0x26c)
r10:00000001 r9:00000100 r8:00000001 r7:8085c000 r6:8085e080 r5:8085e084
r4:00000000
[<8002a094>] (__do_softirq) from [<8002a5f8>] (irq_exit+0xb0/0x104)
r10:805e82a8 r9:8085c000 r8:00000000 r7:f4000100 r6:00000000 r5:0000001d
r4:8085c000
[<8002a548>] (irq_exit) from [<8000f31c>] (handle_IRQ+0x44/0x9c)
r4:80858ffc r3:00000182
[<8000f2d8>] (handle_IRQ) from [<80008540>] (gic_handle_irq+0x30/0x64)
r6:8085df20 r5:80864a98 r4:f400010c r3:000000a0
[<80008510>] (gic_handle_irq) from [<80012864>] (__irq_svc+0x44/0x58)
Exception stack(0x8085df20 to 0x8085df68)df20: 00000001 00000001 00000000 80867268 8085c000 80864588 80864538 8085c000
df40: 00000000 8085c000 805e82a8 8085df74 8085df38 8085df68 800633f0 8000f6a0
df60: 200e0013 ffffffff
r7:8085df54 r6:ffffffff r5:200e0013 r4:8000f6a0
[<8000f678>] (arch_cpu_idle) from [<8005c72c>] (cpu_startup_entry+0xfc/0x160) [<8005c630>] (cpu_startup_entry) from [<805d81e8>] (rest_init+0xb0/0xd8) r7:808045f8 r3:00000000
[<805d8138>] (rest_init) from [<807d3b4c>] (start_kernel+0x310/0x374) r5:808b22c0 r4:80864638
[<807d383c>] (start_kernel) from [<10008074>] (0x10008074) flexcan 2090000.flexcan can0: writing ctrl=0x0729a055
--
Keith Lugsden
Senior Software Engineer
LSI-Robway Pty Ltd – A Division of Load Systems International
Direct:+61 (0)8 8238 3540 Mobile: +61 (0) 420 307 157 Email: [email protected] Web: www.lsirobway.com.au
Marc Kleine-Budde
maintainerQuoted 3 lines · Keith Lugsden
I was asked by Freescale to post this kernel BUG to you and your email address appears in the kernel documentation, so please accept my apologies if you did not wish to see this.
Thanks for the bug report.
Quoted 4 lines
A kernel BUG is triggered during a CAN send operation (kernel version 3.15.7, stack trace follows below). A simple program, such as the one included in the kernel's CAN documentation, will cause this problem, as will the can-utils programs 'cangen' and 'cansend'.
[...]
Quoted 18 lines
Typical stack trace:
BUG: scheduling while atomic: swapper/0/0/0x00000100 1 lock held by swapper/0/0: #0: (((&priv->restart_timer))){+.-...}, at: [<8002fe60>] call_timer_fn+0x0/0xe8 Modules linked in: CPU: 0 PID: 0 Comm: swapper/0 Tainted: G W 3.15.7 #5 Backtrace: [<80011ba4>] (dump_backtrace) from [<80011d40>] (show_stack+0x18/0x1c) r6:00000000 r5:00000000 r4:00000000 r3:00000000 [<80011d28>] (show_stack) from [<805de120>] (dump_stack+0x88/0xa4) [<805de098>] (dump_stack) from [<805db3ec>] (__schedule_bug+0x64/0x7c) r5:80867268 r4:80867268 [<805db388>] (__schedule_bug) from [<805e09b0>] (__schedule+0x540/0x5f8) r4:bf7c7b00 r3:00000002 [<805e0470>] (__schedule) from [<805e0b5c>] (schedule+0x38/0x88) r10:8085c000 r9:00000000 r8:00000001 r7:00000000 r6:00004e20 r5:00000000
Quoted 12 lines
r4:00002710
[<805e0b24>] (schedule) from [<805e03c4>] (schedule_hrtimeout_range_clock+0xe0/0x158)
[<805e02e4>] (schedule_hrtimeout_range_clock) from [<805e0450>] (schedule_hrtimeout_range+0x14/0x18)
r10:808644c4 r8:bf335e00 r7:00000000 r6:c09b8000 r5:c09b8000 r4:bf335800 [<805e043c>] (schedule_hrtimeout_range) from [<8002fb58>] (usleep_range+0x50/0x58)
[<8002fb08>] (usleep_range) from [<803f2964>] (flexcan_chip_start+0x7c/0x440)
[<803f28e8>] (flexcan_chip_start) from [<803f3994>] (flexcan_set_mode+0x28/0x54)
[...]
David Jander already provided a fix for this problem:
8badd65 can: flexcan: avoid calling usleep_range from interrupt context
It will hit mainline soon and then be backported to the stable trees.
Marc
---
From 8badd65e48c90d66587359d5329c2813088c0f50 Mon Sep 17 00:00:00 2001
From: David Jander <[email protected]>
Date: Wed, 27 Aug 2014 12:02:16 +0200
Subject: [PATCH] can: flexcan: avoid calling usleep_range from interrupt
context
Apparently can_restart() runs from a (timer-) interrupt and can call flexcan_chip_[en|dis]able(), so avoid using usleep_range()
--- drivers/net/can/flexcan.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/net/can/flexcan.c +5 -5
@@ -298,7 +298,7 @@ static int flexcan_chip_enable(struct flexcan_priv *priv)flexcan_write (reg, ®s->mcr);while (timeout-- && (flexcan_read (®s->mcr) &FLEXCAN_MCR_LPM_ACK )) -usleep_range (10 ,20 ); +udelay (10 );if (flexcan_read (®s->mcr) &FLEXCAN_MCR_LPM_ACK )return -ETIMEDOUT ;
@@ -317,7 +317,7 @@ static int flexcan_chip_disable(struct flexcan_priv *priv)flexcan_write (reg, ®s->mcr);while (timeout-- && !(flexcan_read (®s->mcr) &FLEXCAN_MCR_LPM_ACK )) -usleep_range (10 ,20 ); +udelay (10 );if (!(flexcan_read (®s->mcr) &FLEXCAN_MCR_LPM_ACK ))return -ETIMEDOUT ;
@@ -336,7 +336,7 @@ static int flexcan_chip_freeze(struct flexcan_priv *priv)flexcan_write (reg, ®s->mcr);while (timeout-- && !(flexcan_read (®s->mcr) &FLEXCAN_MCR_FRZ_ACK )) -usleep_range (100 ,200 ); +udelay (100 );if (!(flexcan_read (®s->mcr) &FLEXCAN_MCR_FRZ_ACK ))return -ETIMEDOUT ;
@@ -355,7 +355,7 @@ static int flexcan_chip_unfreeze(struct flexcan_priv *priv)flexcan_write (reg, ®s->mcr);while (timeout-- && (flexcan_read (®s->mcr) &FLEXCAN_MCR_FRZ_ACK )) -usleep_range (10 ,20 ); +udelay (10 );if (flexcan_read (®s->mcr) &FLEXCAN_MCR_FRZ_ACK )return -ETIMEDOUT ;
@@ -370,7 +370,7 @@ static int flexcan_chip_softreset(struct flexcan_priv *priv)flexcan_write (FLEXCAN_MCR_SOFTRST , ®s->mcr);while (timeout-- && (flexcan_read (®s->mcr) &FLEXCAN_MCR_SOFTRST )) -usleep_range (10 ,20 ); +udelay (10 );if (flexcan_read (®s->mcr) &FLEXCAN_MCR_SOFTRST )return -ETIMEDOUT ;
Signature · 6 lines
2.1.0 -- Pengutronix e.K. | Marc Kleine-Budde | Industrial Linux Solutions | Phone: +49-231-2826-924 | Vertretung West/Dortmund | Fax: +49-5121-206917-5555 | Amtsgericht Hildesheim, HRA 2686 | http://www.pengutronix.de |