Commit 726152d4 authored by Xie Yongji's avatar Xie Yongji Committed by Greg Kroah-Hartman

locking/rwsem: Fix (possible) missed wakeup

[ Upstream commit e158488be27b157802753a59b336142dc0eb0380 ]

Because wake_q_add() can imply an immediate wakeup (cmpxchg failure
case), we must not rely on the wakeup being delayed. However, commit:

  e3851390 ("locking/rwsem: Rework zeroing reader waiter->task")

relies on exactly that behaviour in that the wakeup must not happen
until after we clear waiter->task.

[ peterz: Added changelog. ]
Signed-off-by: default avatarXie Yongji <>
Signed-off-by: default avatarZhang Yu <>
Signed-off-by: default avatarPeter Zijlstra (Intel) <>
Cc: Linus Torvalds <>
Cc: Peter Zijlstra <>
Cc: Thomas Gleixner <>
Fixes: e3851390 ("locking/rwsem: Rework zeroing reader waiter->task")
Link: default avatarIngo Molnar <>
Signed-off-by: default avatarSasha Levin <>
parent f618b90b
......@@ -198,15 +198,22 @@ static void __rwsem_mark_wake(struct rw_semaphore *sem,
tsk = waiter->task;
wake_q_add(wake_q, tsk);
* Ensure that the last operation is setting the reader
* Ensure calling get_task_struct() before setting the reader
* waiter to nil such that rwsem_down_read_failed() cannot
* race with do_exit() by always holding a reference count
* to the task to wakeup.
smp_store_release(&waiter->task, NULL);
* Ensure issuing the wakeup (either by us or someone else)
* after setting the reader waiter to nil.
wake_q_add(wake_q, tsk);
/* wake_q_add() already take the task ref */
adjustment = woken * RWSEM_ACTIVE_READ_BIAS - adjustment;
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment