[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [DO NOT APPLY PATCH XTF 2/2] Add UMIP test
Signed-off-by: Wei Liu <wei.liu2@xxxxxxxxxx> --- tests/umip/Makefile | 9 +++++ tests/umip/main.c | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 111 insertions(+) create mode 100644 tests/umip/Makefile create mode 100644 tests/umip/main.c diff --git a/tests/umip/Makefile b/tests/umip/Makefile new file mode 100644 index 0000000..a74016c --- /dev/null +++ b/tests/umip/Makefile @@ -0,0 +1,9 @@ +include $(ROOT)/build/common.mk + +NAME := umip +CATEGORY := functional +TEST-ENVS := hvm32 + +obj-perenv += main.o + +include $(ROOT)/build/gen.mk diff --git a/tests/umip/main.c b/tests/umip/main.c new file mode 100644 index 0000000..ca74085 --- /dev/null +++ b/tests/umip/main.c @@ -0,0 +1,102 @@ +/** + * @file tests/umip/main.c + * @ref test-umip + * + * @page test-umip UMIP + * + * Test if UMIP (User-Mode Instruction Prevention) is functional. + * + * Returns SUCCESS if UMIP is functional, SKIP if UMIP is not + * available and FAILURE if UMIP doesn't cause SGDT, SLDT, SIDT, STR + * or SMSW to fault. + * + * @see tests/umip/main.c + */ +#include <xtf.h> + +#include <arch/x86/processor.h> + +#define EX(instr) \ + bool seen_ ## instr ## _fault; \ + bool ex_ ##instr(struct cpu_regs *regs, \ + const struct extable_entry *ex) \ + { \ + if ( regs->entry_vector == X86_EXC_GP ) \ + { \ + seen_ ## instr ## _fault = true; \ + regs->ip = ex->fixup; \ + \ + return true; \ + } \ + \ + return false; \ + } \ + +EX(sgdt) +EX(sldt) +EX(sidt) +EX(str) +EX(smsw) + +#undef EX + +void test_main(void) +{ + uint8_t buf[1024]; + + printk("Test if UMIP is functional\n"); + + if ( !cpu_has_umip ) + { + xtf_skip("UMIP is not available\n"); + return; + } + + if ( !xtf_has_fep ) + xtf_skip("FEP not available, some tests will be skipped\n"); + + write_cr4(read_cr4() | X86_CR4_UMIP); + +#define TEST(fep,instr) \ + do { \ + seen_ ## instr ## _fault = false; \ + asm volatile ("1: " fep #instr " %0; 2:" \ + _ASM_EXTABLE_HANDLER(1b, 2b, ex_ ##instr) \ + : : "m"(buf)); \ + if ( !seen_ ## instr ## _fault ) \ + { \ + xtf_failure(fep #instr " didn't cause fault\n"); \ + return; \ + } \ + seen_ ## instr ## _fault = false; \ + } while (0) + + TEST(, sgdt); + TEST(, sldt); + TEST(, sidt); + TEST(, str); + TEST(, smsw); + + if ( xtf_has_fep ) + { + TEST(_ASM_XEN_FEP, sgdt); + TEST(_ASM_XEN_FEP, sldt); + TEST(_ASM_XEN_FEP, sidt); + TEST(_ASM_XEN_FEP, str); + TEST(_ASM_XEN_FEP, smsw); + } + +#undef TEST + + xtf_success(NULL); +} + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ -- 2.11.0 _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx https://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |