diff mbox series

tty: serial: meson_uart: Init port lock early

Message ID 20200705092736.1030598-1-maz@kernel.org (mailing list archive)
State Not Applicable
Headers show
Series tty: serial: meson_uart: Init port lock early | expand

Commit Message

Marc Zyngier July 5, 2020, 9:27 a.m. UTC
The meson UART driver triggers a lockdep splat at boot time, due
to the new expectation that the driver has to initialize the
per-port spinlock itself.

It remains unclear why a double initialization of the port
spinlock is a desirable outcome, but in the meantime let's
fix the splat.

Fixes: a3cb39d258ef ("serial: core: Allow detach and attach serial device for console")
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Marc Zyngier <maz@kernel.org>
---
 drivers/tty/serial/meson_uart.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Andy Shevchenko July 5, 2020, 10:07 a.m. UTC | #1
On Sun, Jul 5, 2020 at 12:32 PM Marc Zyngier <maz@kernel.org> wrote:
>
> The meson UART driver triggers a lockdep splat at boot time, due
> to the new expectation that the driver has to initialize the
> per-port spinlock itself.
>
> It remains unclear why a double initialization of the port
> spinlock is a desirable outcome, but in the meantime let's
> fix the splat.
>

Thanks!

Can you test patch from [1] if it helps and doesn't break anything in your case?

[1]: https://lore.kernel.org/linux-serial/20200217114016.49856-1-andriy.shevchenko@linux.intel.com/T/#m9255e2a7474b160e66c7060fca5323ca3df49cfd

> Fixes: a3cb39d258ef ("serial: core: Allow detach and attach serial device for console")
> Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Signed-off-by: Marc Zyngier <maz@kernel.org>
> ---
>  drivers/tty/serial/meson_uart.c | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/drivers/tty/serial/meson_uart.c b/drivers/tty/serial/meson_uart.c
> index d2c08b760f83..386e39c90628 100644
> --- a/drivers/tty/serial/meson_uart.c
> +++ b/drivers/tty/serial/meson_uart.c
> @@ -759,6 +759,9 @@ static int meson_uart_probe(struct platform_device *pdev)
>         if (ret)
>                 return ret;
>
> +       /* Init the spinlock early in case this is the console */
> +       spin_lock_init(&port->lock);
> +
>         port->iotype = UPIO_MEM;
>         port->mapbase = res_mem->start;
>         port->mapsize = resource_size(res_mem);
> --
> 2.26.2
>
Marc Zyngier July 5, 2020, 10:28 a.m. UTC | #2
On 2020-07-05 11:07, Andy Shevchenko wrote:
> On Sun, Jul 5, 2020 at 12:32 PM Marc Zyngier <maz@kernel.org> wrote:
>> 
>> The meson UART driver triggers a lockdep splat at boot time, due
>> to the new expectation that the driver has to initialize the
>> per-port spinlock itself.
>> 
>> It remains unclear why a double initialization of the port
>> spinlock is a desirable outcome, but in the meantime let's
>> fix the splat.
>> 
> 
> Thanks!
> 
> Can you test patch from [1] if it helps and doesn't break anything in 
> your case?
> 
> [1]:
> https://lore.kernel.org/linux-serial/20200217114016.49856-1-andriy.shevchenko@linux.intel.com/T/#m9255e2a7474b160e66c7060fca5323ca3df49cfd

On its own, this patch doesn't seem to cure the issue (and it
adds a compile-time warning due to unused flags).

Or did you mean to test it in complement of my patch?

         M.
Andy Shevchenko July 5, 2020, 11:22 a.m. UTC | #3
On Sun, Jul 05, 2020 at 11:28:56AM +0100, Marc Zyngier wrote:
> On 2020-07-05 11:07, Andy Shevchenko wrote:
> > On Sun, Jul 5, 2020 at 12:32 PM Marc Zyngier <maz@kernel.org> wrote:
> > > 
> > > The meson UART driver triggers a lockdep splat at boot time, due
> > > to the new expectation that the driver has to initialize the
> > > per-port spinlock itself.
> > > 
> > > It remains unclear why a double initialization of the port
> > > spinlock is a desirable outcome, but in the meantime let's
> > > fix the splat.
> > > 
> > 
> > Thanks!
> > 
> > Can you test patch from [1] if it helps and doesn't break anything in
> > your case?
> > 
> > [1]:
> > https://lore.kernel.org/linux-serial/20200217114016.49856-1-andriy.shevchenko@linux.intel.com/T/#m9255e2a7474b160e66c7060fca5323ca3df49cfd
> 
> On its own, this patch doesn't seem to cure the issue (and it
> adds a compile-time warning due to unused flags).

Ah, sorry, I didn't compile it.
And after second though I think we simple need to initialise spin lock there.
Can you try below (compile-tested only):

