Sched_ext development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Changwoo Min" <changwoo@igalia.com>
Cc: sched-ext@lists.linux.dev
Subject: Re: [PATCH v2 4/8] selftests/sched_ext: Test scx_bpf_sched_id() and scx_bpf_task_sched_id()
Date: Thu, 03 Dec 2026 05:14:00 +0000	[thread overview]
Message-ID: <sashiko-outbox-247178@kernel.org> (raw)
In-Reply-To: <20261203045618.982539-5-changwoo@igalia.com>

Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [Low] selftests/sched_ext: leak BPF skeleton and FDs on error in
  load_and_check()
- [Low] selftests/sched_ext: unassociated probe() bypasses ops->priv in
  scx_prog_sched()
- [Low] selftests/sched_ext: SCX_EQ() evaluates load_and_check() twice
  on failure
- [Low] selftests/sched_ext: sched_id passes getpid() to
  bpf_task_from_pid()
--

commit 9708b30d3e6e6f4f027faf04578e789bbcd68ef1
Author: Changwoo Min <changwoo@igalia.com>

selftests/sched_ext: Test scx_bpf_sched_id() and scx_bpf_task_sched_id()

This commit adds the sched_id sched_ext selftest to verify
scx_bpf_sched_id() and scx_bpf_task_sched_id() across scheduler load,
unload, and reload.

> diff --git a/tools/testing/selftests/sched_ext/sched_id.bpf.c b/tools/testing/selftests/sched_ext/sched_id.bpf.c
> new file mode 100644
> index 0000000000000..8828c3ecec3e4
> --- /dev/null
> +++ b/tools/testing/selftests/sched_ext/sched_id.bpf.c
> @@ -0,0 +1,47 @@
[ ... ]
> +SEC("syscall")
> +int probe(void *ctx)
> +{
> +	struct task_struct *p;
> +
> +	p = bpf_task_from_pid(target_pid);
> +	if (!p)
> +		return -ESRCH;
> +
> +	probe_sched_id = scx_bpf_sched_id();
> +	probe_task_sched_id = scx_bpf_task_sched_id(p);
> +	bpf_task_release(p);
> +	return 0;
> +}

[Severity: Low]
Can bpf_task_from_pid(target_pid) fail or inspect the wrong task when the
test runs in a non-root PID namespace?

load_and_check() stores getpid() in target_pid, which is relative to the
caller's PID namespace, while bpf_task_from_pid() resolves PIDs in
init_pid_ns.  Since probe() runs in the calling task's context via
bpf_prog_test_run_opts(), using bpf_get_current_task_btf() avoids the
namespace mismatch.

> diff --git a/tools/testing/selftests/sched_ext/sched_id.c b/tools/testing/selftests/sched_ext/sched_id.c
> new file mode 100644
> index 0000000000000..a926062e13c76
> --- /dev/null
> +++ b/tools/testing/selftests/sched_ext/sched_id.c
> @@ -0,0 +1,103 @@
[ ... ]
> +static enum scx_test_status load_and_check(u64 *id)
> +{
> +	enum scx_test_status status = SCX_TEST_FAIL;
> +	struct sched_id *skel;
> +	struct bpf_link *link;
> +
> +	skel = sched_id__open();
> +	SCX_FAIL_IF(!skel, "Failed to open skel");
> +	SCX_ENUM_INIT(skel);
> +	SCX_FAIL_IF(sched_id__load(skel), "Failed to load skel");

[Severity: Low]
Does calling sched_id__load() without associating skel->progs.probe with
skel->maps.sched_id_ops bypass the primary scx_prog_sched() path?

Without bpf_program__assoc_struct_ops(), bpf_prog_get_assoc_struct_ops()
returns NULL in scx_prog_sched(), so scx_bpf_sched_id() only passes via
the legacy v6.19 scx_root fallback instead of testing ops->priv.
Associating skel->progs.probe with skel->maps.sched_id_ops before loading
would exercise the primary lookup directly.

> +	skel->bss->target_pid = getpid();
> +
> +	link = bpf_map__attach_struct_ops(skel->maps.sched_id_ops);
> +	SCX_FAIL_IF(!link, "Failed to attach struct_ops");

[Severity: Low]
Do the SCX_FAIL_IF() checks on sched_id__load() and
bpf_map__attach_struct_ops() leak skel?

SCX_FAIL_IF() returns SCX_TEST_FAIL immediately and bypasses the out
cleanup label, skipping sched_id__destroy(skel).  Because runner.c runs
all selftests in one process, the skeleton allocations and loaded BPF
file descriptors stay leaked for subsequent tests.  Initializing link to
NULL and jumping to cleanup avoids this.

[ ... ]

> +static enum scx_test_status run(void *ctx)
> +{
> +	u64 id1 = 0, id2 = 0;
> +
> +	SCX_EQ(load_and_check(&id1), SCX_TEST_PASS);
> +
> +	/* Step 3: A new instance gets a larger id */
> +	SCX_EQ(load_and_check(&id2), SCX_TEST_PASS);
> +	SCX_GT(id2, id1);

[Severity: Low]
Will SCX_EQ() invoke load_and_check() twice when it fails?

SCX_EQ(_x, _y) expands _x both in the comparison and in the error format
arguments, so a failing load_and_check() runs a second full
load/attach/unload cycle, duplicates error output, and reports the second
call's return value instead of the first.  Storing the return value in a
local variable before passing it to SCX_EQ() avoids the double evaluation.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261203045618.982539-1-changwoo@igalia.com?part=4

  reply	other threads:[~2026-12-03  5:14 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03  4:56 [PATCH v2 0/8] sched_ext: Add p->scx.bpf_priv for O(1) task context lookup Changwoo Min
2026-12-03  4:56 ` [PATCH v2 1/8] sched_ext: Reset task fields after ops.exit_task() Changwoo Min
2026-12-04  6:10   ` Andrea Righi
2026-12-03  4:56 ` [PATCH v2 2/8] sched_ext: Mark a task enabled before ops.enable() Changwoo Min
2026-12-04  6:10   ` Andrea Righi
2026-12-03  4:56 ` [PATCH v2 3/8] sched_ext: Add scx_bpf_sched_id() and scx_bpf_task_sched_id() Changwoo Min
2026-12-03  5:14   ` sashiko-bot
2026-12-04  6:44   ` Andrea Righi
2026-12-03  4:56 ` [PATCH v2 4/8] selftests/sched_ext: Test " Changwoo Min
2026-12-03  5:14   ` sashiko-bot [this message]
2026-12-03  4:56 ` [PATCH v2 5/8] sched_ext: Add p->scx.bpf_priv for O(1) task context lookup Changwoo Min
2026-12-03  5:20   ` sashiko-bot
2026-12-03  4:56 ` [PATCH v2 6/8] sched_ext: scx_qmap: Cache task_ctx in p->scx.bpf_priv Changwoo Min
2026-12-03  5:19   ` sashiko-bot
2026-12-03  4:56 ` [PATCH v2 7/8] selftests/sched_ext: Test p->scx.bpf_priv across class changes Changwoo Min
2026-12-03  5:26   ` sashiko-bot
2026-12-03  4:56 ` [PATCH v2 8/8] selftests/sched_ext: Test task field reset across sub-scheduler handoffs Changwoo Min
2026-12-03  5:32   ` sashiko-bot

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=sashiko-outbox-247178@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=changwoo@igalia.com \
    --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