OpenVZ / Virtuozzo kernel development (devel@openvz.org)
 help / color / mirror / Atom feed
* [Devel] [PATCH hci-8.2 0/3] selftests/ve: move ve_devcg_bpf and ve_printk into ve/
@ 2026-11-19  7:48 Mirian Shilakadze
  2026-11-19  7:48 ` [Devel] [PATCH hci-8.2 1/3] selftests/ve: open the host cgroup2 mount instead of creating one Mirian Shilakadze
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Mirian Shilakadze @ 2026-11-19  7:48 UTC (permalink / raw)
  To: khorenko, vasileios.almpanis; +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. No test logic
change.
- 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

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, a vzkernel.vzspecs change
that goes separately. The ve target is already built and runs in CI,
the moved tests run with it.

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           |   6 +
 .../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     |   6 +-
 .../{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, 88 insertions(+), 273 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] 7+ messages in thread

* [Devel] [PATCH hci-8.2 1/3] selftests/ve: open the host cgroup2 mount instead of creating one
  2026-11-19  7:48 [Devel] [PATCH hci-8.2 0/3] selftests/ve: move ve_devcg_bpf and ve_printk into ve/ Mirian Shilakadze
@ 2026-11-19  7:48 ` Mirian Shilakadze
  2026-11-19  7:53   ` no-reply
  2026-11-19  7:48 ` [Devel] [PATCH hci-8.2 2/3] selftests/ve: move ve_devcg_bpf into ve/ and reuse ve_selftest.h Mirian Shilakadze
  2026-11-19  7:48 ` [Devel] [PATCH hci-8.2 3/3] selftests/ve: move ve_printk " Mirian Shilakadze
  2 siblings, 1 reply; 7+ messages in thread
From: Mirian Shilakadze @ 2026-11-19  7:48 UTC (permalink / raw)
  To: khorenko, vasileios.almpanis; +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. Every
caller switches to it, and the skip 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     |  6 ++--
 .../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, 33 insertions(+), 29 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..b52e4141ab99 100644
--- a/tools/testing/selftests/ve/ve_cpuid_override_test.c
+++ b/tools/testing/selftests/ve/ve_cpuid_override_test.c
@@ -153,7 +153,7 @@ 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();
+	self->cgv2_fd = open_cg2_fd();
 	ASSERT_GE(self->cgv2_fd, 0) TH_LOG("cgroup2 mount: %s", strerror(errno));
 	ASSERT_EQ(write_file_at(self->cgv2_fd, "cgroup.subtree_control",
 				VE_CONTROLLERS), 0);
@@ -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,7 +179,7 @@ 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",
 		       strerror(errno), self->ctid);
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] 7+ messages in thread

* [Devel] [PATCH hci-8.2 2/3] selftests/ve: move ve_devcg_bpf into ve/ and reuse ve_selftest.h
  2026-11-19  7:48 [Devel] [PATCH hci-8.2 0/3] selftests/ve: move ve_devcg_bpf and ve_printk into ve/ Mirian Shilakadze
  2026-11-19  7:48 ` [Devel] [PATCH hci-8.2 1/3] selftests/ve: open the host cgroup2 mount instead of creating one Mirian Shilakadze
