ia64/xen-unstable

changeset 15139:c693c50a6ad5

[IA64] memmap: save/restore: support save/restore with domain memmap

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
author Alex Williamson <alex.williamson@hp.com>
date Thu May 24 15:54:52 2007 -0600 (2007-05-24)
parents 010370333a88
children 034f3e20ad10
files tools/libxc/ia64/xc_ia64_linux_restore.c tools/libxc/ia64/xc_ia64_linux_save.c xen/arch/ia64/xen/dom0_ops.c xen/arch/ia64/xen/dom_fw_utils.c
line diff
     1.1 --- a/tools/libxc/ia64/xc_ia64_linux_restore.c	Thu May 24 15:48:31 2007 -0600
     1.2 +++ b/tools/libxc/ia64/xc_ia64_linux_restore.c	Thu May 24 15:54:52 2007 -0600
     1.3 @@ -140,9 +140,7 @@ xc_domain_restore(int xc_handle, int io_
     1.4      /* Build firmware (will be overwritten).  */
     1.5      domctl.domain = (domid_t)dom;
     1.6      domctl.u.arch_setup.flags &= ~XEN_DOMAINSETUP_query;
     1.7 -    domctl.u.arch_setup.bp = ((p2m_size - 3) << PAGE_SHIFT)
     1.8 -                           + sizeof (start_info_t);
     1.9 -    domctl.u.arch_setup.maxmem = (p2m_size - 3) << PAGE_SHIFT;
    1.10 +    domctl.u.arch_setup.bp = 0; /* indicate domain restore */
    1.11      
    1.12      domctl.cmd = XEN_DOMCTL_arch_setup;
    1.13      if (xc_domctl(xc_handle, &domctl))
    1.14 @@ -330,3 +328,13 @@ xc_domain_restore(int xc_handle, int io_
    1.15  
    1.16      return rc;
    1.17  }
    1.18 +
    1.19 +/*
    1.20 + * Local variables:
    1.21 + * mode: C
    1.22 + * c-set-style: "BSD"
    1.23 + * c-basic-offset: 4
    1.24 + * tab-width: 4
    1.25 + * indent-tabs-mode: nil
    1.26 + * End:
    1.27 + */
     2.1 --- a/tools/libxc/ia64/xc_ia64_linux_save.c	Thu May 24 15:48:31 2007 -0600
     2.2 +++ b/tools/libxc/ia64/xc_ia64_linux_save.c	Thu May 24 15:54:52 2007 -0600
     2.3 @@ -22,8 +22,8 @@
     2.4  ** XXX SMH: should consider if want to be able to override MAX_MBIT_RATE too.
     2.5  **
     2.6  */
     2.7 -#define DEF_MAX_ITERS    (4 - 1)	/* limit us to 4 times round loop  */
     2.8 -#define DEF_MAX_FACTOR   3		/* never send more than 3x nr_pfns */
     2.9 +#define DEF_MAX_ITERS    (4 - 1)        /* limit us to 4 times round loop  */
    2.10 +#define DEF_MAX_FACTOR   3              /* never send more than 3x nr_pfns */
    2.11  
    2.12  /*
    2.13  ** During (live) save/migrate, we maintain a number of bitmaps to track
    2.14 @@ -37,24 +37,21 @@
    2.15  
    2.16  #define BITMAP_SHIFT(_nr) ((_nr) % BITS_PER_LONG)
    2.17  
    2.18 -static inline int test_bit (int nr, volatile void * addr)
    2.19 +static inline int test_bit(int nr, volatile void * addr)
    2.20  {
    2.21      return (BITMAP_ENTRY(nr, addr) >> BITMAP_SHIFT(nr)) & 1;
    2.22  }
    2.23  
    2.24 -static inline void clear_bit (int nr, volatile void * addr)
    2.25 +static inline void clear_bit(int nr, volatile void * addr)
    2.26  {
    2.27      BITMAP_ENTRY(nr, addr) &= ~(1UL << BITMAP_SHIFT(nr));
    2.28  }
    2.29  
    2.30 -static inline void set_bit ( int nr, volatile void * addr)
    2.31 +static inline void set_bit(int nr, volatile void * addr)
    2.32  {
    2.33      BITMAP_ENTRY(nr, addr) |= (1UL << BITMAP_SHIFT(nr));
    2.34  }
    2.35  
    2.36 -/* total number of pages used by the current guest */
    2.37 -static unsigned long max_pfn;
    2.38 -
    2.39  static int xc_ia64_shadow_control(int xc_handle,
    2.40                                    uint32_t domid,
    2.41                                    unsigned int sop,
    2.42 @@ -67,7 +64,7 @@ static int xc_ia64_shadow_control(int xc
    2.43          unsigned char *bmap = (unsigned char *)dirty_bitmap;
    2.44          unsigned long bmap_bytes =
    2.45              ((pages + BITS_PER_LONG - 1) & ~(BITS_PER_LONG - 1)) / 8;
    2.46 -        unsigned int bmap_pages = (bmap_bytes + PAGE_SIZE - 1) / PAGE_SIZE; 
    2.47 +        unsigned int bmap_pages = (bmap_bytes + PAGE_SIZE - 1) / PAGE_SIZE;
    2.48  
    2.49          /* Touch the page so that it is in the TC.
    2.50             FIXME: use a more reliable method.  */
    2.51 @@ -168,6 +165,9 @@ xc_domain_save(int xc_handle, int io_fd,
    2.52      /* Number of pages sent (live only).  */
    2.53      unsigned int total_sent;
    2.54  
    2.55 +    /* total number of pages used by the current guest */
    2.56 +    unsigned long p2m_size;
    2.57 +
    2.58      /* Size of the shadow bitmap (live only).  */
    2.59      unsigned int bitmap_size = 0;
    2.60  
    2.61 @@ -182,7 +182,7 @@ xc_domain_save(int xc_handle, int io_fd,
    2.62      char *mem;
    2.63  
    2.64      if (debug)
    2.65 -        fprintf (stderr, "xc_linux_save (ia64): started dom=%d\n", dom);
    2.66 +        fprintf(stderr, "xc_linux_save (ia64): started dom=%d\n", dom);
    2.67  
    2.68      /* If no explicit control parameters given, use defaults */
    2.69      if (!max_iters)
    2.70 @@ -216,17 +216,17 @@ xc_domain_save(int xc_handle, int io_fd,
    2.71          goto out;
    2.72      }
    2.73  
    2.74 -    max_pfn = info.max_memkb >> (PAGE_SHIFT - 10);
    2.75 +    p2m_size = xc_memory_op(xc_handle, XENMEM_maximum_gpfn, &dom);
    2.76  
    2.77 -    page_array = malloc(max_pfn * sizeof(unsigned long));
    2.78 +    page_array = malloc(p2m_size * sizeof(unsigned long));
    2.79      if (page_array == NULL) {
    2.80          ERROR("Could not allocate memory");
    2.81          goto out;
    2.82      }
    2.83  
    2.84      /* This is expected by xm restore.  */
    2.85 -    if (!write_exact(io_fd, &max_pfn, sizeof(unsigned long))) {
    2.86 -        ERROR("write: max_pfn");
    2.87 +    if (!write_exact(io_fd, &p2m_size, sizeof(unsigned long))) {
    2.88 +        ERROR("write: p2m_size");
    2.89          goto out;
    2.90      }
    2.91  
    2.92 @@ -269,7 +269,7 @@ xc_domain_save(int xc_handle, int io_fd,
    2.93  
    2.94          last_iter = 0;
    2.95  
    2.96 -        bitmap_size = ((max_pfn + BITS_PER_LONG-1) & ~(BITS_PER_LONG-1)) / 8;
    2.97 +        bitmap_size = ((p2m_size + BITS_PER_LONG-1) & ~(BITS_PER_LONG-1)) / 8;
    2.98          to_send = malloc(bitmap_size);
    2.99          to_skip = malloc(bitmap_size);
   2.100  
   2.101 @@ -289,7 +289,7 @@ xc_domain_save(int xc_handle, int io_fd,
   2.102              ERROR("Unable to lock_pages to_skip");
   2.103              goto out;
   2.104          }
   2.105 -        
   2.106 +
   2.107      } else {
   2.108  
   2.109          /* This is a non-live suspend. Issue the call back to get the
   2.110 @@ -304,7 +304,7 @@ xc_domain_save(int xc_handle, int io_fd,
   2.111  
   2.112      }
   2.113  
   2.114 -    sent_last_iter = max_pfn;
   2.115 +    sent_last_iter = p2m_size;
   2.116      total_sent = 0;
   2.117  
   2.118      for (iter = 1; ; iter++) {
   2.119 @@ -316,7 +316,7 @@ xc_domain_save(int xc_handle, int io_fd,
   2.120  
   2.121          /* Get the pfn list, as it may change.  */
   2.122          if (xc_ia64_get_pfn_list(xc_handle, dom, page_array,
   2.123 -                                 0, max_pfn) != max_pfn) {
   2.124 +                                 0, p2m_size) != p2m_size) {
   2.125              ERROR("Could not get the page frame list");
   2.126              goto out;
   2.127          }
   2.128 @@ -327,14 +327,14 @@ xc_domain_save(int xc_handle, int io_fd,
   2.129          if (!last_iter) {
   2.130              if (xc_ia64_shadow_control(xc_handle, dom,
   2.131                                         XEN_DOMCTL_SHADOW_OP_PEEK,
   2.132 -                                       to_skip, max_pfn, NULL) != max_pfn) {
   2.133 +                                       to_skip, p2m_size, NULL) != p2m_size) {
   2.134                  ERROR("Error peeking shadow bitmap");
   2.135                  goto out;
   2.136              }
   2.137          }
   2.138  
   2.139          /* Start writing out the saved-domain record. */
   2.140 -        for (N = 0; N < max_pfn; N++) {
   2.141 +        for (N = 0; N < p2m_size; N++) {
   2.142              if (page_array[N] == INVALID_MFN)
   2.143                  continue;
   2.144              if (!last_iter) {
   2.145 @@ -346,7 +346,7 @@ xc_domain_save(int xc_handle, int io_fd,
   2.146  
   2.147              if (debug)
   2.148                  fprintf(stderr, "xc_linux_save: page %lx (%lu/%lu)\n",
   2.149 -                        page_array[N], N, max_pfn);
   2.150 +                        page_array[N], N, p2m_size);
   2.151  
   2.152              mem = xc_map_foreign_range(xc_handle, dom, PAGE_SIZE,
   2.153                                         PROT_READ|PROT_WRITE, N);
   2.154 @@ -360,7 +360,7 @@ xc_domain_save(int xc_handle, int io_fd,
   2.155              }
   2.156  
   2.157              if (!write_exact(io_fd, &N, sizeof(N))) {
   2.158 -                ERROR("write: max_pfn");
   2.159 +                ERROR("write: p2m_size");
   2.160                  munmap(mem, PAGE_SIZE);
   2.161                  goto out;
   2.162              }
   2.163 @@ -384,7 +384,7 @@ xc_domain_save(int xc_handle, int io_fd,
   2.164          if (live) {
   2.165              if ( /* ((sent_this_iter > sent_last_iter) && RATE_IS_MAX()) || */
   2.166                  (iter >= max_iters) || (sent_this_iter+skip_this_iter < 50) ||
   2.167 -                (total_sent > max_pfn*max_factor)) {
   2.168 +                (total_sent > p2m_size*max_factor)) {
   2.169                  DPRINTF("Start last iteration\n");
   2.170                  last_iter = 1;
   2.171  
   2.172 @@ -397,7 +397,7 @@ xc_domain_save(int xc_handle, int io_fd,
   2.173              /* Pages to be sent are pages which were dirty.  */
   2.174              if (xc_ia64_shadow_control(xc_handle, dom,
   2.175                                         XEN_DOMCTL_SHADOW_OP_CLEAN,
   2.176 -                                       to_send, max_pfn, NULL ) != max_pfn) {
   2.177 +                                       to_send, p2m_size, NULL ) != p2m_size) {
   2.178                  ERROR("Error flushing shadow PT");
   2.179                  goto out;
   2.180              }
   2.181 @@ -409,7 +409,7 @@ xc_domain_save(int xc_handle, int io_fd,
   2.182  
   2.183      }
   2.184  
   2.185 -    fprintf (stderr, "All memory is saved\n");
   2.186 +    fprintf(stderr, "All memory is saved\n");
   2.187  
   2.188      /* terminate */
   2.189      {
   2.190 @@ -425,7 +425,7 @@ xc_domain_save(int xc_handle, int io_fd,
   2.191          unsigned int i,j;
   2.192          unsigned long pfntab[1024];
   2.193  
   2.194 -        for (i = 0, j = 0; i < max_pfn; i++) {
   2.195 +        for (i = 0, j = 0; i < p2m_size; i++) {
   2.196              if (page_array[i] == INVALID_MFN)
   2.197                  j++;
   2.198          }
   2.199 @@ -435,13 +435,13 @@ xc_domain_save(int xc_handle, int io_fd,
   2.200              goto out;
   2.201          }
   2.202  
   2.203 -        for (i = 0, j = 0; i < max_pfn; ) {
   2.204 +        for (i = 0, j = 0; i < p2m_size; ) {
   2.205  
   2.206              if (page_array[i] == INVALID_MFN)
   2.207                  pfntab[j++] = i;
   2.208  
   2.209              i++;
   2.210 -            if (j == 1024 || i == max_pfn) {
   2.211 +            if (j == 1024 || i == p2m_size) {
   2.212                  if (!write_exact(io_fd, &pfntab, sizeof(unsigned long)*j)) {
   2.213                      ERROR("Error when writing to state file (6b)");
   2.214                      goto out;
   2.215 @@ -475,7 +475,7 @@ xc_domain_save(int xc_handle, int io_fd,
   2.216          munmap(mem, PAGE_SIZE);
   2.217          goto out;
   2.218      }
   2.219 -    munmap(mem, PAGE_SIZE);    
   2.220 +    munmap(mem, PAGE_SIZE);
   2.221  
   2.222      if (!write_exact(io_fd, live_shinfo, PAGE_SIZE)) {
   2.223          ERROR("Error when writing to state file (1)");
     3.1 --- a/xen/arch/ia64/xen/dom0_ops.c	Thu May 24 15:48:31 2007 -0600
     3.2 +++ b/xen/arch/ia64/xen/dom0_ops.c	Thu May 24 15:54:52 2007 -0600
     3.3 @@ -89,7 +89,7 @@ long arch_do_domctl(xen_domctl_t *op, XE
     3.4                  ds->flags |= XEN_DOMAINSETUP_hvm_guest;
     3.5              /* Set params.  */
     3.6              ds->bp = 0;		/* unknown.  */
     3.7 -            ds->maxmem = 0; /* unknown.  */
     3.8 +            ds->maxmem = d->arch.convmem_end;
     3.9              ds->xsi_va = d->arch.shared_info_va;
    3.10              ds->hypercall_imm = d->arch.breakimm;
    3.11              /* Copy back.  */
     4.1 --- a/xen/arch/ia64/xen/dom_fw_utils.c	Thu May 24 15:48:31 2007 -0600
     4.2 +++ b/xen/arch/ia64/xen/dom_fw_utils.c	Thu May 24 15:54:52 2007 -0600
     4.3 @@ -139,6 +139,14 @@ assign_new_domain_page_if_dom0(struct do
     4.4          assign_new_domain0_page(d, mpaddr);
     4.5  }
     4.6  
     4.7 +static void
     4.8 +dom_fw_setup_for_domain_restore(domain_t *d, unsigned long maxmem)
     4.9 +{
    4.10 +    assign_new_domain_page(d, FW_HYPERCALL_BASE_PADDR);
    4.11 +    dom_fw_domain_init(d, domain_mpa_to_imva(d, FW_TABLES_BASE_PADDR));
    4.12 +    d->arch.convmem_end = maxmem;
    4.13 +}
    4.14 +
    4.15  int
    4.16  dom_fw_setup(domain_t *d, unsigned long bp_mpa, unsigned long maxmem)
    4.17  {
    4.18 @@ -149,6 +157,12 @@ dom_fw_setup(domain_t *d, unsigned long 
    4.19      BUILD_BUG_ON(sizeof(struct fw_tables) >
    4.20                   (FW_TABLES_END_PADDR - FW_TABLES_BASE_PADDR));
    4.21  
    4.22 +    if (bp_mpa == 0) {
    4.23 +        /* bp_mpa == 0 means this is domain restore case. */
    4.24 +        dom_fw_setup_for_domain_restore(d, maxmem);
    4.25 +        return 0;
    4.26 +    }
    4.27 +
    4.28      /* Create page for boot_param.  */
    4.29      assign_new_domain_page_if_dom0(d, bp_mpa);
    4.30      bp = domain_mpa_to_imva(d, bp_mpa);