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

[email protected] Tue, 28 Jul 2026 16:03:52 +0000
Newsgroups dev.linux.lists.sched-ext
Message-ID <[email protected]>
Thank you for your contribution! Sashiko AI review found 1 potential issue(=
s) to consider:

Pre-existing issues:
- [High] Using SCHED_FLAG_KEEP_PARAMS with a new SCHED_DEADLINE policy on a=
 non-deadline task causes a permanent deadline bandwidth leak in the root d=
omain.
--

--- Patch [4]: [PATCH 04/15] sched: Skip class callbacks with SCHED_FLAG_KE=
EP_PARAMS ---
commit 7456fab35f0046cf8daada3381577cde13d7dbe1
Author: Andrea Righi <[email protected]>

sched: Skip class callbacks with SCHED_FLAG_KEEP_PARAMS

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 commit sets DEQUEUE_CLASS only when SCHED_FLAG_KEEP_PARAMS allows
the class to change.

> 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 =3D p->sched_class;
>  	next_class =3D __setscheduler_class(policy, newprio);
> =20
> -	if (prev_class !=3D next_class)
> +	if (!(attr->sched_flags & SCHED_FLAG_KEEP_PARAMS) &&
> +	    prev_class !=3D next_class)
>  		queue_flags |=3D DEQUEUE_CLASS;
> =20
>  	scoped_guard (sched_change, p, queue_flags) {

[Severity: High]
This is a pre-existing issue and was not introduced by the patch under revi=
ew,
but does using SCHED_FLAG_KEEP_PARAMS with a new SCHED_DEADLINE policy on a
non-deadline task cause a permanent deadline bandwidth leak in the root
domain?

When a user with CAP_SYS_NICE calls sched_setattr() with
attr.sched_policy =3D SCHED_DEADLINE and SCHED_FLAG_KEEP_PARAMS on a
non-deadline task, sys_sched_setattr() fetches the current parameters:

sys_sched_setattr()
    if (attr.sched_flags & SCHED_FLAG_KEEP_PARAMS)
        get_params(p, &attr, 0);

This can replace attr.sched_runtime with the task's current fair slice while
leaving attr.sched_period user-provided, constructing a valid deadline rati=
o.

Earlier in __sched_setscheduler(), this requested bandwidth is validated and
permanently added to the global root domain accounting via __dl_add() inside
sched_dl_overflow():

    if ((dl_policy(policy) || dl_task(p)) && sched_dl_overflow(p, policy, a=
ttr)) {

However, because SCHED_FLAG_KEEP_PARAMS is set, the parameter and class
transition is skipped further down inside the scoped_guard block:

    if (!(attr->sched_flags & SCHED_FLAG_KEEP_PARAMS)) {
        __setscheduler_params(p, attr);
        p->sched_class =3D next_class;
        p->prio =3D newprio;
        __setscheduler_dl_pi(newprio, policy, p, scope);
    }

Since the task remains non-deadline and p->dl.dl_bw remains 0, when the task
eventually exits, it will subtract its dl_bw (0) instead of the allocated
bandwidth, leaving the globally added bandwidth permanently leaked.

Is there a way to prevent sched_dl_overflow() from allocating bandwidth if =
we
know SCHED_FLAG_KEEP_PARAMS will skip the parameter updates?

--=20
Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20260728154425.1549=
[email protected]?part=3D4