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: Drop redundant rq-locked check from scx_bpf_task_cgroup()

scx_kf_allowed_on_arg_tasks() runs both an scx_kf_allowed(__SCX_KF_RQ_LOCKED)
mask check and a kf_tasks[] check. After the preceding call-site fixes,
every SCX_CALL_OP_TASK*() invocation has kf_mask & __SCX_KF_RQ_LOCKED
non-zero, so the mask check is redundant whenever the kf_tasks[] check
passes. Drop it and simplify the helper to take only @sch and @p.

Fold the locking guarantee into the SCX_CALL_OP_TASK() comment block, which
scx_bpf_task_cgroup() now points to.

No functional change.

Extracted from a larger verifier-time kfunc context filter patch
originally written by Juntong Deng.

Original-patch-by: Juntong Deng <juntong.deng@outlook.com>
Cc: Cheng-Yang Chou <yphbchou0911@gmail.com>
Signed-off-by: Tejun Heo <tj@kernel.org>
Reviewed-by: Andrea Righi <arighi@nvidia.com>

Tejun Heo 2193af26 0022b328

+14 -16
+14 -16
kernel/sched/ext.c
··· 540 540 }) 541 541 542 542 /* 543 - * Some kfuncs are allowed only on the tasks that are subjects of the 544 - * in-progress scx_ops operation for, e.g., locking guarantees. To enforce such 545 - * restrictions, the following SCX_CALL_OP_*() variants should be used when 546 - * invoking scx_ops operations that take task arguments. These can only be used 547 - * for non-nesting operations due to the way the tasks are tracked. 543 + * SCX_CALL_OP_TASK*() invokes an SCX op that takes one or two task arguments 544 + * and records them in current->scx.kf_tasks[] for the duration of the call. A 545 + * kfunc invoked from inside such an op can then use 546 + * scx_kf_allowed_on_arg_tasks() to verify that its task argument is one of 547 + * those subject tasks. 548 548 * 549 - * kfuncs which can only operate on such tasks can in turn use 550 - * scx_kf_allowed_on_arg_tasks() to test whether the invocation is allowed on 551 - * the specific task. 549 + * Every SCX_CALL_OP_TASK*() call site invokes its op with @p's rq lock held - 550 + * either via the @rq argument here, or (for ops.select_cpu()) via @p's pi_lock 551 + * held by try_to_wake_up() with rq tracking via scx_rq.in_select_cpu. So if 552 + * kf_tasks[] is set, @p's scheduler-protected fields are stable. 553 + * 554 + * These macros only work for non-nesting ops since kf_tasks[] is not stacked. 552 555 */ 553 556 #define SCX_CALL_OP_TASK(sch, mask, op, rq, task, args...) \ 554 557 do { \ ··· 616 613 617 614 /* see SCX_CALL_OP_TASK() */ 618 615 static __always_inline bool scx_kf_allowed_on_arg_tasks(struct scx_sched *sch, 619 - u32 mask, 620 616 struct task_struct *p) 621 617 { 622 - if (!scx_kf_allowed(sch, mask)) 623 - return false; 624 - 625 618 if (unlikely((p != current->scx.kf_tasks[0] && 626 619 p != current->scx.kf_tasks[1]))) { 627 620 scx_error(sch, "called on a task not being operated on"); ··· 9534 9535 * @p->sched_task_group->css.cgroup represents the cgroup @p is associated with 9535 9536 * from the scheduler's POV. SCX operations should use this function to 9536 9537 * determine @p's current cgroup as, unlike following @p->cgroups, 9537 - * @p->sched_task_group is protected by @p's rq lock and thus atomic w.r.t. all 9538 - * rq-locked operations. Can be called on the parameter tasks of rq-locked 9539 - * operations. The restriction guarantees that @p's rq is locked by the caller. 9538 + * @p->sched_task_group is stable for the duration of the SCX op. See 9539 + * SCX_CALL_OP_TASK() for details. 9540 9540 */ 9541 9541 __bpf_kfunc struct cgroup *scx_bpf_task_cgroup(struct task_struct *p, 9542 9542 const struct bpf_prog_aux *aux) ··· 9550 9552 if (unlikely(!sch)) 9551 9553 goto out; 9552 9554 9553 - if (!scx_kf_allowed_on_arg_tasks(sch, __SCX_KF_RQ_LOCKED, p)) 9555 + if (!scx_kf_allowed_on_arg_tasks(sch, p)) 9554 9556 goto out; 9555 9557 9556 9558 cgrp = tg_cgrp(tg);