Skip to contentSkip to conversation

sched_fork: Use READ_ONCE() for lockless read of current->normal_prio

PATCH New Ze Gao 1 participant 1 message Jun 12, 2023 Scheduler

lore
Share & tools
lore

Ze Gao

author
#0 lore raw

PATCH 1/1 sched_fork: Use READ_ONCE() for lockless read of current->normal_prio

The current->normal_prio is locklessly accessed from sched_fork and child's scheduler related initialization procedures heavily rely on the value loaded. Thus we mark this load as READ_ONCE in case of possible load tearing due to concurrent access from other paths, for example if changes of parent's normal_prio happens to be requested via some syscall.

---
 kernel/sched/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/sched/core.c +1 -1
index 944c3ae39861..37a13e4b734d 100644
@@ -4699,7 +4699,7 @@ int sched_fork(unsigned long clone_flags, struct task_struct *p)
 	/*
 	 * Make sure we do not leak PI boosting priority to the child.
 	 */
-	p->prio = current->normal_prio;
+	p->prio = READ_ONCE(current->normal_prio);
 
 	uclamp_fork(p);
 
Signature · 1 line
2.40.1