From: Andrea Righi <arighi@nvidia.com>
To: Ingo Molnar <mingo@redhat.com>,
Peter Zijlstra <peterz@infradead.org>,
Juri Lelli <juri.lelli@redhat.com>,
Vincent Guittot <vincent.guittot@linaro.org>
Cc: Dietmar Eggemann <dietmar.eggemann@arm.com>,
Steven Rostedt <rostedt@goodmis.org>,
Ben Segall <bsegall@google.com>, Mel Gorman <mgorman@suse.de>,
Valentin Schneider <vschneid@redhat.com>,
K Prateek Nayak <kprateek.nayak@amd.com>,
linux-kernel@vger.kernel.org
Subject: [PATCH] sched: Preserve reset-on-fork across concurrent sched_setparam()
Date: Fri, 7 Aug 2026 10:22:36 +0200 [thread overview]
Message-ID: <20260807082236.1076967-1-arighi@nvidia.com> (raw)
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
reply other threads:[~2026-08-07 8:22 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260807082236.1076967-1-arighi@nvidia.com \
--to=arighi@nvidia.com \
--cc=bsegall@google.com \
--cc=dietmar.eggemann@arm.com \
--cc=juri.lelli@redhat.com \
--cc=kprateek.nayak@amd.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mgorman@suse.de \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=vincent.guittot@linaro.org \
--cc=vschneid@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®