From: sashiko-bot@kernel.org
To: "Andrea Righi" <arighi@nvidia.com>
Cc: sched-ext@lists.linux.dev
Subject: Re: [PATCH 3/9] sched_ext: Fix TOCTOU race in consume_remote_task()
Date: Mon, 06 Jul 2026 07:24:33 +0000 [thread overview]
Message-ID: <20260706072434.65F1D1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260706070410.282826-4-arighi@nvidia.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Pre-existing tracking bug in dispatch_to_local_dsq(): it drops the locked_rq lock without clearing the scx_locked_rq_state tracking, which triggers a lockdep crash if a nested ops.dequeue() callback executes in the fallback path.
--
commit aff47a8e37704807f1fefe8e15adcb99c8836308
Author: Andrea Righi <arighi@nvidia.com>
sched_ext: Fix TOCTOU race in consume_remote_task()
This commit addresses a TOCTOU race condition in sched_ext during task
migration between runqueues. It ensures task eligibility is re-evaluated
after locking the source runqueue and properly tracks runqueue lock state
while dropping the lock to avoid lockdep warnings.
> diff --git a/kernel/sched/ext/ext.c b/kernel/sched/ext/ext.c
> index 242f6ffbba350..4c6cd694c86db 100644
> --- a/kernel/sched/ext/ext.c
> +++ b/kernel/sched/ext/ext.c
[ ... ]
> @@ -2240,20 +2246,58 @@ static bool unlink_dsq_and_lock_src_rq(struct task_struct *p,
> !WARN_ON_ONCE(src_rq != task_rq(p));
> }
>
> -static bool consume_remote_task(struct rq *this_rq,
> +static bool consume_remote_task(struct scx_sched *sch, struct rq *this_rq,
> struct task_struct *p, u64 enq_flags,
> struct scx_dispatch_q *dsq, struct rq *src_rq)
> {
> + struct rq *tracked_rq = scx_locked_rq();
> + bool consumed = false;
> +
> + /*
> + * consume_remote_task() may be called from an SCX op with @this_rq
> + * recorded as the currently locked rq. Clear the tracking while the rq
> + * lock is dropped so nested callbacks don't save and later try to restore
> + * an rq which isn't locked anymore.
> + */
> + if (tracked_rq) {
> + WARN_ON_ONCE(tracked_rq != this_rq);
> + update_locked_rq(NULL);
> + }
> raw_spin_rq_unlock(this_rq);
[Severity: High]
This is a pre-existing issue, but does dispatch_to_local_dsq() have a similar
problem with stale rq lock tracking?
Similar to consume_remote_task(), dispatch_to_local_dsq() drops the locked_rq
without temporarily clearing scx_locked_rq_state:
kernel/sched/ext/ext.c:dispatch_to_local_dsq() {
...
/* switch to @src_rq lock */
if (locked_rq != src_rq) {
raw_spin_rq_unlock(locked_rq);
locked_rq = src_rq;
raw_spin_rq_lock(src_rq);
}
...
}
If task_can_run_on_remote_rq() fails, it falls back to enqueueing to the global
DSQ:
} else if (unlikely(!task_can_run_on_remote_rq(sch, p, dst_rq, true))) {
p->scx.holding_cpu = -1;
fallback = true;
scx_dispatch_enqueue(sch, src_rq, find_global_dsq(sch, task_cpu(p)),
p, enq_flags | SCX_ENQ_GDSQ_FALLBACK);
When scx_dispatch_enqueue() triggers the nested ops.dequeue() callback via
SCX_CALL_OP_TASK, the stale, unlocked rq state is saved and later restored
in SCX_CALL_OP, which triggers a lockdep assertion failure.
Could this lead to a lockdep crash if a nested ops.dequeue() executes in the
fallback path?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260706070410.282826-1-arighi@nvidia.com?part=3
next prev parent reply other threads:[~2026-07-06 7:24 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-06 6:50 [PATCHSET v3 sched_ext/for-7.3] sched: Make proxy execution compatible with sched_ext Andrea Righi
2026-07-06 6:50 ` [PATCH 1/9] sched/core: Drop mutex locks before proxy rescheduling Andrea Righi
2026-07-06 8:45 ` K Prateek Nayak
2026-07-06 6:50 ` [PATCH 2/9] sched_ext: Split curr|donor references properly Andrea Righi
2026-07-06 7:35 ` sashiko-bot
2026-07-06 6:50 ` [PATCH 3/9] sched_ext: Fix TOCTOU race in consume_remote_task() Andrea Righi
2026-07-06 7:24 ` sashiko-bot [this message]
2026-07-06 6:50 ` [PATCH 4/9] sched_ext: Handle blocked donor migration with proxy execution Andrea Righi
2026-07-06 7:21 ` sashiko-bot
2026-07-06 6:51 ` [PATCH 5/9] sched_ext: Fix ops.running/stopping() pairing for proxy-exec donors Andrea Righi
2026-07-06 6:51 ` [PATCH 6/9] sched_ext: Delegate proxy donor admission to BPF schedulers Andrea Righi
2026-07-06 7:36 ` sashiko-bot
2026-07-06 7:49 ` K Prateek Nayak
2026-07-06 6:51 ` [PATCH 7/9] sched_ext: Add selftest for blocked donor admission Andrea Righi
2026-07-06 6:51 ` [PATCH 8/9] sched_ext: scx_qmap: Add proxy execution support Andrea Righi
2026-07-06 6:51 ` [PATCH 9/9] sched: Allow enabling proxy exec with sched_ext Andrea Righi
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=20260706072434.65F1D1F000E9@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.