Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1503214 > unrolled thread

[PATCH v2] tty: serial_core: Fix serial console crash on port shutdown

Started byGeert Uytterhoeven <geert+renesas@glider.be>
First post2016-10-18 18:40 +0200
Last post2016-10-19 17:50 +0200
Articles 3 — 3 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH v2] tty: serial_core: Fix serial console crash on port shutdown Geert Uytterhoeven <geert+renesas@glider.be> - 2016-10-18 18:40 +0200
    Re: [v2] tty: serial_core: Fix serial console crash on port shutdown Mugunthan V N <mugunthanvnm@ti.com> - 2016-10-19 11:10 +0200
    Re: [PATCH v2] tty: serial_core: Fix serial console crash on port  shutdown "Niklas Söderlund" <niklas.soderlund@ragnatech.se> - 2016-10-19 17:50 +0200

#1503214 — [PATCH v2] tty: serial_core: Fix serial console crash on port shutdown

FromGeert Uytterhoeven <geert+renesas@glider.be>
Date2016-10-18 18:40 +0200
Subject[PATCH v2] tty: serial_core: Fix serial console crash on port shutdown
Message-ID<stFAK-4gM-27@gated-at.bofh.it>
The port->console flag is always false, as uart_console() is called
before the serial console has been registered.

Hence for a serial port used as the console, uart_tty_port_shutdown()
will still be called when userspace closes the port, powering it down.
This may lead to a system lock up when the serial console driver writes
to the serial port's registers.

To fix this, move the setting of port->console after the call to
uart_configure_port(), which registers the serial console.

Fixes: 761ed4a94582ab29 ("tty: serial_core: convert uart_close to use tty_port_close")
Reported-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Acked-by: Rob Herring <robh@kernel.org>
---
v2:
  - Add Acked-by,
  - Reworded one-line summary (incl. magic word "fix").

Can easily be reproduced on Renesas boards:
  1. With systemd: hangs during boot,
  2. Without systemd: "telinit n" to switch to a runlevel that doesn't
     run a getty on ttySC0, and trigger kernel console output => hang.
---
 drivers/tty/serial/serial_core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
index 6e4f63627479db8d..ce8899c13af3d97f 100644
--- a/drivers/tty/serial/serial_core.c
+++ b/drivers/tty/serial/serial_core.c
@@ -2746,8 +2746,6 @@ int uart_add_one_port(struct uart_driver *drv, struct uart_port *uport)
 	uport->cons = drv->cons;
 	uport->minor = drv->tty_driver->minor_start + uport->line;
 
