[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] Address space reorganization.



ChangeSet 1.1326, 2005/04/19 14:41:12+01:00, kaf24@xxxxxxxxxxxxxxxxxxxx

        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@xxxxxxxxxxx>
        Signed-off-by: Keir Fraser <keir@xxxxxxxxxxxxx>



 arch/x86/mm.c                 |    4 -
 arch/x86/traps.c              |   23 +++------
 arch/x86/x86_32/mm.c          |    6 +-
 arch/x86/x86_32/seg_fixup.c   |    6 +-
 arch/x86/x86_32/xen.lds       |    2 
 include/asm-x86/config.h      |   98 +++++++++++++++++++++++++++---------------
 include/asm-x86/x86_32/page.h |    2 
 7 files changed, 81 insertions(+), 60 deletions(-)


diff -Nru a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c
--- a/xen/arch/x86/mm.c 2005-04-19 10:03:56 -04:00
+++ b/xen/arch/x86/mm.c 2005-04-19 10:03:56 -04:00
@@ -1634,7 +1634,6 @@
         {
             if ( shadow_mode_external(d) )
             {
-                // ignore this request from an external domain...
                 MEM_LOG("ignoring SET_LDT hypercall from external "
                         "domain %u\n", d->id);
                 okay = 0;
@@ -1645,8 +1644,7 @@
             unsigned long ents = op.nr_ents;
             if ( ((ptr & (PAGE_SIZE-1)) != 0) || 
                  (ents > 8192) ||
-                 ((ptr+ents*LDT_ENTRY_SIZE) < ptr) ||
-                 ((ptr+ents*LDT_ENTRY_SIZE) > PAGE_OFFSET) )
+                 !array_access_ok(VERIFY_READ, ptr, ents, LDT_ENTRY_SIZE) )
             {
                 okay = 0;
                 MEM_LOG("Bad args to SET_LDT: ptr=%p, ents=%p", ptr, ents);
diff -Nru a/xen/arch/x86/traps.c b/xen/arch/x86/traps.c
--- a/xen/arch/x86/traps.c      2005-04-19 10:03:56 -04:00
+++ b/xen/arch/x86/traps.c      2005-04-19 10:03:56 -04:00
@@ -268,8 +268,6 @@
 
     DEBUGGER_trap_entry(TRAP_page_fault, regs);
 
-    //printk("do_page_fault(eip=%p, va=%p, code=%d)\n", regs->eip, addr, 
regs->error_code);
-
     perfc_incrc(page_faults);
 
     if ( likely(VM_ASSIST(d, VMASST_TYPE_writable_pagetables)) )
@@ -284,7 +282,7 @@
             return EXCRET_fault_fixed;
         }
 
-        if ( (addr < PAGE_OFFSET) &&
+        if ( (addr < HYPERVISOR_VIRT_START) &&
              ((regs->error_code & 3) == 3) && /* write-protection fault */
              ptwr_do_page_fault(d, addr) )
         {
@@ -1100,13 +1098,6 @@
 }
 
 
-#if defined(__i386__)
-#define DB_VALID_ADDR(_a) \
-    ((_a) <= (PAGE_OFFSET - 4))
-#elif defined(__x86_64__)
-#define DB_VALID_ADDR(_a) \
-    ((_a) >= HYPERVISOR_VIRT_END) || ((_a) <= (HYPERVISOR_VIRT_START-8))
-#endif
 long set_debugreg(struct exec_domain *p, int reg, unsigned long value)
 {
     int i;
@@ -1114,22 +1105,26 @@
     switch ( reg )
     {
     case 0: 
-        if ( !DB_VALID_ADDR(value) ) return -EPERM;
+        if ( !access_ok(VERIFY_READ, value, sizeof(long)) )
+            return -EPERM;
         if ( p == current ) 
             __asm__ ( "mov %0, %%db0" : : "r" (value) );
         break;
     case 1: 
-        if ( !DB_VALID_ADDR(value) ) return -EPERM;
+        if ( !access_ok(VERIFY_READ, value, sizeof(long)) )
+            return -EPERM;
         if ( p == current ) 
             __asm__ ( "mov %0, %%db1" : : "r" (value) );
         break;
     case 2: 
-        if ( !DB_VALID_ADDR(value) ) return -EPERM;
+        if ( !access_ok(VERIFY_READ, value, sizeof(long)) )
+            return -EPERM;
         if ( p == current ) 
             __asm__ ( "mov %0, %%db2" : : "r" (value) );
         break;
     case 3:
-        if ( !DB_VALID_ADDR(value) ) return -EPERM;
+        if ( !access_ok(VERIFY_READ, value, sizeof(long)) )
+            return -EPERM;
         if ( p == current ) 
             __asm__ ( "mov %0, %%db3" : : "r" (value) );
         break;
diff -Nru a/xen/arch/x86/x86_32/mm.c b/xen/arch/x86/x86_32/mm.c
--- a/xen/arch/x86/x86_32/mm.c  2005-04-19 10:03:56 -04:00
+++ b/xen/arch/x86/x86_32/mm.c  2005-04-19 10:03:56 -04:00
@@ -249,7 +249,7 @@
     
     /* Check that base is at least a page away from Xen-private area. */
     base  = (b&(0xff<<24)) | ((b&0xff)<<16) | (a>>16);
-    if ( base >= (PAGE_OFFSET - PAGE_SIZE) )
+    if ( base >= (GUEST_SEGMENT_MAX_ADDR - PAGE_SIZE) )
         goto bad;
 
     /* Check and truncate the limit if necessary. */
@@ -282,9 +282,9 @@
          *     limit == 0x00000 provides 4kB access (if G=1).
          */
         if ( ((base + limit) <= base) || 
-             ((base + limit) > PAGE_OFFSET) )
+             ((base + limit) > GUEST_SEGMENT_MAX_ADDR) )
         {
-            limit = PAGE_OFFSET - base;
+            limit = GUEST_SEGMENT_MAX_ADDR - base;
         truncate:
             if ( !(b & _SEGMENT_G) )
                 goto bad; /* too dangerous; too hard to work out... */
diff -Nru a/xen/arch/x86/x86_32/seg_fixup.c b/xen/arch/x86/x86_32/seg_fixup.c
--- a/xen/arch/x86/x86_32/seg_fixup.c   2005-04-19 10:03:56 -04:00
+++ b/xen/arch/x86/x86_32/seg_fixup.c   2005-04-19 10:03:56 -04:00
@@ -145,7 +145,7 @@
      * Anything that looks like a truncated segment we assume ought really
      * to be a 4GB segment. DANGER!
      */
-    if ( (PAGE_OFFSET - (*base + *limit)) < PAGE_SIZE )
+    if ( (GUEST_SEGMENT_MAX_ADDR - (*base + *limit)) < PAGE_SIZE )
         *limit = 0;
 
     return 1;
@@ -226,14 +226,14 @@
         if ( ((base + limit) < PAGE_SIZE) && (offset <= limit)  )
         {
             /* Flip to expands-up. */
-            limit = PAGE_OFFSET - base;
+            limit = GUEST_SEGMENT_MAX_ADDR - base;
             goto flip;
         }
     }
     else
     {
         /* Expands-up: All the way to Xen space? Assume 4GB if so. */
-        if ( ((PAGE_OFFSET - (base + limit)) < PAGE_SIZE) &&
+        if ( ((GUEST_SEGMENT_MAX_ADDR - (base + limit)) < PAGE_SIZE) &&
              (offset > limit) )
         {
             /* Flip to expands-down. */
diff -Nru a/xen/arch/x86/x86_32/xen.lds b/xen/arch/x86/x86_32/xen.lds
--- a/xen/arch/x86/x86_32/xen.lds       2005-04-19 10:03:56 -04:00
+++ b/xen/arch/x86/x86_32/xen.lds       2005-04-19 10:03:56 -04:00
@@ -11,7 +11,7 @@
 }
 SECTIONS
 {
-  . = 0xFC400000 + 0x100000;
+  . = 0xFF000000 + 0x100000;
   _text = .;                   /* Text and read-only data */
   .text : {
        *(.text)
diff -Nru a/xen/include/asm-x86/config.h b/xen/include/asm-x86/config.h
--- a/xen/include/asm-x86/config.h      2005-04-19 10:03:56 -04:00
+++ b/xen/include/asm-x86/config.h      2005-04-19 10:03:56 -04:00
@@ -216,12 +216,71 @@
 
 #define asmlinkage __attribute__((regparm(0)))
 
-#define XENHEAP_DEFAULT_MB (12)
-#define DIRECTMAP_PHYS_END (12*1024*1024)
+/*
+ * Memory layout (high to low):                          SIZE   PAE-SIZE
+ *                                                       ------ ------
+ *  I/O remapping area                                   ( 4MB)
+ *  Direct-map (1:1) area [Xen code/data/heap]           (12MB)
+ *  map_domain_mem cache                                 ( 4MB)
+ *  Per-domain mappings                                  ( 4MB)
+ *  Shadow linear pagetable                              ( 4MB) ( 8MB)
+ *  Guest linear pagetable                               ( 4MB) ( 8MB)
+ *  Machine-to-physical translation table [writable]     ( 4MB)
+ *  Frame-info table                                     (24MB) (96MB)
+ *   * Start of guest inaccessible area
+ *  Machine-to-physical translation table [read-only]    ( 4MB)
+ *   * Start of guest unmodifiable area
+ */
+
+#define IOREMAP_MBYTES           4
+#define DIRECTMAP_MBYTES        12
+#define MAPCACHE_MBYTES          4
+#define PERDOMAIN_MBYTES         4
+
+#ifdef CONFIG_X86_PAE
+# define LINEARPT_MBYTES         8
+# define MACHPHYS_MBYTES         4 /* KAF: This needs to be bigger */
+# define FRAMETABLE_MBYTES     96 /* 16 GB mem limit (total)      */
+#else
+# define LINEARPT_MBYTES         4
+# define MACHPHYS_MBYTES         4
+# define FRAMETABLE_MBYTES      24
+#endif
+
+#define IOREMAP_VIRT_END       0UL
+#define IOREMAP_VIRT_START     (IOREMAP_VIRT_END - (IOREMAP_MBYTES<<20))
+#define DIRECTMAP_VIRT_END     IOREMAP_VIRT_START
+#define DIRECTMAP_VIRT_START   (DIRECTMAP_VIRT_END - (DIRECTMAP_MBYTES<<20))
+#define MAPCACHE_VIRT_END      DIRECTMAP_VIRT_START
+#define MAPCACHE_VIRT_START    (MAPCACHE_VIRT_END - (MAPCACHE_MBYTES<<20))
+#define PERDOMAIN_VIRT_END     MAPCACHE_VIRT_START
+#define PERDOMAIN_VIRT_START   (PERDOMAIN_VIRT_END - (PERDOMAIN_MBYTES<<20))
+#define SH_LINEAR_PT_VIRT_END  PERDOMAIN_VIRT_START
+#define SH_LINEAR_PT_VIRT_START        (SH_LINEAR_PT_VIRT_END - 
(LINEARPT_MBYTES<<20))
+#define LINEAR_PT_VIRT_END     SH_LINEAR_PT_VIRT_START
+#define LINEAR_PT_VIRT_START   (LINEAR_PT_VIRT_END - (LINEARPT_MBYTES<<20))
+#define RDWR_MPT_VIRT_END      LINEAR_PT_VIRT_START
+#define RDWR_MPT_VIRT_START    (RDWR_MPT_VIRT_END - (MACHPHYS_MBYTES<<20))
+#define FRAMETABLE_VIRT_END    RDWR_MPT_VIRT_START
+#define FRAMETABLE_VIRT_START  (FRAMETABLE_VIRT_END - (FRAMETABLE_MBYTES<<20))
+#define RO_MPT_VIRT_END                FRAMETABLE_VIRT_START
+#define RO_MPT_VIRT_START      (RO_MPT_VIRT_END - (MACHPHYS_MBYTES<<20))
 
+#define XENHEAP_DEFAULT_MB     (DIRECTMAP_MBYTES)
+#define DIRECTMAP_PHYS_END     (DIRECTMAP_MBYTES<<20)
+
+/* Maximum linear address accessible via guest memory segments. */
+#define GUEST_SEGMENT_MAX_ADDR  RO_MPT_VIRT_END
+
+#ifdef CONFIG_X86_PAE
+/* Hypervisor owns top 144MB of virtual address space. */
+# define __HYPERVISOR_VIRT_START  0xF7000000
+# define HYPERVISOR_VIRT_START   (0xF7000000UL)
+#else
 /* Hypervisor owns top 64MB of virtual address space. */
-#define __HYPERVISOR_VIRT_START  0xFC000000
-#define HYPERVISOR_VIRT_START   (0xFC000000UL)
+# define __HYPERVISOR_VIRT_START  0xFC000000
+# define HYPERVISOR_VIRT_START   (0xFC000000UL)
+#endif
 
 #define ROOT_PAGETABLE_FIRST_XEN_SLOT \
     (HYPERVISOR_VIRT_START >> L2_PAGETABLE_SHIFT)
@@ -229,37 +288,6 @@
     (~0UL >> L2_PAGETABLE_SHIFT)
 #define ROOT_PAGETABLE_XEN_SLOTS \
     (ROOT_PAGETABLE_LAST_XEN_SLOT - ROOT_PAGETABLE_FIRST_XEN_SLOT + 1)
-
-/*
- * First 4MB are mapped read-only for all. It's for the machine->physical
- * mapping table (MPT table). The following are virtual addresses.
- */
-#define RO_MPT_VIRT_START     (HYPERVISOR_VIRT_START)
-#define RO_MPT_VIRT_END       (RO_MPT_VIRT_START + (4*1024*1024))
-/* Xen heap extends to end of 1:1 direct-mapped memory region. */
-#define DIRECTMAP_VIRT_START  (RO_MPT_VIRT_END)
-#define DIRECTMAP_VIRT_END    (DIRECTMAP_VIRT_START + DIRECTMAP_PHYS_END)
-/* Machine-to-phys conversion table. */
-#define RDWR_MPT_VIRT_START   (DIRECTMAP_VIRT_END)
-#define RDWR_MPT_VIRT_END     (RDWR_MPT_VIRT_START + (4*1024*1024))
-/* Variable-length page-frame information array. */
-#define FRAMETABLE_VIRT_START (RDWR_MPT_VIRT_END)

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.