Commit d8c1f929 authored by Peter Hurley's avatar Peter Hurley Committed by Greg Kroah-Hartman

tty: Only guarantee termios read safety for throttle/unthrottle

No tty driver modifies termios during throttle() or unthrottle().
Therefore, only read safety is required.

However, tty_throttle_safe and tty_unthrottle_safe must still be
mutually exclusive; introduce throttle_mutex for that purpose.
Signed-off-by: default avatarPeter Hurley <peter@hurleysoftware.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent fb7aa03d
...@@ -1518,9 +1518,7 @@ static void __receive_buf(struct tty_struct *tty, const unsigned char *cp, ...@@ -1518,9 +1518,7 @@ static void __receive_buf(struct tty_struct *tty, const unsigned char *cp,
tty_set_flow_change(tty, TTY_THROTTLE_SAFE); tty_set_flow_change(tty, TTY_THROTTLE_SAFE);
if (receive_room(tty) >= TTY_THRESHOLD_THROTTLE) if (receive_room(tty) >= TTY_THRESHOLD_THROTTLE)
break; break;
up_read(&tty->termios_rwsem);
throttled = tty_throttle_safe(tty); throttled = tty_throttle_safe(tty);
down_read(&tty->termios_rwsem);
if (!throttled) if (!throttled)
break; break;
} }
...@@ -2086,9 +2084,7 @@ static ssize_t n_tty_read(struct tty_struct *tty, struct file *file, ...@@ -2086,9 +2084,7 @@ static ssize_t n_tty_read(struct tty_struct *tty, struct file *file,
if (!tty->count) if (!tty->count)
break; break;
n_tty_set_room(tty); n_tty_set_room(tty);
up_read(&tty->termios_rwsem);
unthrottled = tty_unthrottle_safe(tty); unthrottled = tty_unthrottle_safe(tty);
down_read(&tty->termios_rwsem);
if (!unthrottled) if (!unthrottled)
break; break;
} }
......
...@@ -3015,6 +3015,7 @@ void initialize_tty_struct(struct tty_struct *tty, ...@@ -3015,6 +3015,7 @@ void initialize_tty_struct(struct tty_struct *tty,
tty->session = NULL; tty->session = NULL;
tty->pgrp = NULL; tty->pgrp = NULL;
mutex_init(&tty->legacy_mutex); mutex_init(&tty->legacy_mutex);
mutex_init(&tty->throttle_mutex);
init_rwsem(&tty->termios_rwsem); init_rwsem(&tty->termios_rwsem);
init_ldsem(&tty->ldisc_sem); init_ldsem(&tty->ldisc_sem);
init_waitqueue_head(&tty->write_wait); init_waitqueue_head(&tty->write_wait);
......
...@@ -151,7 +151,7 @@ int tty_throttle_safe(struct tty_struct *tty) ...@@ -151,7 +151,7 @@ int tty_throttle_safe(struct tty_struct *tty)
{ {
int ret = 0; int ret = 0;
down_write(&tty->termios_rwsem); mutex_lock(&tty->throttle_mutex);
if (!test_bit(TTY_THROTTLED, &tty->flags)) { if (!test_bit(TTY_THROTTLED, &tty->flags)) {
if (tty->flow_change != TTY_THROTTLE_SAFE) if (tty->flow_change != TTY_THROTTLE_SAFE)
ret = 1; ret = 1;
...@@ -161,7 +161,7 @@ int tty_throttle_safe(struct tty_struct *tty) ...@@ -161,7 +161,7 @@ int tty_throttle_safe(struct tty_struct *tty)
tty->ops->throttle(tty); tty->ops->throttle(tty);
} }
} }
up_write(&tty->termios_rwsem); mutex_unlock(&tty->throttle_mutex);
return ret; return ret;
} }
...@@ -182,7 +182,7 @@ int tty_unthrottle_safe(struct tty_struct *tty) ...@@ -182,7 +182,7 @@ int tty_unthrottle_safe(struct tty_struct *tty)
{ {
int ret = 0; int ret = 0;
down_write(&tty->termios_rwsem); mutex_lock(&tty->throttle_mutex);
if (test_bit(TTY_THROTTLED, &tty->flags)) { if (test_bit(TTY_THROTTLED, &tty->flags)) {
if (tty->flow_change != TTY_UNTHROTTLE_SAFE) if (tty->flow_change != TTY_UNTHROTTLE_SAFE)
ret = 1; ret = 1;
...@@ -192,7 +192,7 @@ int tty_unthrottle_safe(struct tty_struct *tty) ...@@ -192,7 +192,7 @@ int tty_unthrottle_safe(struct tty_struct *tty)
tty->ops->unthrottle(tty); tty->ops->unthrottle(tty);
} }
} }
up_write(&tty->termios_rwsem); mutex_unlock(&tty->throttle_mutex);
return ret; return ret;
} }
......
...@@ -244,6 +244,7 @@ struct tty_struct { ...@@ -244,6 +244,7 @@ struct tty_struct {
struct mutex atomic_write_lock; struct mutex atomic_write_lock;
struct mutex legacy_mutex; struct mutex legacy_mutex;
struct mutex throttle_mutex;
struct rw_semaphore termios_rwsem; struct rw_semaphore termios_rwsem;
spinlock_t ctrl_lock; spinlock_t ctrl_lock;
/* Termios values are protected by the termios rwsem */ /* Termios values are protected by the termios rwsem */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment