OpenVZ / Virtuozzo kernel development (devel@openvz.org)
 help / color / mirror / Atom feed
From: Mirian Shilakadze <mirian.shilakadze@virtuozzo.com>
To: khorenko@virtuozzo.com, vasileios.almpanis@virtuozzo.com
Cc: devel@openvz.org
Subject: [Devel] [PATCH hci-8.2 2/3] selftests/ve: move ve_devcg_bpf into ve/ and reuse ve_selftest.h
Date: Thu, 19 Nov 2026 11:48:04 +0400	[thread overview]
Message-ID: <20261119074808.478064-3-mirian.shilakadze@virtuozzo.com> (raw)
In-Reply-To: <20261119074808.478064-1-mirian.shilakadze@virtuozzo.com>

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

  parent reply	other threads:[~2026-11-19  7:49 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 ` Mirian Shilakadze [this message]
2026-11-19  7:54   ` [Devel] [PATCH hci-8.2 2/3] selftests/ve: move ve_devcg_bpf into ve/ and reuse ve_selftest.h 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261119074808.478064-3-mirian.shilakadze@virtuozzo.com \
    --to=mirian.shilakadze@virtuozzo.com \
    --cc=devel@openvz.org \
    --cc=khorenko@virtuozzo.com \
    --cc=vasileios.almpanis@virtuozzo.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox