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: [RESEND PATCH v4 09/17] sched/deadline: Reset the deadline and the runtime with the parameters
Date: Thu, 19 Nov 2026 16:49:42 +0000	[thread overview]
Message-ID: <sashiko-outbox-223577@kernel.org> (raw)
In-Reply-To: <07a810645c5ab919a52ffe2cc4b63074a84751fb.1795105408.git.mathieu.desnoyers@efficios.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] sched/deadline: donor runtime and deadline retained after PI
  deboost
- [Medium] sched/deadline: uncanceled dl_timer in __dl_clear_params()
--

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

sched/deadline: Reset the deadline and the runtime with the parameters

This commit resets dl_se->deadline and dl_se->runtime in __dl_clear_params()
and in switched_from_dl() when a boosted task with no deadline parameters of
its own leaves SCHED_DEADLINE, so that the next entry starts a new period.

> diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
> index 71b1c155c2424..d6d2657dcddd6 100644
> --- a/kernel/sched/deadline.c
> +++ b/kernel/sched/deadline.c
> @@ -3569,6 +3569,16 @@ static void switched_from_dl(struct rq *rq, struct task_struct *p)
>  	if (task_on_rq_queued(p) && p->dl.dl_runtime)
>  		task_non_contending(&p->dl, false);
>  
> +	/*
> +	 * A task with no parameters of its own was boosted into the class.
> +	 * Its deadline and runtime are the donor's. Reset them, so that its
> +	 * next entry into the class starts a new period.
> +	 */
> +	if (!p->dl.dl_runtime) {
> +		p->dl.deadline = 0;
> +		p->dl.runtime = 0;
> +	}

[Severity: Medium]
Can a task still retain the donor's deadline and runtime after PI deboost when
p->dl.dl_runtime is non-zero?

If a non-deadline task is PI-boosted by a SCHED_DEADLINE waiter and calls
sched_setattr() to enter SCHED_DEADLINE while still boosted, prev_class and
next_class in __sched_setscheduler() are both &dl_sched_class, so neither
switched_from_dl() nor switched_to_dl() runs.  __setparam_dl() sets
p->dl.dl_runtime without clearing the donor's deadline or runtime (and if p is
sleeping, skipping switched_to_dl() also skips add_rq_bw(), later triggering
WARN_ON_ONCE(dl_rq->running_bw > dl_rq->this_bw) and underflow in
__sub_rq_bw()).  When rt_mutex_setprio() later deboosts p, it stays in
dl_sched_class and restores p->dl.pi_se = &p->dl without ENQUEUE_REPLENISH, so
enqueue_dl_entity() sees the donor's future deadline and skips
setup_new_dl_entity(), letting p run unboosted on the donor's remaining
runtime.

Similarly, if a task leaves SCHED_DEADLINE before its 0-lag time (or changes
policy while boosted via __setscheduler_dl_pi()) and is replenished from a
donor while p->dl.dl_runtime is still non-zero, switched_from_dl() on deboost
skips this !p->dl.dl_runtime reset and passes the donor's deadline and runtime
to task_non_contending().

