Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

Tejun Heo e719e17d 979a98b6

+6 -1
+6 -1
kernel/sched/ext.c
··· 502 502 * held by try_to_wake_up() with rq tracking via scx_rq.in_select_cpu. So if 503 503 * kf_tasks[] is set, @p's scheduler-protected fields are stable. 504 504 * 505 - * These macros only work for non-nesting ops since kf_tasks[] is not stacked. 505 + * kf_tasks[] can not stack, so task-based SCX ops must not nest. The 506 + * WARN_ON_ONCE() in each macro catches a re-entry of any of the three variants 507 + * while a previous one is still in progress. 506 508 */ 507 509 #define SCX_CALL_OP_TASK(sch, op, rq, task, args...) \ 508 510 do { \ 511 + WARN_ON_ONCE(current->scx.kf_tasks[0]); \ 509 512 current->scx.kf_tasks[0] = task; \ 510 513 SCX_CALL_OP((sch), op, rq, task, ##args); \ 511 514 current->scx.kf_tasks[0] = NULL; \ ··· 517 514 #define SCX_CALL_OP_TASK_RET(sch, op, rq, task, args...) \ 518 515 ({ \ 519 516 __typeof__((sch)->ops.op(task, ##args)) __ret; \ 517 + WARN_ON_ONCE(current->scx.kf_tasks[0]); \ 520 518 current->scx.kf_tasks[0] = task; \ 521 519 __ret = SCX_CALL_OP_RET((sch), op, rq, task, ##args); \ 522 520 current->scx.kf_tasks[0] = NULL; \ ··· 527 523 #define SCX_CALL_OP_2TASKS_RET(sch, op, rq, task0, task1, args...) \ 528 524 ({ \ 529 525 __typeof__((sch)->ops.op(task0, task1, ##args)) __ret; \ 526 + WARN_ON_ONCE(current->scx.kf_tasks[0]); \ 530 527 current->scx.kf_tasks[0] = task0; \ 531 528 current->scx.kf_tasks[1] = task1; \ 532 529 __ret = SCX_CALL_OP_RET((sch), op, rq, task0, task1, ##args); \