提交 5f24c443 编写于 作者: X Xie Yongji 提交者: Xie XiuQi

locking/rwsem: Fix (possible) missed wakeup

mainline inclusion
from mainline-5.0
commit e158488be27b
category: bugfix
bugzilla: 7210
CVE: NA

-------------------------------------------------

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: NXie Yongji <xieyongji@baidu.com>
Signed-off-by: NZhang Yu <zhangyu31@baidu.com>
Signed-off-by: NPeter Zijlstra (Intel) <peterz@infradead.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Fixes: e3851390 ("locking/rwsem: Rework zeroing reader waiter->task")
Link: https://lkml.kernel.org/r/1543495830-2644-1-git-send-email-xieyongji@baidu.comSigned-off-by: NIngo Molnar <mingo@kernel.org>
(cherry picked from commit e158488be27b157802753a59b336142dc0eb0380)
Signed-off-by: NXie XiuQi <xiexiuqi@huawei.com>
Reviewed-by: NCheng Jian <cj.chengjian@huawei.com>
Signed-off-by: NYang Yingliang <yangyingliang@huawei.com>
上级 07244d26
...@@ -198,15 +198,22 @@ static void __rwsem_mark_wake(struct rw_semaphore *sem, ...@@ -198,15 +198,22 @@ static void __rwsem_mark_wake(struct rw_semaphore *sem,
woken++; woken++;
tsk = waiter->task; tsk = waiter->task;
wake_q_add(wake_q, tsk); get_task_struct(tsk);
list_del(&waiter->list); list_del(&waiter->list);
/* /*
* 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 * waiter to nil such that rwsem_down_read_failed() cannot
* race with do_exit() by always holding a reference count * race with do_exit() by always holding a reference count
* to the task to wakeup. * to the task to wakeup.
*/ */
smp_store_release(&waiter->task, NULL); 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 */
put_task_struct(tsk);
} }
adjustment = woken * RWSEM_ACTIVE_READ_BIAS - adjustment; adjustment = woken * RWSEM_ACTIVE_READ_BIAS - adjustment;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册