]> xenbits.xensource.com Git - people/royger/xen-test-framework.git/commitdiff
Utility for dumping MSRs visible to a guest
authorAndrew Cooper <andrew.cooper3@citrix.com>
Sat, 5 Mar 2016 19:11:34 +0000 (19:11 +0000)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Sun, 6 Mar 2016 19:44:53 +0000 (19:44 +0000)
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
docs/all-tests.dox
tests/msr/Makefile [new file with mode: 0644]
tests/msr/main.c [new file with mode: 0644]

index 2f732632027a6dd73b528c2865f0e83d466e67bd..d3e02b3615e11823d9800303f2b80e18f90008c8 100644 (file)
@@ -28,4 +28,6 @@ Coveres XSA-106 and XSA-156.
 @section index-utility Utilities
 
 @subpage test-cpuid - Print CPUID information.
+
+@subpage test-msr - Print MSR information.
 */
diff --git a/tests/msr/Makefile b/tests/msr/Makefile
new file mode 100644 (file)
index 0000000..8d215bd
--- /dev/null
@@ -0,0 +1,11 @@
+ROOT := $(abspath $(CURDIR)/../..)
+
+include $(ROOT)/build/common.mk
+
+NAME      := msr
+CATEGORY  := utility
+TEST-ENVS := $(ALL_ENVIRONMENTS)
+
+obj-perenv += main.o
+
+include $(ROOT)/build/gen.mk
diff --git a/tests/msr/main.c b/tests/msr/main.c
new file mode 100644 (file)
index 0000000..391a320
--- /dev/null
@@ -0,0 +1,72 @@
+/**
+ * @file tests/msr/main.c
+ * @ref test-msr
+ *
+ * @page test-msr MSR
+ *
+ * Prints the values of all MSRs which are readable to the guest.
+ *
+ * @warning As this probes all MSR indicies, it can cause substantial logspam
+ * in Xen from extable fixup, depending on log level.
+ *
+ * @sa tests/msr/main.c
+ */
+#include <xtf/lib.h>
+
+static int rdmsr_safe(uint32_t msr, uint64_t *val)
+{
+    uint32_t lo, hi;
+    int ret;
+
+    asm volatile ("1: rdmsr;"
+                  "jmp 3f; 2:"
+                  "xor %[lo], %[lo];"
+                  "xor %[hi], %[hi];"
+                  "mov %[err], %[res];"
+                  "3:"
+                  _ASM_EXTABLE(1b, 2b)
+                  : [lo] "=a" (lo), [hi] "=d" (hi), [res] "=&q" (ret)
+                  : "c" (msr), [err] "ir" (-EFAULT), "2" (0));
+
+    *val = ((uint64_t)hi) << 32 | lo;
+    return ret;
+}
+
+void test_main(void)
+{
+    unsigned int idx = 0;
+    uint64_t val;
+
+    printk("Guest MSR information\n");
+
+    do {
+        if ( !rdmsr_safe(idx, &val) )
+            printk("  %08x -> %016"PRIx64"\n", idx, val);
+
+        idx++;
+
+        switch ( idx )
+        {
+        case 0x2000:
+            idx = 0x40000000;
+            break;
+
+        case 0x40000100:
+            idx = 0xC0000000;
+            break;
+        }
+
+    } while ( idx <= 0xC0001fff );
+
+    xtf_success(NULL);
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */