* [PATCH] sched: Preserve reset-on-fork across concurrent sched_setparam()
@ 2026-08-07 8:22 Andrea Righi
0 siblings, 0 replies; only message in thread
From: Andrea Righi @ 2026-08-07 8:22 UTC (permalink / raw)
To: Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot
Cc: Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
Valentin Schneider, K Prateek Nayak, linux-kernel
SCHED_RESET_ON_FORK prevents scheduling attributes from propagating to a
new child. The request is stored in p->sched_reset_on_fork; at fork
time, the scheduler uses it to reset inherited DL/RT policy, negative
nice values, custom slices and utilization clamps, then clears the flag
in the child.
sched_setparam() uses SETPARAM_POLICY to update scheduler parameters
while preserving both the current policy and the reset-on-fork setting.
However, __sched_setscheduler() samples p->sched_reset_on_fork before
acquiring the task's rq lock. A concurrent sched_setscheduler() can
change the flag after that snapshot and the lagging sched_setparam()
call can overwrite it with the stale value.
Remember when the caller requested to keep the policy and refresh
reset_on_fork after acquiring the rq lock. Both the early-exit and full
update paths then preserve the most recent serialized setting.
Fixes: ca94c442535a ("sched: Introduce SCHED_RESET_ON_FORK scheduling policy flag")
Reported-by: K Prateek Nayak <kprateek.nayak@amd.com>
Link: https://lore.kernel.org/eb62f13e-f9d4-4153-93ff-c144526f9a93@amd.com
Signed-off-by: Andrea Righi <arighi@nvidia.com>
---
kernel/sched/syscalls.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/kernel/sched/syscalls.c b/kernel/sched/syscalls.c
index 8fb8474d0a0ec..b149aeb2fd490 100644
--- a/kernel/sched/syscalls.c
+++ b/kernel/sched/syscalls.c
@@ -503,6 +503,7 @@ int __sched_setscheduler(struct task_struct *p,
int queue_flags = DEQUEUE_SAVE | DEQUEUE_MOVE | DEQUEUE_NOCLOCK;
struct rq *rq;
bool cpuset_locked = false;
+ bool keep_policy = policy < 0;
/* The pi code expects interrupts enabled */
BUG_ON(pi && in_interrupt());
@@ -571,6 +572,10 @@ int __sched_setscheduler(struct task_struct *p,
rq = task_rq_lock(p, &rf);
update_rq_clock(rq);
+ /* Preserve reset_on_fork changes made while the rq lock was not held. */
+ if (keep_policy)
+ reset_on_fork = p->sched_reset_on_fork;
+
/*
* Changing the policy of the stop threads its a very bad idea:
*/
--
2.55.0
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-08-07 8:22 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-08-07 8:22 [PATCH] sched: Preserve reset-on-fork across concurrent sched_setparam() Andrea Righi
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®