mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Peng Huang <penghuang@google.com>
To: Tejun Heo <tj@kernel.org>, Andrea Righi <arighi@nvidia.com>,
	 Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.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_ext: Block donor on rt_mutex_setprio() switch to SCX
Date: Sat, 21 Nov 2026 20:26:05 -0800	[thread overview]
Message-ID: <20261122042605.2996910-1-penghuang@google.com> (raw)

scx_prepare_setscheduler() and scx_root_enable_workfn() block any
retained proxy donor before entering sched_ext so a blocked task is not
carried across scheduling classes without sched_ext admission.
rt_mutex_setprio() misses this cleanup when PI deboost returns a
blocked RT or DL donor back to ext_sched_class.

Expose scx_block_proxy_donor() via scx_prepare_class_switch() in ext.h
and invoke it in rt_mutex_setprio() before sched_change when
transitioning a task into ext_sched_class. Because rt_mutex_setprio()
has already updated rq->clock, calling scx_block_proxy_donor() directly
matches scx_prepare_setscheduler() and avoids double clock updates.

Fixes: be8be8acb268 ("sched_ext: Block proxy donors before taking control")
Signed-off-by: Peng Huang <penghuang@google.com>
---
 kernel/sched/core.c    |  4 +++-
 kernel/sched/ext/ext.c |  8 ++++++--
 kernel/sched/ext/ext.h | 12 ++++++++++++
 3 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 5ed660f099a5..1a2a317f1194 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -7814,8 +7814,10 @@ void rt_mutex_setprio(struct task_struct *p, struct task_struct *pi_task)
 	prev_class = p->sched_class;
 	next_class = __setscheduler_class(p->policy, prio);
 
-	if (prev_class != next_class)
+	if (prev_class != next_class) {
+		scx_prepare_class_switch(rq, p, next_class);
 		queue_flag |= DEQUEUE_CLASS;
+	}
 
 	scoped_guard (sched_change, p, queue_flag) {
 		/*
diff --git a/kernel/sched/ext/ext.c b/kernel/sched/ext/ext.c
index 10de6bd865e8..4914da605519 100644
--- a/kernel/sched/ext/ext.c
+++ b/kernel/sched/ext/ext.c
@@ -26,10 +26,14 @@ DEFINE_RAW_SPINLOCK(scx_sched_lock);
 
 /*
  * Block a retained proxy donor, telling put_prev_task_scx() that the donor is
- * about to be dequeued and must not be reenqueued.
+ * about to be dequeued and must not be reenqueued. Caller holds @p->pi_lock
+ * and @rq's lock and has already updated @rq's clock.
  */
-static void scx_block_proxy_donor(struct rq *rq, struct task_struct *p)
+void scx_block_proxy_donor(struct rq *rq, struct task_struct *p)
 {
+	lockdep_assert_held(&p->pi_lock);
+	lockdep_assert_rq_held(rq);
+
 	rq->scx.flags |= SCX_RQ_PROXY_BLOCKING;
 	sched_proxy_block_task(rq, p);
 	rq->scx.flags &= ~SCX_RQ_PROXY_BLOCKING;
diff --git a/kernel/sched/ext/ext.h b/kernel/sched/ext/ext.h
index d32bc01071b0..d2e0e7a23639 100644
--- a/kernel/sched/ext/ext.h
+++ b/kernel/sched/ext/ext.h
@@ -19,6 +19,7 @@ void scx_rq_activate(struct rq *rq);
 void scx_rq_deactivate(struct rq *rq);
 int scx_check_setscheduler(struct task_struct *p, int policy);
 void scx_prepare_setscheduler(struct task_struct *p, int policy);
+void scx_block_proxy_donor(struct rq *rq, struct task_struct *p);
 bool task_should_scx(int policy);
 bool scx_allow_ttwu_queue(const struct task_struct *p);
 bool __scx_allow_proxy_exec(const struct task_struct *p);
@@ -54,6 +55,14 @@ static inline bool task_on_scx(const struct task_struct *p)
 	return scx_enabled() && p->sched_class == &ext_sched_class;
 }
 
+static inline void
+scx_prepare_class_switch(struct rq *rq, struct task_struct *p,
+			 const struct sched_class *next_class)
+{
+	if (scx_enabled() && next_class == &ext_sched_class)
+		scx_block_proxy_donor(rq, p);
+}
+
 #ifdef CONFIG_SCHED_CORE
 bool scx_prio_less(const struct task_struct *a, const struct task_struct *b,
 		   bool in_fi);
@@ -73,6 +82,9 @@ static inline void scx_rq_deactivate(struct rq *rq) {}
 static inline int scx_check_setscheduler(struct task_struct *p, int policy) { return 0; }
 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 void
+scx_prepare_class_switch(struct rq *rq, struct task_struct *p,
+			 const struct sched_class *next_class) {}
 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 void scx_proxy_donor_start(struct rq *rq) {}
-- 
2.56.1.750.gf70dc682cf-goog


                 reply	other threads:[~2026-11-22  4:26 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=20261122042605.2996910-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®