ia64/xen-unstable

changeset 15062:6e597e529fea

[BUILDER] Ensure that the L3 page table page for a PAE guest which does not
support the extended-cr3 format is below the 4G boundary.

Signed-off-by: Ian Campbell <ian.campbell@xensource.com>
author Ian Campbell <ian.campbell@xensource.com>
date Wed May 09 18:53:02 2007 +0100 (2007-05-09)
parents 8df600f56acd
children 2b80a4a4020e
files tools/libxc/xc_dom_x86.c
line diff
     1.1 --- a/tools/libxc/xc_dom_x86.c	Wed May 09 15:31:37 2007 +0100
     1.2 +++ b/tools/libxc/xc_dom_x86.c	Wed May 09 18:53:02 2007 +0100
     1.3 @@ -153,17 +153,98 @@ static int setup_pgtables_x86_32(struct 
     1.4      return 0;
     1.5  }
     1.6  
     1.7 +/*
     1.8 + * Move the l3 page table page below 4G for guests which do not
     1.9 + * support the extended-cr3 format.  The l3 is currently empty so we
    1.10 + * do not need to preserve the current contents.
    1.11 + */
    1.12 +static xen_pfn_t move_l3_below_4G(struct xc_dom_image *dom,
    1.13 +                                  xen_pfn_t l3pfn,
    1.14 +                                  xen_pfn_t l3mfn)
    1.15 +{
    1.16 +    xen_pfn_t new_l3mfn;
    1.17 +    struct xc_mmu *mmu;
    1.18 +    void *l3tab;
    1.19 +    int xc = dom->guest_xc;
    1.20 +
    1.21 +    mmu = xc_alloc_mmu_updates(xc, dom->guest_domid);
    1.22 +    if ( mmu == NULL )
    1.23 +    {
    1.24 +        xc_dom_printf("%s: failed at %d\n", __FUNCTION__, __LINE__);
    1.25 +        return l3mfn;
    1.26 +    }
    1.27 +
    1.28 +    xc_dom_unmap_one(dom, l3pfn);
    1.29 +
    1.30 +    new_l3mfn = xc_make_page_below_4G(dom->guest_xc, dom->guest_domid, l3mfn);
    1.31 +    if ( !new_l3mfn )
    1.32 +        goto out;
    1.33 +
    1.34 +    dom->p2m_host[l3pfn] = new_l3mfn;
    1.35 +    if ( xc_dom_update_guest_p2m(dom) != 0 )
    1.36 +        goto out;
    1.37 +
    1.38 +    if ( xc_add_mmu_update(xc, mmu,
    1.39 +                           (((unsigned long long)new_l3mfn)
    1.40 +                            << XC_DOM_PAGE_SHIFT(dom)) |
    1.41 +                           MMU_MACHPHYS_UPDATE, l3pfn) )
    1.42 +        goto out;
    1.43 +
    1.44 +    if ( xc_flush_mmu_updates(xc, mmu) )
    1.45 +        goto out;
    1.46 +
    1.47 +    /*
    1.48 +     * This ensures that the entire pgtables_seg is mapped by a single
    1.49 +     * mmap region. arch_setup_bootlate() relies on this to be able to
    1.50 +     * unmap and pin the pagetables.
    1.51 +     */
    1.52 +    if ( xc_dom_seg_to_ptr(dom, &dom->pgtables_seg) == NULL )
    1.53 +        goto out;
    1.54 +
    1.55 +    l3tab = xc_dom_pfn_to_ptr(dom, l3pfn, 1);
    1.56 +    memset(l3tab, 0, XC_DOM_PAGE_SIZE(dom));
    1.57 +
    1.58 +    xc_dom_printf("%s: successfully relocated L3 below 4G. "
    1.59 +                  "(L3 PFN %#"PRIpfn" MFN %#"PRIpfn"=>%#"PRIpfn")\n",
    1.60 +                  __FUNCTION__, l3pfn, l3mfn, new_l3mfn);
    1.61 +
    1.62 +    l3mfn = new_l3mfn;
    1.63 +
    1.64 + out:
    1.65 +    free(mmu);
    1.66 +
    1.67 +    return l3mfn;
    1.68 +}
    1.69 +
    1.70  static int setup_pgtables_x86_32_pae(struct xc_dom_image *dom)
    1.71  {
    1.72      xen_pfn_t l3pfn = dom->pgtables_seg.pfn;
    1.73      xen_pfn_t l2pfn = dom->pgtables_seg.pfn + dom->pg_l3;
    1.74      xen_pfn_t l1pfn = dom->pgtables_seg.pfn + dom->pg_l3 + dom->pg_l2;
    1.75 -    l3_pgentry_64_t *l3tab = xc_dom_pfn_to_ptr(dom, l3pfn, 1);
    1.76 +    l3_pgentry_64_t *l3tab;
    1.77      l2_pgentry_64_t *l2tab = NULL;
    1.78      l1_pgentry_64_t *l1tab = NULL;
    1.79      unsigned long l3off, l2off, l1off;
    1.80      xen_vaddr_t addr;
    1.81      xen_pfn_t pgpfn;
    1.82 +    xen_pfn_t l3mfn = xc_dom_p2m_guest(dom, l3pfn);
    1.83 +
    1.84 +    if ( dom->parms.pae == 1 )
    1.85 +    {
    1.86 +        if ( l3mfn >= 0x100000 )
    1.87 +            l3mfn = move_l3_below_4G(dom, l3pfn, l3mfn);
    1.88 +
    1.89 +        if ( l3mfn >= 0x100000 )
    1.90 +        {
    1.91 +            xc_dom_panic(XC_INTERNAL_ERROR,"%s: cannot move L3 below 4G. "
    1.92 +                         "extended-cr3 not supported by guest. "
    1.93 +                         "(L3 PFN %#"PRIpfn" MFN %#"PRIpfn")\n",
    1.94 +                         __FUNCTION__, l3pfn, l3mfn);
    1.95 +            return -EINVAL;
    1.96 +        }
    1.97 +    }
    1.98 +
    1.99 +    l3tab = xc_dom_pfn_to_ptr(dom, l3pfn, 1);
   1.100  
   1.101      for ( addr = dom->parms.virt_base; addr < dom->virt_pgtab_end;
   1.102            addr += PAGE_SIZE_X86 )