All Virtuozzo development lists (kernel + QEMU)
 help / color / mirror / Atom feed
* [Devel] [PATCH hci-8.2 v2 0/3] selftests/ve: move ve_devcg_bpf and ve_printk into ve/
@ 2026-11-19  8:16 Mirian Shilakadze
  2026-11-19  8:16 ` [Devel] [PATCH hci-8.2 v2 1/3] selftests/ve: open the host cgroup2 mount instead of creating one Mirian Shilakadze
                   ` (4 more replies)
  0 siblings, 5 replies; 12+ messages in thread
From: Mirian Shilakadze @ 2026-11-19  8:16 UTC (permalink / raw)
  To: khorenko, vladimir.riabchun; +Cc: devel

ve_devcg_bpf and ve_printk live in their own selftest directories with
private copies of the helpers in ve_selftest.h. This series moves both
into tools/testing/selftests/ve/ and drops the copies. The test cases
are unchanged.
- 1/3 makes ve_selftest.h open the host cgroup2 mount instead of
  creating one. Creating it cleared nsdelegate and memory_recursiveprot
  on the host /sys/fs/cgroup every time a ve test ran.
- 2/3 moves ve_devcg_bpf
- 3/3 moves ve_printk

Changes since v1, after Sashiko's review:
- the commit messages no longer mention the spec or kselftest-list.txt,
  and say the test cases are unchanged instead of "no test logic change"
- 1/3 says the tests now need the host cgroup2 mount at /sys/fs/cgroup,
  and the two ve_cpuid_override log messages say "cannot open cgroup2"
- 2/3 drops TOOLS_INCLUDES, the installed kernel headers have
  orig_prog_len as well, and says how the shared helpers change the
  creation and removal of the VE cgroup
- open_cg2_fd() still fails rather than skips without cgroup2 at
  /sys/fs/cgroup, every vz10 host has it there

v1: http://lore.virtuozzo.com/20261119074808.478064-1-mirian.shilakadze@virtuozzo.com

The kernel spec builds ve_devcg_bpf and ve_printk as targets of their
own, and with FORCE_TARGETS a missing directory fails the build. So the
spec has to drop both in the same release:
https://bitbucket.org/virtuozzocore/vzkernel.vzspecs/pull-requests/82

Tested on vz10 kernel 6.12.0-211.75.1.26.2, old layout against new: all
53 cases give the same verdicts. The two ve_ns_owner cases fail in both
without the VSTOR-156012 fix. The host cgroup2 mount keeps nsdelegate
and memory_recursiveprot with the series and loses both without it.

https://virtuozzo.atlassian.net/browse/VSTOR-139515

Mirian Shilakadze (3):
  selftests/ve: open the host cgroup2 mount instead of creating one
  selftests/ve: move ve_devcg_bpf into ve/ and reuse ve_selftest.h
  selftests/ve: move ve_printk into ve/ and reuse ve_selftest.h

 tools/testing/selftests/Makefile              |   2 -
 tools/testing/selftests/ve/.gitignore         |   4 +
 tools/testing/selftests/ve/Makefile           |   3 +
 .../selftests/{ve_printk => ve}/test_segf.c   |   0
 .../selftests/{ve_printk => ve}/test_trap.c   |   0
 tools/testing/selftests/ve/ve_aio_ring_test.c |   2 +-
 .../selftests/ve/ve_cpuid_override_test.c     |  10 +-
 .../{ve_devcg_bpf => ve}/ve_devcg_bpf_test.c  |  89 +--------
 .../selftests/ve/ve_mount_accounting_test.c   |   2 +-
 tools/testing/selftests/ve/ve_ns_owner_test.c |   2 +-
 .../selftests/ve/ve_numa_migrate_test.c       |   4 +-
 .../ve/ve_numa_syscalls_prohibited_test.c     |   2 +-
 tools/testing/selftests/ve/ve_perms_test.c    |   2 +-
 .../{ve_printk => ve}/ve_printk_test.c        | 176 ++++--------------
 tools/testing/selftests/ve/ve_selftest.h      |  36 ++--
 .../testing/selftests/ve/ve_tmpfs_mpol_test.c |   2 +-
 tools/testing/selftests/ve/ve_vtty_stress.c   |   4 +-
 .../testing/selftests/ve_devcg_bpf/.gitignore |   1 -
 tools/testing/selftests/ve_devcg_bpf/Makefile |  10 -
 tools/testing/selftests/ve_printk/.gitignore  |   3 -
 tools/testing/selftests/ve_printk/Makefile    |   8 -
 21 files changed, 87 insertions(+), 275 deletions(-)
 rename tools/testing/selftests/{ve_printk => ve}/test_segf.c (100%)
 rename tools/testing/selftests/{ve_printk => ve}/test_trap.c (100%)
 rename tools/testing/selftests/{ve_devcg_bpf => ve}/ve_devcg_bpf_test.c (90%)
 rename tools/testing/selftests/{ve_printk => ve}/ve_printk_test.c (77%)
 delete mode 100644 tools/testing/selftests/ve_devcg_bpf/.gitignore
 delete mode 100644 tools/testing/selftests/ve_devcg_bpf/Makefile
 delete mode 100644 tools/testing/selftests/ve_printk/.gitignore
 delete mode 100644 tools/testing/selftests/ve_printk/Makefile

-- 
2.47.3

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

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Devel] [PATCH hci-8.2 v2 1/3] selftests/ve: open the host cgroup2 mount instead of creating one
  2026-11-19  8:16 [Devel] [PATCH hci-8.2 v2 0/3] selftests/ve: move ve_devcg_bpf and ve_printk into ve/ Mirian Shilakadze
