From: sashiko-bot@kernel.org
To: "Wanwu Li" <liwanwu@kylinos.cn>
Cc: sched-ext@lists.linux.dev
Subject: Re: [PATCH 3/3] tools/sched_ext: scx_pair: Verify task cgroup before dispatch
Date: Thu, 24 Sep 2026 14:50:29 +0000 [thread overview]
Message-ID: <20260924145029.C295D1F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260924143659.268595-4-liwanwu@kylinos.cn>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] sched_ext: fatal abort in scx_pair due to scx_kf_arg_task_ok() violation
--
commit 79e8ca61bf0fbb13b0ca39d2236cec7b65f02134
Author: Wanwu Li <liwanwu@kylinos.cn>
tools/sched_ext: scx_pair: Verify task cgroup before dispatch
This commit modifies try_dispatch() to read the task's current cgroup after
looking it up from its pid. This ensures the task hasn't migrated to another
cgroup between enqueue and dispatch, dropping tasks that have migrated to
avoid dispatching them under the wrong cgroup context.
> diff --git a/tools/sched_ext/scx_pair.bpf.c b/tools/sched_ext/scx_pair.bpf.c
> index 906bb11d678f7..d29bb9fc6c92e 100644
> --- a/tools/sched_ext/scx_pair.bpf.c
> +++ b/tools/sched_ext/scx_pair.bpf.c
> @@ -519,6 +519,25 @@ static int try_dispatch(s32 cpu)
>
> p = bpf_task_from_pid(pid);
> if (p) {
> + struct cgroup *task_cgrp;
> + u64 task_cgid;
> +
> + /*
> + * Without a .dequeue callback, a task that migrated to
> + * another cgroup after being enqueued leaves a stale pid
> + * behind. Dispatching it here would run it under the wrong
> + * cgroup. Drop it and retry.
> + */
> + task_cgrp = scx_bpf_task_cgroup(p);
[Severity: High]
Will this cause a scheduler abort?
Looking at the kfunc implementation, scx_bpf_task_cgroup() internally
validates the task using scx_kf_arg_task_ok(), which requires that the
passed task matches current->scx.kf_tasks[0] (the task currently being
operated on by a task-specific SCX hook).
Because try_dispatch() is invoked from the .dispatch scheduler hook
(pair_dispatch) via SCX_CALL_OP() rather than SCX_CALL_OP_TASK(),
kf_tasks[0] is not populated and remains NULL during dispatch.
Since the looked-up task p is not NULL, won't scx_kf_arg_task_ok()
unconditionally fail and trigger scx_error(), causing a fallback to CFS
on the very first task dispatch?
> + task_cgid = task_cgrp->kn->id;
> + bpf_cgroup_release(task_cgrp);
> +
> + if (task_cgid != cgid) {
> + bpf_task_release(p);
> + __sync_fetch_and_add(&nr_missing, 1);
> + return -EAGAIN;
> + }
> +
> __sync_fetch_and_add(&nr_dispatched, 1);
> scx_bpf_dsq_insert(p, SCX_DSQ_GLOBAL, SCX_SLICE_DFL, 0);
> bpf_task_release(p);
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260924143659.268595-1-liwanwu@kylinos.cn?part=3
next prev parent reply other threads:[~2026-09-24 14:50 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-24 14:36 [PATCH 0/3] tools/sched_ext: Fix three example scheduler bugs Wanwu Li
2026-09-24 14:36 ` [PATCH 1/3] tools/sched_ext: Increment nr_queued when a task is queued to user space Wanwu Li
2026-09-24 14:47 ` sashiko-bot
2026-09-24 14:36 ` [PATCH 2/3] tools/sched_ext: scx_pair: Drain task queue on cgroup exit Wanwu Li
2026-09-24 14:36 ` [PATCH 3/3] tools/sched_ext: scx_pair: Verify task cgroup before dispatch Wanwu Li
2026-09-24 14:50 ` sashiko-bot [this message]
2026-09-24 16:17 ` [PATCH 0/3] tools/sched_ext: Fix three example scheduler bugs Tejun Heo
2026-09-24 22:35 ` liwanwu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260924145029.C295D1F000FF@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=liwanwu@kylinos.cn \
--cc=sashiko-reviews@lists.linux.dev \
--cc=sched-ext@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox