public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [kvm-unit-tests PATCH] x86/memory: pass host clwb and clflushopt support information
@ 2017-12-12  8:35 Haozhong Zhang
  2017-12-18 18:36 ` Eduardo Habkost
  0 siblings, 1 reply; 7+ messages in thread
From: Haozhong Zhang @ 2017-12-12  8:35 UTC (permalink / raw)
  To: kvm; +Cc: Paolo Bonzini, Eduardo Habkost, Haozhong Zhang

Intel VMX cannot intercept guest clwb and clflushopt. When clwb and
clflushopt are not exposed in guest cpuid, clwb and clflushopt
instructions in this test case can still succeed without #UD on the
host CPU which has clwb and clflushopt support, though failures with
UD are expected.

In order to avoid false alarms in such cases, introduce the following
two arguments "has_clwb" and "has_clflushopt" to allow users to
specify whether clwb and clflushopt are supported on the host CPU.

Signed-off-by: Haozhong Zhang <haozhong.zhang@intel.com>
---
 x86/memory.c | 29 +++++++++++++++++++++++++++--
 1 file changed, 27 insertions(+), 2 deletions(-)

diff --git a/x86/memory.c b/x86/memory.c
index cd1eb46..03ff7d3 100644
--- a/x86/memory.c
+++ b/x86/memory.c
@@ -23,10 +23,29 @@ static void handle_ud(struct ex_regs *regs)
 	regs->rip += isize;
 }
 
+/*
+ * Intel VMX cannot intercept guest clwb and clflushopt. When clwb and
+ * clflushopt are not exposed in guest cpuid, clwb and clflushopt
+ * instructions in this test case can still succeed without #UD on
+ * the host CPU which has clwb and clflushopt support. In order to avoid
+ * false alarms in such cases, introduce the following two arguments
+ * to allow users to specify whether clwb and clflushopt are supported on
+ * the host CPU:
+ * - has_clwb:       indicates clwb is supported on the host CPU
+ * - has_clflushopt: indicates clflushopt is supported on the host CPU
+ */
 int main(int ac, char **av)
 {
 	struct cpuid cpuid7, cpuid1;
 	int xfail;
+	int host_has_clwb = 0, host_has_clflushopt = 0; /* 0: unknown */
+	int i;
+
+	for (i = 1; i < ac; i++)
+		if (!strcmp(av[i], "has_clwb"))
+			host_has_clwb = 1;
+		else if (!strcmp(av[i], "has_clflushopt"))
+			host_has_clflushopt = 1;
 
 	setup_idt();
 	handle_exception(UD_VECTOR, handle_ud);
@@ -63,13 +82,19 @@ int main(int ac, char **av)
 	ud = 0;
 	/* clflushopt (%rbx): */
 	asm volatile(".byte 0x66, 0x0f, 0xae, 0x3b" : : "b" (&target));
-	report_xfail("clflushopt", xfail, ud == 0);
+	if (host_has_clflushopt)
+		report("clflushopt", ud == 0);
+	else
+		report_xfail("clflushopt", xfail, ud == 0);
 
 	xfail = !(cpuid7.b & (1U << 24)); /* CLWB */
 	ud = 0;
 	/* clwb (%rbx): */
 	asm volatile(".byte 0x66, 0x0f, 0xae, 0x33" : : "b" (&target));
-	report_xfail("clwb", xfail, ud == 0);
+	if (host_has_clwb)
+		report("clwb", ud == 0);
+	else
+		report_xfail("clwb", xfail, ud == 0);
 
 	ud = 0;
 	/* clwb requires a memory operand, the following is NOT a valid
-- 
2.14.1

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2018-02-14 12:04 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-12-12  8:35 [kvm-unit-tests PATCH] x86/memory: pass host clwb and clflushopt support information Haozhong Zhang
2017-12-18 18:36 ` Eduardo Habkost
2017-12-19  2:54   ` Haozhong Zhang
2017-12-20 21:26     ` Eduardo Habkost
2017-12-21  1:08       ` Haozhong Zhang
2017-12-21  1:32         ` Jim Mattson
2018-02-14 12:04       ` Paolo Bonzini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox