Re: [PATCH 01/10] sched/core: Skip migration disabled tasks in proxy execution

From: John Stultz

Date: Wed May 06 2026 - 17:10:09 EST


On Wed, May 6, 2026 at 10:47 AM Andrea Righi <arighi@xxxxxxxxxx> wrote:
>
> Never attempt to migrate migration-disabled tasks or tasks that can only
> run on a single CPU when switching donor's execution context, preventing
> task pinning violations.
>
> Signed-off-by: Andrea Righi <arighi@xxxxxxxxxx>
> ---
> kernel/sched/core.c | 22 +++++++++++++++++++---
> 1 file changed, 19 insertions(+), 3 deletions(-)
>
> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> index da20fb6ea25ae..75541e5bb66d1 100644
> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
> @@ -6793,9 +6793,13 @@ static void proxy_force_return(struct rq *rq, struct rq_flags *rf,
>
> update_rq_clock(task_rq);
> deactivate_task(task_rq, p, DEQUEUE_NOCLOCK);
> - cpu = select_task_rq(p, p->wake_cpu, &wake_flag);
> - set_task_cpu(p, cpu);
> - target_rq = cpu_rq(cpu);
> + if (p->nr_cpus_allowed > 1 && !is_migration_disabled(p)) {
> + cpu = select_task_rq(p, p->wake_cpu, &wake_flag);
> + set_task_cpu(p, cpu);
> + target_rq = cpu_rq(cpu);
> + } else {
> + target_rq = task_rq;
> + }
> clear_task_blocked_on(p, NULL);
> }
>
> @@ -6893,6 +6897,18 @@ find_proxy_task(struct rq *rq, struct task_struct *donor, struct rq_flags *rf)
> */
> if (curr_in_chain)
> return proxy_resched_idle(rq);
> + /*
> + * Tasks pinned to a single CPU (per-CPU kthreads via
> + * kthread_bind(), tasks under migrate_disable()) cannot
> + * be moved to @owner_cpu. proxy_migrate_task() uses
> + * __set_task_cpu() which would silently violate the
> + * pinning and leave the task to run on a CPU outside
> + * its cpus_ptr once it is unblocked. Stay on this CPU
> + * via force_return; the owner running elsewhere will
> + * wake @p back up when the mutex becomes available.
> + */
> + if (p->nr_cpus_allowed == 1 || is_migration_disabled(p))
> + goto force_return;
> goto migrate_task;

Hey Andrea!
I'm excited to see this series! Thanks for your efforts here!

Though I'm a bit confused on this patch. I see the patch changes it
so we don't proxy-migrate pinned/migration-disabled patches, but I'm
not sure I understand why.

We only proxy-migrate blocked_on tasks, which don't run on the cpu
they are migrated to (they are only migrated to be used as a donor).
That's why we have the proxy_force_return() function to return-migrate
them back when they do become runnable.

Could you provide some more details about what motivated this change
(ie: how you tripped a problem that it resolved?).

thanks
-john