From: Andrea Righi <arighi@nvidia.com>
To: stable@vger.kernel.org, Tejun Heo <tj@kernel.org>,
David Vernet <void@manifault.com>,
Changwoo Min <changwoo@igalia.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Sasha Levin <sashal@kernel.org>,
Kuba Piecuch <jpiecuch@google.com>,
fangqiurong <fangqiurong@kylinos.cn>,
Rahad Bhuiya <rahadbhuiya2021@gmail.com>,
sched-ext@lists.linux.dev
Subject: [PATCH 7.1.y 5/8] sched_ext: Wait for SCX_OPSS_DISPATCHING before moving tasks off DSQs
Date: Sat, 28 Nov 2026 11:23:48 +0100 [thread overview]
Message-ID: <20261128102535.655465-6-arighi@nvidia.com> (raw)
In-Reply-To: <20261128102535.655465-1-arighi@nvidia.com>
From: Kuba Piecuch <jpiecuch@google.com>
commit 2935062be77113c1c4565ca9d0c72180449aafee upstream.
A task can be found on a non-local DSQ while the CPU which dispatched it
is still running ops.dequeue() and hasn't cleared SCX_OPSS_DISPATCHING.
The DSQ consume and move paths don't wait for the dispatch to finish and
can operate on the task concurrently with the dispatcher.
Call scx_wait_dispatching() in scx_move_local_task_to_local_dsq(),
unlink_dsq_and_switch_rq_lock() and move_task_between_dsqs() before they
operate on the task. In scx_move_local_task_to_local_dsq(), wait before
scx_resolve_local_dsq() as it may update p->scx.flags.
Fixes: ebf1ccff79c4 ("sched_ext: Fix ops.dequeue() semantics")
Fixes: cb86607ada73 ("sched_ext: Don't run ops.dequeue() with a DSQ lock held")
Cc: stable@vger.kernel.org # 7.1.x
Reviewed-by: Andrea Righi <arighi@nvidia.com>
Assisted-by: Claude:claude-opus-5.5
Signed-off-by: Kuba Piecuch <jpiecuch@google.com>
Signed-off-by: Tejun Heo <tj@kernel.org>
[arighi: Reuse the 7.2.y backport cc2839946328, with inline checks and
the older static DSQ move and rq-lock helpers.]
Signed-off-by: Andrea Righi <arighi@nvidia.com>
---
kernel/sched/ext.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/kernel/sched/ext.c b/kernel/sched/ext.c
index 7fbbdac45f27b..f47f0349935c6 100644
--- a/kernel/sched/ext.c
+++ b/kernel/sched/ext.c
@@ -2249,6 +2249,8 @@ static void move_local_task_to_local_dsq(struct scx_sched *sch,
lockdep_assert_rq_held(dst_rq);
WARN_ON_ONCE(p->scx.holding_cpu >= 0);
+ if (unlikely(atomic_long_read_acquire(&p->scx.ops_state) == SCX_OPSS_DISPATCHING))
+ wait_ops_state(p, SCX_OPSS_DISPATCHING);
if (enq_flags & (SCX_ENQ_HEAD | SCX_ENQ_PREEMPT))
list_add(&p->scx.dsq_list.node, &dst_dsq->list);
@@ -2419,8 +2421,13 @@ static bool unlink_dsq_and_lock_src_rq(struct task_struct *p,
raw_spin_rq_lock(src_rq);
/* task_rq couldn't have changed if we're still the holding cpu */
- return likely(p->scx.holding_cpu == cpu) &&
- !WARN_ON_ONCE(src_rq != task_rq(p));
+ if (likely(p->scx.holding_cpu == cpu) && !WARN_ON_ONCE(src_rq != task_rq(p))) {
+ if (unlikely(atomic_long_read_acquire(&p->scx.ops_state) == SCX_OPSS_DISPATCHING))
+ wait_ops_state(p, SCX_OPSS_DISPATCHING);
+ return true;
+ }
+
+ return false;
}
static bool consume_remote_task(struct rq *this_rq,
@@ -2466,6 +2473,9 @@ static struct rq *move_task_between_dsqs(struct scx_sched *sch,
lockdep_assert_held(&src_dsq->lock);
lockdep_assert_rq_held(src_rq);
+ if (unlikely(atomic_long_read_acquire(&p->scx.ops_state) == SCX_OPSS_DISPATCHING))
+ wait_ops_state(p, SCX_OPSS_DISPATCHING);
+
if (dst_dsq->id == SCX_DSQ_LOCAL) {
dst_rq = container_of(dst_dsq, struct rq, scx.local_dsq);
if (src_rq != dst_rq &&
--
2.56.1
next prev parent reply other threads:[~2026-11-28 10:26 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-28 10:23 [PATCH 7.1.y 0/8] sched_ext: Backport dispatch and task-state fixes Andrea Righi
2026-11-28 10:23 ` [PATCH 7.1.y 1/8] sched_ext: Check remote rq eligibility under task's rq lock Andrea Righi
2026-11-28 10:23 ` [PATCH 7.1.y 2/8] sched_ext: Don't run ops.dequeue() with a DSQ lock held Andrea Righi
2026-11-28 10:23 ` [PATCH 7.1.y 3/8] sched_ext: Call ops.dequeue() when a task arrives on a remote local DSQ Andrea Righi
2026-11-28 10:23 ` [PATCH 7.1.y 4/8] sched_ext: Wait for SCX_OPSS_DISPATCHING before reenqueueing a task Andrea Righi
2026-11-28 10:23 ` Andrea Righi [this message]
2026-11-28 10:23 ` [PATCH 7.1.y 6/8] sched_ext: Generate qseq from a per-task counter Andrea Righi
2026-11-28 10:23 ` [PATCH 7.1.y 7/8] sched_ext: Reset dsq_vtime and slice when a task leaves SCX Andrea Righi
2026-11-28 10:23 ` [PATCH 7.1.y 8/8] sched_ext: Reset task fields on exit of an SCX_TASK_READY task 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=20261128102535.655465-6-arighi@nvidia.com \
--to=arighi@nvidia.com \
--cc=changwoo@igalia.com \
--cc=fangqiurong@kylinos.cn \
--cc=gregkh@linuxfoundation.org \
--cc=jpiecuch@google.com \
--cc=rahadbhuiya2021@gmail.com \
--cc=sashal@kernel.org \
--cc=sched-ext@lists.linux.dev \
--cc=stable@vger.kernel.org \
--cc=tj@kernel.org \
--cc=void@manifault.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox