Skip to content

sched/fair: Never pick the misfit task as its own rotation partner - #927

Merged
RyanTheTide merged 1 commit into
aurora-silicon:integration/aurorafrom
jgoyvaerts:m4pro/sched-misfit-self-rotation
Nov 5, 2026
Merged

RyanTheTide merged 1 commit into
aurora-silicon:integration/aurorafrom
jgoyvaerts:m4pro/sched-misfit-self-rotation

Conversation

@jgoyvaerts

Copy link
Copy Markdown
Contributor

Fixes a hard hang in the misfit rotation from #690 (2d24fbce39a3).

misfit_rotate_work() checks that the misfit task p is still on src_cpu, then reads the bigger CPUs' rq->curr without taking their locks. If load balancing pulls p onto a bigger CPU in that window, the scan can return p itself. migrate_swap(p, p) then runs migrate_swap_stop(), which takes p->pi_lock twice through guard(double_raw_spinlock) with IRQs off. That CPU never comes back, and the other CPU sits in multi_cpu_stop().

The fix skips p during the scan, which is how task_numa_compare() already handles the same case (cur == env->p).

Seen on the J616s (M4 Pro)

The machine hung hard with every core busy (a FEX build next to a game under emulation):

  • CPU 5 stopped answering IPIs and the NMI backtrace.
  • RCU expedited grace periods stalled.
  • The misfit_rotate_mutex owner was stuck in stop_two_cpus().

It needed a hard reset. Setting NO_MISFIT_ROTATE in /sys/kernel/debug/sched/features avoids the hang until this fix is in.

Testing

  • This commit, on an otherwise identical kernel/sched, has run on our daily J616s kernel since 2026-11-03 21:27 with MISFIT_ROTATE on, through the same all-core loads (game, FEX builds, kernel builds). No hang or RCU stall since.
  • checkpatch is clean.

I have no deterministic reproducer: the window is a lockless read racing load balancing.

🤖 Generated with Claude Code

misfit_rotate_work() checks that p is still on src_cpu, then scans the
bigger CPUs' rq->curr without locks. Load balancing can pull the misfit
task p onto an idle bigger CPU in between, so the scan can return p
itself. migrate_swap(p, p) then runs migrate_swap_stop() on dst_cpu,
which takes double_raw_spinlock(&p->pi_lock, &p->pi_lock) with IRQs off
and spins forever, while src_cpu spins in multi_cpu_stop().

Seen on m4.120: CPU 5 stopped answering IPIs and the NMI backtrace, RCU
stalled, the misfit_rotate_mutex owner sat in stop_two_cpus(), and the
desktop froze until a hard reboot.

Skip p when scanning for a partner.

Fixes: 2d24fbc ("sched/fair: Rotate misfit tasks with tasks on busy bigger CPUs")
Signed-off-by: Jonathan Goyvaerts <jonathan.goyvaerts@gmail.com>
Assisted-by: LLM
@RyanTheTide

Copy link
Copy Markdown
Contributor

Merge train (MTL, 06/11). Gates passed on test tree 0412501 (integration/aurora 2661d71 + this batch):

  • Signed-off-by from the author on every commit. Adversarial review done.
  • W=1 on the touched objects: 0 new warnings. KUnit: drm/apple 112/113 (1 skip), hid 19/19, SEP 158/163 (the 4 known apple_sep_host_store failures, profile tests all pass). dt_binding_check clean. apple-dcp host selftests 86/86, run-host-tests at base parity (with Merge train: G17 hang confinement (#928) plus its host-test fixture #989's fixture).
  • Regression boots of 7.3.0-aurora-mtl1106a, compared with the fleet16/fleet17 rows: M2, M1 Pro, J700 and J616s all clean (0 err-level lines, 0 AVCs, displays, Wi-Fi, BT, Touch ID, camera, speakers at minimal volume with speakerguardd, s2idle, perf at parity).

@RyanTheTide
RyanTheTide merged commit bb22bd6 into aurora-silicon:integration/aurora Nov 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants