This is a note to let you know that I've just added the patch titled sched: Optimize migration_cpu_stop() to the 5.11-stable tree which can be found at: http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary The filename of the patch is: sched-optimize-migration_cpu_stop.patch and it can be found in the queue-5.11 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let <stable@xxxxxxxxxxxxxxx> know about it. >From 3f1bc119cd7fc987c8ed25ffb717f99403bb308c Mon Sep 17 00:00:00 2001 From: Peter Zijlstra <peterz@xxxxxxxxxxxxx> Date: Wed, 24 Feb 2021 11:21:35 +0100 Subject: sched: Optimize migration_cpu_stop() From: Peter Zijlstra <peterz@xxxxxxxxxxxxx> commit 3f1bc119cd7fc987c8ed25ffb717f99403bb308c upstream. When the purpose of migration_cpu_stop() is to migrate the task to 'any' valid CPU, don't migrate the task when it's already running on a valid CPU. Fixes: 6d337eab041d ("sched: Fix migrate_disable() vs set_cpus_allowed_ptr()") Cc: stable@xxxxxxxxxx Signed-off-by: Peter Zijlstra (Intel) <peterz@xxxxxxxxxxxxx> Signed-off-by: Ingo Molnar <mingo@xxxxxxxxxx> Reviewed-by: Valentin Schneider <valentin.schneider@xxxxxxx> Link: https://lkml.kernel.org/r/20210224131355.569238629@xxxxxxxxxxxxx Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> --- kernel/sched/core.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -1936,14 +1936,25 @@ static int migration_cpu_stop(void *data complete = true; } - if (dest_cpu < 0) + if (dest_cpu < 0) { + if (cpumask_test_cpu(task_cpu(p), &p->cpus_mask)) + goto out; + dest_cpu = cpumask_any_distribute(&p->cpus_mask); + } if (task_on_rq_queued(p)) rq = __migrate_task(rq, &rf, p, dest_cpu); else p->wake_cpu = dest_cpu; + /* + * XXX __migrate_task() can fail, at which point we might end + * up running on a dodgy CPU, AFAICT this can only happen + * during CPU hotplug, at which point we'll get pushed out + * anyway, so it's probably not a big deal. + */ + } else if (pending) { /* * This happens when we get migrated between migrate_enable()'s Patches currently in stable-queue which might be from peterz@xxxxxxxxxxxxx are queue-5.11/powerpc-perf-fix-handling-of-privilege-level-checks-in-perf-interrupt-context.patch queue-5.11/sched-fix-migration_cpu_stop-requeueing.patch queue-5.11/sched-simplify-set_affinity_pending-refcounts.patch queue-5.11/perf-traceevent-ensure-read-cmdlines-are-null-terminated.patch queue-5.11/perf-core-flush-pmu-internal-buffers-for-per-cpu-eve.patch queue-5.11/sched-simplify-migration_cpu_stop.patch queue-5.11/sched-membarrier-fix-missing-local-execution-of-ipi_sync_rq_state.patch queue-5.11/x86-unwind-orc-disable-kasan-checking-in-the-orc-unwinder-part-2.patch queue-5.11/arm64-perf-fix-64-bit-event-counter-read-truncation.patch queue-5.11/sched-collate-affine_move_task-stoppers.patch queue-5.11/sched-fix-affine_move_task-self-concurrency.patch queue-5.11/stop_machine-mark-helpers-__always_inline.patch queue-5.11/seqlock-lockdep-fix-seqcount_latch_init.patch queue-5.11/sched-optimize-migration_cpu_stop.patch queue-5.11/perf-build-fix-ccache-usage-in-cc-when-generating-arch-errno-table.patch queue-5.11/mm-userfaultfd-fix-memory-corruption-due-to-writeprotect.patch queue-5.11/perf-x86-intel-set-perf_attach_sched_cb-for-large-pe.patch