• Peter Hurley's avatar
    n_tty: Fix signal handling flushes · d2b6f447
    Peter Hurley authored
    BRKINT and ISIG requires input and output flush when a signal char
    is received. However, the order of operations is significant since
    parallel i/o may be ongoing.
    
    Merge the signal handling for BRKINT with ISIG handling.
    
    Process the signal first. This ensures any ongoing i/o is aborted;
    without this, a waiting writer may continue writing after the flush
    occurs and after the signal char has been echoed.
    
    Write lock the termios_rwsem, which excludes parallel writers from
    pushing new i/o until after the output buffers are flushed; claiming
    the write lock is necessary anyway to exclude parallel readers while
    the read buffer is flushed.
    
    Subclass the termios_rwsem for ptys since the slave pty performing
    the flush may appear to reorder the termios_rwsem->tty buffer lock
    lock order; adding annotation clarifies that
      slave tty_buffer lock-> slave termios_rwsem -> master tty_buffer lock
    is a valid lock order.
    
    Flush the echo buffer. In this context, the echo buffer is 'output'.
    Otherwise, the output will appear discontinuous because the output buffer
    was cleared which contains older output than the echo buffer.
    
    Open-code the read buffer flush since the input worker does not need
    kicking (this is the input worker).
    Signed-off-by: default avatarPeter Hurley <peter@hurleysoftware.com>
    Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
    d2b6f447
n_tty.c 63.2 KB