[PATCH v2 0/3] sched/core: Fix stale core_pick and forced idle after SM_IDLE fast path
From: Ibrahim Elshahed
Date: Fri Nov 20 2026 - 05:58:38 EST
Under core scheduling, a core-wide selection can leave a pick for an
idle sibling in rq->core_pick and force the other sibling idle. If the
picked task is migrated away before the idle sibling schedules, and it
was that sibling's only task, the SM_IDLE fast path (v6.12+) sends the
sibling back to idle without a pick. The core then stays forced idle
with nothing running, and the forced idle accounting keeps using the
stale pointer, also after the task and its cgroup are freed.
Patch 1 clears rq->core_pick when the picked task is dequeued. Patch 2
stops idle CPUs from taking the SM_IDLE fast path while the core is
forced idle. Patch 3 adds a selftest for the stuck forced idle and the
use-after-free.
Changes in v2:
- Patch 2: drop the rq->core_pick check. With patch 1 a pending pick
is always queued on its rq, so an empty runqueue has none (Peter).
Reword the subject and changelog accordingly.
- Patch 3: new, a selftest derived from the reproducer (Peter). It
checks for stuck forced idle and, with cgroup v2 and schedstats,
frees each stalled task with its cgroup to catch the use-after-free.
- v1: https://lore.kernel.org/lkml/20261117142704.6878-1-lshahed@xxxxxxxxx/
Testing, on tip sched/core d7e670601af6, schedstats=enable:
- KVM guest, 2 cores x 2 threads, idle=halt, the v1 reproducer. Without
the series, both boots oopsed in __cgroup_account_cputime_field()
from __sched_core_account_forceidle(). With v2, 6 boots of 240 s
(972562 attempts) showed no stuck forced idle and no oops; the
no-migrate control (194596 attempts) was clean as well.
- cs_forceidle_test through run_kselftest.sh in the same guest, 30 s
runs. Without the series, all 11 runs crashed in
__cgroup_account_cputime_field() 0.4-2.2 s into the test (with
KASAN, 2 of 2 first reported a slab-use-after-free in
__account_forceidle_time()); with -n, which skips freeing the
stalled tasks, 72, 59 and 67 stalls in about 20000 attempts each.
With v2, 10 of 10 runs passed with 0 stalls and nothing in dmesg (2
with KASAN, 2 booted without schedstats). With patch 1 alone, 42, 43
and 34 stalls and no crash; with patch 2 alone, 0 stalls.
- Builds with SCHED_CORE on and off, SCHEDSTATS on and off,
SCHED_CLASS_EXT, PREEMPT_RT, tinyconfig and allnoconfig; W=1 clean in
kernel/sched/, and each patch builds on its own.
Ibrahim Elshahed (3):
sched/core: Clear a stale rq->core_pick after dequeue
sched/core: Don't take the idle fast path while the core is forced
idle
selftests/sched: Add a test for stuck forced idle under core
scheduling
kernel/sched/core.c | 28 +-
tools/testing/selftests/sched/.gitignore | 1 +
tools/testing/selftests/sched/Makefile | 1 +
tools/testing/selftests/sched/config | 2 +-
.../selftests/sched/cs_forceidle_test.c | 471 ++++++++++++++++++
5 files changed, 500 insertions(+), 3 deletions(-)
create mode 100644 tools/testing/selftests/sched/cs_forceidle_test.c
base-commit: d7e670601af6c564ccf6d3b2ddf70ee4f41a6d1c
--
2.47.3