ia64/xen-unstable

changeset 14240:4c08045ff57c

[POWERPC][XEN][LIBXC] Make xc_linux_build() use populate_physmap()
- populate_physmap() is the only way to invoke
guest_physmap_{add/remove}_page(), which populate our new p2m table.
- To use it, we must to specify an array of PFNs where the new MFNs will be
mapped.
- Split out alloc_memory() from xc_linux_build().
- Fix memory free path in xc_linux_build().
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:08:04 2007 -0600 (2007-03-02)
parents b75609e1fa81
children 38b700cca5eb
files tools/libxc/powerpc64/xc_linux_build.c
line diff
     1.1 --- a/tools/libxc/powerpc64/xc_linux_build.c	Fri Mar 02 17:07:59 2007 -0600
     1.2 +++ b/tools/libxc/powerpc64/xc_linux_build.c	Fri Mar 02 17:08:04 2007 -0600
     1.3 @@ -39,6 +39,10 @@
     1.4  #include "utils.h"
     1.5  #include "mk_flatdevtree.h"
     1.6  
     1.7 +/* Use 16MB extents to match PowerPC's large page size. */
     1.8 +#define EXTENT_SHIFT 24
     1.9 +#define EXTENT_ORDER (EXTENT_SHIFT - PAGE_SHIFT)
    1.10 +
    1.11  #define INITRD_ADDR (24UL << 20)
    1.12  #define DEVTREE_ADDR (16UL << 20)
    1.13  
    1.14 @@ -150,6 +154,50 @@ static int check_memory_config(int rma_l
    1.15      return 1;
    1.16  }
    1.17  
    1.18 +static int alloc_memory(int xc_handle, domid_t domid, ulong nr_pages,
    1.19 +                        ulong rma_pages)
    1.20 +{
    1.21 +    xen_pfn_t *extent_pfn_arry;
    1.22 +    ulong nr_extents;
    1.23 +    ulong start_pfn = rma_pages;
    1.24 +    int i;
    1.25 +    int j;
    1.26 +    int rc = 0;
    1.27 +
    1.28 +    nr_extents = (nr_pages - rma_pages) >> EXTENT_ORDER;
    1.29 +    DPRINTF("allocating memory in %lu chunks of %luMB\n", nr_extents,
    1.30 +            1UL >> (20 - EXTENT_ORDER));
    1.31 +
    1.32 +    /* populate_physmap requires an array of PFNs that determine where the
    1.33 +     * guest mapping of the new MFNs. */
    1.34 +    extent_pfn_arry = malloc((1<<EXTENT_ORDER) * sizeof(xen_pfn_t));
    1.35 +    if (extent_pfn_arry == NULL) {
    1.36 +        PERROR("Couldn't allocate extent PFN array.\n");
    1.37 +        return -ENOMEM;
    1.38 +    }
    1.39 +
    1.40 +    /* Now allocate the remaining memory as large-order extents. */
    1.41 +    for (i = 0; i < nr_extents; i++) {
    1.42 +        /* Initialize the extent PFN array. */
    1.43 +        for (j = 0; j < (1 << EXTENT_ORDER); j++)
    1.44 +            extent_pfn_arry[j] = start_pfn++;
    1.45 +
    1.46 +        DPRINTF("populate_physmap(Dom%u, order %u, starting_pfn %llx)\n",
    1.47 +                domid, EXTENT_ORDER, extent_pfn_arry[0]);
    1.48 +
    1.49 +        if (xc_domain_memory_populate_physmap(xc_handle, domid, 1, EXTENT_ORDER,
    1.50 +                                               0, extent_pfn_arry))
    1.51 +        {
    1.52 +            PERROR("Could not allocate extents\n");
    1.53 +            rc = -1;
    1.54 +            break;
    1.55 +        }
    1.56 +    }
    1.57 +
    1.58 +    free(extent_pfn_arry);
    1.59 +    return rc;
    1.60 +}
    1.61 +
    1.62  int xc_linux_build(int xc_handle,
    1.63                     uint32_t domid,
    1.64                     unsigned int mem_mb,
    1.65 @@ -175,9 +223,6 @@ int xc_linux_build(int xc_handle,
    1.66      u64 shared_info_paddr;
    1.67      u64 store_paddr;
    1.68      u64 console_paddr;
    1.69 -    u32 remaining_kb;
    1.70 -    u32 extent_order;
    1.71 -    u64 nr_extents;
    1.72      int rma_log = 26;  /* 64MB RMA */
    1.73      int rc = 0;
    1.74      int op;
    1.75 @@ -200,36 +245,26 @@ int xc_linux_build(int xc_handle,
    1.76          goto out;
    1.77      }
    1.78      
    1.79 -    /* alloc RMA */
    1.80 +    /* Allocate the RMA. */
    1.81 +    DPRINTF("RMA: 0x%lx pages\n", rma_pages);
    1.82      if (xc_alloc_real_mode_area(xc_handle, domid, rma_log)) {
    1.83          rc = -1;
    1.84          goto out;
    1.85      }
    1.86  
    1.87 -    /* subtract already allocated RMA to determine remaining KB to alloc */
    1.88 -    remaining_kb = (nr_pages - rma_pages) * (PAGE_SIZE / 1024);
    1.89 -    DPRINTF("totalmem - RMA = %dKB\n", remaining_kb);
    1.90 -
    1.91 -    /* to allocate in 16MB chunks, we need to determine the order of 
    1.92 -     * the number of PAGE_SIZE pages contained in 16MB. */
    1.93 -    extent_order = 24 - 12; /* extent_order = log2((1 << 24) - (1 << 12)) */
    1.94 -    nr_extents = (remaining_kb / (PAGE_SIZE/1024)) >> extent_order;
    1.95 -    DPRINTF("allocating memory in %llu chunks of %luMB\n", nr_extents,
    1.96 -            (((1 << extent_order) >> 10) * PAGE_SIZE) >> 10);
    1.97 -
    1.98 -    /* now allocate the remaining memory as large-order allocations */
    1.99 -    DPRINTF("increase_reservation(%u, %llu, %u)\n", domid, nr_extents, extent_order);
   1.100 -    if (xc_domain_memory_increase_reservation(xc_handle, domid, nr_extents, 
   1.101 -                                              extent_order, 0, NULL)) {
   1.102 -        rc = -1;
   1.103 -        goto out;
   1.104 -    }
   1.105 -
   1.106 +    /* Get the MFN mapping (for RMA only -- we only load data into the RMA). */
   1.107      if (get_rma_page_array(xc_handle, domid, &page_array, rma_pages)) {
   1.108          rc = -1;
   1.109          goto out;
   1.110      }
   1.111  
   1.112 +    /* Allocate the non-RMA memory. */
   1.113 +    rc = alloc_memory(xc_handle, domid, nr_pages, rma_pages);
   1.114 +    if (rc) {
   1.115 +        goto out;
   1.116 +    }
   1.117 +
   1.118 +    /* Load kernel. */
   1.119      DPRINTF("loading image '%s'\n", image_name);
   1.120      if (load_elf_kernel(xc_handle, domid, image_name, &dsi, page_array)) {
   1.121          rc = -1;
   1.122 @@ -237,6 +272,7 @@ int xc_linux_build(int xc_handle,
   1.123      }
   1.124      kern_addr = 0;
   1.125  
   1.126 +    /* Load initrd. */
   1.127      if (initrd_name && initrd_name[0] != '\0') {
   1.128          DPRINTF("loading initrd '%s'\n", initrd_name);
   1.129          if (load_initrd(xc_handle, domid, page_array, initrd_name,
   1.130 @@ -249,7 +285,7 @@ int xc_linux_build(int xc_handle,
   1.131      /* fetch the current shadow_memory value for this domain */
   1.132      op = XEN_DOMCTL_SHADOW_OP_GET_ALLOCATION;
   1.133      if (xc_shadow_control(xc_handle, domid, op, NULL, 0, 
   1.134 -                          &shadow_mb, 0, NULL) < 0 ) {
   1.135 +                          &shadow_mb, 0, NULL) < 0) {
   1.136          rc = -1;
   1.137          goto out;
   1.138      }
   1.139 @@ -284,16 +320,17 @@ int xc_linux_build(int xc_handle,
   1.140                        devtree_addr, devtree.bph->totalsize)) {
   1.141          DPRINTF("couldn't load flattened device tree.\n");
   1.142          rc = -1;
   1.143 -        goto out;
   1.144 +        goto out2;
   1.145      }
   1.146  
   1.147      if (init_boot_vcpu(xc_handle, domid, &dsi, devtree_addr, kern_addr)) {
   1.148          rc = -1;
   1.149 -        goto out;
   1.150 +        goto out2;
   1.151      }
   1.152  
   1.153 +out2:
   1.154 +    free_devtree(&devtree);
   1.155  out:
   1.156 -    free_devtree(&devtree);
   1.157      free_page_array(page_array);
   1.158      return rc;
   1.159  }