From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.openvz.org (unknown [69.168.225.77]) by lore.virtuozzo.com (Postfix) with ESMTPS id E0CD28017D for ; Tue, 6 Oct 2026 22:55:54 +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 696MseSi028681; Wed, 7 Oct 2026 01:54:40 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 696MseSi028681 Authentication-Results: mail.openvz.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="eCDRU/+T" Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 696Mscef028657 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=FAIL) for ; Wed, 7 Oct 2026 01:54:38 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 696Mscef028657 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-495689bfcc8so27123175e9.1 for ; Tue, 06 Oct 2026 15:54:38 -0700 (PDT) X-Forwarded-Encrypted: i=2; AKwUvBxR1GDTFopZ5D8wsr48pjbwxIFuJzmS9p8AAykhEGBKd+mQIc3kf9FaBFSIr9zVB/0aMaunww==@openvz.org X-Gm-Message-State: AFuF++kjPpvsrcgUbkENcBOENCTsNCrpryN6VLBPaTVoUQp1pnAu88Ku OdoAWFPqzaTgETzCx8bckSIH5lwjFfs1ZpIjnqTjSwHJyxJ7HH0l6PADUn+tGT/PqBut+Mh+P2Q 3SyaNTYua/sm0k50zwXqE1r13winIi0BOeGqkQ+smfxN/y1wfJCvurw== X-Gm-Gg: AYBFou3LR6Y1kXbiiXbbGJFJ3ePFxeNU5YSuiYws60V1rXZlGS8UVJ7ZALTe/wO1Bm0 py30JWeIhL/kUinnHp0l0yu1zTCHo51BTFe2xWHA23gO9LaP715qSmPtAOViAIS6bW6Q4Pj+fYJ A4Lgz0Sjn8hJddUQ0WlC2UY6haO7Bb6p8aoja3yn3ZhTJ0MjWzx8HNOhByb9hepfr24x5u9Y823 YVkoqCf6j5KLqQSGu4AT4a2lU6dcpPt7GELwLfcW2wPpGzHN05Mwdw97xpIBZTmm5aBPmwE+XXW qG9+ZfAWZx84Ew5sCtCGDiaz3TPLh0rqEq0PvXucLI1A17qrw8ePZ0o+EGDk1c14juM1LjtGwmj pCf9FcFupaKRs/FcZ X-Received: by 2002:a05:600c:3b0a:b0:4a0:276e:9efb with SMTP id 5b1f17b1804b1-4a1800ca1dcmr3727835e9.4.1791327278013; Tue, 06 Oct 2026 15:54:38 -0700 (PDT) X-Received: by 2002:a05:600c:3b0a:b0:4a0:276e:9efb with SMTP id 5b1f17b1804b1-4a1800ca1dcmr3727615e9.4.1791327277529; Tue, 06 Oct 2026 15:54:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1791327277; cv=none; d=google.com; s=arc-20260327; b=r3oSBLQBBW7gMBDjCjssaqyl8GzDY0GQ4l4PhcTzxKf84X1G7wyyJoalW1Z9HbIX1C qfDbVho0BVoWgdfCb3LdVQOuUkcyiG8KT4H59ypLPLW+UIyvBIYk9ESzJueWpc2nQlSU skIe9TqQRbWuolrEU611dbLdkuR8GKPTACy4YCwH3cRiVw5kicjN9fFLihClY/aVYm3z eYpzHQ5zZ7XnvldYF/iA3mxiip9BbSx8OzG1A9+D6xNGdwd1r/2knSL2GVYT809SSCe8 4kb7xMcnv985voFSAxRpmOdgwyg8pEp5F9bm0VqFan2fc1E80RbazYvEUZr9gZ5GHnck MNuw== 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=rb+5JtIeSreSKwEcKjEsHfo0wYbWuDnXiPLEMZ7bQxY=; fh=bRkZfFa6377EgOVW8zBDri2gGIQqe/ZeiH+ijEM/ROI=; b=X25B84bbCAlMBXUhg51sPvbU+G4+E40HqIWu8qwjiFSpy9RTfXuPtpKxJuiGiDqyrZ gTb1kleEkL4mvfhVjlcqlfSoCJ0xgPjN3XbE8/xz9O5jzlH7LhE2u1YvQ2QIhlMQ7jLE aocnlsNt4KdVdXbRHFEjyoP9+/3rRQuUKVuqIy8Y9tpcbvIQJDQQ8WVNFITHoMWg/rIw RviNBrlMAMQuq/umGeNxkeVkWENxnL00o3inhQRzKnFvBXkEfEwfclIdogDqSGPfR53F yrUfyUntCxUldZRK7tmSV+tpOFh8VPP2uxoeAhQapG/dX7r+eCKjWp1dtRZZsKF58Z0s tmqA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b="eCDRU/+T"; spf=pass (google.com: domain of khorenko@virtuozzo.com designates 130.117.225.111 as permitted sender) smtp.mailfrom=khorenko@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-48c724a7568si1594463f8f.350.2026.10.06.15.54.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Oct 2026 15:54:37 -0700 (PDT) Received-SPF: pass (google.com: domain of khorenko@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="eCDRU/+T"; spf=pass (google.com: domain of khorenko@virtuozzo.com designates 130.117.225.111 as permitted sender) smtp.mailfrom=khorenko@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=rb+5JtIeSreSKwEcKjEsHfo0wYbWuDnXiPLEMZ7bQxY=; b=eCDRU/+TiI1q2ZQEYs+ +KqjLNG986avUibYxWAvnksiJ1RhS8gmKHbitzi9yC8sx8hlwgW3+mCGgUTekz0jLV/jdADAtRfdP w3XvgSmCKlHuXi3WE927qS4UrmEGfWJY9akvnPDpjMav/Ps6eZL8cX3uyxKketi7C0OazdLFRmvl0 TOh/piTnj8DCUVgaKiOVy+msLWaLvojiE8iAtn/VzG8WQ5ibCG1FlzdHeAi2n85yX50EB5xnyq9ua 3wKZ7bO+SVWWBRvMPBLBlCOg2XbK25JB8tM1yTAwFGDamByJ/y9F9h2JtIcSJN+iYCrKh8/3ZqMvh f6ZejJ0m1viBhyA==; Received: from ch-demo-asa.virtuozzo.com ([130.117.225.8] helo=f0.sw.ru) by relay.virtuozzo.com with esmtp (Exim 4.96) (envelope-from ) id 1xEE0B-005OA8-2j; Wed, 07 Oct 2026 00:54:26 +0200 From: Konstantin Khorenko Date: Wed, 07 Oct 2026 00:54:31 +0200 MIME-Version: 1.0 Message-Id: <20261007-b4-prep-khorenko-vstor-148656-cpuid-v5-1-652c5c9e56da@virtuozzo.com> References: <20261007-b4-prep-khorenko-vstor-148656-cpuid-v5-0-652c5c9e56da@virtuozzo.com> In-Reply-To: <20261007-b4-prep-khorenko-vstor-148656-cpuid-v5-0-652c5c9e56da@virtuozzo.com> To: Pavel Tikhomirov , Vasileios Almpanis X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=12396; i=khorenko@virtuozzo.com; h=from:subject:message-id; bh=QjeHykS7xJ66WCAzpU7rBorSUTOr2zNGxspijiqU1qU=; b=owEBbQKS/ZANAwAKAVGWCkf5YVwqAcsmYgBqxXwqw54iTHQDvLvlAdM1KHn46z6y5/fclts5Y SCdkOQt2B2JAjMEAAEKAB0WIQRWD23IPcXT0GO9CCxRlgpH+WFcKgUCasV8KgAKCRBRlgpH+WFc Kt3hD/oCyf8HaahZYct6R5JipGl0I6Ss3ke92VAJKkoScR7AFV0QCMKLOjUsBd/r8PqWiAFZcwy frow7uRn6Tj3ZXyqtCr0d9ucPavBf9RGYTwJHD8d0exCa+HgvH2CU2QGi/Q/t+2h9Bza8LsFjNY q6n8NuLafosUFyQgOyibXur7dXg4PTkP14yg/I3NEicv8+eIo4JrTvw7Wktp3nWrqZypSyRKMgp PNlfGoF6OSDHJ6eP+NO5WrFQo/bXtQyGllJJ6I/ZFSzY0TKrgj7ZODlrKs7l5wIDThu+iAm7P6x UyD/YZ+Lsv+ssgZDNvIWFK5HSqOpJ91TFWgmBehrj7aSCd6jXjN0BYBDctpQnA9kosuTcb3YET0 3d5eezbzTpT8oQ/UYH53Eoxv4pU+WE3eZecfNNClOzlJAwwK16B7ZtxKCTtveFbhcXXIx5fH925 o3OxoXt+jlotLRbjRt2LXO4o2uuX77cQWhj8Y1qPf68FwsW/eCpV/Mi6KqMp3MfAkXw27PIwwte gm5pFKIbqn4UvXkkHmiRY6v1VVi/5LusxGpmiuHEERRbkVjuEFxBuIAjqyc/eb01tgrWgeRWiBd aW7t5wKm1yZjMJhHyPFX9SNpZEsGXZ8Tth2p2kkQbcGVm9sxAmF29ZD30Xs9K9FYVMeFfZ2J79G EqpZ1xigz5n7oeg== X-Developer-Key: i=khorenko@virtuozzo.com; a=openpgp; fpr=560F6DC83DC5D3D063BD082C51960A47F9615C2A X-OZ-Fwd: true Cc: devel@openvz.org Subject: [Devel] [PATCH hci-8.1 v5 1/5] selftests/ve: check CPUID override emulation for VE tasks 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 Write a one-entry /proc/vz/cpuid_override table that clears one leaf 1 feature bit and compare what a task in a fresh VE and the host see: the VE task must get the table values, the host must keep the hardware bit. A second test flushes the table after the task was armed and expects the hardware bit back, since faulting stays on for the task and the emulation has to fall back to the real CPUID. On its own that test would also pass on a kernel that never arms faulting; the first one proves the arming. Faulting is switched on for a task at its next context switch, not when the flag is set, so the child stops itself with SIGSTOP after entering the VE and the parent resumes it before the CPUID. The stop is reported to the parent before the child leaves the CPU, and a SIGCONT in that window would let it run on without a switch, so the child hands over its voluntary context switch count first and the parent waits for it to grow before the SIGCONT. For the second test the table is flushed while the child stands still. Without commit 07338fbae5a3 ("x86/traps: emulate CPUID faults for user tasks in exc_general_protection()") both children die with SIGSEGV. The tests skip on CPUs without CPUID faulting and restore the previous table on exit; a table the kernel cannot take back in one write fails the setup instead. The harness may skip FIXTURE_TEARDOWN once an ASSERT has fired, so the cleanup is a FIXTURE_TEARDOWN_PARENT, which runs exactly once whether or not one did; it also kills a child that such an ASSERT left stopped in the VE cgroup. The test is built on x86 only. https://virtuozzo.atlassian.net/browse/VSTOR-148843 Feature: x86: cpu pools (cpuid override) Signed-off-by: Konstantin Khorenko --- tools/testing/selftests/ve/.gitignore | 1 + tools/testing/selftests/ve/Makefile | 10 + .../testing/selftests/ve/ve_cpuid_override_test.c | 296 +++++++++++++++++++++ 3 files changed, 307 insertions(+) diff --git a/tools/testing/selftests/ve/.gitignore b/tools/testing/selftests/ve/.gitignore index 3df4d05888dce..bdc322c645d95 100644 --- a/tools/testing/selftests/ve/.gitignore +++ b/tools/testing/selftests/ve/.gitignore @@ -1,3 +1,4 @@ ve_ns_owner_test ve_perms_test ve_mount_accounting_test +ve_cpuid_override_test diff --git a/tools/testing/selftests/ve/Makefile b/tools/testing/selftests/ve/Makefile index c6efe7c4b4fba..d919c1c289c8b 100644 --- a/tools/testing/selftests/ve/Makefile +++ b/tools/testing/selftests/ve/Makefile @@ -6,4 +6,14 @@ TEST_GEN_PROGS += ve_ns_owner_test TEST_GEN_PROGS += ve_perms_test TEST_GEN_PROGS += ve_mount_accounting_test +# ARCH stays untouched: lib.mk picks the clang target by its emptiness. +ifeq ($(ARCH),) +ve_arch := $(shell uname -m 2>/dev/null || echo not) +else +ve_arch := $(ARCH) +endif +ifeq ($(ve_arch),$(filter $(ve_arch),x86 x86_64)) +TEST_GEN_PROGS += ve_cpuid_override_test +endif + include ../lib.mk diff --git a/tools/testing/selftests/ve/ve_cpuid_override_test.c b/tools/testing/selftests/ve/ve_cpuid_override_test.c new file mode 100644 index 0000000000000..398f1fef5d246 --- /dev/null +++ b/tools/testing/selftests/ve/ve_cpuid_override_test.c @@ -0,0 +1,296 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * /proc/vz/cpuid_override selftests + * + * A non-empty override table turns CPUID faulting on for every task that + * enters a VE, and the #GP handler has to emulate the instruction for + * them. The tests check that a task in a VE sees the table values, that + * the host keeps seeing the hardware values, and that a task which was + * armed while the table was set falls back to the hardware once the + * table is flushed. A kernel that does not emulate the fault kills the + * child with SIGSEGV instead. + * + * The table is global: run this on a node without live Containers and one + * instance at a time, a task entering a VE while a case runs is armed for + * life. A harness timeout kills the test without its teardown and leaves + * the test table in place and the VE cgroup behind. + */ +#define _GNU_SOURCE +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "../kselftest_harness.h" +#include "ve_selftest.h" + +#define CPUID_OVERRIDE_PATH "/proc/vz/cpuid_override" +#define CPUID_LEAF 1 +#define CPUID_LINE_LEN 128 +/* The kernel takes a table back only in one write below a page. */ +#define CPUID_WRITE_MAX 4096 +#define CPUID_SAVED_MAX (CPUID_WRITE_MAX + 1) +#define SWITCH_WAIT_ROUNDS 100000 + +struct cpuid_regs { + unsigned int eax, ebx, ecx, edx; +}; + +static void do_cpuid(unsigned int leaf, struct cpuid_regs *r) +{ + __cpuid_count(leaf, 0, r->eax, r->ebx, r->ecx, r->edx); +} + +/* Voluntary context switches of a task, from its /proc status file. */ +static int read_nvcsw(const char *status, unsigned long *nvcsw) +{ + char buf[8192], *p; + + if (read_file_at(AT_FDCWD, status, buf, sizeof(buf)) <= 0) + return -1; + p = strstr(buf, "\nvoluntary_ctxt_switches:"); + if (!p || sscanf(p, "\nvoluntary_ctxt_switches: %lu", nvcsw) != 1) + return -1; + return 0; +} + +struct child_ctx { + int result_pipe[2]; +}; + +/* + * The child enters a fresh VE, so it is armed with the table state of that + * moment, then reports its view of the leaf to the parent over a pipe. It + * stops itself in between: a stopped task is off the CPU, so the resume is + * a context switch, and the parent may change the table while the child + * stands still. It tells the parent its context switch count first, so + * that the parent can wait for the switch out. + */ +static int cpuid_child(struct child_ctx *ctx) +{ + struct cpuid_regs r; + unsigned long nvcsw; + + close(ctx->result_pipe[0]); + + if (unshare(CLONE_NEWVE) < 0) + return 21; + if (read_nvcsw("/proc/self/status", &nvcsw)) + return 22; + if (write(ctx->result_pipe[1], &nvcsw, sizeof(nvcsw)) != sizeof(nvcsw)) + return 23; + if (raise(SIGSTOP)) + return 24; + + do_cpuid(CPUID_LEAF, &r); + + if (write(ctx->result_pipe[1], &r, sizeof(r)) != sizeof(r)) + return 25; + return 0; +} + +FIXTURE(ve_cpuid_override) +{ + int cgv2_fd; + int ctid; + struct cpuid_regs host; + unsigned int bit; + pid_t child; + char table[CPUID_LINE_LEN]; + char saved[CPUID_SAVED_MAX]; +}; + +FIXTURE_SETUP(ve_cpuid_override) +{ + int fd, len; + + if (geteuid()) + SKIP(return, "needs root"); + fd = open(CPUID_OVERRIDE_PATH, O_RDONLY); + if (fd < 0) + SKIP(return, "%s: %s", CPUID_OVERRIDE_PATH, strerror(errno)); + close(fd); + + len = read_file_at(AT_FDCWD, CPUID_OVERRIDE_PATH, self->saved, + sizeof(self->saved)); + ASSERT_GE(len, 0) TH_LOG("%s: %s", CPUID_OVERRIDE_PATH, strerror(errno)); + ASSERT_LT(len, CPUID_WRITE_MAX) + TH_LOG("a table of at least %d bytes cannot be restored", len); + + /* Mask one feature bit the host has; SSE2 when present. */ + do_cpuid(CPUID_LEAF, &self->host); + self->bit = 1u << 26; + if (!(self->host.edx & self->bit)) + self->bit = self->host.edx & -self->host.edx; + ASSERT_NE(self->bit, 0u); + + snprintf(self->table, sizeof(self->table), + "0x%08x: 0x%08x 0x%08x 0x%08x 0x%08x\n", CPUID_LEAF, + self->host.eax, self->host.ebx, self->host.ecx, + 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)); + 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); +} + +/* + * 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. + */ +FIXTURE_TEARDOWN_PARENT(ve_cpuid_override) +{ + int cgv2_fd; + + EXPECT_EQ(write_file_at(AT_FDCWD, CPUID_OVERRIDE_PATH, + self->saved[0] ? self->saved : "\n"), 0) + TH_LOG("could not restore %s: %s", CPUID_OVERRIDE_PATH, + strerror(errno)); + + /* A child left stopped by a failed ASSERT keeps the VE cgroup busy. */ + if (self->child > 0) + kill(self->child, SIGKILL); + + cgv2_fd = mount_cg2_fd(); + if (cgv2_fd < 0) { + TH_LOG("cgroup2 mount: %s, VE cgroup %d left behind", + strerror(errno), self->ctid); + return; + } + destroy_ve(cgv2_fd, self->ctid); + close(cgv2_fd); +} + +/* + * Stopped is reported to the parent before the child leaves the CPU, so a + * SIGCONT sent right away could keep it running without a switch. Wait + * until its voluntary context switch count has moved on. + */ +static void wait_switched_out(struct __test_metadata *_metadata, pid_t pid, + unsigned long nvcsw_before) +{ + char status[64]; + unsigned long nvcsw; + int i; + + snprintf(status, sizeof(status), "/proc/%d/status", pid); + for (i = 0; i < SWITCH_WAIT_ROUNDS; i++) { + ASSERT_EQ(read_nvcsw(status, &nvcsw), 0); + if (nvcsw > nvcsw_before) + return; + sched_yield(); + } + ASSERT_GT(nvcsw, nvcsw_before); +} + +/* Fork the child into the VE and return once it is off the CPU. */ +static pid_t spawn_cpuid_child(struct __test_metadata *_metadata, + FIXTURE_DATA(ve_cpuid_override) * self, + struct child_ctx *ctx) +{ + unsigned long nvcsw; + int status; + pid_t pid; + + ASSERT_EQ(pipe(ctx->result_pipe), 0); + ASSERT_GE(enter_cgroup(self->cgv2_fd, self->ctid), 0); + + pid = fork(); + if (pid == 0) + _exit(cpuid_child(ctx)); + if (pid > 0) + self->child = pid; + + /* Leave the VE cgroup before any ASSERT, or destroy_ve() gets EBUSY. */ + ASSERT_GE(enter_cgroup(self->cgv2_fd, 0), 0); + ASSERT_GE(pid, 0); + close(ctx->result_pipe[1]); + + ASSERT_GE(waitpid(pid, &status, WUNTRACED), 0); + if (!WIFSTOPPED(status)) { + /* Reaped: the pid may be reused, keep it from teardown. */ + self->child = 0; + if (WIFEXITED(status)) + TH_LOG("child exited with %d", WEXITSTATUS(status)); + if (WIFSIGNALED(status)) + TH_LOG("child killed by signal %d", WTERMSIG(status)); + } + ASSERT_TRUE(WIFSTOPPED(status)); + ASSERT_EQ(read(ctx->result_pipe[0], &nvcsw, sizeof(nvcsw)), + (int)sizeof(nvcsw)); + wait_switched_out(_metadata, pid, nvcsw); + return pid; +} + +static void resume_cpuid_child(struct __test_metadata *_metadata, pid_t pid) +{ + ASSERT_EQ(kill(pid, SIGCONT), 0); +} + +static void collect_cpuid_child(struct __test_metadata *_metadata, + FIXTURE_DATA(ve_cpuid_override) * self, + struct child_ctx *ctx, struct cpuid_regs *r) +{ + int status, len; + + len = read(ctx->result_pipe[0], r, sizeof(*r)); + ASSERT_GE(waitpid(self->child, &status, 0), 0); + self->child = 0; + if (WIFSIGNALED(status)) + TH_LOG("child killed by signal %d", WTERMSIG(status)); + ASSERT_TRUE(WIFEXITED(status)); + ASSERT_EQ(WEXITSTATUS(status), 0); + ASSERT_EQ(len, (int)sizeof(*r)); + + close(ctx->result_pipe[0]); +} + +TEST_F(ve_cpuid_override, ve_sees_table_host_sees_hardware) +{ + struct child_ctx ctx; + struct cpuid_regs r; + pid_t pid; + + ASSERT_EQ(write_file_at(AT_FDCWD, CPUID_OVERRIDE_PATH, self->table), 0); + + pid = spawn_cpuid_child(_metadata, self, &ctx); + resume_cpuid_child(_metadata, pid); + collect_cpuid_child(_metadata, self, &ctx, &r); + + EXPECT_EQ(r.eax, self->host.eax); + EXPECT_EQ(r.ebx, self->host.ebx); + EXPECT_EQ(r.ecx, self->host.ecx); + EXPECT_EQ(r.edx, self->host.edx & ~self->bit); + + do_cpuid(CPUID_LEAF, &r); + EXPECT_NE(r.edx & self->bit, 0u); +} + +TEST_F(ve_cpuid_override, flushed_table_falls_back_to_hardware) +{ + struct child_ctx ctx; + struct cpuid_regs r; + pid_t pid; + + ASSERT_EQ(write_file_at(AT_FDCWD, CPUID_OVERRIDE_PATH, self->table), 0); + + pid = spawn_cpuid_child(_metadata, self, &ctx); + + ASSERT_EQ(write_file_at(AT_FDCWD, CPUID_OVERRIDE_PATH, "\n"), 0); + resume_cpuid_child(_metadata, pid); + collect_cpuid_child(_metadata, self, &ctx, &r); + + EXPECT_NE(r.edx & self->bit, 0u); +} + +TEST_HARNESS_MAIN -- 2.43.0 _______________________________________________ Devel mailing list Devel@openvz.org https://lists.openvz.org/mailman/listinfo/devel