• Peter Hurley's avatar
    tty: Fix pty master read() after slave closes · f8747d4a
    Peter Hurley authored
    Commit f95499c3,
      n_tty: Don't wait for buffer work in read() loop
    creates a race window which can cause a pty master read()
    to miss the last pty slave write(s) and return -EIO instead,
    thus signalling the pty slave is closed. This can happen when
    the pty slave is written and immediately closed but before the
    tty buffer i/o loop receives the new input; the pty master
    read() is scheduled, sees its read buffer is empty and the
    pty slave has been closed, and exits.
    
    Because tty_flush_to_ldisc() has significant performance impact
    for parallel i/o, rather than revert the commit, special case this
    condition (ie., when the read buffer is empty and the 'other' pty
    has been closed) and, only then, wait for buffer work to complete
    before re-testing if the read buffer is still empty.
    
    As before, subsequent pty master reads return any available data
    until no more data is available, and then returns -EIO to
    indicate the pty slave has closed.
    Reported-by: default avatarMikael Pettersson <mikpelinux@gmail.com>
    Signed-off-by: default avatarPeter Hurley <peter@hurleysoftware.com>
    Tested-by: default avatarMikael Pettersson <mikpelinux@gmail.com>
    Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
    f8747d4a
n_tty.c 60.8 KB