From: Ibrahim Elshahed <lshahed@amazon.de>
To: Ingo Molnar <mingo@redhat.com>,
Peter Zijlstra <peterz@infradead.org>,
Juri Lelli <juri.lelli@redhat.com>,
Vincent Guittot <vincent.guittot@linaro.org>
Cc: Dietmar Eggemann <dietmar.eggemann@arm.com>,
Steven Rostedt <rostedt@goodmis.org>,
Ben Segall <bsegall@google.com>, Mel Gorman <mgorman@suse.de>,
Valentin Schneider <vschneid@redhat.com>,
K Prateek Nayak <kprateek.nayak@amd.com>,
Josh Don <joshdon@google.com>, Shuah Khan <shuah@kernel.org>,
<linux-kselftest@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<nh-open-source@amazon.com>, Fernand Sieber <sieberf@amazon.com>,
Roman Kagan <rkagan@amazon.de>
Subject: [PATCH v2 0/3] sched/core: Fix stale core_pick and forced idle after SM_IDLE fast path
Date: Fri, 20 Nov 2026 10:58:19 +0000 [thread overview]
Message-ID: <20261120105822.7770-1-lshahed@amazon.de> (raw)
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@amazon.de/
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
next reply other threads:[~2026-11-20 10:58 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-20 10:58 Ibrahim Elshahed [this message]
2026-11-20 10:58 ` [PATCH v2 1/3] sched/core: Clear a stale rq->core_pick after dequeue Ibrahim Elshahed
2026-11-20 10:58 ` [PATCH v2 2/3] sched/core: Don't take the idle fast path while the core is forced idle Ibrahim Elshahed
2026-11-20 10:58 ` [PATCH v2 3/3] selftests/sched: Add a test for stuck forced idle under core scheduling Ibrahim Elshahed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261120105822.7770-1-lshahed@amazon.de \
--to=lshahed@amazon.de \
--cc=bsegall@google.com \
--cc=dietmar.eggemann@arm.com \
--cc=joshdon@google.com \
--cc=juri.lelli@redhat.com \
--cc=kprateek.nayak@amd.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=mgorman@suse.de \
--cc=mingo@redhat.com \
--cc=nh-open-source@amazon.com \
--cc=peterz@infradead.org \
--cc=rkagan@amazon.de \
--cc=rostedt@goodmis.org \
--cc=shuah@kernel.org \
--cc=sieberf@amazon.com \
--cc=vincent.guittot@linaro.org \
--cc=vschneid@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.