Skip to contentSkip to conversation

serial: 8250: Clear CON_PRINTBUFFER on port re-registration

PATCH Superseded Fushuai Wang 2 participants 5 messages Apr 28 – May 22 TTY layer and serial drivers

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 serial: 8250: Clear CON_PRINTBUFFER on port re-registration

From: Fushuai Wang <[email protected]>

When two PnP devices map to the same physical port, the serial8250 driver removes and re-registers the console structure for the same port.

During re-registration, the console structure still has CON_PRINTBUFFER set from the initial registration, which causes console_init_seq() to set console->seq to syslog_seq. This results in re-printing the entire system log buffer, which may lead to RCU stall on slow serial consoles.

Clear CON_PRINTBUFFER when re-registering a port to prevent duplicate log printing.

Fixes 835d844d1a28 ("8250_pnp: do pnp probe before legacy probe")

---
V1->V2: Add Fixes tag
previous discussion: https://lore.kernel.org/all/[email protected]/T/#u

Please ignore previous email if you received it before. There is something wrong with my email client.

 drivers/tty/serial/8250/8250_core.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/tty/serial/8250/8250_core.c +8 -1
index a428e88938eb..01b14392d9f7 100644
@@ -694,6 +694,7 @@ int serial8250_register_8250_port(const struct uart_8250_port *up)
 {
 	struct uart_8250_port *uart;
 	int ret;
+	bool was_removed = false;
 
 	if (up->port.uartclk == 0)
 		return -EINVAL;
@@ -716,8 +717,10 @@ int serial8250_register_8250_port(const struct uart_8250_port *up)
 	if (uart->port.type == PORT_8250_CIR)
 		return -ENODEV;
 
-	if (uart->port.dev)
+	if (uart->port.dev) {
 		uart_remove_one_port(&serial8250_reg, &uart->port);
+		was_removed = true;
+	}
 
 	uart->port.ctrl_id	= up->port.ctrl_id;
 	uart->port.port_id	= up->port.port_id;
@@ -819,6 +822,10 @@ int serial8250_register_8250_port(const struct uart_8250_port *up)
 					&uart->capabilities);
 
 		serial8250_apply_quirks(uart);
+
+		if (was_removed && uart_console(&uart->port))
+			uart->port.cons->flags &= ~CON_PRINTBUFFER;
+
 		ret = uart_add_one_port(&serial8250_reg,
 					&uart->port);
 		if (ret)
Signature · 1 line
2.36.1
maintainer
#1 lore raw
Quoted 49 lines · Fushuai Wang

From: Fushuai Wang <[email protected]>

When two PnP devices map to the same physical port, the serial8250 driver removes and re-registers the console structure for the same port.

During re-registration, the console structure still has CON_PRINTBUFFER set from the initial registration, which causes console_init_seq() to set console->seq to syslog_seq. This results in re-printing the entire system log buffer, which may lead to RCU stall on slow serial consoles.

Clear CON_PRINTBUFFER when re-registering a port to prevent duplicate log printing.

Fixes 835d844d1a28 ("8250_pnp: do pnp probe before legacy probe")

---
V1->V2: Add Fixes tag
previous discussion: https://lore.kernel.org/all/[email protected]/T/#u

Please ignore previous email if you received it before. There is something wrong with my email client.

 drivers/tty/serial/8250/8250_core.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/tty/serial/8250/8250_core.c +4 -1