@ 2026-11-19  8:16 ` Mirian Shilakadze
  2026-11-19  8:21   ` no-reply
  2026-11-19 17:00   ` Konstantin Khorenko
  2026-11-19  8:16 ` [Devel] [PATCH hci-8.2 v2 2/3] selftests/ve: move ve_devcg_bpf into ve/ and reuse ve_selftest.h Mirian Shilakadze
                   ` (3 subsequent siblings)
  4 siblings, 2 replies; 12+ messages in thread
From: Mirian Shilakadze @ 2026-11-19  8:16 UTC (permalink / raw)
  To: khorenko, vladimir.riabchun; +Cc: devel

mount_cg2_fd() gave the tests their cgroup2 fd by creating a fresh mount
with fsopen(), fsconfig() and fsmount(), with no options. That ends in
cgroup_get_tree(), which calls apply_cgroup_root_flags() with the new
mount's options once the tree is built. For a caller in the root cgroup
namespace that function does not only set the flags the new mount asked
for, it also clears on cgrp_dfl_root the nsdelegate,
memory_recursiveprot and other root options the new mount did not carry,
and cgrp_dfl_root is the one hierarchy behind every cgroup2 mount on the
host. So every fixture setup switched nsdelegate and
memory_recursiveprot off on the host /sys/fs/cgroup until something
remounted it. A node the ve tests had run on shows its cgroup2 mount
without either option, three untouched nodes of the same image still
show both.

Open the existing mount instead. open_cg2_fd() opens /sys/fs/cgroup as a
directory fd and checks with fstatfs() that it is cgroup2. The *at()
calls the tests make work on that fd as they did on the fsmount fd, and
nothing is mounted, so the host flags stay as systemd set them. The
tests now need the host cgroup2 mount at /sys/fs/cgroup, which every
vz10 host has. Every caller switches to it, and the messages that said
"mount" now say "open". The header also no longer needs the glibc 2.36
mount API wrappers.

Fixes: 2f614e4b0e5c ("selftests/ve: factor common helpers into ve_selftest.h")
Feature: fix selftests
https://virtuozzo.atlassian.net/browse/VSTOR-139515
Signed-off-by: Mirian Shilakadze <mirian.shilakadze@virtuozzo.com>
---
 tools/testing/selftests/ve/ve_aio_ring_test.c |  2 +-
 .../selftests/ve/ve_cpuid_override_test.c     | 10 +++---
 .../selftests/ve/ve_mount_accounting_test.c   |  2 +-
 tools/testing/selftests/ve/ve_ns_owner_test.c |  2 +-
 .../selftests/ve/ve_numa_migrate_test.c       |  4 +--
 .../ve/ve_numa_syscalls_prohibited_test.c     |  2 +-
 tools/testing/selftests/ve/ve_perms_test.c    |  2 +-
 tools/testing/selftests/ve/ve_selftest.h      | 36 ++++++++++---------
 .../testing/selftests/ve/ve_tmpfs_mpol_test.c |  2 +-
 tools/testing/selftests/ve/ve_vtty_stress.c   |  4 +--
 10 files changed, 35 insertions(+), 31 deletions(-)

diff --git a/tools/testing/selftests/ve/ve_aio_ring_test.c b/tools/testing/selftests/ve/ve_aio_ring_test.c
index 1922a05aceef..c5b90427bdb3 100644
--- a/tools/testing/selftests/ve/ve_aio_ring_test.c
+++ b/tools/testing/selftests/ve/ve_aio_ring_test.c
@@ -152,7 +152,7 @@ FIXTURE_SETUP(ve_aio_ring)
 			 MAP_SHARED | MAP_ANONYMOUS, -1, 0);
 	ASSERT_NE(self->arg, MAP_FAILED);
 
-	self->cgv2_fd = mount_cg2_fd();
+	self->cgv2_fd = open_cg2_fd();
 	ASSERT_GE(self->cgv2_fd, 0);
 
 	ASSERT_EQ(write_file_at(self->cgv2_fd, "cgroup.subtree_control",
diff --git a/tools/testing/selftests/ve/ve_cpuid_override_test.c b/tools/testing/selftests/ve/ve_cpuid_override_test.c
index b9f5e49d6c43..fe8959b2adf3 100644
--- a/tools/testing/selftests/ve/ve_cpuid_override_test.c
+++ b/tools/testing/selftests/ve/ve_cpuid_override_test.c
@@ -153,8 +153,8 @@ FIXTURE_SETUP(ve_cpuid_override)
 		 self->host.edx & ~self->bit);
 
 	/* Last, so that a failed ASSERT above leaves no VE cgroup behind. */
-	self->cgv2_fd = mount_cg2_fd();
-	ASSERT_GE(self->cgv2_fd, 0) TH_LOG("cgroup2 mount: %s", strerror(errno));
+	self->cgv2_fd = open_cg2_fd();
+	ASSERT_GE(self->cgv2_fd, 0) TH_LOG("cannot open cgroup2: %s", strerror(errno));
 	ASSERT_EQ(write_file_at(self->cgv2_fd, "cgroup.subtree_control",
 				VE_CONTROLLERS), 0);
 	self->ctid = make_ve(self->cgv2_fd, CTID_MIN);
@@ -164,7 +164,7 @@ FIXTURE_SETUP(ve_cpuid_override)
 /*
  * Runs after the test body in whichever process the harness picks, the test
  * process itself after a failed ASSERT, so the table is restored whether or
- * not one fired. The setup fd may be gone by then, hence the fresh mount.
+ * not one fired. The setup fd may be gone by then, hence a fresh one.
  */
 FIXTURE_TEARDOWN_PARENT(ve_cpuid_override)
 {
@@ -179,9 +179,9 @@ FIXTURE_TEARDOWN_PARENT(ve_cpuid_override)
 	if (self->child > 0)
 		kill(self->child, SIGKILL);
 
-	cgv2_fd = mount_cg2_fd();
+	cgv2_fd = open_cg2_fd();
 	if (cgv2_fd < 0) {
-		TH_LOG("cgroup2 mount: %s, VE cgroup %d left behind",
+		TH_LOG("cannot open cgroup2: %s, VE cgroup %d left behind",
 		       strerror(errno), self->ctid);
 		return;
 	}
diff --git a/tools/testing/selftests/ve/ve_mount_accounting_test.c b/tools/testing/selftests/ve/ve_mount_accounting_test.c
index 8bb13e961542..3c0791e80527 100644
--- a/tools/testing/selftests/ve/ve_mount_accounting_test.c
+++ b/tools/testing/selftests/ve/ve_mount_accounting_test.c
@@ -294,7 +294,7 @@ FIXTURE_SETUP(ve_mnt_acc)
 	int initial_mnt_avail_nr;
 	char path[64];
 
-	self->cgv2_fd = mount_cg2_fd();
+	self->cgv2_fd = open_cg2_fd();
 	ASSERT_GE(self->cgv2_fd, 0);
 	mkdir(TMP_DIR, 0755);
 
diff --git a/tools/testing/selftests/ve/ve_ns_owner_test.c b/tools/testing/selftests/ve/ve_ns_owner_test.c
index dcff4d54172d..a177514343a2 100644
--- a/tools/testing/selftests/ve/ve_ns_owner_test.c
+++ b/tools/testing/selftests/ve/ve_ns_owner_test.c
@@ -142,7 +142,7 @@ FIXTURE_SETUP(ve_ns_owner)
 	char val[16];
 	char path[PATH_MAX];
 
-	self->cgv2_fd = mount_cg2_fd();
+	self->cgv2_fd = open_cg2_fd();
 	ASSERT_GE(self->cgv2_fd, 0);
 
 	ASSERT_EQ(write_file_at(self->cgv2_fd, "cgroup.subtree_control",
diff --git a/tools/testing/selftests/ve/ve_numa_migrate_test.c b/tools/testing/selftests/ve/ve_numa_migrate_test.c
index 02e134bc914d..2223e770be62 100644
--- a/tools/testing/selftests/ve/ve_numa_migrate_test.c
+++ b/tools/testing/selftests/ve/ve_numa_migrate_test.c
@@ -363,9 +363,9 @@ static int prepare(FIXTURE_DATA(numa_migrate) *self, const char **why)
 {
 	int fd;
 
-	self->cgv2_fd = mount_cg2_fd();
+	self->cgv2_fd = open_cg2_fd();
 	if (self->cgv2_fd < 0) {
-		*why = "cannot mount cgroup2";
+		*why = "cannot open cgroup2";
 		goto fail;
 	}
 	if (write_file_at(self->cgv2_fd, "cgroup.subtree_control",
diff --git a/tools/testing/selftests/ve/ve_numa_syscalls_prohibited_test.c b/tools/testing/selftests/ve/ve_numa_syscalls_prohibited_test.c
index c76fcb1c79ff..ef44b1191c70 100644
--- a/tools/testing/selftests/ve/ve_numa_syscalls_prohibited_test.c
+++ b/tools/testing/selftests/ve/ve_numa_syscalls_prohibited_test.c
@@ -126,7 +126,7 @@ FIXTURE_SETUP(numa_syscalls)
 	}
 	ASSERT_LT(i, NODE_BITS);
 
-	self->cgv2_fd = mount_cg2_fd();
+	self->cgv2_fd = open_cg2_fd();
 	ASSERT_GE(self->cgv2_fd, 0);
 	ASSERT_EQ(write_file_at(self->cgv2_fd, "cgroup.subtree_control",
 				VE_CONTROLLERS), 0);
diff --git a/tools/testing/selftests/ve/ve_perms_test.c b/tools/testing/selftests/ve/ve_perms_test.c
index c57325d10901..375f98c36f87 100644
--- a/tools/testing/selftests/ve/ve_perms_test.c
+++ b/tools/testing/selftests/ve/ve_perms_test.c
@@ -189,7 +189,7 @@ static int default_granted(int cgv2_fd, const char *fs, const char *entry)
 
 FIXTURE_SETUP(ve_perms)
 {
-	self->cgv2_fd = mount_cg2_fd();
+	self->cgv2_fd = open_cg2_fd();
 	ASSERT_GE(self->cgv2_fd, 0);
 
 	ASSERT_EQ(write_file_at(self->cgv2_fd, "cgroup.subtree_control",
diff --git a/tools/testing/selftests/ve/ve_selftest.h b/tools/testing/selftests/ve/ve_selftest.h
index 1fc3f8dcac18..af7725600453 100644
--- a/tools/testing/selftests/ve/ve_selftest.h
+++ b/tools/testing/selftests/ve/ve_selftest.h
@@ -1,8 +1,8 @@
 /* SPDX-License-Identifier: GPL-2.0 */
 /*
- * Shared helpers for the ve selftests: a private cgroup2 mount, small file and
- * cgroup helpers, VE cgroup create and destroy, and a mount point query, used
- * across the tests in this directory.
+ * Shared helpers for the ve selftests: the host cgroup2 mount as a directory
+ * fd, small file and cgroup helpers, VE cgroup create and destroy, and a mount
+ * point query, used across the tests in this directory.
  */
 #ifndef __SELFTESTS_VE_VE_SELFTEST_H
 #define __SELFTESTS_VE_VE_SELFTEST_H
@@ -15,8 +15,9 @@
 #include <errno.h>
 #include <limits.h>
 #include <sys/stat.h>
-#include <sys/mount.h>
+#include <sys/vfs.h>
 #include <sys/syscall.h>
+#include <linux/magic.h>
 #include <linux/openat2.h>
 
 #ifndef CLONE_NEWVE
@@ -245,23 +246,26 @@ static inline int read_s32_at(int dirfd, const char *path,
 	return 0;
 }
 
-/* A fresh, private cgroup2 mount, returned as an fd to use with *at() calls. */
-static inline int mount_cg2_fd(void)
+/*
+ * The host cgroup2 mount as a directory fd to use with *at() calls. The mount
+ * is opened, not created: mounting cgroup2 from the root cgroup namespace
+ * applies the new mount's options to the whole hierarchy and clears the ones
+ * it does not carry, nsdelegate and memory_recursiveprot included.
+ */
+static inline int open_cg2_fd(void)
 {
-	int fs_fd, mnt_fd;
+	struct statfs st;
+	int fd;
 
-	fs_fd = fsopen("cgroup2", 0);
-	if (fs_fd < 0)
+	fd = open("/sys/fs/cgroup", O_RDONLY | O_DIRECTORY | O_CLOEXEC);
+	if (fd < 0)
 		return -1;
-
-	if (fsconfig(fs_fd, FSCONFIG_CMD_CREATE, NULL, NULL, 0) < 0) {
-		close(fs_fd);
+	if (fstatfs(fd, &st) < 0 || st.f_type != CGROUP2_SUPER_MAGIC) {
+		close(fd);
+		errno = ENODEV;
 		return -1;
 	}
-
-	mnt_fd = fsmount(fs_fd, 0, 0);
-	close(fs_fd);
-	return mnt_fd;
+	return fd;
 }
 
 /* Move the caller into cgroup @ctid (or the root when @ctid is 0). */
diff --git a/tools/testing/selftests/ve/ve_tmpfs_mpol_test.c b/tools/testing/selftests/ve/ve_tmpfs_mpol_test.c
index 6254f95fadec..dbc1a51941a0 100644
--- a/tools/testing/selftests/ve/ve_tmpfs_mpol_test.c
+++ b/tools/testing/selftests/ve/ve_tmpfs_mpol_test.c
@@ -57,7 +57,7 @@ FIXTURE_SETUP(tmpfs_mpol)
 		SKIP(return, "no NUMA API on the host");
 	ASSERT_EQ(ret, 0);
 
-	self->cgv2_fd = mount_cg2_fd();
+	self->cgv2_fd = open_cg2_fd();
 	ASSERT_GE(self->cgv2_fd, 0);
 	ASSERT_EQ(write_file_at(self->cgv2_fd, "cgroup.subtree_control",
 				VE_CONTROLLERS), 0);
diff --git a/tools/testing/selftests/ve/ve_vtty_stress.c b/tools/testing/selftests/ve/ve_vtty_stress.c
index f4bdd81133b8..318ccab5bcdb 100644
--- a/tools/testing/selftests/ve/ve_vtty_stress.c
+++ b/tools/testing/selftests/ve/ve_vtty_stress.c
@@ -192,9 +192,9 @@ int main(int argc, char **argv)
 			       "(vzdev, vzmon) are needed\n",
 			       strerror(errno));
 
-	cg = mount_cg2_fd();
+	cg = open_cg2_fd();
 	if (cg < 0)
-		ksft_exit_skip("cannot mount cgroup2: %s\n", strerror(errno));
+		ksft_exit_skip("cannot open cgroup2: %s\n", strerror(errno));
 	if (write_file_at(cg, "cgroup.subtree_control", VE_CONTROLLERS) < 0)
 		ksft_exit_skip("cannot enable the ve controller: %s\n",
 			       strerror(errno));
-- 
2.47.3

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

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Devel] [PATCH hci-8.2 v2 2/3] selftests/ve: move ve_devcg_bpf into ve/ and reuse ve_selftest.h
  2026-11-19  8:16 [Devel] [PATCH hci-8.2 v2 0/3] selftests/ve: move ve_devcg_bpf and ve_printk into ve/ Mirian Shilakadze
  2026-11-19  8:16 ` [Devel] [PATCH hci-8.2 v2 1/3] selftests/ve: open the host cgroup2 mount instead of creating one Mirian Shilakadze
