mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Peng Huang <penghuang@google.com>
To: Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>, Tejun Heo <tj@kernel.org>,
	 Andrea Righi <arighi@nvidia.com>,
	sched-ext@lists.linux.dev
Cc: David Vernet <void@manifault.com>,
	Changwoo Min <changwoo@igalia.com>,
	 Juri Lelli <juri.lelli@redhat.com>,
	Vincent Guittot <vincent.guittot@linaro.org>,
	 Dietmar Eggemann <dietmar.eggemann@arm.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	 Ben Segall <bsegall@google.com>, Mel Gorman <mgorman@suse.de>,
	 Valentin Schneider <vschneid@redhat.com>,
	K Prateek Nayak <kprateek.nayak@amd.com>,
	 John Stultz <jstultz@google.com>,
	linux-kernel@vger.kernel.org, penghuang@google.com
Subject: [PATCH] sched/proxy, sched_ext: Skip proxy-exec on SCX owner with holding_cpu
Date: Sat, 21 Nov 2026 19:52:54 -0800	[thread overview]
Message-ID: <20261122035254.2891197-1-penghuang@google.com> (raw)

During remote DSQ consumption or dispatch_to_local_dsq(), another CPU
claims @p->scx.holding_cpu and drops the DSQ lock while switching to
@p's source rq lock. Because commit 13ae184e4b82 ("sched_ext: Handle
proxy-exec races in remote DSQ transfers") made proxy execution
compatible with sched_ext, find_proxy_task() on the source CPU can pick
such an owner while holding source rq->lock, forcing the transferring CPU
to abort the placement and bounce the task to reject_dsq once it acquires
source rq->lock.

Like task_on_rq_migrating(), an SCX task with holding_cpu >= 0 is in an
in-flight cross-rq lock handoff. Expose scx_task_held() in ext.h, have
find_proxy_task() yield to rq->idle via resched_idle when an SCX owner
is held so the transfer can complete, and pair the lockless READ_ONCE()
with WRITE_ONCE()/READ_ONCE() on holding_cpu updates.

Signed-off-by: Peng Huang <penghuang@google.com>
---
 kernel/sched/core.c    |  9 +++++++++
 kernel/sched/ext/ext.c | 14 +++++++-------
 kernel/sched/ext/ext.h |  6 ++++++
 3 files changed, 22 insertions(+), 7 deletions(-)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 5ed660f099a5..8aa309d86a6c 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -7108,6 +7108,15 @@ find_proxy_task(struct rq *rq, struct task_struct *donor, struct rq_flags *rf)
 		if (!task_on_rq_queued(owner) || task_cpu(owner) != this_cpu)
 			return NULL;
 
+		/*
+		 * Do not proxy-execute a sched_ext owner while another CPU has
+		 * claimed holding_cpu to transfer it off a DSQ before locking
+		 * this rq; yield the rq lock so the transfer can finish
+		 * without bouncing the owner into reject_dsq.
+		 */
+		if (unlikely(scx_task_held(owner)))
+			goto resched_idle;
+
 		if (owner == p) {
 			/*
 			 * It's possible we interleave with mutex_unlock like:
diff --git a/kernel/sched/ext/ext.c b/kernel/sched/ext/ext.c
index e29c9c18e1ab..5202f750a3b5 100644
--- a/kernel/sched/ext/ext.c
+++ b/kernel/sched/ext/ext.c
@@ -2043,8 +2043,8 @@ void scx_dispatch_dequeue(struct rq *rq, struct task_struct *p)
 		 * but @p->scx.holding_cpu may be set. Clearing holding_cpu
 		 * tells dispatch_to_local_dsq() that it lost to a dequeue.
 		 */
-		if (p->scx.holding_cpu >= 0)
-			p->scx.holding_cpu = -1;
+		if (READ_ONCE(p->scx.holding_cpu) >= 0)
+			WRITE_ONCE(p->scx.holding_cpu, -1);
 
 		return;
 	}
@@ -2067,7 +2067,7 @@ void scx_dispatch_dequeue(struct rq *rq, struct task_struct *p)
 		 * unlink_dsq_and_switch_rq_lock() that it lost the race.
 		 */
 		WARN_ON_ONCE(!list_empty(&p->scx.dsq_list.node));
