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

Re: [Xen-devel] [rfc] address space reorganization



  Hi,

> I think it would be good to introduce a new constant to indicate the
> start of the hypervisor protected area rather than using RO_MPT_VIRT_END
> everywhere.

Fixed ;)

cheers,

  Gerd

==============================[ cut here ]==============================
Subject: [patch] address space reorganization

Shuffle around the memory blocks a bit ;)

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.

Note that PAGE_OFFSET isn't the start address of xen's
private memory area any more.  Thats why the segment
range checks are fixed up and use the new
HYPERVISOR_VIRT_PRIV_START define which is currently
aliased to RO_MPT_VIRT_END.

Signed-off-by: Gerd Knorr <kraxel@xxxxxxxxxxx>
---
 arch/x86/mm.c                 |    2 
 arch/x86/traps.c              |    4 -
 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      |   85 ++++++++++++++++++++--------------
 include/asm-x86/x86_32/page.h |    2 
 7 files changed, 61 insertions(+), 46 deletions(-)

Index: xen/arch/x86/x86_32/xen.lds
===================================================================
--- xen.orig/arch/x86/x86_32/xen.lds    2005-04-15 15:31:22.000000000 +0200
+++ xen/arch/x86/x86_32/xen.lds 2005-04-18 20:33:04.000000000 +0200
@@ -11,7 +11,7 @@ PHDRS
 }
 SECTIONS
 {
-  . = 0xFC400000 + 0x100000;
+  . = 0xFF000000 + 0x100000;
   _text = .;                   /* Text and read-only data */
   .text : {
        *(.text)
Index: xen/include/asm-x86/config.h
===================================================================
--- xen.orig/include/asm-x86/config.h   2005-04-15 15:31:22.000000000 +0200
+++ xen/include/asm-x86/config.h        2005-04-19 11:20:58.000000000 +0200
@@ -216,12 +216,56 @@ extern void __out_of_line_bug(int line) 
 
 #define asmlinkage __attribute__((regparm(0)))
 
-#define XENHEAP_DEFAULT_MB (12)
-#define DIRECTMAP_PHYS_END (12*1024*1024)
+#define IOREMAP_VIRT_SIZE      4
+#define DIRECTMAP_VIRT_SIZE    12
+#define MAPCACHE_VIRT_SIZE     4
+#define PERDOMAIN_VIRT_SIZE    4
+
+#ifdef CONFIG_X86_PAE
+# define SH_LINEAR_PT_VIRT_SIZE        8
+# define LINEAR_PT_VIRT_SIZE   8
+# define RDWR_MPT_VIRT_SIZE    4       /*  4 GB mem limit (per domain) */
+# define FRAMETABLE_VIRT_SIZE  96      /* 16 GB mem limit (total)      */
+# define RO_MPT_VIRT_SIZE      4       /*  4 GB mem limit (per domain) */
+#else
+# define SH_LINEAR_PT_VIRT_SIZE        4
+# define LINEAR_PT_VIRT_SIZE   4
+# define RDWR_MPT_VIRT_SIZE    4
+# define FRAMETABLE_VIRT_SIZE  24
+# define RO_MPT_VIRT_SIZE      4
+#endif
 
+#define IOREMAP_VIRT_END       0UL
+#define IOREMAP_VIRT_START     (IOREMAP_VIRT_END - 
(IOREMAP_VIRT_SIZE*1024*1024))
+#define DIRECTMAP_VIRT_END     IOREMAP_VIRT_START
+#define DIRECTMAP_VIRT_START   (DIRECTMAP_VIRT_END - 
(DIRECTMAP_VIRT_SIZE*1024*1024))
+#define MAPCACHE_VIRT_END      DIRECTMAP_VIRT_START
+#define MAPCACHE_VIRT_START    (MAPCACHE_VIRT_END - 
(MAPCACHE_VIRT_SIZE*1024*1024))
+#define PERDOMAIN_VIRT_END     MAPCACHE_VIRT_START
+#define PERDOMAIN_VIRT_START   (PERDOMAIN_VIRT_END - 
(PERDOMAIN_VIRT_SIZE*1024*1024))
+#define SH_LINEAR_PT_VIRT_END  PERDOMAIN_VIRT_START
+#define SH_LINEAR_PT_VIRT_START        (SH_LINEAR_PT_VIRT_END - 
(SH_LINEAR_PT_VIRT_SIZE*1024*1024))
+#define LINEAR_PT_VIRT_END     SH_LINEAR_PT_VIRT_START
+#define LINEAR_PT_VIRT_START   (LINEAR_PT_VIRT_END - 
(LINEAR_PT_VIRT_SIZE*1024*1024))
+#define RDWR_MPT_VIRT_END      LINEAR_PT_VIRT_START
+#define RDWR_MPT_VIRT_START    (RDWR_MPT_VIRT_END - 
(RDWR_MPT_VIRT_SIZE*1024*1024))
+#define FRAMETABLE_VIRT_END    RDWR_MPT_VIRT_START
+#define FRAMETABLE_VIRT_START  (FRAMETABLE_VIRT_END - 
(FRAMETABLE_VIRT_SIZE*1024*1024))
+#define RO_MPT_VIRT_END                FRAMETABLE_VIRT_START
+#define RO_MPT_VIRT_START      (RO_MPT_VIRT_END - (RO_MPT_VIRT_SIZE*1024*1024))
+
+#define XENHEAP_DEFAULT_MB     (DIRECTMAP_VIRT_SIZE)
+#define DIRECTMAP_PHYS_END     (DIRECTMAP_VIRT_SIZE*1024*1024)
+
+#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)
@@ -230,37 +274,6 @@ extern void __out_of_line_bug(int line) 
 #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)
