All of lore.kernel.org
 help / color / mirror / Atom feed
From: Baruch Siach <baruch@tkos.co.il>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Jiri Slaby <jirislaby@kernel.org>
Cc: linux-serial@vger.kernel.org, Baruch Siach <baruch@tkos.co.il>
Subject: [RFC PATCH] tty: flush buffer on signal interrupted tty close
Date: Mon,  1 Nov 2021 17:48:08 +0200	[thread overview]
Message-ID: <319321886d97c456203d5c6a576a5480d07c3478.1635781688.git.baruch@tkos.co.il> (raw)

When a signal interrupts tty_wait_until_sent() on a UART device, there
might be data left on the xmit buffer that the UART will never transmit.
This causes set_termios() to wait forever in tty_wait_until_sent().

The hang reproduces easily on my system that is equipped with DesignWare
8250. Run

  while true; do echo -ne 0123456789abcdef01 > /dev/ttyS1; done

Hit Ctrl-C to interrupt the loop. When data is left in the struct
uart_state xmit buffer, the following command hangs:

  stty -F /dev/ttyS1 raw -echo

Call tty_driver_flush_buffer() on signal interrupted wait, to discard
data from the xmit buffer.

Signed-off-by: Baruch Siach <baruch@tkos.co.il>
---
 drivers/tty/tty_ioctl.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/tty/tty_ioctl.c b/drivers/tty/tty_ioctl.c
index 507a25d692bb..0bf6fad7ecb3 100644
--- a/drivers/tty/tty_ioctl.c
+++ b/drivers/tty/tty_ioctl.c
@@ -203,6 +203,8 @@ void tty_wait_until_sent(struct tty_struct *tty, long timeout)
 
 	timeout = wait_event_interruptible_timeout(tty->write_wait,
 			!tty_chars_in_buffer(tty), timeout);
+	if (timeout == -ERESTARTSYS && tty->closing)
+		tty_driver_flush_buffer(tty);
 	if (timeout <= 0)
 		return;
 
-- 
2.33.0


             reply	other threads:[~2021-11-01 15:48 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-01 15:48 Baruch Siach [this message]
2021-11-08  8:58 ` [RFC PATCH] tty: flush buffer on signal interrupted tty close Johan Hovold
2021-11-08  9:00   ` Johan Hovold

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=319321886d97c456203d5c6a576a5480d07c3478.1635781688.git.baruch@tkos.co.il \
    --to=baruch@tkos.co.il \
    --cc=gregkh@linuxfoundation.org \
    --cc=jirislaby@kernel.org \
    --cc=linux-serial@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.