From: Andrew Cooper Date: Fri, 11 Dec 2015 15:35:12 +0000 (+0000) Subject: Refactor architectural trap setup X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=f4a4bcb6b5190dd58a3a6d8334b24818e2b93548;p=people%2Froyger%2Fxen-test-framework.git Refactor architectural trap setup The setup of entry points is very different between PV and HVM guests. Introduce two new traps.c to accommodate, a stub arch_init_traps(), and a stub do_trap() as the C entry point for traps. Adjust the single arch_crash_hard() into the relevant arch traps.c to reduce the #ifdef'ary Signed-off-by: Andrew Cooper --- diff --git a/arch/x86/hvm/traps.c b/arch/x86/hvm/traps.c new file mode 100644 index 0000000..a6d81c7 --- /dev/null +++ b/arch/x86/hvm/traps.c @@ -0,0 +1,29 @@ +#include + +void arch_init_traps(void) +{ +} + +void __noreturn arch_crash_hard(void) +{ + /* + * Clear interrupts and halt. Xen should catch this condition and shut + * the VM down. If that fails, sit in a loop. + */ + asm volatile("cli;" + "1: hlt;" + "pause;" + "jmp 1b" + ::: "memory"); + unreachable(); +} + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/arch/x86/pv/traps.c b/arch/x86/pv/traps.c new file mode 100644 index 0000000..f8f9c85 --- /dev/null +++ b/arch/x86/pv/traps.c @@ -0,0 +1,47 @@ +#include + +void arch_init_traps(void) +{ +} + +void __noreturn arch_crash_hard(void) +{ + /* + * For both architectures, put the stack pointer into an invalid place and + * attempt to use it. Xen should fail to create a bounce frame and crash + * the domain. + */ + asm volatile( +#ifdef __i386__ + "mov %0, %%esp;" +#else + "movabs %0, %%rsp;" +#endif + "pushf" + :: +#ifdef __i386__ + "i" (0xfbadc0deUL) /* 32bit: In the read-only M2P mapping. */ +#else + "i" (0x800000000badc0deUL) /* 64bit: Non-canonical region. */ +#endif + : "memory" ); + + /* + * Attempt to crash failed. Give up and sit in a loop. + */ + asm volatile("1: hlt;" + "pause;" + "jmp 1b" + ::: "memory"); + unreachable(); +} + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/arch/x86/setup.c b/arch/x86/setup.c index bc9553a..773bcd9 100644 --- a/arch/x86/setup.c +++ b/arch/x86/setup.c @@ -4,6 +4,7 @@ #include #include +#include uint8_t boot_stack[PAGE_SIZE] __aligned(PAGE_SIZE); @@ -116,6 +117,8 @@ void arch_setup(void) register_console_callback(xen_console_write); + arch_init_traps(); + init_hypercalls(); setup_pv_console(); diff --git a/arch/x86/traps.c b/arch/x86/traps.c index 3879ad7..710003b 100644 --- a/arch/x86/traps.c +++ b/arch/x86/traps.c @@ -1,42 +1,13 @@ +#include #include /* - * Getting called means that a shutdown(crash) hypercall has not succeeded. - * Attempt more extreme measures to try and force a crash, and fall into an - * infinite loop if all else fails. + * C entry-point for exceptions, after the per-environment stubs have suitably + * adjusted the stack. */ -void __noreturn arch_crash_hard(void) +void do_exception(void) { -#if defined(CONFIG_ENV_pv32) - /* - * 32bit PV - put the stack in the Xen read-only M2P mappings and attempt - * to use it. - */ - asm volatile("mov %0, %%esp; pushf" - :: "i" (0xfbadc0deUL) : "memory"); - -#elif defined(CONFIG_ENV_pv64) - /* - * 64bit PV - put the stack in the middle of the non-canonical region, and - * attempt to use it. - */ - asm volatile("movabs %0, %%rsp; pushf" - :: "i" (0x800000000badc0deUL) : "memory"); - -#elif defined(CONFIG_ENV_hvm) - /* - * HVM - clear interrupts and halt. Xen should catch this condition and - * shut the VM down. - */ - asm volatile("cli; hlt"); - -#endif - - /* - * Attempt to crash failed. Give up and sit in a loop. - */ - asm volatile("1: hlt; rep; nop; jmp 1b" ::: "memory"); - unreachable(); + panic("Unhandled exception\n"); } /* diff --git a/build/files.mk b/build/files.mk index 49302f3..cc30949 100644 --- a/build/files.mk +++ b/build/files.mk @@ -20,6 +20,13 @@ obj-perenv += $(ROOT)/arch/x86/hypercall_page.o # HVM specific objects obj-hvm += $(ROOT)/arch/x86/hvm_pagetables.o +obj-hvm += $(ROOT)/arch/x86/hvm/traps.o obj-hvm32 += $(obj-hvm) obj-hvm64 += $(obj-hvm) + +# PV specific objects +obj-pv += $(ROOT)/arch/x86/pv/traps.o + +obj-pv32 += $(obj-pv) +obj-pv64 += $(obj-pv) diff --git a/include/arch/x86/traps.h b/include/arch/x86/traps.h index fc89d17..0a88cec 100644 --- a/include/arch/x86/traps.h +++ b/include/arch/x86/traps.h @@ -3,6 +3,15 @@ #include +/* + * Arch-specific function to initialise the exception entry points, etc. + */ +void arch_init_traps(void); + +/* + * Arch-specific function to quiesce the domain, in the event that a + * shutdown(crash) hypercall has not succeeded. + */ void __noreturn arch_crash_hard(void); #endif /* XTF_X86_TRAPS_H */