From: sashiko-bot@kernel.org
To: "Andrea Righi" <arighi@nvidia.com>
Cc: sched-ext@lists.linux.dev
Subject: Re: [PATCH 05/11] sched_ext: Fix TOCTOU race in consume_remote_task()
Date: Thu, 16 Jul 2026 14:39:18 +0000 [thread overview]
Message-ID: <20260716143918.D02AC1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260716132229.61603-6-arighi@nvidia.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Infinite livelock loop in scx_consume_dispatch_q() when falling back to the global DSQ.
--
--- Patch [5]: [PATCH 05/11] sched_ext: Fix TOCTOU race in consume_remote_task() ---
commit bf5934bbeaad49172aa99cf40eef02a6a7ea4bd6
Author: Andrea Righi <arighi@nvidia.com>
sched_ext: Fix TOCTOU race in consume_remote_task()
This commit attempts to fix a TOCTOU race in consume_remote_task() when
pulling a task from a non-local DSQ by deferring the validation until the
task's source rq is locked. It splits the check into lockless and locked
variants, and falls back to enqueueing the task to the global DSQ if the
locked check fails.
> diff --git a/kernel/sched/ext/ext.c b/kernel/sched/ext/ext.c
> index 04fc34a7ded65..6699144b36e5e 100644
> --- a/kernel/sched/ext/ext.c
> +++ b/kernel/sched/ext/ext.c
[ ... ]
> @@ -2480,6 +2496,28 @@ static bool consume_remote_task(struct scx_sched *sch, struct rq *this_rq,
> struct scx_dispatch_q *dsq, struct rq *src_rq)
> {
> if (unlink_dsq_and_switch_rq_lock(p, dsq, this_rq, src_rq)) {
> + /*
> + * Whether @p may be migrated to @this_rq may have changed while
> + * switching rq locks. This is a kernel-side race, not an invalid BPF
> + * placement request, so don't abort the scheduler on failure. Fall
> + * back to the global DSQ, where normal consumption filters can select
> + * a valid destination without forcing the task onto the source local
> + * DSQ.
> + */
> + if (unlikely(!task_can_move_from_locked_rq(sch, p, this_rq, false))) {
> + p->scx.dsq = NULL;
> + p->scx.holding_cpu = -1;
> + scx_dispatch_enqueue(sch, src_rq,
> + find_global_dsq(sch, task_cpu(p)), p,
> + enq_flags | SCX_ENQ_CLEAR_OPSS |
> + SCX_ENQ_GDSQ_FALLBACK);
> + if (sched_class_above(p->sched_class,
> + src_rq->donor->sched_class))
> + resched_curr(src_rq);
> + switch_rq_lock(src_rq, this_rq);
> + return false;
[Severity: High]
Can this fallback path cause an infinite livelock if the DSQ being scanned
is already the global DSQ?
When scx_consume_dispatch_q() locklessly picks a task that is executing on a
remote CPU, task_can_move_from_locked_rq() correctly fails.
Because consume_remote_task() enqueues the task back to find_global_dsq()
and returns false, scx_consume_dispatch_q() will react to the false return
value by jumping to its retry label.
If scx_consume_dispatch_q() was scanning the global DSQ:
kernel/sched/ext/ext.c:scx_consume_dispatch_q() {
retry:
...
nldsq_for_each_task(p, dsq) {
...
if (task_can_run_on_remote_rq(sch, p, rq, false)) {
if (likely(consume_remote_task(sch, rq, p, enq_flags,
dsq, task_rq)))
return true;
goto retry;
}
}
...
}
Does this cause the scanner to jump back to retry, rescan the global DSQ,
find the exact same task again, fail the locked check again, and repeat
the sequence indefinitely while holding runqueue locks?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260716132229.61603-1-arighi@nvidia.com?part=5
next prev parent reply other threads:[~2026-07-16 14:39 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-16 13:20 [PATCHSET v7 sched_ext/for-7.3] sched: Make proxy execution compatible with sched_ext Andrea Righi
2026-07-16 13:20 ` [PATCH 01/11] sched: Make NOHZ CFS bandwidth checks follow proxy donor Andrea Righi
2026-07-16 13:20 ` [PATCH 02/11] sched: Add helper to block retained proxy donors Andrea Righi
2026-07-16 13:20 ` [PATCH 03/11] sched_ext: Block proxy donors across scheduler transitions Andrea Righi
2026-07-16 13:20 ` [PATCH 04/11] sched_ext: Fix ops.running/stopping() pairing for proxy-exec donors Andrea Righi
2026-07-16 13:20 ` [PATCH 05/11] sched_ext: Fix TOCTOU race in consume_remote_task() Andrea Righi
2026-07-16 14:39 ` sashiko-bot [this message]
2026-07-16 21:29 ` Tejun Heo
2026-07-16 21:38 ` Tejun Heo
2026-07-16 13:20 ` [PATCH 06/11] sched_ext: Split curr|donor references properly Andrea Righi
2026-07-16 15:02 ` sashiko-bot
2026-07-16 13:20 ` [PATCH 07/11] sched_ext: Handle blocked donor migration with proxy execution Andrea Righi
2026-07-16 15:22 ` sashiko-bot
2026-07-16 13:20 ` [PATCH 08/11] sched_ext: Delegate proxy donor admission to BPF schedulers Andrea Righi
2026-07-16 13:20 ` [PATCH 09/11] sched_ext: Add selftest for blocked donor admission Andrea Righi
2026-07-16 13:20 ` [PATCH 10/11] sched_ext: scx_qmap: Add proxy execution support Andrea Righi
2026-07-16 15:54 ` sashiko-bot
2026-07-16 13:20 ` [PATCH 11/11] sched: Allow enabling proxy exec with sched_ext Andrea Righi
-- strict thread matches above, loose matches on Subject: below --
2026-07-15 20:54 [PATCHSET v6 sched_ext/for-7.3] sched: Make proxy execution compatible " Andrea Righi
2026-07-15 20:54 ` [PATCH 05/11] sched_ext: Fix TOCTOU race in consume_remote_task() Andrea Righi
2026-07-15 21:14 ` sashiko-bot
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=20260716143918.D02AC1F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=arighi@nvidia.com \
--cc=sashiko-reviews@lists.linux.dev \
--cc=sched-ext@lists.linux.dev \
/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.