ia64/xen-unstable

changeset 14238:f56981f78d73

[POWERPC][XEN] Implement guest_physmap_max_mem_pages().
- Create a p2m array large enough to cover d->max_pages.
- Free in domain_relinquish_resources().
Signed-off-by: Ryan Harper <ryanh@us.ibm.com>
Signed-off-by: Hollis Blanchard <hollisb@us.ibm.com>
author Hollis Blanchard <hollisb@us.ibm.com>
date Fri Mar 02 17:07:01 2007 -0600 (2007-03-02)
parents eceb9ccd84a8
children b75609e1fa81
files xen/arch/powerpc/domain.c xen/arch/powerpc/mm.c xen/include/asm-powerpc/domain.h xen/include/asm-powerpc/mm.h xen/include/asm-powerpc/shadow.h
line diff
     1.1 --- a/xen/arch/powerpc/domain.c	Fri Mar 02 17:06:50 2007 -0600
     1.2 +++ b/xen/arch/powerpc/domain.c	Fri Mar 02 17:07:01 2007 -0600
     1.3 @@ -16,6 +16,8 @@
     1.4   * Copyright IBM Corp. 2005, 2006, 2007
     1.5   *
     1.6   * Authors: Jimi Xenidis <jimix@watson.ibm.com>
     1.7 + *          Ryan Harper <ryanh@us.ibm.com>
     1.8 + *          Hollis Blanchard <hollisb@us.ibm.com>
     1.9   */
    1.10  
    1.11  #include <stdarg.h>
    1.12 @@ -311,6 +313,7 @@ void domain_relinquish_resources(struct 
    1.13      relinquish_memory(d, &d->page_list);
    1.14      free_extents(d);
    1.15      xfree(d->arch.foreign_mfns);
    1.16 +    xfree(d->arch.p2m);
    1.17      return;
    1.18  }
    1.19  
     2.1 --- a/xen/arch/powerpc/mm.c	Fri Mar 02 17:06:50 2007 -0600
     2.2 +++ b/xen/arch/powerpc/mm.c	Fri Mar 02 17:07:01 2007 -0600
     2.3 @@ -536,6 +536,47 @@ unsigned long mfn_to_gmfn(struct domain 
     2.4      return INVALID_M2P_ENTRY;
     2.5  }
     2.6  
     2.7 +/* NB: caller holds d->page_alloc lock, sets d->max_pages = new_max */
     2.8 +int guest_physmap_max_mem_pages(struct domain *d, unsigned long new_max_pages)
     2.9 +{
    2.10 +    u32 *p2m_array = NULL;
    2.11 +    u32 *p2m_old = NULL;
    2.12 +    ulong i;
    2.13 +
    2.14 +    /* XXX We probably could, but right now we don't shrink the p2m array.
    2.15 +     * NB: d->max_pages >= d->arch.p2m_entries */
    2.16 +    if (new_max_pages < d->max_pages) {
    2.17 +        printk("Can't shrink DOM%d max memory pages\n", d->domain_id);
    2.18 +        return -EINVAL;
    2.19 +    }
    2.20 +
    2.21 +    /* Allocate one u32 per page. */
    2.22 +    p2m_array = xmalloc_array(u32, new_max_pages);
    2.23 +    if (p2m_array == NULL)
    2.24 +        return -ENOMEM;
    2.25 +
    2.26 +    /* Copy old mappings into new array. */
    2.27 +    if (d->arch.p2m != NULL) {
    2.28 +        /* XXX This could take a long time; we should use a continuation. */
    2.29 +        memcpy(p2m_array, d->arch.p2m, d->arch.p2m_entries * sizeof(u32));
    2.30 +        p2m_old = d->arch.p2m;
    2.31 +    }
    2.32 +
    2.33 +    /* Mark new mfns as invalid. */
    2.34 +    for (i = d->arch.p2m_entries; i < new_max_pages; i++)
    2.35 +        p2m_array[i] = INVALID_MFN;
    2.36 +
    2.37 +    /* Set new p2m pointer and size. */
    2.38 +    d->arch.p2m = p2m_array;
    2.39 +    d->arch.p2m_entries = new_max_pages;
    2.40 +
    2.41 +    /* Free old p2m array if present. */
    2.42 +    if (p2m_old)
    2.43 +        xfree(p2m_old);
    2.44 +
    2.45 +    return 0;
    2.46 +}
    2.47 +
    2.48  void guest_physmap_add_page(
    2.49      struct domain *d, unsigned long gpfn, unsigned long mfn)
    2.50  {
     3.1 --- a/xen/include/asm-powerpc/domain.h	Fri Mar 02 17:06:50 2007 -0600
     3.2 +++ b/xen/include/asm-powerpc/domain.h	Fri Mar 02 17:07:01 2007 -0600
     3.3 @@ -13,7 +13,7 @@
     3.4   * along with this program; if not, write to the Free Software
     3.5   * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
     3.6   *
     3.7 - * Copyright (C) IBM Corp. 2005
     3.8 + * Copyright IBM Corp. 2005, 2007
     3.9   *
    3.10   * Authors: Hollis Blanchard <hollisb@us.ibm.com>
    3.11   */
    3.12 @@ -47,6 +47,9 @@ struct arch_domain {
    3.13      /* I/O-port access bitmap mask. */
    3.14      u8 *iobmp_mask;       /* Address of IO bitmap mask, or NULL.      */
    3.15  
    3.16 +    u32 *p2m; /* Array of 32-bit MFNs supports 44 bits of physical memory. */
    3.17 +    ulong p2m_entries;
    3.18 +
    3.19      uint large_page_sizes;
    3.20      uint large_page_order[4];
    3.21  } __cacheline_aligned;
     4.1 --- a/xen/include/asm-powerpc/mm.h	Fri Mar 02 17:06:50 2007 -0600
     4.2 +++ b/xen/include/asm-powerpc/mm.h	Fri Mar 02 17:07:01 2007 -0600
     4.3 @@ -239,7 +239,9 @@ extern unsigned long mfn_to_gmfn(struct 
     4.4  
     4.5  extern unsigned long paddr_to_maddr(unsigned long paddr);
     4.6  
     4.7 -#define INVALID_MFN (~0UL)
     4.8 +/* INVALID_MFN can be any value that fails mfn_valid(). */
     4.9 +#define INVALID_MFN (~0U)
    4.10 +
    4.11  #define PFN_TYPE_NONE 0
    4.12  #define PFN_TYPE_RMA 1
    4.13  #define PFN_TYPE_LOGICAL 2
     5.1 --- a/xen/include/asm-powerpc/shadow.h	Fri Mar 02 17:06:50 2007 -0600
     5.2 +++ b/xen/include/asm-powerpc/shadow.h	Fri Mar 02 17:07:01 2007 -0600
     5.3 @@ -32,6 +32,8 @@
     5.4        ? machine_to_phys_mapping[(mfn)]                 \
     5.5        : (mfn) )
     5.6  
     5.7 +extern int guest_physmap_max_mem_pages(struct domain *d, unsigned long new_max);
     5.8 +
     5.9  extern void guest_physmap_add_page(
    5.10      struct domain *d, unsigned long gpfn, unsigned long mfn);
    5.11  
    5.12 @@ -60,7 +62,5 @@ static inline unsigned int shadow_get_al
    5.13      return (1ULL << (d->arch.htab.order + PAGE_SHIFT)) >> 20;
    5.14  }
    5.15  
    5.16 -#define guest_physmap_max_mem_pages(d, n) (0)
    5.17 -
    5.18  #endif
    5.19