The Linux Kernel Mailing List
 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 30/40] sched/deadline: Start a period for a task requeued onto an rt_mutex
Date: Fri, 20 Nov 2026 21:24:13 +0000	[thread overview]
Message-ID: <sashiko-outbox-226170@kernel.org> (raw)
In-Reply-To: <6c7be87e201d405bdf589989cb45afca9160c2e4.1795207232.git.mathieu.desnoyers@efficios.com>

Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [Medium] sched/deadline: dl_proxy_block() skips period start for
  PI-boosted tasks
- [Medium] locking/rtmutex: proxy lock steal uses stale deadline before
  dl_proxy_block()
- [Medium] sched/deadline: missing dl_entity_overflow() check in
  dl_proxy_block()
- [Medium] sched/deadline: dl_proxy_block() skips period start for zero
  constrained deadline
--

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

sched/deadline: Start a period for a task requeued onto an rt_mutex

This commit adds dl_proxy_block() to start a new period for a sleeping
SCHED_DEADLINE task when it is proxy-locked onto an rt_mutex, so the
waiter node does not use a deadline of 0 or a deadline in the past.

> diff --git a/kernel/locking/rtmutex.c b/kernel/locking/rtmutex.c
> index b09816977d4e5..5ff123d24b2a6 100644
> --- a/kernel/locking/rtmutex.c
> +++ b/kernel/locking/rtmutex.c
> @@ -1245,6 +1245,9 @@ static int __sched task_blocks_on_rt_mutex(struct rt_mutex_base *lock,
>  		return -EDEADLK;
>  
>  	raw_spin_lock(&task->pi_lock);
> +	/* A proxy lock: @task sleeps, and its deadline can be stale. */
> +	if (task != current)
> +		dl_proxy_block(task);
>  	waiter->task = task;
>  	waiter->lock = lock;
>  	waiter_update_prio(waiter, task);

[Severity: Medium]
Can __rt_mutex_start_proxy_lock() steal the rt_mutex using a stale
task->dl.deadline before task_blocks_on_rt_mutex() runs dl_proxy_block()?

__rt_mutex_start_proxy_lock() calls try_to_take_rt_mutex(lock, task, NULL)
before calling task_blocks_on_rt_mutex().  When the target PI futex has
just been unlocked and is in the handoff state with waiters,
try_to_take_rt_mutex() tests rt_mutex_steal(task_to_waiter(task),
rt_mutex_top_waiter(lock)), which reads task->dl.deadline before
dl_proxy_block() refreshes it:

kernel/locking/rtmutex.c:try_to_take_rt_mutex() {
    ...
		if (rt_mutex_has_waiters(lock)) {
			/* Check whether the trylock can steal it. */
			if (!rt_mutex_steal(task_to_waiter(task),
					    rt_mutex_top_waiter(lock)))
				return 0;
    ...
}

A requeued task with a deadline of 0 or a passed deadline can then steal
the lock from a woken top waiter with an earlier real deadline, and
because try_to_take_rt_mutex() does not call rt_mutex_adjust_prio(), the
new owner remains unboosted once wakeup assigns its real later deadline.

> diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
> index b1346be9e81da..1c5888b1717de 100644
> --- a/kernel/sched/deadline.c
> +++ b/kernel/sched/deadline.c
> @@ -1573,6 +1573,36 @@ static inline u64 dl_next_period(struct sched_dl_entity *dl_se)
>  	return dl_se->deadline - dl_se->dl_deadline + dl_se->dl_period;
>  }
>  
> +#ifdef CONFIG_RT_MUTEXES
> +/*
> + * FUTEX_CMP_REQUEUE_PI makes @p wait on an rt_mutex while @p sleeps.
> + * The waiter node of @p takes its deadline, before any wakeup. @p would
> + * not run with a deadline of 0, which it has if it entered the class
> + * asleep. Nor would it run with a deadline that has passed. Start a new
> + * period then, as its wakeup would. Leave a task past its deadline and
> + * before its next period: its wakeup throttles it until that period.
> + *
> + * The caller holds the pi_lock of @p.
> + */
> +void dl_proxy_block(struct task_struct *p)
> +{
> +	struct sched_dl_entity *dl_se = &p->dl;
> +	struct rq_flags rf;
> +	struct rq *rq;
> +
> +	if (!dl_task(p) || is_dl_boosted(dl_se) || !dl_se->dl_runtime)
> +		return;

[Severity: Medium]
Does returning early on is_dl_boosted(dl_se) or !dl_se->dl_runtime leave
p->dl.deadline at 0 (or expired) when p was PI-boosted while sleeping in
FUTEX_WAIT_REQUEUE_PI?

While p sleeps in futex_wait_requeue_pi(), p is not queued and
p->pi_blocked_on is NULL (so dl_task_pi_blocked(p) is false).  If p holds
another rt_mutex and a SCHED_DEADLINE waiter blocks on it, both
dl_boost_blocked() and switched_to_dl() skip replenish_dl_new_period()
because dl_task_pi_blocked(p) is false, leaving p->dl.deadline at 0 or at
a passed deadline.  When FUTEX_CMP_REQUEUE_PI then requeues p onto a
second rt_mutex, dl_proxy_block() returns early instead of starting a
period from pi_of(dl_se), and waiter_update_prio() copies the 0 or
expired deadline into waiter->tree.deadline.

> +	rq = __task_rq_lock(p, &rf);
> +	update_rq_clock(rq);
> +	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);

[Severity: Medium]
Should an implicit-deadline task also start a new period here when
dl_entity_overflow(dl_se, rq_clock(rq)) is true?

When an implicit-deadline task sleeps in FUTEX_WAIT_REQUEUE_PI past its
0-lag time (or has its parameters shrunk via sched_setattr() while
sleeping) and is requeued before its old dl_se->deadline passes,
dl_entity_overflow(dl_se, rq_clock(rq)) is already true.  Because the
task is asleep, update_dl_entity() will unconditionally see
dl_entity_overflow() (or a passed deadline) at wakeup and call
replenish_dl_new_period().  Without checking dl_entity_overflow() in
dl_proxy_block(), waiter_update_prio() copies the old dl_se->deadline that
the task would never run with, causing it to sort ahead of waiters whose
deadlines are earlier than its wakeup deadline.

[Severity: Medium]
What happens if a constrained-deadline task has dl_se->deadline == 0 when
rq_clock(rq) is still before dl_next_period(dl_se)?

If sched_setattr() switches a task sleeping in FUTEX_WAIT_REQUEUE_PI to
SCHED_DEADLINE with dl_deadline < dl_period, dl_se->deadline is 0.
Because dl_is_implicit(dl_se) is false, dl_proxy_block() evaluates
dl_next_period(dl_se), which computes dl_period - dl_deadline (or
dl_period after commit "sched/deadline: Keep the start of the period
across a change of dl_deadline") as if a period had started at t = 0.  If
rq_clock(rq) < dl_next_period(dl_se), dl_proxy_block() skips
replenish_dl_new_period() and leaves waiter->tree.deadline at 0.  Checking
!dl_se->deadline before testing dl_next_period(dl_se) would avoid this.

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

  reply	other threads:[~2026-11-20 21:24 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 [this message]
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
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-226170@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