ia64/xen-unstable

changeset 10121:d081a485f34b

[BUILDER] Always build initial PAE pagetables with a fourth mid-level
pgdir. This is required for Xen to be able to insert its own protected
mappings. At the same time, clean up 32b and pae pagetable-size
calculations to use the helper macro already used for x86/64.

Based on an original patch from Bruce Rogers at Novell.

Signed-off-by: Keir Fraser <keir@xensource.com>
author kaf24@firebug.cl.cam.ac.uk
date Sat May 20 16:25:28 2006 +0100 (2006-05-20)
parents ab27023d4c5b
children 4dcb93547710
files tools/libxc/xc_linux_build.c
line diff
     1.1 --- a/tools/libxc/xc_linux_build.c	Fri May 19 22:08:32 2006 +0100
     1.2 +++ b/tools/libxc/xc_linux_build.c	Sat May 20 16:25:28 2006 +0100
     1.3 @@ -329,6 +329,13 @@ static int setup_pg_tables_pae(int xc_ha
     1.4          vl1e++;
     1.5      }
     1.6  
     1.7 +    /* Xen requires a mid-level pgdir mapping 0xC0000000 region. */
     1.8 +    if ( (vl3tab[3] & _PAGE_PRESENT) == 0 )
     1.9 +    {
    1.10 +        alloc_pt(l2tab, vl2tab, pl2tab);
    1.11 +        vl3tab[3] = l2tab | L3_PROT;
    1.12 +    }
    1.13 +
    1.14      munmap(vl1tab, PAGE_SIZE);
    1.15      munmap(vl2tab, PAGE_SIZE);
    1.16      munmap(vl3tab, PAGE_SIZE);
    1.17 @@ -727,25 +734,28 @@ static int setup_guest(int xc_handle,
    1.18          v_end            = (vstack_end + (1UL<<22)-1) & ~((1UL<<22)-1);
    1.19          if ( (v_end - vstack_end) < (512UL << 10) )
    1.20              v_end += 1UL << 22; /* Add extra 4MB to get >= 512kB padding. */
    1.21 +#define NR(_l,_h,_s) \
    1.22 +    (((((_h) + ((1UL<<(_s))-1)) & ~((1UL<<(_s))-1)) - \
    1.23 +    ((_l) & ~((1UL<<(_s))-1))) >> (_s))
    1.24  #if defined(__i386__)
    1.25          if ( dsi.pae_kernel )
    1.26          {
    1.27 -            /* FIXME: assumes one L2 pgtable @ 0xc0000000 */
    1.28 -            if ( (((v_end - dsi.v_start + ((1<<L2_PAGETABLE_SHIFT_PAE)-1)) >>
    1.29 -                   L2_PAGETABLE_SHIFT_PAE) + 2) <= nr_pt_pages )
    1.30 +            if ( (1 + /* # L3 */
    1.31 +                  NR(dsi.v_start, v_end, L3_PAGETABLE_SHIFT_PAE) + /* # L2 */
    1.32 +                  NR(dsi.v_start, v_end, L2_PAGETABLE_SHIFT_PAE) + /* # L1 */
    1.33 +                  /* Include a fourth mid-level page directory for Xen. */
    1.34 +                  (v_end <= (3 << L3_PAGETABLE_SHIFT_PAE)))
    1.35 +                  <= nr_pt_pages )
    1.36                  break;
    1.37          }
    1.38          else
    1.39          {
    1.40 -            if ( (((v_end - dsi.v_start + ((1<<L2_PAGETABLE_SHIFT)-1)) >>
    1.41 -                   L2_PAGETABLE_SHIFT) + 1) <= nr_pt_pages )
    1.42 +            if ( (1 + /* # L2 */
    1.43 +                  NR(dsi.v_start, v_end, L2_PAGETABLE_SHIFT)) /* # L1 */
    1.44 +                 <= nr_pt_pages )
    1.45                  break;
    1.46          }
    1.47 -#endif
    1.48 -#if defined(__x86_64__)
    1.49 -#define NR(_l,_h,_s) \
    1.50 -    (((((_h) + ((1UL<<(_s))-1)) & ~((1UL<<(_s))-1)) - \
    1.51 -    ((_l) & ~((1UL<<(_s))-1))) >> (_s))
    1.52 +#elif defined(__x86_64__)
    1.53          if ( (1 + /* # L4 */
    1.54                NR(dsi.v_start, v_end, L4_PAGETABLE_SHIFT) + /* # L3 */
    1.55                NR(dsi.v_start, v_end, L3_PAGETABLE_SHIFT) + /* # L2 */