[PATCH 04/15] sched: Skip class callbacks with SCHED_FLAG_KEEP_PARAMS

From: Andrea Righi

Date: Tue Jul 28 2026 - 12:51:03 EST


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 SCHED_FLAG_KEEP_PARAMS allows the class to
change. This also ensures that incoming-class preparation added by a
later change is only performed for an actual class transition.

Fixes: 637b0682821b ("sched: Fold sched_class::switch{ing,ed}_{to,from}() into the change pattern")
Signed-off-by: Andrea Righi <arighi@xxxxxxxxxx>
---
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;

scoped_guard (sched_change, p, queue_flags) {
--
2.55.0