sched: Clarify wake_up_q()'s write to task->wake_q.next
PATCH 1/1 sched: Clarify wake_up_q()'s write to task->wake_q.next
Clarify that wake_up_q() does an atomic write to task->wake_q.next, after which a concurrent __wake_q_add() can immediately overwrite task->wake_q.next again.
---
a minor change; I figured we should at least be using WRITE_ONCE() here, and I might as well change the comments a little bit while I'm touching this
--- kernel/sched/core.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
kernel/sched/core.c +3 -2
@@ -1063,9 +1063,10 @@ void wake_up_q(struct wake_q_head *head)struct task_struct *task; task = container_of(node, struct task_struct, wake_q); -/* Task can safely be re-inserted now: */ node = node->next; - task->wake_q.next =NULL ; +/* pairs with cmpxchg_relaxed() in __wake_q_add() */ +WRITE_ONCE (task->wake_q.next,NULL ); +/* Task can safely be re-inserted now. */ /* * wake_up_process() executes a full barrier, which pairs with
---
base-commit: 05dbaf8dd8bf537d4b4eb3115ab42a5fb40ff1f5
change-id: 20250129-sched-wakeup-prettier-c28762d8deee
Signature · 1 line
Jann Horn <[email protected]>
Peter Zijlstra
maintainerQuoted 18 lines · Jann Horn
Clarify that
wake_up_q()does an atomic write totask->wake_q.next, after which a concurrent__wake_q_add()can immediately overwritetask->wake_q.nextagain.Signed-off-by Jann Horn <[email protected]>---
a minor change; I figured we should at least be usingWRITE_ONCE()here, and I might as well change the comments a little bit while I'm touching this--- kernel/sched/core.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)kernel/sched/core.c +0
-0
kernel/sched/core.c void wake_up_q(struct wake_q_head *head) · line 1069
Quoted 9 lines
kernel/sched/core.c +3
-2@@ -1063,9 +1063,10 @@ void wake_up_q(struct wake_q_head *head)struct task_struct *task; task = container_of(node, struct task_struct, wake_q); -/* Task can safely be re-inserted now: */ node = node->next; - task->wake_q.next =NULL ; +/* pairs with cmpxchg_relaxed() in __wake_q_add() */ +WRITE_ONCE (task->wake_q.next,NULL ); +/* Task can safely be re-inserted now. */
Right, so even if the store is shattered, the cmpxchg won't proceed until all bits land -- eg. NULL becomes 'complete'.
That said, your patch makes sense, so let me go stick that in a queue somewhere.
Thanks!
The following commit has been merged into the sched/urgent branch of tip:
The following commit has been merged into the sched/urgent branch of tip:
Commit-ID: bcc6244e13b4d4903511a1ea84368abf925031c0 Gitweb: https://git.kernel.org/tip/bcc6244e13b4d4903511a1ea84368abf925031c0 Author: Jann Horn <[email protected]> AuthorDate: Wed, 29 Jan 2025 20:53:03 +01:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Sat, 08 Feb 2025 15:43:12 +01:00
sched: Clarify wake_up_q()'s write to task->wake_q.next
Clarify that wake_up_q() does an atomic write to task->wake_q.next, after which a concurrent __wake_q_add() can immediately overwrite task->wake_q.next again.
--- kernel/sched/core.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
kernel/sched/core.c +3 -2
@@ -1055,9 +1055,10 @@ void wake_up_q(struct wake_q_head *head)struct task_struct *task; task = container_of(node, struct task_struct, wake_q); -/* Task can safely be re-inserted now: */ node = node->next; - task->wake_q.next =NULL ; +/* pairs with cmpxchg_relaxed() in __wake_q_add() */ +WRITE_ONCE (task->wake_q.next,NULL ); +/* Task can safely be re-inserted now. */ /* * wake_up_process() executes a full barrier, which pairs with