From: Andrew Cooper Date: Fri, 2 Jun 2017 12:33:58 +0000 (+0100) Subject: Improvements to, and new TSS infrastructure X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=2bcda1aa60cd0032ea7371037c645b3d87104e21;p=people%2Fandrewcoop%2Fxen-test-framework.git Improvements to, and new TSS infrastructure * Rename hw_tss to env_tss, to highlight that it is the TSS appropriate for the current environment * Rename hw_tss{32,64} to x86_tss{32,64} to highlight that it is a structure specified by x86 * Replace reserved fields with empty bitfields * Remove erroneous link field from x86_tss64 * Introduce dump_x86_tss{32,64}() to neatly format a TSS. Signed-off-by: Andrew Cooper --- diff --git a/arch/x86/hvm/traps.c b/arch/x86/hvm/traps.c index 076d207..17ca66e 100644 --- a/arch/x86/hvm/traps.c +++ b/arch/x86/hvm/traps.c @@ -29,7 +29,7 @@ void entry_XM(void); void entry_VE(void); void entry_ret_to_kernel(void); -hw_tss tss __aligned(16) = +env_tss tss __aligned(16) = { #if defined(__i386__) @@ -47,7 +47,7 @@ hw_tss tss __aligned(16) = }; #if defined(__i386__) -static hw_tss tss_DF __aligned(16) = +static env_tss tss_DF __aligned(16) = { .esp = _u(&boot_stack[3 * PAGE_SIZE]), .ss = __KERN_DS, diff --git a/arch/x86/include/arch/desc.h b/arch/x86/include/arch/desc.h index 7908db6..bea7911 100644 --- a/arch/x86/include/arch/desc.h +++ b/arch/x86/include/arch/desc.h @@ -169,7 +169,7 @@ extern desc_ptr gdt_ptr; extern gate_desc idt[256]; extern desc_ptr idt_ptr; -extern hw_tss tss; +extern env_tss tss; #endif #endif /* XTF_X86_DESC_H */ diff --git a/arch/x86/include/arch/x86-tss.h b/arch/x86/include/arch/x86-tss.h index a95d948..4e13f00 100644 --- a/arch/x86/include/arch/x86-tss.h +++ b/arch/x86/include/arch/x86-tss.h @@ -10,17 +10,17 @@ #include #include -struct __packed hw_tss32 { - uint16_t link; uint16_t _r0; +struct __packed x86_tss32 { + uint16_t link; uint16_t :16; uint32_t esp0; - uint16_t ss0; uint16_t _r1; + uint16_t ss0; uint16_t :16; uint32_t esp1; - uint16_t ss1; uint16_t _r2; + uint16_t ss1; uint16_t :16; uint32_t esp2; - uint16_t ss2; uint16_t _r3; + uint16_t ss2; uint16_t :16; uint32_t cr3; uint32_t eip; @@ -34,42 +34,57 @@ struct __packed hw_tss32 { uint32_t esi; uint32_t edi; - uint16_t es; uint16_t _r4; - uint16_t cs; uint16_t _r5; - uint16_t ss; uint16_t _r6; - uint16_t ds; uint16_t _r7; - uint16_t fs; uint16_t _r8; - uint16_t gs; uint16_t _r9; - uint16_t ldtr; uint16_t _r10; - uint16_t t; uint16_t iopb; + uint16_t es; uint16_t :16; + uint16_t cs; uint16_t :16; + uint16_t ss; uint16_t :16; + uint16_t ds; uint16_t :16; + uint16_t fs; uint16_t :16; + uint16_t gs; uint16_t :16; + uint16_t ldtr; uint16_t :16; + + uint16_t trace:1, :15; + uint16_t iopb; }; -struct __packed hw_tss64 { - uint16_t link; uint16_t _r0; +struct __packed x86_tss64 { + uint32_t :32; uint64_t rsp0; uint64_t rsp1; uint64_t rsp2; - uint64_t _r1; + uint64_t :64; uint64_t ist[7]; /* 1-based structure */ - uint64_t _r2; + uint64_t :64; - uint16_t t; + uint16_t trace:1, :15; uint16_t iopb; }; #define X86_TSS_INVALID_IO_BITMAP 0x8000 +void dump_x86_tss32(const struct x86_tss32 *t); +void dump_x86_tss64(const struct x86_tss64 *t); + #if defined(__x86_64__) -typedef struct hw_tss64 hw_tss; +typedef struct x86_tss64 env_tss; + +static inline void dump_env_tss(const env_tss *t) +{ + dump_x86_tss64(t); +} #elif defined(__i386__) -typedef struct hw_tss32 hw_tss; +typedef struct x86_tss32 env_tss; + +static inline void dump_env_tss(const env_tss *t) +{ + dump_x86_tss32(t); +} #else # error Bad architecture for TSS infrastructure diff --git a/arch/x86/x86-tss.c b/arch/x86/x86-tss.c new file mode 100644 index 0000000..5dd2487 --- /dev/null +++ b/arch/x86/x86-tss.c @@ -0,0 +1,70 @@ +/** + * @file arch/x86/x86-tss.c + * + * %x86 Task State Segment helper routines. + */ +#include + +#include + +void dump_x86_tss32(const struct x86_tss32 *t) +{ + printk("Dump x86_tss32 at %p {\n" + " link %04x\n" + " r0 %04x:%08x\n" + " r1 %04x:%08x\n" + " r2 %04x:%08x\n" + " cr3 %08x\n" + " eip %08x, eflags %08x\n" + " eax %08x, ecx %08x\n" + " edx %08x, ebx %08x\n" + " esp %08x, ebp %08x\n" + " esi %08x, edi %08x\n" + " es %04x, cs %04x, ss %04x\n" + " ds %04x, fs %04x, gs %04x\n" + " ldtr %04x, trace %u, iobp %04x\n" + "}\n", + t, + t->link, + t->ss0, t->esp0, + t->ss1, t->esp1, + t->ss2, t->esp2, + t->cr3, + t->eip, t->eflags, + t->eax, t->ecx, + t->edx, t->ebx, + t->esp, t->ebp, + t->esi, t->edi, + t->es, t->cs, t->ss, + t->ds, t->fs, t->gs, + t->ldtr, t->trace, t->iopb); +} + +void dump_x86_tss64(const struct x86_tss64 *t) +{ + printk("Dump x86_tss64 at %p {\n" + " rsp0 %016"PRIx64", rsp1 %016"PRIx64"\n" + " rsp2 %016"PRIx64", ist1 %016"PRIx64"\n" + " ist2 %016"PRIx64", ist3 %016"PRIx64"\n" + " ist4 %016"PRIx64", ist5 %016"PRIx64"\n" + " ist6 %016"PRIx64", ist7 %016"PRIx64"\n" + " trace %u, iobp %04x\n" + "}\n", + t, + t->rsp0, t->rsp1, + t->rsp2, t->ist[0], + t->ist[1], t->ist[2], + t->ist[3], t->ist[4], + t->ist[5], t->ist[6], + t->trace, t->iopb); +} + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/build/files.mk b/build/files.mk index a179f27..8ffd6e7 100644 --- a/build/files.mk +++ b/build/files.mk @@ -26,6 +26,10 @@ obj-perenv += $(ROOT)/arch/x86/traps.o # HVM specific objects obj-hvm += $(ROOT)/arch/x86/hvm/pagetables.o obj-hvm += $(ROOT)/arch/x86/hvm/traps.o + +# Arguably common objects, but PV guests will have no interest in them. +obj-hvm += $(ROOT)/arch/x86/x86-tss.o + $(foreach env,$(HVM_ENVIRONMENTS),$(eval obj-$(env) += $(obj-hvm))) diff --git a/tests/xsa-192/main.c b/tests/xsa-192/main.c index 7e5b10b..28c208b 100644 --- a/tests/xsa-192/main.c +++ b/tests/xsa-192/main.c @@ -41,7 +41,7 @@ asm(".align 16;" ); /* Virtual 8068 task. */ -hw_tss vm86_tss __aligned(16) = +env_tss vm86_tss __aligned(16) = { .eflags = X86_EFLAGS_VM | X86_EFLAGS_IOPL | X86_EFLAGS_MBS, .eip = 0x1000,