Skip to contentSkip to conversation

x86-64's paging_init()

DISCUSSION Jan Beulich 2 participants 6 messages Aug 31, 2006 – Sep 12, 2006

lore
Share & tools
lore
#0 lore raw

While adding code to create the compatibility p2m table mappings it seemed to me that the creation of the native ones is restricted to memory below the 512G boundary - otherwise, additional L2 tables would need to be allocated (currently other memory following the one L2 page getting allocated would be blindly overwritten). While I realize that machines this big aren't likely to be targeted by Xen at this point anyway (although the direct map area explicitly provides for 1T), I'd still want this fixed if someone confirms I'm not mis-reading something here (of if that's the case, then I'd still need a good explanation, as then I'm likely screwing up the compatibility table creation).

Jan

#1 lore raw

Correct. I suggest either a clean BUG_ON() in virt_to_xen_l2e(), or allocate-and-map the new l2 in that same function (but raises question of how to test the new code path).

-- Keir

Quoted 16 lines · Jan Beulich

While adding code to create the compatibility p2m table mappings it seemed
to me that the creation of the native ones is restricted to memory below the 512G boundary - otherwise, additional L2 tables would need to be allocated (currently other memory following the one L2 page getting allocated would be blindly overwritten). While I realize that machines this
big aren't likely to be targeted by Xen at this point anyway (although the
direct map area explicitly provides for 1T), I'd still want this fixed if
someone confirms I'm not mis-reading something here (of if that's the case,
then I'd still need a good explanation, as then I'm likely screwing up the
compatibility table creation).

#2 lore raw
Quoted 4 lines
Quoted 1 line
Quoted 1 line

Keir Fraser <[email protected]> 31.08.06 19:58 >>>

Correct. I suggest either a clean BUG_ON() in virt_to_xen_l2e(), or allocate-and-map the new l2 in that same function (but raises question of how to test the new code path).

Why in virt_to_xen_l2e()? We likely wouldn't make it there on a system this big, due to earlier memory corruption.
But anyway, I'll try to change the code so the code path won't be entirely unused (similar to the dom0 page table setup in contruct_dom0()).

Jan

Quoted 18 lines · Jan Beulich
Quoted 17 lines

While adding code to create the compatibility p2m table mappings it seemed
to me that the creation of the native ones is restricted to memory below the 512G boundary - otherwise, additional L2 tables would need to be allocated (currently other memory following the one L2 page getting allocated would be blindly overwritten). While I realize that machines this
big aren't likely to be targeted by Xen at this point anyway (although the
direct map area explicitly provides for 1T), I'd still want this fixed if
someone confirms I'm not mis-reading something here (of if that's the case,
then I'd still need a good explanation, as then I'm likely screwing up the
compatibility table creation).

#3 lore raw
Quoted 6 lines · Jan Beulich
Quoted 3 lines

Correct. I suggest either a clean BUG_ON() in virt_to_xen_l2e(), or allocate-and-map the new l2 in that same function (but raises question of how to test the new code path).

Why in virt_to_xen_l2e()? We likely wouldn't make it there on a system this big, due to earlier memory corruption.

Why? The memory is only discovered and mapped after the e820 map is parsed. The mapping occurs via map_pages_to_xen(). That function discovers the l2e by using virt_to_xen_l2e(). So I think it ought to work.

You can test it out by doing a map_pages_to_xen() call on an area of virtual address space that currently has no l2e. Should crash now, and work with the modified virt_to_xen_l2e().

-- Keir

Quoted 2 lines

But anyway, I'll try to change the code so the code path won't be entirely unused (similar to the dom0 page table setup in contruct_dom0()).

#4 lore raw
Quoted 7 lines · Keir Fraser
Quoted 6 lines
Quoted 3 lines

Correct. I suggest either a clean BUG_ON() in virt_to_xen_l2e(), or allocate-and-map the new l2 in that same function (but raises question of how to test the new code path).

Why in virt_to_xen_l2e()? We likely wouldn't make it there on a system this big, due to earlier memory corruption.

Quoted 7 lines

Why? The memory is only discovered and mapped after the e820 map is parsed. The mapping occurs via map_pages_to_xen(). That function discovers the l2e by using virt_to_xen_l2e(). So I think it ought to work.

