patch "tty: Don't hold ldisc lock in tty_reopen() if ldisc present" added to tty-linus
Subsystems (2)
This is a note to let you know that I've just added the patch titled
tty: Don't hold ldisc lock in tty_reopen() if ldisc present
to my tty git tree which can be found at
git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty.git
in the tty-linus branch.
The patch will show up in the next release of the linux-next tree (usually sometime within the next 24 hours during the week.)
The patch will hopefully also be merged in Linus's tree for the next -rc kernel release.
If you have any questions about this process, please let me know.
From d3736d82e8169768218ee0ef68718875918091a0 Mon Sep 17 00:00:00 2001
From: Dmitry Safonov <[email protected]>
Date: Wed, 9 Jan 2019 01:17:40 +0000
Subject: tty: Don't hold ldisc lock in tty_reopen() if ldisc present
Try to get reference for ldisc during tty_reopen().
If ldisc present, we don't need to do tty_ldisc_reinit() and lock the write side for line discipline semaphore.
Effectively, it optimizes fast-path for tty_reopen(), but more importantly it won't interrupt ongoing IO on the tty as no ldisc change is needed.
Fixes user-visible issue when tty_reopen() interrupted login process for user with a long password, observed and reported by Lukas.
--- drivers/tty/tty_io.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-)
drivers/tty/tty_io.c +13 -7
@@ -1256,7 +1256,8 @@ static void tty_driver_remove_tty(struct tty_driver *driver, struct tty_struct *static int tty_reopen (struct tty_struct *tty) {struct tty_driver *driver = tty->driver; -int retval; +struct tty_ldisc *ld; +int retval =0 ;if (driver->type ==TTY_DRIVER_TYPE_PTY && driver->subtype ==PTY_TYPE_MASTER )
@@ -1268,13 +1269,18 @@ static int tty_reopen(struct tty_struct *tty)if (test_bit (TTY_EXCLUSIVE , &tty->flags) && !capable (CAP_SYS_ADMIN ))return -EBUSY ; - retval =tty_ldisc_lock (tty,5 *HZ ); -if (retval) -return retval; + ld =tty_ldisc_ref_wait (tty); +if (ld) { +tty_ldisc_deref (ld); + }else { + retval =tty_ldisc_lock (tty,5 *HZ ); +if (retval) +return retval; -if (!tty->ldisc) - retval =tty_ldisc_reinit (tty, tty->termios.c_line); -tty_ldisc_unlock (tty); +if (!tty->ldisc) + retval =tty_ldisc_reinit (tty, tty->termios.c_line); +tty_ldisc_unlock (tty); + }if (retval ==0 ) tty->count++;
Signature · 1 line
2.20.1