diff options
author | Oleg Nesterov <oleg@redhat.com> | 2016-09-06 10:00:47 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@kernel.org> | 2016-09-30 04:53:19 -0400 |
commit | 38a3e1fc1dac480f3672ab22fc97e1f995c80ed7 (patch) | |
tree | a0bc0bb9932d0acaee5e2195260dcefae46d7348 | |
parent | ab522e33f91799661aad47bebb691f241a9f6bb8 (diff) |
sched/wait: Fix abort_exclusive_wait(), it should pass TASK_NORMAL to wake_up()
Otherwise this logic only works if mode is "compatible" with another
exclusive waiter.
If some wq has both TASK_INTERRUPTIBLE and TASK_UNINTERRUPTIBLE waiters,
abort_exclusive_wait() won't wait an uninterruptible waiter.
The main user is __wait_on_bit_lock() and currently it is fine but only
because TASK_KILLABLE includes TASK_UNINTERRUPTIBLE and we do not have
lock_page_interruptible() yet.
Just use TASK_NORMAL and remove the "mode" arg from abort_exclusive_wait().
Yes, this means that (say) wake_up_interruptible() can wake up the non-
interruptible waiter(s), but I think this is fine. And in fact I think
that abort_exclusive_wait() must die, see the next change.
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Al Viro <viro@ZenIV.linux.org.uk>
Cc: Bart Van Assche <bvanassche@acm.org>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Neil Brown <neilb@suse.de>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/20160906140047.GA6157@redhat.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
-rw-r--r-- | include/linux/wait.h | 6 | ||||
-rw-r--r-- | kernel/sched/wait.c | 8 |
2 files changed, 6 insertions, 8 deletions
diff --git a/include/linux/wait.h b/include/linux/wait.h index c3ff74d764fa..e4cfd1ed726e 100644 --- a/include/linux/wait.h +++ b/include/linux/wait.h | |||
@@ -281,8 +281,8 @@ wait_queue_head_t *bit_waitqueue(void *, int); | |||
281 | if (___wait_is_interruptible(state) && __int) { \ | 281 | if (___wait_is_interruptible(state) && __int) { \ |
282 | __ret = __int; \ | 282 | __ret = __int; \ |
283 | if (exclusive) { \ | 283 | if (exclusive) { \ |
284 | abort_exclusive_wait(&wq, &__wait, \ | 284 | abort_exclusive_wait(&wq, &__wait, \ |
285 | state, NULL); \ | 285 | NULL); \ |
286 | goto __out; \ | 286 | goto __out; \ |
287 | } \ | 287 | } \ |
288 | break; \ | 288 | break; \ |
@@ -989,7 +989,7 @@ void prepare_to_wait(wait_queue_head_t *q, wait_queue_t *wait, int state); | |||
989 | void prepare_to_wait_exclusive(wait_queue_head_t *q, wait_queue_t *wait, int state); | 989 | void prepare_to_wait_exclusive(wait_queue_head_t *q, wait_queue_t *wait, int state); |
990 | long prepare_to_wait_event(wait_queue_head_t *q, wait_queue_t *wait, int state); | 990 | long prepare_to_wait_event(wait_queue_head_t *q, wait_queue_t *wait, int state); |
991 | void finish_wait(wait_queue_head_t *q, wait_queue_t *wait); | 991 | void finish_wait(wait_queue_head_t *q, wait_queue_t *wait); |
992 | void abort_exclusive_wait(wait_queue_head_t *q, wait_queue_t *wait, unsigned int mode, void *key); | 992 | void abort_exclusive_wait(wait_queue_head_t *q, wait_queue_t *wait, void *key); |
993 | long wait_woken(wait_queue_t *wait, unsigned mode, long timeout); | 993 | long wait_woken(wait_queue_t *wait, unsigned mode, long timeout); |
994 | int woken_wake_function(wait_queue_t *wait, unsigned mode, int sync, void *key); | 994 | int woken_wake_function(wait_queue_t *wait, unsigned mode, int sync, void *key); |
995 | int autoremove_wake_function(wait_queue_t *wait, unsigned mode, int sync, void *key); | 995 | int autoremove_wake_function(wait_queue_t *wait, unsigned mode, int sync, void *key); |
diff --git a/kernel/sched/wait.c b/kernel/sched/wait.c index f15d6b6a538a..2bbba0175ab2 100644 --- a/kernel/sched/wait.c +++ b/kernel/sched/wait.c | |||
@@ -259,7 +259,6 @@ EXPORT_SYMBOL(finish_wait); | |||
259 | * abort_exclusive_wait - abort exclusive waiting in a queue | 259 | * abort_exclusive_wait - abort exclusive waiting in a queue |
260 | * @q: waitqueue waited on | 260 | * @q: waitqueue waited on |
261 | * @wait: wait descriptor | 261 | * @wait: wait descriptor |
262 | * @mode: runstate of the waiter to be woken | ||
263 | * @key: key to identify a wait bit queue or %NULL | 262 | * @key: key to identify a wait bit queue or %NULL |
264 | * | 263 | * |
265 | * Sets current thread back to running state and removes | 264 | * Sets current thread back to running state and removes |
@@ -273,8 +272,7 @@ EXPORT_SYMBOL(finish_wait); | |||
273 | * aborts and is woken up concurrently and no one wakes up | 272 | * aborts and is woken up concurrently and no one wakes up |
274 | * the next waiter. | 273 | * the next waiter. |
275 | */ | 274 | */ |
276 | void abort_exclusive_wait(wait_queue_head_t *q, wait_queue_t *wait, | 275 | void abort_exclusive_wait(wait_queue_head_t *q, wait_queue_t *wait, void *key) |
277 | unsigned int mode, void *key) | ||
278 | { | 276 | { |
279 | unsigned long flags; | 277 | unsigned long flags; |
280 | 278 | ||
@@ -283,7 +281,7 @@ void abort_exclusive_wait(wait_queue_head_t *q, wait_queue_t *wait, | |||
283 | if (!list_empty(&wait->task_list)) | 281 | if (!list_empty(&wait->task_list)) |
284 | list_del_init(&wait->task_list); | 282 | list_del_init(&wait->task_list); |
285 | else if (waitqueue_active(q)) | 283 | else if (waitqueue_active(q)) |
286 | __wake_up_locked_key(q, mode, key); | 284 | __wake_up_locked_key(q, TASK_NORMAL, key); |
287 | spin_unlock_irqrestore(&q->lock, flags); | 285 | spin_unlock_irqrestore(&q->lock, flags); |
288 | } | 286 | } |
289 | EXPORT_SYMBOL(abort_exclusive_wait); | 287 | EXPORT_SYMBOL(abort_exclusive_wait); |
@@ -434,7 +432,7 @@ __wait_on_bit_lock(wait_queue_head_t *wq, struct wait_bit_queue *q, | |||
434 | ret = action(&q->key, mode); | 432 | ret = action(&q->key, mode); |
435 | if (!ret) | 433 | if (!ret) |
436 | continue; | 434 | continue; |
437 | abort_exclusive_wait(wq, &q->wait, mode, &q->key); | 435 | abort_exclusive_wait(wq, &q->wait, &q->key); |
438 | return ret; | 436 | return ret; |
439 | } while (test_and_set_bit(q->key.bit_nr, q->key.flags)); | 437 | } while (test_and_set_bit(q->key.bit_nr, q->key.flags)); |
440 | finish_wait(wq, &q->wait); | 438 | finish_wait(wq, &q->wait); |