All of lore.kernel.org
 help / color / mirror / Atom feed
* wait_on_page_bit_common(TASK_KILLABLE, EXCLUSIVE) can miss wakeup?
@ 2020-06-24 16:11 Oleg Nesterov
  2020-06-24 16:20 ` Oleg Nesterov
  2020-06-24 16:22 ` Linus Torvalds
  0 siblings, 2 replies; 23+ messages in thread
From: Oleg Nesterov @ 2020-06-24 16:11 UTC (permalink / raw)
  To: Linus Torvalds, Nick Piggin, Peter Zijlstra, Mel Gorman,
	Jan Kara, Davidlohr Bueso, Andi Kleen
  Cc: Lukas Czerner, linux-kernel

Suppose that 2 threads T1 and T2 call __lock_page_killable() and sleep in
wait_on_page_bit_common() -> io_schedule().

T1 is killed, it does test_and_set_bit_lock() but the page is still locked.

unlock_page() calls __wake_up_common(nr_exclusive = 1), this wakes T1 up.
T2 is not woken.

T1 checks signal_pending_state() and returns EINTR.

T2 will sleep until another thread does lock/unlock ?

----------------------------------------------------------------------------
I noticed this by accident, I am hunting for another / unrelated bug. I did
git-blame and iiuc the commit a8b169afbf06a ("Avoid page waitqueue race leaving
possible page locker waiting") tried to fix the problem but see above, I don't
understand how can it help.

Don't we need something like below or I am totally confused?

Oleg.

--- x/mm/filemap.c
+++ x/mm/filemap.c
@@ -1131,14 +1131,23 @@ static inline int wait_on_page_bit_commo
 	wait_page.bit_nr = bit_nr;
 
 	for (;;) {
+		int intr = 0;
+
 		spin_lock_irq(&q->lock);
 
-		if (likely(list_empty(&wait->entry))) {
-			__add_wait_queue_entry_tail(q, wait);
-			SetPageWaiters(page);
-		}
+		// see the comment prepare_to_wait_event()
+		if (signal_pending_state(state, current)) {
+			list_del_init(&wait->entry);
+			intr = 1;
+		} else {
+			if (likely(list_empty(&wait->entry))) {
+				// HMM. head/tail depending on EXCLUSIVE ???
+				__add_wait_queue_entry_tail(q, wait);
+				SetPageWaiters(page);
+			}
 
-		set_current_state(state);
+			set_current_state(state);
+		}
 
 		spin_unlock_irq(&q->lock);
 
@@ -1146,7 +1155,7 @@ static inline int wait_on_page_bit_commo
 		if (behavior == DROP)
 			put_page(page);
 
-		if (likely(bit_is_set))
+		if (!intr && likely(bit_is_set))
 			io_schedule();
 
 		if (behavior == EXCLUSIVE) {
@@ -1157,7 +1166,7 @@ static inline int wait_on_page_bit_commo
 				break;
 		}
 
-		if (signal_pending_state(state, current)) {
+		if (intr) {
 			ret = -EINTR;
 			break;
 		}


^ permalink raw reply	[flat|nested] 23+ messages in thread

end of thread, other threads:[~2020-06-30 18:57 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-24 16:11 wait_on_page_bit_common(TASK_KILLABLE, EXCLUSIVE) can miss wakeup? Oleg Nesterov
2020-06-24 16:20 ` Oleg Nesterov
2020-06-24 16:36   ` Linus Torvalds
2020-06-26 15:43     ` Peter Zijlstra
2020-06-28  5:39       ` Linus Torvalds
2020-06-28 13:18         ` Peter Zijlstra
2020-06-29  3:28         ` Nicholas Piggin
2020-06-29 13:16           ` Nicholas Piggin
2020-06-29 16:36             ` Linus Torvalds
2020-06-30  2:12               ` Nicholas Piggin
2020-06-29 14:02           ` Oleg Nesterov
2020-06-30  2:08             ` Nicholas Piggin
2020-06-30  6:17               ` Oleg Nesterov
2020-06-30  9:08                 ` Nicholas Piggin
2020-06-30 10:53                   ` Oleg Nesterov
2020-06-30 11:36                     ` Oleg Nesterov
2020-06-30 11:50                       ` Oleg Nesterov
2020-06-30 18:02                         ` Linus Torvalds
2020-06-30 18:29                           ` Oleg Nesterov
2020-06-30 18:57                             ` Linus Torvalds
2020-06-29 15:13         ` Oleg Nesterov
2020-06-24 16:22 ` Linus Torvalds
2020-06-24 16:43   ` Oleg Nesterov

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.