public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] sched: add READ_ONCE to task_on_rq_queued
@ 2024-11-14 16:21 Jon Kohler
  2024-11-14 18:52 ` Phil Auld
  0 siblings, 1 reply; 4+ messages in thread
From: Jon Kohler @ 2024-11-14 16:21 UTC (permalink / raw)
  To: Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot,
	Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
	Valentin Schneider, linux-kernel
  Cc: Jon Kohler

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: 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;
 }
 
 static inline int task_on_rq_migrating(struct task_struct *p)
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] sched: add READ_ONCE to task_on_rq_queued
  2024-11-14 16:21 [PATCH] sched: add READ_ONCE to task_on_rq_queued Jon Kohler
@ 2024-11-14 18:52 ` Phil Auld
  2024-11-14 18:59   ` Jon Kohler
  0 siblings, 1 reply; 4+ messages in thread
From: Phil Auld @ 2024-11-14 18:52 UTC (permalink / raw)
  To: Jon Kohler
  Cc: Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot,
	Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
	Valentin Schneider, linux-kernel

On Thu, Nov 14, 2024 at 09:21:28AM -0700 Jon Kohler wrote:
> 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: 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;
>  }
>  
>  static inline int task_on_rq_migrating(struct task_struct *p)
> -- 
> 2.43.0
> 
> 

That looks right especially when seen with task_on_rq_migrating()
right below it, as you said.

Reviewed-by: Phil Auld <pauld@redhat.com>


Cheers,
Phil
-- 


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] sched: add READ_ONCE to task_on_rq_queued
  2024-11-14 18:52 ` Phil Auld
@ 2024-11-14 18:59   ` Jon Kohler
  2024-11-14 19:14     ` Phil Auld
  0 siblings, 1 reply; 4+ messages in thread
From: Jon Kohler @ 2024-11-14 18:59 UTC (permalink / raw)
  To: Phil Auld
  Cc: Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot,
	Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
	Valentin Schneider, linux-kernel@vger.kernel.org



> On Nov 14, 2024, at 1:52 PM, Phil Auld <pauld@redhat.com> wrote:
> 
> !-------------------------------------------------------------------|
>  CAUTION: External Email
> 
> |-------------------------------------------------------------------!
> 
> On Thu, Nov 14, 2024 at 09:21:28AM -0700 Jon Kohler wrote:
>> 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: 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;
>> }
>> 
>> static inline int task_on_rq_migrating(struct task_struct *p)
>> -- 
>> 2.43.0
>> 
>> 
> 
> That looks right especially when seen with task_on_rq_migrating()
> right below it, as you said.
> 
> Reviewed-by: Phil Auld <pauld@redhat.com>
> 

Thanks Phil - note, I’ve got a v2 coming shortly as I’ve bungled the
author and codeveloped tag from our internal version of this patch.

I’ll get that out, but it will be the exact same code.

> 
> Cheers,
> Phil
> -- 
> 


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] sched: add READ_ONCE to task_on_rq_queued
  2024-11-14 18:59   ` Jon Kohler
@ 2024-11-14 19:14     ` Phil Auld
  0 siblings, 0 replies; 4+ messages in thread
From: Phil Auld @ 2024-11-14 19:14 UTC (permalink / raw)
  To: Jon Kohler
  Cc: Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot,
	Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
	Valentin Schneider, linux-kernel@vger.kernel.org

On Thu, Nov 14, 2024 at 06:59:14PM +0000 Jon Kohler wrote:
> 
> 
> > On Nov 14, 2024, at 1:52 PM, Phil Auld <pauld@redhat.com> wrote:
> > 
> > !-------------------------------------------------------------------|
> >  CAUTION: External Email
> > 
> > |-------------------------------------------------------------------!
> > 
> > On Thu, Nov 14, 2024 at 09:21:28AM -0700 Jon Kohler wrote:
> >> 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: 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;
> >> }
> >> 
> >> static inline int task_on_rq_migrating(struct task_struct *p)
> >> -- 
> >> 2.43.0
> >> 
> >> 
> > 
> > That looks right especially when seen with task_on_rq_migrating()
> > right below it, as you said.
> > 
> > Reviewed-by: Phil Auld <pauld@redhat.com>
> > 
> 
> Thanks Phil - note, I’ve got a v2 coming shortly as I’ve bungled the
> author and codeveloped tag from our internal version of this patch.
> 
> I’ll get that out, but it will be the exact same code.
>

You can just put my reviewed by on that one when you send it then.


Cheers,
Phil



> > 
> > Cheers,
> > Phil
> > -- 
> > 
> 

-- 


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-11-14 19:14 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-14 16:21 [PATCH] sched: add READ_ONCE to task_on_rq_queued Jon Kohler
2024-11-14 18:52 ` Phil Auld
2024-11-14 18:59   ` Jon Kohler
2024-11-14 19:14     ` Phil Auld

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox