Re: [PATCH v34 07/14] sched/proxy: Avoid transient blocked_donor cycles
From: John Stultz
Date: Wed Dec 02 2026 - 01:59:39 EST
On Tue, Dec 1, 2026 at 10:29 PM K Prateek Nayak <kprateek.nayak@xxxxxxx> wrote:
> On 12/2/2026 9:22 AM, John Stultz wrote:
> > diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> > index 17871c8a5ab30..6a9fec7a26f67 100644
> > --- a/kernel/sched/core.c
> > +++ b/kernel/sched/core.c
> > @@ -7050,7 +7050,11 @@ static void proxy_migrate_task(struct rq *rq, struct rq_flags *rf,
> > * before we release the lock.
> > */
> > proxy_resched_idle(rq);
> > - for (; p; p = READ_ONCE(p->blocked_donor)) {
> > + while (p && task_on_rq_queued(p)) {
> > + struct task_struct *next = READ_ONCE(p->blocked_donor);
> > +
> > + /* clear blocked_donor so we can't end up in cycles */
> > + WRITE_ONCE(p->blocked_donor, NULL);
>
> Ooo! Interesting. I suppose this is still needed with Patch 10 and 11
> because a ww_mutex unlock can suddenly clear a cycle before the
> Brent checkpoint can converge but the backwards link are already
> cyclic?
So less likely to be mutex related, this came up as a issue with the
proxy-enabled futexes Suleiman is working on, as if userspace controls
the locks, they can create lots of odd looking cycles (including stuff
like locking a lock they already own, or maliciously locking it with
another task's tid who then tries to lock the lock). So while we have
to be careful in the main find_proxy_task(), we also have to be
careful elsewhere where we walk chains to guard against infinitely
looping (the later chain migration patches in the series also had a
few spots like this to address).
Additionally, with the other stale blocked_donor issues that had been
found, this seemed like a good place to zap them, since the primary
uses of blocked_donor is to go a single step back
(rq->curr->blocked_donor) when handing locks off, and the
proxy_migrate_task() optimization to migrate the full chain in one go.
So clearing it as we go in the migration function seemed like a good
step to avoid mistakes.
thanks
-john