-		p->scx.holding_cpu = -1;
+		WRITE_ONCE(p->scx.holding_cpu, -1);
 	}
 	p->scx.dsq = NULL;
 
@@ -2978,7 +2978,7 @@ static bool unlink_dsq_and_switch_rq_lock(struct task_struct *p,
 
 	WARN_ON_ONCE(p->scx.holding_cpu >= 0);
 	scx_task_unlink_from_dsq(p, dsq);
-	p->scx.holding_cpu = cpu;
+	WRITE_ONCE(p->scx.holding_cpu, cpu);
 
 	raw_spin_unlock(&dsq->lock);
 	switch_rq_lock(locked_rq, src_rq);
@@ -2993,7 +2993,7 @@ static bool unlink_dsq_and_switch_rq_lock(struct task_struct *p,
 		 * holding_cpu with it so that no caller has to.
 		 */
 		p->scx.dsq = NULL;
-		p->scx.holding_cpu = -1;
+		WRITE_ONCE(p->scx.holding_cpu, -1);
 		scx_wait_dispatching(p);
 		return true;
 	}
@@ -3213,7 +3213,7 @@ static void dispatch_to_local_dsq(struct scx_sched *sch, struct rq *rq,
 	 * under transfer with holding_cpu, release DISPATCHING and then follow
 	 * the same protocol. See unlink_dsq_and_switch_rq_lock().
 	 */
-	p->scx.holding_cpu = raw_smp_processor_id();
+	WRITE_ONCE(p->scx.holding_cpu, raw_smp_processor_id());
 
 	/* store_release ensures that dequeue sees the above */
 	atomic_long_set_release(&p->scx.ops_state, SCX_OPSS_NONE);
@@ -3230,7 +3230,7 @@ static void dispatch_to_local_dsq(struct scx_sched *sch, struct rq *rq,
 		bool fallback = false;
 
 		/* the handshake is over, see unlink_dsq_and_switch_rq_lock() */
-		p->scx.holding_cpu = -1;
+		WRITE_ONCE(p->scx.holding_cpu, -1);
 
 		/*
 		 * If @p is staying on the same rq, there's no need to go
diff --git a/kernel/sched/ext/ext.h b/kernel/sched/ext/ext.h
index d32bc01071b0..f936300b5aea 100644
--- a/kernel/sched/ext/ext.h
+++ b/kernel/sched/ext/ext.h
@@ -54,6 +54,11 @@ static inline bool task_on_scx(const struct task_struct *p)
 	return scx_enabled() && p->sched_class == &ext_sched_class;
 }
 
+static inline bool scx_task_held(const struct task_struct *p)
+{
+	return task_on_scx(p) && READ_ONCE(p->scx.holding_cpu) >= 0;
+}
+
 #ifdef CONFIG_SCHED_CORE
 bool scx_prio_less(const struct task_struct *a, const struct task_struct *b,
 		   bool in_fi);
@@ -75,6 +80,7 @@ static inline void scx_prepare_setscheduler(struct task_struct *p, int policy) {
 static inline bool task_on_scx(const struct task_struct *p) { return false; }
 static inline bool scx_allow_ttwu_queue(const struct task_struct *p) { return true; }
 static inline bool scx_allow_proxy_exec(const struct task_struct *p) { return true; }
+static inline bool scx_task_held(const struct task_struct *p) { return false; }
 static inline void scx_proxy_donor_start(struct rq *rq) {}
 static inline void scx_proxy_reenqueue_retry(struct rq *rq,
 					     struct task_struct *next) {}
-- 
2.56.1.750.gf70dc682cf-goog


                 reply	other threads:[~2026-11-22  3:52 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261122035254.2891197-1-penghuang@google.com \
    --to=penghuang@google.com \
    --cc=arighi@nvidia.com \
    --cc=bsegall@google.com \
    --cc=changwoo@igalia.com \
    --cc=dietmar.eggemann@arm.com \
    --cc=jstultz@google.com \
    --cc=juri.lelli@redhat.com \
    --cc=kprateek.nayak@amd.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mgorman@suse.de \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=sched-ext@lists.linux.dev \
    --cc=tj@kernel.org \
    --cc=vincent.guittot@linaro.org \
    --cc=void@manifault.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®