Skip to content

tty locking changes

Peter Hurley linux-serial lkml 2 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest26 patches 6 repliesIn review
  2. v127 patches 5 repliesSuperseded

Changes in v2 from the cover letter

* New patch 19 ('tty: Preset lock subclass for nested tty locks') makes passing the tty_lock subclass at lock time unnecessary; regular ttys and master ptys use subclass 0 and slave ptys use subclass 1. The expected lock order is first subclass 0 then subclass 1. Lockdep will warn if the reverse order is used.

* That makes introducing tty_hangup_slave and refactoring tty_hangup et al unnecessary, so the previous patch 20 ('tty: Refactor __tty_hangup to enable lockdep annotation') was removed, along with 'tty: Document hangup call tree'.

* Added Alan's Reviewed-by tag to the patches Alan already reviewed, which just leaves the following patches needing re-review:
19/26 tty: Preset lock subclass for nested tty locks 21/26 pty: Don't drop pty master tty lock to hangup slave

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/26tty: Don't hold tty_lock for ldisc releasedrivers/tty/tty_ldisc.c+2 -40 replies
2/26tty: Invert tty_lock/ldisc_sem lock orderdrivers/tty/tty_ldisc.c+3 -40 replies
3/26tty: Remove TTY_HUPPINGdrivers/tty/tty_io.c drivers/tty/tty_ldisc.c include/linux/tty.h+2 -140 replies
4/26tty: Clarify re-open behavior of master ptysdrivers/tty/tty_io.c+4 -110 replies
5/26tty: Check tty->count instead of TTY_CLOSING in tty_reopen()drivers/tty/tty_io.c+1 -10 replies
6/26pty: Always return -EIO if slave BSD pty opened firstdrivers/tty/pty.c+5 -20 replies
7/26tty: Re-open /dev/tty without tty_mutexdrivers/tty/tty_io.c+27 -260 replies
8/26tty: Drop tty_mutex before tty reopendrivers/tty/tty_io.c+17 -80 replies
9/26tty: Remove TTY_CLOSINGdrivers/tty/tty_io.c include/linux/tty.h+2 -130 replies
10/26tty: Don't take tty_mutex for tty count changesdrivers/tty/tty_io.c+0 -64 replies
11/26tty: Don't release tty locks for wait queue sanity checkdrivers/tty/tty_io.c+2 -61 reply
12/26tty: Document check_tty_count() requires tty_lock helddrivers/tty/tty_io.c+1 -00 replies
13/26tty: Simplify pty pair teardown logicdrivers/tty/tty_io.c+10 -190 replies
14/26tty: Fold pty pair handling into tty_flush_works()drivers/tty/tty_io.c+7 -50 replies
15/26tty: Simplify tty_ldisc_release() interfacedrivers/tty/tty_io.c drivers/tty/tty_ldisc.c include/linux/tty.h+9 -100 replies
16/26tty: Simplify tty_release_checks() interfacedrivers/tty/tty_io.c+4 -30 replies
17/26tty: Simplify tty_release() state checksdrivers/tty/tty_io.c+9 -100 replies
18/26tty: Change tty lock order to master->slavedrivers/tty/tty_io.c drivers/tty/tty_mutex.c include/linux/tty.h+21 -280 replies
19/26tty: Preset lock subclass for nested tty locksdrivers/tty/pty.c drivers/tty/tty_mutex.c include/linux/tty.h+12 -100 replies
20/26tty: Remove tty_unhangup() declarationinclude/linux/tty.h+0 -10 replies
21/26pty: Don't drop pty master tty lock to hangup slavedrivers/tty/pty.c+0 -21 reply
22/26pty, n_tty: Simplify input processing on final closedrivers/tty/n_tty.c drivers/tty/pty.c+21 -260 replies
23/26tty: Prefix tty_ldisc_{lock,lock_nested,unlock} functionsdrivers/tty/tty_ldisc.c+12 -120 replies
24/26tty: Fix hung task on pty hangupdrivers/tty/tty_ldisc.c+20 -20 replies
25/26tty: Fix timeout on pty set ldiscdrivers/tty/tty_ldisc.c+4 -170 replies
26/26tty: Flush ldisc buffer atomically with tty flip buffersdrivers/tty/tty_buffer.c drivers/tty/tty_io.c drivers/tty/tty_ldisc.c +1 more+15 -110 replies

Reviews trailers per patch

25 of 26 patches have a Reviewed-by or Acked-by.

