diff options
author | Peter Zijlstra <peterz@infradead.org> | 2014-09-24 04:18:51 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@kernel.org> | 2014-10-28 05:56:10 -0400 |
commit | 97d9e28d1a27b84a6a0b155f2390289afa279341 (patch) | |
tree | 795f01ef74c97cb2397f0abddb17234c0b264b75 /drivers | |
parent | e23738a7300a7591a57a22f47b813fd1b53ec404 (diff) |
sched, tty: Deal with nested sleeps
n_tty_{read,write} are wait loops with sleeps in. Wait loops rely on
task_struct::state and sleeps do too, since that's the only means of
actually sleeping. Therefore the nested sleeps destroy the wait loop
state.
Fix this by using the new woken_wake_function and wait_woken() stuff,
which registers wakeups in wait and thereby allows shrinking the
task_state::state changes to the actual sleep part.
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Jiri Slaby <jslaby@suse.cz>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: tglx@linutronix.de
Cc: ilya.dryomov@inktank.com
Cc: umgwanakikbuti@gmail.com
Cc: oleg@redhat.com
Link: http://lkml.kernel.org/r/20140924082242.323011233@infradead.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/tty/n_tty.c | 17 |
1 files changed, 5 insertions, 12 deletions
diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c index 89c4cee253e3..fb3f519b803f 100644 --- a/drivers/tty/n_tty.c +++ b/drivers/tty/n_tty.c | |||
@@ -2123,7 +2123,7 @@ static ssize_t n_tty_read(struct tty_struct *tty, struct file *file, | |||
2123 | { | 2123 | { |
2124 | struct n_tty_data *ldata = tty->disc_data; | 2124 | struct n_tty_data *ldata = tty->disc_data; |
2125 | unsigned char __user *b = buf; | 2125 | unsigned char __user *b = buf; |
2126 | DECLARE_WAITQUEUE(wait, current); | 2126 | DEFINE_WAIT_FUNC(wait, woken_wake_function); |
2127 | int c; | 2127 | int c; |
2128 | int minimum, time; | 2128 | int minimum, time; |
2129 | ssize_t retval = 0; | 2129 | ssize_t retval = 0; |
@@ -2186,10 +2186,6 @@ static ssize_t n_tty_read(struct tty_struct *tty, struct file *file, | |||
2186 | nr--; | 2186 | nr--; |
2187 | break; | 2187 | break; |
2188 | } | 2188 | } |
2189 | /* This statement must be first before checking for input | ||
2190 | so that any interrupt will set the state back to | ||
2191 | TASK_RUNNING. */ | ||
2192 | set_current_state(TASK_INTERRUPTIBLE); | ||
2193 | 2189 | ||
2194 | if (((minimum - (b - buf)) < ldata->minimum_to_wake) && | 2190 | if (((minimum - (b - buf)) < ldata->minimum_to_wake) && |
2195 | ((minimum - (b - buf)) >= 1)) | 2191 | ((minimum - (b - buf)) >= 1)) |
@@ -2220,13 +2216,13 @@ static ssize_t n_tty_read(struct tty_struct *tty, struct file *file, | |||
2220 | n_tty_set_room(tty); | 2216 | n_tty_set_room(tty); |
2221 | up_read(&tty->termios_rwsem); | 2217 | up_read(&tty->termios_rwsem); |
2222 | 2218 | ||
2223 | timeout = schedule_timeout(timeout); | 2219 | timeout = wait_woken(&wait, TASK_INTERRUPTIBLE, |
2220 | timeout); | ||
2224 | 2221 | ||
2225 | down_read(&tty->termios_rwsem); | 2222 | down_read(&tty->termios_rwsem); |
2226 | continue; | 2223 | continue; |
2227 | } | 2224 | } |
2228 | } | 2225 | } |
2229 | __set_current_state(TASK_RUNNING); | ||
2230 | 2226 | ||
2231 | /* Deal with packet mode. */ | 2227 | /* Deal with packet mode. */ |
2232 | if (packet && b == buf) { | 2228 | if (packet && b == buf) { |
@@ -2273,7 +2269,6 @@ static ssize_t n_tty_read(struct tty_struct *tty, struct file *file, | |||
2273 | 2269 | ||
2274 | mutex_unlock(&ldata->atomic_read_lock); | 2270 | mutex_unlock(&ldata->atomic_read_lock); |
2275 | 2271 | ||
2276 | __set_current_state(TASK_RUNNING); | ||
2277 | if (b - buf) | 2272 | if (b - buf) |
2278 | retval = b - buf; | 2273 | retval = b - buf; |
2279 | 2274 | ||
@@ -2306,7 +2301,7 @@ static ssize_t n_tty_write(struct tty_struct *tty, struct file *file, | |||
2306 | const unsigned char *buf, size_t nr) | 2301 | const unsigned char *buf, size_t nr) |
2307 | { | 2302 | { |
2308 | const unsigned char *b = buf; | 2303 | const unsigned char *b = buf; |
2309 | DECLARE_WAITQUEUE(wait, current); | 2304 | DEFINE_WAIT_FUNC(wait, woken_wake_function); |
2310 | int c; | 2305 | int c; |
2311 | ssize_t retval = 0; | 2306 | ssize_t retval = 0; |
2312 | 2307 | ||
@@ -2324,7 +2319,6 @@ static ssize_t n_tty_write(struct tty_struct *tty, struct file *file, | |||
2324 | 2319 | ||
2325 | add_wait_queue(&tty->write_wait, &wait); | 2320 | add_wait_queue(&tty->write_wait, &wait); |
2326 | while (1) { | 2321 | while (1) { |
2327 | set_current_state(TASK_INTERRUPTIBLE); | ||
2328 | if (signal_pending(current)) { | 2322 | if (signal_pending(current)) { |
2329 | retval = -ERESTARTSYS; | 2323 | retval = -ERESTARTSYS; |
2330 | break; | 2324 | break; |
@@ -2378,12 +2372,11 @@ static ssize_t n_tty_write(struct tty_struct *tty, struct file *file, | |||
2378 | } | 2372 | } |
2379 | up_read(&tty->termios_rwsem); | 2373 | up_read(&tty->termios_rwsem); |
2380 | 2374 | ||
2381 | schedule(); | 2375 | wait_woken(&wait, TASK_INTERRUPTIBLE, MAX_SCHEDULE_TIMEOUT); |
2382 | 2376 | ||
2383 | down_read(&tty->termios_rwsem); | 2377 | down_read(&tty->termios_rwsem); |
2384 | } | 2378 | } |
2385 | break_out: | 2379 | break_out: |
2386 | __set_current_state(TASK_RUNNING); | ||
2387 | remove_wait_queue(&tty->write_wait, &wait); | 2380 | remove_wait_queue(&tty->write_wait, &wait); |
2388 | if (b - buf != nr && tty->fasync) | 2381 | if (b - buf != nr && tty->fasync) |
2389 | set_bit(TTY_DO_WRITE_WAKEUP, &tty->flags); | 2382 | set_bit(TTY_DO_WRITE_WAKEUP, &tty->flags); |