Linux kernel -stable discussions
 help / color / mirror / Atom feed
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 4/8] sched_ext: Wait for SCX_OPSS_DISPATCHING before reenqueueing a task
Date: Sat, 28 Nov 2026 11:23:47 +0100	[thread overview]
Message-ID: <20261128102535.655465-5-arighi@nvidia.com> (raw)
In-Reply-To: <20261128102535.655465-1-arighi@nvidia.com>

From: Tejun Heo <tj@kernel.org>

commit 7de9a6fb44eae4f05e68c805d58b9c618815adfa upstream.

ebf1ccff79c4 ("sched_ext: Fix ops.dequeue() semantics") moved the final
ops_state store in scx_dispatch_enqueue() after the DSQ unlock so that
the custody update and ops.dequeue() precede it. A task can thus be
found on a DSQ while still SCX_OPSS_DISPATCHING.

The dequeue and core-sched pick paths wait for the state to clear in
ops_dequeue() but the reenqueue paths don't. A reenqueue in that window
runs ops.enqueue() and sets SCX_OPSS_QUEUED before the dispatch has
completed.
The dispatcher's final store then overwrites it with SCX_OPSS_NONE and
finish_dispatch() drops every later dispatch of the task.

Wait for SCX_OPSS_DISPATCHING to clear before dequeueing a task for
reenqueue, the same way ops_dequeue() does.

Fixes: ebf1ccff79c4 ("sched_ext: Fix ops.dequeue() semantics")
Cc: stable@vger.kernel.org # 7.1.x
Signed-off-by: Tejun Heo <tj@kernel.org>
Reviewed-by: Andrea Righi <arighi@nvidia.com>
[arighi: Reuse the 7.2.y backport 43457bf65500, using inline state
 checks in the local and user-DSQ paths in the unsplit ext.c.]
Signed-off-by: Andrea Righi <arighi@nvidia.com>
---
 kernel/sched/ext.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/kernel/sched/ext.c b/kernel/sched/ext.c
index e746ee4d9ce2e..7fbbdac45f27b 100644
--- a/kernel/sched/ext.c
+++ b/kernel/sched/ext.c
@@ -4104,6 +4104,14 @@ static u32 reenq_local(struct scx_sched *sch, struct rq *rq, u64 reenq_flags)
 		if (!local_task_should_reenq(p, &reenq_flags, &reason))
 			continue;
 
+		/*
+		 * The dispatcher stores the final ops_state after dropping the DSQ
+		 * lock, so @p can be found on a DSQ while still
+		 * %SCX_OPSS_DISPATCHING. Reenqueueing @p before that store lands
+		 * would have it clobber the new %SCX_OPSS_QUEUED.
+		 */
+		if (unlikely(atomic_long_read_acquire(&p->scx.ops_state) == SCX_OPSS_DISPATCHING))
+			wait_ops_state(p, SCX_OPSS_DISPATCHING);
 		dispatch_dequeue(rq, p);
 
 		if (WARN_ON_ONCE(p->scx.flags & SCX_TASK_REENQ_REASON_MASK))
@@ -4224,6 +4232,8 @@ static void reenq_user(struct rq *rq, struct scx_dispatch_q *dsq, u64 reenq_flag
 		}
 
 		/* @p is on @dsq, its rq and @dsq are locked */
+		if (unlikely(atomic_long_read_acquire(&p->scx.ops_state) == SCX_OPSS_DISPATCHING))
+			wait_ops_state(p, SCX_OPSS_DISPATCHING);
 		dispatch_dequeue_locked(p, dsq);
 		raw_spin_unlock(&dsq->lock);
 
-- 
2.56.1


  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 ` Andrea Righi [this message]
2026-11-28 10:23 ` [PATCH 7.1.y 5/8] sched_ext: Wait for SCX_OPSS_DISPATCHING before moving tasks off DSQs Andrea Righi
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-5-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