* If set, reject future sched_setscheduler(2) calls updating the policy
* to %SCHED_EXT with -%EACCES.
*
- * If set from ops.init_task() and the task's policy is already
- * %SCHED_EXT, which can happen while the BPF scheduler is being loaded
- * or by inhering the parent's policy during fork, the task's policy is
- * rejected and forcefully reverted to %SCHED_NORMAL. The number of
- * such events are reported through /sys/kernel/debug/sched_ext::nr_rejected.
+ * Can be set from ops.init_task() while the BPF scheduler is being
+ * loaded (!scx_init_task_args->fork). If set and the task's policy is
+ * already %SCHED_EXT, the task's policy is rejected and forcefully
+ * reverted to %SCHED_NORMAL. The number of such events are reported
+ * through /sys/kernel/debug/sched_ext::nr_rejected. Setting this flag
+ * during fork is not allowed.
*/
bool disallow; /* reject switching into SCX */
scx_set_task_state(p, SCX_TASK_INIT);
if (p->scx.disallow) {
- struct rq *rq;
- struct rq_flags rf;
+ if (!fork) {
+ struct rq *rq;
+ struct rq_flags rf;
- rq = task_rq_lock(p, &rf);
+ rq = task_rq_lock(p, &rf);
- /*
- * We're either in fork or load path and @p->policy will be
- * applied right after. Reverting @p->policy here and rejecting
- * %SCHED_EXT transitions from scx_check_setscheduler()
- * guarantees that if ops.init_task() sets @p->disallow, @p can
- * never be in SCX.
- */
- if (p->policy == SCHED_EXT) {
- p->policy = SCHED_NORMAL;
- atomic_long_inc(&scx_nr_rejected);
- }
+ /*
+ * We're in the load path and @p->policy will be applied
+ * right after. Reverting @p->policy here and rejecting
+ * %SCHED_EXT transitions from scx_check_setscheduler()
+ * guarantees that if ops.init_task() sets @p->disallow,
+ * @p can never be in SCX.
+ */
+ if (p->policy == SCHED_EXT) {
+ p->policy = SCHED_NORMAL;
+ atomic_long_inc(&scx_nr_rejected);
+ }
- task_rq_unlock(rq, p, &rf);
+ task_rq_unlock(rq, p, &rf);
+ } else if (p->policy == SCHED_EXT) {
+ scx_ops_error("ops.init_task() set task->scx.disallow for %s[%d] during fork",
+ p->comm, p->pid);
+ }
}
p->scx.flags |= SCX_TASK_RESET_RUNNABLE_AT;