All of lore.kernel.org
 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 v8 32/33] sched/deadline: Check the runtime of a task whose parameters change
Date: Thu, 19 Nov 2026 20:59:05 +0000	[thread overview]
Message-ID: <sashiko-outbox-224081@kernel.org> (raw)
In-Reply-To: <efcd611a473f0da0161243c58f4af7c7ca73e2ba.1795116791.git.mathieu.desnoyers@efficios.com>

Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [Medium] sched/deadline: dl_deboost() skips dl_check_constrained_dl()
  and sleep check
- [Medium] sched/deadline: __setparam_dl() skips dl_new_params on
  boosted policy re-entry
- [Medium] sched/deadline: stale deadline in rt_mutex_adjust_pi() on
  blocked param change
- [Medium] sched/deadline: missing PI boost when update_dl_entity()
  pushes owner deadline
--

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

sched/deadline: Check the runtime of a task whose parameters change

This commit marks deadline tasks whose runtime, deadline, or period
changes in __setparam_dl() and runs update_dl_entity() on the next
unboosted enqueue or upon deboost in dl_deboost().

> diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
> index 7ed2f525b883e..2849484428c60 100644
> --- a/kernel/sched/deadline.c
> +++ b/kernel/sched/deadline.c
[ ... ]
> @@ -130,6 +136,12 @@ void dl_deboost(struct sched_dl_entity *dl_se)
>  	if (dl_se->dl_donor_refill)
>  		dl_start_own_period(dl_se);
>  	dl_drop_boost(dl_se);
> +
> +	if (dl_se->dl_new_params) {
> +		dl_se->dl_new_params = 0;
> +		if (!dl_se->dl_throttled)
> +			update_dl_entity(dl_se);
> +	}
>  }

[Severity: Medium]
Does calling update_dl_entity() directly from dl_deboost() bypass
dl_check_constrained_dl() and update sleeping tasks prematurely?

In enqueue_dl_entity(), dl_check_constrained_dl() runs before
update_dl_entity() so a constrained task (!dl_is_implicit(dl_se)) with
dl_se->deadline < rq_clock(rq) < dl_next_period(dl_se) is throttled until
its next period.  Because rt_mutex_setprio() calls dl_deboost() before
sched_change_end() enqueues the task, update_dl_entity() sees
dl_time_before(dl_se->deadline, rq_clock(rq)) and immediately starts a new
period via replenish_dl_new_period(), moving dl_se->deadline into the
future before enqueue_dl_entity() can throttle it.

In addition, if the lock owner is sleeping on a non-PI wait when a donor
times out or is interrupted (!task_on_rq_queued(p) &&
!dl_task_pi_blocked(p)), dl_deboost() clears dl_new_params and starts a
new period while the task is still asleep rather than waiting for its
wakeup enqueue.

[ ... ]

