Except the TSS, which is 16-bytes in 64-bit mode, we can use the same structure and share the constants. This will aid in porting tests to 64-bit. Multiple bitwidth and ring 3 selectors aren't used yet. I couldn't make my mind on keeping vs. dropping them, in the end I kept the ring 3 selectors which have a chance of being used for SMAP or paging unit tests. With this change, vmx.c can start using desc.h's constants and those in vm.h (why vm.h?) can be dropped. Signed-off-by: Paolo Bonzini <pbonzini@xxxxxxxxxx> --- lib/x86/desc.c | 12 +++++++----- lib/x86/desc.h | 6 ++++-- lib/x86/vm.h | 13 ------------- x86/cstart.S | 6 +++--- x86/cstart64.S | 16 ++++++++++++---- x86/vmx.c | 32 ++++++++++++++++---------------- 6 files changed, 42 insertions(+), 43 deletions(-) diff --git a/lib/x86/desc.c b/lib/x86/desc.c index 442c9a1..ec1fda3 100644 --- a/lib/x86/desc.c +++ b/lib/x86/desc.c @@ -191,11 +191,13 @@ unsigned exception_error_code(void) /* * GDT, with 6 entries: * 0x00 - NULL descriptor - * 0x08 - Code segment - * 0x10 - Data segment - * 0x18 - Not present code segment - * 0x20 - Interrupt task - * 0x28 to 0x78 - Free to use for test cases + * 0x08 - Code segment (ring 0) + * 0x10 - Data segment (ring 0) + * 0x18 - Not present code segment (ring 0) + * 0x20 - Code segment (ring 3) + * 0x28 - Data segment (ring 3) + * 0x30 - Interrupt task + * 0x38 to 0x78 - Free to use for test cases * 0x80 - Primary task (CPU 0) */ diff --git a/lib/x86/desc.h b/lib/x86/desc.h index 4689474..cd41a74 100644 --- a/lib/x86/desc.h +++ b/lib/x86/desc.h @@ -72,8 +72,10 @@ typedef struct { #define KERNEL_CS 0x08 #define KERNEL_DS 0x10 #define NP_SEL 0x18 -#define TSS_INTR 0x20 -#define FIRST_SPARE_SEL 0x28 +#define USER_CS 0x20 +#define USER_DS 0x28 +#define TSS_INTR 0x30 +#define FIRST_SPARE_SEL 0x38 #define TSS_MAIN 0x80 typedef struct { diff --git a/lib/x86/vm.h b/lib/x86/vm.h index 6e0ce2b..03a9b4e 100644 --- a/lib/x86/vm.h +++ b/lib/x86/vm.h @@ -28,19 +28,6 @@ #define X86_CR4_PAE 0x00000020 #define X86_CR4_PCIDE 0x00020000 -#ifdef __x86_64__ -#define SEL_NULL_DESC 0x0 -#define SEL_KERN_CODE_64 0x8 -#define SEL_KERN_DATA_64 0x10 -#define SEL_USER_CODE_64 0x18 -#define SEL_USER_DATA_64 0x20 -#define SEL_CODE_32 0x28 -#define SEL_DATA_32 0x30 -#define SEL_CODE_16 0x38 -#define SEL_DATA_16 0x40 -#define SEL_TSS_RUN 0x48 -#endif - void setup_vm(); void *vmalloc(unsigned long size); diff --git a/x86/cstart.S b/x86/cstart.S index ffa0768..f9ba1fe 100644 --- a/x86/cstart.S +++ b/x86/cstart.S @@ -34,10 +34,10 @@ gdt32: .quad 0x00cf9b000000ffff // flat 32-bit code segment .quad 0x00cf93000000ffff // flat 32-bit data segment .quad 0x00cf1b000000ffff // flat 32-bit code segment, not present + .quad 0x00cffb000000ffff // 64-bit code segment (user) + .quad 0x00cff3000000ffff // 64-bit data segment (user) - .quad 0 // 12 spare selectors - .quad 0 - .quad 0 + .quad 0 // 10 spare selectors .quad 0 .quad 0 .quad 0 diff --git a/x86/cstart64.S b/x86/cstart64.S index 0fe76da..1a0c85e 100644 --- a/x86/cstart64.S +++ b/x86/cstart64.S @@ -54,12 +54,20 @@ gdt64: .quad 0 .quad 0x00af9b000000ffff // 64-bit code segment .quad 0x00cf93000000ffff // 64-bit data segment + .quad 0x00af1b000000ffff // 64-bit code segment, not present .quad 0x00affb000000ffff // 64-bit code segment (user) .quad 0x00cff3000000ffff // 64-bit data segment (user) - .quad 0x00cf9b000000ffff // 32-bit code segment - .quad 0x00cf92000000ffff // 32-bit code segment - .quad 0x008F9A000000FFFF // 16-bit code segment - .quad 0x008F92000000FFFF // 16-bit data segment + + .quad 0 // 10 spare selectors + .quad 0 + .quad 0 + .quad 0 + .quad 0 + .quad 0 + .quad 0 + .quad 0 + .quad 0 + .quad 0 tss_descr: .rept max_cpus diff --git a/x86/vmx.c b/x86/vmx.c index 2278078..1d28c6f 100644 --- a/x86/vmx.c +++ b/x86/vmx.c @@ -346,16 +346,16 @@ static void init_vmcs_host(void) vmcs_write(HOST_CR3, read_cr3()); vmcs_write(HOST_CR4, read_cr4()); vmcs_write(HOST_SYSENTER_EIP, (u64)(&entry_sysenter)); - vmcs_write(HOST_SYSENTER_CS, SEL_KERN_CODE_64); + vmcs_write(HOST_SYSENTER_CS, KERNEL_CS); /* 26.2.3 */ - vmcs_write(HOST_SEL_CS, SEL_KERN_CODE_64); - vmcs_write(HOST_SEL_SS, SEL_KERN_DATA_64); - vmcs_write(HOST_SEL_DS, SEL_KERN_DATA_64); - vmcs_write(HOST_SEL_ES, SEL_KERN_DATA_64); - vmcs_write(HOST_SEL_FS, SEL_KERN_DATA_64); - vmcs_write(HOST_SEL_GS, SEL_KERN_DATA_64); - vmcs_write(HOST_SEL_TR, SEL_TSS_RUN); + vmcs_write(HOST_SEL_CS, KERNEL_CS); + vmcs_write(HOST_SEL_SS, KERNEL_DS); + vmcs_write(HOST_SEL_DS, KERNEL_DS); + vmcs_write(HOST_SEL_ES, KERNEL_DS); + vmcs_write(HOST_SEL_FS, KERNEL_DS); + vmcs_write(HOST_SEL_GS, KERNEL_DS); + vmcs_write(HOST_SEL_TR, TSS_MAIN); vmcs_write(HOST_BASE_TR, tss_descr.base); vmcs_write(HOST_BASE_GDTR, gdt64_desc.base); vmcs_write(HOST_BASE_IDTR, idt_descr.base); @@ -389,7 +389,7 @@ static void init_vmcs_guest(void) vmcs_write(GUEST_CR0, guest_cr0); vmcs_write(GUEST_CR3, guest_cr3); vmcs_write(GUEST_CR4, guest_cr4); - vmcs_write(GUEST_SYSENTER_CS, SEL_KERN_CODE_64); + vmcs_write(GUEST_SYSENTER_CS, KERNEL_CS); vmcs_write(GUEST_SYSENTER_ESP, (u64)(guest_syscall_stack + PAGE_SIZE - 1)); vmcs_write(GUEST_SYSENTER_EIP, (u64)(&entry_sysenter)); @@ -397,13 +397,13 @@ static void init_vmcs_guest(void) vmcs_write(GUEST_EFER, rdmsr(MSR_EFER)); /* 26.3.1.2 */ - vmcs_write(GUEST_SEL_CS, SEL_KERN_CODE_64); - vmcs_write(GUEST_SEL_SS, SEL_KERN_DATA_64); - vmcs_write(GUEST_SEL_DS, SEL_KERN_DATA_64); - vmcs_write(GUEST_SEL_ES, SEL_KERN_DATA_64); - vmcs_write(GUEST_SEL_FS, SEL_KERN_DATA_64); - vmcs_write(GUEST_SEL_GS, SEL_KERN_DATA_64); - vmcs_write(GUEST_SEL_TR, SEL_TSS_RUN); + vmcs_write(GUEST_SEL_CS, KERNEL_CS); + vmcs_write(GUEST_SEL_SS, KERNEL_DS); + vmcs_write(GUEST_SEL_DS, KERNEL_DS); + vmcs_write(GUEST_SEL_ES, KERNEL_DS); + vmcs_write(GUEST_SEL_FS, KERNEL_DS); + vmcs_write(GUEST_SEL_GS, KERNEL_DS); + vmcs_write(GUEST_SEL_TR, TSS_MAIN); vmcs_write(GUEST_SEL_LDTR, 0); vmcs_write(GUEST_BASE_CS, 0); -- 1.8.3.1 -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html