Re: [PATCH v26 10/10] sched: Handle blocked-waiter migration (and return migration)
From: Peter Zijlstra
Date: Thu Apr 02 2026 - 11:16:23 EST
On Thu, Apr 02, 2026 at 04:43:02PM +0200, Peter Zijlstra wrote:
>
> So with that other issue cured, I'm back to staring at this thing....
>
> On Tue, Mar 24, 2026 at 07:13:25PM +0000, John Stultz wrote:
> > +static bool proxy_deactivate(struct rq *rq, struct task_struct *donor)
> > {
> > unsigned long state = READ_ONCE(donor->__state);
> >
> > @@ -6598,17 +6610,140 @@ static bool __proxy_deactivate(struct rq *rq, struct task_struct *donor)
> > return try_to_block_task(rq, donor, &state, true);
> > }
> >
>
> > @@ -6741,7 +6900,17 @@ find_proxy_task(struct rq *rq, struct task_struct *donor, struct rq_flags *rf)
> > /* Handle actions we need to do outside of the guard() scope */
> > switch (action) {
> > case DEACTIVATE_DONOR:
> > - return proxy_deactivate(rq, donor);
> > + if (proxy_deactivate(rq, donor))
> > + return NULL;
> > + /* If deactivate fails, force return */
> > + p = donor;
> > + fallthrough;
>
> I was going to reply to Prateek's email and was going over the whole
> ttwu path because of that, and that got me looking at this.
>
> What happens here if donor is migrated; the current CPU no longer valid
> and we fail proxy_deactivate() because of a pending signal?
Something like so?
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -2160,7 +2160,7 @@ void deactivate_task(struct rq *rq, stru
dequeue_task(rq, p, flags);
}
-static void block_task(struct rq *rq, struct task_struct *p, int flags)
+static void _block_task(struct rq *rq, struct task_struct *p, int flags)
{
if (dequeue_task(rq, p, DEQUEUE_SLEEP | flags))
__block_task(rq, p);
@@ -6503,6 +6503,31 @@ pick_next_task(struct rq *rq, struct tas
#define SM_PREEMPT 1
#define SM_RTLOCK_WAIT 2
+static bool block_task(struct rq *rq, struct task_struct *p, unsigned long task_state)
+{
+ int flags = DEQUEUE_NOCLOCK;
+
+ p->sched_contributes_to_load =
+ (task_state & TASK_UNINTERRUPTIBLE) &&
+ !(task_state & TASK_NOLOAD) &&
+ !(task_state & TASK_FROZEN);
+
+ if (unlikely(is_special_task_state(task_state)))
+ flags |= DEQUEUE_SPECIAL;
+
+ /*
+ * __schedule() ttwu()
+ * prev_state = prev->state; if (p->on_rq && ...)
+ * if (prev_state) goto out;
+ * p->on_rq = 0; smp_acquire__after_ctrl_dep();
+ * p->state = TASK_WAKING
+ *
+ * Where __schedule() and ttwu() have matching control dependencies.
+ *
+ * After this, schedule() must not care about p->state any more.
+ */
+ _block_task(rq, p, flags);
+}
/*
* Helper function for __schedule()
*
@@ -6515,7 +6540,6 @@ static bool try_to_block_task(struct rq
unsigned long *task_state_p, bool should_block)
{
unsigned long task_state = *task_state_p;
- int flags = DEQUEUE_NOCLOCK;
if (signal_pending_state(task_state, p)) {
WRITE_ONCE(p->__state, TASK_RUNNING);
@@ -6535,26 +6559,7 @@ static bool try_to_block_task(struct rq
if (!should_block)
return false;
- p->sched_contributes_to_load =
- (task_state & TASK_UNINTERRUPTIBLE) &&
- !(task_state & TASK_NOLOAD) &&
- !(task_state & TASK_FROZEN);
-
- if (unlikely(is_special_task_state(task_state)))
- flags |= DEQUEUE_SPECIAL;
-
- /*
- * __schedule() ttwu()
- * prev_state = prev->state; if (p->on_rq && ...)
- * if (prev_state) goto out;
- * p->on_rq = 0; smp_acquire__after_ctrl_dep();
- * p->state = TASK_WAKING
- *
- * Where __schedule() and ttwu() have matching control dependencies.
- *
- * After this, schedule() must not care about p->state any more.
- */
- block_task(rq, p, flags);
+ block_task(rq, p, task_state);
return true;
}
@@ -6599,7 +6604,8 @@ static bool proxy_deactivate(struct rq *
* need to be changed from next *before* we deactivate.
*/
proxy_resched_idle(rq);
- return try_to_block_task(rq, donor, &state, true);
+ block_task(rq, donor, state);
+ return true;
}
static inline void proxy_release_rq_lock(struct rq *rq, struct rq_flags *rf)