From ed4c882e7dc3fdfcea706ada0678c060c36163b3 Mon Sep 17 00:00:00 2001
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Date: Sat, 4 Jul 2020 19:30:39 +0300
Subject: [PATCH 1/1] serial: core: Initialise spin lock before use in
 uart_configure_port()

In case of the port to be used as a console we must initialise
a spin lock before use.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/tty/serial/serial_core.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
index 3cc183acf7ba..a81b4900eb60 100644
--- a/drivers/tty/serial/serial_core.c
+++ b/drivers/tty/serial/serial_core.c
@@ -2371,6 +2371,13 @@ uart_configure_port(struct uart_driver *drv, struct uart_state *state,
 		/* Power up port for set_mctrl() */
 		uart_change_pm(state, UART_PM_STATE_ON);
 
+		/*
+		 * If this driver supports console, and it hasn't been
+		 * successfully registered yet, initialise spin lock for it.
+		 */
+		if (port->cons && !(port->cons->flags & CON_ENABLED))
+			spin_lock_init(&port->lock);
+
 		/*
 		 * Ensure that the modem control lines are de-activated.
 		 * keep the DTR setting that is set in uart_set_options()
Marc Zyngier July 5, 2020, 3:51 p.m. UTC | #4
On 2020-07-05 12:22, Andy Shevchenko wrote:
> On Sun, Jul 05, 2020 at 11:28:56AM +0100, Marc Zyngier wrote:
>> On 2020-07-05 11:07, Andy Shevchenko wrote:
>> > On Sun, Jul 5, 2020 at 12:32 PM Marc Zyngier <maz@kernel.org> wrote:
>> > >
>> > > The meson UART driver triggers a lockdep splat at boot time, due
>> > > to the new expectation that the driver has to initialize the
>> > > per-port spinlock itself.
>> > >
>> > > It remains unclear why a double initialization of the port
>> > > spinlock is a desirable outcome, but in the meantime let's
>> > > fix the splat.
>> > >
>> >
>> > Thanks!
>> >
>> > Can you test patch from [1] if it helps and doesn't break anything in
>> > your case?
>> >
>> > [1]:
>> > https://lore.kernel.org/linux-serial/20200217114016.49856-1-andriy.shevchenko@linux.intel.com/T/#m9255e2a7474b160e66c7060fca5323ca3df49cfd
>> 
>> On its own, this patch doesn't seem to cure the issue (and it
>> adds a compile-time warning due to unused flags).
> 
> Ah, sorry, I didn't compile it.
> And after second though I think we simple need to initialise spin lock 
> there.
> Can you try below (compile-tested only):
> 
> From ed4c882e7dc3fdfcea706ada0678c060c36163b3 Mon Sep 17 00:00:00 2001
> From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> Date: Sat, 4 Jul 2020 19:30:39 +0300
> Subject: [PATCH 1/1] serial: core: Initialise spin lock before use in
>  uart_configure_port()
> 
> In case of the port to be used as a console we must initialise
> a spin lock before use.
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>  drivers/tty/serial/serial_core.c | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/drivers/tty/serial/serial_core.c 
> b/drivers/tty/serial/serial_core.c
> index 3cc183acf7ba..a81b4900eb60 100644
> --- a/drivers/tty/serial/serial_core.c
> +++ b/drivers/tty/serial/serial_core.c
> @@ -2371,6 +2371,13 @@ uart_configure_port(struct uart_driver *drv,
> struct uart_state *state,
>  		/* Power up port for set_mctrl() */
>  		uart_change_pm(state, UART_PM_STATE_ON);
> 
> +		/*
> +		 * If this driver supports console, and it hasn't been
> +		 * successfully registered yet, initialise spin lock for it.
> +		 */
> +		if (port->cons && !(port->cons->flags & CON_ENABLED))
> +			spin_lock_init(&port->lock);
> +
>  		/*
>  		 * Ensure that the modem control lines are de-activated.
>  		 * keep the DTR setting that is set in uart_set_options()
> --
> 2.27.0
> 
> 
> 
>> Or did you mean to test it in complement of my patch?
> 
> No, the idea to avoid "fixing" driver as you rightfully noticed a
> double init issue.

This certainly keeps lockdep quiet on my system. You probably want
to set the lockdep class whilst you're at it (keeping that code
common with uart_port_spin_lock_init).

Thanks,

         M.
diff mbox series

Patch

diff --git a/drivers/tty/serial/meson_uart.c b/drivers/tty/serial/meson_uart.c
index d2c08b760f83..386e39c90628 100644
--- a/drivers/tty/serial/meson_uart.c
+++ b/drivers/tty/serial/meson_uart.c
@@ -759,6 +759,9 @@  static int meson_uart_probe(struct platform_device *pdev)
 	if (ret)
 		return ret;
 
+	/* Init the spinlock early in case this is the console */
+	spin_lock_init(&port->lock);
+
 	port->iotype = UPIO_MEM;
 	port->mapbase = res_mem->start;
 	port->mapsize = resource_size(res_mem);