The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Jann Horn <jannh@google.com>
Cc: Ingo Molnar <mingo@redhat.com>,
	Juri Lelli <juri.lelli@redhat.com>,
	Vincent Guittot <vincent.guittot@linaro.org>,
	Dietmar Eggemann <dietmar.eggemann@arm.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	Ben Segall <bsegall@google.com>, Mel Gorman <mgorman@suse.de>,
	Valentin Schneider <vschneid@redhat.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] sched: Clarify wake_up_q()'s write to task->wake_q.next
Date: Mon, 3 Feb 2025 13:14:28 +0100	[thread overview]
Message-ID: <20250203121428.GC14028@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <20250129-sched-wakeup-prettier-v1-1-2f51f5f663fa@google.com>

On Wed, Jan 29, 2025 at 08:53:03PM +0100, Jann Horn wrote:
> 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>
> ---
> 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(-)
> 
> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> index 9142a0394d46605e96e10cef97cce02d741f6c93..ce64652858703826dca510479f563a28c2fb2405 100644
> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
> @@ -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!

  reply	other threads:[~2025-02-03 12:14 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-29 19:53 [PATCH] sched: Clarify wake_up_q()'s write to task->wake_q.next Jann Horn
2025-02-03 12:14 ` Peter Zijlstra [this message]
2025-02-08 14:51 ` [tip: sched/urgent] " tip-bot2 for Jann Horn

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250203121428.GC14028@noisy.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=bsegall@google.com \
    --cc=dietmar.eggemann@arm.com \
    --cc=jannh@google.com \
    --cc=juri.lelli@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mgorman@suse.de \
    --cc=mingo@redhat.com \
    --cc=rostedt@goodmis.org \
    --cc=vincent.guittot@linaro.org \
    --cc=vschneid@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox