ia64/xen-unstable

changeset 17925:469d9b00382d

stubdom: add live migration support by having ioemu just notify the
hypervisor about memory changes.

The impact on disk performance is typically making it from 71.5MBps
down to 70.5Mbps during the live migration. The impact on network
performance is actually even hard to measure.

Signed-off-by: Samuel Thibault <samuel.thibault@eu.citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Mon Jun 30 09:57:27 2008 +0100 (2008-06-30)
parents 34bfbedae16b
children 0b4dbd9a9896
files tools/ioemu/target-i386-dm/exec-dm.c tools/ioemu/xenstore.c tools/libxc/xc_misc.c tools/libxc/xenctrl.h xen/arch/ia64/vmx/vmx_hypercall.c xen/arch/x86/hvm/hvm.c xen/include/public/hvm/hvm_op.h
line diff
     1.1 --- a/tools/ioemu/target-i386-dm/exec-dm.c	Mon Jun 30 09:51:34 2008 +0100
     1.2 +++ b/tools/ioemu/target-i386-dm/exec-dm.c	Mon Jun 30 09:57:27 2008 +0100
     1.3 @@ -483,9 +483,11 @@ static void memcpy_words(void *dst, void
     1.4  }
     1.5  #endif
     1.6  
     1.7 -void cpu_physical_memory_rw(target_phys_addr_t addr, uint8_t *buf, 
     1.8 -                            int len, int is_write)
     1.9 +void cpu_physical_memory_rw(target_phys_addr_t _addr, uint8_t *buf, 
    1.10 +                            int _len, int is_write)
    1.11  {
    1.12 +    target_phys_addr_t addr = _addr;
    1.13 +    int len = _len;
    1.14      int l, io_index;
    1.15      uint8_t *ptr;
    1.16      uint32_t val;
    1.17 @@ -520,6 +522,7 @@ void cpu_physical_memory_rw(target_phys_
    1.18              } else if ((ptr = phys_ram_addr(addr)) != NULL) {
    1.19                  /* Writing to RAM */
    1.20                  memcpy_words(ptr, buf, l);
    1.21 +#ifndef CONFIG_STUBDOM
    1.22                  if (logdirty_bitmap != NULL) {
    1.23                      /* Record that we have dirtied this frame */
    1.24                      unsigned long pfn = addr >> TARGET_PAGE_BITS;
    1.25 @@ -531,6 +534,7 @@ void cpu_physical_memory_rw(target_phys_
    1.26                              |= 1UL << pfn % HOST_LONG_BITS;
    1.27                      }
    1.28                  }
    1.29 +#endif
    1.30  #ifdef __ia64__
    1.31                  sync_icache(ptr, l);
    1.32  #endif 
    1.33 @@ -566,6 +570,13 @@ void cpu_physical_memory_rw(target_phys_
    1.34          addr += l;
    1.35      }
    1.36  
    1.37 +#ifdef CONFIG_STUBDOM
    1.38 +    if (logdirty_bitmap != NULL)
    1.39 +        xc_hvm_modified_memory(xc_handle, domid, _addr >> TARGET_PAGE_BITS,
    1.40 +                (_addr + _len + TARGET_PAGE_SIZE - 1) >> TARGET_PAGE_BITS
    1.41 +                    - _addr >> TARGET_PAGE_BITS);
    1.42 +#endif
    1.43 +
    1.44      mapcache_unlock();
    1.45  }
    1.46  #endif
     2.1 --- a/tools/ioemu/xenstore.c	Mon Jun 30 09:51:34 2008 +0100
     2.2 +++ b/tools/ioemu/xenstore.c	Mon Jun 30 09:57:27 2008 +0100
     2.3 @@ -402,6 +402,10 @@ void xenstore_process_logdirty_event(voi
     2.4              /* No key yet: wait for the next watch */
     2.5              return;
     2.6  
     2.7 +#ifdef CONFIG_STUBDOM
     2.8 +        /* We pass the writes to hypervisor */
     2.9 +        seg = (void*)1;
    2.10 +#else
    2.11          strncpy(key_terminated, key_ascii, 16);
    2.12          free(key_ascii);
    2.13          key = (key_t) strtoull(key_terminated, NULL, 16);
    2.14 @@ -417,11 +421,6 @@ void xenstore_process_logdirty_event(voi
    2.15          fprintf(logfile, "%s: key=%16.16llx size=%lu\n", __FUNCTION__,
    2.16                  (unsigned long long)key, logdirty_bitmap_size);
    2.17  
    2.18 -#ifdef CONFIG_STUBDOM
    2.19 -        /* XXX we just can't use shm. */
    2.20 -        fprintf(logfile, "Log dirty is not implemented in stub domains!\n");
    2.21 -        return;
    2.22 -#else
    2.23          shmid = shmget(key, 2 * logdirty_bitmap_size, S_IRUSR|S_IWUSR);
    2.24          if (shmid == -1) {
    2.25              fprintf(logfile, "Log-dirty: shmget failed: segment %16.16llx "
     3.1 --- a/tools/libxc/xc_misc.c	Mon Jun 30 09:51:34 2008 +0100
     3.2 +++ b/tools/libxc/xc_misc.c	Mon Jun 30 09:57:27 2008 +0100
     3.3 @@ -267,6 +267,34 @@ int xc_hvm_track_dirty_vram(
     3.4      return rc;
     3.5  }
     3.6  
     3.7 +int xc_hvm_modified_memory(
     3.8 +    int xc_handle, domid_t dom, uint64_t first_pfn, uint64_t nr)
     3.9 +{
    3.10 +    DECLARE_HYPERCALL;
    3.11 +    struct xen_hvm_modified_memory arg;
    3.12 +    int rc;
    3.13 +
    3.14 +    hypercall.op     = __HYPERVISOR_hvm_op;
    3.15 +    hypercall.arg[0] = HVMOP_modified_memory;
    3.16 +    hypercall.arg[1] = (unsigned long)&arg;
    3.17 +
    3.18 +    arg.domid     = dom;
    3.19 +    arg.first_pfn = first_pfn;
    3.20 +    arg.nr        = nr;
    3.21 +
    3.22 +    if ( (rc = lock_pages(&arg, sizeof(arg))) != 0 )
    3.23 +    {
    3.24 +        PERROR("Could not lock memory");
    3.25 +        return rc;
    3.26 +    }
    3.27 +
    3.28 +    rc = do_xen_hypercall(xc_handle, &hypercall);
    3.29 +
    3.30 +    unlock_pages(&arg, sizeof(arg));
    3.31 +
    3.32 +    return rc;
    3.33 +}
    3.34 +
    3.35  void *xc_map_foreign_pages(int xc_handle, uint32_t dom, int prot,
    3.36                             const xen_pfn_t *arr, int num)
    3.37  {
     4.1 --- a/tools/libxc/xenctrl.h	Mon Jun 30 09:51:34 2008 +0100
     4.2 +++ b/tools/libxc/xenctrl.h	Mon Jun 30 09:57:27 2008 +0100
     4.3 @@ -929,6 +929,12 @@ int xc_hvm_track_dirty_vram(
     4.4      uint64_t first_pfn, uint64_t nr,
     4.5      unsigned long *bitmap);
     4.6  
     4.7 +/*
     4.8 + * Notify that some pages got modified by the Device Model
     4.9 + */
    4.10 +int xc_hvm_modified_memory(
    4.11 +    int xc_handle, domid_t dom, uint64_t first_pfn, uint64_t nr);
    4.12 +
    4.13  typedef enum {
    4.14    XC_ERROR_NONE = 0,
    4.15    XC_INTERNAL_ERROR = 1,
     5.1 --- a/xen/arch/ia64/vmx/vmx_hypercall.c	Mon Jun 30 09:51:34 2008 +0100
     5.2 +++ b/xen/arch/ia64/vmx/vmx_hypercall.c	Mon Jun 30 09:57:27 2008 +0100
     5.3 @@ -204,6 +204,53 @@ do_hvm_op(unsigned long op, XEN_GUEST_HA
     5.4          rc = -ENOSYS;
     5.5          break;
     5.6  
     5.7 +    case HVMOP_modified_memory:
     5.8 +    {
     5.9 +        struct xen_hvm_modified_memory a;
    5.10 +        struct domain *d;
    5.11 +        unsigned long pfn;
    5.12 +
    5.13 +        if ( copy_from_guest(&a, arg, 1) )
    5.14 +            return -EFAULT;
    5.15 +
    5.16 +        if ( a.domid == DOMID_SELF )
    5.17 +        {
    5.18 +            d = rcu_lock_current_domain();
    5.19 +        }
    5.20 +        else
    5.21 +        {
    5.22 +            if ( (d = rcu_lock_domain_by_id(a.domid)) == NULL )
    5.23 +                return -ESRCH;
    5.24 +            if ( !IS_PRIV_FOR(current->domain, d) )
    5.25 +            {
    5.26 +                rc = -EPERM;
    5.27 +                goto param_fail3;
    5.28 +            }
    5.29 +        }
    5.30 +
    5.31 +        rc = -EINVAL;
    5.32 +        if ( !is_hvm_domain(d) )
    5.33 +            goto param_fail3;
    5.34 +
    5.35 +        rc = -EINVAL;
    5.36 +        if ( a.first_pfn > domain_get_maximum_gpfn(d)
    5.37 +                || a.first_pfn + a.nr - 1 < a.first_pfn
    5.38 +                || a.first_pfn + a.nr - 1 > domain_get_maximum_gpfn(d))
    5.39 +            goto param_fail3;
    5.40 +
    5.41 +        rc = 0;
    5.42 +        if ( !d->arch.shadow_bitmap )
    5.43 +            goto param_fail3;
    5.44 +
    5.45 +        for (pfn = a.first_pfn; pfn < a.first_pfn + a.nr; pfn++)
    5.46 +            if (pfn < d->arch.shadow_bitmap_size)
    5.47 +                set_bit(pfn, d->arch.shadow_bitmap);
    5.48 +
    5.49 +    param_fail3:
    5.50 +        rcu_unlock_domain(d);
    5.51 +        break;
    5.52 +    }
    5.53 +
    5.54      default:
    5.55          gdprintk(XENLOG_INFO, "Bad HVM op %ld.\n", op);
    5.56          rc = -ENOSYS;
     6.1 --- a/xen/arch/x86/hvm/hvm.c	Mon Jun 30 09:51:34 2008 +0100
     6.2 +++ b/xen/arch/x86/hvm/hvm.c	Mon Jun 30 09:57:27 2008 +0100
     6.3 @@ -2529,6 +2529,66 @@ long do_hvm_op(unsigned long op, XEN_GUE
     6.4          break;
     6.5      }
     6.6  
     6.7 +    case HVMOP_modified_memory:
     6.8 +    {
     6.9 +        struct xen_hvm_modified_memory a;
    6.10 +        struct domain *d;
    6.11 +        unsigned long pfn;
    6.12 +
    6.13 +        if ( copy_from_guest(&a, arg, 1) )
    6.14 +            return -EFAULT;
    6.15 +
    6.16 +        if ( a.domid == DOMID_SELF )
    6.17 +        {
    6.18 +            d = rcu_lock_current_domain();
    6.19 +        }
    6.20 +        else
    6.21 +        {
    6.22 +            if ( (d = rcu_lock_domain_by_id(a.domid)) == NULL )
    6.23 +                return -ESRCH;
    6.24 +            if ( !IS_PRIV_FOR(current->domain, d) )
    6.25 +            {
    6.26 +                rc = -EPERM;
    6.27 +                goto param_fail3;
    6.28 +            }
    6.29 +        }
    6.30 +
    6.31 +        rc = -EINVAL;
    6.32 +        if ( !is_hvm_domain(d) )
    6.33 +            goto param_fail3;
    6.34 +
    6.35 +        rc = xsm_hvm_param(d, op);
    6.36 +        if ( rc )
    6.37 +            goto param_fail3;
    6.38 +
    6.39 +        rc = -EINVAL;
    6.40 +        if ( (a.first_pfn > domain_get_maximum_gpfn(d)) ||
    6.41 +             ((a.first_pfn + a.nr - 1) < a.first_pfn) ||
    6.42 +             ((a.first_pfn + a.nr - 1) > domain_get_maximum_gpfn(d)) )
    6.43 +            goto param_fail3;
    6.44 +
    6.45 +        rc = 0;
    6.46 +        if ( !paging_mode_log_dirty(d) )
    6.47 +            goto param_fail3;
    6.48 +
    6.49 +        for ( pfn = a.first_pfn; pfn < a.first_pfn + a.nr; pfn++ )
    6.50 +        {
    6.51 +            p2m_type_t t;
    6.52 +            mfn_t mfn = gfn_to_mfn(d, pfn, &t);
    6.53 +            if ( mfn_x(mfn) != INVALID_MFN )
    6.54 +            {
    6.55 +                paging_mark_dirty(d, mfn_x(mfn));
    6.56 +                /* These are most probably not page tables any more */
    6.57 +                /* don't take a long time and don't die either */
    6.58 +                sh_remove_shadows(d->vcpu[0], mfn, 1, 0);
    6.59 +            }
    6.60 +        }
    6.61 +
    6.62 +    param_fail3:
    6.63 +        rcu_unlock_domain(d);
    6.64 +        break;
    6.65 +    }
    6.66 +
    6.67      default:
    6.68      {
    6.69          gdprintk(XENLOG_WARNING, "Bad HVM op %ld.\n", op);
     7.1 --- a/xen/include/public/hvm/hvm_op.h	Mon Jun 30 09:51:34 2008 +0100
     7.2 +++ b/xen/include/public/hvm/hvm_op.h	Mon Jun 30 09:57:27 2008 +0100
     7.3 @@ -92,6 +92,19 @@ struct xen_hvm_track_dirty_vram {
     7.4  typedef struct xen_hvm_track_dirty_vram xen_hvm_track_dirty_vram_t;
     7.5  DEFINE_XEN_GUEST_HANDLE(xen_hvm_track_dirty_vram_t);
     7.6  
     7.7 +/* Notify that some pages got modified by the Device Model. */
     7.8 +#define HVMOP_modified_memory    7
     7.9 +struct xen_hvm_modified_memory {
    7.10 +    /* Domain to be updated. */
    7.11 +    domid_t  domid;
    7.12 +    /* First pfn. */
    7.13 +    uint64_aligned_t first_pfn;
    7.14 +    /* Number of pages. */
    7.15 +    uint64_aligned_t nr;
    7.16 +};
    7.17 +typedef struct xen_hvm_modified_memory xen_hvm_modified_memory_t;
    7.18 +DEFINE_XEN_GUEST_HANDLE(xen_hvm_modified_memory_t);
    7.19 +
    7.20  #endif /* defined(__XEN__) || defined(__XEN_TOOLS__) */
    7.21  
    7.22  #endif /* __XEN_PUBLIC_HVM_HVM_OP_H__ */