PatchAlan Cox
1/26R-b
2/26R-b
3/26R-b
4/26R-b
5/26R-b
6/26R-b
7/26R-b
8/26R-b
9/26R-b
10/26R-b
11/26R-b
12/26R-b
13/26R-b
14/26R-b
15/26R-b
16/26R-b
17/26R-b
18/26R-b
19/26
20/26R-b
21/26R-b
22/26R-b
23/26R-b
24/26R-b
25/26R-b
26/26R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v2 thread

Cover letter [PATCH -next v2 00/26] tty locking changes

Changes in v2:
* New patch 19 ('tty: Preset lock subclass for nested tty locks') makes passing the tty_lock subclass at lock time unnecessary; regular ttys and master ptys use subclass 0 and slave ptys use subclass 1. The expected lock order is first subclass 0 then subclass 1. Lockdep will warn if the reverse order is used.

* That makes introducing tty_hangup_slave and refactoring tty_hangup et al unnecessary, so the previous patch 20 ('tty: Refactor __tty_hangup to enable lockdep annotation') was removed, along with 'tty: Document hangup call tree'.

* Added Alan's Reviewed-by tag to the patches Alan already reviewed, which just leaves the following patches needing re-review:
19/26 tty: Preset lock subclass for nested tty locks 21/26 pty: Don't drop pty master tty lock to hangup slave

I forgot to point this out in v1; this series depends on 'tty: Fix high cpu load if tty is unreleasable' 'tty: Prevent "read/write wait queue active!" log flooding'

==
Hi Greg,

This patch series has 3 major changes to how tty locking behaves:
1. the lock order of tty_lock() and tty->ldisc_sem is reversed; this eliminates a bunch of lock drop/reacquire which, in turn, eliminates tty state tracking that can no longer be observed. This also allows the pty driver to wait for input processing to complete while closing before setting TTY_OTHER_CLOSED (which eliminates the ugliness of checking input twice in n_tty_read() and n_tty_poll()).
2. the footprint of tty_mutex is reduced to only adding and removing ttys and is no longer held to acquire the tty_lock() in tty_open(); this allows for multiple ttys to be opened concurrently, even if one open stalls waiting for its tty_lock().
3. pty pair locking is reordered to master first, then slave, rather than by address. This works because, while releasing the master pty, the slave tty count needs to be changed, whereas, when releasing the slave, the master pty does not need to be accessed.
This furthur eliminates more lock drop/reacquire.

The longer-term goals, which this series builds towards, is:
1. simplifying the tty open/close behavior
2. eliminating the ASYNC_CLOSING code without breaking existing userspace
3. eliminating returning -EIO from tty_open(). Not sure if this is possible yet.

Regards,

Peter Hurley (26):
tty: Don't hold tty_lock for ldisc release
tty: Invert tty_lock/ldisc_sem lock order
tty: Remove TTY_HUPPING
tty: Clarify re-open behavior of master ptys
tty: Check tty->count instead of TTY_CLOSING in tty_reopen()
pty: Always return -EIO if slave BSD pty opened first
tty: Re-open /dev/tty without tty_mutex
tty: Drop tty_mutex before tty reopen
tty: Remove TTY_CLOSING
tty: Don't take tty_mutex for tty count changes
tty: Don't release tty locks for wait queue sanity check
tty: Document check_tty_count() requires tty_lock held
tty: Simplify pty pair teardown logic
tty: Fold pty pair handling into tty_flush_works()
tty: Simplify tty_ldisc_release() interface
tty: Simplify tty_release_checks() interface
tty: Simplify tty_release() state checks
tty: Change tty lock order to master->slave
tty: Preset lock subclass for nested tty locks
tty: Remove tty_unhangup() declaration
pty: Don't drop pty master tty lock to hangup slave pty, n_tty: Simplify input processing on final close
tty: Prefix tty_ldisc_{lock,lock_nested,unlock} functions
tty: Fix hung task on pty hangup
tty: Fix timeout on pty set ldisc
tty: Flush ldisc buffer atomically with tty flip buffers

 drivers/tty/n_tty.c      |  46 +++++------
 drivers/tty/pty.c        |  12 ++-
 drivers/tty/tty_buffer.c |  10 ++-
 drivers/tty/tty_io.c     | 195 ++++++++++++++++++++---------------------------
 drivers/tty/tty_ldisc.c  | 106 +++++++++++++-------------
 drivers/tty/tty_mutex.c  |  49 +++++-------
 include/linux/tty.h      |  15 ++--
 7 files changed, 196 insertions(+), 237 deletions(-)
Signature · 1 line
2.1.3