@ 2026-11-19  7:48 ` Mirian Shilakadze
  2026-11-19  7:54   ` no-reply
  2026-11-19  7:48 ` [Devel] [PATCH hci-8.2 3/3] selftests/ve: move ve_printk " Mirian Shilakadze
  2 siblings, 1 reply; 7+ messages in thread
From: Mirian Shilakadze @ 2026-11-19  7:48 UTC (permalink / raw)
  To: khorenko, vasileios.almpanis; +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 moves into the ve
Makefile with the test, as ve_devcg_bpf_test reads orig_prog_len from
the in-tree bpf.h. In kselftest-list.txt the test moves from the
ve_devcg_bpf collection to ve. No test logic change.

The kernel spec builds ve_devcg_bpf as a target of its own and has to
drop it in the same release.

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           |  4 +
 .../{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, 12 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..3f47e34cbb18 100644
--- a/tools/testing/selftests/ve/Makefile
+++ b/tools/testing/selftests/ve/Makefile
@@ -1,6 +1,9 @@
 # SPDX-License-Identifier: GPL-2.0
 # Makefile for ve selftests.
 CFLAGS += -g -Wall -O2 $(KHDR_INCLUDES)
+# 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_ns_owner_test
 TEST_GEN_PROGS += ve_perms_test
@@ -10,6 +13,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] 7+ messages in thread

* [Devel] [PATCH hci-8.2 3/3] selftests/ve: move ve_printk into ve/ and reuse ve_selftest.h
  2026-11-19  7:48 [Devel] [PATCH hci-8.2 0/3] selftests/ve: move ve_devcg_bpf and ve_printk into ve/ Mirian Shilakadze
  2026-11-19  7:48 ` [Devel] [PATCH hci-8.2 1/3] selftests/ve: open the host cgroup2 mount instead of creating one Mirian Shilakadze
  2026-11-19  7:48 ` [Devel] [PATCH hci-8.2 2/3] selftests/ve: move ve_devcg_bpf into ve/ and reuse ve_selftest.h Mirian Shilakadze
@ 2026-11-19  7:48 ` Mirian Shilakadze
  2026-11-19  7:56   ` no-reply
  2 siblings, 1 reply; 7+ messages in thread
From: Mirian Shilakadze @ 2026-11-19  7:48 UTC (permalink / raw)
  To: khorenko, vasileios.almpanis; +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. No test logic change.

The kernel spec builds ve_printk as a target of its own and has to drop
it in the same release. In kselftest-list.txt the test moves from the
ve_printk collection to ve.

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 3f47e34cbb18..da7d818b5df0 100644
--- a/tools/testing/selftests/ve/Makefile
+++ b/tools/testing/selftests/ve/Makefile
@@ -14,6 +14,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] 7+ messages in thread

* Re: [Devel] [PATCH hci-8.2 1/3] selftests/ve: open the host cgroup2 mount instead of creating one
  2026-11-19  7:48 ` [Devel] [PATCH hci-8.2 1/3] selftests/ve: open the host cgroup2 mount instead of creating one Mirian Shilakadze
