aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/include/linux/tty.h
diff options
context:
space:
mode:
authorDmitry Safonov <dima@arista.com>2018-11-01 00:24:48 +0000
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2018-12-05 12:16:33 +0100
commitc96cf923a98d1b094df9f0cf97a83e118817e31b (patch)
tree600f4d868ef87ff58a642bb7e6d4825894d9c657 /include/linux/tty.h
parenttty: Hold tty_ldisc_lock() during tty_reopen() (diff)
downloadwireguard-linux-c96cf923a98d1b094df9f0cf97a83e118817e31b.tar.xz
wireguard-linux-c96cf923a98d1b094df9f0cf97a83e118817e31b.zip
tty: Don't block on IO when ldisc change is pending
There might be situations where tty_ldisc_lock() has blocked, but there is already IO on tty and it prevents line discipline changes. It might theoretically turn into dead-lock. Basically, provide more priority to pending tty_ldisc_lock() than to servicing reads/writes over tty. User-visible issue was reported by Mikulas where on pa-risc with Debian 5 reboot took either 80 seconds, 3 minutes or 3:25 after proper locking in tty_reopen(). Cc: Jiri Slaby <jslaby@suse.com> Reported-by: Mikulas Patocka <mpatocka@redhat.com> Signed-off-by: Dmitry Safonov <dima@arista.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'include/linux/tty.h')
-rw-r--r--include/linux/tty.h7
1 files changed, 7 insertions, 0 deletions
diff --git a/include/linux/tty.h b/include/linux/tty.h
index 414db2bce715..80ae5528ef8e 100644
--- a/include/linux/tty.h
+++ b/include/linux/tty.h
@@ -366,6 +366,7 @@ struct tty_file_private {
#define TTY_NO_WRITE_SPLIT 17 /* Preserve write boundaries to driver */
#define TTY_HUPPED 18 /* Post driver->hangup() */
#define TTY_HUPPING 19 /* Hangup in progress */
+#define TTY_LDISC_CHANGING 20 /* Change pending - non-block IO */
#define TTY_LDISC_HALTED 22 /* Line discipline is halted */
/* Values for tty->flow_change */
@@ -383,6 +384,12 @@ static inline void tty_set_flow_change(struct tty_struct *tty, int val)
smp_mb();
}
+static inline bool tty_io_nonblock(struct tty_struct *tty, struct file *file)
+{
+ return file->f_flags & O_NONBLOCK ||
+ test_bit(TTY_LDISC_CHANGING, &tty->flags);
+}
+
static inline bool tty_io_error(struct tty_struct *tty)
{
return test_bit(TTY_IO_ERROR, &tty->flags);