summaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2026-04-10 07:54:06 -1000
committerTejun Heo <tj@kernel.org>2026-04-10 07:54:06 -1000
commite719e17d99aaf3922dbc15ae3ac3bb62fac32bad (patch)
tree8d32eeffa5016bc380678a426914f646833f15be /kernel
parent979a98b6e9bf8ebf11dc3ca260be087606ac4c2c (diff)
sched_ext: Warn on task-based SCX op recursion
The kf_tasks[] design assumes task-based SCX ops don't nest - if they did, kf_tasks[0] would get clobbered. The old scx_kf_allow() WARN_ONCE caught invalid nesting via kf_mask, but that machinery is gone now. Add a WARN_ON_ONCE(current->scx.kf_tasks[0]) at the top of each SCX_CALL_OP_TASK*() macro. Checking kf_tasks[0] alone is sufficient: all three variants (SCX_CALL_OP_TASK, SCX_CALL_OP_TASK_RET, SCX_CALL_OP_2TASKS_RET) write to kf_tasks[0], so a non-NULL value at entry to any of the three means re-entry from somewhere in the family. Signed-off-by: Tejun Heo <tj@kernel.org> Acked-by: Andrea Righi <arighi@nvidia.com>
Diffstat (limited to 'kernel')
-rw-r--r--kernel/sched/ext.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/kernel/sched/ext.c b/kernel/sched/ext.c
index 40421698c9e3..b8dbae251fd5 100644
--- a/kernel/sched/ext.c
+++ b/kernel/sched/ext.c
@@ -502,10 +502,13 @@ do { \
* held by try_to_wake_up() with rq tracking via scx_rq.in_select_cpu. So if
* kf_tasks[] is set, @p's scheduler-protected fields are stable.
*
- * These macros only work for non-nesting ops since kf_tasks[] is not stacked.
+ * kf_tasks[] can not stack, so task-based SCX ops must not nest. The
+ * WARN_ON_ONCE() in each macro catches a re-entry of any of the three variants
+ * while a previous one is still in progress.
*/
#define SCX_CALL_OP_TASK(sch, op, rq, task, args...) \
do { \
+ WARN_ON_ONCE(current->scx.kf_tasks[0]); \
current->scx.kf_tasks[0] = task; \
SCX_CALL_OP((sch), op, rq, task, ##args); \
current->scx.kf_tasks[0] = NULL; \
@@ -514,6 +517,7 @@ do { \
#define SCX_CALL_OP_TASK_RET(sch, op, rq, task, args...) \
({ \
__typeof__((sch)->ops.op(task, ##args)) __ret; \
+ WARN_ON_ONCE(current->scx.kf_tasks[0]); \
current->scx.kf_tasks[0] = task; \
__ret = SCX_CALL_OP_RET((sch), op, rq, task, ##args); \
current->scx.kf_tasks[0] = NULL; \
@@ -523,6 +527,7 @@ do { \
#define SCX_CALL_OP_2TASKS_RET(sch, op, rq, task0, task1, args...) \
({ \
__typeof__((sch)->ops.op(task0, task1, ##args)) __ret; \
+ WARN_ON_ONCE(current->scx.kf_tasks[0]); \
current->scx.kf_tasks[0] = task0; \
current->scx.kf_tasks[1] = task1; \
__ret = SCX_CALL_OP_RET((sch), op, rq, task0, task1, ##args); \