Sched_ext development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Kuba Piecuch" <jpiecuch@google.com>
Cc: sched-ext@lists.linux.dev
Subject: Re: [RFC PATCH 2/2] selftests/sched_ext: Test that ops.sub_caps_updated() runs unlocked
Date: Wed, 25 Nov 2026 16:06:25 +0000	[thread overview]
Message-ID: <sashiko-outbox-233710@kernel.org> (raw)
In-Reply-To: <20261125153353.1364467-3-jpiecuch@google.com>

Thank you for your contribution! Sashiko AI review found 5 potential
issues to consider:
- [Medium] selftests/sched_ext: colliding fixed map_extra arena mapping
  in sub_caps_ctx
- [Low] selftests/sched_ext: hardcoded /sys/fs/cgroup and hand-rolled
  I/O in setup()
- [Low] selftests/sched_ext: setup() leaks CGRP_PATH directory on error
  paths
- [Low] selftests/sched_ext: run() leaves worker child processes
  unreaped on failure
- [Low] selftests/sched_ext: silent SCX_TEST_SKIP returns in setup()
--

commit 4d12e206bd2b4220ed100124b368c1ee420871bc
Author: Kuba Piecuch <jpiecuch@google.com>

selftests/sched_ext: Test that ops.sub_caps_updated() runs unlocked

This commit adds the sub_caps_ctx selftest to verify that a child
sub-scheduler's ops.sub_caps_updated() callback runs without holding the
parent's rq lock when capabilities are granted or revoked from
ops.enqueue() and ops.select_cid().

> diff --git a/tools/testing/selftests/sched_ext/sub_caps_ctx.bpf.c b/tools/testing/selftests/sched_ext/sub_caps_ctx.bpf.c
> new file mode 100644
> index 0000000000000..e6613fc23d15e
> --- /dev/null
> +++ b/tools/testing/selftests/sched_ext/sub_caps_ctx.bpf.c
> @@ -0,0 +1,136 @@

[ ... ]

> +struct {
> +	__uint(type, BPF_MAP_TYPE_ARENA);
> +	__uint(map_flags, BPF_F_MMAPABLE);
> +	__uint(max_entries, 1 << 8);
> +#if defined(__TARGET_ARCH_arm64) || defined(__aarch64__)
> +	__ulong(map_extra, 0x1ull << 32);
> +#else
> +	__ulong(map_extra, 0x1ull << 44);
> +#endif
> +} arena SEC(".maps");

[Severity: Medium]
Does setting a fixed map_extra address cause the child skeleton's arena
mapping to collide with the parent's?

When map_extra is non-zero, libbpf maps the arena with MAP_FIXED at that
user virtual address.  Because setup() loads both test_ctx.parent and
test_ctx.child in the same process, loading test_ctx.child overwrites
test_ctx.parent's user arena mapping at the same address, and cleanup()
later calls munmap() twice on that range.  Also, 0x1ull << 44 exceeds the
user virtual address space on architectures such as riscv64 SV39, causing
skeleton load to fail.  Since userspace never accesses this arena, can
map_extra be omitted as in enable_cmask.bpf.c and unlocked_kfunc_cid.bpf.c?

[ ... ]

> diff --git a/tools/testing/selftests/sched_ext/sub_caps_ctx.c b/tools/testing/selftests/sched_ext/sub_caps_ctx.c
> new file mode 100644
> index 0000000000000..5881a6312cb65
> --- /dev/null
> +++ b/tools/testing/selftests/sched_ext/sub_caps_ctx.c
> @@ -0,0 +1,165 @@

[ ... ]

> +#define CGRP_ROOT	"/sys/fs/cgroup"
> +#define CGRP_PATH	CGRP_ROOT "/sub_caps_ctx"
> +#define NR_WORKERS	8
> +
> +struct ctx {
> +	struct sub_caps_ctx *parent;
> +	struct sub_caps_ctx *child;
> +	struct bpf_link *parent_link;
> +	struct bpf_link *child_link;
> +};
> +
> +static struct ctx test_ctx;
> +
> +static void write_file(const char *path, const char *buf)
> +{
> +	FILE *f = fopen(path, "w");
> +
> +	if (!f)
> +		return;
> +	fputs(buf, f);
> +	fclose(f);
> +}

