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 v10 35/40] sched/deadline: Check the runtime of a task whose parameters change
Date: Fri, 20 Nov 2026 21:38:53 +0000	[thread overview]
Message-ID: <sashiko-outbox-226204@kernel.org> (raw)
In-Reply-To: <f0f5e657ac6bccc75297da3739df812adda360b2.1795207233.git.mathieu.desnoyers@efficios.com>

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] sched/deadline: dl_proxy_block() misses dl_new_params check
  on PI futex requeue
- [Medium] sched/deadline: missing PI boost when update_dl_entity()
  pushes owner deadline
- [Low] sched/deadline: __setparam_dl() skips dl_new_params on
  same-param re-entry
--

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

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

This commit tracks deadline parameter changes in dl_new_params so that
the remaining runtime is checked against the new reservation at the next
enqueue, at deboost, or immediately when blocked on an rt_mutex.

> diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
> index 83aefe5ab671c..fe48137509ad8 100644
> --- a/kernel/sched/deadline.c
> +++ b/kernel/sched/deadline.c
[ ... ]
> @@ -145,12 +177,41 @@ void dl_deboost(struct sched_dl_entity *dl_se)
>  		}
>  	}
>  	dl_drop_boost(dl_se);
> +
> +	if (!task_on_rq_queued(p) && !dl_task_pi_blocked(p))
> +		return;
> +	if (dl_se->dl_new_params && !dl_se->dl_throttled && dl_in_constrained_gap(dl_se))
> +		return;
> +	if (dl_se->dl_new_params) {
> +		dl_se->dl_new_params = 0;
> +		if (!dl_se->dl_throttled)
> +			update_dl_entity(dl_se);
> +	}
>  }
>  
> -/* Return true if @p waits on an rt_mutex. The caller holds its pi_lock. */
> -static inline bool dl_task_pi_blocked(struct task_struct *p)
> +/*
> + * Check the runtime of @p against the parameters that sched_setattr() just
> + * gave it, if @p waits on an rt_mutex. Before any wakeup, its waiter node
> + * holds its deadline. The caller then calls rt_mutex_adjust_pi(), which
> + * requeues the waiter with the result. Other changes of @p, such as a
> + * cgroup move, do not requeue it: leave the check to sched_setattr().
> + *
> + * A boosted task, a throttled one, or one past its deadline and before
> + * its next period keeps the mark. Its deboost or its wakeup checks it.
> + * The caller holds the rq lock and the pi_lock of @p, and has updated the
> + * rq clock.
> + */
> +void dl_check_blocked_params(struct task_struct *p)
>  {
> -	return p->pi_blocked_on;
> +	struct sched_dl_entity *dl_se = &p->dl;
> +
> +	if (!dl_task(p) || task_on_rq_queued(p) || !dl_task_pi_blocked(p))
> +		return;
> +	if (dl_se->dl_new_params && !is_dl_boosted(dl_se) &&
> +	    !dl_se->dl_throttled && !dl_in_constrained_gap(dl_se)) {
> +		dl_se->dl_new_params = 0;
> +		update_dl_entity(dl_se);
> +	}
>  }

[Severity: Medium]
Should dl_proxy_block() also check and clear dl_se->dl_new_params?

When a task sleeps in futex(FUTEX_WAIT_REQUEUE_PI), p->pi_blocked_on is
NULL, so dl_check_blocked_params() returns early and leaves
dl_se->dl_new_params set.  If futex(FUTEX_CMP_REQUEUE_PI) then requeues
the task onto an rt_mutex before its old deadline expires,
task_blocks_on_rt_mutex() calls dl_proxy_block() before copying
p->dl.deadline into the waiter node:

kernel/sched/deadline.c:dl_proxy_block() {
	...
	if (!task_on_rq_queued(p) && !dl_se->dl_throttled &&
	    dl_time_before(dl_se->deadline, rq_clock(rq)) &&
	    (dl_is_implicit(dl_se) ||
	     !dl_time_before(rq_clock(rq), dl_next_period(dl_se))))
		replenish_dl_new_period(dl_se, rq);
	...
}

