linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] tty: serial: msm: Fix lock init issue with earlycon
@ 2014-10-17 13:13 Kumar Gala
  2014-10-20 18:27 ` Stephen Boyd
  0 siblings, 1 reply; 6+ messages in thread
From: Kumar Gala @ 2014-10-17 13:13 UTC (permalink / raw)
  To: gregkh; +Cc: Kumar Gala, linux-kernel, linux-arm-msm, linux-arm-kernel

With CONFIG_DEBUG_SPINLOCK enabled we see:

BUG: spinlock bad magic on CPU#0, swapper/0
 lock: early_console_dev+0x8/0x160, .magic: 00000000, .owner: <none>/-1, .owner_cpu: 0
CPU: 0 PID: 0 Comm: swapper Not tainted 3.17.0-09733-gb446b33-dirty #18
Call trace:
[<c0087ba0>] dump_backtrace+0x0/0x140
[<c0087cf0>] show_stack+0x10/0x1c
[<c0598be0>] dump_stack+0x74/0xb8
[<c00cb720>] spin_dump+0x78/0x88
[<c00cb754>] spin_bug+0x24/0x34
[<c00cb7e4>] do_raw_spin_lock+0x30/0x158
[<c059ea2c>] _raw_spin_lock+0x1c/0x2c
[<c02e0e30>] __msm_console_write+0x68/0x154
[<c02e0f50>] msm_serial_early_write_dm+0x14/0x20
[<c00cf040>] call_console_drivers.constprop.23+0xa4/0xc4
[<c00d00c4>] console_unlock+0x2a8/0x330
[<c00d121c>] register_console+0x26c/0x338
[<c0805af4>] setup_earlycon+0x2c0/0x300
[<c0805c48>] msm_serial_dm_setup_earlycon+0x18/0x24
[<c07ed158>] do_early_param+0x84/0xd0
[<c00aec18>] parse_args+0x2b4/0x3ec
[<c07ed588>] parse_early_options+0x2c/0x38
[<c07ed5c8>] parse_early_param+0x34/0x50
[<c07f03c0>] setup_arch+0x290/0x604
[<c07ed67c>] start_kernel+0x94/0x38c

As the earlycon write function for msm requires a lock, we need to init
it as part of the setup call.

Signed-off-by: Kumar Gala <galak@codeaurora.org>
---
 drivers/tty/serial/msm_serial.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/tty/serial/msm_serial.c b/drivers/tty/serial/msm_serial.c
index 4b6c783..8ab27c9 100644
--- a/drivers/tty/serial/msm_serial.c
+++ b/drivers/tty/serial/msm_serial.c
@@ -973,6 +973,8 @@ msm_serial_early_console_setup(struct earlycon_device *device, const char *opt)
 	if (!device->port.membase)
 		return -ENODEV;
 
+	spin_lock_init(&device->port.lock);
+
 	device->con->write = msm_serial_early_write;
 	return 0;
 }
@@ -995,6 +997,8 @@ msm_serial_early_console_setup_dm(struct earlycon_device *device,
 	if (!device->port.membase)
 		return -ENODEV;
 
+	spin_lock_init(&device->port.lock);
+
 	device->con->write = msm_serial_early_write_dm;
 	return 0;
 }
-- 
Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] tty: serial: msm: Fix lock init issue with earlycon
  2014-10-17 13:13 [PATCH] tty: serial: msm: Fix lock init issue with earlycon Kumar Gala
@ 2014-10-20 18:27 ` Stephen Boyd
  2014-10-20 21:38   ` Peter Hurley
  0 siblings, 1 reply; 6+ messages in thread
From: Stephen Boyd @ 2014-10-20 18:27 UTC (permalink / raw)
  To: Kumar Gala
  Cc: gregkh, linux-kernel, linux-arm-msm, linux-arm-kernel, Rob Herring

On 10/17/2014 06:13 AM, Kumar Gala wrote:
> With CONFIG_DEBUG_SPINLOCK enabled we see:
>
> BUG: spinlock bad magic on CPU#0, swapper/0
>   lock: early_console_dev+0x8/0x160, .magic: 00000000, .owner: <none>/-1, .owner_cpu: 0
> CPU: 0 PID: 0 Comm: swapper Not tainted 3.17.0-09733-gb446b33-dirty #18

[...]

> diff --git a/drivers/tty/serial/msm_serial.c b/drivers/tty/serial/msm_serial.c
> index 4b6c783..8ab27c9 100644
> --- a/drivers/tty/serial/msm_serial.c
> +++ b/drivers/tty/serial/msm_serial.c
> @@ -973,6 +973,8 @@ msm_serial_early_console_setup(struct earlycon_device *device, const char *opt)
>   	if (!device->port.membase)
>   		return -ENODEV;
>   
> +	spin_lock_init(&device->port.lock);
> +
>   	device->con->write = msm_serial_early_write;
>   	return 0;
>   }
> @@ -995,6 +997,8 @@ msm_serial_early_console_setup_dm(struct earlycon_device *device,
>   	if (!device->port.membase)
>   		return -ENODEV;
>   
> +	spin_lock_init(&device->port.lock);
> +
>   	device->con->write = msm_serial_early_write_dm;
>   	return 0;
>   }

Could this be done in the tty core instead?

-- 
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] tty: serial: msm: Fix lock init issue with earlycon
  2014-10-20 18:27 ` Stephen Boyd
