ia64/xen-unstable

changeset 682:29c5d712802c

bitkeeper revision 1.397 (3f4e025cTStPJGtnPMTvJ95GFn4NAg)

mm.h, config.h, hypervisor-if.h, desc.h, trampoline.S, mm.c, boot.S:
Move reserved GDT entries to later in the GDT, allowing support for hard-coded small selector values in brain-dead OSes.
author kaf24@scramble.cl.cam.ac.uk
date Thu Aug 28 13:23:40 2003 +0000 (2003-08-28)
parents 3aa0265ba99b
children 6137a63f86c4
files xen/arch/i386/boot/boot.S xen/arch/i386/mm.c xen/arch/i386/trampoline.S xen/include/asm-i386/desc.h xen/include/hypervisor-ifs/hypervisor-if.h xen/include/xeno/config.h xen/include/xeno/mm.h
line diff
     1.1 --- a/xen/arch/i386/boot/boot.S	Wed Aug 27 21:24:41 2003 +0000
     1.2 +++ b/xen/arch/i386/boot/boot.S	Thu Aug 28 13:23:40 2003 +0000
     1.3 @@ -1,4 +1,5 @@
     1.4  #include <xeno/config.h>
     1.5 +#include <hypervisor-ifs/hypervisor-if.h>
     1.6  #include <asm/page.h>
     1.7  
     1.8  #define  SECONDARY_CPU_FLAG 0xA5A5A5A5
     1.9 @@ -229,26 +230,27 @@ SYMBOL_NAME(idt):
    1.10  
    1.11          .word   0
    1.12  gdt_descr:
    1.13 -	.word	(2*NR_CPUS+8)*8-1
    1.14 +	.word	(LAST_RESERVED_GDT_ENTRY*8)+7
    1.15  SYMBOL_NAME(gdt):       
    1.16          .long   SYMBOL_NAME(gdt_table)	/* gdt base */
    1.17  
    1.18          .word   0
    1.19  nopaging_gdt_descr:
    1.20 -        .word   (2*NR_CPUS+8)*8-1
    1.21 +        .word   (LAST_RESERVED_GDT_ENTRY*8)+7
    1.22          .long   SYMBOL_NAME(gdt_table)-__PAGE_OFFSET
    1.23          
    1.24          ALIGN
    1.25  /* NB. Rings != 0 get access up to 0xFC400000. This allows access to the */
    1.26  /*     machine->physical mapping table. Ring 0 can access all memory.    */
    1.27  ENTRY(gdt_table)
    1.28 -        .quad 0x0000000000000000     /* 0x0000 NULL descriptor */
    1.29 -        .quad 0x00cf9a000000ffff     /* 0x0008 ring 0 4.00GB code at 0x0 */
    1.30 -        .quad 0x00cf92000000ffff     /* 0x0010 ring 0 4.00GB data at 0x0 */
    1.31 -        .quad 0x00cfba000000c3ff     /* 0x0019 ring 1 3.95GB code at 0x0 */
    1.32 -        .quad 0x00cfb2000000c3ff     /* 0x0021 ring 1 3.95GB data at 0x0 */
    1.33 -        .quad 0x00cffa000000c3ff     /* 0x002b ring 3 3.95GB code at 0x0 */
    1.34 -        .quad 0x00cff2000000c3ff     /* 0x0033 ring 3 3.95GB data at 0x0 */
    1.35 +        .fill FIRST_RESERVED_GDT_ENTRY,8,0
    1.36 +        .quad 0x0000000000000000     /* unused */
    1.37 +        .quad 0x00cf9a000000ffff     /* 0x0808 ring 0 4.00GB code at 0x0 */
    1.38 +        .quad 0x00cf92000000ffff     /* 0x0810 ring 0 4.00GB data at 0x0 */
    1.39 +        .quad 0x00cfba000000c3ff     /* 0x0819 ring 1 3.95GB code at 0x0 */
    1.40 +        .quad 0x00cfb2000000c3ff     /* 0x0821 ring 1 3.95GB data at 0x0 */
    1.41 +        .quad 0x00cffa000000c3ff     /* 0x082b ring 3 3.95GB code at 0x0 */
    1.42 +        .quad 0x00cff2000000c3ff     /* 0x0833 ring 3 3.95GB data at 0x0 */
    1.43          .quad 0x0000000000000000     /* unused                           */
    1.44          .fill 2*NR_CPUS,8,0          /* space for TSS and LDT per CPU    */
    1.45  
     2.1 --- a/xen/arch/i386/mm.c	Wed Aug 27 21:24:41 2003 +0000
     2.2 +++ b/xen/arch/i386/mm.c	Thu Aug 28 13:23:40 2003 +0000
     2.3 @@ -188,7 +188,7 @@ long do_set_gdt(unsigned long *frame_lis
     2.4      long ret = -EINVAL;
     2.5      struct pfn_info *page;
     2.6  
     2.7 -    if ( (entries < FIRST_DOMAIN_GDT_ENTRY) || (entries > 8192) ) 
     2.8 +    if ( (entries <= LAST_RESERVED_GDT_ENTRY) || (entries > 8192) ) 
     2.9          return -EINVAL;
    2.10  
    2.11      if ( copy_from_user(frames, frame_list, nr_pages * sizeof(unsigned long)) )
    2.12 @@ -249,8 +249,10 @@ long do_set_gdt(unsigned long *frame_lis
    2.13  
    2.14      local_flush_tlb();
    2.15  
    2.16 -    /* Copy over first entries of the new GDT. */
    2.17 -    memcpy((void *)GDT_VIRT_START, gdt_table, FIRST_DOMAIN_GDT_ENTRY*8);
    2.18 +    /* Copy reserved GDT entries to the new GDT. */
    2.19 +    memcpy((struct desc_struct *)GDT_VIRT_START + FIRST_RESERVED_GDT_ENTRY, 
    2.20 +           gdt_table + FIRST_RESERVED_GDT_ENTRY, 
    2.21 +           NR_RESERVED_GDT_ENTRIES*8);
    2.22      
    2.23      SET_GDT_ADDRESS(current, GDT_VIRT_START);
    2.24      SET_GDT_ENTRIES(current, (entries*8)-1);
    2.25 @@ -284,9 +286,10 @@ long do_update_descriptor(
    2.26      switch ( (page->flags & PG_type_mask) )
    2.27      {
    2.28      case PGT_gdt_page:
    2.29 -        /* Disallow updates of Xen-private descriptors in the current GDT. */
    2.30 +        /* Disallow updates of Xen-reserved descriptors in the current GDT. */
    2.31          if ( (l1_pgentry_to_pagenr(current->mm.perdomain_pt[0]) == pfn) &&
    2.32 -             (((pa&(PAGE_SIZE-1))>>3) < FIRST_DOMAIN_GDT_ENTRY) )
    2.33 +             (((pa&(PAGE_SIZE-1))>>3) >= FIRST_RESERVED_GDT_ENTRY) &&
    2.34 +             (((pa&(PAGE_SIZE-1))>>3) <= LAST_RESERVED_GDT_ENTRY) )
    2.35              goto out;
    2.36      case PGT_ldt_page:
    2.37      case PGT_writeable_page:
     3.1 --- a/xen/arch/i386/trampoline.S	Wed Aug 27 21:24:41 2003 +0000
     3.2 +++ b/xen/arch/i386/trampoline.S	Thu Aug 28 13:23:40 2003 +0000
     3.3 @@ -16,6 +16,7 @@
     3.4   */
     3.5  
     3.6  #include <xeno/config.h>
     3.7 +#include <hypervisor-ifs/hypervisor-if.h>
     3.8  #include <asm/page.h>
     3.9  
    3.10  #ifdef CONFIG_SMP
    3.11 @@ -49,8 +50,8 @@ idt_48:
    3.12  	.word	0, 0			# idt base = 0L
    3.13  
    3.14  gdt_48:
    3.15 -	.word	0x0800			# gdt limit = 2048, 256 GDT entries
    3.16 -	.long	gdt_table-__PAGE_OFFSET	# gdt base = gdt (first SMP CPU)
    3.17 +	.word	(LAST_RESERVED_GDT_ENTRY*8)+7
    3.18 +	.long	gdt_table-__PAGE_OFFSET
    3.19  
    3.20  .globl SYMBOL_NAME(trampoline_end)
    3.21  SYMBOL_NAME_LABEL(trampoline_end)
     4.1 --- a/xen/include/asm-i386/desc.h	Wed Aug 27 21:24:41 2003 +0000
     4.2 +++ b/xen/include/asm-i386/desc.h	Thu Aug 28 13:23:40 2003 +0000
     4.3 @@ -3,8 +3,8 @@
     4.4  
     4.5  #define LDT_ENTRY_SIZE 8
     4.6  
     4.7 -#define __FIRST_TSS_ENTRY 8
     4.8 -#define __FIRST_LDT_ENTRY (__FIRST_TSS_ENTRY+1)
     4.9 +#define __FIRST_TSS_ENTRY (FIRST_RESERVED_GDT_ENTRY + 8)
    4.10 +#define __FIRST_LDT_ENTRY (__FIRST_TSS_ENTRY + 1)
    4.11  
    4.12  #define __TSS(n) (((n)<<1) + __FIRST_TSS_ENTRY)
    4.13  #define __LDT(n) (((n)<<1) + __FIRST_LDT_ENTRY)
    4.14 @@ -14,14 +14,18 @@
    4.15  /*
    4.16   * Guest OS must provide its own code selectors, or use the one we provide.
    4.17   * The RPL must be 1, as we only create bounce frames to ring 1.
    4.18 + * Any LDT selector value is okay.
    4.19   */
    4.20 -#define VALID_CODESEL(_s)                                                  \
    4.21 -    (((((_s)>>2) >= FIRST_DOMAIN_GDT_ENTRY) || ((_s) == FLAT_RING1_CS)) && \
    4.22 +
    4.23 +#define VALID_SEL(_s)                                                      \
    4.24 +    (((((_s)>>3) < FIRST_RESERVED_GDT_ENTRY) ||                            \
    4.25 +      (((_s)>>3) >  LAST_RESERVED_GDT_ENTRY) ||                            \
    4.26 +      ((_s)&4)) &&                                                         \
    4.27       (((_s)&3) == 1))
    4.28  
    4.29 -#define VALID_DATASEL(_s)                                                  \
    4.30 -    (((((_s)>>2) >= FIRST_DOMAIN_GDT_ENTRY) || ((_s) == FLAT_RING1_DS)) && \
    4.31 -     (((_s)&3) == 1))
    4.32 +#define VALID_CODESEL(_s) ((_s) == FLAT_RING1_CS || VALID_SEL(_s))
    4.33 +
    4.34 +#define VALID_DATASEL(_s) ((_s) == FLAT_RING1_DS || VALID_SEL(_s))
    4.35  
    4.36  /* These are bitmasks for the first 32 bits of a descriptor table entry. */
    4.37  #define _SEGMENT_TYPE    (15<< 8)
     5.1 --- a/xen/include/hypervisor-ifs/hypervisor-if.h	Wed Aug 27 21:24:41 2003 +0000
     5.2 +++ b/xen/include/hypervisor-ifs/hypervisor-if.h	Thu Aug 28 13:23:40 2003 +0000
     5.3 @@ -10,17 +10,29 @@
     5.4  /*
     5.5   * SEGMENT DESCRIPTOR TABLES
     5.6   */
     5.7 -/* The first few GDT entries are reserved by Xen. */
     5.8 -#define FIRST_DOMAIN_GDT_ENTRY	40
     5.9  /*
    5.10 - * These flat segments are in the Xen-private section of every GDT. Since 
    5.11 - * these are also present in the initial GDT, many OSes will be able to avoid 
    5.12 + * A number of GDT entries are reserved by Xen. These are not situated at the
    5.13 + * start of the GDT because some stupid OSes export hard-coded selector values
    5.14 + * in their ABI. These hard-coded values are always near the start of the GDT,
    5.15 + * so Xen places itself out of the way.
    5.16 + * 
    5.17 + * NB. The reserved range is inclusive (that is, both FIRST_RESERVED_GDT_ENTRY
    5.18 + * and LAST_RESERVED_GDT_ENTRY are reserved).
    5.19 + */
    5.20 +#define NR_RESERVED_GDT_ENTRIES         40
    5.21 +#define FIRST_RESERVED_GDT_ENTRY	256
    5.22 +#define LAST_RESERVED_GDT_ENTRY         \
    5.23 +  (FIRST_RESERVED_GDT_ENTRY + NR_RESERVED_GDT_ENTRIES - 1)
    5.24 +
    5.25 +/*
    5.26 + * These flat segments are in the Xen-private section of every GDT. Since these
    5.27 + * are also present in the initial GDT, many OSes will be able to avoid
    5.28   * installing their own GDT.
    5.29   */
    5.30 -#define FLAT_RING1_CS		0x0019
    5.31 -#define FLAT_RING1_DS		0x0021
    5.32 -#define FLAT_RING3_CS		0x002b
    5.33 -#define FLAT_RING3_DS		0x0033
    5.34 +#define FLAT_RING1_CS		0x0819
    5.35 +#define FLAT_RING1_DS		0x0821
    5.36 +#define FLAT_RING3_CS		0x082b
    5.37 +#define FLAT_RING3_DS		0x0833
    5.38  
    5.39  
    5.40  /*
     6.1 --- a/xen/include/xeno/config.h	Wed Aug 27 21:24:41 2003 +0000
     6.2 +++ b/xen/include/xeno/config.h	Thu Aug 28 13:23:40 2003 +0000
     6.3 @@ -127,8 +127,8 @@
     6.4  
     6.5  #define barrier() __asm__ __volatile__("": : :"memory")
     6.6  
     6.7 -#define __HYPERVISOR_CS 0x0008
     6.8 -#define __HYPERVISOR_DS 0x0010
     6.9 +#define __HYPERVISOR_CS 0x0808
    6.10 +#define __HYPERVISOR_DS 0x0810
    6.11  
    6.12  #define NR_syscalls 256
    6.13  
     7.1 --- a/xen/include/xeno/mm.h	Wed Aug 27 21:24:41 2003 +0000
     7.2 +++ b/xen/include/xeno/mm.h	Thu Aug 28 13:23:40 2003 +0000
     7.3 @@ -149,7 +149,7 @@ int check_descriptor(unsigned long a, un
     7.4  /* Part of the domain API. */
     7.5  int do_process_page_updates(page_update_request_t *updates, int count);
     7.6  
     7.7 -#define DEFAULT_GDT_ENTRIES     ((FIRST_DOMAIN_GDT_ENTRY*8)-1)
     7.8 +#define DEFAULT_GDT_ENTRIES     ((LAST_RESERVED_GDT_ENTRY*8)+7)
     7.9  #define DEFAULT_GDT_ADDRESS     ((unsigned long)gdt_table)
    7.10  
    7.11  #endif /* __XENO_MM_H__ */