* [PATCH v2] tty: discard flip-buffer input for TCSAFLUSH
@ 2026-10-27 8:22 Hungyu Lin
2026-10-27 19:17 ` Hungyu Lin
0 siblings, 1 reply; 2+ messages in thread
From: Hungyu Lin @ 2026-10-27 8:22 UTC (permalink / raw)
To: gregkh, jirislaby; +Cc: linux-serial, linux-kernel, sashiko-bot, dennylin0707
set_termios() handles TERMIOS_FLUSH by clearing only the line discipline's
input buffer. Data already committed to the tty flip buffers can be
delivered after that flush, leaving old input readable after a successful
tcsetattr(TCSAFLUSH).
This can be reproduced with a noncanonical PTY: complete an 8192-byte
master write, wait until the slave reports 4095 unread bytes, and apply
TCSAFLUSH. The remaining 4097 bytes are still readable afterwards. Small
amounts of pending input can also survive if they have not reached the
line discipline yet.
Use tty_buffer_flush() with the referenced line discipline to discard both
receive queues under the existing buffer lock. If the line discipline has
a flush_buffer callback, also unthrottle the tty after releasing that lock,
as TCIFLUSH does. Otherwise a paused input source or sleeping PTY writer
can remain stopped after the queues are emptied.
Signed-off-by: Hungyu Lin <dennylin0707@gmail.com>
---
Changes in v2:
- Unthrottle after flushing when the line discipline has a flush_buffer
callback, matching TCIFLUSH and addressing Sashiko's review.
- Add local blocked-writer and serial-type N_TTY flow-control validation;
rerun the original functional and sudo/PAM tests. Test harnesses are
kept outside this patch.
drivers/tty/tty_ioctl.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/drivers/tty/tty_ioctl.c b/drivers/tty/tty_ioctl.c
index 90c70d8d14e3..be764f04bf3a 100644
--- a/drivers/tty/tty_ioctl.c
+++ b/drivers/tty/tty_ioctl.c
@@ -496,8 +496,11 @@ static int set_termios(struct tty_struct *tty, void __user *arg, int opt)
ld = tty_ldisc_ref(tty);
if (ld != NULL) {
- if ((opt & TERMIOS_FLUSH) && ld->ops->flush_buffer)
- ld->ops->flush_buffer(tty);
+ if (opt & TERMIOS_FLUSH) {
+ tty_buffer_flush(tty, ld);
+ if (ld->ops->flush_buffer)
+ tty_unthrottle(tty);
+ }
tty_ldisc_deref(ld);
}
--
2.43.0
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH v2] tty: discard flip-buffer input for TCSAFLUSH
2026-10-27 8:22 [PATCH v2] tty: discard flip-buffer input for TCSAFLUSH Hungyu Lin
@ 2026-10-27 19:17 ` Hungyu Lin
0 siblings, 0 replies; 2+ messages in thread
From: Hungyu Lin @ 2026-10-27 19:17 UTC (permalink / raw)
To: gregkh, jirislaby; +Cc: linux-serial, linux-kernel, sashiko-bot
> I'm still investigating and don't have a replacement ready.
Fixing this properly involves more changes than I expected, so I won't
be pursuing it further. Please disregard both v1 and v2.
Thanks,
Hungyu
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-10-27 19:18 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-27 8:22 [PATCH v2] tty: discard flip-buffer input for TCSAFLUSH Hungyu Lin
2026-10-27 19:17 ` Hungyu Lin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®