-	port->console = uart_console(uport);
-
 	/*
 	 * If this port is a console, then the spinlock is already
 	 * initialised.
@@ -2761,6 +2759,8 @@ int uart_add_one_port(struct uart_driver *drv, struct uart_port *uport)
 
 	uart_configure_port(drv, state, uport);
 
+	port->console = uart_console(uport);
+
 	num_groups = 2;
 	if (uport->attr_group)
 		num_groups++;
-- 
1.9.1

[toc] | [next] | [standalone]


#1503590 — Re: [v2] tty: serial_core: Fix serial console crash on port shutdown

FromMugunthan V N <mugunthanvnm@ti.com>
Date2016-10-19 11:10 +0200
SubjectRe: [v2] tty: serial_core: Fix serial console crash on port shutdown
Message-ID<stV2N-7yU-5@gated-at.bofh.it>
In reply to#1503214
On Tuesday 18 October 2016 10:05 PM, Geert Uytterhoeven wrote:
> The port->console flag is always false, as uart_console() is called
> before the serial console has been registered.
> 
> Hence for a serial port used as the console, uart_tty_port_shutdown()
> will still be called when userspace closes the port, powering it down.
> This may lead to a system lock up when the serial console driver writes
> to the serial port's registers.
> 
> To fix this, move the setting of port->console after the call to
> uart_configure_port(), which registers the serial console.
> 
> Fixes: 761ed4a94582ab29 ("tty: serial_core: convert uart_close to use tty_port_close")
> Reported-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
> Acked-by: Rob Herring <robh@kernel.org>

Fixes some junk characters seen on boot console on TI platforms.

Tested-by: Mugunthan V N <mugunthanvnm@ti.com>

Regards
Mugunthan V N

> ---
> v2:
>   - Add Acked-by,
>   - Reworded one-line summary (incl. magic word "fix").
> 
> Can easily be reproduced on Renesas boards:
>   1. With systemd: hangs during boot,
>   2. Without systemd: "telinit n" to switch to a runlevel that doesn't
>      run a getty on ttySC0, and trigger kernel console output => hang.
> ---
>  drivers/tty/serial/serial_core.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
> index 6e4f63627479db8d..ce8899c13af3d97f 100644
> --- a/drivers/tty/serial/serial_core.c
> +++ b/drivers/tty/serial/serial_core.c
> @@ -2746,8 +2746,6 @@ int uart_add_one_port(struct uart_driver *drv, struct uart_port *uport)
>  	uport->cons = drv->cons;
>  	uport->minor = drv->tty_driver->minor_start + uport->line;
>  
> -	port->console = uart_console(uport);
> -
>  	/*
>  	 * If this port is a console, then the spinlock is already
>  	 * initialised.
> @@ -2761,6 +2759,8 @@ int uart_add_one_port(struct uart_driver *drv, struct uart_port *uport)
>  
>  	uart_configure_port(drv, state, uport);
>  
> +	port->console = uart_console(uport);
> +
>  	num_groups = 2;
>  	if (uport->attr_group)
>  		num_groups++;
> 

[toc] | [prev] | [next] | [standalone]


#1503961 — Re: [PATCH v2] tty: serial_core: Fix serial console crash on port shutdown

From"Niklas Söderlund" <niklas.soderlund@ragnatech.se>
Date2016-10-19 17:50 +0200
SubjectRe: [PATCH v2] tty: serial_core: Fix serial console crash on port shutdown
Message-ID<su1hU-3b7-29@gated-at.bofh.it>
In reply to#1503214
Hi Geert,

On 2016-10-18 18:35:40 +0200, Geert Uytterhoeven wrote:
> The port->console flag is always false, as uart_console() is called
> before the serial console has been registered.
> 
> Hence for a serial port used as the console, uart_tty_port_shutdown()
> will still be called when userspace closes the port, powering it down.
> This may lead to a system lock up when the serial console driver writes
> to the serial port's registers.
> 
> To fix this, move the setting of port->console after the call to
> uart_configure_port(), which registers the serial console.
> 
> Fixes: 761ed4a94582ab29 ("tty: serial_core: convert uart_close to use tty_port_close")
> Reported-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
> Acked-by: Rob Herring <robh@kernel.org>

It fixes the issue I was seeing with systemd as a init system.

Tested-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>

> ---
> v2:
>   - Add Acked-by,
>   - Reworded one-line summary (incl. magic word "fix").
> 
> Can easily be reproduced on Renesas boards:
>   1. With systemd: hangs during boot,
>   2. Without systemd: "telinit n" to switch to a runlevel that doesn't
>      run a getty on ttySC0, and trigger kernel console output => hang.
> ---
>  drivers/tty/serial/serial_core.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
> index 6e4f63627479db8d..ce8899c13af3d97f 100644
> --- a/drivers/tty/serial/serial_core.c
> +++ b/drivers/tty/serial/serial_core.c
> @@ -2746,8 +2746,6 @@ int uart_add_one_port(struct uart_driver *drv, struct uart_port *uport)
>  	uport->cons = drv->cons;
>  	uport->minor = drv->tty_driver->minor_start + uport->line;
>  
> -	port->console = uart_console(uport);
> -
>  	/*
>  	 * If this port is a console, then the spinlock is already
>  	 * initialised.
> @@ -2761,6 +2759,8 @@ int uart_add_one_port(struct uart_driver *drv, struct uart_port *uport)
>  
>  	uart_configure_port(drv, state, uport);
>  
> +	port->console = uart_console(uport);
> +
>  	num_groups = 2;
>  	if (uport->attr_group)
>  		num_groups++;
> -- 
> 1.9.1
> 

-- 
Regards,
Niklas Söderlund

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web