[Devel] [PATCH hci-8.1 v5 5/5] selftests/ve: check CPUID override emulation for a prefixed CPUID
Konstantin Khorenko
khorenko at virtuozzo.com
Wed Oct 7 01:54:35 MSK 2026
Execute CPUID with an operand-size prefix, which the CPU ignores, and
expect the table values. Before the kernel change the #GP handler
matched only the bare opcode and the child died with SIGSEGV.
https://virtuozzo.atlassian.net/browse/VSTOR-148843
Feature: x86: cpu pools (cpuid override)
Signed-off-by: Konstantin Khorenko <khorenko at virtuozzo.com>
---
.../testing/selftests/ve/ve_cpuid_override_test.c | 32 +++++++++++++++++++++-
1 file changed, 31 insertions(+), 1 deletion(-)
diff --git a/tools/testing/selftests/ve/ve_cpuid_override_test.c b/tools/testing/selftests/ve/ve_cpuid_override_test.c
index f944fb5d806f6..98649d7df8ed4 100644
--- a/tools/testing/selftests/ve/ve_cpuid_override_test.c
+++ b/tools/testing/selftests/ve/ve_cpuid_override_test.c
@@ -47,6 +47,17 @@ static void do_cpuid(unsigned int leaf, struct cpuid_regs *r)
__cpuid_count(leaf, 0, r->eax, r->ebx, r->ecx, r->edx);
}
+/* CPUID with an operand-size prefix, which the CPU accepts and ignores. */
+static void do_cpuid_prefixed(unsigned int leaf, struct cpuid_regs *r)
+{
+ /* ebx is the PIC base on i386; swap it out like <cpuid.h> does. */
+ asm volatile("xchg %%ebx, %1\n\t"
+ ".byte 0x66, 0x0f, 0xa2\n\t"
+ "xchg %%ebx, %1"
+ : "=a" (r->eax), "=&r" (r->ebx), "=c" (r->ecx), "=d" (r->edx)
+ : "a" (leaf), "c" (0));
+}
+
/* Voluntary context switches of a task, from its /proc status file. */
static int read_nvcsw(const char *status, unsigned long *nvcsw)
{
@@ -63,6 +74,7 @@ static int read_nvcsw(const char *status, unsigned long *nvcsw)
struct child_ctx {
int result_pipe[2];
int stop;
+ int prefixed;
};
/*
@@ -92,7 +104,10 @@ static int cpuid_child(struct child_ctx *ctx)
return 24;
}
- do_cpuid(CPUID_LEAF, &r);
+ if (ctx->prefixed)
+ do_cpuid_prefixed(CPUID_LEAF, &r);
+ else
+ do_cpuid(CPUID_LEAF, &r);
if (write(ctx->result_pipe[1], &r, sizeof(r)) != sizeof(r))
return 25;
@@ -324,4 +339,19 @@ TEST_F(ve_cpuid_override, armed_before_first_reschedule)
}
}
+TEST_F(ve_cpuid_override, prefixed_cpuid_is_emulated)
+{
+ struct child_ctx ctx = { .stop = 1, .prefixed = 1 };
+ 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.edx, self->host.edx & ~self->bit);
+}
+
TEST_HARNESS_MAIN
--
2.43.0
More information about the Devel
mailing list