-#define FRAMETABLE_VIRT_END   (FRAMETABLE_VIRT_START + (24*1024*1024))
-/* Next 4MB of virtual address space is used as a linear p.t. mapping. */
-#define LINEAR_PT_VIRT_START  (FRAMETABLE_VIRT_END)
-#define LINEAR_PT_VIRT_END    (LINEAR_PT_VIRT_START + (4*1024*1024))
-/* Next 4MB of virtual address space is used as a shadow linear p.t. map. */
-#define SH_LINEAR_PT_VIRT_START (LINEAR_PT_VIRT_END)
-#define SH_LINEAR_PT_VIRT_END (SH_LINEAR_PT_VIRT_START + (4*1024*1024))
-/* Next 4MB of virtual address space used for per-domain mappings (eg. GDT). */
-#define PERDOMAIN_VIRT_START  (SH_LINEAR_PT_VIRT_END)
-#define PERDOMAIN_VIRT_END    (PERDOMAIN_VIRT_START + (4*1024*1024))
-/* Penultimate 4MB of virtual address space used for domain page mappings. */
-#define MAPCACHE_VIRT_START   (PERDOMAIN_VIRT_END)
-#define MAPCACHE_VIRT_END     (MAPCACHE_VIRT_START + (4*1024*1024))
-/* Final 4MB of virtual address space used for ioremap(). */
-#define IOREMAP_VIRT_START    (MAPCACHE_VIRT_END)
-#define IOREMAP_VIRT_END      (IOREMAP_VIRT_START + (4*1024*1024))
-
 #define PGT_base_page_table PGT_l2_page_table
 
 #define __HYPERVISOR_CS 0x0808
@@ -278,6 +291,8 @@ extern void __out_of_line_bug(int line) 
 extern unsigned long xenheap_phys_end; /* user-configurable */
 #endif
 
+#define HYPERVISOR_VIRT_PRIV_START RO_MPT_VIRT_END
+
 #define GDT_VIRT_START(ed)    (PERDOMAIN_VIRT_START + ((ed)->eid << 
PDPT_VCPU_VA_SHIFT))
 #define GDT_VIRT_END(ed)      (GDT_VIRT_START(ed) + (64*1024))
 #define LDT_VIRT_START(ed)    (PERDOMAIN_VIRT_START + (64*1024) + ((ed)->eid 
<< PDPT_VCPU_VA_SHIFT))
Index: xen/include/asm-x86/x86_32/page.h
===================================================================
--- xen.orig/include/asm-x86/x86_32/page.h      2005-04-18 20:33:03.000000000 
+0200
+++ xen/include/asm-x86/x86_32/page.h   2005-04-19 11:09:37.000000000 +0200
@@ -12,7 +12,7 @@
 #define L2_PAGETABLE_ENTRIES    (1<<PAGETABLE_ORDER)
 #define ROOT_PAGETABLE_ENTRIES  L2_PAGETABLE_ENTRIES
 
-#define __PAGE_OFFSET           (0xFC400000)
+#define __PAGE_OFFSET           (0xFF000000)
 
 #define PADDR_BITS              32
 #define VADDR_BITS              32
