Re: [PATCH v6 27/37] sched/deadline: Keep the last CPU a task has in its root domain

From: sashiko-bot

Date: Mon Nov 16 2026 - 14:52:01 EST


Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] sched/deadline: missing affinity masks in
dl_task_leaves_span() fallback
- [Low] sched/deadline: dl_task_leaves_span() rejects CPU offline for
dead tasks
--

commit 48b62790717c3a90940a59e814da93b5ddf9ada9
Author: Mathieu Desnoyers <mathieu.desnoyers@xxxxxxxxxxxx>

sched/deadline: Keep the last CPU a task has in its root domain

This commit refuses to take a CPU offline with -EBUSY when doing so would
leave a deadline task with runnable CPUs only outside the root domain that
accounts for its bandwidth.

> diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
> index 5294546786f12..096c0ec55cdc2 100644
> --- a/kernel/sched/deadline.c
> +++ b/kernel/sched/deadline.c
> @@ -4896,9 +4896,63 @@ static int dl_bw_manage(enum dl_bw_request req, int cpu, u64 dl_bw)
> return overflow ? -EBUSY : 0;
> }
>
> +/*
> + * Return true if @p has CPUs to run on once @cpu is offline, but none in
> + * the root domain of @cpu, which counts its bandwidth.
> + */
> +static bool dl_task_leaves_span(struct task_struct *p, int cpu,
> + const struct cpumask *span)
> +{
> + struct cpumask *msk;
> +
> + guard(raw_spinlock_irqsave)(&p->pi_lock);
> + if (dl_task_bw_span(p) != span)
> + return false;
> + msk = this_cpu_cpumask_var_ptr(local_cpu_mask_dl);
> + cpumask_and(msk, p->cpus_ptr, cpu_active_mask);
> + cpumask_clear_cpu(cpu, msk);
> + /* With no CPU left, the cpuset gives @p the CPUs of an ancestor. */
> + if (cpumask_empty(msk))
> + cpuset_cpus_allowed_without(p, cpu, msk);
> + return !cpumask_empty(msk) && !cpumask_intersects(msk, span);
> +}

[Severity: Medium]
When msk is empty and dl_task_leaves_span() falls back to
cpuset_cpus_allowed_without(), does it also need to restrict the inherited
ancestor mask by p->user_cpus_ptr (when their intersection is non-empty)
and task_cpu_possible_mask(p)?

When the CPU goes offline, cpuset_update_tasks_cpumask() updates the task
via __set_cpus_allowed_ptr(), which intersects the new cpuset mask with
p->user_cpus_ptr if they overlap:

kernel/sched/core.c:__set_cpus_allowed_ptr() {
...
if (p->user_cpus_ptr &&
!(ctx->flags & (SCA_USER | SCA_MIGRATE_ENABLE | SCA_MIGRATE_DISABLE)) &&
cpumask_and(rq->scratch_mask, ctx->new_mask, p->user_cpus_ptr))
ctx->new_mask = rq->scratch_mask;
...
}

Suppose CPUs 0-1 are housekeeping CPUs in span and CPUs 2-3 are isolated
(isolcpus=domain,2,3), and a task with user_cpus_ptr = {0, 2, 3} is moved
into a child cpuset with cpuset.cpus = 0 under top_cpuset (0-3). Taking
CPU 0 offline leaves msk empty, so cpuset_cpus_allowed_without() returns
{1, 2, 3} from top_cpuset. Because dl_task_leaves_span() sees CPU 1 in
msk & span, it allows the offline, after which __set_cpus_allowed_ptr()
intersects {1, 2, 3} with user_cpus_ptr and restricts the task to {2, 3} in
the default root domain without an admission check.

In addition, the CONFIG_CPUSETS implementation of
cpuset_cpus_allowed_without() does not intersect cs->effective_cpus with
task_cpu_possible_mask(tsk), unlike guarantee_active_cpus() and the
!CONFIG_CPUSETS stub.

> +
> +/*
> + * Return true if @cpu is the last CPU that a deadline task can run on in
> + * the root domain that counts its bandwidth. With @cpu offline, the task
> + * would run in another root domain, which did not admit it. The mask of
> + * a task holds CPUs of two root domains only with isolcpus="domain".
> + *
> + * A suspend takes the CPUs offline with the tasks frozen, and the resume
> + * puts them back. Without admission control, there is no limit to exceed.
> + * Return false in both cases.
> + */
> +static bool dl_cpu_last_of_task(int cpu)
> +{
> + const struct cpumask *span;
> + struct task_struct *g, *p;
> +
> + if (cpuhp_tasks_frozen || !dl_bandwidth_enabled())
> + return false;
> + /* No task holds a bandwidth: do not walk the task list. */
> + if (!atomic_read(&dl_nr_bw_tasks))
> + return false;
> + guard(rcu)();
> + span = cpu_rq(cpu)->rd->span;
> + for_each_process_thread(g, p) {
> + if (task_has_dl_policy(p) && dl_task_leaves_span(p, cpu, span))
> + return true;
> + }

[Severity: Low]
Can this reject a CPU offline when p is an un-reaped exited task waiting for
its 0-lag timer?

When a deadline task exits before its 0-lag time, task_non_contending()
places it on dl_departed_list and arms inactive_timer while leaving
p->policy and p->dl.dl_bw_cpu set. Until release_task() unhashes the task
or inactive_timer fires, for_each_process_thread() still visits it and
dl_task_leaves_span() returns true if the outgoing CPU was its only CPU in
span, causing dl_bw_deactivate() to fail with -EBUSY even though a
TASK_DEAD task will never run again or move its bandwidth to another root
domain.

--
Sashiko AI review · https://sashiko.dev/#/patchset/20261116190549.230119-1-mathieu.desnoyers@xxxxxxxxxxxx?part=27