@ 2026-11-19  8:16 ` Mirian Shilakadze
  2026-11-19  8:20   ` no-reply
  2026-11-19 17:00   ` Konstantin Khorenko
  2026-11-19  8:16 ` [Devel] [PATCH hci-8.2 v2 3/3] selftests/ve: move ve_printk " Mirian Shilakadze
                   ` (2 subsequent siblings)
  4 siblings, 2 replies; 12+ messages in thread
From: Mirian Shilakadze @ 2026-11-19  8:16 UTC (permalink / raw)
  To: khorenko, vladimir.riabchun; +Cc: devel

ve_devcg_bpf lives in its own selftests directory and carries private
copies of the helpers that ve_selftest.h provides: a mount_cg2_fd of its
own, which creates the optionless cgroup2 mount the previous commit
stopped the shared header from creating, write_file_at, enter_cgroup,
the free ctid search and VE cgroup creation, the CLONE_NEWVE fallback,
the ctid range and the controller set a VE cgroup needs enabled.

Move the test into tools/testing/selftests/ve/, include ve_selftest.h
and drop the local copies. The fixture takes its cgroup2 fd from
open_cg2_fd(), creates its VE cgroup with make_ve and removes it with
destroy_ve. The vz.slice removal in the teardown stays: the kernel
creates that cgroup under the VE root when the container is started,
and this test starts one. The TOOLS_INCLUDES flag is not carried over,
the ve Makefile builds against the installed kernel headers, which have
orig_prog_len as well. destroy_ve retries a busy cgroup for up to a
second and make_ve removes the cgroup when unhiding the ve files fails.
The old code did neither. The test cases are unchanged.

Feature: fix selftests
https://virtuozzo.atlassian.net/browse/VSTOR-139515
Signed-off-by: Mirian Shilakadze <mirian.shilakadze@virtuozzo.com>
---
 tools/testing/selftests/Makefile              |  1 -
 tools/testing/selftests/ve/.gitignore         |  1 +
 tools/testing/selftests/ve/Makefile           |  1 +
 .../{ve_devcg_bpf => ve}/ve_devcg_bpf_test.c  | 89 ++-----------------
 .../testing/selftests/ve_devcg_bpf/.gitignore |  1 -
 tools/testing/selftests/ve_devcg_bpf/Makefile | 10 ---
 6 files changed, 9 insertions(+), 94 deletions(-)
 rename tools/testing/selftests/{ve_devcg_bpf => ve}/ve_devcg_bpf_test.c (90%)
 delete mode 100644 tools/testing/selftests/ve_devcg_bpf/.gitignore
 delete mode 100644 tools/testing/selftests/ve_devcg_bpf/Makefile

diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile
index 8ec0ba2deb62..9f820344c16c 100644
--- a/tools/testing/selftests/Makefile
+++ b/tools/testing/selftests/Makefile
@@ -119,7 +119,6 @@ TARGETS += user_events
 TARGETS += vDSO
 TARGETS += ve
 TARGETS += ve_printk
-TARGETS += ve_devcg_bpf
 TARGETS += mm
 TARGETS += vfio
 TARGETS += x86
diff --git a/tools/testing/selftests/ve/.gitignore b/tools/testing/selftests/ve/.gitignore
index a468ef980e28..9b1a8911b4cf 100644
--- a/tools/testing/selftests/ve/.gitignore
+++ b/tools/testing/selftests/ve/.gitignore
@@ -7,3 +7,4 @@ ve_numa_migrate_test
 ve_aio_ring_test
 ve_numa_syscalls_prohibited_test
 ve_tmpfs_mpol_test
+ve_devcg_bpf_test
diff --git a/tools/testing/selftests/ve/Makefile b/tools/testing/selftests/ve/Makefile
index fa4f858227e5..38d92eecc3c8 100644
--- a/tools/testing/selftests/ve/Makefile
+++ b/tools/testing/selftests/ve/Makefile
@@ -10,6 +10,7 @@ TEST_GEN_PROGS += ve_numa_migrate_test
 TEST_GEN_PROGS += ve_aio_ring_test
 TEST_GEN_PROGS += ve_numa_syscalls_prohibited_test
 TEST_GEN_PROGS += ve_tmpfs_mpol_test
+TEST_GEN_PROGS += ve_devcg_bpf_test
 
 # CPUID faulting is x86-64 only. ARCH says "x86" for 32-bit too and lib.mk
 # picks the clang target by its emptiness, so decide by the compiler.
diff --git a/tools/testing/selftests/ve_devcg_bpf/ve_devcg_bpf_test.c b/tools/testing/selftests/ve/ve_devcg_bpf_test.c
similarity index 90%
rename from tools/testing/selftests/ve_devcg_bpf/ve_devcg_bpf_test.c
rename to tools/testing/selftests/ve/ve_devcg_bpf_test.c
index cca0f6905d8d..4027754ace34 100644
--- a/tools/testing/selftests/ve_devcg_bpf/ve_devcg_bpf_test.c
+++ b/tools/testing/selftests/ve/ve_devcg_bpf_test.c
@@ -35,13 +35,7 @@
 #include <errno.h>
 
 #include "../kselftest_harness.h"
-
-#define CTID_MIN		108
-#define CTID_MAX		200
-
-#ifndef CLONE_NEWVE
-#define CLONE_NEWVE		0x00000040
-#endif
+#include "ve_selftest.h"
 
 #ifndef VE_FEATURE_BPF
 #define VE_FEATURE_SYSFS	(1ULL << 0)	/* deprecated */
@@ -74,20 +68,6 @@
 #endif
 
 
-static int write_file_at(int dirfd, const char *path, const char *val)
-{
-	int fd, ret;
-	size_t len = strlen(val);
-
-	fd = openat(dirfd, path, O_WRONLY);
-	if (fd < 0)
-		return -1;
-
-	ret = write(fd, val, len);
-	close(fd);
-	return (ret == len) ? 0 : -1;
-}
-
 enum {
 	TEST_PROG_LOAD,
 	TEST_PROG_LOAD_DENIED,
@@ -132,25 +112,6 @@ static int load_devcg_prog(void)
 	return syscall(__NR_bpf, BPF_PROG_LOAD, &attr, sizeof(attr));
 }
 
-static int mount_cg2_fd(void)
-{
-	int fs_fd, mnt_fd;
-
-	fs_fd = syscall(__NR_fsopen, "cgroup2", 0);
-	if (fs_fd < 0)
-		return -1;
-
-	if (syscall(__NR_fsconfig, fs_fd, FSCONFIG_CMD_CREATE,
-		    NULL, NULL, 0) < 0) {
-		close(fs_fd);
-		return -1;
-	}
-
-	mnt_fd = syscall(__NR_fsmount, fs_fd, 0, 0);
-	close(fs_fd);
-	return mnt_fd;
-}
-
 static int test_prog_load(void)
 {
 	int fd;
@@ -524,30 +485,6 @@ int child_func(void *arg)
 	return ret;
 }
 
-int enter_cgroup(int cgv2_fd, int ctid)
-{
-	char cg_path[64];
-	char pid_str[64];
-	int fd;
-	int ret;
-
-	if (ctid)
-		snprintf(cg_path, sizeof(cg_path), "%d/cgroup.procs", ctid);
-	else
-		snprintf(cg_path, sizeof(cg_path), "cgroup.procs");
-	fd = openat(cgv2_fd, cg_path, O_WRONLY);
-	if (fd < 0)
-		return -1;
-
-	snprintf(pid_str, sizeof(pid_str), "%d", getpid());
-	ret = write(fd, pid_str, strlen(pid_str));
-	if (ret < 0 || ret != strlen(pid_str))
-		ret = -1;
-
-	close(fd);
-	return ret;
-}
-
 int run_vzct(struct __test_metadata *_metadata, int cgv2_fd, int ctid,
 	     int testid)
 {
@@ -592,11 +529,11 @@ FIXTURE_SETUP(ve_devcg_bpf)
 	char ctid_str[16];
 	char path[64];
 
-	self->cgv2_fd = mount_cg2_fd();
+	self->cgv2_fd = open_cg2_fd();
 	ASSERT_GE(self->cgv2_fd, 0);
 
 	ASSERT_EQ(write_file_at(self->cgv2_fd, "cgroup.subtree_control",
-		  "+cpuset +cpu +cpuacct +io +memory +hugetlb +pids +rdma +misc +ve"), 0);
+		  VE_CONTROLLERS), 0);
 
 	ASSERT_EQ(write_file_at(self->cgv2_fd,
 		  "ve.default_sysfs_permissions", "/ rx"), 0);
@@ -605,21 +542,10 @@ FIXTURE_SETUP(ve_devcg_bpf)
 	ASSERT_EQ(write_file_at(self->cgv2_fd,
 		  "ve.default_sysfs_permissions", "fs/cgroup rw"), 0);
 
-	self->ctid = CTID_MIN;
-	while (self->ctid < CTID_MAX) {
-		snprintf(ctid_str, sizeof(ctid_str), "%d", self->ctid);
-		if (faccessat(self->cgv2_fd, ctid_str, F_OK, 0) != 0 &&
-		    errno == ENOENT)
-			break;
-		self->ctid++;
-	}
-	ASSERT_LT(self->ctid, CTID_MAX);
-
-	ASSERT_EQ(mkdirat(self->cgv2_fd, ctid_str, 0755), 0);
-
-	snprintf(path, sizeof(path), "%d/cgroup.controllers_hidden", self->ctid);
-	ASSERT_EQ(write_file_at(self->cgv2_fd, path, "-ve"), 0);
+	self->ctid = make_ve(self->cgv2_fd, CTID_MIN);
+	ASSERT_GE(self->ctid, 0);
 
+	snprintf(ctid_str, sizeof(ctid_str), "%d", self->ctid);
 	snprintf(path, sizeof(path), "%d/ve.veid", self->ctid);
 	ASSERT_EQ(write_file_at(self->cgv2_fd, path, ctid_str), 0);
 };
@@ -630,8 +556,7 @@ FIXTURE_TEARDOWN(ve_devcg_bpf)
 
 	snprintf(path, sizeof(path), "%d/vz.slice", self->ctid);
 	unlinkat(self->cgv2_fd, path, AT_REMOVEDIR);
-	snprintf(path, sizeof(path), "%d", self->ctid);
-	unlinkat(self->cgv2_fd, path, AT_REMOVEDIR);
+	destroy_ve(self->cgv2_fd, self->ctid);
 	close(self->cgv2_fd);
 }
 
diff --git a/tools/testing/selftests/ve_devcg_bpf/.gitignore b/tools/testing/selftests/ve_devcg_bpf/.gitignore
deleted file mode 100644
index a1f032ce2428..000000000000
--- a/tools/testing/selftests/ve_devcg_bpf/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-ve_devcg_bpf_test
diff --git a/tools/testing/selftests/ve_devcg_bpf/Makefile b/tools/testing/selftests/ve_devcg_bpf/Makefile
deleted file mode 100644
index ba811f22e36a..000000000000
--- a/tools/testing/selftests/ve_devcg_bpf/Makefile
+++ /dev/null
@@ -1,10 +0,0 @@
-# SPDX-License-Identifier: GPL-2.0
-# Makefile for ve_devcg_bpf selftests.
-CFLAGS += -g -Wall -O2
-# orig_prog_len/orig_prog_insns may be newer than the system UAPI headers, so
-# build against the in-tree copy under tools/include/uapi.
-CFLAGS += $(TOOLS_INCLUDES)
-
-TEST_GEN_PROGS += ve_devcg_bpf_test
-
-include ../lib.mk
-- 
2.47.3

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

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Devel] [PATCH hci-8.2 v2 3/3] selftests/ve: move ve_printk into ve/ and reuse ve_selftest.h
  2026-11-19  8:16 [Devel] [PATCH hci-8.2 v2 0/3] selftests/ve: move ve_devcg_bpf and ve_printk into ve/ Mirian Shilakadze
  2026-11-19  8:16 ` [Devel] [PATCH hci-8.2 v2 1/3] selftests/ve: open the host cgroup2 mount instead of creating one Mirian Shilakadze
  2026-11-19  8:16 ` [Devel] [PATCH hci-8.2 v2 2/3] selftests/ve: move ve_devcg_bpf into ve/ and reuse ve_selftest.h Mirian Shilakadze
@ 2026-11-19  8:16 ` Mirian Shilakadze
  2026-11-19  8:22   ` no-reply
  2026-11-19 17:00   ` Konstantin Khorenko
  2026-11-19 17:00 ` [Devel] [PATCH hci-8.2 v2 0/3] selftests/ve: move ve_devcg_bpf and ve_printk into ve/ Konstantin Khorenko
  2026-11-19 17:01 ` Konstantin Khorenko
  4 siblings, 2 replies; 12+ messages in thread
