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

Message ID 20230612033505.8148-1-zegao@tencent.com
State New
Headers
Series sched_fork: Use READ_ONCE() for lockless read of current->normal_prio |

Commit Message

Ze Gao June 12, 2023, 3:35 a.m. UTC
  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.

Signed-off-by: Ze Gao <zegao@tencent.com>
---
 kernel/sched/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Patch

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 944c3ae39861..37a13e4b734d 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -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);