@ 2026-11-19  7:53   ` no-reply
  0 siblings, 0 replies; 7+ messages in thread
From: no-reply @ 2026-11-19  7:53 UTC (permalink / raw)
  To: Mirian Shilakadze, khorenko, vasileios.almpanis; +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 when
  cgroup2 is not at /sys/fs/cgroup
- [Low] selftests/ve: stale 'cgroup2 mount' log messages in
  ve_cpuid_override_test.c
--

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

selftests/ve: open the host cgroup2 mount instead of creating one

The commit replaces mount_cg2_fd(), which created a fresh cgroup2 mount with fsopen()/fsconfig()/fsmount(), with open_cg2_fd(). The new helper opens /sys/fs/cgroup and checks with fstatfs() that it is cgroup2. This stops each fixture setup from clearing nsdelegate and memory_recursiveprot on the host hierarchy. All callers are switched over.

> diff --git a/tools/testing/selftests/ve/ve_cpuid_override_test.c b/tools/testing/selftests/ve/ve_cpuid_override_test.c
> index b9f5e49d6c43..b52e4141ab99 100644
> --- a/tools/testing/selftests/ve/ve_cpuid_override_test.c
> +++ b/tools/testing/selftests/ve/ve_cpuid_override_test.c
> @@ -153,7 +153,7 @@ 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();
> +	self->cgv2_fd = open_cg2_fd();
>  	ASSERT_GE(self->cgv2_fd, 0) TH_LOG("cgroup2 mount: %s", strerror(errno));

[Severity: Low]
This isn't a bug, but this message still says "cgroup2 mount" although
open_cg2_fd() no longer mounts anything. The commit message says the
messages that said "mount" now say "open". The TH_LOG() in
FIXTURE_TEARDOWN_PARENT(ve_cpuid_override), "cgroup2 mount: %s, VE cgroup
%d left behind", was missed in the same way. Could both be changed to
"cgroup2 open"?

[ ... ]

> 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);

[ ... ]

> 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
> @@ -245,23 +245,26 @@ static inline int read_s32_at(int dirfd, const char *path,
[ ... ]
> +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;

[Severity: Low]
Should a missing cgroup2 at /sys/fs/cgroup be treated as a skip rather
than a failure? On a host with a cgroup v1 or hybrid layout, or where the
path is absent, open_cg2_fd() returns -1 with errno set to ENODEV. Most
callers, such as the FIXTURE_SETUP(ve_perms) above, only do
ASSERT_GE(self->cgv2_fd, 0), so they report a hard failure. Only
ve_numa_migrate and ve_vtty_stress turn the error into a skip. The old
mount_cg2_fd() worked on those hosts, and the commit message does not
mention the new assumption about the host layout. Could the callers skip
with a reason in this case?

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

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

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

* Re: [Devel] [PATCH hci-8.2 2/3] selftests/ve: move ve_devcg_bpf into ve/ and reuse ve_selftest.h
  2026-11-19  7:48 ` [Devel] [PATCH hci-8.2 2/3] selftests/ve: move ve_devcg_bpf into ve/ and reuse ve_selftest.h Mirian Shilakadze
@ 2026-11-19  7:54   ` no-reply
  0 siblings, 0 replies; 7+ messages in thread
From: no-reply @ 2026-11-19  7:54 UTC (permalink / raw)
  To: Mirian Shilakadze, khorenko, vasileios.almpanis; +Cc: devel

Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [Low] selftests/ve: commit message says 'No test logic change' but
  fixture behavior changed
- [Low] selftests/ve: TOOLS_INCLUDES now applies to every ve test, not
  just one
- [Low] selftests/ve: Makefile comment claims in-tree headers are
  preferred but KHDR comes first
- [Low] selftests/ve: commit message cites a kselftest-list.txt change
  not present in the patch
--

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

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

This moves the ve_devcg_bpf test into tools/testing/selftests/ve/. It drops the test's private copies of helpers that ve_selftest.h already provides, and moves the TOOLS_INCLUDES flag into the ve Makefile.

> In kselftest-list.txt the test moves from the ve_devcg_bpf collection to
> ve. No test logic change.

[Severity: Low]
Is the kselftest-list.txt sentence accurate? The diff touches no such file, and none is tracked in the tree. selftests/Makefile generates it at install time from TARGETS and the per-target test lists. The move follows from the TARGETS removal and the ve Makefile addition, but the wording reads as if a file was edited.

[Severity: Low]
Is "No test logic change" accurate? The fixture's behavior differs in a few ways:

- FIXTURE_SETUP now uses open_cg2_fd(), which opens the host's existing cgroup2 mount at /sys/fs/cgroup and checks its magic. The old mount_cg2_fd() made a private mount through fsopen()/fsmount(). A host with no cgroup2 mount there now fails the ASSERT_GE in the fixture, where it used to pass.
- FIXTURE_TEARDOWN now calls destroy_ve(), which retries on EBUSY for about a second and prints diagnostics. The old code made a single unlinkat().
- make_ve() removes the new cgroup if the controllers_hidden write fails. The old code did not.

These look reasonable, but the changelog could describe them instead of claiming no change.

> diff --git a/tools/testing/selftests/ve/Makefile b/tools/testing/selftests/ve/Makefile
> index fa4f858227e5e..3f47e34cbb18f 100644
> --- a/tools/testing/selftests/ve/Makefile
> +++ b/tools/testing/selftests/ve/Makefile
> @@ -1,6 +1,9 @@
>  # SPDX-License-Identifier: GPL-2.0
>  # Makefile for ve selftests.
>  CFLAGS += -g -Wall -O2 $(KHDR_INCLUDES)
> +# 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)

[Severity: Low]
Does this comment match the include order? KHDR_INCLUDES comes first in CFLAGS, and -isystem directories are searched in the order given. A header present in both trees is therefore taken from the installed headers, and the tools/include/uapi copy is only a fallback. The old ve_devcg_bpf Makefile used TOOLS_INCLUDES alone, so this ordering is a silent change. Should the comment be reworded, or the two flags swapped?

[Severity: Low]
Should TOOLS_INCLUDES be applied to every ve test? Only ve_devcg_bpf_test needs it, but the flag now goes into the shared CFLAGS. ve_perms_test, ve_tmpfs_mpol_test and the others are now built with the tools uapi directory on their include path too. A per-target CFLAGS assignment for ve_devcg_bpf_test would keep the change scoped to the test that needs it.

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

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

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

* Re: [Devel] [PATCH hci-8.2 3/3] selftests/ve: move ve_printk into ve/ and reuse ve_selftest.h
  2026-11-19  7:48 ` [Devel] [PATCH hci-8.2 3/3] selftests/ve: move ve_printk " Mirian Shilakadze
