aboutsummaryrefslogtreecommitdiffstats
path: root/mm/filemap.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2017-08-27 19:25:09 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2017-08-27 19:25:09 -0400
commita8b169afbf06a678437632709caac98e16f99263 (patch)
treeae0db5e530f6ce6831c371ccf9c10b941849a468 /mm/filemap.c
parent3510ca20ece0150af6b10c77a74ff1b5c198e3e2 (diff)
Avoid page waitqueue race leaving possible page locker waiting
The "lock_page_killable()" function waits for exclusive access to the page lock bit using the WQ_FLAG_EXCLUSIVE bit in the waitqueue entry set. That means that if it gets woken up, other waiters may have been skipped. That, in turn, means that if it sees the page being unlocked, it *must* take that lock and return success, even if a lethal signal is also pending. So instead of checking for lethal signals first, we need to check for them after we've checked the actual bit that we were waiting for. Even if that might then delay the killing of the process. This matches the order of the old "wait_on_bit_lock()" infrastructure that the page locking used to use (and is still used in a few other areas). Note that if we still return an error after having unsuccessfully tried to acquire the page lock, that is ok: that means that some other thread was able to get ahead of us and lock the page, and when that other thread then unlocks the page, the wakeup event will be repeated. So any other pending waiters will now get properly woken up. Fixes: 62906027091f ("mm: add PageWaiters indicating tasks are waiting for a page bit") Cc: Nick Piggin <npiggin@gmail.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Mel Gorman <mgorman@techsingularity.net> Cc: Jan Kara <jack@suse.cz> Cc: Davidlohr Bueso <dave@stgolabs.net> Cc: Andi Kleen <ak@linux.intel.com> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'mm/filemap.c')
-rw-r--r--mm/filemap.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/mm/filemap.c b/mm/filemap.c
index baba290c276b..0b41c8cbeabc 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -986,10 +986,6 @@ static inline int wait_on_page_bit_common(wait_queue_head_t *q,
986 986
987 if (likely(test_bit(bit_nr, &page->flags))) { 987 if (likely(test_bit(bit_nr, &page->flags))) {
988 io_schedule(); 988 io_schedule();
989 if (unlikely(signal_pending_state(state, current))) {
990 ret = -EINTR;
991 break;
992 }
993 } 989 }
994 990
995 if (lock) { 991 if (lock) {
@@ -999,6 +995,11 @@ static inline int wait_on_page_bit_common(wait_queue_head_t *q,
999 if (!test_bit(bit_nr, &page->flags)) 995 if (!test_bit(bit_nr, &page->flags))
1000 break; 996 break;
1001 } 997 }
998
999 if (unlikely(signal_pending_state(state, current))) {
1000 ret = -EINTR;
1001 break;
1002 }
1002 } 1003 }
1003 1004
1004 finish_wait(q, wait); 1005 finish_wait(q, wait);