[Devel] [PATCH hci-8.1 v5 2/2] selftests: ve: Test sched_getaffinity in VE

no-reply at sashiko.virtuozzo.com no-reply at sashiko.virtuozzo.com
Thu Nov 19 13:01:43 MSK 2026


Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Low] selftests/ve: CT cgroup leaked when FIXTURE_SETUP asserts after
  make_ve()
- [Low] selftests/ve: unused includes in ve_sched_getaffinity_test.c
- [Low] selftests/ve: expected VE CPU count taken from runner affinity,
  not CT cpuset
--

commit 5e9a4b8d7f3a2a0ccd577e3cb0c687874f127e7c
Author: Vladimir Riabchun <vladimir.riabchun at virtuozzo.com>

selftests: ve: Test sched_getaffinity in VE

Adds a selftest that checks sched_getaffinity() inside a VE respects both
the CT cgroup cpuset.cpus and cpu.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 000000000000..969daf32ffdb
> --- /dev/null
> +++ b/tools/testing/selftests/ve/ve_sched_getaffinity_test.c
> @@ -0,0 +1,214 @@
> +#define _GNU_SOURCE
> +#include <asm/unistd.h>
> +#include <linux/sched.h>
> +#include <sys/mman.h>
> +#include <sys/syscall.h>
> +#include <sys/stat.h>
> +#include <errno.h>
> +#include <sched.h>
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <unistd.h>
> +#include <string.h>

[Severity: Low]
This isn't a bug, but asm/unistd.h, linux/sched.h, sys/syscall.h, sys/stat.h
and stdlib.h are not used by anything in this file. They look copied from a
sibling test. Could they be dropped? The double-underscore name
__getaffinity_ve is also a style nit.

[ ... ]

> +FIXTURE_SETUP(ve_getaff_test)
> +{
> +	if (geteuid())
> +		SKIP(return, "needs root");
> +
> +	ASSERT_EQ(sched_getaffinity(getpid(), sizeof(cpu_set_t), &self->orig_cpuset), 0);
> +	self->orig_cpucount = CPU_COUNT(&self->orig_cpuset);

[Severity: Low]
Is orig_cpucount the right expected value for the CT? It is taken from the
runner's own affinity mask. The child created by run_in_ve() is attached to
the CT cgroup with enter_cgroup(), which replaces its cpus_mask with the
cgroup's effective cpus. The runner's narrowed mask is not inherited. The
runner is also moved to the root of the private cgroup2 mount at the end of
prepare_namespaces(), so orig_cpuset is stale for the rest of the test.

If the runner starts under "taskset -c 0,1" on a larger host, orig_cpucount
is 2 while the VE reports every online CPU. The first
check_cpumask_is_prefix(&in_ve, self->orig_cpucount) then fails spuriously.
get_nth_cpu() on orig_cpuset can also pick CPUs that are not in the CT
cpuset.

Could the expected count come from the CT cgroup's cpuset.cpus.effective
instead, or could the test skip when the runner's mask differs from the
online set? Also, sched_getaffinity() with sizeof(cpu_set_t) returns EINVAL
on machines with more than 1024 CPUs.

[ ... ]

> +	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 created by make_ve()? If ASSERT_GE() on ctid or
ASSERT_EQ() on prepare_namespaces() fails, the harness exits before
setup_completed is set, so FIXTURE_TEARDOWN never runs. The CT cgroup, its
CTID and any namespace fds already saved stay behind. Would it be better to
destroy the VE explicitly on these failure paths, or to move the fallible
steps out of FIXTURE_SETUP?

Carry the trailer below into the next revision and Sashiko will not review this patch again.

Reviewed-by: Sashiko <no-reply at sashiko.virtuozzo.com>

-- 
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261119-ct-invalid-nrpoc-v5-0-ff22216f458b@virtuozzo.com?part=2



More information about the Devel mailing list