You can test it out by doing a map_pages_to_xen() call on an area of virtual address space that currently has no l2e. Should crash now, and work with the modified virt_to_xen_l2e().

Actually virt_to_xen_l2e() already allocates pagetables on demand, it turns out. So I think there is no issue here that needs fixing.

-- Keir

#5 lore raw
Quoted 14 lines
Quoted 1 line
Quoted 1 line

Keir Fraser <[email protected]> 01.09.06 17:58 >>>

Quoted 11 lines · Keir Fraser
Quoted 6 lines
Quoted 3 lines

Correct. I suggest either a clean BUG_ON() in virt_to_xen_l2e(), or allocate-and-map the new l2 in that same function (but raises question of how to test the new code path).

Why in virt_to_xen_l2e()? We likely wouldn't make it there on a system this big, due to earlier memory corruption.

Why? The memory is only discovered and mapped after the e820 map is parsed. The mapping occurs via map_pages_to_xen(). That function discovers the l2e by using virt_to_xen_l2e(). So I think it ought to work.

Quoted 6 lines
Quoted 3 lines

You can test it out by doing a map_pages_to_xen() call on an area of virtual address space that currently has no l2e. Should crash now, and work with the modified virt_to_xen_l2e().

Actually virt_to_xen_l2e() already allocates pagetables on demand, it turns out. So I think there is no issue here that needs fixing.

Here's the change I was hinting towards - replaces the BUG_ON() with proper code.

xen/arch/x86/x86_64/mm.c +12 -8
Index: 2006-09-11/xen/arch/x86/x86_64/mm.c
===================================================================
@@ -78,7 +78,7 @@ void __init paging_init(void)
 {
     unsigned long i, mpt_size;
     l3_pgentry_t *l3_ro_mpt;
-    l2_pgentry_t *l2_ro_mpt;
+    l2_pgentry_t *l2_ro_mpt = NULL;
     struct page_info *pg;
 
     /* Create user-accessible L2 directory to map the MPT for guests. */
@@ -87,12 +87,6 @@ void __init paging_init(void)
     idle_pg_table[l4_table_offset(RO_MPT_VIRT_START)] =
         l4e_from_page(
             virt_to_page(l3_ro_mpt), __PAGE_HYPERVISOR | _PAGE_USER);
-    l2_ro_mpt = alloc_xenheap_page();
-    clear_page(l2_ro_mpt);
-    l3_ro_mpt[l3_table_offset(RO_MPT_VIRT_START)] =
-        l3e_from_page(
-            virt_to_page(l2_ro_mpt), __PAGE_HYPERVISOR | _PAGE_USER);
-    l2_ro_mpt += l2_table_offset(RO_MPT_VIRT_START);
 
     /*
      * Allocate and map the machine-to-phys table.
@@ -110,10 +104,20 @@ void __init paging_init(void)
             PAGE_HYPERVISOR);
         memset((void *)(RDWR_MPT_VIRT_START + (i << L2_PAGETABLE_SHIFT)), 0x55,
                1UL << L2_PAGETABLE_SHIFT);
+        if ( !((unsigned long)l2_ro_mpt & ~PAGE_MASK) )
+        {
+            unsigned long va = RO_MPT_VIRT_START + (i << L2_PAGETABLE_SHIFT);
+
+            l2_ro_mpt = alloc_xenheap_page();
+            clear_page(l2_ro_mpt);
+            l3_ro_mpt[l3_table_offset(va)] =
+                l3e_from_page(
+                    virt_to_page(l2_ro_mpt), __PAGE_HYPERVISOR | _PAGE_USER);
+            l2_ro_mpt += l2_table_offset(va);
+        }
         /* NB. Cannot be GLOBAL as shadow_mode_translate reuses this area. */
         *l2_ro_mpt++ = l2e_from_page(
             pg, /*_PAGE_GLOBAL|*/_PAGE_PSE|_PAGE_USER|_PAGE_PRESENT);
-        BUG_ON(((unsigned long)l2_ro_mpt & ~PAGE_MASK) == 0);
     }
 
     /* Set up linear page table mapping. */