Skip to contentSkip to conversation

32-on-64 phys2machine handling

RFC PATCH In review Jan Beulich 1 participant 1 message Oct 4, 2006

lore
Share & tools
lore
#0 lore raw

RFC PATCH 7/17 32-on-64 phys2machine handling

xen/arch/x86/domain.c +44 -3
Index: 2006-10-04/xen/arch/x86/domain.c
===================================================================
@@ -143,11 +143,34 @@ struct vcpu *alloc_vcpu_struct(struct do
 
     pae_l3_cache_init(&v->arch.pae_l3_cache);
 
+#ifdef CONFIG_COMPAT
+    if ( IS_COMPAT(d) )
+    {
+        struct page_info *pg = alloc_domheap_page(NULL);
+        l4_pgentry_t *l4tab;
+
+        if ( !pg )
+        {
+            xfree(v);
+            return NULL;
+        }
+        l4tab = copy_page(page_to_virt(pg), idle_pg_table);
+        l4tab[l4_table_offset(LINEAR_PT_VIRT_START)] =
+            l4e_from_page(pg, __PAGE_HYPERVISOR);
+        l4tab[l4_table_offset(PERDOMAIN_VIRT_START)] =
+            l4e_from_paddr(__pa(d->arch.mm_perdomain_l3), __PAGE_HYPERVISOR);
+        v->arch.guest_table = pagetable_from_page(pg);
+        v->arch.guest_table_user = v->arch.guest_table;
+    }
+#endif
+
     return v;
 }
 
 void free_vcpu_struct(struct vcpu *v)
 {
+    if ( IS_COMPAT(v->domain) )
+        free_domheap_page(pagetable_get_page(v->arch.guest_table));
     xfree(v);
 }
 
