Linux real-time development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Mathieu Desnoyers" <mathieu.desnoyers@efficios.com>
Cc: linux-rt-devel@lists.linux.dev, tj@kernel.org,
	hannes@cmpxchg.org, mkoutny@suse.com,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v12 01/43] sched/deadline: Keep departing bandwidth across a root domain rebuild
Date: Fri, 27 Nov 2026 15:22:11 +0000	[thread overview]
Message-ID: <sashiko-outbox-237715@kernel.org> (raw)
In-Reply-To: <fca1ab7a541ea78376d27e327b472acff2ab6fb3.1795771147.git.mathieu.desnoyers@efficios.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] sched/deadline: departed bw misattributed in
  dl_clear_root_domains()
- [Medium] sched/deadline: departed bw not discounted under lock in
  sched_dl_overflow()
--

commit 11764f8fab5822dc0f850c6d21fd4579821bb933
Author: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>

sched/deadline: Keep departing bandwidth across a root domain rebuild

This commit tracks tasks that leave SCHED_DEADLINE or die before their
0-lag time on dl_departed_list with their departing CPU and a rebuild
generation counter, so root domain accounting rebuilds and the inactive
timer preserve and release their bandwidth in the original root domain.

> diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
> index fe6b12500b54b..c2b5b5fdf1b98 100644
> --- a/kernel/sched/deadline.c
> +++ b/kernel/sched/deadline.c

[ ... ]

> @@ -3643,9 +3778,51 @@ void dl_clear_root_domain(struct root_domain *rd)
>  		dl_server_add_bw(rd, i);
>  }
>  
> -void dl_clear_root_domain_cpu(int cpu)
> +/*
> + * Clear every root domain before a rebuild of their accounting, and count
> + * the rebuild in dl_bw_gen. Put back the bandwidth of their servers. Put
> + * back the bandwidth of the tasks on dl_departed_list, which no cpuset
> + * holds as deadline tasks. Put each in the root domain of the CPU
> + * recorded for it, or drop it if that CPU is not active.
> + * dl_add_task_root_domain() then adds the deadline tasks of the cpusets.
> + */
> +void dl_clear_root_domains(void)
>  {
> -	dl_clear_root_domain(cpu_rq(cpu)->rd);
> +	struct sched_dl_entity *dl_se;
> +	u64 cookie = ++dl_cookie;
> +	struct dl_bw *dl_b;
> +	int cpu;
> +
> +	guard(raw_spinlock_irqsave)(&dl_departed_lock);
> +	dl_bw_gen++;
> +	for_each_possible_cpu(cpu) {
> +		if (!dl_bw_visited(cpu, cookie))
> +			dl_clear_root_domain(cpu_rq(cpu)->rd);
> +	}
> +	list_for_each_entry(dl_se, &dl_departed_list, dl_departed_node) {
> +		cpu = dl_se->dl_departed_cpu;
> +		/*
> +		 * Skip bandwidth that an earlier rebuild dropped. It is not
> +		 * counted now, and its release removes nothing
> +		 * (dl_task_release_bw()).
> +		 */
> +		if (dl_se->dl_bw_gen != dl_bw_gen - 1)
> +			continue;
> +		/*
> +		 * Drop the bandwidth of a task whose CPU is inactive. A CPU
> +		 * that goes offline is in the default root domain by then.
> +		 * The root domain that counted the task cannot be found
> +		 * from the recorded number. The release then removes
> +		 * nothing, and no later rebuild restores it.
> +		 */
> +		if (!cpu_active(cpu))
> +			continue;
> +		dl_b = dl_bw_of(cpu);
> +		raw_spin_lock(&dl_b->lock);
> +		__dl_add(dl_b, dl_se->dl_bw, dl_bw_cpus(cpu));
> +		raw_spin_unlock(&dl_b->lock);
> +		dl_se->dl_bw_gen = dl_bw_gen;
> +	}
>  }

[Severity: Medium]
Can dl_clear_root_domains() charge departing bandwidth to the wrong root
domain and underflow cpu_rq(cpu)->dl.extra_bw when dl_departed_cpu is
moved into a new child cpuset partition root before the 0-lag timer
fires?

If two tasks in a 3-CPU top_cpuset (each with dl_bw = 0.6) depart while
running on CPU 2 and a new 1-CPU partition root is then created on CPU 2,
this loop adds both tasks' bandwidth (1.2 total) to the new 1-CPU root
domain via dl_bw_of(2).  That drops the departing bandwidth from
top_cpuset, blocks deadline admissions in the new partition with -EBUSY,
and subtracts 1.2 from cpu_rq(2)->dl.extra_bw (initialized to 0.95),
wrapping the unsigned u64 below zero.

Later commits in this series ("sched/deadline: Record the root domain
holding a task's bandwidth" and "sched/deadline: Make a rebuild count a
task in the root domain it runs in") check whether a partition root took
the recorded CPU for live deadline tasks, but leave dl_clear_root_domains()
and the departed branch of dl_add_task_root_domain() using
dl_departed_cpu unconditionally.

[ ... ]

> @@ -3963,8 +4156,6 @@ int sched_dl_overflow(struct task_struct *p, int policy,
>  
>  	if (dl_policy(policy) && !task_has_dl_policy(p) &&
>  	    !__dl_overflow(dl_b, cap, 0, new_bw)) {
> -		if (hrtimer_active(&p->dl.inactive_timer))
> -			__dl_sub(dl_b, p->dl.dl_bw, cpus);
>  		__dl_add(dl_b, new_bw, cpus);
>  		err = 0;
>  	} else if (dl_policy(policy) && task_has_dl_policy(p) &&
> @@ -3990,6 +4181,19 @@ int sched_dl_overflow(struct task_struct *p, int policy,
>  	}
>  	raw_spin_unlock(&dl_b->lock);
>  
> +	/*
> +	 * A task that comes back before its 0-lag time still has the
> +	 * bandwidth it left with. The new bandwidth replaces it, so remove the
> +	 * old one from the root domain that keeps it (dl_task_release_bw()).
> +	 * No rebuild can run meanwhile: the caller holds cpuset_mutex.
> +	 */
> +	if (!err && dl_policy(policy) && !task_has_dl_policy(p)) {
> +		lockdep_assert_cpuset_lock_held();
> +		if (p->dl.dl_departed_cpu >= 0)
> +			dl_task_release_bw(p, -1);
> +		p->dl.dl_bw_gen = dl_bw_gen;
> +	}
> +
>  	return err;
>  }

[Severity: Medium]
When a departed task returns to SCHED_DEADLINE in the same root domain
before its 0-lag timer fires, doesn't releasing p->dl.dl_bw after dropping
dl_b->lock transiently double-count the task's old and new bandwidth in
dl_b->total_bw and rq->dl.extra_bw?

Between raw_spin_unlock(&dl_b->lock) and dl_task_release_bw() taking
dl_b->lock again, both p->dl.dl_bw and new_bw are counted in dl_b, which
can cause concurrent sched_dl_global_validate() or
dl_server_apply_params() calls to fail with -EBUSY and transiently reduces
(or underflows when admission control is disabled) rq->dl.extra_bw read
by grub_reclaim().  In addition, __dl_overflow(dl_b, cap, 0, new_bw)
still checks admission with old_bw = 0 even when p->dl.dl_bw is already
counted in the same dl_b and about to be replaced, rejecting a task with
50% bandwidth in a 1-CPU partition root that switches to SCHED_OTHER and
back to SCHED_DEADLINE before its 0-lag time.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1795771147.git.mathieu.desnoyers@efficios.com?part=1

  reply	other threads:[~2026-11-27 15:22 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-27 14:35 [PATCH v12 00/43] sched/deadline: bandwidth accounting fixes and selftests Mathieu Desnoyers
2026-11-27 14:35 ` [PATCH v12 01/43] sched/deadline: Keep departing bandwidth across a root domain rebuild Mathieu Desnoyers
2026-11-27 15:22   ` sashiko-bot [this message]
2026-11-27 14:35 ` [PATCH v12 02/43] sched/deadline: Rebuild the root domains' accounting from the task list Mathieu Desnoyers
2026-11-27 14:35 ` [PATCH v12 03/43] sched/deadline: Record the root domain holding a task's bandwidth Mathieu Desnoyers
2026-11-27 14:35 ` [PATCH v12 04/43] sched/deadline: Leave a dying task out of a rebuild of the accounting Mathieu Desnoyers
2026-11-27 14:35 ` [PATCH v12 05/43] selftests/sched: Test SCHED_DEADLINE bandwidth across a root domain rebuild Mathieu Desnoyers
2026-11-27 15:16   ` sashiko-bot
2026-11-27 14:35 ` [PATCH v12 06/43] selftests/sched: Test the root domain rebuild in deadline_bw_test Mathieu Desnoyers
2026-11-27 14:35 ` [PATCH v12 07/43] sched/deadline: Move a task's bandwidth only where room was made Mathieu Desnoyers
2026-11-27 14:35 ` [PATCH v12 08/43] cgroup/cpuset: Wait for an attach before rebuilding the sched domains Mathieu Desnoyers
2026-11-27 14:35 ` [PATCH v12 09/43] sched: Make deadline policy and affinity changes wait for a cpuset attach Mathieu Desnoyers
2026-11-27 14:35 ` [PATCH v12 10/43] cgroup/cpuset: Give back the bandwidth an attach did not move Mathieu Desnoyers
2026-11-27 14:35 ` [PATCH v12 11/43] cgroup/cpuset: Reserve the bandwidth in the root domain a task moves to Mathieu Desnoyers
2026-11-27 14:35 ` [PATCH v12 12/43] selftests/sched: Test cpuset moves in deadline_bw_test Mathieu Desnoyers
2026-11-27 14:35 ` [PATCH v12 13/43] sched/deadline: Make a rebuild count a task in the root domain it runs in Mathieu Desnoyers
2026-11-27 14:35 ` [PATCH v12 14/43] sched/deadline: Move a task's bandwidth to " Mathieu Desnoyers
2026-11-27 14:35 ` [PATCH v12 15/43] sched/deadline: Keep a task in the root domain that counts its bandwidth Mathieu Desnoyers
2026-11-27 14:35 ` [PATCH v12 16/43] sched/deadline: Keep the last CPU a task has in its root domain Mathieu Desnoyers
2026-11-27 14:35 ` [PATCH v12 17/43] cgroup/cpuset: Refuse to take a deadline task out of " Mathieu Desnoyers
2026-11-27 14:35 ` [PATCH v12 18/43] selftests/sched: Test the root domain of a task in deadline_bw_test Mathieu Desnoyers
2026-11-27 14:35 ` [PATCH v12 19/43] sched/deadline: Count only active CPUs when spreading extra_bw Mathieu Desnoyers
2026-11-27 14:35 ` [PATCH v12 20/43] sched/deadline: Do not truncate a bandwidth to 32 bits in __dl_add/sub() Mathieu Desnoyers
2026-11-27 14:35 ` [PATCH v12 21/43] rtmutex: Continue the chain walk when a waiter's deadline donor changes Mathieu Desnoyers
2026-11-27 14:35 ` [PATCH v12 22/43] rtmutex: Do not stop the chain walk at an owner whose top waiter changed Mathieu Desnoyers
2026-11-27 14:35 ` [PATCH v12 23/43] sched/deadline: Hold a reference on the deadline donor of a boosted task Mathieu Desnoyers
2026-11-27 14:35 ` [PATCH v12 24/43] selftests/sched: Test the rtmutex chain walk in deadline_bw_test Mathieu Desnoyers
2026-11-27 14:35 ` [PATCH v12 25/43] sched/deadline: Count the 0-lag time from the next period Mathieu Desnoyers
2026-11-27 14:35 ` [PATCH v12 26/43] sched/deadline: Keep a departing constrained task until its " Mathieu Desnoyers
2026-11-27 14:35 ` [PATCH v12 27/43] sched/deadline: Replenish a throttled task boosted while asleep Mathieu Desnoyers
2026-11-27 14:35 ` [PATCH v12 28/43] sched/deadline: Restore the owner's period at a deboost in the class Mathieu Desnoyers
2026-11-27 14:35 ` [PATCH v12 29/43] sched/deadline: Count the bandwidth a boosted task is given Mathieu Desnoyers
2026-11-27 14:35 ` [PATCH v12 30/43] sched/deadline: Start a period for a task that enters the class blocked Mathieu Desnoyers
2026-11-27 14:35 ` [PATCH v12 31/43] sched/deadline: Restore the owner's period at a deboost out of the class Mathieu Desnoyers
2026-11-27 14:35 ` [PATCH v12 32/43] sched/deadline: Start a period for a task requeued onto an rt_mutex Mathieu Desnoyers
2026-11-27 14:36 ` [PATCH v12 33/43] selftests/sched: Test deadline boosts in deadline_bw_test Mathieu Desnoyers
2026-11-27 14:36 ` [PATCH v12 34/43] sched/deadline: Cancel the replenishment timer with the parameters Mathieu Desnoyers
2026-11-27 14:36 ` [PATCH v12 35/43] sched/deadline: Cap the runtime left of a constrained task at dl_runtime Mathieu Desnoyers
2026-11-27 14:36 ` [PATCH v12 36/43] sched/deadline: Check the runtime of a task that comes back runnable Mathieu Desnoyers
2026-11-27 14:36 ` [PATCH v12 37/43] sched/deadline: Keep the debt of a task across a change of parameters Mathieu Desnoyers
2026-11-27 14:36 ` [PATCH v12 38/43] sched/deadline: Boost an owner that cannot run on its own reservation Mathieu Desnoyers
2026-11-27 14:36 ` [PATCH v12 39/43] sched/deadline: Boost an owner throttled after its waiter blocked Mathieu Desnoyers
2026-11-27 14:36 ` [PATCH v12 40/43] sched/deadline: Reschedule a running task throttled at its enqueue Mathieu Desnoyers
2026-11-27 14:36 ` [PATCH v12 41/43] sched/deadline: Run a boost held at its first refill on a donor period Mathieu Desnoyers
2026-11-27 14:36 ` [PATCH v12 42/43] selftests/sched: Test parameter changes in deadline_bw_test Mathieu Desnoyers
2026-11-27 14:36 ` [PATCH v12 43/43] selftests/sched: Share the helpers of the deadline tests Mathieu Desnoyers

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-237715@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=hannes@cmpxchg.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rt-devel@lists.linux.dev \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=mkoutny@suse.com \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=tj@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox