* [PATCH] sched_ext, rcu: Eject BPF scheduler on RCU CPU stall panic
@ 2025-06-24 22:49 David Dai
2025-06-24 23:06 ` Tejun Heo
0 siblings, 1 reply; 2+ messages in thread
From: David Dai @ 2025-06-24 22:49 UTC (permalink / raw)
To: tj, void, arighi, changwoo, paulmck
Cc: david.dai, davidai, sched-ext, linux-kernel, rcu, kernel-team
For systems using a sched_ext scheduler and has panic_on_rcu_stall
enabled, try kicking out the current scheduler before issuing a panic.
While there are numerous reasons for RCU CPU stalls that are not
directly attributed to the scheduler, deferring the panic gives
sched_ext an opportunity to provide additional debug info when ejecting
the current scheduler. Also, handling the event more gracefully allows
us to potentially recover the system instead of incurring additional
down time.
Suggested-by: Tejun Heo <tj@kernel.org>
Reviewed-by: Paul E. McKenney <paulmck@kernel.org>
Signed-off-by: David Dai <david.dai@linux.dev>
---
include/linux/sched/ext.h | 2 ++
kernel/rcu/tree_stall.h | 7 +++++++
kernel/sched/ext.c | 35 +++++++++++++++++++++++++++++++++++
3 files changed, 44 insertions(+)
diff --git a/include/linux/sched/ext.h b/include/linux/sched/ext.h
index 8b92842776cb..0cf0915572c9 100644
--- a/include/linux/sched/ext.h
+++ b/include/linux/sched/ext.h
@@ -206,12 +206,14 @@ struct sched_ext_entity {
void sched_ext_free(struct task_struct *p);
void print_scx_info(const char *log_lvl, struct task_struct *p);
void scx_softlockup(u32 dur_s);
+bool scx_rcu_cpu_stall(void);
#else /* !CONFIG_SCHED_CLASS_EXT */
static inline void sched_ext_free(struct task_struct *p) {}
static inline void print_scx_info(const char *log_lvl, struct task_struct *p) {}
static inline void scx_softlockup(u32 dur_s) {}
+static inline bool scx_rcu_cpu_stall(void) { return false; }
#endif /* CONFIG_SCHED_CLASS_EXT */
diff --git a/kernel/rcu/tree_stall.h b/kernel/rcu/tree_stall.h
index 486c00536207..af61b2d0d311 100644
--- a/kernel/rcu/tree_stall.h
+++ b/kernel/rcu/tree_stall.h
@@ -134,6 +134,13 @@ static void panic_on_rcu_stall(void)
{
static int cpu_stall;
+ /*
+ * Attempt to kick out the BPF scheduler if it's installed and defer
+ * the panic to give the system a chance to recover.
+ */
+ if (scx_rcu_cpu_stall())
+ return;
+
if (++cpu_stall < sysctl_max_rcu_stall_to_panic)
return;
diff --git a/kernel/sched/ext.c b/kernel/sched/ext.c
index bee98fdcdd01..df5b2c952cf7 100644
--- a/kernel/sched/ext.c
+++ b/kernel/sched/ext.c
@@ -4672,6 +4672,41 @@ bool scx_allow_ttwu_queue(const struct task_struct *p)
p->sched_class != &ext_sched_class;
}
+/**
+ * scx_rcu_cpu_stall - sched_ext RCU CPU stall handler
+ *
+ * While there are various reasons why RCU CPU stalls can occur on a system
+ * that may not be caused by the current BPF scheduler, try kicking out the
+ * current scheduler in an attempt to recover the system to a good state before
+ * issuing panics.
+ */
+bool scx_rcu_cpu_stall(void)
+{
+ struct scx_sched *sch;
+
+ rcu_read_lock();
+
+ sch = rcu_dereference(scx_root);
+ if (unlikely(!sch)) {
+ rcu_read_unlock();
+ return false;
+ }
+
+ switch (scx_enable_state()) {
+ case SCX_ENABLING:
+ case SCX_ENABLED:
+ break;
+ default:
+ rcu_read_unlock();
+ return false;
+ }
+
+ scx_error(sch, "RCU CPU stall detected!");
+ rcu_read_unlock();
+
+ return true;
+}
+
/**
* scx_softlockup - sched_ext softlockup handler
* @dur_s: number of seconds of CPU stuck due to soft lockup
--
2.47.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] sched_ext, rcu: Eject BPF scheduler on RCU CPU stall panic
2025-06-24 22:49 [PATCH] sched_ext, rcu: Eject BPF scheduler on RCU CPU stall panic David Dai
@ 2025-06-24 23:06 ` Tejun Heo
0 siblings, 0 replies; 2+ messages in thread
From: Tejun Heo @ 2025-06-24 23:06 UTC (permalink / raw)
To: David Dai
Cc: void, arighi, changwoo, paulmck, davidai, sched-ext, linux-kernel,
rcu, kernel-team
On Tue, Jun 24, 2025 at 03:49:06PM -0700, David Dai wrote:
> For systems using a sched_ext scheduler and has panic_on_rcu_stall
> enabled, try kicking out the current scheduler before issuing a panic.
>
> While there are numerous reasons for RCU CPU stalls that are not
> directly attributed to the scheduler, deferring the panic gives
> sched_ext an opportunity to provide additional debug info when ejecting
> the current scheduler. Also, handling the event more gracefully allows
> us to potentially recover the system instead of incurring additional
> down time.
>
> Suggested-by: Tejun Heo <tj@kernel.org>
> Reviewed-by: Paul E. McKenney <paulmck@kernel.org>
> Signed-off-by: David Dai <david.dai@linux.dev>
Applied to sched_ext/for-6.17.
Thanks.
--
tejun
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-06-24 23:06 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-24 22:49 [PATCH] sched_ext, rcu: Eject BPF scheduler on RCU CPU stall panic David Dai
2025-06-24 23:06 ` Tejun Heo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).