linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] tty: serial_core: Fix the incorrect configuration of baud rate and data length at the console serial port resume
@ 2019-05-09  5:42 Lanqing Liu
  2019-05-14  7:34 ` Johan Hovold
  0 siblings, 1 reply; 3+ messages in thread
From: Lanqing Liu @ 2019-05-09  5:42 UTC (permalink / raw)
  To: baolin.wang, baolin.wang, gregkh, jslaby
  Cc: lanqing.liu, liuhhome, robh, linux-serial, linux-kernel,
	chunyan.zhang, orson.zhai, zhang.lyra

When userspace opens a serial port for console, uart_port_startup()
is called. This function assigns the uport->cons->cflag value to
TTY->termios.c_cflag, then it is cleared to 0. When the user space
closes this serial port, the TTY structure will be released, and at
this time uport->cons->cflag has also been cleared.

On the Spreadtrum platform, in some special scenarios, like charging mode,
userspace needs to close the console, which means the uport->cons->cflag
has also been cleared. But printing logs is still needed in the kernel. So
when system enters suspend and resume, the console needs to be configure
the baud rate and data length of the serial port according to its own cflag
when resuming the console port. At this time, the cflag is 0, which will
cause serial port to produce configuration errors that do not meet user
expectations.

To fix this, assigning the TTY->termios.c_cflag value to uport->cons->cflag
before the userspace closes this console serial port. It will ensure that
the correct cflag value can be gotten when the console serial port was
resumed.

Signed-off-by: Lanqing Liu <liuhhome@gmail.com>
---
 drivers/tty/serial/serial_core.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
index 351843f..f233cf8 100644
--- a/drivers/tty/serial/serial_core.c
+++ b/drivers/tty/serial/serial_core.c
@@ -1539,6 +1539,7 @@ static void uart_set_termios(struct tty_struct *tty,
 static void uart_close(struct tty_struct *tty, struct file *filp)
 {
 	struct uart_state *state = tty->driver_data;
+	struct uart_port *uport;
 
 	if (!state) {
 		struct uart_driver *drv = tty->driver->driver_state;
@@ -1553,6 +1554,9 @@ static void uart_close(struct tty_struct *tty, struct file *filp)
 	}
 
 	pr_debug("uart_close(%d) called\n", tty->index);
+	uport = uart_port_check(state);
+	if (uport && uart_console(uport))
+		uport->cons->cflag = tty->termios.c_cflag;
 
 	tty_port_close(tty->port, tty, filp);
 }
-- 
1.9.1


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

* Re: [PATCH] tty: serial_core: Fix the incorrect configuration of baud rate and data length at the console serial port resume
  2019-05-09  5:42 [PATCH] tty: serial_core: Fix the incorrect configuration of baud rate and data length at the console serial port resume Lanqing Liu
@ 2019-05-14  7:34 ` Johan Hovold
  2019-05-15  9:15   ` hhome liu
  0 siblings, 1 reply; 3+ messages in thread
From: Johan Hovold @ 2019-05-14  7:34 UTC (permalink / raw)
  To: Lanqing Liu, Rob Herring, Greg Kroah-Hartman
  Cc: baolin.wang, baolin.wang, jslaby, lanqing.liu, linux-serial,
	linux-kernel, chunyan.zhang, orson.zhai, zhang.lyra

On Thu, May 09, 2019 at 01:42:39PM +0800, Lanqing Liu wrote:
> When userspace opens a serial port for console, uart_port_startup()
> is called. This function assigns the uport->cons->cflag value to
> TTY->termios.c_cflag, then it is cleared to 0. When the user space
> closes this serial port, the TTY structure will be released, and at
> this time uport->cons->cflag has also been cleared.
> 
> On the Spreadtrum platform, in some special scenarios, like charging mode,
> userspace needs to close the console, which means the uport->cons->cflag
> has also been cleared. But printing logs is still needed in the kernel. So
> when system enters suspend and resume, the console needs to be configure
> the baud rate and data length of the serial port according to its own cflag
> when resuming the console port. At this time, the cflag is 0, which will
> cause serial port to produce configuration errors that do not meet user
> expectations.

This is actually yet another regression due to 761ed4a94582 ("tty:
serial_core: convert uart_close to use tty_port_close") which
incidentally removed the call to uart_shutdown() where the cflag was
being saved precisely to avoid the problem you're describing:

	ae84db9661ca ("serial: core: Preserve termios c_cflag for console resume")

Judging from a quick look it seems the xmit buf, which is released in
that function may now be leaking too.

> To fix this, assigning the TTY->termios.c_cflag value to uport->cons->cflag
> before the userspace closes this console serial port. It will ensure that
> the correct cflag value can be gotten when the console serial port was
> resumed.

Not sure this is the right fix, but I don't have time to look at this
right now.

Johan

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

* Re: [PATCH] tty: serial_core: Fix the incorrect configuration of baud rate and data length at the console serial port resume
  2019-05-14  7:34 ` Johan Hovold
@ 2019-05-15  9:15   ` hhome liu
  0 siblings, 0 replies; 3+ messages in thread
From: hhome liu @ 2019-05-15  9:15 UTC (permalink / raw)
  To: Johan Hovold
  Cc: Rob Herring, Greg Kroah-Hartman, baolin.wang, Baolin Wang,
	jslaby, 刘岚清 (Lanqing Liu),
	linux-serial, linux-kernel, chunyan.zhang, orson.zhai,
	zhang.lyra

Johan Hovold <johan@kernel.org> 于2019年5月14日周二 下午3:35写道:

>
> On Thu, May 09, 2019 at 01:42:39PM +0800, Lanqing Liu wrote:
> > When userspace opens a serial port for console, uart_port_startup()
> > is called. This function assigns the uport->cons->cflag value to
> > TTY->termios.c_cflag, then it is cleared to 0. When the user space
> > closes this serial port, the TTY structure will be released, and at
> > this time uport->cons->cflag has also been cleared.
> >
> > On the Spreadtrum platform, in some special scenarios, like charging mode,
> > userspace needs to close the console, which means the uport->cons->cflag
> > has also been cleared. But printing logs is still needed in the kernel. So
> > when system enters suspend and resume, the console needs to be configure
> > the baud rate and data length of the serial port according to its own cflag
> > when resuming the console port. At this time, the cflag is 0, which will
> > cause serial port to produce configuration errors that do not meet user
> > expectations.
>
> This is actually yet another regression due to 761ed4a94582 ("tty:
> serial_core: convert uart_close to use tty_port_close") which
> incidentally removed the call to uart_shutdown() where the cflag was
> being saved precisely to avoid the problem you're describing:
>
>         ae84db9661ca ("serial: core: Preserve termios c_cflag for console resume")

Yes, agree with you.

>
> Judging from a quick look it seems the xmit buf, which is released in
> that function may now be leaking too.

We haven't found this issue before, but we can try to reproduce it on
our platform.

>
> > To fix this, assigning the TTY->termios.c_cflag value to uport->cons->cflag
> > before the userspace closes this console serial port. It will ensure that
> > the correct cflag value can be gotten when the console serial port was
> > resumed.
>
> Not sure this is the right fix, but I don't have time to look at this
> right now.

OK. Thanks for your comments.

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

end of thread, other threads:[~2019-05-15  9:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-09  5:42 [PATCH] tty: serial_core: Fix the incorrect configuration of baud rate and data length at the console serial port resume Lanqing Liu
2019-05-14  7:34 ` Johan Hovold
2019-05-15  9:15   ` hhome liu

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).