From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.openvz.org (mail.openvz.org [69.168.225.77]) by lore.virtuozzo.com (Postfix) with ESMTPS id 137988017D for ; Tue, 27 Oct 2026 20:53:17 +0000 (UTC) Received: from mail.openvz.org (localhost [127.0.0.1]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 69RKq4Zv001377; Tue, 27 Oct 2026 23:52:05 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 69RKq4Zv001377 Authentication-Results: mail.openvz.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="hEEgPbf6" Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 69RKpuLI001269 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=FAIL) for ; Tue, 27 Oct 2026 23:51:56 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 69RKpuLI001269 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-48b01a74792so158449f8f.0 for ; Tue, 27 Oct 2026 13:51:56 -0700 (PDT) X-Forwarded-Encrypted: i=2; AKwUvBza5xAX01QJQdoSQWU1oVkMAgVNlMNH7Avy3sow7COf5QpytZsRqQlvkgEzPhHgfyvicMAVXQ==@openvz.org X-Gm-Message-State: AFq9FYKdEpyukHSc5O3myS+HcnbED1H+K01V3HcziUtX4qX2sTdcV9h+ c1p8bJ9PxfItHQAXLp32E0EDcRnU20JnmmvH6/rbUZnUhfRKUsUo1Rw/hR7xXxA4b/ACqUcw0MA CwaMA4U8Ac32gGzO2uXQGk3j9EczOTdiIUTvyP5RIjGHSwmcoNT6gdg== X-Gm-Gg: AYBFou03u5rmf3xLz6v3hLRa0fjEFFnerGJtbzNKwLc8oOLgT2/0cDzyg1Xa6RXGPHT bNu6RHDBbKoty2glsdHWD5VfQSUTctQ2VlHsKhrDLSEWz4DYkcWHUN8I+vKTnoH2C1PLodTbzRI ssvHKgqny+Etid4u3ECjSacIdOxvo5ftzNKmwh5X5sY4DbeGz4Wac++wSEZ5xEwecc6qyZXsMco 5Sep7RBzcWXoSKc+gESJ+nEQ1f4O4ol2/qK1Bt/dw0xTSAQXYQWlf/O5mOugR13wd4QSqi0T0yU /KUwzHusdeFWjpR1DfDPUVfmS/tYS10FASSLlBJh7QScAgPoBAJf/9SxNR88d1v1ik9GTgf60DE emwGrx9a4WX2NHHurTKqQru5AuuYO X-Received: by 2002:a05:6000:2502:b0:488:7496:15b5 with SMTP id ffacd0b85a97d-48e5d5ada48mr1229238f8f.47.1793134316266; Tue, 27 Oct 2026 13:51:56 -0700 (PDT) X-Received: by 2002:a05:6000:2502:b0:488:7496:15b5 with SMTP id ffacd0b85a97d-48e5d5ada48mr1229195f8f.47.1793134315726; Tue, 27 Oct 2026 13:51:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1793134315; cv=none; d=google.com; s=arc-20260327; b=RkKMgjyr1HSF2tfehf6r60yooRLkpf+CMbM7jFbcL2My47s8AoStWzm7LChrUwRRWk ULrq2/Hc0H3dmPnAlAWJj8EHUvWC0yOXCOWq8XAo9m7ZJP+FFuyzdla8Ufa3Vxq4Ndac At6H5scO5Rm6iNUSYQ8VlFGXVh5/mwWTUhOHs6JN6ye4qW8Lnsk1KejcJo/i18sEmUtH ElWC3onlul1GJQzoMy4YVNS0WErPlgWM05fsVSs+npTvW1gAqBrcgc8PQxk+Evf5uDt9 YKr9Sgg2tOELP0luG2evrUGHKJyvQVe/mWoYQUa0sI0q6N+A4uIWucig3vDZOs8O0jqH msPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:dkim-signature; bh=6V4xhIyuRMBGjx5CyXfywMz3KQEt1oRXS8MpKwClKqs=; fh=5hQRK+XZF8m8FADH0g5yAiDkSoTAVGTSxnnvVVATGZQ=; b=K0RnRcGZ365pqU3+hgtc+/defHynrlL3wiLXbxzFAzFxux9xc+NoNkMN83x2Rl+itH txjaHul7MRkPvRsuqdZrb6XSKZbA3BD0lST2fOHSpTwWN66TU4gS9IdDCD+DZbrKvYpj 0TzUplB8+yVRWxw7hypJ9eaOZHqvLZyPL/VnizMwViLhAJbO8CyN6HvfPBlKt8m+N7bR 8yRvinEF+L+25/LphXU8UADs3ZF5yN1AHzzbw++YQ+sBfs9YLZDTohW5+b2tcJGRVbqL Kr4aoMjkrYJMYHjopctiNR9Lz3jOaopBo8kPvEPqNkpZK1J2n2IL9TqpInWrAJ1qVlGc GW8A==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=hEEgPbf6; spf=pass (google.com: domain of vladimir.riabchun@virtuozzo.com designates 130.117.225.111 as permitted sender) smtp.mailfrom=vladimir.riabchun@virtuozzo.com; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com Received: from relay.virtuozzo.com (relay.virtuozzo.com. [130.117.225.111]) by mx.google.com with ESMTPS id ffacd0b85a97d-48e3ecdb4ddsi21859302f8f.93.2026.10.27.13.51.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Oct 2026 13:51:55 -0700 (PDT) Received-SPF: pass (google.com: domain of vladimir.riabchun@virtuozzo.com designates 130.117.225.111 as permitted sender) client-ip=130.117.225.111; Authentication-Results: mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=hEEgPbf6; spf=pass (google.com: domain of vladimir.riabchun@virtuozzo.com designates 130.117.225.111 as permitted sender) smtp.mailfrom=vladimir.riabchun@virtuozzo.com; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=virtuozzo.com; s=relay; h=Message-Id:Content-Type:MIME-Version:Subject:Date :From; bh=6V4xhIyuRMBGjx5CyXfywMz3KQEt1oRXS8MpKwClKqs=; b=hEEgPbf6UrDevQ6LOsO VvgrTleNNMFw05k4az3NMT/+HwJNXeHPMobCTca2jLu4fw7YPoig0tnI0Ee266uu3gOJUjWsrDhEW 7dD1mQAxXYOhf0KQ8+LAGgJptdRBaRMNaAFB+fLRFc/TpSB8zOi15LemwLol5Z9zUxv3tQGvYCmyz vWaf9pbsQQjp6hFyJPrx/I5FHOVVd13nlvHWBuYMwvl+0eKw0yimpCgWG6YNmWdEpuAIP9hmImaSx d1HArX5aAIf0+lyQCDdq4AY8x2iw4NgElObgkjBI5DuNLwtOF7eOWM89PVDIFMzB3MHww9nWqeB2/ R9h/snDB5uRzQMA==; Received: from ch-demo-asa.virtuozzo.com ([130.117.225.8] helo=192.168.1.87) by relay.virtuozzo.com with esmtps (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1xLo5S-004tG8-10; Tue, 27 Oct 2026 21:51:45 +0100 From: Vladimir Riabchun Date: Tue, 27 Oct 2026 21:51:11 +0100 MIME-Version: 1.0 Message-Id: <20261027-ct-invalid-nrpoc-v1-2-48727c3afe16@virtuozzo.com> References: <20261027-ct-invalid-nrpoc-v1-0-48727c3afe16@virtuozzo.com> In-Reply-To: <20261027-ct-invalid-nrpoc-v1-0-48727c3afe16@virtuozzo.com> To: ptikhomirov@virtuozzo.com, Konstantin Khorenko X-Mailer: b4 0.16.0 X-OZ-Fwd: true Cc: devel@openvz.org Subject: [Devel] [PATCH hci-8.1 2/2] selftests: ve: Test sched_getaffinity in VE X-BeenThere: devel@openvz.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: OpenVZ development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: devel-bounces@openvz.org Errors-To: devel-bounces@openvz.org Add a new selftest that verifies that sched_getaffinity respects both cgroup cpuset and nr_cpus limits. https://virtuozzo.atlassian.net/browse/VSTOR-141682 Signed-off-by: Vladimir Riabchun --- tools/testing/selftests/ve/.gitignore | 1 + tools/testing/selftests/ve/Makefile | 1 + .../selftests/ve/ve_sched_getaffinity_test.c | 147 +++++++++++++++++++++ 3 files changed, 149 insertions(+) diff --git a/tools/testing/selftests/ve/.gitignore b/tools/testing/selftests/ve/.gitignore index 8ab1bfe6f5e4..178de0ee1822 100644 --- a/tools/testing/selftests/ve/.gitignore +++ b/tools/testing/selftests/ve/.gitignore @@ -3,3 +3,4 @@ ve_perms_test ve_mount_accounting_test ve_cpuid_override_test ve_vtty_stress +ve_sched_getaffinity_test diff --git a/tools/testing/selftests/ve/Makefile b/tools/testing/selftests/ve/Makefile index 51f9316beb99..d53e724205f7 100644 --- a/tools/testing/selftests/ve/Makefile +++ b/tools/testing/selftests/ve/Makefile @@ -6,6 +6,7 @@ TEST_GEN_PROGS += ve_ns_owner_test TEST_GEN_PROGS += ve_perms_test TEST_GEN_PROGS += ve_mount_accounting_test TEST_GEN_PROGS += ve_vtty_stress +TEST_GEN_PROGS += ve_sched_getaffinity_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/ve_sched_getaffinity_test.c b/tools/testing/selftests/ve/ve_sched_getaffinity_test.c new file mode 100644 index 000000000000..a47cee832c3b --- /dev/null +++ b/tools/testing/selftests/ve/ve_sched_getaffinity_test.c @@ -0,0 +1,147 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * ve_mount_accounting selftests + * + * Tests to check cpuset virtualization. + */ +#define _GNU_SOURCE +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "../kselftest_harness.h" +#include "ve_selftest.h" + +FIXTURE(ve_getaff_test) +{ + int cgv2_fd; + int ctid; + struct namespace_ctx ns_ctx; +}; + +static int __getaffinity_ve(void *cpuset) +{ + cpu_set_t *dst = cpuset; + + return sched_getaffinity(getpid(), sizeof(*dst), dst); +} + +static int getaffinity_ve(FIXTURE_DATA(ve_getaff_test) * self, cpu_set_t *dst) +{ + int ret = -1; + cpu_set_t *tmp = mmap(NULL, sizeof(cpu_set_t), + PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0); + + if (tmp == MAP_FAILED) { + fprintf(stderr, "Failed to mmap shared region: %s\n", strerror(errno)); + return -1; + } + CPU_ZERO(tmp); + CPU_ZERO(dst); + + ret = run_in_ve(self->cgv2_fd, self->ctid, &self->ns_ctx, + CLONE_NEWVE, __getaffinity_ve, tmp); + + if (!ret) + memcpy(dst, tmp, sizeof(cpu_set_t)); + + munmap(tmp, sizeof(cpu_set_t)); + return ret; +} + +FIXTURE_SETUP(ve_getaff_test) +{ + cpu_set_t this, in_ve; + + self->cgv2_fd = mount_cg2_fd(); + ASSERT_GE(self->cgv2_fd, 0); + + ASSERT_EQ(write_file_at(self->cgv2_fd, "cgroup.subtree_control", + VE_CONTROLLERS), 0); + + self->ctid = make_ve(self->cgv2_fd, CTID_MIN); + ASSERT_GE(self->ctid, 0); + + ASSERT_EQ(prepare_namespaces(&self->ns_ctx, CLONE_NEWVE, + self->cgv2_fd, self->ctid), 0); + + + ASSERT_EQ(sched_getaffinity(getpid(), sizeof(this), &this), 0); + if (CPU_COUNT(&this) < 2) + SKIP(return, "Not enough CPUs available"); + + /* Chech that we are talking about the same CPUs */ + ASSERT_EQ(getaffinity_ve(self, &in_ve), 0); + ASSERT_TRUE(CPU_EQUAL(&this, &in_ve)); +}; + +FIXTURE_TEARDOWN(ve_getaff_test) +{ + close_namespace_fds(&self->ns_ctx); + destroy_ve(self->cgv2_fd, self->ctid); + close(self->cgv2_fd); +} + +/* Test correct processing of cpuset.cpus updates */ +TEST_F(ve_getaff_test, update_cg_cpuset) +{ + char path[PATH_MAX]; + int cpu_victim = 0; + cpu_set_t in_ve; + + snprintf(path, sizeof(path), "%d/cpuset.cpus", self->ctid); + if (faccessat(self->cgv2_fd, path, F_OK, 0)) + SKIP(return, "CT cgroup doesn't have cpuset.cpus entry"); + + ASSERT_EQ(getaffinity_ve(self, &in_ve), 0); + + /* Find one CPU and leave it alone via cgroup interface */ + while (!CPU_ISSET(cpu_victim, &in_ve)) + cpu_victim++; + + ASSERT_EQ(write_u64_at(self->cgv2_fd, path, cpu_victim), 0); + + /* Verify sched_getaffinity sees updated value */ + ASSERT_EQ(getaffinity_ve(self, &in_ve), 0); + ASSERT_EQ(CPU_COUNT(&in_ve), 1); + ASSERT_TRUE(CPU_ISSET(cpu_victim, &in_ve)); +} + +/* Test correct processing of cpu.nr_cpus updates */ +TEST_F(ve_getaff_test, nr_proc_bound) +{ + char path[PATH_MAX]; + int cpu_victim = 0; + cpu_set_t in_ve; + + snprintf(path, sizeof(path), "%d/cpu.nr_cpus", self->ctid); + if (faccessat(self->cgv2_fd, path, F_OK, 0)) + SKIP(return, "CT cgroup doesn't have cpu.nr_cpus entry"); + + ASSERT_EQ(getaffinity_ve(self, &in_ve), 0); + + /* Find one CPU and bound nr_cpus by its value */ + while (!CPU_ISSET(cpu_victim, &in_ve)) + cpu_victim++; + + ASSERT_EQ(write_u64_at(self->cgv2_fd, path, cpu_victim + 1), 0); + + /* Verify sched_getaffinity sees only one CPU */ + ASSERT_EQ(getaffinity_ve(self, &in_ve), 0); + ASSERT_EQ(CPU_COUNT(&in_ve), 1); + ASSERT_TRUE(CPU_ISSET(cpu_victim, &in_ve)); +} + +TEST_HARNESS_MAIN -- 2.52.0 _______________________________________________ Devel mailing list Devel@openvz.org https://lists.openvz.org/mailman/listinfo/devel