@ 2014-10-20 21:38   ` Peter Hurley
  2014-10-20 22:16     ` Stephen Boyd
  0 siblings, 1 reply; 6+ messages in thread
From: Peter Hurley @ 2014-10-20 21:38 UTC (permalink / raw)
  To: Stephen Boyd, Kumar Gala
  Cc: gregkh, linux-kernel, linux-arm-msm, linux-arm-kernel, Rob Herring

On 10/20/2014 02:27 PM, Stephen Boyd wrote:
> On 10/17/2014 06:13 AM, Kumar Gala wrote:
>> With CONFIG_DEBUG_SPINLOCK enabled we see:
>>
>> BUG: spinlock bad magic on CPU#0, swapper/0
>>   lock: early_console_dev+0x8/0x160, .magic: 00000000, .owner: <none>/-1, .owner_cpu: 0
>> CPU: 0 PID: 0 Comm: swapper Not tainted 3.17.0-09733-gb446b33-dirty #18
> 
> [...]
> 
>> diff --git a/drivers/tty/serial/msm_serial.c b/drivers/tty/serial/msm_serial.c
>> index 4b6c783..8ab27c9 100644
>> --- a/drivers/tty/serial/msm_serial.c
>> +++ b/drivers/tty/serial/msm_serial.c
>> @@ -973,6 +973,8 @@ msm_serial_early_console_setup(struct earlycon_device *device, const char *opt)
>>       if (!device->port.membase)
>>           return -ENODEV;
>>   +    spin_lock_init(&device->port.lock);
>> +
>>       device->con->write = msm_serial_early_write;
>>       return 0;
>>   }
>> @@ -995,6 +997,8 @@ msm_serial_early_console_setup_dm(struct earlycon_device *device,
>>       if (!device->port.membase)
>>           return -ENODEV;
>>   +    spin_lock_init(&device->port.lock);
>> +
>>       device->con->write = msm_serial_early_write_dm;
>>       return 0;
>>   }
> 
> Could this be done in the tty core instead?

Or even better: refactor __msm_console_write() so no spin_lock() is required
for the earlycon write.

FWIW, __msm_console_write() is a deadlock-waiting-to_happen since it does
not disable interrupts with spin_lock_irqsave().

Regards,
Peter Hurley

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] tty: serial: msm: Fix lock init issue with earlycon
  2014-10-20 21:38   ` Peter Hurley
@ 2014-10-20 22:16     ` Stephen Boyd
  2014-10-20 22:20       ` Stephen Boyd
  0 siblings, 1 reply; 6+ messages in thread
From: Stephen Boyd @ 2014-10-20 22:16 UTC (permalink / raw)
  To: Peter Hurley
  Cc: Kumar Gala, gregkh, linux-kernel, linux-arm-msm,
	linux-arm-kernel, Rob Herring

On 10/20, Peter Hurley wrote:
> On 10/20/2014 02:27 PM, Stephen Boyd wrote:
> > On 10/17/2014 06:13 AM, Kumar Gala wrote:
> >> With CONFIG_DEBUG_SPINLOCK enabled we see:
> >>
> >> BUG: spinlock bad magic on CPU#0, swapper/0
> >>   lock: early_console_dev+0x8/0x160, .magic: 00000000, .owner: <none>/-1, .owner_cpu: 0
> >> CPU: 0 PID: 0 Comm: swapper Not tainted 3.17.0-09733-gb446b33-dirty #18
> > 
> > [...]
> > 
> >> diff --git a/drivers/tty/serial/msm_serial.c b/drivers/tty/serial/msm_serial.c
> >> index 4b6c783..8ab27c9 100644
> >> --- a/drivers/tty/serial/msm_serial.c
> >> +++ b/drivers/tty/serial/msm_serial.c
> >> @@ -973,6 +973,8 @@ msm_serial_early_console_setup(struct earlycon_device *device, const char *opt)
> >>       if (!device->port.membase)
> >>           return -ENODEV;
> >>   +    spin_lock_init(&device->port.lock);
> >> +
> >>       device->con->write = msm_serial_early_write;
> >>       return 0;
> >>   }
> >> @@ -995,6 +997,8 @@ msm_serial_early_console_setup_dm(struct earlycon_device *device,
> >>       if (!device->port.membase)
> >>           return -ENODEV;
> >>   +    spin_lock_init(&device->port.lock);
> >> +
> >>       device->con->write = msm_serial_early_write_dm;
> >>       return 0;
> >>   }
> > 
> > Could this be done in the tty core instead?
> 
> Or even better: refactor __msm_console_write() so no spin_lock() is required
> for the earlycon write.

Can't we keep the early console forever with keep_bootcon? In
which case we may want to prevent things from trampling on each
other? I don't see how the lock will help us here though because
the port isn't even the same between the earlycon and the ttyMSM
console. Removing the lock from the earlycon path is probably
easier than caring about this debugging scenario.

> 
> FWIW, __msm_console_write() is a deadlock-waiting-to_happen since it does
> not disable interrupts with spin_lock_irqsave().
> 

Yeah we should fix that. As far as I can tell we've never used
the irqsave variant of the lock in the console path. Did this
become necessary at some point since this driver was introduced?
I'm wondering how many stable trees need the fix.

-- 
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] tty: serial: msm: Fix lock init issue with earlycon
  2014-10-20 22:16     ` Stephen Boyd
@ 2014-10-20 22:20       ` Stephen Boyd
  2014-10-21 19:42         ` Peter Hurley
  0 siblings, 1 reply; 6+ messages in thread
From: Stephen Boyd @ 2014-10-20 22:20 UTC (permalink / raw)
  To: Peter Hurley
  Cc: Kumar Gala, gregkh, linux-kernel, linux-arm-msm,
	linux-arm-kernel, Rob Herring

On 10/20, Stephen Boyd wrote:
> On 10/20, Peter Hurley wrote:
> > 
> > FWIW, __msm_console_write() is a deadlock-waiting-to_happen since it does
> > not disable interrupts with spin_lock_irqsave().
> > 
> 
> Yeah we should fix that. As far as I can tell we've never used
> the irqsave variant of the lock in the console path. Did this
> become necessary at some point since this driver was introduced?
> I'm wondering how many stable trees need the fix.

Actually I don't see this case. It looks like the console is
always called in call_console_drivers() with irqs saved and
disabled via the logbuf_lock in console_cont_flush() or
console_unlock().

-- 
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] tty: serial: msm: Fix lock init issue with earlycon
  2014-10-20 22:20       ` Stephen Boyd
@ 2014-10-21 19:42         ` Peter Hurley
  0 siblings, 0 replies; 6+ messages in thread
From: Peter Hurley @ 2014-10-21 19:42 UTC (permalink / raw)
  To: Stephen Boyd
  Cc: Kumar Gala, gregkh, linux-kernel, linux-arm-msm,
	linux-arm-kernel, Rob Herring

On 10/20/2014 06:20 PM, Stephen Boyd wrote:
> On 10/20, Stephen Boyd wrote:
>> On 10/20, Peter Hurley wrote:
>>>
>>> FWIW, __msm_console_write() is a deadlock-waiting-to_happen since it does
>>> not disable interrupts with spin_lock_irqsave().
>>>
>>
>> Yeah we should fix that. As far as I can tell we've never used
>> the irqsave variant of the lock in the console path. Did this
>> become necessary at some point since this driver was introduced?
>> I'm wondering how many stable trees need the fix.
> 
> Actually I don't see this case. It looks like the console is
> always called in call_console_drivers() with irqs saved and
> disabled via the logbuf_lock in console_cont_flush() or
> console_unlock().

Thanks for bringing that to my attention.

That looks like a vestige of the initial transition away from BKL.
I might look into just disabling preemption; even that might not
really be necessary.

Regards,
Peter Hurley


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2014-10-21 19:42 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-10-17 13:13 [PATCH] tty: serial: msm: Fix lock init issue with earlycon Kumar Gala
2014-10-20 18:27 ` Stephen Boyd
2014-10-20 21:38   ` Peter Hurley
2014-10-20 22:16     ` Stephen Boyd
2014-10-20 22:20       ` Stephen Boyd
2014-10-21 19:42         ` Peter Hurley

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).