> @@ -3984,7 +3994,8 @@ bool __checkparam_dl(const struct sched_attr *attr)
>  }
>  
>  /*
> - * This function clears the sched_dl_entity static params.
> + * Clear the static parameters of @dl_se. Also reset its deadline and its
> + * runtime, so that its next enqueue starts a new period.
>   */
>  static void __dl_clear_params(struct sched_dl_entity *dl_se)
>  {
> @@ -3995,6 +4006,9 @@ static void __dl_clear_params(struct sched_dl_entity *dl_se)
>  	dl_se->dl_bw			= 0;
>  	dl_se->dl_density		= 0;
>  
> +	dl_se->deadline			= 0;
> +	dl_se->runtime			= 0;
> +
>  	dl_se->dl_throttled		= 0;
>  	dl_se->dl_yielded		= 0;
>  	dl_se->dl_non_contending	= 0;

[Severity: Medium]
Does resetting deadline, runtime, and dl_throttled in __dl_clear_params()
without canceling dl_se->dl_timer leave a stale replenishment timer queued?

When a task yields with remaining runtime (or uses a constrained deadline with
dl_deadline < dl_period) and is throttled, its 0-lag time arrives before
dl_se->dl_timer fires at dl_next_period(dl_se).  If the task switches out of
SCHED_DEADLINE while throttled, __dl_clear_params() runs at the 0-lag time and
clears deadline and dl_throttled while dl_se->dl_timer remains queued.  If the
task re-enters SCHED_DEADLINE before that old timer expires,
enqueue_dl_entity() starts a new period, and when the task throttles in the
new period, start_dl_timer() bails out because hrtimer_is_queued(timer) is
already true:

kernel/sched/deadline.c:start_dl_timer() {
	...
	if (!hrtimer_is_queued(timer)) {
		if (!dl_server(dl_se))
			get_task_struct(dl_task_of(dl_se));
		hrtimer_start(timer, act, HRTIMER_MODE_ABS_HARD);
	}

	return 1;
}

When the stale dl_timer fires at the old period boundary, dl_task_timer()
replenishes and unthrottles the task in the middle of its new period, allowing
it to exceed its reservation.

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

  reply	other threads:[~2026-11-19 16:49 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-19 16:24 [RESEND PATCH v4 00/17] sched/deadline: first bandwidth accounting fixes and selftests Mathieu Desnoyers
2026-11-19 16:24 ` [RESEND PATCH v4 01/17] sched: Refuse SCHED_FLAG_KEEP_PARAMS that would change the policy or the class Mathieu Desnoyers
2026-11-19 16:24 ` [RESEND PATCH v4 02/17] sched/deadline: Do not admit bandwidth for parameters that are kept Mathieu Desnoyers
2026-11-19 16:24 ` [RESEND PATCH v4 03/17] sched: Let a task boosted by a deadline waiter change its policy Mathieu Desnoyers
2026-11-19 16:24 ` [RESEND PATCH v4 04/17] sched/deadline: Do not divide by zero active CPUs of a root domain Mathieu Desnoyers
2026-11-19 16:24 ` [RESEND PATCH v4 05/17] sched/deadline: Refuse dl_server debugfs writes while the rq is offline Mathieu Desnoyers
2026-11-19 16:24 ` [RESEND PATCH v4 06/17] sched: Take cpuset_mutex for a deadline policy change only with pi Mathieu Desnoyers
2026-11-19 16:24 ` [RESEND PATCH v4 07/17] sched/deadline: Do not lose a throttled task switched out and back Mathieu Desnoyers
2026-11-19 16:24 ` [RESEND PATCH v4 08/17] sched/deadline: Do not replenish a boost from cleared parameters Mathieu Desnoyers
2026-11-19 16:24 ` [RESEND PATCH v4 09/17] sched/deadline: Reset the deadline and the runtime with the parameters Mathieu Desnoyers
2026-11-19 16:49   ` sashiko-bot [this message]
2026-11-19 16:24 ` [RESEND PATCH v4 10/17] sched/deadline: Fix an overflow of the 0-lag time with long periods Mathieu Desnoyers
2026-11-19 16:46   ` sashiko-bot
2026-11-19 18:14     ` Mathieu Desnoyers
2026-11-19 16:24 ` [RESEND PATCH v4 11/17] sched/deadline: Release the bandwidth of a task that leaves the class asleep Mathieu Desnoyers
2026-11-19 16:24 ` [RESEND PATCH v4 12/17] sched/deadline: Reject SCHED_DEADLINE on exited tasks Mathieu Desnoyers
2026-11-19 16:24 ` [RESEND PATCH v4 13/17] sched/deadline: Fix this_bw when a task is changed during a remote wakeup Mathieu Desnoyers
2026-11-19 16:24 ` [RESEND PATCH v4 14/17] sched/deadline: Check SCHED_DEADLINE affinity under the rq lock Mathieu Desnoyers
2026-11-19 16:24 ` [RESEND PATCH v4 15/17] sched/debug: Show the deadline bandwidth of each runqueue Mathieu Desnoyers
2026-11-19 16:24 ` [RESEND PATCH v4 16/17] selftests/sched: Add a test of SCHED_DEADLINE policy round trips Mathieu Desnoyers
2026-11-19 16:24 ` [RESEND PATCH v4 17/17] selftests/sched: Add a test of SCHED_DEADLINE bandwidth accounting 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-223577@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.