From: no-reply@sashiko.virtuozzo.com
To: Vladimir Riabchun <vladimir.riabchun@virtuozzo.com>,
Konstantin Khorenko <khorenko@virtuozzo.com>
Cc: devel@openvz.org
Subject: Re: [Devel] [PATCH hci-8.1 v4 2/2] selftests: ve: Test sched_getaffinity in VE
Date: Wed, 18 Nov 2026 19:50:05 +0000 [thread overview]
Message-ID: <010701a1f03593e1-3c86e92c-5f18-45c3-93bc-f5c3564d9da9-000000@eu-central-1.amazonses.com> (raw)
In-Reply-To: <20261118-ct-invalid-nrpoc-v4-2-30baaeda3f87@virtuozzo.com>
Thank you for your contribution! Sashiko AI review found 5 potential
issues to consider:
- [Medium] selftests/ve: sched_getaffinity() gets CPU_SETSIZE bits as
byte length
- [Low] selftests/ve: getaffinity test fails instead of skipping without
root/cgroup2
- [Low] selftests/ve: expected VE CPU count taken from runner affinity,
not CT cpuset
- [Low] selftests/ve: CT cgroup leaked when FIXTURE_SETUP assert fails
- [Low] selftests/ve: ambiguous 'leave' comment and stray blank line in
getaffinity test
--
commit e9584f474b4d974bdc60fd7bc11784a4df6ee364
Author: Vladimir Riabchun <vladimir.riabchun@virtuozzo.com>
selftests: ve: Test sched_getaffinity in VE
Add a new selftest that verifies that sched_getaffinity respects both
cgroup cpuset and nr_cpus limits.
> diff --git a/tools/testing/selftests/ve/ve_sched_getaffinity_test.c b/tools/testing/selftests/ve/ve_sched_getaffinity_test.c
> new file mode 100644
> index 0000000000000..73cbdaeb95be0
> --- /dev/null
> +++ b/tools/testing/selftests/ve/ve_sched_getaffinity_test.c
[ ... ]
> +static int __getaffinity_ve(void *cpuset)
> +{
> + cpu_set_t *dst = cpuset;
> +
> + return sched_getaffinity(getpid(), CPU_SETSIZE, dst);
> +}
[Severity: Medium]
Is CPU_SETSIZE the right length here? sched_getaffinity() takes the mask
size in bytes, but CPU_SETSIZE is a bit count (1024), while cpu_set_t is
only 128 bytes. After the syscall returns, the glibc wrapper clears the
remaining cpusetsize - res bytes, so it writes roughly 900 bytes past the
end of dst.
Here the destination is a one-page mmap, so the overrun happens to stay in
the page. The same call in FIXTURE_SETUP below targets self->orig_cpuset,
a field of the fixture data, so it overruns into neighbouring memory.
Would sizeof(cpu_set_t) be correct, keeping CPU_SETSIZE only as the loop
bound in get_nth_cpu()?
[ ... ]
> +FIXTURE_SETUP(ve_getaff_test)
> +{
> + ASSERT_EQ(sched_getaffinity(getpid(), CPU_SETSIZE, &self->orig_cpuset), 0);
> + self->orig_cpucount = CPU_COUNT(&self->orig_cpuset);
[Severity: Low]
Is orig_cpucount the right expected value for the CT? Attaching the child
to the CT cgroup goes through cpuset_attach() -> cpuset_attach_task(),
which overwrites its cpus_mask with the CT cgroup's effective cpus.
prepare_namespaces() likewise moves the runner into the root of the private
cgroup2 mount, which resets its own affinity. The VE's sched_getaffinity()
therefore reports the CT cpuset's CPU count, not the count captured here.
If the test is started with a narrowed affinity, for example taskset -c 0,1
on a larger host, orig_cpucount is 2 while the VE reports every online CPU.
The check_cpumask_is_prefix(..., self->orig_cpucount) assertions in all
three tests then fail spuriously. Should the expected count come from the
CT cgroup's effective cpuset, or should the test skip when the two differ?
> + if (self->orig_cpucount < 2)
> + SKIP(return, "Not enough CPUs available");
> +
> + self->cgv2_fd = mount_cg2_fd();
> + ASSERT_GE(self->cgv2_fd, 0);
[Severity: Low]
Should a missing prerequisite be a skip here rather than a failure? An
unprivileged run, or one without cgroup2 support, fails on this ASSERT_GE.
The sibling ve_cpuid_override_test and ve_numa_migrate_test skip with a
"needs root" reason via geteuid(). The same applies to the
subtree_control write, make_ve() and prepare_namespaces() below.
> +
> + ASSERT_EQ(write_file_at(self->cgv2_fd, "cgroup.subtree_control",
> + VE_CONTROLLERS), 0);
> +
> + self->ctid = make_ve(self->cgv2_fd, CTID_MIN);
> + ASSERT_GE(self->ctid, 0);
> +
> + ASSERT_EQ(prepare_namespaces(&self->ns_ctx, CLONE_NEWVE,
> + self->cgv2_fd, self->ctid), 0);
> +}
[Severity: Low]
Can this leak the CT cgroup when prepare_namespaces() fails? The harness
exits from a failed setup before setting setup_completed, so
FIXTURE_TEARDOWN is not run. destroy_ve() and close() are then skipped,
and the cgroup created by make_ve() stays behind and consumes a CTID.
Should the failure path in FIXTURE_SETUP clean up after itself, or a
comment say that the leak is intentional?
[ ... ]
> + /* Find two CPUs and leave the second via cgroup interface */
> + cpu_leave = get_nth_cpu(&self->orig_cpuset, 2);
> + ASSERT_GE(cpu_leave, 0);
> + ASSERT_EQ(write_u64_at(self->cgv2_fd, path, cpu_leave), 0);
[Severity: Low]
This isn't a bug, but "leave the second" can be read as removing the second
CPU, while the code keeps only that CPU in cpuset.cpus. The name cpu_leave
adds to the confusion. Also, the next comment says "that is the first
one", which means the VE's CPU 0, not the host's first CPU. Rewording
would make both clearer.
[ ... ]
> + /* Set vCPU limit to 1 and check that we have one vCPU only */
> + ASSERT_EQ(write_u64_at(self->cgv2_fd, path_nr, 1), 0);
> + ASSERT_EQ(getaffinity_ve(self, &in_ve), 0);
> + ASSERT_TRUE(check_cpumask_is_prefix(&in_ve, 1));
> +
> +}
[Severity: Low]
This isn't a bug, but there is a stray blank line before the closing brace
of limits_interaction().
--
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261118-ct-invalid-nrpoc-v4-0-30baaeda3f87@virtuozzo.com?part=2
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
next prev parent reply other threads:[~2026-11-18 19:51 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-18 19:42 [Devel] [PATCH hci-8.1 v4 0/2] sched: Fix incorrect nproc report inside CT Vladimir Riabchun
2026-11-18 19:43 ` [Devel] [PATCH hci-8.1 v4 1/2] sched: Fix sched_getaffinity syscall Vladimir Riabchun
2026-11-18 19:47 ` no-reply
2026-11-18 19:43 ` [Devel] [PATCH hci-8.1 v4 2/2] selftests: ve: Test sched_getaffinity in VE Vladimir Riabchun
2026-11-18 19:50 ` no-reply [this message]
2026-11-19 9:51 ` Vladimir Riabchun
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=010701a1f03593e1-3c86e92c-5f18-45c3-93bc-f5c3564d9da9-000000@eu-central-1.amazonses.com \
--to=no-reply@sashiko.virtuozzo.com \
--cc=devel@openvz.org \
--cc=khorenko@virtuozzo.com \
--cc=vladimir.riabchun@virtuozzo.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.