Re: [PATCH v7 09/40] rtmutex: Continue the chain walk when a waiter's deadline donor changes

From: Mathieu Desnoyers

Date: Wed Nov 18 2026 - 09:54:10 EST


On 18/11/26 15:27, Juri Lelli wrote:
> So I have to
> wonder (and ask for Peter, Thomas, etc opinion) if we'd rather not keep
> extending the chain walk for DEADLINE PI, which is known broken and
> proxy execution is going to replace anyway, and leave rtmutex.c alone.
>
> It looks like what we lack is memory safety, apart from accurate PI.
> It's an hack after another, but how about having the owner pin its donor
> instead: take a reference on the task behind dl.pi_se whenever it is set
> to another task's entity, and drop it when pi_se changes
> (rt_mutex_setprio() and __setscheduler_dl_pi() are the only writers).

I like it. It closes the use after free in every case, also the window
that no change to the walk can close. I checked two points in the code.

The writers: rt_mutex_setprio() and __setscheduler_dl_pi() set pi_se to
a donor. dl_drop_boost() resets it to the task's own entity.
dl_deboost() calls it. One helper can do all of them: drop the reference
on the old donor, take one on the new one. The task behind pi_se is the
owner of that entity, which can be a donor further up the chain. A task
that exits while boosted needs its reference dropped too.

The locks: these writers hold the rq lock. put_task_struct() is safe
there. It frees the task through call_rcu(), also on PREEMPT_RT.

Then patch 9 is no longer needed for memory safety. I would drop it.
The owner keeps running on a stale donor until the next walk, as today.

The new patch after this one in the planned next version is a different
case. Its subject is "rtmutex: Continue the walk when the owner's top
waiter changes lock". It fixes a bug of RT priorities from 2006: an
owner stays boosted to the priority of a waiter that left the chain.
pi_chain_top_moves_rt shows it without any deadline task. I would keep
it, Cc'd to the locking maintainers, or send it on its own.

I will wait for Peter's and Thomas' opinion before I change the series.

Thanks,

Mathieu


--
Mathieu Desnoyers
EfficiOS Inc.
https://www.efficios.com