Index: xen/arch/x86/mm.c
===================================================================
--- xen.orig/arch/x86/mm.c      2005-04-18 20:33:03.000000000 +0200
+++ xen/arch/x86/mm.c   2005-04-19 11:12:54.000000000 +0200
@@ -1634,7 +1634,7 @@ int do_mmuext_op(
             if ( ((ptr & (PAGE_SIZE-1)) != 0) || 
                  (ents > 8192) ||
                  ((ptr+ents*LDT_ENTRY_SIZE) < ptr) ||
-                 ((ptr+ents*LDT_ENTRY_SIZE) > PAGE_OFFSET) )
+                 ((ptr+ents*LDT_ENTRY_SIZE) > HYPERVISOR_VIRT_PRIV_START) )
             {
                 okay = 0;
                 MEM_LOG("Bad args to SET_LDT: ptr=%p, ents=%p", ptr, ents);
Index: xen/arch/x86/x86_32/seg_fixup.c
===================================================================
--- xen.orig/arch/x86/x86_32/seg_fixup.c        2005-04-15 15:31:22.000000000 
+0200
+++ xen/arch/x86/x86_32/seg_fixup.c     2005-04-19 11:15:32.000000000 +0200
@@ -145,7 +145,7 @@ int get_baselimit(u16 seg, unsigned long
      * 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 ( (HYPERVISOR_VIRT_PRIV_START - (*base + *limit)) < PAGE_SIZE )
         *limit = 0;
 
     return 1;
@@ -226,14 +226,14 @@ int fixup_seg(u16 seg, unsigned long off
         if ( ((base + limit) < PAGE_SIZE) && (offset <= limit)  )
         {
             /* Flip to expands-up. */
-            limit = PAGE_OFFSET - base;
+            limit = HYPERVISOR_VIRT_PRIV_START - base;
             goto flip;
         }
     }
     else
     {
         /* Expands-up: All the way to Xen space? Assume 4GB if so. */
-        if ( ((PAGE_OFFSET - (base + limit)) < PAGE_SIZE) &&
+        if ( ((HYPERVISOR_VIRT_PRIV_START - (base + limit)) < PAGE_SIZE) &&
              (offset > limit) )
         {
             /* Flip to expands-down. */
Index: xen/arch/x86/traps.c
===================================================================
--- xen.orig/arch/x86/traps.c   2005-04-15 15:31:22.000000000 +0200
+++ xen/arch/x86/traps.c        2005-04-19 11:15:32.000000000 +0200
@@ -284,7 +284,7 @@ asmlinkage int do_page_fault(struct xen_
             return EXCRET_fault_fixed;
         }
 
-        if ( (addr < PAGE_OFFSET) &&
+        if ( (addr < HYPERVISOR_VIRT_PRIV_START) &&
              ((regs->error_code & 3) == 3) && /* write-protection fault */
              ptwr_do_page_fault(d, addr) )
         {
@@ -1102,7 +1102,7 @@ long do_set_trap_table(trap_info_t *trap
 
 #if defined(__i386__)
 #define DB_VALID_ADDR(_a) \
-    ((_a) <= (PAGE_OFFSET - 4))
+    ((_a) <= (HYPERVISOR_VIRT_PRIV_START - 4))
 #elif defined(__x86_64__)
 #define DB_VALID_ADDR(_a) \
     ((_a) >= HYPERVISOR_VIRT_END) || ((_a) <= (HYPERVISOR_VIRT_START-8))
Index: xen/arch/x86/x86_32/mm.c
===================================================================
--- xen.orig/arch/x86/x86_32/mm.c       2005-04-18 20:33:03.000000000 +0200
+++ xen/arch/x86/x86_32/mm.c    2005-04-19 11:15:32.000000000 +0200
@@ -248,7 +248,7 @@ int check_descriptor(struct desc_struct 
     
     /* 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 >= (HYPERVISOR_VIRT_PRIV_START - PAGE_SIZE) )
         goto bad;
 
     /* Check and truncate the limit if necessary. */
@@ -281,9 +281,9 @@ int check_descriptor(struct desc_struct 
          *     limit == 0x00000 provides 4kB access (if G=1).
          */
         if ( ((base + limit) <= base) || 
-             ((base + limit) > PAGE_OFFSET) )
+             ((base + limit) > HYPERVISOR_VIRT_PRIV_START) )
         {
-            limit = PAGE_OFFSET - base;
+            limit = HYPERVISOR_VIRT_PRIV_START - base;
         truncate:
             if ( !(b & _SEGMENT_G) )
                 goto bad; /* too dangerous; too hard to work out... */

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


 


Rackspace

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