Skip to contentSkip to conversation

sched: add READ_ONCE to task_on_rq_queued

PATCH Superseded Jon Kohler 2 participants 4 messages Nov 14, 2024 Scheduler

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Jon Kohler

author
#0 lore raw

PATCH 1/1 sched: add READ_ONCE to task_on_rq_queued

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.

---
 kernel/sched/sched.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/sched/sched.h +1 -1
index c03b3d7b320e..dbbe5ce0dd96 100644
@@ -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)
Signature · 1 line
2.43.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 29 lines · 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.

---
 kernel/sched/sched.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/sched/sched.h +1 -1
index c03b3d7b320e..dbbe5ce0dd96 100644
@@ -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)
Signature · 1 line
2.43.0

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

Cheers,
Phil

author
#2 lore raw
Quoted 43 lines · Phil Auld

!-------------------------------------------------------------------|
CAUTION: External Email

|-------------------------------------------------------------------!

Quoted 29 lines · 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.

---
kernel/sched/sched.h | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
kernel/sched/sched.h +1 -1
index c03b3d7b320e..dbbe5ce0dd96 100644
@@ -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)
Signature · 1 line
2.43.0

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

Quoted 2 lines

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.

Quoted 5 lines

Cheers,
Phil

#3 lore raw
Quoted 43 lines · On Thu, Nov 14, 2024 at 06:59:14PM +0000 Jon Kohler wrote:
Quoted 43 lines · Phil Auld

!-------------------------------------------------------------------|
CAUTION: External Email

|-------------------------------------------------------------------!

Quoted 29 lines · 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.

---
kernel/sched/sched.h | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
kernel/sched/sched.h +1 -1
index c03b3d7b320e..dbbe5ce0dd96 100644
@@ -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)
Signature · 1 line
2.43.0

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

Quoted 8 lines
Quoted 2 lines

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

Quoted 6 lines
Quoted 5 lines

Cheers,
Phil