Re: [PATCH v3] sched: Reset cpumask if __migrate_task() failed for migration_cpu_stop()

From: Sebastian Andrzej Siewior

Date: Wed Dec 02 2026 - 09:13:11 EST


On 2026-11-26 11:40:49 [+0100], Peter Zijlstra wrote:
> > > So the problem begins here, by selecting a CPU that isn't guarded to
> > > remain online until after the operation completes.
> >
> > Right, we don't enforce this so everyone without a CPU-HP lock held has
> > a problem here. From irq_thread_check_affinity() perspective, it is fine
> > because once the CPU goes down, there will be another update aligning
> > the thread with the CPU that has been picked to serve the interrupt.
>
> Right, that is true in this case. But will that always be true for
> people that 'forget' hotplug.

We could have one interface for tglx and one for everyone else with a
warning with the HP lock is missing. I added a warning there and the
first one was kthread_affine_node() with a warning why it is okay if we
miss the CPU…

…
> Right -- so the printk is gated with p->mm, which kthreads will mostly
> fail. So even if the timing was different and we'd have hit
> select_fallback_rq() we'd not have seen a printk().
>
> However, the 'fixup' is different, select_fallback_rq() will set the
> widest possible mask, while this will set only the one CPU.

Yes, the current CPU we were on anyway.

> Then there also are __balance_push_cpu_stop() and
> sched_non_preferred_cpu_push_stop() that use __migrate_task(). AFAICT
> both of those should also be able to hit this task, both of them run it
> through select_fallback_rq().
>
> Does something like so make sense? That routes them all through
> select_fallback_rq().

The box freezes. migration_cpu_stop() takes the rq and then
select_fallback_rq() does the same:

| ============================================
| WARNING: possible recursive locking detected
| 7.4.0-rc5+ #16 Not tainted
| --------------------------------------------
| migration/0/21 is trying to acquire lock:
| ffff88817bc2e220 (&rq->__lock){-...}-{2:2}, at: ___task_rq_lock+0x4d/0x100
|
| but task is already holding lock:
| ffff88817bc2e220 (&rq->__lock){-...}-{2:2}, at: migration_cpu_stop+0x72/0x360
|
| other info that might help us debug this:
| Possible unsafe locking scenario:
|
| CPU0
| ----
| lock(&rq->__lock);
| lock(&rq->__lock);
|
| *** DEADLOCK ***
|
| May be due to missing lock nesting notation
|
| locks held by migration/0/21: 2, on CPU#0:
| #0: ffff888102b55f80 (&p->pi_lock){-...}-{2:2}, at: migration_cpu_stop+0x5c/0x360
| #1: ffff88817bc2e220 (&rq->__lock){-...}-{2:2}, at: migration_cpu_stop+0x72/0x360
|
| stack backtrace:
| CPU: 0 UID: 0 PID: 21 Comm: migration/0 Not tainted 7.4.0-rc5+ #16 PREEMPT_{RT,(lazy)}
| Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 2026.11+ds-1 11/26/2026
| Stopper: migration_cpu_stop+0x0/0x360 <- affine_move_task+0x459/0x620
| Call Trace:
| Call Trace:
| <TASK>
| dump_stack_lvl+0x5b/0x80
| print_deadlock_bug.cold+0xc0/0xe2
| __lock_acquire+0x1515/0x27e0
| lock_acquire+0xc2/0x2b0
| _raw_spin_lock_nested+0x2a/0x40
| ___task_rq_lock+0x4d/0x100
| set_cpus_allowed_force+0x45/0xd0
| select_fallback_rq+0x128/0x140
| migration_cpu_stop+0x34c/0x360
| cpu_stopper_thread+0x9d/0x140
| smpboot_thread_fn+0xf5/0x240
| kthread+0xe4/0x120
| ret_from_fork+0x2ba/0x390
| ret_from_fork_asm+0x11/0x20
| </TASK>

Sebastian