public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Avi Kivity <avi@redhat.com>
To: Joerg Roedel <joerg.roedel@amd.com>,
	Marcelo Tosatti <mtosatti@redhat.com>,
	kvm@vger.kernel.org
Subject: [PATCH 6/6] test: verify that the emulator honours svm intercepts
Date: Wed, 28 Jul 2010 19:25:51 +0300	[thread overview]
Message-ID: <1280334351-6395-7-git-send-email-avi@redhat.com> (raw)
In-Reply-To: <1280334351-6395-1-git-send-email-avi@redhat.com>

Signed-off-by: Avi Kivity <avi@redhat.com>
---
 kvm/test/x86/svm.c |   37 +++++++++++++++++++++++++++++++++++++
 1 files changed, 37 insertions(+), 0 deletions(-)

diff --git a/kvm/test/x86/svm.c b/kvm/test/x86/svm.c
index 3c30118..cb26af6 100644
--- a/kvm/test/x86/svm.c
+++ b/kvm/test/x86/svm.c
@@ -3,6 +3,7 @@
 #include "processor.h"
 #include "msr.h"
 #include "vm.h"
+#include "smp.h"
 
 static void setup_svm(void)
 {
@@ -168,6 +169,39 @@ static bool check_cr3_nointercept(struct test *test)
     return null_check(test) && test->scratch == read_cr3();
 }
 
+static void corrupt_cr3_intercept_bypass(void *_test)
+{
+    struct test *test = _test;
+    extern volatile u32 mmio_insn;
+
+    while (!__sync_bool_compare_and_swap(&test->scratch, 1, 2))
+        pause();
+    pause();
+    pause();
+    pause();
+    mmio_insn = 0x90d8200f;  // mov %cr3, %rax; nop
+}
+
+static void prepare_cr3_intercept_bypass(struct test *test)
+{
+    default_prepare(test);
+    test->vmcb->control.intercept_cr_read |= 1 << 3;
+    on_cpu_async(1, corrupt_cr3_intercept_bypass, test);
+}
+
+static void test_cr3_intercept_bypass(struct test *test)
+{
+    ulong a = 0xa0000;
+
+    test->scratch = 1;
+    while (test->scratch != 2)
+        barrier();
+
+    asm volatile ("mmio_insn: mov %0, (%0); nop"
+                  : "+a"(a) : : "memory");
+    test->scratch = a;
+}
+
 static struct test tests[] = {
     { "null", default_prepare, null_test, default_finished, null_check },
     { "vmrun", default_prepare, test_vmrun, default_finished, check_vmrun },
@@ -177,6 +211,8 @@ static struct test tests[] = {
       default_finished, check_cr3_intercept },
     { "cr3 read nointercept", default_prepare, test_cr3_intercept,
       default_finished, check_cr3_nointercept },
+    { "cr3 read intercept emulate", prepare_cr3_intercept_bypass,
+      test_cr3_intercept_bypass, default_finished, check_cr3_intercept }
 };
 
 int main(int ac, char **av)
@@ -185,6 +221,7 @@ int main(int ac, char **av)
     struct vmcb *vmcb;
 
     setup_vm();
+    smp_init();
 
     if (!(cpuid(0x80000001).c & 4)) {
         printf("SVM not availble\n");
-- 
1.7.1


  parent reply	other threads:[~2010-07-28 16:25 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-07-28 16:25 [PATCH 0/6] svm intercept tests Avi Kivity
2010-07-28 16:25 ` [PATCH 1/6] test: add scratch word for use by svm tests Avi Kivity
2010-07-28 16:25 ` [PATCH 2/6] test: add intercepted and unintercepted cr3 read tests for svm Avi Kivity
2010-07-28 16:25 ` [PATCH 3/6] test: add pause() instruction accessor Avi Kivity
2010-07-28 16:25 ` [PATCH 4/6] test: add cli() and sti() instruction accessors Avi Kivity
2010-07-28 16:25 ` [PATCH 5/6] test: ensure svm tests are executed with interrupts disabled by default Avi Kivity
2010-07-28 16:25 ` Avi Kivity [this message]
2010-07-28 18:04   ` [PATCH 6/6] test: verify that the emulator honours svm intercepts Avi Kivity
2010-07-29  7:43     ` Roedel, Joerg
2010-07-29  7:48       ` Avi Kivity
2010-07-29  7:59         ` Roedel, Joerg
2010-07-29  8:45           ` Avi Kivity
2010-07-29  8:16 ` [PATCH 0/6] svm intercept tests Roedel, Joerg
2010-07-29 21:40   ` 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=1280334351-6395-7-git-send-email-avi@redhat.com \
    --to=avi@redhat.com \
    --cc=joerg.roedel@amd.com \
    --cc=kvm@vger.kernel.org \
    --cc=mtosatti@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox