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 v14 31/39] sched/deadline: Record the start of the period
Date: Thu, 03 Dec 2026 17:42:59 +0000	[thread overview]
Message-ID: <sashiko-outbox-248294@kernel.org> (raw)
In-Reply-To: <6b1869882be16d6d09413804a673ebb3d97aaddb.1796296313.git.mathieu.desnoyers@efficios.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] sched/deadline: switched_from_dl() wipes preserved deadline
  and period_start
- [Medium] sched/deadline: double dl_release_params() wipes constrained
  task period state
--

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

sched/deadline: Record the start of the period

This commit adds a period_start field to struct sched_dl_entity and updates
or clears it alongside deadline so that a follow-up patch can compute the
next period from the period start after sched_setattr().

> diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
> index 58fc1c6c41178..820e71ee7fdf0 100644
> --- a/kernel/sched/deadline.c
> +++ b/kernel/sched/deadline.c

[ ... ]

> @@ -4675,6 +4680,7 @@ static void switched_from_dl(struct rq *rq, struct task_struct *p)
>  	 */
>  	if (!p->dl.dl_runtime) {
>  		p->dl.deadline = 0;
> +		p->dl.period_start = 0;
>  		p->dl.runtime = 0;
>  	}

[Severity: Medium]
Can this block wipe the deadline and period_start that dl_release_params()
just preserved for a constrained-deadline task?

When a runnable constrained-deadline task leaves SCHED_DEADLINE past its
0-lag time, switched_from_dl() first calls task_non_contending(), which
invokes dl_release_params().  That clears p->dl.dl_runtime to 0 while
intentionally keeping p->dl.deadline and p->dl.period_start.

The !p->dl.dl_runtime check then fires and zeroes both fields.  If the task
re-enters SCHED_DEADLINE before its next period, dl_check_constrained_dl()
skips throttling and starts a fresh period immediately, bypassing bandwidth
confinement.

Checking !p->dl.dl_runtime before task_non_contending() (or using else if)
would avoid clobbering the preserved state.

[ ... ]

> @@ -5224,12 +5231,16 @@ static void __dl_clear_params(struct sched_dl_entity *dl_se)
>   */
>  static void dl_release_params(struct sched_dl_entity *dl_se)
>  {
> +	u64 period_start = dl_se->period_start;
>  	u64 deadline = dl_se->deadline;
>  	bool constrained = !dl_is_implicit(dl_se);
>  
>  	__dl_clear_params(dl_se);
> -	if (constrained)
> +	if (constrained) {
> +		/* Keep the start of the period with its deadline. */
> +		dl_se->period_start = period_start;
>  		dl_se->deadline = deadline;
> +	}
>  }

[Severity: Medium]
Is dl_release_params() safe if it runs twice for a departing
constrained-deadline task?

When inactive_task_timer() has already fired on another CPU and is waiting
for task_rq_lock(p), hrtimer_active() is still true.  If the task switches
out of SCHED_DEADLINE concurrently, task_non_contending() calls
dl_release_params() first, and inactive_task_timer() calls it again:

CPU0                            CPU1
                                inactive_task_timer()
                                  task_rq_lock(p)  (spins)
switched_from_dl()
  task_non_contending()
    hrtimer_active() == true
    dl_release_params()
      clears dl_deadline/period
      keeps deadline/period_start
rq unlock
                                  (acquires rq lock)
                                  dl_release_params()
                                    dl_is_implicit() == true
                                    clears deadline/period_start <-- wiped

On the second call, dl_deadline and dl_period are both 0, so
dl_is_implicit() returns true and __dl_clear_params() wipes the preserved
deadline and period_start.  A task that re-enters SCHED_DEADLINE before its
next period then skips throttling in dl_check_constrained_dl().

Returning early in dl_release_params() when !dl_se->dl_deadline (or
guarding the call in inactive_task_timer() on dl_se->dl_runtime) would
prevent the second call from clearing the preserved state.

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

  reply	other threads:[~2026-12-03 17:43 UTC|newest]

