All Virtuozzo development lists (kernel + QEMU)
 help / color / mirror / Atom feed
From: Konstantin Khorenko <khorenko@virtuozzo.com>
To: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>,
	Vasileios Almpanis <vasileios.almpanis@virtuozzo.com>
Cc: devel@openvz.org
Subject: [Devel] [PATCH hci-8.1 3/5] selftests/ve: check CPUID override right after entering a VE
Date: Tue, 06 Oct 2026 16:56:36 +0200	[thread overview]
Message-ID: <20261006-b4-prep-khorenko-vstor-148656-cpuid-v1-3-741609f4f03a@virtuozzo.com> (raw)
In-Reply-To: <20261006-b4-prep-khorenko-vstor-148656-cpuid-v1-0-741609f4f03a@virtuozzo.com>

Add a case where the child executes CPUID straight after unshare(),
without blocking or waking anyone in between, and expects the table
values. Before the kernel change the override took effect only after
the first context switch, so the child saw the hardware values.

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

Feature: x86: cpu pools (cpuid override)
Signed-off-by: Konstantin Khorenko <khorenko@virtuozzo.com>
---
 .../testing/selftests/ve/ve_cpuid_override_test.c  | 42 ++++++++++++++++------
 1 file changed, 32 insertions(+), 10 deletions(-)

diff --git a/tools/testing/selftests/ve/ve_cpuid_override_test.c b/tools/testing/selftests/ve/ve_cpuid_override_test.c
index c066d67d72a82..be2b808f1c77e 100644
--- a/tools/testing/selftests/ve/ve_cpuid_override_test.c
+++ b/tools/testing/selftests/ve/ve_cpuid_override_test.c
@@ -54,13 +54,14 @@ static int write_cpuid_override(const char *table)
 
 /*
  * 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
- * blocks between the two steps: faulting is switched on for the task at its
- * next context switch, and the parent may change the table meanwhile.
+ * moment, then reports its view of the leaf to the parent over a pipe. With
+ * @wait_go it blocks between the two steps, which lets the parent change
+ * the table meanwhile and forces a context switch before the CPUID.
  */
 struct child_ctx {
 	int result_pipe[2];
 	int go_pipe[2];
+	int wait_go;
 };
 
 static int cpuid_child(struct child_ctx *ctx)
@@ -73,12 +74,18 @@ static int cpuid_child(struct child_ctx *ctx)
 
 	if (unshare(CLONE_NEWVE) < 0)
 		return 21;
-	if (write(ctx->result_pipe[1], "R", 1) != 1)
-		return 22;
-	if (read(ctx->go_pipe[0], &go, 1) != 1)
-		return 23;
-
+	if (ctx->wait_go) {
+		if (write(ctx->result_pipe[1], "R", 1) != 1)
+			return 22;
+		if (read(ctx->go_pipe[0], &go, 1) != 1)
+			return 23;
+	}
+
+	/* Without wait_go nothing wakes the parent before the CPUID. */
 	do_cpuid(CPUID_LEAF, &r);
+
+	if (!ctx->wait_go && write(ctx->result_pipe[1], "R", 1) != 1)
+		return 22;
 	if (write(ctx->result_pipe[1], &r, sizeof(r)) != sizeof(r))
 		return 24;
 	return 0;
@@ -187,7 +194,7 @@ static void collect_cpuid_child(struct __test_metadata *_metadata, pid_t pid,
 
 TEST_F(ve_cpuid_override, ve_sees_table_host_sees_hardware)
 {
-	struct child_ctx ctx;
+	struct child_ctx ctx = { .wait_go = 1 };
 	struct cpuid_regs r;
 	pid_t pid;
 
@@ -208,7 +215,7 @@ TEST_F(ve_cpuid_override, ve_sees_table_host_sees_hardware)
 
 TEST_F(ve_cpuid_override, flushed_table_falls_back_to_hardware)
 {
-	struct child_ctx ctx;
+	struct child_ctx ctx = { .wait_go = 1 };
 	struct cpuid_regs r;
 	pid_t pid;
 
@@ -224,4 +231,19 @@ TEST_F(ve_cpuid_override, flushed_table_falls_back_to_hardware)
 	EXPECT_NE(r.edx & self->bit, 0);
 }
 
+/* No context switch between entering the VE and the CPUID. */
+TEST_F(ve_cpuid_override, armed_before_first_reschedule)
+{
+	struct child_ctx ctx = { .wait_go = 0 };
+	struct cpuid_regs r;
+	pid_t pid;
+
+	ASSERT_EQ(write_cpuid_override(self->table), 0);
+
+	pid = spawn_cpuid_child(_metadata, self->cgv2_fd, self->ctid, &ctx);
+	collect_cpuid_child(_metadata, pid, &ctx, &r);
+
+	EXPECT_EQ(r.edx, self->host.edx & ~self->bit);
+}
+
 TEST_HARNESS_MAIN

-- 
2.43.0

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

  parent reply	other threads:[~2026-10-06 14:58 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-06 14:56 [Devel] [PATCH hci-8.1 0/5] x86/ve: CPUID override follow-ups: arm at once, prefixes, selftests Konstantin Khorenko
2026-10-06 14:56 ` [Devel] [PATCH hci-8.1 1/5] selftests/ve: check CPUID override emulation for VE tasks Konstantin Khorenko
2026-10-06 15:07   ` no-reply
2026-10-06 14:56 ` [Devel] [PATCH hci-8.1 2/5] x86/ve: enable CPUID faulting at once when the current task enters a VE Konstantin Khorenko
2026-10-06 15:01   ` no-reply
2026-10-06 14:56 ` Konstantin Khorenko [this message]
2026-10-06 15:03   ` [Devel] [PATCH hci-8.1 3/5] selftests/ve: check CPUID override right after entering " no-reply
2026-10-06 14:56 ` [Devel] [PATCH hci-8.1 4/5] x86/traps: decode the faulting CPUID with the instruction decoder Konstantin Khorenko
2026-10-06 15:04   ` no-reply
2026-10-06 14:56 ` [Devel] [PATCH hci-8.1 5/5] selftests/ve: check CPUID override emulation for a prefixed CPUID Konstantin Khorenko
2026-10-06 15:04   ` 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=20261006-b4-prep-khorenko-vstor-148656-cpuid-v1-3-741609f4f03a@virtuozzo.com \
    --to=khorenko@virtuozzo.com \
    --cc=devel@openvz.org \
    --cc=ptikhomirov@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 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.