All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jan Kiszka <jan.kiszka@siemens.com>
To: kvm <kvm@vger.kernel.org>, Paolo Bonzini <pbonzini@redhat.com>,
	Marcelo Tosatti <mtosatti@redhat.com>
Subject: [PATCH kvm-unit-test] x86: vmx: Check #UD triggering of vmmcall
Date: Mon, 09 Mar 2015 21:00:11 +0100	[thread overview]
Message-ID: <54FDFBCB.9030806@siemens.com> (raw)

KVM tends to patch and emulated vmmcall on Intel. But that must not
happen for L2.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---

If the recently posted fixed for KVM are applied, this test passes.

 x86/vmx_tests.c | 40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)

diff --git a/x86/vmx_tests.c b/x86/vmx_tests.c
index 41a9a82..4f8ace1 100644
--- a/x86/vmx_tests.c
+++ b/x86/vmx_tests.c
@@ -11,6 +11,7 @@
 #include "fwcfg.h"
 #include "isr.h"
 #include "apic.h"
+#include "types.h"
 
 u64 ia32_pat;
 u64 ia32_efer;
@@ -1493,6 +1494,44 @@ static int msr_switch_exit_handler()
 	return VMX_TEST_EXIT;
 }
 
+static int vmmcall_init(struct vmcs *vmcs	)
+{
+	vmcs_write(EXC_BITMAP, 1 << UD_VECTOR);
+	return VMX_TEST_START;
+}
+
+static void vmmcall_main(void)
+{
+	asm volatile(
+		"mov $0xABCD, %%rax\n\t"
+		"vmmcall\n\t"
+		::: "rax");
+
+	report("VMMCALL", 0);
+}
+
+static int vmmcall_exit_handler()
+{
+	ulong reason;
+
+	reason = vmcs_read(EXI_REASON);
+	switch (reason) {
+	case VMX_VMCALL:
+		printf("here\n");
+		report("VMMCALL triggers #UD", 0);
+		break;
+	case VMX_EXC_NMI:
+		report("VMMCALL triggers #UD",
+		       (vmcs_read(EXI_INTR_INFO) & 0xff) == UD_VECTOR);
+		break;
+	default:
+		printf("Unknown exit reason, %d\n", reason);
+		print_vmexit_info();
+	}
+
+	return VMX_TEST_VMEXIT;
+}
+
 /* name/init/guest_main/exit_handler/syscall_handler/guest_regs */
 struct vmx_test vmx_tests[] = {
 	{ "null", NULL, basic_guest_main, basic_exit_handler, NULL, {0} },
@@ -1516,5 +1555,6 @@ struct vmx_test vmx_tests[] = {
 		NULL, {0} },
 	{ "MSR switch", msr_switch_init, msr_switch_main,
 		msr_switch_exit_handler, NULL, {0} },
+	{ "vmmcall", vmmcall_init, vmmcall_main, vmmcall_exit_handler, NULL, {0} },
 	{ NULL, NULL, NULL, NULL, NULL, {0} },
 };
-- 
2.1.4

             reply	other threads:[~2015-03-09 20:00 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-09 20:00 Jan Kiszka [this message]
2015-03-13 16:49 ` [PATCH kvm-unit-test] x86: vmx: Check #UD triggering of vmmcall Marcelo Tosatti

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=54FDFBCB.9030806@siemens.com \
    --to=jan.kiszka@siemens.com \
    --cc=kvm@vger.kernel.org \
    --cc=mtosatti@redhat.com \
    --cc=pbonzini@redhat.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.