@@ -323,7 +346,8 @@ int arch_set_info_guest(
     if ( !(c->flags & VGCF_HVM_GUEST) )
     {
         cr3_pfn = gmfn_to_mfn(d, xen_cr3_to_pfn(c->ctrlreg[3]));
-        v->arch.guest_table = pagetable_from_pfn(cr3_pfn);
+        if ( !IS_COMPAT(d) )
+            v->arch.guest_table = pagetable_from_pfn(cr3_pfn);
     }
 
     if ( (rc = (int)set_gdt(v, c->gdt_frames, c->gdt_ents)) != 0 )
@@ -336,7 +360,7 @@ int arch_set_info_guest(
         if ( !hvm_initialize_guest_resources(v) )
             return -EINVAL;
     }
-    else
+    else if ( !IS_COMPAT(d) )
     {
         if ( shadow_mode_refcounts(d)
              ? !get_page(mfn_to_page(cr3_pfn), d)
@@ -346,7 +370,24 @@ int arch_set_info_guest(
             destroy_gdt(v);
             return -EINVAL;
         }
-    }    
+    }
+#ifdef CONFIG_COMPAT
+    else
+    {
+        l4_pgentry_t *l4tab;
+
+        if ( shadow_mode_refcounts(d)
+             ? !get_page(mfn_to_page(cr3_pfn), d)
+             : !get_page_and_type(mfn_to_page(cr3_pfn), d,
+                                PGT_l3_page_table) )
+        {
+            destroy_gdt(v);
+            return -EINVAL;
+        }
+        l4tab = __va(pagetable_get_paddr(v->arch.guest_table));
+        *l4tab = l4e_from_pfn(cr3_pfn, _PAGE_PRESENT|_PAGE_RW|_PAGE_USER|_PAGE_ACCESSED|_PAGE_DIRTY);
+    }
+#endif
 
     /* Shadow: make sure the domain has enough shadow memory to
      * boot another vcpu */
xen/arch/x86/domain_build.c +60 -12

140 lines not on this page · raw message

xen/arch/x86/mm.c +46 -28

196 lines not on this page · raw message

xen/arch/x86/x86_64/mm.c +54 -1

73 lines not on this page · raw message

xen/include/asm-x86/config.h +21 -1
Index: 2006-10-04/xen/include/asm-x86/config.h
===================================================================
@@ -135,7 +135,11 @@ static inline void FORCE_CRASH(void) 
  *    Page-frame information array.
  *  0xffff828800000000 - 0xffff828bffffffff [16GB,  2^34 bytes, PML4:261]
  *    ioremap()/fixmap area.
- *  0xffff828c00000000 - 0xffff82ffffffffff [464GB,             PML4:261]
+ *  0xffff828c00000000 - 0xffff828c3fffffff [1GB,   2^30 bytes, PML4:261]
+ *    Compatibility machine-to-phys translation table.
+ *  0xffff828c40000000 - 0xffff828c7fffffff [1GB,   2^30 bytes, PML4:261]
+ *    High read-only compatibility machine-to-phys translation table.
+ *  0xffff828c80000000 - 0xffff82ffffffffff [462GB,             PML4:261]
  *    Reserved for future use.
  *  0xffff830000000000 - 0xffff83ffffffffff [1TB,   2^40 bytes, PML4:262-263]
  *    1:1 direct mapping of all physical memory. Xen and its heap live here.
@@ -184,6 +188,12 @@ static inline void FORCE_CRASH(void) 
 /* Slot 261: ioremap()/fixmap area (16GB). */
 #define IOREMAP_VIRT_START      (FRAMETABLE_VIRT_END)
 #define IOREMAP_VIRT_END        (IOREMAP_VIRT_START + (16UL<<30))
+/* Slot 261: compatibility machine-to-phys conversion table (1GB). */
+#define RDWR_COMPAT_MPT_VIRT_START IOREMAP_VIRT_END
+#define RDWR_COMPAT_MPT_VIRT_END   (RDWR_COMPAT_MPT_VIRT_START + (1UL << 30))
+/* Slot 261: high read-only compatibility machine-to-phys conversion table (1GB). */
+#define HIRO_COMPAT_MPT_VIRT_START RDWR_COMPAT_MPT_VIRT_END
+#define HIRO_COMPAT_MPT_VIRT_END   (HIRO_COMPAT_MPT_VIRT_START + (1UL << 30))
 /* Slot 262-263: A direct 1:1 mapping of all of physical memory. */
 #define DIRECTMAP_VIRT_START    (PML4_ADDR(262))
 #define DIRECTMAP_VIRT_END      (DIRECTMAP_VIRT_START + PML4_ENTRY_BYTES*2)
@@ -196,6 +206,16 @@ static inline void FORCE_CRASH(void) 
 #define MACH2PHYS_COMPAT_VIRT_END      mk_unsigned_long(__MACH2PHYS_COMPAT_VIRT_END)
 #define MACH2PHYS_COMPAT_NR_ENTRIES    ((MACH2PHYS_COMPAT_VIRT_END-MACH2PHYS_COMPAT_VIRT_START)>>2)
 
+#define COMPAT_RO_MPT_VIRT_START       MACH2PHYS_COMPAT_VIRT_START
+#define COMPAT_RO_MPT_VIRT_END         MACH2PHYS_COMPAT_VIRT_END
+
+#define COMPAT_L2_PAGETABLE_FIRST_XEN_SLOT \
+    l2_table_offset(HYPERVISOR_COMPAT_VIRT_START)
+#define COMPAT_L2_PAGETABLE_LAST_XEN_SLOT  \
+    l2_table_offset(~0U)
+#define COMPAT_L2_PAGETABLE_XEN_SLOTS \
+    (COMPAT_L2_PAGETABLE_LAST_XEN_SLOT - COMPAT_L2_PAGETABLE_FIRST_XEN_SLOT + 1)
+
 #define PGT_base_page_table     PGT_l4_page_table
 
 #define __HYPERVISOR_CS64 0xe008
xen/include/asm-x86/mm.h +8 -0
Index: 2006-10-04/xen/include/asm-x86/mm.h
===================================================================
@@ -293,7 +293,15 @@ int check_descriptor(const struct domain
 #define INVALID_M2P_ENTRY        (~0UL)
 #define VALID_M2P(_e)            (!((_e) & (1UL<<(BITS_PER_LONG-1))))
 
+#ifdef CONFIG_COMPAT
+#define compat_machine_to_phys_mapping ((unsigned int *)RDWR_COMPAT_MPT_VIRT_START)
+#define set_gpfn_from_mfn(mfn, pfn) \
+    ((void)((mfn) >= (RDWR_COMPAT_MPT_VIRT_END - RDWR_COMPAT_MPT_VIRT_START) / 4 || \
+            (compat_machine_to_phys_mapping[(mfn)] = (unsigned int)(pfn))), \
+     machine_to_phys_mapping[(mfn)] = (pfn))
+#else
 #define set_gpfn_from_mfn(mfn, pfn) (machine_to_phys_mapping[(mfn)] = (pfn))
+#endif
 #define get_gpfn_from_mfn(mfn)      (machine_to_phys_mapping[(mfn)])
 
 
xen/include/asm-x86/page.h +4 -0
Index: 2006-10-04/xen/include/asm-x86/page.h
===================================================================
@@ -173,6 +173,7 @@ typedef struct { u32 pfn; } pagetable_t;
 typedef struct { u64 pfn; } pagetable_t;
 #endif
 #define pagetable_get_paddr(x)  ((paddr_t)(x).pfn << PAGE_SHIFT)
+#define pagetable_get_page(x)   mfn_to_page((x).pfn)
 #define pagetable_get_pfn(x)    ((x).pfn)
 #define pagetable_is_null(x)    ((x).pfn == 0)
 #define pagetable_from_pfn(pfn) ((pagetable_t) { (pfn) })
@@ -254,6 +255,9 @@ extern l2_pgentry_t   idle_pg_table_l2[R
 #else
 extern root_pgentry_t idle_pg_table[ROOT_PAGETABLE_ENTRIES];
 extern l2_pgentry_t   idle_pg_table_l2[ROOT_PAGETABLE_ENTRIES];
+#ifdef CONFIG_COMPAT
+extern l2_pgentry_t  *compat_idle_pg_table_l2;
+#endif
 #endif
 void paging_init(void);
 void setup_idle_pagetable(void);
xen/include/asm-x86/x86_32/page-2level.h +1 -1
Index: 2006-10-04/xen/include/asm-x86/x86_32/page-2level.h
===================================================================
@@ -38,7 +38,7 @@ typedef l2_pgentry_t root_pgentry_t;
 
 /* misc */
 #define is_guest_l1_slot(_s)    (1)
-#define is_guest_l2_slot(_t,_s) ((_s) < L2_PAGETABLE_FIRST_XEN_SLOT)
+#define is_guest_l2_slot(_d, _t,_s) ((_s) < L2_PAGETABLE_FIRST_XEN_SLOT)
 
 /*
  * PTE pfn and flags:
xen/include/asm-x86/x86_32/page-3level.h +1 -1
Index: 2006-10-04/xen/include/asm-x86/x86_32/page-3level.h
===================================================================
@@ -48,7 +48,7 @@ typedef l3_pgentry_t root_pgentry_t;
 
 /* misc */
 #define is_guest_l1_slot(s)    (1)
-#define is_guest_l2_slot(t,s)                                              \
+#define is_guest_l2_slot(d,t,s)                                            \
     ( !((t) & PGT_pae_xen_l2) ||                                           \
       ((s) < (L2_PAGETABLE_FIRST_XEN_SLOT & (L2_PAGETABLE_ENTRIES - 1))) )
 #define is_guest_l3_slot(s)    (1)
xen/include/asm-x86/x86_64/page.h +4 -1
Index: 2006-10-04/xen/include/asm-x86/x86_64/page.h
===================================================================
@@ -48,7 +48,10 @@ typedef l4_pgentry_t root_pgentry_t;
 #define l4_linear_offset(_a) (((_a) & VADDR_MASK) >> L4_PAGETABLE_SHIFT)
 
 #define is_guest_l1_slot(_s) (1)
-#define is_guest_l2_slot(_t, _s) (1)
+#define is_guest_l2_slot(_d, _t, _s)                   \
+    ( !IS_COMPAT(_d) ||                                \
+      !((_t) & PGT_pae_xen_l2) ||                      \
+      ((_s) < COMPAT_L2_PAGETABLE_FIRST_XEN_SLOT) )
 #define is_guest_l3_slot(_s) (1)
 #define is_guest_l4_slot(_s)                   \
     (((_s) < ROOT_PAGETABLE_FIRST_XEN_SLOT) || \