Because dl_proxy_block() only checks whether dl_se->deadline has passed,
a task whose reservation was shrunk while sleeping in
FUTEX_WAIT_REQUEUE_PI is queued on the rt_mutex (and boosts the lock
owner) with its stale earlier deadline, allowing it to acquire the lock
ahead of waiters with earlier deadlines.  Even when the old deadline has
passed and dl_proxy_block() starts a new period, it leaves
dl_se->dl_new_params set, so a later boost and deboost while blocked
calls update_dl_entity() a second time.

[ ... ]

> @@ -5179,6 +5261,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;
> +

[Severity: Low]
Can __setparam_dl() leave dl_se->dl_new_params unset when a task leaves
SCHED_DEADLINE before its 0-lag time and later re-enters the class with
the same parameters?

When a task leaves SCHED_DEADLINE before its 0-lag time,
switched_from_dl() leaves dl_runtime, dl_deadline and dl_period in
dl_se until inactive_task_timer() runs __dl_clear_params().  If the task
was PI-boosted back into dl_sched_class before the 0-lag time (without
refilling from the donor), or if sched_setattr() races with
inactive_task_timer() right after the 0-lag time while the task is
blocked on an rt_mutex, calling sched_setattr() to restore
SCHED_DEADLINE with identical parameters sees no change in dl_runtime,
dl_deadline or dl_period and does not set dl_se->dl_new_params.
switched_to_dl() then cancels inactive_timer without starting a new
period if dl_se->deadline has not passed, and neither
dl_check_blocked_params() nor dl_deboost() checks the remaining runtime
against the new reservation.

> diff --git a/kernel/sched/syscalls.c b/kernel/sched/syscalls.c
> index 9884fa55538ac..b25504e8748be 100644
> --- a/kernel/sched/syscalls.c
> +++ b/kernel/sched/syscalls.c
> @@ -311,6 +311,9 @@ static inline void __setscheduler_dl_pi(int newprio, int policy,
>  	 */
>  	if (!dl_prio(newprio))
>  		dl_drop_boost(&p->dl);
> +
> +	/* rt_mutex_adjust_pi() then requeues the waiter of a blocked task. */
> +	dl_check_blocked_params(p);
>  }
>  #else /* !CONFIG_RT_MUTEXES */
>  static inline void __setscheduler_dl_pi(int newprio, int policy,

[Severity: Medium]
What happens if p owns an rt_mutex with a deadline waiter whose deadline
was later than p's old deadline, and shrinking p's reservation pushes
p->dl.deadline past that waiter's deadline?

In __setscheduler_dl_pi(), rt_mutex_get_top_task(p) is only checked when
!dl_policy(policy):

kernel/sched/syscalls.c:__setscheduler_dl_pi() {
	if (dl_prio(newprio) && !dl_policy(policy)) {
		struct task_struct *pi_task = rt_mutex_get_top_task(p);

		if (pi_task) {
			dl_set_donor(&p->dl, pi_task);
			scope->flags |= ENQUEUE_REPLENISH;
		}
	}
	...
}

When an unboosted deadline task p stays in SCHED_DEADLINE and shrinks
its reservation, update_dl_entity() (in dl_check_blocked_params() or in
enqueue_dl_entity() during sched_change_end()) can start a new period
and move p->dl.deadline after its top waiter's deadline.  Unlike
rt_mutex_setprio(), which rechecks whether pi_task preempts p after
dl_deboost() updates p->dl, __sched_setscheduler() never boosts p with
its top waiter.  If p is running, it will throttle when its reduced
runtime expires while holding the lock instead of running on the
waiter's donor parameters; if p is blocked on another rt_mutex,
rt_mutex_adjust_pi() will propagate p's own unboosted deadline up the PI
chain instead of the waiter's.

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

  reply	other threads:[~2026-11-20 21:38 UTC|newest]

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

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-226204@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