From: Avi Kivity <a...@redhat.com>

kvm used to read host values from this msr.

Signed-off-by: Avi Kivity <a...@redhat.com>

diff --git a/user/config-x86-common.mak b/user/config-x86-common.mak
index 315091a..e789fd4 100644
--- a/user/config-x86-common.mak
+++ b/user/config-x86-common.mak
@@ -21,7 +21,7 @@ FLATLIBS = test/lib/libcflat.a $(libgcc)
 tests-common = $(TEST_DIR)/bootstrap \
                        $(TEST_DIR)/vmexit.flat $(TEST_DIR)/tsc.flat \
                        $(TEST_DIR)/smptest.flat  $(TEST_DIR)/port80.flat \
-                       $(TEST_DIR)/realmode.flat
+                       $(TEST_DIR)/realmode.flat $(TEST_DIR)/msr.flat
 
 test_cases: $(tests-common) $(tests)
 
@@ -59,6 +59,8 @@ $(TEST_DIR)/realmode.flat: $(TEST_DIR)/realmode.o
 
 $(TEST_DIR)/realmode.o: bits = 32
 
+$(TEST_DIR)/msr.flat: $(cstart.o) $(TEST_DIR)/msr.o
+
 arch_clean:
        $(RM) $(TEST_DIR)/bootstrap $(TEST_DIR)/*.o $(TEST_DIR)/*.flat \
        $(TEST_DIR)/.*.d $(TEST_DIR)/lib/.*.d $(TEST_DIR)/lib/*.o
diff --git a/user/test/x86/msr.c b/user/test/x86/msr.c
new file mode 100644
index 0000000..5010ad0
--- /dev/null
+++ b/user/test/x86/msr.c
@@ -0,0 +1,50 @@
+/* msr tests */
+
+#include "libcflat.h"
+
+#define MSR_KERNEL_GS_BASE     0xc0000102 /* SwapGS GS shadow */
+
+int nr_passed, nr_tests;
+
+static void report(const char *name, int passed)
+{
+       ++nr_tests;
+       if (passed)
+               ++nr_passed;
+       printf("%s: %s\n", name, passed ? "PASS" : "FAIL");
+}
+
+static void wrmsr(unsigned index, unsigned long long value)
+{
+       asm volatile ("wrmsr" : : "c"(index), "A"(value));
+}
+
+static unsigned long long rdmsr(unsigned index)
+{
+       unsigned long long value;
+
+       asm volatile ("rdmsr" : "=A"(value) : "c"(index));
+
+       return value;
+}
+
+static void test_kernel_gs_base(void)
+{
+#ifdef __x86_64__
+       unsigned long long v1 = 0x123456789abcdef, v2;
+
+       wrmsr(MSR_KERNEL_GS_BASE, v1);
+       v2 = rdmsr(MSR_KERNEL_GS_BASE);
+       report("MSR_KERNEL_GS_BASE", v1 == v2);
+#endif
+}
+
+int main(int ac, char **av)
+{
+       test_kernel_gs_base();
+
+       printf("%d tests, %d failures\n", nr_tests, nr_tests - nr_passed);
+
+       return nr_passed == nr_tests ? 0 : 1;
+}
+
--
To unsubscribe from this list: send the line "unsubscribe kvm-commits" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to