From: Peter Zijlstra <peterz@infradead.org>
To: Jon Kohler <jon@nutanix.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,
Harshit Agarwal <harshit@nutanix.com>,
Phil Auld <pauld@redhat.com>
Subject: Re: [PATCH v2] sched: add READ_ONCE to task_on_rq_queued
Date: Fri, 15 Nov 2024 10:50:52 +0100 [thread overview]
Message-ID: <20241115095052.GU22801@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <20241114210812.1836587-1-jon@nutanix.com>
On Thu, Nov 14, 2024 at 02:08:11PM -0700, Jon Kohler wrote:
> From: Harshit Agarwal <harshit@nutanix.com>
>
> task_on_rq_queued read p->on_rq without READ_ONCE, though p->on_rq is
> set with WRITE_ONCE in {activate|deactivate}_task and smp_store_release
> in __block_task, and also read with READ_ONCE in task_on_rq_migrating.
>
> Make all of these accesses pair together by adding READ_ONCE in the
> task_on_rq_queued.
>
> Signed-off-by: Harshit Agarwal <harshit@nutanix.com>
> Reviewed-by: Phil Auld <pauld@redhat.com>
> Cc: Jon Kohler <jon@nutanix.com>
> ---
> kernel/sched/sched.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
> index c03b3d7b320e..dbbe5ce0dd96 100644
> --- a/kernel/sched/sched.h
> +++ b/kernel/sched/sched.h
> @@ -2277,7 +2277,7 @@ static inline int task_on_cpu(struct rq *rq, struct task_struct *p)
>
> static inline int task_on_rq_queued(struct task_struct *p)
> {
> - return p->on_rq == TASK_ON_RQ_QUEUED;
> + return READ_ONCE(p->on_rq) == TASK_ON_RQ_QUEUED;
> }
I think that strictly speaking we don't need it here, *IF* we see the
ON_RQ_QUEUED value, it must be stable.
But yeah, this is probably easier to reason about.
If you've got time, it might be worth to try something like:
if (READ_ONCE(p->on_rq) == TASK_ON_RQ_QUEUED) {
/*
* If we observe ON_RQ_QUEUED, it should be stable. IOW
* there should be no concurrent writes at this point.
*/
ASSERT_EXCLUSIVE_WRITER(p->on_rq);
return true;
}
return false;
next prev parent reply other threads:[~2024-11-15 9:51 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-14 21:08 Jon Kohler
2024-11-15 9:50 ` Peter Zijlstra [this message]
2024-12-02 11:14 ` [tip: sched/core] " tip-bot2 for Harshit Agarwal
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=20241115095052.GU22801@noisy.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=bsegall@google.com \
--cc=dietmar.eggemann@arm.com \
--cc=harshit@nutanix.com \
--cc=jon@nutanix.com \
--cc=juri.lelli@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mgorman@suse.de \
--cc=mingo@redhat.com \
--cc=pauld@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
all inboxes | Powered by JetHome®