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

From: sashiko-bot

Date: Thu Nov 19 2026 - 09:08:36 EST


Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] sched/deadline: dl_b->total_bw underflow in __dl_sub() on
inactive CPUs
--

commit 020d8b15e9dbdf61a1582bcfb9d8b730079aa6d8
Author: Mathieu Desnoyers <mathieu.desnoyers@xxxxxxxxxxxx>

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

This commit guards the __dl_update() calls in __dl_sub() and __dl_add()
against dividing by zero when a root domain has no active CPUs 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);
> }

[Severity: Medium]
Can updating dl_b->total_bw when the CPU is inactive underflow
def_root_domain.dl_bw.total_bw?

When a CPU is deactivated during hotplug, detach_destroy_domains() attaches
it to def_root_domain and dl_clear_root_domain() resets
def_root_domain.dl_bw.total_bw to 0, repopulating it only from active CPUs.
A SCHED_DEADLINE task on that CPU that exited or switched classes before
its 0-lag time is not accounted in def_root_domain, so when
inactive_task_timer() fires while task_cpu(p) is offline, __dl_sub()
subtracts p->dl.dl_bw from 0, wrapping the u64 total_bw counter and causing
__dl_overflow() and sched_dl_global_validate() on def_root_domain to reject
admissions with -EBUSY.

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