mirror of https://lore.kernel.org/lkml/
 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 v3 20/24] sched/deadline: Count the bandwidth a boosted task is given
Date: Thu, 05 Nov 2026 21:13:35 +0000	[thread overview]
Message-ID: <sashiko-outbox-200204@kernel.org> (raw)
In-Reply-To: <20261105193359.1450487-21-mathieu.desnoyers@efficios.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] sched/deadline: uncounted bandwidth skipped in sched_dl_overflow()
--

commit 58e85ecec73a900cbca47b57215c8b485328d349
Author: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>

sched/deadline: Count the bandwidth a boosted task is given

This commit moves the runqueue bandwidth accounting update from
sched_dl_overflow() to __setparam_dl() so that tasks boosted into
SCHED_DEADLINE via priority inheritance have their new bandwidth added to
rq->dl.this_bw when their parameters are updated. It also charges new_bw when
dl_se->dl_bw_oncpu is not set and skips special SCHED_FLAG_SUGOV requests.

> diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
> index f772a944a3e53..746bffb03b7cb 100644
> --- a/kernel/sched/deadline.c
> +++ b/kernel/sched/deadline.c

[ ... ]

> @@ -4283,6 +4292,20 @@ int sched_dl_overflow(struct task_struct *p, int policy,
>  void __setparam_dl(struct task_struct *p, const struct sched_attr *attr)
>  {
>  	struct sched_dl_entity *dl_se = &p->dl;
> +	u64 period = attr->sched_period ?: attr->sched_deadline;
> +
> +	/*
> +	 * The bandwidth of a special entity is counted on no runqueue, and
> +	 * the request tells one, the flags of the entity being those of the
> +	 * parameters it had. The rest have theirs changed here, where their
> +	 * parameters are:
> +	 * switched_to_dl() hands it to the runqueue of a task that enters
> +	 * the class, and a task that priority inheritance boosted into the
> +	 * class is in it already, so nothing dequeues it and enqueues it
> +	 * back for that.
> +	 */
> +	if (!(attr->sched_flags & SCHED_FLAG_SUGOV))
> +		dl_change_utilization(p, to_ratio(period, attr->sched_runtime));

[Severity: High]
When a sugov kthread is given a reservation of its own via sched_setattr()
without SCHED_FLAG_SUGOV, or when a deadline task whose bandwidth was dropped
by a root domain rebuild updates its parameters, what happens if the new
runtime-to-period ratio matches the existing p->dl.dl_bw?

For example, sugov_kthread_create() initializes a sugov kthread with
SCHED_DEADLINE, SCHED_FLAG_SUGOV, sched_runtime = 1ms, and sched_period =
10ms. In sched_dl_overflow(), the SCHED_FLAG_SUGOV check returns 0 early,
leaving p->dl.dl_bw_cpu at -1 and not adding to dl_b->total_bw, while
__setparam_dl() still sets p->dl.dl_bw to to_ratio(10ms, 1ms).

If sched_setattr() is later called on that kthread without SCHED_FLAG_SUGOV
and with the same 1:10 ratio, dl_param_changed() returns true because the
flags changed, and __sched_setscheduler() calls sched_dl_overflow():

kernel/sched/deadline.c:sched_dl_overflow() {
	...
	/* !deadline task may carry old deadline bandwidth */
	if (new_bw == p->dl.dl_bw && task_has_dl_policy(p))
		return 0;

	counted = task_has_dl_policy(p) && p->dl.dl_bw_cpu >= 0 &&
		  p->dl.dl_bw_gen == dl_bw_gen;
	...
}

Because new_bw == p->dl.dl_bw && task_has_dl_policy(p) is checked before
counted, sched_dl_overflow() returns 0 early without running admission
control, adding new_bw to dl_b->total_bw, or setting p->dl.dl_bw_cpu.

__setparam_dl() then adds the bandwidth to rq->dl.this_bw via
dl_change_utilization() (or on enqueue if queued) and clears SCHED_FLAG_SUGOV
from p->dl.flags while p->dl.dl_bw_cpu remains -1. If the task later exits or
leaves SCHED_DEADLINE, dl_task_release_bw() hits:

kernel/sched/deadline.c:dl_task_release_bw() {
	...
	cpu = dl_se->dl_bw_cpu;
	WARN_ON_ONCE(dl_se->dl_bw && cpu < 0);
	if (cpu < 0 || dl_se->dl_bw_gen != dl_bw_gen)
		return;
	...
}

The same early return in sched_dl_overflow() also skips restoring root domain
bandwidth when a task whose bandwidth was dropped by a root domain rebuild
(p->dl.dl_bw_gen != dl_bw_gen) changes its deadline or flags while keeping
new_bw == p->dl.dl_bw.

Should the early return in sched_dl_overflow() require counted to be true
before skipping the root domain update when new_bw == p->dl.dl_bw?

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

  reply	other threads:[~2026-11-05 21:13 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-05 19:33 [PATCH v3 00/24] sched/deadline: bandwidth accounting fixes and selftests Mathieu Desnoyers
2026-11-05 19:33 ` [PATCH v3 01/24] sched: Fix cpuset_mutex double unlock in __sched_setscheduler() Mathieu Desnoyers
2026-11-05 19:51   ` Kayra Cizmeci
2026-11-05 19:54     ` Mathieu Desnoyers
2026-11-05 19:59       ` Mathieu Desnoyers
2026-11-05 19:33 ` [PATCH v3 02/24] sched: Refuse SCHED_FLAG_KEEP_PARAMS that would change the policy or the class Mathieu Desnoyers
2026-11-05 19:33 ` [PATCH v3 03/24] sched/deadline: Do not admit bandwidth for parameters that are kept Mathieu Desnoyers
2026-11-05 19:33 ` [PATCH v3 04/24] sched/deadline: Do not divide by zero active CPUs of a root domain Mathieu Desnoyers
2026-11-05 19:59   ` sashiko-bot
2026-11-05 19:33 ` [PATCH v3 05/24] sched: Take cpuset_mutex for a deadline policy change only with pi Mathieu Desnoyers
2026-11-05 19:33 ` [PATCH v3 06/24] sched/deadline: Do not lose a throttled task switched out and back Mathieu Desnoyers
2026-11-05 19:33 ` [PATCH v3 07/24] sched/deadline: Reset the deadline and the runtime with the parameters Mathieu Desnoyers
2026-11-05 19:33 ` [PATCH v3 08/24] sched/deadline: Release the bandwidth of a task that leaves the class asleep Mathieu Desnoyers
2026-11-05 20:10   ` sashiko-bot
2026-11-05 19:33 ` [PATCH v3 09/24] sched/deadline: Reject SCHED_DEADLINE on exited tasks Mathieu Desnoyers
2026-11-05 19:33 ` [PATCH v3 10/24] sched/deadline: Keep departing bandwidth across a root domain rebuild Mathieu Desnoyers
2026-11-05 19:33 ` [PATCH v3 11/24] sched/deadline: Do not take a waking task's bandwidth off a runqueue it left Mathieu Desnoyers
2026-11-05 20:35   ` sashiko-bot
2026-11-05 19:33 ` [PATCH v3 12/24] sched/deadline: Rebuild the root domains' accounting without cpusets too Mathieu Desnoyers
2026-11-05 19:33 ` [PATCH v3 13/24] sched/deadline: Leave a dying task out of a rebuild of the accounting Mathieu Desnoyers
2026-11-05 19:33 ` [PATCH v3 14/24] sched/deadline: Record the root domain holding a task's bandwidth Mathieu Desnoyers
2026-11-05 20:50   ` sashiko-bot
2026-11-05 19:33 ` [PATCH v3 15/24] sched/deadline: Move a task's bandwidth only where room was made Mathieu Desnoyers
2026-11-05 19:33 ` [PATCH v3 16/24] cgroup/cpuset: Wait for an attach before rebuilding the sched domains Mathieu Desnoyers
2026-11-05 20:36   ` sashiko-bot
2026-11-05 19:33 ` [PATCH v3 17/24] cgroup/cpuset: Give back the bandwidth an attach did not move Mathieu Desnoyers
2026-11-05 19:33 ` [PATCH v3 18/24] sched/deadline: Credit a rebuild to the CPU recorded with the task's bandwidth Mathieu Desnoyers
2026-11-05 20:58   ` sashiko-bot
2026-11-05 19:33 ` [PATCH v3 19/24] sched/deadline: Cancel the replenishment timer with the parameters Mathieu Desnoyers
2026-11-05 21:05   ` sashiko-bot
2026-11-05 19:33 ` [PATCH v3 20/24] sched/deadline: Count the bandwidth a boosted task is given Mathieu Desnoyers
2026-11-05 21:13   ` sashiko-bot [this message]
2026-11-05 19:33 ` [PATCH v3 21/24] sched/debug: Show the deadline bandwidth of each runqueue Mathieu Desnoyers
2026-11-05 19:33 ` [PATCH v3 22/24] selftests/sched: Add a test of SCHED_DEADLINE policy round trips Mathieu Desnoyers
2026-11-05 19:33 ` [PATCH v3 23/24] selftests/sched: Test SCHED_DEADLINE bandwidth across a root domain rebuild Mathieu Desnoyers
2026-11-05 19:33 ` [PATCH v3 24/24] selftests/sched: Add a test of SCHED_DEADLINE bandwidth accounting Mathieu Desnoyers
2026-11-05 21:17   ` sashiko-bot
2026-11-05 21:20 ` [PATCH v3 00/24] sched/deadline: bandwidth accounting fixes and selftests 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-200204@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

all inboxes | Powered by JetHome®