From: Andrew Cooper Date: Sat, 5 Mar 2016 19:11:34 +0000 (+0000) Subject: Utility for dumping MSRs visible to a guest X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=989150f5f0ac3f4fee5ef8f0b9375ea3688bf11f;p=people%2Froyger%2Fxen-test-framework.git Utility for dumping MSRs visible to a guest Signed-off-by: Andrew Cooper --- diff --git a/docs/all-tests.dox b/docs/all-tests.dox index 2f73263..d3e02b3 100644 --- a/docs/all-tests.dox +++ b/docs/all-tests.dox @@ -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 index 0000000..8d215bd --- /dev/null +++ b/tests/msr/Makefile @@ -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 index 0000000..391a320 --- /dev/null +++ b/tests/msr/main.c @@ -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 + +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: + */