All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jan Kiszka <jan.kiszka@web.de>
To: Gleb Natapov <gleb@kernel.org>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Marcelo Tosatti <mtosatti@redhat.com>
Cc: kvm <kvm@vger.kernel.org>
Subject: [PATCH 06/13] x2apic: Test for invalid state transitions
Date: Sat,  4 Jan 2014 18:59:12 +0100	[thread overview]
Message-ID: <54ef8db7c3d723cbbf3d486bdbd69c124178557b.1388858359.git.jan.kiszka@web.de> (raw)
In-Reply-To: <cover.1388858359.git.jan.kiszka@web.de>
In-Reply-To: <cover.1388858359.git.jan.kiszka@web.de>

From: Jan Kiszka <jan.kiszka@siemens.com>

This checks if KVM properly acknowledges invalid state transitions on
MSR_APIC_BASE writes with a #GP.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
 lib/x86/apic-defs.h |  3 +++
 x86/apic.c          | 41 ++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 43 insertions(+), 1 deletion(-)

diff --git a/lib/x86/apic-defs.h b/lib/x86/apic-defs.h
index c061e3d..94112b4 100644
--- a/lib/x86/apic-defs.h
+++ b/lib/x86/apic-defs.h
@@ -9,6 +9,9 @@
  */
 
 #define	APIC_DEFAULT_PHYS_BASE	0xfee00000
+#define APIC_BSP		(1UL << 8)
+#define APIC_EXTD		(1UL << 10)
+#define APIC_EN			(1UL << 11)
 
 #define	APIC_ID		0x20
 
diff --git a/x86/apic.c b/x86/apic.c
index d06153f..4ebcd4f 100644
--- a/x86/apic.c
+++ b/x86/apic.c
@@ -4,6 +4,7 @@
 #include "smp.h"
 #include "desc.h"
 #include "isr.h"
+#include "msr.h"
 
 static int g_fail;
 static int g_tests;
@@ -70,14 +71,52 @@ static void test_tsc_deadline_timer(void)
     }
 }
 
-#define MSR_APIC_BASE 0x0000001b
+static void do_write_apicbase(void *data)
+{
+    set_exception_return(&&resume);
+    wrmsr(MSR_IA32_APICBASE, *(u64 *)data);
+resume:
+    barrier();
+}
 
 void test_enable_x2apic(void)
 {
+    u64 invalid_state = APIC_DEFAULT_PHYS_BASE | APIC_BSP | APIC_EXTD;
+    u64 apic_enabled = APIC_DEFAULT_PHYS_BASE | APIC_BSP | APIC_EN;
+    u64 x2apic_enabled =
+        APIC_DEFAULT_PHYS_BASE | APIC_BSP | APIC_EN | APIC_EXTD;
+
     if (enable_x2apic()) {
         printf("x2apic enabled\n");
+
+        report("x2apic enabled to invalid state",
+               test_for_exception(GP_VECTOR, do_write_apicbase,
+                                  &invalid_state));
+        report("x2apic enabled to apic enabled",
+               test_for_exception(GP_VECTOR, do_write_apicbase,
+                                  &apic_enabled));
+
+        wrmsr(MSR_IA32_APICBASE, APIC_DEFAULT_PHYS_BASE | APIC_BSP);
+        report("disabled to invalid state",
+               test_for_exception(GP_VECTOR, do_write_apicbase,
+                                  &invalid_state));
+        report("disabled to x2apic enabled",
+               test_for_exception(GP_VECTOR, do_write_apicbase,
+                                  &x2apic_enabled));
+
+        wrmsr(MSR_IA32_APICBASE, apic_enabled);
+        report("apic enabled to invalid state",
+               test_for_exception(GP_VECTOR, do_write_apicbase,
+                                  &invalid_state));
+
+        wrmsr(MSR_IA32_APICBASE, x2apic_enabled);
+        apic_write(APIC_SPIV, 0x1ff);
     } else {
         printf("x2apic not detected\n");
+
+        report("enable unsupported x2apic",
+               test_for_exception(GP_VECTOR, do_write_apicbase,
+                                  &x2apic_enabled));
     }
 }
 
-- 
1.8.1.1.298.ge7eed54


  parent reply	other threads:[~2014-01-04 17:59 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-04 17:59 [PATCH 00/13] kvm-unit-tests: Various improvements for x86 tests Jan Kiszka
2014-01-04 17:59 ` [PATCH 01/13] VMX: Add test cases around interrupt injection and halting Jan Kiszka
2014-01-04 17:59 ` [PATCH 02/13] VMX: Extend preemption timer tests Jan Kiszka
2014-01-04 17:59 ` [PATCH 03/13] apic: Remove redundant enable_apic Jan Kiszka
2014-01-04 17:59 ` [PATCH 04/13] VMX: Fix return label in fault-triggering handlers Jan Kiszka
2014-01-22 15:00   ` Paolo Bonzini
2014-01-22 17:21     ` Paolo Bonzini
2014-01-04 17:59 ` [PATCH 05/13] lib/x86: Move exception test code into library Jan Kiszka
2014-01-04 17:59 ` Jan Kiszka [this message]
2014-01-04 17:59 ` [PATCH 07/13] lib/x86/apic: Consolidate over MSR_IA32_APICBASE Jan Kiszka
2014-01-04 17:59 ` [PATCH 08/13] apic: Add test case for relocation and writing reserved bits Jan Kiszka
2014-01-04 17:59 ` [PATCH 09/13] VMX: Check unconditional I/O exiting Jan Kiszka
2014-01-04 17:59 ` [PATCH 10/13] Provide common report and report_summary services Jan Kiszka
2014-01-04 17:59 ` [PATCH 11/13] Ignore *.elf build outputs Jan Kiszka
2014-01-04 17:59 ` [PATCH 12/13] svm: Add missing build dependency Jan Kiszka
2014-01-04 17:59 ` [PATCH 13/13] x86: Add debug facility test case Jan Kiszka
2014-01-22 17:23 ` [PATCH 00/13] kvm-unit-tests: Various improvements for x86 tests Paolo Bonzini
2014-02-25 14:35 ` Paolo Bonzini

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=54ef8db7c3d723cbbf3d486bdbd69c124178557b.1388858359.git.jan.kiszka@web.de \
    --to=jan.kiszka@web.de \
    --cc=gleb@kernel.org \
    --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.