ia64/xen-unstable

changeset 12883:bc3044bf4928

[IA64] xc_ia64_linux_restore fix for new foreign domain page mapping semantics

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
author awilliam@xenbuild2.aw
date Thu Dec 07 15:00:49 2006 -0700 (2006-12-07)
parents 566e0e95cf00
children 45f79978ceb5
files tools/libxc/ia64/xc_ia64_linux_restore.c
line diff
     1.1 --- a/tools/libxc/ia64/xc_ia64_linux_restore.c	Thu Dec 07 14:56:01 2006 -0700
     1.2 +++ b/tools/libxc/ia64/xc_ia64_linux_restore.c	Thu Dec 07 15:00:49 2006 -0700
     1.3 @@ -63,7 +63,7 @@ xc_linux_restore(int xc_handle, int io_f
     1.4  {
     1.5      DECLARE_DOMCTL;
     1.6      int rc = 1, i;
     1.7 -    unsigned long mfn, pfn;
     1.8 +    unsigned long gmfn;
     1.9      unsigned long ver;
    1.10  
    1.11      /* The new domain's shared-info frame number. */
    1.12 @@ -99,28 +99,29 @@ xc_linux_restore(int xc_handle, int io_f
    1.13          return 1;
    1.14      }
    1.15  
    1.16 -    /* Get the domain's shared-info frame. */
    1.17 -    domctl.cmd = XEN_DOMCTL_getdomaininfo;
    1.18 -    domctl.domain = (domid_t)dom;
    1.19 -    if (xc_domctl(xc_handle, &domctl) < 0) {
    1.20 -        ERROR("Could not get information on new domain");
    1.21 -        goto out;
    1.22 -    }
    1.23 -    shared_info_frame = domctl.u.getdomaininfo.shared_info_frame;
    1.24 -
    1.25      if (xc_domain_setmaxmem(xc_handle, dom, PFN_TO_KB(max_pfn)) != 0) {
    1.26          errno = ENOMEM;
    1.27          goto out;
    1.28      }
    1.29  
    1.30 -    if (xc_domain_memory_increase_reservation(xc_handle, dom, max_pfn,
    1.31 -                                              0, 0, NULL) != 0) {
    1.32 -        ERROR("Failed to increase reservation by %ld KB", PFN_TO_KB(max_pfn));
    1.33 -        errno = ENOMEM;
    1.34 +    /* Get pages.  */
    1.35 +    page_array = malloc(max_pfn * sizeof(unsigned long));
    1.36 +    if (page_array == NULL) {
    1.37 +        ERROR("Could not allocate memory");
    1.38          goto out;
    1.39      }
    1.40  
    1.41 -    DPRINTF("Increased domain reservation by %ld KB\n", PFN_TO_KB(max_pfn));
    1.42 +    for ( i = 0; i < max_pfn; i++ )
    1.43 +        page_array[i] = i;
    1.44 +
    1.45 +    if ( xc_domain_memory_populate_physmap(xc_handle, dom, max_pfn,
    1.46 +                                           0, 0, page_array) )
    1.47 +    {
    1.48 +        ERROR("Failed to allocate memory for %ld KB to dom %d.\n",
    1.49 +              PFN_TO_KB(max_pfn), dom);
    1.50 +        goto out;
    1.51 +    }
    1.52 +    DPRINTF("Allocated memory by %ld KB\n", PFN_TO_KB(max_pfn));
    1.53  
    1.54      if (!read_exact(io_fd, &domctl.u.arch_setup, sizeof(domctl.u.arch_setup))) {
    1.55          ERROR("read: domain setup");
    1.56 @@ -138,34 +139,28 @@ xc_linux_restore(int xc_handle, int io_f
    1.57      if (xc_domctl(xc_handle, &domctl))
    1.58          goto out;
    1.59  
    1.60 -    /* Get pages.  */
    1.61 -    page_array = malloc(max_pfn * sizeof(unsigned long));
    1.62 -    if (page_array == NULL ) {
    1.63 -        ERROR("Could not allocate memory");
    1.64 +    /* Get the domain's shared-info frame. */
    1.65 +    domctl.cmd = XEN_DOMCTL_getdomaininfo;
    1.66 +    domctl.domain = (domid_t)dom;
    1.67 +    if (xc_domctl(xc_handle, &domctl) < 0) {
    1.68 +        ERROR("Could not get information on new domain");
    1.69          goto out;
    1.70      }
    1.71 -
    1.72 -    if (xc_ia64_get_pfn_list(xc_handle, dom, page_array,
    1.73 -                             0, max_pfn) != max_pfn) {
    1.74 -        ERROR("Could not get the page frame list");
    1.75 -        goto out;
    1.76 -    }
    1.77 +    shared_info_frame = domctl.u.getdomaininfo.shared_info_frame;
    1.78  
    1.79      DPRINTF("Reloading memory pages:   0%%\n");
    1.80  
    1.81      while (1) {
    1.82 -        if (!read_exact(io_fd, &mfn, sizeof(unsigned long))) {
    1.83 +        if (!read_exact(io_fd, &gmfn, sizeof(unsigned long))) {
    1.84              ERROR("Error when reading batch size");
    1.85              goto out;
    1.86          }
    1.87 -	if (mfn == INVALID_MFN)
    1.88 +	if (gmfn == INVALID_MFN)
    1.89  		break;
    1.90  
    1.91 -	pfn = page_array[mfn];
    1.92 +       //DPRINTF("xc_linux_restore: page %lu/%lu at %lx\n", gmfn, max_pfn, pfn);
    1.93  
    1.94 -        //DPRINTF("xc_linux_restore: page %lu/%lu at %lx\n", mfn, max_pfn, pfn);
    1.95 -
    1.96 -	if (read_page(xc_handle, io_fd, dom, page_array[mfn]) < 0)
    1.97 +	if (read_page(xc_handle, io_fd, dom, gmfn) < 0)
    1.98  		goto out;
    1.99      }
   1.100  
   1.101 @@ -279,19 +274,19 @@ xc_linux_restore(int xc_handle, int io_f
   1.102      for (i = 0; i < MAX_VIRT_CPUS; i++)
   1.103          shared_info->vcpu_info[i].evtchn_pending_sel = 0;
   1.104  
   1.105 -    mfn = page_array[shared_info->arch.start_info_pfn];
   1.106 +    gmfn = shared_info->arch.start_info_pfn;
   1.107  
   1.108      munmap (shared_info, PAGE_SIZE);
   1.109  
   1.110      /* Uncanonicalise the suspend-record frame number and poke resume rec. */
   1.111      start_info = xc_map_foreign_range(xc_handle, dom, PAGE_SIZE,
   1.112 -                                      PROT_READ | PROT_WRITE, mfn);
   1.113 +                                      PROT_READ | PROT_WRITE, gmfn);
   1.114      start_info->nr_pages = max_pfn;
   1.115      start_info->shared_info = shared_info_frame << PAGE_SHIFT;
   1.116      start_info->flags = 0;
   1.117 -    *store_mfn = page_array[start_info->store_mfn];
   1.118 +    *store_mfn = start_info->store_mfn;
   1.119      start_info->store_evtchn = store_evtchn;
   1.120 -    *console_mfn = page_array[start_info->console.domU.mfn];
   1.121 +    *console_mfn = start_info->console.domU.mfn;
   1.122      start_info->console.domU.evtchn = console_evtchn;
   1.123      munmap(start_info, PAGE_SIZE);
   1.124  
   1.125 @@ -315,7 +310,8 @@ xc_linux_restore(int xc_handle, int io_f
   1.126      if ((rc != 0) && (dom != 0))
   1.127          xc_domain_destroy(xc_handle, dom);
   1.128  
   1.129 -    free (page_array);
   1.130 +    if (page_array != NULL)
   1.131 +	    free(page_array);
   1.132  
   1.133      DPRINTF("Restore exit with rc=%d\n", rc);
   1.134