All of lore.kernel.org
 help / color / mirror / Atom feed
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>,
	Tejun Heo <tj@kernel.org>,
	Patrick Bellasi <patrick.bellasi@arm.com>,
	linux-kernel@vger.kernel.org
Subject: [PATCH v2] sched: Reject policy changes with SCHED_FLAG_KEEP_PARAMS
Date: Thu, 30 Jul 2026 15:58:58 +0200	[thread overview]
Message-ID: <20260730135858.2460751-1-arighi@nvidia.com> (raw)

SCHED_FLAG_KEEP_PARAMS prevents __sched_setscheduler() from applying the
requested scheduler parameters, policy and class. However, a different
requested policy can still trigger deadline bandwidth accounting and
scheduling class callbacks.

Reject policy changes with SCHED_FLAG_KEEP_PARAMS while holding the
task's rq lock. Also skip deadline bandwidth accounting and class
transition callbacks when the guarded scheduler update cannot apply the
corresponding changes.

This prevents deadline bandwidth from being accounted without changing
the task and avoids class callbacks when p->sched_class remains
unchanged.

Fixes: a509a7cd7974 ("sched/uclamp: Extend sched_setattr() to support utilization clamping")
Fixes: 637b0682821b ("sched: Fold sched_class::switch{ing,ed}_{to,from}() into the change pattern")
Suggested-by: Peter Zijlstra <peterz@infradead.org>
Cc: K Prateek Nayak <kprateek.nayak@amd.com>
Signed-off-by: Andrea Righi <arighi@nvidia.com>
---
Changes in v2:
 - Reject policy changes with SCHED_FLAG_KEEP_PARAMS (Peter Zijlstra)
 - Perform the policy check under the rq lock to avoid racing with a concurrent
   policy change
 - Link to v1: https://lore.kernel.org/all/20260730055011.2267333-1-arighi@nvidia.com/

 kernel/sched/syscalls.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/kernel/sched/syscalls.c b/kernel/sched/syscalls.c
index b215b0ead9a60..8fb8474d0a0ec 100644
--- a/kernel/sched/syscalls.c
+++ b/kernel/sched/syscalls.c
@@ -645,12 +645,19 @@ int __sched_setscheduler(struct task_struct *p,
 		goto recheck;
 	}
 
+	/* KEEP_PARAMS only makes sense if the scheduling policy is unchanged */
+	if ((attr->sched_flags & SCHED_FLAG_KEEP_PARAMS) && policy != p->policy) {
+		retval = -EINVAL;
+		goto unlock;
+	}
+
 	/*
 	 * If setscheduling to SCHED_DEADLINE (or changing the parameters
 	 * of a SCHED_DEADLINE task) we need to check if enough bandwidth
 	 * is available.
 	 */
-	if ((dl_policy(policy) || dl_task(p)) && sched_dl_overflow(p, policy, attr)) {
+	if (!(attr->sched_flags & SCHED_FLAG_KEEP_PARAMS) &&
+	    (dl_policy(policy) || dl_task(p)) && sched_dl_overflow(p, policy, attr)) {
 		retval = -EBUSY;
 		goto unlock;
 	}
@@ -675,7 +682,7 @@ int __sched_setscheduler(struct task_struct *p,
 	prev_class = p->sched_class;
 	next_class = __setscheduler_class(policy, newprio);
 
-	if (prev_class != next_class)
+	if (!(attr->sched_flags & SCHED_FLAG_KEEP_PARAMS) && prev_class != next_class)
 		queue_flags |= DEQUEUE_CLASS;
 
 	scoped_guard (sched_change, p, queue_flags) {
-- 
2.55.0


             reply	other threads:[~2026-07-30 13:59 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-30 13:58 Andrea Righi [this message]
2026-07-31  5:21 ` [PATCH v2] sched: Reject policy changes with SCHED_FLAG_KEEP_PARAMS K Prateek Nayak
2026-07-31 12:16   ` Andrea Righi

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=20260730135858.2460751-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=patrick.bellasi@arm.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=tj@kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.