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

From: Sebastian Andrzej Siewior

Date: Thu Dec 03 2026 - 12:42:55 EST


On 2026-12-03 16:37:38 [+0100], Peter Zijlstra wrote:
> > \o/
> >
> > OK, let me go split this into a few patches and commit somewhere.
>
> git://git.kernel.org/pub/scm/linux/kernel/git/peterz/queue.git sched/urgent

Still works. Mind to fold the snippet at the bottom?

I don't hit the corner case:

|__set_cpus_allowed_ptr_locked()
|{
…
| dest_cpu = cpumask_any_and_distribute(cpu_valid_mask, ctx->new_mask);
| if (dest_cpu >= nr_cpu_ids) {
| ret = -EINVAL;
| goto out;
| }
…
|}

from ___migrate_enable() and I'm not sure why that is. It might be
because the CPU mask is never invalid to begin with in this test case.
But a CPU affinity change from userland on a thread which is in a
mg-disabled section might do this.

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 54df37f18ba0e..514c4b5290244 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -3341,9 +3341,9 @@ void force_compatible_cpus_allowed_ptr(struct task_struct *p)
alloc_cpumask_var(&new_mask, GFP_KERNEL);

/*
- * __migrate_task() can fail silently in the face of concurrent
- * offlining of the chosen destination CPU, so take the hotplug
- * lock to ensure that the migration succeeds.
+ * migration_cpu_stop() can silently choose a different CPU in the face
+ * of concurrent offlining of the chosen destination CPU, so take the
+ * hotplug lock to ensure that the migration succeeds.
*/
cpus_read_lock();
if (!cpumask_available(new_mask))

Sebastian