public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] locking/rwsem: Synchronize task state & waiter->task of readers
@ 2018-04-10 17:22 Waiman Long
  2018-04-18  6:20 ` Benjamin Herrenschmidt
  2018-04-23 16:46 ` Waiman Long
  0 siblings, 2 replies; 7+ messages in thread
From: Waiman Long @ 2018-04-10 17:22 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar
  Cc: linux-kernel, Dave Chinner, Eric Sandeen, Paul E. McKenney,
	Waiman Long

It was observed occasionally in PowerPC systems that there was reader
who had not been woken up but that its waiter->task had been cleared.

One probable cause of this missed wakeup may be the fact that the
waiter->task and the task state have not been properly synchronized as
the lock release-acquire pair of different locks in the wakeup code path
does not provide a full memory barrier guarantee. So smp_store_mb()
is now used to set waiter->task to NULL to provide a proper memory
barrier for synchronization.

Signed-off-by: Waiman Long <longman@redhat.com>
---
 kernel/locking/rwsem-xadd.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/kernel/locking/rwsem-xadd.c b/kernel/locking/rwsem-xadd.c
index e795908..b3c588c 100644
--- a/kernel/locking/rwsem-xadd.c
+++ b/kernel/locking/rwsem-xadd.c
@@ -209,6 +209,23 @@ static void __rwsem_mark_wake(struct rw_semaphore *sem,
 		smp_store_release(&waiter->task, NULL);
 	}
 
+	/*
+	 * To avoid missed wakeup of reader, we need to make sure
+	 * that task state and waiter->task are properly synchronized.
+	 *
+	 *     wakeup		      sleep
+	 *     ------		      -----
+	 * __rwsem_mark_wake:	rwsem_down_read_failed*:
+	 *   [S] waiter->task	  [S] set_current_state(state)
+	 *	 MB		      MB
+	 * try_to_wake_up:
+	 *   [L] state		  [L] waiter->task
+	 *
+	 * For the wakeup path, the original lock release-acquire pair
+	 * does not provide enough guarantee of proper synchronization.
+	 */
+	smp_mb();
+
 	adjustment = woken * RWSEM_ACTIVE_READ_BIAS - adjustment;
 	if (list_empty(&sem->wait_list)) {
 		/* hit end of list above */
-- 
1.8.3.1

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

end of thread, other threads:[~2018-04-24 14:49 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-04-10 17:22 [PATCH] locking/rwsem: Synchronize task state & waiter->task of readers Waiman Long
2018-04-18  6:20 ` Benjamin Herrenschmidt
2018-04-23 16:46 ` Waiman Long
2018-04-23 20:55   ` Andrea Parri
2018-04-23 21:30     ` Waiman Long
2018-04-24  9:15     ` Peter Zijlstra
2018-04-24 14:49       ` Waiman Long

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox