]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
sched: Clarify wake_up_q()'s write to task->wake_q.next
authorJann Horn <jannh@google.com>
Wed, 29 Jan 2025 19:53:03 +0000 (20:53 +0100)
committerPeter Zijlstra <peterz@infradead.org>
Sat, 8 Feb 2025 14:43:12 +0000 (15:43 +0100)
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.

Signed-off-by: Jann Horn <jannh@google.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lkml.kernel.org/r/20250129-sched-wakeup-prettier-v1-1-2f51f5f663fa@google.com
kernel/sched/core.c

index 3e5a6bf587f911184c3aa47af035b412f926217c..8931d9b1e895e0081109ba4ef6e7a3e75609d0b1 100644 (file)
@@ -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