Re: [PATCH 04/16] sched/deadline: Do not divide by zero active CPUs of a root domain

From: sashiko-bot

Date: Wed Nov 18 2026 - 15:23:31 EST


Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [High] sched/deadline: integer overflow in __dl_sub() and __dl_add()
[1]
--

commit 976d925f6742563bd97b6e12f465ca24230d49b8
Author: Mathieu Desnoyers <mathieu.desnoyers@xxxxxxxxxxxx>

sched/deadline: Do not divide by zero active CPUs of a root domain

This commit guards the extra_bw updates in __dl_sub() and __dl_add()
against a zero active CPU count in a root domain during CPU hotplug.

> diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
> index dfae08625342e..b614d5fc1a1ac 100644
> --- a/kernel/sched/deadline.c
> +++ b/kernel/sched/deadline.c
> @@ -189,18 +189,25 @@ void __dl_update(struct dl_bw *dl_b, s64 bw)
> }
> }
>
> +/*
> + * Spread a change of total_bw over the extra_bw of the active CPUs of the
> + * root domain. @cpus is their number. With no active CPU, as can happen
> + * during CPU hotplug, change total_bw alone.
> + */
> static inline
> void __dl_sub(struct dl_bw *dl_b, u64 tsk_bw, int cpus)
> {
> dl_b->total_bw -= tsk_bw;
> - __dl_update(dl_b, (s32)tsk_bw / cpus);
> + if (cpus)
> + __dl_update(dl_b, (s32)tsk_bw / cpus);
> }
>
> static inline
> void __dl_add(struct dl_bw *dl_b, u64 tsk_bw, int cpus)
> {
> dl_b->total_bw += tsk_bw;
> - __dl_update(dl_b, -((s32)tsk_bw / cpus));
> + if (cpus)
> + __dl_update(dl_b, -((s32)tsk_bw / cpus));
> }

[Severity: High]
This problem wasn't introduced by this patch, but can casting tsk_bw to
s32 in __dl_sub() and __dl_add() overflow and flip the sign [1]?

During a large cpuset bandwidth migration (cpuset_reserve_dl_bw() ->
dl_bw_alloc()), tsk_bw can exceed S32_MAX on systems with many CPUs.
Truncating tsk_bw to a negative s32 before dividing by cpus reverses the
sign of the delta passed to __dl_update(), corrupting per-runqueue
extra_bw accounting and breaking SCHED_DEADLINE admission control.

[1] https://sashiko.dev/#/bug/linux-ebf16093-b39b-4cd9-a580-85c7bb17302b

--
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1795031605.git.mathieu.desnoyers@xxxxxxxxxxxx?part=4