From: Mirian Shilakadze @ 2026-11-19  8:16 UTC (permalink / raw)
  To: khorenko, vladimir.riabchun; +Cc: devel

ve_printk lives in its own selftests directory and drives the cgroup
side of its fixture by hand: it looks the cgroup2 mount up in
/proc/mounts, writes the control files through system("echo ..."),
searches the free ctid itself and has a path based enter_cgroup. The
openat based form of all of that is in ve_selftest.h, used by the other
ve tests.

Move the test and its two helper programs into
tools/testing/selftests/ve/, include ve_selftest.h and drop the local
copies. The fixture holds the fd of the host cgroup2 mount from
open_cg2_fd() instead of a path, creates its VE cgroup with make_ve and
removes it with destroy_ve, and the container child writes ve.state
through write_file_at on that fd. The vz.slice removal in the teardown
stays, since the kernel creates that cgroup when the container is
started. The includes that lose their last user with the local helpers
go too, together with the unused __STACK_SIZE define and time.h include
next to them.

The -I../../../../usr/include flag is dropped: the ve Makefile already
passes the same headers through KHDR_INCLUDES. Like the other ve tests,
the fixture now needs the host cgroup2 mount at /sys/fs/cgroup instead
of looking one up in /proc/mounts. The test cases are unchanged.

Feature: fix selftests
https://virtuozzo.atlassian.net/browse/VSTOR-139515
Signed-off-by: Mirian Shilakadze <mirian.shilakadze@virtuozzo.com>
---
 tools/testing/selftests/Makefile              |   1 -
 tools/testing/selftests/ve/.gitignore         |   3 +
 tools/testing/selftests/ve/Makefile           |   2 +
 .../selftests/{ve_printk => ve}/test_segf.c   |   0
 .../selftests/{ve_printk => ve}/test_trap.c   |   0
 .../{ve_printk => ve}/ve_printk_test.c        | 176 ++++--------------
 tools/testing/selftests/ve_printk/.gitignore  |   3 -
 tools/testing/selftests/ve_printk/Makefile    |   8 -
 8 files changed, 43 insertions(+), 150 deletions(-)
 rename tools/testing/selftests/{ve_printk => ve}/test_segf.c (100%)
 rename tools/testing/selftests/{ve_printk => ve}/test_trap.c (100%)
 rename tools/testing/selftests/{ve_printk => ve}/ve_printk_test.c (77%)
 delete mode 100644 tools/testing/selftests/ve_printk/.gitignore
 delete mode 100644 tools/testing/selftests/ve_printk/Makefile

diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile
index 9f820344c16c..7f458f1bcb5c 100644
--- a/tools/testing/selftests/Makefile
+++ b/tools/testing/selftests/Makefile
@@ -118,7 +118,6 @@ TARGETS += uevent
 TARGETS += user_events
 TARGETS += vDSO
 TARGETS += ve
-TARGETS += ve_printk
 TARGETS += mm
 TARGETS += vfio
 TARGETS += x86
diff --git a/tools/testing/selftests/ve/.gitignore b/tools/testing/selftests/ve/.gitignore
index 9b1a8911b4cf..9f0f4832326e 100644
--- a/tools/testing/selftests/ve/.gitignore
+++ b/tools/testing/selftests/ve/.gitignore
@@ -8,3 +8,6 @@ ve_aio_ring_test
 ve_numa_syscalls_prohibited_test
 ve_tmpfs_mpol_test
 ve_devcg_bpf_test
+ve_printk_test
+test_segf
+test_trap
diff --git a/tools/testing/selftests/ve/Makefile b/tools/testing/selftests/ve/Makefile
index 38d92eecc3c8..36c068b4bb66 100644
--- a/tools/testing/selftests/ve/Makefile
+++ b/tools/testing/selftests/ve/Makefile
@@ -11,6 +11,8 @@ TEST_GEN_PROGS += ve_aio_ring_test
 TEST_GEN_PROGS += ve_numa_syscalls_prohibited_test
 TEST_GEN_PROGS += ve_tmpfs_mpol_test
 TEST_GEN_PROGS += ve_devcg_bpf_test
+TEST_GEN_PROGS += ve_printk_test
+TEST_GEN_FILES += test_segf test_trap
 
 # CPUID faulting is x86-64 only. ARCH says "x86" for 32-bit too and lib.mk
 # picks the clang target by its emptiness, so decide by the compiler.
diff --git a/tools/testing/selftests/ve_printk/test_segf.c b/tools/testing/selftests/ve/test_segf.c
similarity index 100%
rename from tools/testing/selftests/ve_printk/test_segf.c
rename to tools/testing/selftests/ve/test_segf.c
diff --git a/tools/testing/selftests/ve_printk/test_trap.c b/tools/testing/selftests/ve/test_trap.c
similarity index 100%
rename from tools/testing/selftests/ve_printk/test_trap.c
rename to tools/testing/selftests/ve/test_trap.c
diff --git a/tools/testing/selftests/ve_printk/ve_printk_test.c b/tools/testing/selftests/ve/ve_printk_test.c
similarity index 77%
rename from tools/testing/selftests/ve_printk/ve_printk_test.c
rename to tools/testing/selftests/ve/ve_printk_test.c
index 020df691e5d5..fa8403da089f 100644
--- a/tools/testing/selftests/ve_printk/ve_printk_test.c
+++ b/tools/testing/selftests/ve/ve_printk_test.c
@@ -22,7 +22,6 @@
  */
 #define _GNU_SOURCE
 #include <linux/sched.h>
-#include <time.h>
 #include <sched.h>
 #include <sys/wait.h>
 #include <unistd.h>
@@ -31,119 +30,56 @@
 #include <stdlib.h>
 #include <fcntl.h>
 #include <string.h>
-#include <sys/stat.h>
 #include <sys/mount.h>
-#include <linux/limits.h>
-#include <errno.h>
 
 #include "../kselftest_harness.h"
+#include "ve_selftest.h"
 
-#define __STACK_SIZE (8 * 1024 * 1024)
-#define CTID_MIN 108
-#define CTID_MAX 200
 #define SEGFAULT_PROG "test_segf"
 #define TRAP_PROG "test_trap"
 #define TEST_RATELIMIT_BURST 10
 #define TEST_RATELIMIT 5
 
-static int has_substr(char *buf, const char *str)
-{
-	char *token;
-	char *str_ptr = buf;
-
-	while ((token = strsep(&str_ptr, ",")) != NULL) {
-		if (!strcmp(token, str))
-			return 1;
-	}
-	return 0;
-}
-
-static int get_mount_path(const char *fstype, const char *subsys, char *out, int size)
-{
-	FILE *fp;
-	int n;
-	char buf[PATH_MAX];
-	char target[4096];
-	char ops[4096];
-	char format[4096];
-	int ret = 1;
-
-	snprintf(format, sizeof(format), "%%*s %%4095s %s %%4095s", fstype);
-
-	fp = fopen("/proc/mounts", "r");
-	if (fp == NULL)
-		return -1;
-
-	while (fgets(buf, sizeof(buf), fp)) {
-		n = sscanf(buf, format, target, ops);
-		if (n != 2)
-			continue;
-		if (subsys == NULL || has_substr(ops, subsys)) {
-			strncpy(out, target, size);
-			out[size-1] = '\0';
-			ret = 0;
-			break;
-		}
-	}
-	fclose(fp);
-
-	return ret;
-}
-
 FIXTURE(ve_printk)
 {
-	char cgv2_path[PATH_MAX];
+	int cgv2_fd;
 	int ctid;
 };
 
 FIXTURE_SETUP(ve_printk)
 {
-	char path[PATH_MAX * 2];
-
-	ASSERT_EQ(get_mount_path("cgroup2", NULL, self->cgv2_path, sizeof(self->cgv2_path)), 0);
+	char ctid_str[16];
+	char path[64];
 
-	snprintf(path, sizeof(path), "echo \"+cpuset +cpu +cpuacct +io +memory +hugetlb +pids +rdma +misc +ve\""
-				     " > %s/cgroup.subtree_control 2>/dev/null", self->cgv2_path);
-	ASSERT_EQ(system(path), 0);
+	self->cgv2_fd = open_cg2_fd();
+	ASSERT_GE(self->cgv2_fd, 0);
 
-	snprintf(path, sizeof(path), "echo \"/ rx\" > %s/ve.default_sysfs_permissions 2>/dev/null", self->cgv2_path);
-	ASSERT_EQ(system(path), 0);
-
-	snprintf(path, sizeof(path), "echo \"fs rx\" > %s/ve.default_sysfs_permissions 2>/dev/null", self->cgv2_path);
-	ASSERT_EQ(system(path), 0);
-
-	snprintf(path, sizeof(path), "echo \"fs/cgroup rw\" > %s/ve.default_sysfs_permissions 2>/dev/null", self->cgv2_path);
-	ASSERT_EQ(system(path), 0);
-
-	self->ctid = CTID_MIN;
-	while (self->ctid < CTID_MAX) {
-		snprintf(path, sizeof(path), "%s/%d", self->cgv2_path, self->ctid);
-		if (access(path, F_OK) != 0 && errno == ENOENT) {
-			break;
-		}
-		self->ctid++;
-	}
-	ASSERT_LT(self->ctid, CTID_MAX);
+	ASSERT_EQ(write_file_at(self->cgv2_fd, "cgroup.subtree_control",
+		  VE_CONTROLLERS), 0);
 
-	ASSERT_EQ(mkdir(path, 0755), 0);
+	ASSERT_EQ(write_file_at(self->cgv2_fd,
+		  "ve.default_sysfs_permissions", "/ rx"), 0);
+	ASSERT_EQ(write_file_at(self->cgv2_fd,
+		  "ve.default_sysfs_permissions", "fs rx"), 0);
+	ASSERT_EQ(write_file_at(self->cgv2_fd,
+		  "ve.default_sysfs_permissions", "fs/cgroup rw"), 0);
 
-	snprintf(path, sizeof(path), "echo -ve > %s/%d/cgroup.controllers_hidden",
-			self->cgv2_path, self->ctid);
-	ASSERT_EQ(system(path), 0);
+	self->ctid = make_ve(self->cgv2_fd, CTID_MIN);
+	ASSERT_GE(self->ctid, 0);
 
-	snprintf(path, sizeof(path), "echo %d > %s/%d/ve.veid",
-			self->ctid, self->cgv2_path, self->ctid);
-	ASSERT_EQ(system(path), 0);
+	snprintf(ctid_str, sizeof(ctid_str), "%d", self->ctid);
+	snprintf(path, sizeof(path), "%d/ve.veid", self->ctid);
+	ASSERT_EQ(write_file_at(self->cgv2_fd, path, ctid_str), 0);
 };
 
 FIXTURE_TEARDOWN(ve_printk)
 {
-	char path[PATH_MAX * 2];
+	char path[64];
 
-	snprintf(path, sizeof(path), "%s/%d/vz.slice", self->cgv2_path, self->ctid);
-	rmdir(path);
-	snprintf(path, sizeof(path), "%s/%d", self->cgv2_path, self->ctid);
-	rmdir(path);
+	snprintf(path, sizeof(path), "%d/vz.slice", self->ctid);
+	unlinkat(self->cgv2_fd, path, AT_REMOVEDIR);
+	destroy_ve(self->cgv2_fd, self->ctid);
+	close(self->cgv2_fd);
 }
 
 int setup_timens(void)
