Re: [PATCH 12/16] sched/deadline: Fix this_bw when a task is changed during a remote wakeup
From: sashiko-bot
Date: Wed Nov 18 2026 - 15:47:04 EST
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] sched/deadline: this_bw desync in add_rq_bw() for PI-boosted
tasks
--
commit 31f5271550e5299348b26e477800f7ac60f7e6c1
Author: Mathieu Desnoyers <mathieu.desnoyers@xxxxxxxxxxxx>
sched/deadline: Fix this_bw when a task is changed during a remote wakeup
This commit introduces a dl_bw_oncpu bit in struct sched_dl_entity to track
whether a runqueue's this_bw currently accounts for the task's bandwidth,
preventing bandwidth drift when parameters change during a remote wakeup.
> diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
> index f0e03f97fd82f..c36516210669d 100644
> --- a/kernel/sched/deadline.c
> +++ b/kernel/sched/deadline.c
> @@ -267,18 +267,35 @@ void __sub_rq_bw(u64 dl_bw, struct dl_rq *dl_rq)
> WARN_ON_ONCE(dl_rq->running_bw > dl_rq->this_bw);
> }
>
> +/*
> + * @dl_se->dl_bw_oncpu tells whether the this_bw of a runqueue counts the
> + * bandwidth of @dl_se. add_rq_bw() adds the bandwidth only if no runqueue
> + * counts it. sub_rq_bw() subtracts it only if one does.
> + *
> + * A wakeup on another CPU takes the bandwidth off the old runqueue. The
> + * enqueue on the new CPU adds it back later. A change of the task in
> + * between must not count the bandwidth twice, nor take it off a runqueue
> + * that does not count it.
> + *
> + * The servers track their bandwidth with dl_bw_attached. They call
> + * __add_rq_bw() and __sub_rq_bw() directly.
> + */
> static inline
> void add_rq_bw(struct sched_dl_entity *dl_se, struct dl_rq *dl_rq)
> {
> - if (!dl_entity_is_special(dl_se))
> - __add_rq_bw(dl_se->dl_bw, dl_rq);
> + if (dl_entity_is_special(dl_se) || dl_se->dl_bw_oncpu)
> + return;
> + __add_rq_bw(dl_se->dl_bw, dl_rq);
> + dl_se->dl_bw_oncpu = 1;
> }
[Severity: Medium]
Can add_rq_bw() set dl_bw_oncpu = 1 while dl_se->dl_bw is 0 for a PI-boosted
non-deadline task, causing dl_rq->this_bw to miss a later SCHED_DEADLINE
bandwidth assignment?
When a non-deadline task (dl_runtime == 0, dl_bw == 0) is PI-boosted into
dl_sched_class via rt_mutex_setprio(), enqueue_dl_entity(ENQUEUE_RESTORE) or
switched_to_dl() calls add_rq_bw(), which adds 0 to this_bw and sets
dl_bw_oncpu = 1.
If sched_setattr() assigns SCHED_DEADLINE with new_bw > 0 while the boosted
task is unqueued (either sleeping or on a remote wake_list), prev_class and
next_class are both &dl_sched_class so ENQUEUE_CLASS is not set, and
!task_has_dl_policy(p) is true so sched_dl_overflow() skips
dl_change_utilization(). __setparam_dl() then sets p->dl.dl_bw = new_bw
while dl_bw_oncpu is already 1 and this_bw still has 0.
When the task finishes waking up, task_contending() calls add_rq_bw(), which
returns early because dl_bw_oncpu is 1, and then add_running_bw() adds new_bw
to running_bw, triggering WARN_ON_ONCE(dl_rq->running_bw > dl_rq->this_bw).
When the task later migrates, leaves SCHED_DEADLINE, or exits, sub_rq_bw()
subtracts new_bw and underflows this_bw. Should add_rq_bw() also return
early when !dl_se->dl_bw (or !dl_se->dl_runtime)?
--
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1795031605.git.mathieu.desnoyers@xxxxxxxxxxxx?part=12