Re: [PATCH v34 05/14] sched/proxy: Clear blocked_donor when the donor stops donating
From: K Prateek Nayak
Date: Wed Dec 02 2026 - 01:10:41 EST
Hello John, Mathieu,
On 12/2/2026 9:22 AM, John Stultz wrote:
> From: Mathieu Desnoyers <mathieu.desnoyers@xxxxxxxxxxxx>
>
> find_proxy_task() sets owner->blocked_donor to the task that donates to
> the owner. __mutex_unlock_slowpath() reads current->blocked_donor to
> hand the mutex to that task. The comment of the field says that it is
> set in schedule() and only stable under preempt_disable(). So the
> pointer is valid until the owner schedules again.
>
> But the donor can stop donating while the owner keeps running. It is
> woken, or a change of its scheduling class or of its affinity takes it
> off the runqueue. The owner keeps its blocked_donor until it schedules.
> Meanwhile the donor can run on another CPU and exit.
So we can just clear it in proxy_reset_donor() right? Only
current->blocked_donor is ever looked at and, it the proxy breaks mid
way, the only path that can be taken is via ttwu_runnable().
If the task is retained on the same CPU, it is safe to get the
reference since unlock is done with preempt disable - otherwise, we
check:
donor = current->blocked_donor;
guard(&donor->blocked_lock);
next_lock = __get_task_blocked_on(donor);
if (next_lock == lock)
next = get_task_struct(donor);
...
If ttwu_runnable() manages to clear the blocked_on relation first
under the blocked lock then we don't take a reference here and if
we manage to take a reference here, the task cannot exit
unexpectedly - it'll just get a spurious wakeup in the worst case.
IMO, a simple READ_ONCE() to check it here and WRITE_ONCE() in
proxy_reset_donor() after the re-arrangement suggested on Patch3
should do the trick based on my understanding.
o Race:
try_to_wake_up(donor) mutex_unlock_slowpath()
ttwu_runnable(rq, donor) /* MUTEX_HANDOFF */
proxy_needs_return(rq, donor) donor = current->blocked_donor;
proxy_reset_donor(rq) raw_spin_lock_nested(donor->blocked_lock)
WRITE_ONCE(rq->curr->blocked_donor, NULL); next = get_task_struct(donor);
... /* Donor wakes up runs, exits */
/*
* t->__state = TASK_DEAD
* t->usage != 0 so freeing is deferred wake_up_process(p)
*/ !ttwu_state_match()
put_task_struct()
/* Freed via RCU */
If the task runs and blocks on a different lock, wake_up_process() from
mutex_unlock_slowpath() (if it still think lock has not changed) will
just lead to a spurious wakeup.
Is here a scenario where proxy_reset_donor() clearing is not enough?
--
Thanks and Regards,
Prateek