From: sashiko-bot@kernel.org
To: "Cheng-Yang Chou" <yphbchou0911@gmail.com>
Cc: sched-ext@lists.linux.dev
Subject: Re: [PATCH v2 2/2] selftests/sched_ext: Add dispatch_cookie test
Date: Wed, 06 May 2026 20:52:34 +0000 [thread overview]
Message-ID: <20260506205234.E6240C2BCB0@smtp.kernel.org> (raw)
In-Reply-To: <20260506160412.522199-3-yphbchou0911@gmail.com>
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] Failing an assertion in the run() function leaks the bpf_link and leaves the BPF scheduler permanently attached.
- [Medium] The BPF program incorrectly drops the kernel-provided enq_flags when calling scx_bpf_dsq_insert_with_cookie().
- [Medium] The return value of fork() is not checked for errors, leading to incorrect waitpid() behavior.
--
commit de7f9ee9893bdc6cb049e25475e095b028e1ed26
Author: Cheng-Yang Chou <yphbchou0911@gmail.com>
selftests/sched_ext: Add dispatch_cookie test
This commit adds a new sched_ext selftest to verify the behavior of
scx_bpf_task_get_cookie() and scx_bpf_dsq_insert_with_cookie(). It captures
a cookie before dispatch and verifies that userspace accurately reflects
the cookie-based dispatch activity.
> diff --git a/tools/testing/selftests/sched_ext/dispatch_cookie.bpf.c b/tools/testing/selftests/sched_ext/dispatch_cookie.bpf.c
> new file mode 100644
> index 0000000000000..cb198a5f50e89
> --- /dev/null
> +++ b/tools/testing/selftests/sched_ext/dispatch_cookie.bpf.c
[ ... ]
> +void BPF_STRUCT_OPS(dispatch_cookie_enqueue, struct task_struct *p,
> + u64 enq_flags)
> +{
> + u64 cookie = scx_bpf_task_get_cookie(p);
> +
> + if (scx_bpf_dsq_insert_with_cookie(p, SCX_DSQ_GLOBAL, 0, cookie))
Does this code unintentionally drop the enq_flags provided by the kernel?
The fallback branch correctly passes enq_flags to scx_bpf_dsq_insert(),
but hardcoding 0 here might alter task placement context by dropping
directives like SCX_ENQ_WAKEUP.
> + __sync_fetch_and_add(&nr_cookie_dispatched, 1);
> + else
> + scx_bpf_dsq_insert(p, SCX_DSQ_GLOBAL, SCX_SLICE_DFL, enq_flags);
> +}
[ ... ]
> diff --git a/tools/testing/selftests/sched_ext/dispatch_cookie.c b/tools/testing/selftests/sched_ext/dispatch_cookie.c
> new file mode 100644
> index 0000000000000..f799b5828f9d6
> --- /dev/null
> +++ b/tools/testing/selftests/sched_ext/dispatch_cookie.c
[ ... ]
> +static enum scx_test_status run(void *ctx)
> +{
> + struct dispatch_cookie *skel = ctx;
> + struct bpf_link *link;
> + pid_t pids[NUM_CHILDREN];
> + int i, status;
> +
> + link = bpf_map__attach_struct_ops(skel->maps.dispatch_cookie_ops);
> + SCX_FAIL_IF(!link, "Failed to attach scheduler");
> +
> + for (i = 0; i < NUM_CHILDREN; i++) {
> + pids[i] = fork();
Should the return value of fork() be checked here?
If fork() fails and returns -1, waitpid() in the subsequent loop will be
called with -1, causing it to wait for any child process rather than the
specific process. This could lead to out-of-order reaping and confusing
test failures.
> + if (pids[i] == 0)
> + exit(0);
> + }
> +
> + for (i = 0; i < NUM_CHILDREN; i++) {
> + SCX_EQ(waitpid(pids[i], &status, 0), pids[i]);
> + SCX_EQ(status, 0);
Can this cause a resource leak that affects other tests?
SCX_EQ() forces an immediate return upon failure. If a check fails here,
the function will return before reaching bpf_link__destroy(link).
Leaving the BPF scheduler attached could cause subsequent tests in the
runner to fail with -EBUSY, since sched_ext only allows one active
scheduler globally.
> + }
> +
> + bpf_link__destroy(link);
> +
> + SCX_GT(skel->bss->nr_cookie_dispatched, 0);
> +
> + return SCX_TEST_PASS;
> +}
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260506160412.522199-1-yphbchou0911@gmail.com?part=2
next prev parent reply other threads:[~2026-05-06 20:52 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-06 16:04 [PATCH v2 sched_ext/for-7.2 0/2] sched_ext: Add cookie API for early qseq capture Cheng-Yang Chou
2026-05-06 16:04 ` [PATCH v2 1/2] " Cheng-Yang Chou
2026-05-06 20:34 ` sashiko-bot
2026-05-06 16:04 ` [PATCH v2 2/2] selftests/sched_ext: Add dispatch_cookie test Cheng-Yang Chou
2026-05-06 20:52 ` sashiko-bot [this message]
2026-05-07 10:43 ` Cheng-Yang Chou
2026-05-08 18:51 ` [PATCH v2 sched_ext/for-7.2 0/2] sched_ext: Add cookie API for early qseq capture Tejun Heo
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=20260506205234.E6240C2BCB0@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=sashiko@lists.linux.dev \
--cc=sched-ext@lists.linux.dev \
--cc=yphbchou0911@gmail.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.