index a428e88938eb..01b14392d9f7 100644
@@ -694,6 +694,7 @@ int serial8250_register_8250_port(const struct uart_8250_port *up)
 {
 	struct uart_8250_port *uart;
 	int ret;
+	bool was_removed = false;
 
 	if (up->port.uartclk == 0)
 		return -EINVAL;
@@ -716,8 +717,10 @@ int serial8250_register_8250_port(const struct uart_8250_port *up)
 	if (uart->port.type == PORT_8250_CIR)
 		return -ENODEV;
 
-	if (uart->port.dev)
+	if (uart->port.dev) {
 		uart_remove_one_port(&serial8250_reg, &uart->port);
+		was_removed = true;
+	}
 
 	uart->port.ctrl_id	= up->port.ctrl_id;
 	uart->port.port_id	= up->port.port_id;

drivers/tty/serial/8250/8250_core.c int serial8250_register_8250_port(const struct uart_8250_port *up) · line 827

Quoted 6 lines
drivers/tty/serial/8250/8250_core.c +3 -0
@@ -819,6 +822,10 @@ int serial8250_register_8250_port(const struct uart_8250_port *up)
 					&uart->capabilities);
 
 		serial8250_apply_quirks(uart);
+
+		if (was_removed && uart_console(&uart->port))
+			uart->port.cons->flags &= ~CON_PRINTBUFFER;

Why not set the flag up above when you remove the port? Why down here?

thanks,

greg k-h

#2 lore raw
Quoted 58 lines
Quoted 49 lines

From: Fushuai Wang <[email protected]>

When two PnP devices map to the same physical port, the serial8250 driver removes and re-registers the console structure for the same port.

During re-registration, the console structure still has CON_PRINTBUFFER set from the initial registration, which causes console_init_seq() to set console->seq to syslog_seq. This results in re-printing the entire system log buffer, which may lead to RCU stall on slow serial consoles.

Clear CON_PRINTBUFFER when re-registering a port to prevent duplicate log printing.

Fixes 835d844d1a28 ("8250_pnp: do pnp probe before legacy probe")

---
V1->V2: Add Fixes tag
previous discussion: https://lore.kernel.org/all/[email protected]/T/#u

Please ignore previous email if you received it before. There is something wrong with my email client.

 drivers/tty/serial/8250/8250_core.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/tty/serial/8250/8250_core.c +4 -1
index a428e88938eb..01b14392d9f7 100644
@@ -694,6 +694,7 @@ int serial8250_register_8250_port(const struct uart_8250_port *up)
 {
 	struct uart_8250_port *uart;
 	int ret;
+	bool was_removed = false;
 
 	if (up->port.uartclk == 0)
 		return -EINVAL;
@@ -716,8 +717,10 @@ int serial8250_register_8250_port(const struct uart_8250_port *up)
 	if (uart->port.type == PORT_8250_CIR)
 		return -ENODEV;
 
-	if (uart->port.dev)
+	if (uart->port.dev) {
 		uart_remove_one_port(&serial8250_reg, &uart->port);
+		was_removed = true;
+	}
 
 	uart->port.ctrl_id	= up->port.ctrl_id;
 	uart->port.port_id	= up->port.port_id;

drivers/tty/serial/8250/8250_core.c int serial8250_register_8250_port(const struct uart_8250_port *up) · line 827

Quoted 6 lines
drivers/tty/serial/8250/8250_core.c +3 -0
@@ -819,6 +822,10 @@ int serial8250_register_8250_port(const struct uart_8250_port *up)
 					&uart->capabilities);
 
 		serial8250_apply_quirks(uart);
+
+		if (was_removed && uart_console(&uart->port))
+			uart->port.cons->flags &= ~CON_PRINTBUFFER;

Why not set the flag up above when you remove the port? Why down here?

Quoted 3 lines

thanks,

greg k-h

Hi, Greg

I just felt it's cleaner to clear it only when re-registration happens. Do you think there is any problem with doing it right after the removal?

Signature · 2 lines
Regards,
WANG
maintainer
#3 lore raw
Quoted 58 lines · Fushuai Wang
Quoted 58 lines
Quoted 49 lines

From: Fushuai Wang <[email protected]>

When two PnP devices map to the same physical port, the serial8250 driver removes and re-registers the console structure for the same port.

During re-registration, the console structure still has CON_PRINTBUFFER set from the initial registration, which causes console_init_seq() to set console->seq to syslog_seq. This results in re-printing the entire system log buffer, which may lead to RCU stall on slow serial consoles.

