direct-io.hg

changeset 13826:780f097b54c5

[HVM] Save/restore: don't try to save the MMIO memory-hole at 4GB.
Also remove two integer arrays that were set to a[i] == i.
Signed-off-by: Tim Deegan <Tim.Deegan@xensource.com>
author Tim Deegan <Tim.Deegan@xensource.com>
date Wed Feb 07 17:29:52 2007 +0000 (2007-02-07)
parents ce97d6714be4
children 6524e02edbeb
files tools/libxc/xc_hvm_save.c
line diff
     1.1 --- a/tools/libxc/xc_hvm_save.c	Wed Feb 07 17:29:21 2007 +0000
     1.2 +++ b/tools/libxc/xc_hvm_save.c	Wed Feb 07 17:29:52 2007 +0000
     1.3 @@ -27,6 +27,7 @@
     1.4  #include <stdlib.h>
     1.5  #include <unistd.h>
     1.6  #include <sys/time.h>
     1.7 +#include <xen/hvm/e820.h>
     1.8  
     1.9  #include "xc_private.h"
    1.10  #include "xg_private.h"
    1.11 @@ -275,9 +276,8 @@ int xc_hvm_save(int xc_handle, int io_fd
    1.12      /* A copy of the CPU context of the guest. */
    1.13      vcpu_guest_context_t ctxt;
    1.14  
    1.15 -    /* A table containg the type of each PFN (/not/ MFN!). */
    1.16 -    unsigned long *pfn_type = NULL;
    1.17 -    unsigned long *pfn_batch = NULL;
    1.18 +    /* A table containg the PFNs (/not/ MFN!) to map. */
    1.19 +    xen_pfn_t *pfn_batch = NULL;
    1.20  
    1.21      /* A copy of hvm domain context buffer*/
    1.22      uint32_t hvm_buf_size;
    1.23 @@ -290,7 +290,6 @@ int xc_hvm_save(int xc_handle, int io_fd
    1.24      unsigned char *region_base = NULL;
    1.25  
    1.26      uint32_t nr_pfns, rec_size, nr_vcpus;
    1.27 -    unsigned long *page_array = NULL;
    1.28  
    1.29      /* power of 2 order of max_pfn */
    1.30      int order_nr;
    1.31 @@ -361,18 +360,12 @@ int xc_hvm_save(int xc_handle, int io_fd
    1.32          goto out;
    1.33      }
    1.34  
    1.35 -    max_pfn = live_shinfo->arch.max_pfn;
    1.36 -
    1.37      DPRINTF("saved hvm domain info:max_memkb=0x%lx, max_mfn=0x%lx, nr_pages=0x%lx\n", info.max_memkb, max_mfn, info.nr_pages); 
    1.38  
    1.39 -    /* nr_pfns: total pages excluding vga acc mem
    1.40 -     * max_pfn: nr_pfns + 0x20 vga hole(0xa0~0xc0)
    1.41 -     * getdomaininfo.tot_pages: all the allocated pages for this domain
    1.42 -     */
    1.43      if (live) {
    1.44          ERROR("hvm domain doesn't support live migration now.\n");
    1.45          goto out;
    1.46 -
    1.47 +        
    1.48          if (xc_shadow_control(xc_handle, dom,
    1.49                                XEN_DOMCTL_SHADOW_OP_ENABLE_LOGDIRTY,
    1.50                                NULL, 0, NULL, 0, NULL) < 0) {
    1.51 @@ -381,6 +374,7 @@ int xc_hvm_save(int xc_handle, int io_fd
    1.52          }
    1.53  
    1.54          /* excludes vga acc mem */
    1.55 +        /* XXX will need to check whether acceleration is enabled here! */
    1.56          nr_pfns = info.nr_pages - 0x800;
    1.57  
    1.58          last_iter = 0;
    1.59 @@ -396,8 +390,8 @@ int xc_hvm_save(int xc_handle, int io_fd
    1.60              ERROR("HVM Domain appears not to have suspended");
    1.61              goto out;
    1.62          }
    1.63 -        nr_pfns = info.nr_pages;
    1.64 -        DPRINTF("after suspend hvm domain nr_pages=0x%x.\n", nr_pfns);
    1.65 +
    1.66 +        nr_pfns = info.nr_pages; 
    1.67      }
    1.68  
    1.69      DPRINTF("after 1st handle hvm domain nr_pfns=0x%x, nr_pages=0x%lx, max_memkb=0x%lx, live=%d.\n",
    1.70 @@ -406,10 +400,15 @@ int xc_hvm_save(int xc_handle, int io_fd
    1.71              info.max_memkb,
    1.72              live);
    1.73  
    1.74 -    nr_pfns = info.nr_pages;
    1.75 -
    1.76 -    /*XXX: caculate the VGA hole*/
    1.77 -    max_pfn = nr_pfns + 0x20;
    1.78 +    /* Calculate the highest PFN of "normal" memory:
    1.79 +     * HVM memory is sequential except for the VGA and MMIO holes, and
    1.80 +     * we have nr_pfns of it (which now excludes the cirrus video RAM) */
    1.81 +    max_pfn = nr_pfns; 
    1.82 +    /* Skip the VGA hole from 0xa0000 to 0xc0000 */
    1.83 +    max_pfn += 0x20;   
    1.84 +    /* Skip the MMIO hole: 256MB just below 4GB */
    1.85 +    if ( max_pfn >= (HVM_BELOW_4G_MMIO_START >> PAGE_SHIFT) )
    1.86 +        max_pfn += (HVM_BELOW_4G_MMIO_LENGTH >> PAGE_SHIFT); 
    1.87  
    1.88      skip_this_iter = 0;/*XXX*/
    1.89      /* pretend we sent all the pages last iteration */
    1.90 @@ -424,7 +423,6 @@ int xc_hvm_save(int xc_handle, int io_fd
    1.91      to_send = malloc(BITMAP_SIZE);
    1.92      to_skip = malloc(BITMAP_SIZE);
    1.93  
    1.94 -    page_array = (unsigned long *) malloc( sizeof(unsigned long) * max_pfn);
    1.95  
    1.96      hvm_buf_size = xc_domain_hvm_getcontext(xc_handle, dom, 0, 0);
    1.97      if ( hvm_buf_size == -1 )
    1.98 @@ -434,7 +432,7 @@ int xc_hvm_save(int xc_handle, int io_fd
    1.99      }
   1.100      hvm_buf = malloc(hvm_buf_size);
   1.101  
   1.102 -    if (!to_send ||!to_skip ||!page_array ||!hvm_buf) {
   1.103 +    if (!to_send ||!to_skip ||!hvm_buf) {
   1.104          ERROR("Couldn't allocate memory");
   1.105          goto out;
   1.106      }
   1.107 @@ -454,26 +452,16 @@ int xc_hvm_save(int xc_handle, int io_fd
   1.108  
   1.109      analysis_phase(xc_handle, dom, max_pfn, to_skip, 0);
   1.110  
   1.111 -    /* get all the HVM domain pfns */
   1.112 -    for ( i = 0; i < max_pfn; i++)
   1.113 -        page_array[i] = i;
   1.114 -
   1.115  
   1.116      /* We want zeroed memory so use calloc rather than malloc. */
   1.117 -    pfn_type  = calloc(MAX_BATCH_SIZE, sizeof(*pfn_type));
   1.118      pfn_batch = calloc(MAX_BATCH_SIZE, sizeof(*pfn_batch));
   1.119  
   1.120 -    if ((pfn_type == NULL) || (pfn_batch == NULL)) {
   1.121 -        ERROR("failed to alloc memory for pfn_type and/or pfn_batch arrays");
   1.122 +    if (pfn_batch == NULL) {
   1.123 +        ERROR("failed to alloc memory for pfn_batch array");
   1.124          errno = ENOMEM;
   1.125          goto out;
   1.126      }
   1.127  
   1.128 -    if (lock_pages(pfn_type, MAX_BATCH_SIZE * sizeof(*pfn_type))) {
   1.129 -        ERROR("Unable to lock");
   1.130 -        goto out;
   1.131 -    }
   1.132 -
   1.133      /* Start writing out the saved-domain record. */
   1.134      if (!write_exact(io_fd, &max_pfn, sizeof(unsigned long))) {
   1.135          ERROR("write: max_pfn");
   1.136 @@ -511,16 +499,15 @@ int xc_hvm_save(int xc_handle, int io_fd
   1.137              }
   1.138  
   1.139  
   1.140 -            /* load pfn_type[] with the mfn of all the pages we're doing in
   1.141 +            /* load pfn_batch[] with the mfn of all the pages we're doing in
   1.142                 this batch. */
   1.143              for (batch = 0; batch < MAX_BATCH_SIZE && N < max_pfn ; N++) {
   1.144  
   1.145                  int n = permute(N, max_pfn, order_nr);
   1.146  
   1.147                  if (debug) {
   1.148 -                    DPRINTF("%d pfn= %08lx mfn= %08lx %d \n",
   1.149 -                            iter, (unsigned long)n, page_array[n],
   1.150 -                            test_bit(n, to_send));
   1.151 +                    DPRINTF("%d pfn= %08lx %d \n",
   1.152 +                            iter, (unsigned long)n, test_bit(n, to_send));
   1.153                  }
   1.154  
   1.155                  if (!last_iter && test_bit(n, to_send)&& test_bit(n, to_skip))
   1.156 @@ -530,10 +517,12 @@ int xc_hvm_save(int xc_handle, int io_fd
   1.157                        (test_bit(n, to_send) && last_iter)))
   1.158                      continue;
   1.159  
   1.160 -                if (n >= 0xa0 && n < 0xc0) {
   1.161 -/*                    DPRINTF("get a vga hole pfn= %x.\n", n);*/
   1.162 +                /* Skip PFNs that aren't really there */
   1.163 +                if ((n >= 0xa0 && n < 0xc0) /* VGA hole */
   1.164 +                    || (n >= (HVM_BELOW_4G_MMIO_START >> PAGE_SHIFT)
   1.165 +                        && n < (1ULL << 32) >> PAGE_SHIFT)) /* 4G MMIO hole */
   1.166                      continue;
   1.167 -                }
   1.168 +
   1.169                  /*
   1.170                  ** we get here if:
   1.171                  **  1. page is marked to_send & hasn't already been re-dirtied
   1.172 @@ -541,7 +530,6 @@ int xc_hvm_save(int xc_handle, int io_fd
   1.173                  */
   1.174  
   1.175                  pfn_batch[batch] = n;
   1.176 -                pfn_type[batch]  = page_array[n];
   1.177  
   1.178                  batch++;
   1.179              }
   1.180 @@ -573,7 +561,6 @@ int xc_hvm_save(int xc_handle, int io_fd
   1.181                  goto out;
   1.182              }
   1.183  
   1.184 -
   1.185              sent_this_iter += batch;
   1.186  
   1.187              munmap(region_base, batch*PAGE_SIZE);
   1.188 @@ -723,9 +710,6 @@ int xc_hvm_save(int xc_handle, int io_fd
   1.189      }
   1.190  
   1.191      free(hvm_buf);
   1.192 -    free(page_array);
   1.193 -
   1.194 -    free(pfn_type);
   1.195      free(pfn_batch);
   1.196      free(to_send);
   1.197      free(to_skip);