From: "Aaron Lu" <ziqianlu@bytedance.com>
To: "Peter Zijlstra" <peterz@infradead.org>
Cc: <mingo@kernel.org>, <juri.lelli@redhat.com>,
<vincent.guittot@linaro.org>, <dietmar.eggemann@arm.com>,
<rostedt@goodmis.org>, <bsegall@google.com>, <mgorman@suse.de>,
<vschneid@redhat.com>, <kprateek.nayak@amd.com>,
<linux-kernel@vger.kernel.org>, <tj@kernel.org>
Subject: Re: [PATCH 1/7] sched/core: Fix pick_next_task() self recursion
Date: Thu, 3 Sep 2026 19:13:35 +0800 [thread overview]
Message-ID: <20260903111335.GA3594512@bytedance.com> (raw)
In-Reply-To: <20260828104018.378378994@infradead.org>
On Fri, Aug 28, 2026 at 12:17:00PM +0200, Peter Zijlstra wrote:
> It is possible for another sibling to end up in pick_next_task() when:
>
> pick_next_task()
> pick_task()
> sched_class::pick_task()
>
> drops the core wide rq->lock. In this case they end up trampling the core wide
> task selection state, possibly leading to NULL derefs. Detect this case by
> keeping a local copy of core_task_seq, a value that is incremented on
> {en,de}queue and schedule.
>
> Since RETRY_TASK is only possible when a higher priority task gets enqueued
> during the lock break, this must mean core_task_seq will also be incremented
> and is thus completely covered by the seq number mismatch.
For the uncookied no-sync fast path, we should check if core wide is
still uncookied after lock is re-acquired? Something like below, or we
can pick an uncookied task when sibling picked a cookied one:
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index cd0149f5f6693..781f751acdb5b 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -6314,6 +6314,14 @@ pick_next_task(struct rq *rq, struct rq_flags *rf)
goto restart;
if (!next->core_cookie) {
+ /*
+ * pick_task() can drop the core rq lock through newidle balance.
+ * If a sibling established a core-wide cookie while the lock was
+ * dropped, the uncookied no-sync fast path is no longer valid.
+ */
+ if (unlikely(rq->core->core_cookie))
+ goto restart;
+
rq->core_pick = NULL;
rq->core_dl_server = NULL;
/*
We can also do a core_task_seq check above but if sibling picked an
uncookied task, it's actually OK for this rq to go this fast path so I
chose to check rq->core->core_cookie here.
next prev parent reply other threads:[~2026-09-03 11:14 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-28 10:16 [PATCH 0/7] sched: core-sched fixes and balancing Peter Zijlstra
2026-08-28 10:17 ` [PATCH 1/7] sched/core: Fix pick_next_task() self recursion Peter Zijlstra
2026-09-03 11:13 ` Aaron Lu [this message]
2026-09-25 14:33 ` Peter Zijlstra
2026-08-28 10:17 ` [PATCH 2/7] sched/core: Simplify/fix time updates Peter Zijlstra
2026-09-02 5:38 ` Tejun Heo
2026-09-02 14:32 ` Peter Zijlstra
2026-08-28 10:17 ` [PATCH 3/7] sched/core: Allow newidle for core-sched Peter Zijlstra
2026-08-28 10:17 ` [PATCH 4/7] sched/rt: Add early exit on balance path Peter Zijlstra
2026-08-28 10:17 ` [PATCH 5/7] sched/fair: Reflow pick_task_fair() / newidle Peter Zijlstra
2026-08-28 10:17 ` [PATCH 6/7] sched/fair: Push sched_balance_newidle() unlock down Peter Zijlstra
2026-08-28 10:17 ` [PATCH 7/7] sched: Remove sched_class::balance() Peter Zijlstra
2026-09-01 23:47 ` Tejun Heo
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=20260903111335.GA3594512@bytedance.com \
--to=ziqianlu@bytedance.com \
--cc=bsegall@google.com \
--cc=dietmar.eggemann@arm.com \
--cc=juri.lelli@redhat.com \
--cc=kprateek.nayak@amd.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mgorman@suse.de \
--cc=mingo@kernel.org \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=tj@kernel.org \
--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.