ia64/xen-unstable

changeset 4572:147d96171c0e

bitkeeper revision 1.1326 (42650a788JSw9ebwfL7C9aWTza0ZlA)

Address space reorganization.

Intention is to have largely the same memory layout
in both PAE and non-PAE mode, so I moved the
fixed-size stuff to the top, followed by the
variable-sized stuff (frametable and linear page
tables), and the domain-accessable machine-phys-table
at the bottom.

Signed-off-by: Gerd Knorr <kraxel@bytesex.org>
Signed-off-by: Keir Fraser <keir@xensource.com>
author kaf24@firebug.cl.cam.ac.uk
date Tue Apr 19 13:41:12 2005 +0000 (2005-04-19)
parents e90dde144eb9
children dfe18db08708
files xen/arch/x86/mm.c xen/arch/x86/traps.c xen/arch/x86/x86_32/mm.c xen/arch/x86/x86_32/seg_fixup.c xen/arch/x86/x86_32/xen.lds xen/include/asm-x86/config.h xen/include/asm-x86/x86_32/page.h
line diff
     1.1 --- a/xen/arch/x86/mm.c	Tue Apr 19 12:09:05 2005 +0000
     1.2 +++ b/xen/arch/x86/mm.c	Tue Apr 19 13:41:12 2005 +0000
     1.3 @@ -1634,7 +1634,6 @@ int do_mmuext_op(
     1.4          {
     1.5              if ( shadow_mode_external(d) )
     1.6              {
     1.7 -                // ignore this request from an external domain...
     1.8                  MEM_LOG("ignoring SET_LDT hypercall from external "
     1.9                          "domain %u\n", d->id);
    1.10                  okay = 0;
    1.11 @@ -1645,8 +1644,7 @@ int do_mmuext_op(
    1.12              unsigned long ents = op.nr_ents;
    1.13              if ( ((ptr & (PAGE_SIZE-1)) != 0) || 
    1.14                   (ents > 8192) ||
    1.15 -                 ((ptr+ents*LDT_ENTRY_SIZE) < ptr) ||
    1.16 -                 ((ptr+ents*LDT_ENTRY_SIZE) > PAGE_OFFSET) )
    1.17 +                 !array_access_ok(VERIFY_READ, ptr, ents, LDT_ENTRY_SIZE) )
    1.18              {
    1.19                  okay = 0;
    1.20                  MEM_LOG("Bad args to SET_LDT: ptr=%p, ents=%p", ptr, ents);
     2.1 --- a/xen/arch/x86/traps.c	Tue Apr 19 12:09:05 2005 +0000
     2.2 +++ b/xen/arch/x86/traps.c	Tue Apr 19 13:41:12 2005 +0000
     2.3 @@ -268,8 +268,6 @@ asmlinkage int do_page_fault(struct xen_
     2.4  
     2.5      DEBUGGER_trap_entry(TRAP_page_fault, regs);
     2.6  
     2.7 -    //printk("do_page_fault(eip=%p, va=%p, code=%d)\n", regs->eip, addr, regs->error_code);
     2.8 -
     2.9      perfc_incrc(page_faults);
    2.10  
    2.11      if ( likely(VM_ASSIST(d, VMASST_TYPE_writable_pagetables)) )
    2.12 @@ -284,7 +282,7 @@ asmlinkage int do_page_fault(struct xen_
    2.13              return EXCRET_fault_fixed;
    2.14          }
    2.15  
    2.16 -        if ( (addr < PAGE_OFFSET) &&
    2.17 +        if ( (addr < HYPERVISOR_VIRT_START) &&
    2.18               ((regs->error_code & 3) == 3) && /* write-protection fault */
    2.19               ptwr_do_page_fault(d, addr) )
    2.20          {
    2.21 @@ -1100,13 +1098,6 @@ long do_set_trap_table(trap_info_t *trap
    2.22  }
    2.23  
    2.24  
    2.25 -#if defined(__i386__)
    2.26 -#define DB_VALID_ADDR(_a) \
    2.27 -    ((_a) <= (PAGE_OFFSET - 4))
    2.28 -#elif defined(__x86_64__)
    2.29 -#define DB_VALID_ADDR(_a) \
    2.30 -    ((_a) >= HYPERVISOR_VIRT_END) || ((_a) <= (HYPERVISOR_VIRT_START-8))
    2.31 -#endif
    2.32  long set_debugreg(struct exec_domain *p, int reg, unsigned long value)
    2.33  {
    2.34      int i;
    2.35 @@ -1114,22 +1105,26 @@ long set_debugreg(struct exec_domain *p,
    2.36      switch ( reg )
    2.37      {
    2.38      case 0: 
    2.39 -        if ( !DB_VALID_ADDR(value) ) return -EPERM;
    2.40 +        if ( !access_ok(VERIFY_READ, value, sizeof(long)) )
    2.41 +            return -EPERM;
    2.42          if ( p == current ) 
    2.43              __asm__ ( "mov %0, %%db0" : : "r" (value) );
    2.44          break;
    2.45      case 1: 
    2.46 -        if ( !DB_VALID_ADDR(value) ) return -EPERM;
    2.47 +        if ( !access_ok(VERIFY_READ, value, sizeof(long)) )
    2.48 +            return -EPERM;
    2.49          if ( p == current ) 
    2.50              __asm__ ( "mov %0, %%db1" : : "r" (value) );
    2.51          break;
    2.52      case 2: 
    2.53 -        if ( !DB_VALID_ADDR(value) ) return -EPERM;
    2.54 +        if ( !access_ok(VERIFY_READ, value, sizeof(long)) )
    2.55 +            return -EPERM;
    2.56          if ( p == current ) 
    2.57              __asm__ ( "mov %0, %%db2" : : "r" (value) );
    2.58          break;
    2.59      case 3:
    2.60 -        if ( !DB_VALID_ADDR(value) ) return -EPERM;
    2.61 +        if ( !access_ok(VERIFY_READ, value, sizeof(long)) )
    2.62 +            return -EPERM;
    2.63          if ( p == current ) 
    2.64              __asm__ ( "mov %0, %%db3" : : "r" (value) );
    2.65          break;
     3.1 --- a/xen/arch/x86/x86_32/mm.c	Tue Apr 19 12:09:05 2005 +0000
     3.2 +++ b/xen/arch/x86/x86_32/mm.c	Tue Apr 19 13:41:12 2005 +0000
     3.3 @@ -249,7 +249,7 @@ int check_descriptor(struct desc_struct 
     3.4      
     3.5      /* Check that base is at least a page away from Xen-private area. */
     3.6      base  = (b&(0xff<<24)) | ((b&0xff)<<16) | (a>>16);
     3.7 -    if ( base >= (PAGE_OFFSET - PAGE_SIZE) )
     3.8 +    if ( base >= (GUEST_SEGMENT_MAX_ADDR - PAGE_SIZE) )
     3.9          goto bad;
    3.10  
    3.11      /* Check and truncate the limit if necessary. */
    3.12 @@ -282,9 +282,9 @@ int check_descriptor(struct desc_struct 
    3.13           *     limit == 0x00000 provides 4kB access (if G=1).
    3.14           */
    3.15          if ( ((base + limit) <= base) || 
    3.16 -             ((base + limit) > PAGE_OFFSET) )
    3.17 +             ((base + limit) > GUEST_SEGMENT_MAX_ADDR) )
    3.18          {
    3.19 -            limit = PAGE_OFFSET - base;
    3.20 +            limit = GUEST_SEGMENT_MAX_ADDR - base;
    3.21          truncate:
    3.22              if ( !(b & _SEGMENT_G) )
    3.23                  goto bad; /* too dangerous; too hard to work out... */
     4.1 --- a/xen/arch/x86/x86_32/seg_fixup.c	Tue Apr 19 12:09:05 2005 +0000
     4.2 +++ b/xen/arch/x86/x86_32/seg_fixup.c	Tue Apr 19 13:41:12 2005 +0000
     4.3 @@ -145,7 +145,7 @@ int get_baselimit(u16 seg, unsigned long
     4.4       * Anything that looks like a truncated segment we assume ought really
     4.5       * to be a 4GB segment. DANGER!
     4.6       */
     4.7 -    if ( (PAGE_OFFSET - (*base + *limit)) < PAGE_SIZE )
     4.8 +    if ( (GUEST_SEGMENT_MAX_ADDR - (*base + *limit)) < PAGE_SIZE )
     4.9          *limit = 0;
    4.10  
    4.11      return 1;
    4.12 @@ -226,14 +226,14 @@ int fixup_seg(u16 seg, unsigned long off
    4.13          if ( ((base + limit) < PAGE_SIZE) && (offset <= limit)  )
    4.14          {
    4.15              /* Flip to expands-up. */
    4.16 -            limit = PAGE_OFFSET - base;
    4.17 +            limit = GUEST_SEGMENT_MAX_ADDR - base;
    4.18              goto flip;
    4.19          }
    4.20      }
    4.21      else
    4.22      {
    4.23          /* Expands-up: All the way to Xen space? Assume 4GB if so. */
    4.24 -        if ( ((PAGE_OFFSET - (base + limit)) < PAGE_SIZE) &&
    4.25 +        if ( ((GUEST_SEGMENT_MAX_ADDR - (base + limit)) < PAGE_SIZE) &&
    4.26               (offset > limit) )
    4.27          {
    4.28              /* Flip to expands-down. */
     5.1 --- a/xen/arch/x86/x86_32/xen.lds	Tue Apr 19 12:09:05 2005 +0000
     5.2 +++ b/xen/arch/x86/x86_32/xen.lds	Tue Apr 19 13:41:12 2005 +0000
     5.3 @@ -11,7 +11,7 @@ PHDRS
     5.4  }
     5.5  SECTIONS
     5.6  {
     5.7 -  . = 0xFC400000 + 0x100000;
     5.8 +  . = 0xFF000000 + 0x100000;
     5.9    _text = .;			/* Text and read-only data */
    5.10    .text : {
    5.11  	*(.text)
     6.1 --- a/xen/include/asm-x86/config.h	Tue Apr 19 12:09:05 2005 +0000
     6.2 +++ b/xen/include/asm-x86/config.h	Tue Apr 19 13:41:12 2005 +0000
     6.3 @@ -216,12 +216,71 @@ extern void __out_of_line_bug(int line) 
     6.4  
     6.5  #define asmlinkage __attribute__((regparm(0)))
     6.6  
     6.7 -#define XENHEAP_DEFAULT_MB (12)
     6.8 -#define DIRECTMAP_PHYS_END (12*1024*1024)
     6.9 +/*
    6.10 + * Memory layout (high to low):                          SIZE   PAE-SIZE
    6.11 + *                                                       ------ ------
    6.12 + *  I/O remapping area                                   ( 4MB)
    6.13 + *  Direct-map (1:1) area [Xen code/data/heap]           (12MB)
    6.14 + *  map_domain_mem cache                                 ( 4MB)
    6.15 + *  Per-domain mappings                                  ( 4MB)
    6.16 + *  Shadow linear pagetable                              ( 4MB) ( 8MB)
    6.17 + *  Guest linear pagetable                               ( 4MB) ( 8MB)
    6.18 + *  Machine-to-physical translation table [writable]     ( 4MB)
    6.19 + *  Frame-info table                                     (24MB) (96MB)
    6.20 + *   * Start of guest inaccessible area
    6.21 + *  Machine-to-physical translation table [read-only]    ( 4MB)
    6.22 + *   * Start of guest unmodifiable area
    6.23 + */
    6.24 +
    6.25 +#define IOREMAP_MBYTES           4
    6.26 +#define DIRECTMAP_MBYTES        12
    6.27 +#define MAPCACHE_MBYTES          4
    6.28 +#define PERDOMAIN_MBYTES         4
    6.29 +
    6.30 +#ifdef CONFIG_X86_PAE
    6.31 +# define LINEARPT_MBYTES         8
    6.32 +# define MACHPHYS_MBYTES         4 /* KAF: This needs to be bigger */
    6.33 +# define FRAMETABLE_MBYTES	96 /* 16 GB mem limit (total)      */
    6.34 +#else
    6.35 +# define LINEARPT_MBYTES         4
    6.36 +# define MACHPHYS_MBYTES         4
    6.37 +# define FRAMETABLE_MBYTES      24
    6.38 +#endif
    6.39  
    6.40 +#define IOREMAP_VIRT_END	0UL
    6.41 +#define IOREMAP_VIRT_START	(IOREMAP_VIRT_END - (IOREMAP_MBYTES<<20))
    6.42 +#define DIRECTMAP_VIRT_END	IOREMAP_VIRT_START
    6.43 +#define DIRECTMAP_VIRT_START	(DIRECTMAP_VIRT_END - (DIRECTMAP_MBYTES<<20))
    6.44 +#define MAPCACHE_VIRT_END	DIRECTMAP_VIRT_START
    6.45 +#define MAPCACHE_VIRT_START	(MAPCACHE_VIRT_END - (MAPCACHE_MBYTES<<20))
    6.46 +#define PERDOMAIN_VIRT_END	MAPCACHE_VIRT_START
    6.47 +#define PERDOMAIN_VIRT_START	(PERDOMAIN_VIRT_END - (PERDOMAIN_MBYTES<<20))
    6.48 +#define SH_LINEAR_PT_VIRT_END	PERDOMAIN_VIRT_START
    6.49 +#define SH_LINEAR_PT_VIRT_START	(SH_LINEAR_PT_VIRT_END - (LINEARPT_MBYTES<<20))
    6.50 +#define LINEAR_PT_VIRT_END	SH_LINEAR_PT_VIRT_START
    6.51 +#define LINEAR_PT_VIRT_START	(LINEAR_PT_VIRT_END - (LINEARPT_MBYTES<<20))
    6.52 +#define RDWR_MPT_VIRT_END	LINEAR_PT_VIRT_START
    6.53 +#define RDWR_MPT_VIRT_START	(RDWR_MPT_VIRT_END - (MACHPHYS_MBYTES<<20))
    6.54 +#define FRAMETABLE_VIRT_END	RDWR_MPT_VIRT_START
    6.55 +#define FRAMETABLE_VIRT_START	(FRAMETABLE_VIRT_END - (FRAMETABLE_MBYTES<<20))
    6.56 +#define RO_MPT_VIRT_END		FRAMETABLE_VIRT_START
    6.57 +#define RO_MPT_VIRT_START	(RO_MPT_VIRT_END - (MACHPHYS_MBYTES<<20))
    6.58 +
    6.59 +#define XENHEAP_DEFAULT_MB	(DIRECTMAP_MBYTES)
    6.60 +#define DIRECTMAP_PHYS_END	(DIRECTMAP_MBYTES<<20)
    6.61 +
    6.62 +/* Maximum linear address accessible via guest memory segments. */
    6.63 +#define GUEST_SEGMENT_MAX_ADDR  RO_MPT_VIRT_END
    6.64 +
    6.65 +#ifdef CONFIG_X86_PAE
    6.66 +/* Hypervisor owns top 144MB of virtual address space. */
    6.67 +# define __HYPERVISOR_VIRT_START  0xF7000000
    6.68 +# define HYPERVISOR_VIRT_START   (0xF7000000UL)
    6.69 +#else
    6.70  /* Hypervisor owns top 64MB of virtual address space. */
    6.71 -#define __HYPERVISOR_VIRT_START  0xFC000000
    6.72 -#define HYPERVISOR_VIRT_START   (0xFC000000UL)
    6.73 +# define __HYPERVISOR_VIRT_START  0xFC000000
    6.74 +# define HYPERVISOR_VIRT_START   (0xFC000000UL)
    6.75 +#endif
    6.76  
    6.77  #define ROOT_PAGETABLE_FIRST_XEN_SLOT \
    6.78      (HYPERVISOR_VIRT_START >> L2_PAGETABLE_SHIFT)
    6.79 @@ -230,37 +289,6 @@ extern void __out_of_line_bug(int line) 
    6.80  #define ROOT_PAGETABLE_XEN_SLOTS \
    6.81      (ROOT_PAGETABLE_LAST_XEN_SLOT - ROOT_PAGETABLE_FIRST_XEN_SLOT + 1)
    6.82  
    6.83 -/*
    6.84 - * First 4MB are mapped read-only for all. It's for the machine->physical
    6.85 - * mapping table (MPT table). The following are virtual addresses.
    6.86 - */
    6.87 -#define RO_MPT_VIRT_START     (HYPERVISOR_VIRT_START)
    6.88 -#define RO_MPT_VIRT_END       (RO_MPT_VIRT_START + (4*1024*1024))
    6.89 -/* Xen heap extends to end of 1:1 direct-mapped memory region. */
    6.90 -#define DIRECTMAP_VIRT_START  (RO_MPT_VIRT_END)
    6.91 -#define DIRECTMAP_VIRT_END    (DIRECTMAP_VIRT_START + DIRECTMAP_PHYS_END)
    6.92 -/* Machine-to-phys conversion table. */
    6.93 -#define RDWR_MPT_VIRT_START   (DIRECTMAP_VIRT_END)
    6.94 -#define RDWR_MPT_VIRT_END     (RDWR_MPT_VIRT_START + (4*1024*1024))
    6.95 -/* Variable-length page-frame information array. */
    6.96 -#define FRAMETABLE_VIRT_START (RDWR_MPT_VIRT_END)
    6.97 -#define FRAMETABLE_VIRT_END   (FRAMETABLE_VIRT_START + (24*1024*1024))
    6.98 -/* Next 4MB of virtual address space is used as a linear p.t. mapping. */
    6.99 -#define LINEAR_PT_VIRT_START  (FRAMETABLE_VIRT_END)
   6.100 -#define LINEAR_PT_VIRT_END    (LINEAR_PT_VIRT_START + (4*1024*1024))
   6.101 -/* Next 4MB of virtual address space is used as a shadow linear p.t. map. */
   6.102 -#define SH_LINEAR_PT_VIRT_START (LINEAR_PT_VIRT_END)
   6.103 -#define SH_LINEAR_PT_VIRT_END (SH_LINEAR_PT_VIRT_START + (4*1024*1024))
   6.104 -/* Next 4MB of virtual address space used for per-domain mappings (eg. GDT). */
   6.105 -#define PERDOMAIN_VIRT_START  (SH_LINEAR_PT_VIRT_END)
   6.106 -#define PERDOMAIN_VIRT_END    (PERDOMAIN_VIRT_START + (4*1024*1024))
   6.107 -/* Penultimate 4MB of virtual address space used for domain page mappings. */
   6.108 -#define MAPCACHE_VIRT_START   (PERDOMAIN_VIRT_END)
   6.109 -#define MAPCACHE_VIRT_END     (MAPCACHE_VIRT_START + (4*1024*1024))
   6.110 -/* Final 4MB of virtual address space used for ioremap(). */
   6.111 -#define IOREMAP_VIRT_START    (MAPCACHE_VIRT_END)
   6.112 -#define IOREMAP_VIRT_END      (IOREMAP_VIRT_START + (4*1024*1024))
   6.113 -
   6.114  #define PGT_base_page_table PGT_l2_page_table
   6.115  
   6.116  #define __HYPERVISOR_CS 0x0808
     7.1 --- a/xen/include/asm-x86/x86_32/page.h	Tue Apr 19 12:09:05 2005 +0000
     7.2 +++ b/xen/include/asm-x86/x86_32/page.h	Tue Apr 19 13:41:12 2005 +0000
     7.3 @@ -12,7 +12,7 @@
     7.4  #define L2_PAGETABLE_ENTRIES    (1<<PAGETABLE_ORDER)
     7.5  #define ROOT_PAGETABLE_ENTRIES  L2_PAGETABLE_ENTRIES
     7.6  
     7.7 -#define __PAGE_OFFSET           (0xFC400000)
     7.8 +#define __PAGE_OFFSET           (0xFF000000)
     7.9  
    7.10  #define PADDR_BITS              32
    7.11  #define VADDR_BITS              32