@@ -169,7 +105,7 @@ int setup_timens(void)
 }
 
 struct fargs {
-	char *cgve;
+	int cgv2_fd;
 	int ctid;
 	int test;
 };
@@ -371,14 +307,12 @@ int child_func(void *arg)
 	int ret;
 	int fd;
 	struct fargs *args = (struct fargs *)arg;
-	char cg_state[PATH_MAX];
+	char path[64];
 
 	ret = setup_timens();
 	if (ret)
 		return ret;
 
-	snprintf(cg_state, sizeof(cg_state), "%s/%d/ve.state", args->cgve, args->ctid);
-
 	(void)umount2("/proc", MNT_DETACH);
 	ret = mount("proc", "/proc", "proc", 0, NULL);
 	if (ret < 0)
@@ -394,18 +328,10 @@ int child_func(void *arg)
 	}
 	close(fd);
 
-	fd = open(cg_state, O_WRONLY);
-	if (fd < 0) {
-		return 1;
-	}
-
-	ret = write(fd, "START", strlen("START"));
-	if (ret < 0 || ret != strlen("START")) {
-		close(fd);
+	snprintf(path, sizeof(path), "%d/ve.state", args->ctid);
+	ret = write_file_at(args->cgv2_fd, path, "START");
+	if (ret < 0)
 		return 1;
-	}
-
-	close(fd);
 
 	switch (args->test) {
 	case TEST_LOG:
@@ -429,37 +355,11 @@ int child_func(void *arg)
 	return ret;
 }
 
-int enter_cgroup(const char *cgroup, int ctid)
-{
-	char cg_path[PATH_MAX];
-	char pid_str[64];
-	int fd;
-	int ret = 0;
-
-	if (ctid)
-		snprintf(cg_path, sizeof(cg_path), "%s/%d/cgroup.procs", cgroup, ctid);
-	else
-		snprintf(cg_path, sizeof(cg_path), "%s/cgroup.procs", cgroup);
-	snprintf(pid_str, sizeof(pid_str), "%d", getpid());
-	fd = open(cg_path, O_WRONLY);
-	if (fd < 0) {
-		return -1;
-	}
-
-	ret = write(fd, pid_str, strlen(pid_str));
-	if (ret < 0 || ret != strlen(pid_str)) {
-		ret = -1;
-	}
-
-	close(fd);
-	return ret;
-}
-
-int run_vzct(char *cgv2, int ctid, int testid)
+int run_vzct(int cgv2_fd, int ctid, int testid)
 {
 	pid_t pid;
 	struct fargs args = {
-		.cgve = cgv2,
+		.cgv2_fd = cgv2_fd,
 		.ctid = ctid,
 		.test = testid,
 	};
@@ -472,7 +372,7 @@ int run_vzct(char *cgv2, int ctid, int testid)
 	int status;
 	int ret;
 
-	ret = enter_cgroup(cgv2, ctid);
+	ret = enter_cgroup(cgv2_fd, ctid);
 	if (ret < 0)
 		return -1;
 
@@ -489,7 +389,7 @@ int run_vzct(char *cgv2, int ctid, int testid)
 	if (WIFEXITED(status)) {
 		ret = WEXITSTATUS(status);
 	}
-	enter_cgroup(cgv2, 0);
+	enter_cgroup(cgv2_fd, 0);
 
 	return ret;
 }
@@ -566,7 +466,7 @@ TEST_F(ve_printk, ve_log)
 	fdmesg = open_dmesg();
 	ASSERT_NE(fdmesg, NULL);
 
