From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 667823F12EC for ; Thu, 30 Jul 2026 09:57:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.92.199 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785405468; cv=none; b=O95GAWt+vZGNbkY9A9SgyY14DVjZftgGfGP43alMVDybnWM+Som0UaR1J7ZDV13TBERnqFunM8XYu0o8VtDFtgE7CaWdno7xYXXDNQyvnYeU/6jY4PqNxxhxw0HVmER7sehax+2eBMrE/GM7kjbGvAU5tu6+UryWLjmi6T9pC5E= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785405468; c=relaxed/simple; bh=2moOFjBYWVpZwcPaMZs7Ss9vlHlFM66ScNriCUEZSC0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=lty3zSUm76vBeAO462d+K/EALUY8qctRk9hOArVW6hbZdZPD0hXxEUvPpcs4x6pUQ1AbcT4DJbommceWJQnsdKgk0LKQt2/CXUx38qnvAUTEvqQKwnorCmr9X0AMbDtY0Gohe3oFkJDcvyMS3o/r9tI+j4R3hf777snq0OXAHoU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org; spf=pass smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=Be8sd42s; arc=none smtp.client-ip=90.155.92.199 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="Be8sd42s" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=f94Q0QrlVh2mbJli3STG5EsIS69nh+1L2mE8RQpBGN8=; b=Be8sd42s/qy/MRRIdF/bH1pKcL yl4XQrQl2kPbVp2px3nntcbmE3UFgxoD2JLH7uzB4Co5H6BVzTgMoUIMXY7YJaLWrvJq5e+YFN0KS BzMGK75jibDb4jhUrCuZ/Ql56LQ0ZWQzEnAbDgwLb51Kb7b+HfroTpzweI0USd60htqj/hIqTNm/N aht41X9fBZOH9K/aUqXfCUQb6AQiEnFJokrFBAhiI9FeP286D24HmVIHsiuhaKpB8KC2ZtbaqkRny /yt6Ztrnz6ZeXCF44LZx9Moo5+2wfBOP5NratsFK/cYYvUaPyF3cHo1TO+iMnNecHHffL3Vxy8RsL uPy3sX5A==; Received: from 77-249-17-252.cable.dynamic.v4.ziggo.nl ([77.249.17.252] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.99.2 #2 (Red Hat Linux)) id 1wpNWE-00000006Yei-45eL; Thu, 30 Jul 2026 09:57:39 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id 02FDA30095A; Thu, 30 Jul 2026 11:57:38 +0200 (CEST) Date: Thu, 30 Jul 2026 11:57:37 +0200 From: Peter Zijlstra To: K Prateek Nayak Cc: Andrea Righi , Ingo Molnar , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider , Tejun Heo , Patrick Bellasi , linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/2] sched: Skip class callbacks with SCHED_FLAG_KEEP_PARAMS Message-ID: <20260730095737.GO49951@noisy.programming.kicks-ass.net> References: <20260730055011.2267333-1-arighi@nvidia.com> <20260730055011.2267333-2-arighi@nvidia.com> <93830a3d-c85e-4aee-b293-b9fbbdbf61dc@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <93830a3d-c85e-4aee-b293-b9fbbdbf61dc@amd.com> On Thu, Jul 30, 2026 at 12:59:37PM +0530, K Prateek Nayak wrote: > Hello Andrea, > > On 7/30/2026 11:20 AM, Andrea Righi wrote: > > SCHED_FLAG_KEEP_PARAMS suppresses scheduler parameter and class changes, > > but __sched_setscheduler() can still set DEQUEUE_CLASS when the class > > computed from the requested policy differs from the task's current > > class. > > > > This causes the switching_from(), switched_from(), switching_to() and > > switched_to() callbacks to run even though p->sched_class remains > > unchanged. > > > > Set DEQUEUE_CLASS only when the sched class is allowed to change. > > > > Fixes: 637b0682821b ("sched: Fold sched_class::switch{ing,ed}_{to,from}() into the change pattern") > > Signed-off-by: Andrea Righi > > --- > > kernel/sched/syscalls.c | 3 ++- > > 1 file changed, 2 insertions(+), 1 deletion(-) > > > > diff --git a/kernel/sched/syscalls.c b/kernel/sched/syscalls.c > > index b215b0ead9a60..903b47f5d0b74 100644 > > --- a/kernel/sched/syscalls.c > > +++ b/kernel/sched/syscalls.c > > @@ -675,7 +675,8 @@ 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; > > It seems there also exists a SCHED_FLAG_KEEP_POLICY which should be used > to retain the policy. By a quick look at the syscall path, > SCHED_FLAG_KEEP_PARAMS should just do an equivalent of: > > get_params(p, &attr, 0) > > and match the some properties of sched_attr with that of the task. > > The task is still free to switch classes if the attr->sched_policy > differs given SCHED_FLAG_KEEP_PARAMS and SCHED_FLAG_KEEP_POLICY are two > distinct flags and there is a separate SCHED_FLAG_KEEP_ALL to combines > them both. > > I'm having a sneaky suspicion that the bit in sched_change guard below > should actually check for SCHED_FLAG_KEEP_ALL like: > > diff --git a/kernel/sched/syscalls.c b/kernel/sched/syscalls.c > index b215b0ead9a6..baf1fc59069e 100644 > --- a/kernel/sched/syscalls.c > +++ b/kernel/sched/syscalls.c > @@ -680,7 +680,7 @@ int __sched_setscheduler(struct task_struct *p, > > scoped_guard (sched_change, p, queue_flags) { > > - if (!(attr->sched_flags & SCHED_FLAG_KEEP_PARAMS)) { > + if ((attr->sched_flags & SCHED_FLAG_KEEP_ALL) != SCHED_FLAG_KEEP_ALL) { > __setscheduler_params(p, attr); > p->sched_class = next_class; > p->prio = newprio; Hmm, but if we have KEEP_PARAMS then params are loaded with the current set and actually re-setting them doesn't matter. So perhaps we should just remove that conditional entirely? --- diff --git a/kernel/sched/syscalls.c b/kernel/sched/syscalls.c index b215b0ead9a6..1893938c76db 100644 --- a/kernel/sched/syscalls.c +++ b/kernel/sched/syscalls.c @@ -680,12 +680,10 @@ int __sched_setscheduler(struct task_struct *p, scoped_guard (sched_change, p, queue_flags) { - if (!(attr->sched_flags & SCHED_FLAG_KEEP_PARAMS)) { - __setscheduler_params(p, attr); - p->sched_class = next_class; - p->prio = newprio; - __setscheduler_dl_pi(newprio, policy, p, scope); - } + __setscheduler_params(p, attr); + p->sched_class = next_class; + p->prio = newprio; + __setscheduler_dl_pi(newprio, policy, p, scope); __setscheduler_uclamp(p, attr); if (scope->queued) { @@ -979,8 +977,11 @@ SYSCALL_DEFINE3(sched_setattr, pid_t, pid, struct sched_attr __user *, uattr, if (!p) return -ESRCH; - if (attr.sched_flags & SCHED_FLAG_KEEP_PARAMS) + if (attr.sched_flags & SCHED_FLAG_KEEP_PARAMS) { + if (attr.sched_policy != SETPARAM_POLICY && attr.sched_policy != p->policy) + return -EINVAL; get_params(p, &attr, 0); + } return sched_setattr(p, &attr); }