Clear CON_PRINTBUFFER when re-registering a port to prevent duplicate log printing.

Fixes 835d844d1a28 ("8250_pnp: do pnp probe before legacy probe")

---
V1->V2: Add Fixes tag
previous discussion: https://lore.kernel.org/all/[email protected]/T/#u

Please ignore previous email if you received it before. There is something wrong with my email client.

 drivers/tty/serial/8250/8250_core.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/tty/serial/8250/8250_core.c +4 -1
index a428e88938eb..01b14392d9f7 100644
@@ -694,6 +694,7 @@ int serial8250_register_8250_port(const struct uart_8250_port *up)
 {
 	struct uart_8250_port *uart;
 	int ret;
+	bool was_removed = false;
 
 	if (up->port.uartclk == 0)
 		return -EINVAL;
@@ -716,8 +717,10 @@ int serial8250_register_8250_port(const struct uart_8250_port *up)
 	if (uart->port.type == PORT_8250_CIR)
 		return -ENODEV;
 
-	if (uart->port.dev)
+	if (uart->port.dev) {
 		uart_remove_one_port(&serial8250_reg, &uart->port);
+		was_removed = true;
+	}
 
 	uart->port.ctrl_id	= up->port.ctrl_id;
 	uart->port.port_id	= up->port.port_id;

drivers/tty/serial/8250/8250_core.c int serial8250_register_8250_port(const struct uart_8250_port *up) · line 827

Quoted 6 lines
drivers/tty/serial/8250/8250_core.c +3 -0
@@ -819,6 +822,10 @@ int serial8250_register_8250_port(const struct uart_8250_port *up)
 					&uart->capabilities);
 
 		serial8250_apply_quirks(uart);
+
+		if (was_removed && uart_console(&uart->port))
+			uart->port.cons->flags &= ~CON_PRINTBUFFER;

Why not set the flag up above when you remove the port? Why down here?

Quoted 8 lines
Quoted 3 lines

thanks,

greg k-h

Hi, Greg

I just felt it's cleaner to clear it only when re-registration happens. Do you think there is any problem with doing it right after the removal?

If you do that, no flag is needed.

#4 lore raw
Quoted 34 lines
Quoted 34 lines
Quoted 34 lines
Quoted 23 lines
drivers/tty/serial/8250/8250_core.c +4 -1
@@ -694,6 +694,7 @@ int serial8250_register_8250_port(const struct uart_8250_port *up)
 {
 	struct uart_8250_port *uart;
 	int ret;
+	bool was_removed = false;
 
 >  	if (up->port.uartclk == 0)
 		return -EINVAL;
@@ -716,8 +717,10 @@ int serial8250_register_8250_port(const struct uart_8250_port *up)
 	if (uart->port.type == PORT_8250_CIR)
 		return -ENODEV;
 
-	if (uart->port.dev)
+	if (uart->port.dev) {
 		uart_remove_one_port(&serial8250_reg, &uart->port);
+		was_removed = true;
+	}
 
 	uart->port.ctrl_id	= up->port.ctrl_id;
 	uart->port.port_id	= up->port.port_id;

drivers/tty/serial/8250/8250_core.c int serial8250_register_8250_port(const struct uart_8250_port *up) · line 827

Quoted 6 lines
drivers/tty/serial/8250/8250_core.c +3 -0
@@ -819,6 +822,10 @@ int serial8250_register_8250_port(const struct uart_8250_port *up)
 					&uart->capabilities);
 
 		serial8250_apply_quirks(uart);
+
+		if (was_removed && uart_console(&uart->port))
+			uart->port.cons->flags &= ~CON_PRINTBUFFER;

Why not set the flag up above when you remove the port? Why down here?

thanks,

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

greg k-h

Hi, Greg

I just felt it's cleaner to clear it only when re-registration happens. Do you think there is any problem with doing it right after the removal?

If you do that, no flag is needed.

OK, I will send a v3 shortly.

Signature · 2 lines
Regards,
WANG