mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] sched_ext: Block donor on rt_mutex_setprio() switch to SCX
@ 2026-11-22  4:26 Peng Huang
  0 siblings, 0 replies; only message in thread
From: Peng Huang @ 2026-11-22  4:26 UTC (permalink / raw)
  To: Tejun Heo, Andrea Righi, Peter Zijlstra, Ingo Molnar, sched-ext
  Cc: David Vernet, Changwoo Min, Juri Lelli, Vincent Guittot,
	Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
	Valentin Schneider, K Prateek Nayak, John Stultz, linux-kernel,
	penghuang

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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-22  4:26 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-22  4:26 [PATCH] sched_ext: Block donor on rt_mutex_setprio() switch to SCX Peng Huang

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®