Re: [PATCH v3] sched: Reset cpumask if __migrate_task() failed for migration_cpu_stop()
From: Karl Mehltretter
Date: Sat Nov 21 2026 - 09:39:37 EST
On Fri, 20 Nov 2026 18:16:58 +0100, Sebastian Andrzej Siewior wrote:
> syzbot reported a race of assigning a CPU affinity during CPU hotplug
> operation.
I tested the patch on PREEMPT_RT with syzbot's config, changing IRQ
affinities while SMT was switched off and on. The warning is gone with
the patch. Without it, every boot warned, and one also hit a BUG:
kernel BUG at kernel/sched/core.c:3642!
try_to_wake_up+0x85f/0x1320
irq_do_set_affinity+0x42c/0x5d0
RIP: 0010:select_fallback_rq+0x1f6/0x200
Kernel panic - not syncing: Fatal exception in interrupt
> There are a few spots where set_cpus_allowed_ptr() does not use
> cpus_read_lock(). In the IRQ thread case, there will be an update
> following if the CPU goes offline so it is not really needed to block
> CPU hotplug during the update.
sched_setaffinity() is one of those spots, but a user task gets no
later update.
With the patch, a test that changed the affinity of user threads in the
same setup read back a CPU outside the requested mask in about 1 of 5000
calls, on RT and non-RT. Without the patch it never did.
Thanks,
Karl