-	ret = run_vzct(self->cgv2_path, self->ctid, TEST_LOG);
+	ret = run_vzct(self->cgv2_fd, self->ctid, TEST_LOG);
 	ASSERT_EQ(ret, 0);
 
 	while (fgets(buf, sizeof(buf), fdmesg)) {
@@ -595,7 +495,7 @@ TEST_F(ve_printk, ve0_log)
 	fdmesg = open_dmesg();
 	ASSERT_NE(fdmesg, NULL);
 
-	ret = run_vzct(self->cgv2_path, self->ctid, TEST_LOGV0);
+	ret = run_vzct(self->cgv2_fd, self->ctid, TEST_LOGV0);
 	ASSERT_EQ(ret, 0);
 
 	while (fgets(buf, sizeof(buf), fdmesg)) {
@@ -631,7 +531,7 @@ TEST_F(ve_printk, ve_log_both)
 	fdmesg = open_dmesg();
 	ASSERT_NE(fdmesg, NULL);
 
-	ret = run_vzct(self->cgv2_path, self->ctid, TEST_LOGBOTH);
+	ret = run_vzct(self->cgv2_fd, self->ctid, TEST_LOGBOTH);
 	ASSERT_EQ(ret, 0);
 
 	while (fgets(buf, sizeof(buf), fdmesg)) {
@@ -667,7 +567,7 @@ TEST_F(ve_printk, ve_printk_ratelimited)
 	fdmesg = open_dmesg();
 	ASSERT_NE(fdmesg, NULL);
 
-	ret = run_vzct(self->cgv2_path, self->ctid, TEST_PR_RATELIMIT);
+	ret = run_vzct(self->cgv2_fd, self->ctid, TEST_PR_RATELIMIT);
 	ASSERT_EQ(ret, 0);
 
 	while (fgets(buf, sizeof(buf), fdmesg)) {
@@ -693,7 +593,7 @@ TEST_F(ve_printk, ve_printk_overflow)
 
 	ASSERT_EQ(set_param("/proc/sys/debug/exception-trace", 1, &ex_trace), 0);
 
-	ret = run_vzct(self->cgv2_path, self->ctid, TEST_OVERFLOW);
+	ret = run_vzct(self->cgv2_fd, self->ctid, TEST_OVERFLOW);
 	ASSERT_EQ(ret, 0);
 	restore_param("/proc/sys/debug/exception-trace", ex_trace);
 
diff --git a/tools/testing/selftests/ve_printk/.gitignore b/tools/testing/selftests/ve_printk/.gitignore
deleted file mode 100644
index a4ad6620b803..000000000000
--- a/tools/testing/selftests/ve_printk/.gitignore
+++ /dev/null
@@ -1,3 +0,0 @@
-ve_printk_test
-test_segf
-test_trap
diff --git a/tools/testing/selftests/ve_printk/Makefile b/tools/testing/selftests/ve_printk/Makefile
deleted file mode 100644
index e3edcbacda1e..000000000000
--- a/tools/testing/selftests/ve_printk/Makefile
+++ /dev/null
@@ -1,8 +0,0 @@
-# SPDX-License-Identifier: GPL-2.0
-# Makefile for ve_printk selftests.
-CFLAGS = -g -I../../../../usr/include/ -Wall -O2
-
-TEST_GEN_PROGS += ve_printk_test
-TEST_GEN_FILES += test_segf test_trap
-
-include ../lib.mk
-- 
2.47.3

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

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [Devel] [PATCH hci-8.2 v2 2/3] selftests/ve: move ve_devcg_bpf into ve/ and reuse ve_selftest.h
  2026-11-19  8:16 ` [Devel] [PATCH hci-8.2 v2 2/3] selftests/ve: move ve_devcg_bpf into ve/ and reuse ve_selftest.h Mirian Shilakadze
@ 2026-11-19  8:20   ` no-reply
  2026-11-19 17:00   ` Konstantin Khorenko
  1 sibling, 0 replies; 12+ messages in thread
From: no-reply @ 2026-11-19  8:20 UTC (permalink / raw)
  To: Mirian Shilakadze, khorenko, vladimir.riabchun; +Cc: devel

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] selftests/ve: ve_devcg_bpf fixture fails instead of skipping
  without cgroup2
--

commit e03e60874f39ad9941b752aa021d66a24b8a4706
Author: Mirian Shilakadze <mirian.shilakadze@virtuozzo.com>

selftests/ve: move ve_devcg_bpf into ve/ and reuse ve_selftest.h

This commit moves the ve_devcg_bpf test into tools/testing/selftests/ve/. It drops the test's private helpers (mount_cg2_fd, write_file_at, enter_cgroup, ctid search, VE cgroup creation) in favour of those in ve_selftest.h.

> diff --git a/tools/testing/selftests/ve_devcg_bpf/ve_devcg_bpf_test.c b/tools/testing/selftests/ve/ve_devcg_bpf_test.c
> similarity index 90%
> rename from tools/testing/selftests/ve_devcg_bpf/ve_devcg_bpf_test.c
> rename to tools/testing/selftests/ve/ve_devcg_bpf_test.c

[ ... ]

> @@ -592,11 +529,11 @@ FIXTURE_SETUP(ve_devcg_bpf)
>  	char ctid_str[16];
>  	char path[64];
>
> -	self->cgv2_fd = mount_cg2_fd();
> +	self->cgv2_fd = open_cg2_fd();
>  	ASSERT_GE(self->cgv2_fd, 0);

[Severity: Low]
Should a missing cgroup2 mount be a skip here rather than a failure?

If /sys/fs/cgroup is not a cgroup2 mount (a cgroup v1 or hybrid host, for example), open_cg2_fd() returns -1 with ENODEV. ASSERT_GE() then fails the fixture, and every TEST_F is reported as failed with no reason. The old private mount_cg2_fd() used fsopen/fsconfig/fsmount, so it did not depend on the host mount layout.

Skipping with a reason string when open_cg2_fd() fails would keep a missing prerequisite distinct from a real failure.

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/20261119081654.484107-2-mirian.shilakadze@virtuozzo.com?part=2

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

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [Devel] [PATCH hci-8.2 v2 1/3] selftests/ve: open the host cgroup2 mount instead of creating one
  2026-11-19  8:16 ` [Devel] [PATCH hci-8.2 v2 1/3] selftests/ve: open the host cgroup2 mount instead of creating one Mirian Shilakadze
@ 2026-11-19  8:21   ` no-reply
  2026-11-19 17:00   ` Konstantin Khorenko
  1 sibling, 0 replies; 12+ messages in thread
From: no-reply @ 2026-11-19  8:21 UTC (permalink / raw)
  To: Mirian Shilakadze, khorenko, vladimir.riabchun; +Cc: devel

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Low] selftests/ve: open_cg2_fd() fails instead of skipping without
  cgroup2 at /sys/fs/cgroup
- [Low] selftests/ve: Fixes tag names refactor 2f614e4b0e5c, not the
  commit that added the mount
--

commit 9abf088913d8283815643e8a2c0680ba8c91d1a5
Author: Mirian Shilakadze <mirian.shilakadze@virtuozzo.com>

> selftests/ve: open the host cgroup2 mount instead of creating one
>
> mount_cg2_fd() gave the tests their cgroup2 fd by creating a fresh mount
> with fsopen(), fsconfig() and fsmount(), with no options. That ends in
> cgroup_get_tree(), which calls apply_cgroup_root_flags() with the new
> mount's options once the tree is built. For a caller in the root cgroup
> namespace that function does not only set the flags the new mount asked
> for, it also clears on cgrp_dfl_root the nsdelegate,
> memory_recursiveprot and other root options the new mount did not carry,
> and cgrp_dfl_root is the one hierarchy behind every cgroup2 mount on the
> host. So every fixture setup switched nsdelegate and
> memory_recursiveprot off on the host /sys/fs/cgroup until something
> remounted it. A node the ve tests had run on shows its cgroup2 mount
> without either option, three untouched nodes of the same image still
> show both.
>
> Open the existing mount instead. open_cg2_fd() opens /sys/fs/cgroup as a
> directory fd and checks with fstatfs() that it is cgroup2. The *at()
> calls the tests make work on that fd as they did on the fsmount fd, and
> nothing is mounted, so the host flags stay as systemd set them. The
> tests now need the host cgroup2 mount at /sys/fs/cgroup, which every
> vz10 host has. Every caller switches to it, and the messages that said
> "mount" now say "open". The header also no longer needs the glibc 2.36
> mount API wrappers.
>
> Fixes: 2f614e4b0e5c ("selftests/ve: factor common helpers into ve_selftest.h")
> Feature: fix selftests
> https://virtuozzo.atlassian.net/browse/VSTOR-139515
> Signed-off-by: Mirian Shilakadze <mirian.shilakadze@virtuozzo.com>

[Severity: Low]
Does this Fixes: tag name the commit that introduced the problem? Commit
2f614e4b0e5c ("selftests/ve: factor common helpers into ve_selftest.h")
only moved the helper. Before it, ve_ns_owner_test.c already had a private
mount_cg2_fd() doing fsopen(), FSCONFIG_CMD_CREATE and fsmount() with no
options. That behaviour comes from 26ab97f91b8c ("selftests/ve: regression
test for CLONE_NEWVE owner correctness"). The other tests picked up the
behaviour through their own introducing commits, so no single commit covers
all of them. Could the commit message cite 26ab97f91b8c, or explain why the
refactor commit was chosen?

> diff --git a/tools/testing/selftests/ve/ve_aio_ring_test.c b/tools/testing/selftests/ve/ve_aio_ring_test.c
> index 1922a05aceef..c5b90427bdb3 100644
> --- a/tools/testing/selftests/ve/ve_aio_ring_test.c
> +++ b/tools/testing/selftests/ve/ve_aio_ring_test.c
> @@ -152,7 +152,7 @@ FIXTURE_SETUP(ve_aio_ring)
>  			 MAP_SHARED | MAP_ANONYMOUS, -1, 0);
>  	ASSERT_NE(self->arg, MAP_FAILED);
>  
> -	self->cgv2_fd = mount_cg2_fd();
> +	self->cgv2_fd = open_cg2_fd();
>  	ASSERT_GE(self->cgv2_fd, 0);

[Severity: Low]
Should this skip instead of fail when /sys/fs/cgroup is missing or is not
cgroup2? open_cg2_fd() returns -1 with ENOENT or ENODEV in that case (for
example a cgroup1 or hybrid layout, or a different mount namespace), and
this ASSERT_GE reports a test failure. The old fsopen() path did not depend
on where userspace mounted cgroup2. Kselftest policy treats a missing
prerequisite as a skip with a reason. Only ve_vtty_stress and
ve_numa_migrate turn the failure into a skip. The aio_ring, ns_owner,
perms, mount_accounting, numa_syscalls, tmpfs_mpol and cpuid_override
fixtures all assert.

[ ... ]

> diff --git a/tools/testing/selftests/ve/ve_selftest.h b/tools/testing/selftests/ve/ve_selftest.h
> --- a/tools/testing/selftests/ve/ve_selftest.h
> +++ b/tools/testing/selftests/ve/ve_selftest.h
> @@ -245,23 +246,26 @@ static inline int read_s32_at(int dirfd, const char *path,
> +static inline int open_cg2_fd(void)
> {
> +	struct statfs st;
> +	int fd;
>
> +	fd = open("/sys/fs/cgroup", O_RDONLY | O_DIRECTORY | O_CLOEXEC);
>  	if (fd < 0)
>  		return -1;
> +	if (fstatfs(fd, &st) < 0 || st.f_type != CGROUP2_SUPER_MAGIC) {
> +		close(fd);
> +		errno = ENODEV;
>  		return -1;
>  	}
> +	return fd;
>  }

[Severity: Low]
This is the helper behind the previous comment. Would returning a distinct
error, or having callers map ENOENT and ENODEV to SKIP with a reason such
as "no cgroup2 mount at /sys/fs/cgroup", keep the fixtures from failing
on hosts without that mount?

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/20261119081654.484107-2-mirian.shilakadze@virtuozzo.com?part=1

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

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [Devel] [PATCH hci-8.2 v2 3/3] selftests/ve: move ve_printk into ve/ and reuse ve_selftest.h
  2026-11-19  8:16 ` [Devel] [PATCH hci-8.2 v2 3/3] selftests/ve: move ve_printk " Mirian Shilakadze
@ 2026-11-19  8:22   ` no-reply
  2026-11-19 17:00   ` Konstantin Khorenko
  1 sibling, 0 replies; 12+ messages in thread
From: no-reply @ 2026-11-19  8:22 UTC (permalink / raw)
  To: Mirian Shilakadze, khorenko, vladimir.riabchun; +Cc: devel

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] selftests/ve: x86-only test_trap/test_segf built unconditionally
  in ve Makefile
--

commit 52f33c00132204518cd88777f4c0fb239dd0a002
Author: Mirian Shilakadze <mirian.shilakadze@virtuozzo.com>

selftests/ve: move ve_printk into ve/ and reuse ve_selftest.h

The patch moves the ve_printk test and its two helper programs, test_segf and test_trap, into tools/testing/selftests/ve/. It also switches the test to the openat-based helpers from ve_selftest.h and removes the old ve_printk directory and its Makefile.

> diff --git a/tools/testing/selftests/ve/Makefile b/tools/testing/selftests/ve/Makefile
> --- a/tools/testing/selftests/ve/Makefile
> +++ b/tools/testing/selftests/ve/Makefile
> @@ -11,6 +11,8 @@ TEST_GEN_PROGS += ve_aio_ring_test
>  TEST_GEN_PROGS += ve_numa_syscalls_prohibited_test
>  TEST_GEN_PROGS += ve_tmpfs_mpol_test
>  TEST_GEN_PROGS += ve_devcg_bpf_test
> +TEST_GEN_PROGS += ve_printk_test
> +TEST_GEN_FILES += test_segf test_trap
>  
>  # CPUID faulting is x86-64 only. ARCH says "x86" for 32-bit too and lib.mk
>  # picks the clang target by its emptiness, so decide by the compiler.

[Severity: Low]
Should test_segf and test_trap be built unconditionally here?

test_trap.c uses __asm__("int3"), which does not assemble on non-x86 targets. test_segf.c also casts the 64-bit address 0xffffffffffffff00 to an int pointer. The Makefile already guards ve_cpuid_override_test for x86-64 just below this hunk, but these helpers have no such guard.

Before this patch, such a build failure only affected the separate ve_printk target. Now it breaks the whole ve selftest directory on non-x86 and 32-bit builds. Could the helpers and ve_printk_test go behind the same x86-64 check?

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/20261119081654.484107-2-mirian.shilakadze@virtuozzo.com?part=3

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

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [Devel] [PATCH hci-8.2 v2 0/3] selftests/ve: move ve_devcg_bpf and ve_printk into ve/
  2026-11-19  8:16 [Devel] [PATCH hci-8.2 v2 0/3] selftests/ve: move ve_devcg_bpf and ve_printk into ve/ Mirian Shilakadze
                   ` (2 preceding siblings ...)
  2026-11-19  8:16 ` [Devel] [PATCH hci-8.2 v2 3/3] selftests/ve: move ve_printk " Mirian Shilakadze
@ 2026-11-19 17:00 ` Konstantin Khorenko
  2026-11-19 17:01 ` Konstantin Khorenko
  4 siblings, 0 replies; 12+ messages in thread
From: Konstantin Khorenko @ 2026-11-19 17:00 UTC (permalink / raw)
  To: Mirian Shilakadze; +Cc: devel

Applying the series with this fix on my side:

1. 1/3: Fixes: names 26ab97f91b8c ("selftests/ve: regression test for
   CLONE_NEWVE owner correctness") instead of the refactor 2f614e4b0e5c,
   as Sashiko asked: the optionless cgroup2 mount came from there.

On Thu, 19 Nov 2026 12:16:25 +0400, Mirian Shilakadze wrote:
> The kernel spec builds ve_devcg_bpf and ve_printk as targets of their
> own, and with FORCE_TARGETS a missing directory fails the build. So the
> spec has to drop both in the same release:

vzspecs PR 82 drops both from kernel.spec TARGETS and from the
kselftests-set1 suites in bitbucket-pipelines.yml; the tests then run in
the "ve" suite. I take the series together with it.

-- 
Konstantin Khorenko,
Virtuozzo Linux Kernel Team

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

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [Devel] [PATCH hci-8.2 v2 1/3] selftests/ve: open the host cgroup2 mount instead of creating one
  2026-11-19  8:16 ` [Devel] [PATCH hci-8.2 v2 1/3] selftests/ve: open the host cgroup2 mount instead of creating one Mirian Shilakadze
  2026-11-19  8:21   ` no-reply
@ 2026-11-19 17:00   ` Konstantin Khorenko
  1 sibling, 0 replies; 12+ messages in thread
From: Konstantin Khorenko @ 2026-11-19 17:00 UTC (permalink / raw)
  To: Mirian Shilakadze; +Cc: devel

Applying with this fix on my side:

- Item 1 of the cover letter reply: Fixes: 26ab97f91b8c.

On Thu, 19 Nov 2026 12:16:26 +0400, Mirian Shilakadze wrote:
> Fixes: 2f614e4b0e5c ("selftests/ve: factor common helpers into ve_selftest.h")

2f614e4b0e5c only moved mount_cg2_fd() into the header; the mount that
clears the host flags came with ve_ns_owner_test in 26ab97f91b8c.

-- 
Konstantin Khorenko,
Virtuozzo Linux Kernel Team

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

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [Devel] [PATCH hci-8.2 v2 2/3] selftests/ve: move ve_devcg_bpf into ve/ and reuse ve_selftest.h
  2026-11-19  8:16 ` [Devel] [PATCH hci-8.2 v2 2/3] selftests/ve: move ve_devcg_bpf into ve/ and reuse ve_selftest.h Mirian Shilakadze
  2026-11-19  8:20   ` no-reply
@ 2026-11-19 17:00   ` Konstantin Khorenko
  1 sibling, 0 replies; 12+ messages in thread
From: Konstantin Khorenko @ 2026-11-19 17:00 UTC (permalink / raw)
  To: Mirian Shilakadze; +Cc: devel

Applying as is.

On Thu, 19 Nov 2026 12:16:27 +0400, Mirian Shilakadze wrote:
> ve_devcg_bpf lives in its own selftests directory and carries private

Thanks.

-- 
Konstantin Khorenko,
Virtuozzo Linux Kernel Team

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

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [Devel] [PATCH hci-8.2 v2 3/3] selftests/ve: move ve_printk into ve/ and reuse ve_selftest.h
  2026-11-19  8:16 ` [Devel] [PATCH hci-8.2 v2 3/3] selftests/ve: move ve_printk " Mirian Shilakadze
  2026-11-19  8:22   ` no-reply
@ 2026-11-19 17:00   ` Konstantin Khorenko
  1 sibling, 0 replies; 12+ messages in thread
From: Konstantin Khorenko @ 2026-11-19 17:00 UTC (permalink / raw)
  To: Mirian Shilakadze; +Cc: devel

Applying as is.

On Thu, 19 Nov 2026 12:16:28 +0400, Mirian Shilakadze wrote:
> Move the test and its two helper programs into

On Sashiko's x86 remark: test_trap and ve_printk were built without an
x86 guard before the move as well, and vz10 builds x86_64 only, so
nothing to change now.

-- 
Konstantin Khorenko,
Virtuozzo Linux Kernel Team

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

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [Devel] [PATCH hci-8.2 v2 0/3] selftests/ve: move ve_devcg_bpf and ve_printk into ve/
  2026-11-19  8:16 [Devel] [PATCH hci-8.2 v2 0/3] selftests/ve: move ve_devcg_bpf and ve_printk into ve/ Mirian Shilakadze
                   ` (3 preceding siblings ...)
  2026-11-19 17:00 ` [Devel] [PATCH hci-8.2 v2 0/3] selftests/ve: move ve_devcg_bpf and ve_printk into ve/ Konstantin Khorenko
@ 2026-11-19 17:01 ` Konstantin Khorenko
  4 siblings, 0 replies; 12+ messages in thread
From: Konstantin Khorenko @ 2026-11-19 17:01 UTC (permalink / raw)
  To: vladimir.riabchun, Mirian Shilakadze; +Cc: devel

On Thu, 19 Nov 2026 12:16:25 +0400, Mirian Shilakadze wrote:
> selftests/ve: move ve_devcg_bpf and ve_printk into ve/
> 
> ve_devcg_bpf and ve_printk live in their own selftest directories with
> private copies of the helpers in ve_selftest.h. This series moves both
> into tools/testing/selftests/ve/ and drops the copies. The test cases
> are unchanged.
> - 1/3 makes ve_selftest.h open the host cgroup2 mount instead of
>   creating one. Creating it cleared nsdelegate and memory_recursiveprot
>   on the host /sys/fs/cgroup every time a ve test ran.
> - 2/3 moves ve_devcg_bpf
> - 3/3 moves ve_printk
> 
> [...]

Applied to branch-rh10-6.12.0-211.75.1.26.x.vz10-ovz, will be released in rh10-6.12.0-211.75.1.26.4.vz10, thanks!

[1/3] selftests/ve: open the host cgroup2 mount instead of creating one
      https://bitbucket.org/virtuozzocore/vzkernel.vzs/commits/26182b5f9943
[2/3] selftests/ve: move ve_devcg_bpf into ve/ and reuse ve_selftest.h
      https://bitbucket.org/virtuozzocore/vzkernel.vzs/commits/e8fc2ff432d6
[3/3] selftests/ve: move ve_printk into ve/ and reuse ve_selftest.h
      https://bitbucket.org/virtuozzocore/vzkernel.vzs/commits/0073605a2555

-- 
Konstantin Khorenko,
Virtuozzo Linux Kernel Team


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

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2026-11-19 17:02 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-19  8:16 [Devel] [PATCH hci-8.2 v2 0/3] selftests/ve: move ve_devcg_bpf and ve_printk into ve/ Mirian Shilakadze
2026-11-19  8:16 ` [Devel] [PATCH hci-8.2 v2 1/3] selftests/ve: open the host cgroup2 mount instead of creating one Mirian Shilakadze
2026-11-19  8:21   ` no-reply
2026-11-19 17:00   ` Konstantin Khorenko
2026-11-19  8:16 ` [Devel] [PATCH hci-8.2 v2 2/3] selftests/ve: move ve_devcg_bpf into ve/ and reuse ve_selftest.h Mirian Shilakadze
2026-11-19  8:20   ` no-reply
2026-11-19 17:00   ` Konstantin Khorenko
2026-11-19  8:16 ` [Devel] [PATCH hci-8.2 v2 3/3] selftests/ve: move ve_printk " Mirian Shilakadze
2026-11-19  8:22   ` no-reply
2026-11-19 17:00   ` Konstantin Khorenko
2026-11-19 17:00 ` [Devel] [PATCH hci-8.2 v2 0/3] selftests/ve: move ve_devcg_bpf and ve_printk into ve/ Konstantin Khorenko
2026-11-19 17:01 ` Konstantin Khorenko

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.