Thread overview: 57+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03 14:58 [PATCH v14 00/39] sched/deadline: bandwidth accounting fixes and selftests Mathieu Desnoyers
2026-12-03 14:58 ` [PATCH v14 01/39] sched/deadline: Hold a reference on the deadline donor of a boosted task Mathieu Desnoyers
2026-12-03 15:44   ` sashiko-bot
2026-12-03 14:58 ` [PATCH v14 02/39] sched/deadline: Replenish a throttled task boosted while asleep Mathieu Desnoyers
2026-12-03 15:29   ` sashiko-bot
2026-12-03 14:58 ` [PATCH v14 03/39] sched/deadline: Do not truncate a bandwidth to 32 bits in __dl_add/sub() Mathieu Desnoyers
2026-12-03 14:58 ` [PATCH v14 04/39] sched/deadline: Count the 0-lag time from the next period Mathieu Desnoyers
2026-12-03 14:58 ` [PATCH v14 05/39] sched/deadline: Clear dl_overrun under the rq lock Mathieu Desnoyers
2026-12-03 14:58 ` [PATCH v14 06/39] sched/deadline: Admit a returning task without the bandwidth it holds Mathieu Desnoyers
2026-12-03 14:58 ` [PATCH v14 07/39] sched/deadline: Leave an active task alone in the inactive timer Mathieu Desnoyers
2026-12-03 14:58 ` [PATCH v14 08/39] sched/deadline: Keep the deadline of a departed constrained task Mathieu Desnoyers
2026-12-03 15:45   ` sashiko-bot
2026-12-03 14:58 ` [PATCH v14 09/39] sched/deadline: Keep departing bandwidth across a root domain rebuild Mathieu Desnoyers
2026-12-03 15:49   ` sashiko-bot
2026-12-03 14:58 ` [PATCH v14 10/39] sched/deadline: Rebuild the root domains' accounting from the task list Mathieu Desnoyers
2026-12-03 15:57   ` sashiko-bot
2026-12-03 14:58 ` [PATCH v14 11/39] sched/deadline: Record the root domain holding a task's bandwidth Mathieu Desnoyers
2026-12-03 14:58 ` [PATCH v14 12/39] sched/deadline: Leave a dying task out of a rebuild of the accounting Mathieu Desnoyers
2026-12-03 16:20   ` sashiko-bot
2026-12-03 14:58 ` [PATCH v14 13/39] selftests/sched: Test SCHED_DEADLINE bandwidth across a root domain rebuild Mathieu Desnoyers
2026-12-03 16:10   ` sashiko-bot
2026-12-03 14:58 ` [PATCH v14 14/39] selftests/sched: Test the root domain rebuild in deadline_bw_test Mathieu Desnoyers
2026-12-03 16:10   ` sashiko-bot
2026-12-03 14:58 ` [PATCH v14 15/39] sched/deadline: Move a task's bandwidth only where room was made Mathieu Desnoyers
2026-12-03 14:58 ` [PATCH v14 16/39] cgroup/cpuset: Wait for an attach before rebuilding the sched domains Mathieu Desnoyers
2026-12-03 16:22   ` sashiko-bot
2026-12-03 14:58 ` [PATCH v14 17/39] sched: Make deadline policy and affinity changes wait for a cpuset attach Mathieu Desnoyers
2026-12-03 14:58 ` [PATCH v14 18/39] cgroup/cpuset: Give back the bandwidth an attach did not move Mathieu Desnoyers
2026-12-03 14:58 ` [PATCH v14 19/39] cgroup/cpuset: Reserve the bandwidth in the root domain a task moves to Mathieu Desnoyers
2026-12-03 14:58 ` [PATCH v14 20/39] selftests/sched: Test cpuset moves in deadline_bw_test Mathieu Desnoyers
2026-12-03 14:58 ` [PATCH v14 21/39] sched/deadline: Make a rebuild count a task in the root domain it runs in Mathieu Desnoyers
2026-12-03 14:58 ` [PATCH v14 22/39] sched/deadline: Move a task's bandwidth to " Mathieu Desnoyers
2026-12-03 14:58 ` [PATCH v14 23/39] sched/deadline: Keep a task in the root domain that counts its bandwidth Mathieu Desnoyers
2026-12-03 14:58 ` [PATCH v14 24/39] sched/deadline: Keep the last CPU a task has in its root domain Mathieu Desnoyers
2026-12-03 14:58 ` [PATCH v14 25/39] cgroup/cpuset: Refuse to take a deadline task out of " Mathieu Desnoyers
2026-12-03 14:58 ` [PATCH v14 26/39] selftests/sched: Test the root domain of a task in deadline_bw_test Mathieu Desnoyers
2026-12-03 17:25   ` sashiko-bot
2026-12-03 14:58 ` [PATCH v14 27/39] sched/deadline: Count only active CPUs when spreading extra_bw Mathieu Desnoyers
2026-12-03 14:58 ` [PATCH v14 28/39] sched/deadline: Cancel the replenishment timer with the parameters Mathieu Desnoyers
2026-12-03 17:39   ` sashiko-bot
2026-12-03 14:58 ` [PATCH v14 29/39] sched/deadline: Cap the runtime left of a constrained task at dl_runtime Mathieu Desnoyers
2026-12-03 14:58 ` [PATCH v14 30/39] sched/deadline: Check the runtime of a task that comes back runnable Mathieu Desnoyers
2026-12-03 14:58 ` [PATCH v14 31/39] sched/deadline: Record the start of the period Mathieu Desnoyers
2026-12-03 17:42   ` sashiko-bot [this message]
2026-12-03 14:58 ` [PATCH v14 32/39] sched/deadline: Keep the debt of a task across a change of parameters Mathieu Desnoyers
2026-12-03 14:58 ` [PATCH v14 33/39] selftests/sched: Test parameter changes in deadline_bw_test Mathieu Desnoyers
2026-12-03 17:56   ` sashiko-bot
2026-12-03 14:58 ` [PATCH v14 34/39] sched/deadline: Count a task that departs while a rebuild walks the tasks Mathieu Desnoyers
2026-12-03 14:58 ` [PATCH v14 35/39] sched/deadline: Count again a departed task that a boost brings back Mathieu Desnoyers
2026-12-03 18:01   ` sashiko-bot
2026-12-03 14:58 ` [PATCH v14 36/39] sched/deadline: Keep a reaped deadline task in a rebuild Mathieu Desnoyers
2026-12-03 18:14   ` sashiko-bot
2026-12-03 14:58 ` [PATCH v14 37/39] sched/deadline: Warn when a runqueue keeps the bandwidth of a task Mathieu Desnoyers
2026-12-03 18:05   ` sashiko-bot
2026-12-03 14:58 ` [PATCH v14 38/39] selftests/sched: Test PI against hotplug and rebuilds in deadline_bw_test Mathieu Desnoyers
2026-12-03 18:07   ` sashiko-bot
2026-12-03 14:58 ` [PATCH v14 39/39] 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-248294@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