> @@ -2913,12 +2934,13 @@ enqueue_dl_entity(struct sched_dl_entity *dl_se, int flags)
>  		update_dl_entity(dl_se);
>  	} else if (flags & ENQUEUE_REPLENISH) {
>  		replenish_dl_entity(dl_se);
> -	} else if ((flags & ENQUEUE_CLASS) && !is_dl_boosted(dl_se)) {
> +	} else if (((flags & ENQUEUE_CLASS) || new_params) &&
> +		   !is_dl_boosted(dl_se)) {
>  		/*
> -		 * The task enters the class runnable. It may come back before
> -		 * its deadline, with the runtime left from older parameters.
> -		 * Check that runtime against the new parameters, as a wakeup
> -		 * does.
> +		 * The task enters the class, or its parameters change, while
> +		 * it is runnable. It may have runtime left from older
> +		 * parameters. Check that runtime against the new parameters,
> +		 * as a wakeup does.
>  		 */
>  		update_dl_entity(dl_se);
>  	} else if ((flags & ENQUEUE_MOVE) &&

[Severity: Medium]
Can an unboosted SCHED_DEADLINE lock owner miss a required PI boost when
update_dl_entity() pushes its deadline past its top waiter's deadline?

Suppose a SCHED_DEADLINE task p holds an rt_mutex with a SCHED_DEADLINE
waiter whose deadline is later than p->dl.deadline, so p is not boosted.
When sched_setattr() shrinks p's reservation, __setscheduler_dl_pi() runs
before sched_change_end() and only checks !dl_policy(policy).  Then
enqueue_dl_entity() calls update_dl_entity(), which starts a new period
and advances p->dl.deadline past the waiter's deadline.  Unlike
rt_mutex_setprio(), which rechecks dl_entity_preempt(&pi_task->dl, &p->dl)
after dl_deboost(), __sched_setscheduler() never compares p's new deadline
against rt_mutex_get_top_task(p), leaving p unboosted and allowing it to
be throttled on its reduced runtime while holding the lock.

[ ... ]

> @@ -4971,6 +4993,11 @@ void __setparam_dl(struct task_struct *p, const struct sched_attr *attr)
>  	u64 period = attr->sched_period ?: attr->sched_deadline;
>  	bool held;
>  
> +	if (attr->sched_runtime != dl_se->dl_runtime ||
> +	    attr->sched_deadline != dl_se->dl_deadline ||
> +	    period != dl_se->dl_period)
> +		dl_se->dl_new_params = 1;
> +
>  	/*
>  	 * Change the bandwidth that the runqueue counts here, with the
>  	 * parameters. A task that priority inheritance boosted into the

[Severity: Medium]
Does __setparam_dl() leave dl_new_params unset when a task leaves
SCHED_DEADLINE and re-enters with the same parameters while PI-boosted?

When a SCHED_DEADLINE task switches to another policy while PI-boosted (or
switches before its 0-lag time and is then PI-boosted back into
dl_sched_class, where switched_to_dl() cancels inactive_timer), its old
dl_runtime, dl_deadline, dl_period, runtime, and deadline remain in p->dl.
If the task still has positive runtime so replenish_dl_entity() does not
set dl_donor_refill, and sched_setattr() switches it back to
SCHED_DEADLINE with identical parameters while still boosted, prev_class
and next_class are both &dl_sched_class (so ENQUEUE_CLASS is not set) and
the parameter comparison above is false.  At deboost, dl_deboost() sees
both dl_donor_refill == 0 and dl_new_params == 0 and skips
update_dl_entity(), letting the task consume its old leftover runtime
before the old deadline.

[Severity: Medium]
When sched_setattr() shrinks the parameters of an unboosted task blocked
on an rt_mutex, does rt_mutex_adjust_pi() use a stale p->dl.deadline?

For a task blocked waiting on an rt_mutex (dl_task_pi_blocked(p) is true
and task_on_rq_queued(p) is false), sched_change_end() does not call
enqueue_task_dl(); prio_changed_dl() returns early because the task is not
queued, and switched_to_dl() only replenishes when p->dl.deadline is
already in the past:

kernel/sched/deadline.c:switched_to_dl() {
	...
		if (dl_task_pi_blocked(p) && !p->dl.dl_throttled &&
		    dl_time_before(p->dl.deadline, rq_clock(rq)))
			replenish_dl_new_period(&p->dl, rq);
	...
}

When __sched_setscheduler() then calls rt_mutex_adjust_pi(p),
dl_new_params is still pending and update_dl_entity() has not run, so an
overflowing remaining runtime does not advance p->dl.deadline to a new
period before the waiter tree and lock owner boost are updated.

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

  reply	other threads:[~2026-11-19 20:59 UTC|newest]

Thread overview: 57+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-19 20:15 [PATCH v8 00/33] sched/deadline: bandwidth accounting fixes and selftests Mathieu Desnoyers
2026-11-19 20:15 ` [PATCH v8 01/33] sched/deadline: Keep departing bandwidth across a root domain rebuild Mathieu Desnoyers
2026-11-19 20:15 ` [PATCH v8 02/33] sched/deadline: Rebuild the root domains' accounting from the task list Mathieu Desnoyers
2026-11-19 20:15 ` [PATCH v8 03/33] sched/deadline: Record the root domain holding a task's bandwidth Mathieu Desnoyers
2026-11-19 20:51   ` sashiko-bot
2026-11-20 13:48     ` Mathieu Desnoyers
2026-11-19 20:15 ` [PATCH v8 04/33] sched/deadline: Leave a dying task out of a rebuild of the accounting Mathieu Desnoyers
2026-11-19 20:15 ` [PATCH v8 05/33] selftests/sched: Test SCHED_DEADLINE bandwidth across a root domain rebuild Mathieu Desnoyers
2026-11-19 20:28   ` sashiko-bot
2026-11-20 13:49     ` Mathieu Desnoyers
2026-11-19 20:15 ` [PATCH v8 06/33] selftests/sched: Test the root domain rebuild in deadline_bw_test Mathieu Desnoyers
2026-11-19 20:15 ` [PATCH v8 07/33] sched/deadline: Move a task's bandwidth only where room was made Mathieu Desnoyers
2026-11-19 20:15 ` [PATCH v8 08/33] cgroup/cpuset: Wait for an attach before rebuilding the sched domains Mathieu Desnoyers
2026-11-19 20:15 ` [PATCH v8 09/33] sched: Make deadline policy and affinity changes wait for a cpuset attach Mathieu Desnoyers
2026-11-19 20:15 ` [PATCH v8 10/33] cgroup/cpuset: Give back the bandwidth an attach did not move Mathieu Desnoyers
2026-11-19 20:15 ` [PATCH v8 11/33] cgroup/cpuset: Reserve the bandwidth in the root domain a task moves to Mathieu Desnoyers
2026-11-19 20:15 ` [PATCH v8 12/33] selftests/sched: Test cpuset moves in deadline_bw_test Mathieu Desnoyers
2026-11-19 20:15 ` [PATCH v8 13/33] sched/deadline: Make a rebuild count a task in the root domain it runs in Mathieu Desnoyers
2026-11-19 20:15 ` [PATCH v8 14/33] sched/deadline: Move a task's bandwidth to " Mathieu Desnoyers
2026-11-19 20:53   ` sashiko-bot
2026-11-20 13:49     ` Mathieu Desnoyers
2026-11-19 20:15 ` [PATCH v8 15/33] sched/deadline: Keep a task in the root domain that counts its bandwidth Mathieu Desnoyers
2026-11-19 20:55   ` sashiko-bot
2026-11-20 13:50     ` Mathieu Desnoyers
2026-11-19 20:15 ` [PATCH v8 16/33] sched/deadline: Keep the last CPU a task has in its root domain Mathieu Desnoyers
2026-11-19 20:22   ` Mathieu Desnoyers
2026-11-19 20:48   ` sashiko-bot
2026-11-20 13:51     ` Mathieu Desnoyers
2026-11-19 20:15 ` [PATCH v8 17/33] cgroup/cpuset: Refuse to take a deadline task out of " Mathieu Desnoyers
2026-11-19 20:43   ` sashiko-bot
2026-11-20 13:51     ` Mathieu Desnoyers
2026-11-19 20:15 ` [PATCH v8 18/33] selftests/sched: Test the root domain of a task in deadline_bw_test Mathieu Desnoyers
2026-11-19 20:27   ` sashiko-bot
2026-11-20 13:51     ` Mathieu Desnoyers
2026-11-19 20:15 ` [PATCH v8 19/33] sched/deadline: Count only active CPUs when spreading extra_bw Mathieu Desnoyers
2026-11-19 20:15 ` [PATCH v8 20/33] rtmutex: Continue the chain walk when a waiter's deadline donor changes Mathieu Desnoyers
2026-11-19 20:16 ` [PATCH v8 21/33] rtmutex: Continue the walk when the owner's top waiter changes lock Mathieu Desnoyers
2026-11-19 20:16 ` [PATCH v8 22/33] selftests/sched: Test the rtmutex chain walk in deadline_bw_test Mathieu Desnoyers
2026-11-19 20:16 ` [PATCH v8 23/33] sched/deadline: Reset the donor's runtime at a deboost in the class Mathieu Desnoyers
2026-11-19 20:53   ` sashiko-bot
2026-11-20 13:52     ` Mathieu Desnoyers
2026-11-19 20:16 ` [PATCH v8 24/33] sched/deadline: Replenish a throttled task boosted while asleep Mathieu Desnoyers
2026-11-19 20:16 ` [PATCH v8 25/33] sched/deadline: Count the bandwidth a boosted task is given Mathieu Desnoyers
2026-11-19 20:16 ` [PATCH v8 26/33] sched/deadline: Start a period for a task that enters the class blocked Mathieu Desnoyers
2026-11-19 20:57   ` sashiko-bot
2026-11-20 13:52     ` Mathieu Desnoyers
2026-11-19 20:16 ` [PATCH v8 27/33] sched/deadline: Start a period at a deboost out of the class Mathieu Desnoyers
2026-11-19 20:47   ` sashiko-bot
2026-11-20 13:53     ` Mathieu Desnoyers
2026-11-19 20:16 ` [PATCH v8 28/33] selftests/sched: Test deadline boosts in deadline_bw_test Mathieu Desnoyers
2026-11-19 20:16 ` [PATCH v8 29/33] sched/deadline: Cancel the replenishment timer with the parameters Mathieu Desnoyers
2026-11-19 20:16 ` [PATCH v8 30/33] sched/deadline: Cap the runtime left of a constrained task at dl_runtime Mathieu Desnoyers
2026-11-19 20:16 ` [PATCH v8 31/33] sched/deadline: Check the runtime of a task that comes back runnable Mathieu Desnoyers
2026-11-19 20:16 ` [PATCH v8 32/33] sched/deadline: Check the runtime of a task whose parameters change Mathieu Desnoyers
2026-11-19 20:59   ` sashiko-bot [this message]
2026-11-20 13:53     ` Mathieu Desnoyers
2026-11-19 20:16 ` [PATCH v8 33/33] selftests/sched: Test parameter changes in deadline_bw_test 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-224081@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.