@ 2026-11-19  7:56   ` no-reply
  0 siblings, 0 replies; 7+ messages in thread
From: no-reply @ 2026-11-19  7:56 UTC (permalink / raw)
  To: Mirian Shilakadze, khorenko, vasileios.almpanis; +Cc: devel

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Low] selftests/ve: commit message cites spec and list changes not in
  the patch
- [Low] selftests/ve: cgroup2 lookup now fixed to /sys/fs/cgroup despite
  'no logic change'
--

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

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

This moves the ve_printk selftest and its two helper programs into tools/testing/selftests/ve/. The test now uses the openat-based helpers from ve_selftest.h instead of its own /proc/mounts lookup, system("echo ...") calls, ctid search and enter_cgroup.

> The kernel spec builds ve_printk as a target of its own and has to drop
> it in the same release. In kselftest-list.txt the test moves from the
> ve_printk collection to ve.

[Severity: Low]
Is this sentence accurate for this tree? The TARGETS list in redhat/kernel.spec.template names neither ve nor ve_printk. The patch touches no spec file and no kselftest-list.txt. If these changes live out of tree, could the message say where? Otherwise the sentence could be corrected.

> 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

[ ... ]

>  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);

[Severity: Low]
Is this really "No test logic change"? The removed get_mount_path("cgroup2", ...) accepted a cgroup2 mount anywhere in /proc/mounts. open_cg2_fd() opens only /sys/fs/cgroup and fails with ENODEV unless it is a cgroup2 mount. On a host with cgroup2 mounted elsewhere, the fixture now fails at ASSERT_GE() where it used to run, and there is no skip reason. The shared helper makes this consistent with the other ve tests, but the commit message should mention the change.

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

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

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

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

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-19  7:48 [Devel] [PATCH hci-8.2 0/3] selftests/ve: move ve_devcg_bpf and ve_printk into ve/ Mirian Shilakadze
2026-11-19  7:48 ` [Devel] [PATCH hci-8.2 1/3] selftests/ve: open the host cgroup2 mount instead of creating one Mirian Shilakadze
2026-11-19  7:53   ` no-reply
2026-11-19  7:48 ` [Devel] [PATCH hci-8.2 2/3] selftests/ve: move ve_devcg_bpf into ve/ and reuse ve_selftest.h Mirian Shilakadze
2026-11-19  7:54   ` no-reply
2026-11-19  7:48 ` [Devel] [PATCH hci-8.2 3/3] selftests/ve: move ve_printk " Mirian Shilakadze
2026-11-19  7:56   ` no-reply

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox