Skip to content

Commit

Permalink
tty: Make lock subclasses available for other tty locks
Browse files Browse the repository at this point in the history
Besides nested legacy_mutex locking which is required on pty pair
teardown, other nested pty operations require lock subclassing.

Move lock subclass definition to tty interface header, include/linux/tty.h,
and document its use.

Signed-off-by: Peter Hurley <peter@hurleysoftware.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Peter Hurley authored and Greg Kroah-Hartman committed Feb 2, 2015
1 parent fb5ef9e commit 3abf87c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
12 changes: 1 addition & 11 deletions drivers/tty/tty_mutex.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,8 @@
#include <linux/semaphore.h>
#include <linux/sched.h>

/*
* Nested tty locks are necessary for releasing pty pairs.
* The stable lock order is master pty first, then slave pty.
*/

/* Legacy tty mutex glue */

enum {
TTY_MUTEX_NORMAL,
TTY_MUTEX_SLAVE,
};

/*
* Getting the big tty mutex.
*/
Expand Down Expand Up @@ -58,5 +48,5 @@ void __lockfunc tty_unlock_slave(struct tty_struct *tty)

void tty_set_lock_subclass(struct tty_struct *tty)
{
lockdep_set_subclass(&tty->legacy_mutex, TTY_MUTEX_SLAVE);
lockdep_set_subclass(&tty->legacy_mutex, TTY_LOCK_SLAVE);
}
17 changes: 17 additions & 0 deletions include/linux/tty.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,23 @@
#include <linux/llist.h>


/*
* Lock subclasses for tty locks
*
* TTY_LOCK_NORMAL is for normal ttys and master ptys.
* TTY_LOCK_SLAVE is for slave ptys only.
*
* Lock subclasses are necessary for handling nested locking with pty pairs.
* tty locks which use nested locking:
*
* legacy_mutex - Nested tty locks are necessary for releasing pty pairs.
* The stable lock order is master pty first, then slave pty.
*/

enum {
TTY_LOCK_NORMAL = 0,
TTY_LOCK_SLAVE,
};

/*
* (Note: the *_driver.minor_start values 1, 64, 128, 192 are
Expand Down

0 comments on commit 3abf87c

Please sign in to comment.