[Severity: Low]
Could this reuse cg_find_unified_root(), cg_write(), cg_create(), and
cg_destroy() from cgroup_util.h (as cgroup_nr_cpus.c does) instead of
hardcoding /sys/fs/cgroup and ignoring errors in write_file()?

If cgroup2 is mounted elsewhere and /sys/fs/cgroup is a tmpfs or cgroup v1
mount, write_file() silently fails or writes a regular file while mkdir()
and stat() in setup() still succeed, causing bpf_map__attach_struct_ops()
for the child in run() to fail with -ENOENT instead of skipping the test.

> +
> +static enum scx_test_status setup(void **ctx)
> +{
> +	struct sub_caps_ctx *skel;
> +	struct stat st;
> +
> +	if (!__COMPAT_struct_has_field("sched_ext_ops_cid", "sub_caps_updated"))
> +		return SCX_TEST_SKIP;
> +
> +	/* a single cid is always the parent's rq, which scx_bpf_cidperf_set() accepts */
> +	if (sysconf(_SC_NPROCESSORS_ONLN) < 2)
> +		return SCX_TEST_SKIP;

[Severity: Low]
Should these two skip paths print a reason message explaining which
prerequisite was missing before returning SCX_TEST_SKIP?

> +
> +	write_file(CGRP_ROOT "/cgroup.subtree_control", "+cpu");
> +	if (mkdir(CGRP_PATH, 0755) && errno != EEXIST) {
> +		fprintf(stderr, "Failed to create %s (%s)\n", CGRP_PATH, strerror(errno));
> +		return SCX_TEST_SKIP;
> +	}
> +	SCX_FAIL_IF(stat(CGRP_PATH, &st), "Failed to stat %s", CGRP_PATH);
> +
> +	skel = SCX_OPS_CID_OPEN(sub_caps_ctx_ops, sub_caps_ctx);
> +	SCX_OPS_LOAD(skel, sub_caps_ctx_ops, sub_caps_ctx, uei);
> +	test_ctx.parent = skel;
> +
> +	skel = SCX_OPS_CID_OPEN(sub_caps_ctx_ops, sub_caps_ctx);
> +	skel->struct_ops.sub_caps_ctx_ops->sub_cgroup_id = st.st_ino;
> +	SCX_OPS_LOAD(skel, sub_caps_ctx_ops, sub_caps_ctx, uei);
> +	test_ctx.child = skel;

[Severity: Low]
Does setup() leak the CGRP_PATH directory if stat() or skeleton loading
fails?  The test runner does not invoke cleanup() when setup() fails or
aborts via SCX_OPS_CID_OPEN() / SCX_OPS_LOAD(), leaving CGRP_PATH behind on
the host cgroup filesystem.

[ ... ]

> +	for (i = 0; i < NR_WORKERS; i++) {
> +		pids[i] = fork();
> +		SCX_FAIL_IF(pids[i] < 0, "Failed to fork");
> +		if (!pids[i])
> +			worker();
> +	}
> +	for (i = 0; i < NR_WORKERS; i++)
> +		SCX_FAIL_IF(waitpid(pids[i], &status, 0) != pids[i] || status,
> +			    "Worker %d failed", i);

[Severity: Low]
If fork() fails after spawning some workers, or waitpid() fails on one
worker, does SCX_FAIL_IF() return without reaping the remaining children?
Because the runner executes all tests in a single process and cleanup()
does not wait on pids[], any remaining workers continue running into
cleanup() and subsequent tests and are left as zombies.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261125153353.1364467-1-jpiecuch@google.com?part=2

  reply	other threads:[~2026-11-25 16:06 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25 15:34 [RFC PATCHSET sched_ext/for-7.4-fixes] sched_ext: sub: Don't run ops.sub_caps_updated() in an SCX op context Kuba Piecuch
2026-11-25 15:34 ` [RFC PATCH 1/2] sched_ext: sub: Defer ops.sub_caps_updated() out of SCX op contexts Kuba Piecuch
2026-11-25 15:34 ` [RFC PATCH 2/2] selftests/sched_ext: Test that ops.sub_caps_updated() runs unlocked Kuba Piecuch
2026-11-25 16:06   ` sashiko-bot [this message]
2026-11-27 15:43 ` [RFC PATCHSET sched_ext/for-7.4-fixes] sched_ext: sub: Don't run ops.sub_caps_updated() in an SCX op context 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=sashiko-outbox-233710@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=jpiecuch@google.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