OpenVZ / Virtuozzo kernel development (devel@openvz.org)
 help / color / mirror / Atom feed
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 v5 2/2] selftests: ve: Test sched_getaffinity in VE
Date: Thu, 19 Nov 2026 10:01:43 +0000	[thread overview]
Message-ID: <010701a1f341461a-095b8946-cb80-4b24-818e-f7d8fb21925c-000000@eu-central-1.amazonses.com> (raw)
In-Reply-To: <20261119-ct-invalid-nrpoc-v5-2-ff22216f458b@virtuozzo.com>

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@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@sashiko.virtuozzo.com>

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

_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel

  reply	other threads:[~2026-11-19 10:03 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-19  9:54 [Devel] [PATCH hci-8.1 v5 0/2] sched: Fix incorrect nproc report inside CT Vladimir Riabchun
2026-11-19  9:54 ` [Devel] [PATCH hci-8.1 v5 1/2] sched: Fix sched_getaffinity syscall Vladimir Riabchun
2026-11-19 17:32   ` Konstantin Khorenko
2026-11-19  9:54 ` [Devel] [PATCH hci-8.1 v5 2/2] selftests: ve: Test sched_getaffinity in VE Vladimir Riabchun
2026-11-19 10:01   ` no-reply [this message]
2026-11-19 17:32   ` Konstantin Khorenko
2026-11-19 17:32 ` [Devel] [PATCH hci-8.1 v5 0/2] sched: Fix incorrect nproc report inside CT Konstantin Khorenko

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=010701a1f341461a-095b8946-cb80-4b24-818e-f7d8fb21925c-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox