Skip to contentSkip to conversation

COarse-grain LOck-stepping Virtual Machines for Non-stop Service

RFC PATCH Superseded Wen Congyang 4 participants 36 messages Jul 18, 2014 – Aug 7, 2014

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

cover COarse-grain LOck-stepping Virtual Machines for Non-stop Service

Virtual machine (VM) replication is a well known technique for providing application-agnostic software-implemented hardware fault tolerance - "non-stop service". Currently, remus provides this function, but it buffers all output packets, and the latency is unacceptable.

In xen summit 2012, We introduce a new VM replication solution: colo (COarse-grain LOck-stepping virtual machine). The presentation is in the following URL:
http://www.slideshare.net/xen_com_mgr/colo-coarsegrain-lockstepping-virtual-machines-for-nonstop-service

Here is the summary of the solution:

Quoted 1 line

From the client's point of view, as long as the client observes identical

responses from the primary and secondary VMs, according to the service semantics, then the secondary vm is a valid replica of the primary vm, and can successfully take over when a hardware failure of the primary vm is detected.

This patchset is RFC, and implements the frame of colo:
1. Both primary vm and secondary vm are running
2. do checkoint

This patchset is based on remus-v15, and use migration v1. Only supports hvm guest now.

TODO list:
1. rebase to remus-v17 or newer
2. support migration v2
3. nic/disk replication
4. support pvm

Patch 1-3: bugfix
Patch 4-6: temporarily update remus to reuse remus device codes Patch 7-14: update some APIs which will be used by colo
Patch 15-22: colo related codes
Patch 23: Hack patch, just for test
Patch 24-25: bugfix. We find this bug before rebasing colo to newest xen.
But we don't trigger this bug now.
Patch 26: A patch for qemu-xen

Hong Tao (1):
copy the correct page to memory

Wen Congyang (24):
csum the correct page
don't zero out ioreq page
don't touch remus in remus_device
rename remus device to checkpoint device
adjust the indentation
Refactor domain_suspend_callback_common()
Update libxl__domain_resume() for colo
Update libxl__domain_suspend_common_switch_qemu_logdirty() for colo Introduce a new internal API libxl__domain_unpause() Update libxl__domain_unpause() to support qemu-xen support to resume uncooperative HVM guests
update datecopier to support sending data only
introduce a new API to aync read data from fd
Update libxl_save_msgs_gen.pl to support return data from xl to xc Allow slave sends data to master
secondary vm suspend/resume/checkpoint code
primary vm suspend/get_dirty_pfn/resume/checkpoint code
xc_domain_save: flush cache before calling callbacks->postcopy() in
colo mode
COLO: xc related codes
send store mfn and console mfn to xl before resuming secondary vm implement the cmdline for COLO
HACK: do checkpoint per 20ms
fix vm entry fail
sync mmu before resuming secondary vm

 docs/man/xl.pod.1                                  |   9 +-
 tools/libxc/xc_domain.c                            |   9 +
 tools/libxc/xc_domain_restore.c                    |  74 +-
 tools/libxc/xc_domain_save.c                       |  66 +-
 tools/libxc/xc_resume.c                            |  20 +-
 tools/libxc/xenctrl.h                              |   2 +
 tools/libxc/xenguest.h                             |  40 +
 tools/libxl/Makefile                               |   3 +-
 tools/libxl/libxl.c                                | 102 ++-
 tools/libxl/libxl.h                                |   3 +-
 tools/libxl/libxl_aoutils.c                        |  81 +-
 ...xl_remus_device.c => libxl_checkpoint_device.c} | 266 ++++---
 tools/libxl/libxl_colo.h                           |  48 ++
 tools/libxl/libxl_colo_restore.c                   | 882 +++++++++++++++++++++
 tools/libxl/libxl_colo_save.c                      | 602 ++++++++++++++
 tools/libxl/libxl_create.c                         | 131 ++-
 tools/libxl/libxl_dom.c                            | 424 ++++++----
 tools/libxl/libxl_internal.h                       | 262 ++++--
 tools/libxl/libxl_netbuffer.c                      |  85 +-
 tools/libxl/libxl_nonetbuffer.c                    |  14 +-
 tools/libxl/libxl_qmp.c                            |  10 +
 tools/libxl/libxl_remus_disk_drbd.c                |  54 +-
 tools/libxl/libxl_save_callout.c                   |  37 +-
 tools/libxl/libxl_save_helper.c                    |  17 +
 tools/libxl/libxl_save_msgs_gen.pl                 |  74 +-
 tools/libxl/libxl_types.idl                        |  12 +-
 tools/libxl/xl_cmdimpl.c                           |  54 +-
 tools/libxl/xl_cmdtable.c                          |   3 +-
 xen/arch/x86/domctl.c                              |  15 +
 xen/arch/x86/hvm/save.c                            |   6 +
 xen/arch/x86/hvm/vmx/vmcs.c                        |   8 +
 xen/arch/x86/hvm/vmx/vmx.c                         |   8 +
 xen/include/asm-x86/hvm/hvm.h                      |   1 +
 xen/include/asm-x86/hvm/vmx/vmcs.h                 |   1 +
 xen/include/public/domctl.h                        |   1 +
 xen/include/xen/hvm/save.h                         |   2 +
 36 files changed, 2895 insertions(+), 531 deletions(-)
 rename tools/libxl/{libxl_remus_device.c => libxl_checkpoint_device.c} (47%)
 create mode 100644 tools/libxl/libxl_colo.h
 create mode 100644 tools/libxl/libxl_colo_restore.c
 create mode 100644 tools/libxl/libxl_colo_save.c
Signature · 1 line
1.9.3
#1 lore raw

RFC PATCH 1/25 copy the correct page to memory

From: Hong Tao <[email protected]>

apply_batch() only handles MAX_BATCH_SIZE pages at one time. If there is some bogus/unmapped/allocate-only/broken page, we will skip it. So when we call apply_batch() again, the first page's index is curbatch - invalid_pages. invalid_pages stores the number of bogus/unmapped/allocate-only/broken pages we have found.

In many cases, invalid_pages is 0, so we don't catch this error.

---
 tools/libxc/xc_domain_restore.c | 24 +++++++++++++++++++-----
 1 file changed, 19 insertions(+), 5 deletions(-)
tools/libxc/xc_domain_restore.c +19 -5
index 071ab6a..f7ca4ad 100644
@@ -1106,7 +1106,7 @@ static int pagebuf_get(xc_interface *xch, struct restore_ctx *ctx,
 static int apply_batch(xc_interface *xch, uint32_t dom, struct restore_ctx *ctx,
                        xen_pfn_t* region_mfn, unsigned long* pfn_type, int pae_extended_cr3,
                        struct xc_mmu* mmu,
-                       pagebuf_t* pagebuf, int curbatch)
+                       pagebuf_t* pagebuf, int curbatch, int *invalid_pages)
 {
     int i, j, curpage, nr_mfns;
     int k, scount;
@@ -1121,6 +1121,12 @@ static int apply_batch(xc_interface *xch, uint32_t dom, struct restore_ctx *ctx,
     struct domain_info_context *dinfo = &ctx->dinfo;
     int* pfn_err = NULL;
     int rc = -1;
+    int local_invalid_pages = 0;
+    /* We have handled curbatch pages before this batch, and there are
+     * *invalid_pages pages that are not in pagebuf->pages. So the first
+     * page for this page is (curbatch - *invalid_pages) page.
+     */
+    int first_page = curbatch - *invalid_pages;
 
     unsigned long mfn, pfn, pagetype;
 
@@ -1293,10 +1299,13 @@ static int apply_batch(xc_interface *xch, uint32_t dom, struct restore_ctx *ctx,
         pfn      = pagebuf->pfn_types[i + curbatch] & ~XEN_DOMCTL_PFINFO_LTAB_MASK;
         pagetype = pagebuf->pfn_types[i + curbatch] &  XEN_DOMCTL_PFINFO_LTAB_MASK;
 
-        if ( pagetype == XEN_DOMCTL_PFINFO_XTAB 
+        if ( pagetype == XEN_DOMCTL_PFINFO_XTAB
              || pagetype == XEN_DOMCTL_PFINFO_XALLOC)
+        {
+            local_invalid_pages++;
             /* a bogus/unmapped/allocate-only page: skip it */
             continue;
+        }
 
         if ( pagetype == XEN_DOMCTL_PFINFO_BROKEN )
         {
@@ -1306,6 +1315,8 @@ static int apply_batch(xc_interface *xch, uint32_t dom, struct restore_ctx *ctx,
                       "dom=%d, pfn=%lx\n", dom, pfn);
                 goto err_mapped;
             }
+
+            local_invalid_pages++;
             continue;
         }
 
@@ -1344,7 +1355,7 @@ static int apply_batch(xc_interface *xch, uint32_t dom, struct restore_ctx *ctx,
             }
         }
         else
-            memcpy(page, pagebuf->pages + (curpage + curbatch) * PAGE_SIZE,
+            memcpy(page, pagebuf->pages + (first_page + curpage) * PAGE_SIZE,
                    PAGE_SIZE);
 
         pagetype &= XEN_DOMCTL_PFINFO_LTABTYPE_MASK;
@@ -1418,6 +1429,7 @@ static int apply_batch(xc_interface *xch, uint32_t dom, struct restore_ctx *ctx,
     } /* end of 'batch' for loop */
 
     rc = nraces;
+    *invalid_pages += local_invalid_pages;
 
   err_mapped:
     munmap(region_base, j*PAGE_SIZE);
@@ -1621,7 +1633,7 @@ int xc_domain_restore(xc_interface *xch, int io_fd, uint32_t dom,
  loadpages:
     for ( ; ; )
     {
-        int j, curbatch;
+        int j, curbatch, invalid_pages;
 
         xc_report_progress_step(xch, n, dinfo->p2m_size);
 
@@ -1665,11 +1677,13 @@ int xc_domain_restore(xc_interface *xch, int io_fd, uint32_t dom,
 
         /* break pagebuf into batches */
         curbatch = 0;
+        invalid_pages = 0;
         while ( curbatch < j ) {
             int brc;
 
             brc = apply_batch(xch, dom, ctx, region_mfn, pfn_type,
-                              pae_extended_cr3, mmu, &pagebuf, curbatch);
+                              pae_extended_cr3, mmu, &pagebuf, curbatch,
+                              &invalid_pages);
             if ( brc < 0 )
                 goto out;
 
Signature · 1 line
1.9.3
#2 lore raw

RFC PATCH 2/25 csum the correct page

In reply to Wen Congyang

In verify mode, we map the guest memory, and the guest page is region_base + i * PAGE_SIZE. So we should csum page (region_base
+ i * PAGE_SIZE), not (region_base + (i+curbatch) * PAGE_SIZE)

---
 tools/libxc/xc_domain_restore.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/libxc/xc_domain_restore.c +1 -1
index f7ca4ad..89b84fc 100644
@@ -1405,7 +1405,7 @@ static int apply_batch(xc_interface *xch, uint32_t dom, struct restore_ctx *ctx,
 
                 DPRINTF("************** pfn=%lx type=%lx gotcs=%08lx "
                         "actualcs=%08lx\n", pfn, pagebuf->pfn_types[pfn],
-                        csum_page(region_base + (i + curbatch)*PAGE_SIZE),
+                        csum_page(region_base + i * PAGE_SIZE),
                         csum_page(buf));
 
                 for ( v = 0; v < 4; v++ )
Signature · 1 line
1.9.3
#3 lore raw

RFC PATCH 3/25 don't zero out ioreq page

In reply to Wen Congyang

ioreq page may contain some pending I/O requests, and we need to handle the pending I/O req after migration.

TODO:
1. update qemu to handle the pending I/O req

---
 tools/libxc/xc_domain_restore.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
tools/libxc/xc_domain_restore.c +1 -3
index 89b84fc..32a3e72 100644
@@ -2301,9 +2301,7 @@ int xc_domain_restore(xc_interface *xch, int io_fd, uint32_t dom,
     }
 
     /* These comms pages need to be zeroed at the start of day */
-    if ( xc_clear_domain_page(xch, dom, tailbuf.u.hvm.magicpfns[0]) ||
-         xc_clear_domain_page(xch, dom, tailbuf.u.hvm.magicpfns[1]) ||
-         xc_clear_domain_page(xch, dom, tailbuf.u.hvm.magicpfns[2]) )
+    if ( xc_clear_domain_page(xch, dom, tailbuf.u.hvm.magicpfns[2]) )
     {
         PERROR("error zeroing magic pages");
         goto out;
Signature · 1 line
1.9.3
#4 lore raw

RFC PATCH 4/25 don't touch remus in remus_device

In reply to Wen Congyang

remus device is an abstract layer to do checkpoint. COLO can also use it to do checkpoint. But there is still some codes in remus device which touch remus:
1. netbufscript is for remus, move it to domain_suspend_state
2. diskbuf: not a suitable name for checkpoint. Use enabled_device_kinds to instead of it.

---
 tools/libxl/libxl.c              |  9 ++++++---
 tools/libxl/libxl_internal.h     | 19 ++++++++++++-------
 tools/libxl/libxl_netbuffer.c    |  7 +++++--
 tools/libxl/libxl_remus_device.c |  4 ++--
 4 files changed, 25 insertions(+), 14 deletions(-)
tools/libxl/libxl.c +6 -3
index cd038d1..94087ff 100644
@@ -832,10 +832,10 @@ int libxl_domain_remus_start(libxl_ctx *ctx, libxl_domain_remus_info *info,
         }
 
         if (info->netbufscript) {
-            rds->netbufscript =
+            dss->netbufscript =
                 libxl__strdup(gc, info->netbufscript);
         } else {
-            rds->netbufscript =
+            dss->netbufscript =
                 GCSPRINTF("%s/remus-netbuf-setup",
                 libxl__xen_script_dir_path());
         }
@@ -844,9 +844,12 @@ int libxl_domain_remus_start(libxl_ctx *ctx, libxl_domain_remus_info *info,
     rds->ao = ao;
     rds->egc = egc;
     rds->domid = domid;
-    rds->diskbuf = info->diskbuf;
     rds->callback = libxl__remus_setup_done;
     rds->ops = remus_ops;
+    if (info->diskbuf)
+        rds->enabled_device_kinds |= LIBXL__REMUS_DEVICE_DISK;
+    if (info->netbuf)
+        rds->enabled_device_kinds |= LIBXL__REMUS_DEVICE_NIC;
 
     /* Point of no return */
     libxl__remus_devices_setup(egc, rds);
tools/libxl/libxl_internal.h +12 -7
index 441a51f..e327604 100644
@@ -2505,8 +2505,8 @@ typedef struct libxl__save_helper_state {
  */
 
 typedef enum libxl__remus_device_kind {
-    LIBXL__REMUS_DEVICE_NIC,
-    LIBXL__REMUS_DEVICE_DISK,
+    LIBXL__REMUS_DEVICE_NIC = (1 << 0),
+    LIBXL__REMUS_DEVICE_DISK= (1 << 1),
 } libxl__remus_device_kind;
 
 typedef struct libxl__remus_device libxl__remus_device;
@@ -2581,8 +2581,7 @@ struct libxl__remus_device_state {
     libxl__remus_callback *callback;
     /* the last ops must be NULL */
     const libxl__remus_device_subkind_ops **ops;
-    const char *netbufscript;
-    bool diskbuf;
+    int enabled_device_kinds;
 
     /* private */
     /* devices that have been set up */
@@ -2692,9 +2691,15 @@ struct libxl__domain_suspend_state {
     libxl__ev_xswatch guest_watch;
     libxl__ev_time guest_timeout;
     const char *dm_savefile;
-    libxl__remus_device_state rds;
-    libxl__ev_time checkpoint_timeout; /* used for Remus checkpoint */
-    int interval; /* checkpoint interval (for Remus) */
+    /* for Remus */
+    struct {
+        libxl__remus_device_state rds;
+        const char *netbufscript;
+        /* used for Remus checkpoint */
+        libxl__ev_time checkpoint_timeout;
+        /* checkpoint interval */
+        int interval;
+    };
     libxl__save_helper_state shs;
     libxl__logdirty_switch logdirty;
     void (*callback_common_done)(libxl__egc*,
tools/libxl/libxl_netbuffer.c +5 -2
index 39025f4..2387563 100644
@@ -28,6 +28,7 @@
 struct libxl__remus_netbuf_state {
     libxl__ao *ao;
     uint32_t domid;
+    const char *netbufscript;
 
     struct nl_sock *nlsock;
     struct nl_cache *qdisc_cache;
@@ -51,6 +52,7 @@ static int nic_init(libxl__remus_device_state *rds)
 {
     int rc, ret;
     libxl__remus_netbuf_state *ns;
+    libxl__domain_suspend_state *dss = CONTAINER_OF(rds, *dss, rds);
 
     STATE_AO_GC(rds->ao);
 
@@ -83,6 +85,7 @@ static int nic_init(libxl__remus_device_state *rds)
 
     ns->ao = rds->ao;
     ns->domid = rds->domid;
+    ns->netbufscript = dss->netbufscript;
 
     rc = 0;
 
@@ -258,7 +261,7 @@ static void setup_async_exec(libxl__remus_device *dev, char *op)
 
     /* Convenience aliases */
     libxl__remus_netbuf_state *ns = CTX->rns;
-    char *const script = libxl__strdup(gc, dev->rds->netbufscript);
+    char *const script = libxl__strdup(gc, ns->netbufscript);
     const uint32_t domid = ns->domid;
     const int dev_id = remus_nic->devid;
     const char *const vif = remus_nic->vif;
@@ -381,7 +384,7 @@ static void netbuf_setup_script_cb(libxl__egc *egc,
 
     if (hotplug_error) {
         LOG(ERROR, "netbuf script %s setup failed for vif %s: %s",
-            dev->rds->netbufscript, vif, hotplug_error);
+            CTX->rns->netbufscript, vif, hotplug_error);
         rc = ERROR_FAIL;
         goto out;
     }
tools/libxl/libxl_remus_device.c +2 -2
index c9df7f0..2acf3bb 100644
@@ -86,10 +86,10 @@ void libxl__remus_devices_setup(libxl__egc *egc, libxl__remus_device_state *rds)
     rds->num_nics = 0;
     rds->num_disks = 0;
 
-    if (rds->netbufscript)
+    if (rds->enabled_device_kinds & LIBXL__REMUS_DEVICE_NIC)
         rds->nics = libxl_device_nic_list(CTX, rds->domid, &rds->num_nics);
 
-    if (rds->diskbuf)
+    if (rds->enabled_device_kinds & LIBXL__REMUS_DEVICE_NIC)
         rds->disks = libxl_device_disk_list(CTX, rds->domid, &rds->num_disks);
 
     if (rds->num_nics == 0 && rds->num_disks == 0)
Signature · 1 line
1.9.3
#5 lore raw

RFC PATCH 5/25 rename remus device to checkpoint device

In reply to Wen Congyang

This patch is auto generated by the following commands:
1. git mv tools/libxl/libxl_remus_device.c tools/libxl/libxl_checkpoint_device.c
2. perl -pi -e 's/libxl_remus_device/libxl_checkpoint_device/g' tools/libxl/Makefile
3. perl -pi -e 's/libxl__remus_device/libxl__checkpoint_device/g' tools/libxl/*.[ch]
4. perl -pi -e 's/remus_device_checkpoint_api/checkpoint_device_api/g' tools/libxl/*.[ch]
5. perl -pi -e 's/\brds\b/cds/g' tools/libxl/*.[ch]
6. perl -pi -e 's/REMUS_DEVICE/CHECKPOINT_DEVICE/g' tools/libxl/*.[ch] tools/libxl/*.idl
7. perl -pi -e 's/REMUS_DEVOPS/CHECKPOINT_DEVOPS/g' tools/libxl/*.[ch] tools/libxl/*.idl
8. perl -pi -e 's/\bremus\b/checkpoint/g' tools/libxl/libxl_checkpoint_device.[ch]

---
 tools/libxl/Makefile                               |   2 +-
 tools/libxl/libxl.c                                |  36 +--
 ...xl_remus_device.c => libxl_checkpoint_device.c} | 258 ++++++++++-----------
 tools/libxl/libxl_dom.c                            |  46 ++--
 tools/libxl/libxl_internal.h                       | 102 ++++----
 tools/libxl/libxl_netbuffer.c                      |  80 +++----
 tools/libxl/libxl_nonetbuffer.c                    |  14 +-
 tools/libxl/libxl_remus_disk_drbd.c                |  54 ++---
 tools/libxl/libxl_types.idl                        |   4 +-
 9 files changed, 298 insertions(+), 298 deletions(-)
 rename tools/libxl/{libxl_remus_device.c => libxl_checkpoint_device.c} (49%)
tools/libxl/Makefile +1 -1
index ba10ab7..a33497d 100644
@@ -56,7 +56,7 @@ else
 LIBXL_OBJS-y += libxl_nonetbuffer.o
 endif
 
-LIBXL_OBJS-y += libxl_remus_device.o libxl_remus_disk_drbd.o
+LIBXL_OBJS-y += libxl_checkpoint_device.o libxl_remus_disk_drbd.o
 
 LIBXL_OBJS-$(CONFIG_X86) += libxl_cpuid.o libxl_x86.o
 LIBXL_OBJS-$(CONFIG_ARM) += libxl_nocpuid.o libxl_arm.o
tools/libxl/libxl.c +18 -18
index 94087ff..fc60bb1 100644
@@ -782,13 +782,13 @@ out:
 }
 
 static void libxl__remus_setup_done(libxl__egc *egc,
-                                    libxl__remus_device_state *rds, int rc);
+                                    libxl__checkpoint_device_state *cds, int rc);
 static void libxl__remus_setup_failed(libxl__egc *egc,
-                                      libxl__remus_device_state *rds, int rc);
+                                      libxl__checkpoint_device_state *cds, int rc);
 static void remus_failover_cb(libxl__egc *egc,
                               libxl__domain_suspend_state *dss, int rc);
 
-static const libxl__remus_device_subkind_ops *remus_ops[] = {
+static const libxl__checkpoint_device_subkind_ops *remus_ops[] = {
     &remus_device_nic,
     &remus_device_drbd_disk,
     NULL,
@@ -823,7 +823,7 @@ int libxl_domain_remus_start(libxl_ctx *ctx, libxl_domain_remus_info *info,
     assert(info);
 
     /* Convenience aliases */
-    libxl__remus_device_state *const rds = &dss->rds;
+    libxl__checkpoint_device_state *const cds = &dss->cds;
 
     if (info->netbuf) {
         if (!libxl__netbuffer_enabled(gc)) {
@@ -841,18 +841,18 @@ int libxl_domain_remus_start(libxl_ctx *ctx, libxl_domain_remus_info *info,
         }
     }
 
-    rds->ao = ao;
-    rds->egc = egc;
-    rds->domid = domid;
-    rds->callback = libxl__remus_setup_done;
-    rds->ops = remus_ops;
+    cds->ao = ao;
+    cds->egc = egc;
+    cds->domid = domid;
+    cds->callback = libxl__remus_setup_done;
+    cds->ops = remus_ops;
     if (info->diskbuf)
-        rds->enabled_device_kinds |= LIBXL__REMUS_DEVICE_DISK;
+        cds->enabled_device_kinds |= LIBXL__CHECKPOINT_DEVICE_DISK;
     if (info->netbuf)
-        rds->enabled_device_kinds |= LIBXL__REMUS_DEVICE_NIC;
+        cds->enabled_device_kinds |= LIBXL__CHECKPOINT_DEVICE_NIC;
 
     /* Point of no return */
-    libxl__remus_devices_setup(egc, rds);
+    libxl__checkpoint_devices_setup(egc, cds);
     return AO_INPROGRESS;
 
  out:
@@ -860,9 +860,9 @@ int libxl_domain_remus_start(libxl_ctx *ctx, libxl_domain_remus_info *info,
 }
 
 static void libxl__remus_setup_done(libxl__egc *egc,
-                                    libxl__remus_device_state *rds, int rc)
+                                    libxl__checkpoint_device_state *cds, int rc)
 {
-    libxl__domain_suspend_state *dss = CONTAINER_OF(rds, *dss, rds);
+    libxl__domain_suspend_state *dss = CONTAINER_OF(cds, *dss, cds);
     STATE_AO_GC(dss->ao);
 
     if (!rc) {
@@ -872,14 +872,14 @@ static void libxl__remus_setup_done(libxl__egc *egc,
 
     LOG(ERROR, "Remus: failed to setup device for guest with domid %u, rc %d",
         dss->domid, rc);
-    rds->callback = libxl__remus_setup_failed;
-    libxl__remus_devices_teardown(egc, rds);
+    cds->callback = libxl__remus_setup_failed;
+    libxl__checkpoint_devices_teardown(egc, cds);
 }
 
 static void libxl__remus_setup_failed(libxl__egc *egc,
-                                      libxl__remus_device_state *rds, int rc)
+                                      libxl__checkpoint_device_state *cds, int rc)
 {
-    libxl__domain_suspend_state *dss = CONTAINER_OF(rds, *dss, rds);
+    libxl__domain_suspend_state *dss = CONTAINER_OF(cds, *dss, cds);
     STATE_AO_GC(dss->ao);
 
     if (rc)
tools/libxl/libxl_checkpoint_device.c renamed from tools/libxl/libxl_remus_device.c +129 -129

443 lines not on this page · raw message

tools/libxl/libxl_dom.c +23 -23

127 lines not on this page · raw message

tools/libxl/libxl_internal.h +51 -51

202 lines not on this page · raw message

tools/libxl/libxl_netbuffer.c +40 -40

224 lines not on this page · raw message

tools/libxl/libxl_nonetbuffer.c +7 -7
index fc29c36..b4a067e 100644
@@ -22,25 +22,25 @@ int libxl__netbuffer_enabled(libxl__gc *gc)
     return 0;
 }
 
-static void nic_match(libxl__remus_device *dev)
+static void nic_match(libxl__checkpoint_device *dev)
 {
-    STATE_AO_GC(dev->rds->ao);
+    STATE_AO_GC(dev->cds->ao);
 
-    dev->callback(dev->rds->egc, dev, ERROR_FAIL);
+    dev->callback(dev->cds->egc, dev, ERROR_FAIL);
 }
 
-static int nic_init(libxl__remus_device_state *rds)
+static int nic_init(libxl__checkpoint_device_state *cds)
 {
     return 0;
 }
 
-static void nic_destroy(libxl__remus_device_state *rds)
+static void nic_destroy(libxl__checkpoint_device_state *cds)
 {
     return;
 }
 
-const libxl__remus_device_subkind_ops remus_device_nic = {
-    .kind = LIBXL__REMUS_DEVICE_NIC,
+const libxl__checkpoint_device_subkind_ops remus_device_nic = {
+    .kind = LIBXL__CHECKPOINT_DEVICE_NIC,
     .init = nic_init,
     .destroy = nic_destroy,
     .match = nic_match,
tools/libxl/libxl_remus_disk_drbd.c +27 -27

160 lines not on this page · raw message

tools/libxl/libxl_types.idl +2 -2
index 6551109..dc9f78e 100644
@@ -58,8 +58,8 @@ libxl_error = Enumeration("error", [
     (-12, "OSEVENT_REG_FAIL"),
     (-13, "BUFFERFULL"),
     (-14, "UNKNOWN_CHILD"),
-    (-15, "REMUS_DEVOPS_NOT_MATCH"),
-    (-16, "REMUS_DEVICE_NOT_SUPPORTED"),
+    (-15, "CHECKPOINT_DEVOPS_NOT_MATCH"),
+    (-16, "CHECKPOINT_DEVICE_NOT_SUPPORTED"),
     ], value_namespace = "")
 
 libxl_domain_type = Enumeration("domain_type", [
Signature · 1 line
1.9.3
#6 lore raw

RFC PATCH 6/25 adjust the indentation

In reply to Wen Congyang
---
 tools/libxl/libxl_checkpoint_device.c | 32 ++++++++++++++++++--------------
 tools/libxl/libxl_internal.h          | 14 +++++++-------
 2 files changed, 25 insertions(+), 21 deletions(-)
tools/libxl/libxl_checkpoint_device.c +18 -14
index 87ee412..b1575f7 100644
@@ -67,10 +67,11 @@ static void device_teardown_cb(libxl__egc *egc,
 /* checkpoint device setup and teardown */
 
 static void libxl__checkpoint_device_init(libxl__egc *egc,
-                                     libxl__checkpoint_device_state *cds,
-                                     libxl__checkpoint_device_kind kind,
-                                     void *libxl_dev);
-void libxl__checkpoint_devices_setup(libxl__egc *egc, libxl__checkpoint_device_state *cds)
+                                          libxl__checkpoint_device_state *cds,
+                                          libxl__checkpoint_device_kind kind,
+                                          void *libxl_dev);
+void libxl__checkpoint_devices_setup(libxl__egc *egc,
+                                     libxl__checkpoint_device_state *cds)
 {
     int i;
     STATE_AO_GC(cds->ao);
@@ -99,12 +100,14 @@ void libxl__checkpoint_devices_setup(libxl__egc *egc, libxl__checkpoint_device_s
 
     for (i = 0; i < cds->num_nics; i++) {
         libxl__checkpoint_device_init(egc, cds,
-                                 LIBXL__CHECKPOINT_DEVICE_NIC, &cds->nics[i]);
+                                      LIBXL__CHECKPOINT_DEVICE_NIC,
+                                      &cds->nics[i]);
     }
 
     for (i = 0; i < cds->num_disks; i++) {
         libxl__checkpoint_device_init(egc, cds,
-                                 LIBXL__CHECKPOINT_DEVICE_DISK, &cds->disks[i]);
+                                      LIBXL__CHECKPOINT_DEVICE_DISK,
+                                      &cds->disks[i]);
     }
 
     return;
@@ -115,9 +118,9 @@ out:
 }
 
 static void libxl__checkpoint_device_init(libxl__egc *egc,
-                                     libxl__checkpoint_device_state *cds,
-                                     libxl__checkpoint_device_kind kind,
-                                     void *libxl_dev)
+                                          libxl__checkpoint_device_state *cds,
+                                          libxl__checkpoint_device_kind kind,
+                                          void *libxl_dev)
 {
     libxl__checkpoint_device *dev = NULL;
 
@@ -234,7 +237,8 @@ static void device_setup_cb(libxl__egc *egc,
         cds->callback(egc, cds, cds->saved_rc);
 }
 
-void libxl__checkpoint_devices_teardown(libxl__egc *egc, libxl__checkpoint_device_state *cds)
+void libxl__checkpoint_devices_teardown(libxl__egc *egc,
+                                        libxl__checkpoint_device_state *cds)
 {
     int i, num_set_up;
     libxl__checkpoint_device *dev;
@@ -309,12 +313,12 @@ static void device_checkpoint_cb(libxl__egc *egc,
 
 /* API implementations */
 
-#define define_checkpoint_device_api(api)                             \
-void libxl__checkpoint_devices_##api(libxl__egc *egc,                            \
-                                libxl__checkpoint_device_state *cds)             \
+#define define_checkpoint_device_api(api)                                   \
+void libxl__checkpoint_devices_##api(libxl__egc *egc,                       \
+                                libxl__checkpoint_device_state *cds)        \
 {                                                                           \
     int i;                                                                  \
-    libxl__checkpoint_device *dev;                                               \
+    libxl__checkpoint_device *dev;                                          \
                                                                             \
     STATE_AO_GC(cds->ao);                                                   \
                                                                             \
tools/libxl/libxl_internal.h +7 -7
index f18503e..bb2aaed 100644
@@ -2600,8 +2600,8 @@ struct libxl__checkpoint_device_state {
 };
 
 typedef void libxl__checkpoint_device_callback(libxl__egc *,
-                                          libxl__checkpoint_device *,
-                                          int rc);
+                                               libxl__checkpoint_device *,
+                                               int rc);
 /*
  * This structure is init and setup by remus device abstruct layer,
  * and pass to remus device ops
@@ -2638,15 +2638,15 @@ struct libxl__checkpoint_device {
 
 /* the following 5 APIs are async ops, call cds->callback when done */
 _hidden void libxl__checkpoint_devices_setup(libxl__egc *egc,
-                                        libxl__checkpoint_device_state *cds);
+                                             libxl__checkpoint_device_state *cds);
 _hidden void libxl__checkpoint_devices_teardown(libxl__egc *egc,
-                                           libxl__checkpoint_device_state *cds);
+                                                libxl__checkpoint_device_state *cds);
 _hidden void libxl__checkpoint_devices_postsuspend(libxl__egc *egc,
-                                              libxl__checkpoint_device_state *cds);
+                                                   libxl__checkpoint_device_state *cds);
 _hidden void libxl__checkpoint_devices_preresume(libxl__egc *egc,
-                                            libxl__checkpoint_device_state *cds);
+                                                 libxl__checkpoint_device_state *cds);
 _hidden void libxl__checkpoint_devices_commit(libxl__egc *egc,
-                                         libxl__checkpoint_device_state *cds);
+                                              libxl__checkpoint_device_state *cds);
 
 extern const libxl__checkpoint_device_subkind_ops remus_device_nic;
 extern const libxl__checkpoint_device_subkind_ops remus_device_drbd_disk;
Signature · 1 line
1.9.3
#7 lore raw

RFC PATCH 7/25 Refactor domain_suspend_callback_common()

In reply to Wen Congyang

libxl__domain_suspend() is to save the guest. I think we should call it libxl__domain_save(), but I don't rename it.

Secondary vm is running in colo mode. So we will do the following things again and again:
1. suspend both primay vm and secondary vm
2. sync the state
3. resume both primary vm and secondary vm
To suspend secondary vm, we need an independent API to suspend vm.

The core function to suspend vm is domain_suspend_callback_common(). So use a new structure libxl__domain_suspend_state2 to instead of libxl__domain_suspend_state. The dss's members that will be used in domain_suspend_callback_common() are moved to dss2.

We introduce a new API libxl__domain_suspend2() too.

---
 tools/libxl/libxl_dom.c      | 235 ++++++++++++++++++++++++-------------------
 tools/libxl/libxl_internal.h |  39 +++++--
 2 files changed, 159 insertions(+), 115 deletions(-)
tools/libxl/libxl_dom.c +130 -105
index cf79b74..035d25a 100644
@@ -797,7 +797,7 @@ int libxl__toolstack_restore(uint32_t domid, const uint8_t *buf,
 static void domain_suspend_done(libxl__egc *egc,
                         libxl__domain_suspend_state *dss, int rc);
 static void domain_suspend_callback_common_done(libxl__egc *egc,
-                                libxl__domain_suspend_state *dss, int ok);
+                                libxl__domain_suspend_state2 *dss2, int ok);
 
 /*----- complicated callback, called by xc_domain_save -----*/
 
@@ -1015,16 +1015,17 @@ static void switch_logdirty_done(libxl__egc *egc,
 /*----- callbacks, called by xc_domain_save -----*/
 
 int libxl__domain_suspend_device_model(libxl__gc *gc,
-                                       libxl__domain_suspend_state *dss)
+                                       libxl__domain_suspend_state2 *dss2)
 {
     int ret = 0;
-    uint32_t const domid = dss->domid;
-    const char *const filename = dss->dm_savefile;
+    uint32_t const domid = dss2->domid;
+    const char *const filename = dss2->dm_savefile;
 
     switch (libxl__device_model_version_running(gc, domid)) {
     case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL: {
         LOG(DEBUG, "Saving device model state to %s", filename);
-        libxl__qemu_traditional_cmd(gc, domid, "save");
+        if (dss2->save_dm)
+            libxl__qemu_traditional_cmd(gc, domid, "save");
         libxl__wait_for_device_model_deprecated(gc, domid, "paused", NULL, NULL, NULL);
         break;
     }
@@ -1032,9 +1033,11 @@ int libxl__domain_suspend_device_model(libxl__gc *gc,
         if (libxl__qmp_stop(gc, domid))
             return ERROR_FAIL;
         /* Save DM state into filename */
-        ret = libxl__qmp_save(gc, domid, filename);
-        if (ret)
-            unlink(filename);
+        if (dss2->save_dm) {
+            ret = libxl__qmp_save(gc, domid, filename);
+            if (ret)
+                unlink(filename);
+        }
         break;
     default:
         return ERROR_INVAL;
@@ -1064,9 +1067,9 @@ int libxl__domain_resume_device_model(libxl__gc *gc, uint32_t domid)
 }
 
 static void domain_suspend_common_wait_guest(libxl__egc *egc,
-                                             libxl__domain_suspend_state *dss);
+                                             libxl__domain_suspend_state2 *dss2);
 static void domain_suspend_common_guest_suspended(libxl__egc *egc,
-                                         libxl__domain_suspend_state *dss);
+                                         libxl__domain_suspend_state2 *dss2);
 
 static void domain_suspend_common_pvcontrol_suspending(libxl__egc *egc,
       libxl__xswait_state *xswa, int rc, const char *state);
@@ -1075,14 +1078,14 @@ static void domain_suspend_common_wait_guest_evtchn(libxl__egc *egc,
 static void suspend_common_wait_guest_watch(libxl__egc *egc,
       libxl__ev_xswatch *xsw, const char *watch_path, const char *event_path);
 static void suspend_common_wait_guest_check(libxl__egc *egc,
-        libxl__domain_suspend_state *dss);
+                                            libxl__domain_suspend_state2 *dss2);
 static void suspend_common_wait_guest_timeout(libxl__egc *egc,
       libxl__ev_time *ev, const struct timeval *requested_abs);
 
 static void domain_suspend_common_failed(libxl__egc *egc,
-                                         libxl__domain_suspend_state *dss);
+                                         libxl__domain_suspend_state2 *dss2);
 static void domain_suspend_common_done(libxl__egc *egc,
-                                       libxl__domain_suspend_state *dss,
+                                       libxl__domain_suspend_state2 *dss2,
                                        bool ok);
 
 static bool domain_suspend_pvcontrol_acked(const char *state) {
@@ -1091,36 +1094,36 @@ static bool domain_suspend_pvcontrol_acked(const char *state) {
     return strcmp(state,"suspend");
 }
 
-/* calls dss->callback_common_done when done */
+/* calls dss2->callback_common_done when done */
 static void domain_suspend_callback_common(libxl__egc *egc,
-                                           libxl__domain_suspend_state *dss)
+                                           libxl__domain_suspend_state2 *dss2)
 {
-    STATE_AO_GC(dss->ao);
+    STATE_AO_GC(dss2->ao);
     uint64_t hvm_s_state = 0, hvm_pvdrv = 0;
     int ret, rc;
 
     /* Convenience aliases */
-    const uint32_t domid = dss->domid;
+    const uint32_t domid = dss2->domid;
 
-    if (dss->hvm) {
+    if (dss2->hvm) {
         xc_hvm_param_get(CTX->xch, domid, HVM_PARAM_CALLBACK_IRQ, &hvm_pvdrv);
         xc_hvm_param_get(CTX->xch, domid, HVM_PARAM_ACPI_S_STATE, &hvm_s_state);
     }
 
-    if ((hvm_s_state == 0) && (dss->guest_evtchn.port >= 0)) {
+    if ((hvm_s_state == 0) && (dss2->guest_evtchn.port >= 0)) {
         LOG(DEBUG, "issuing %s suspend request via event channel",
-            dss->hvm ? "PVHVM" : "PV");
-        ret = xc_evtchn_notify(CTX->xce, dss->guest_evtchn.port);
+            dss2->hvm ? "PVHVM" : "PV");
+        ret = xc_evtchn_notify(CTX->xce, dss2->guest_evtchn.port);
         if (ret < 0) {
             LOG(ERROR, "xc_evtchn_notify failed ret=%d", ret);
             goto err;
         }
 
-        dss->guest_evtchn.callback = domain_suspend_common_wait_guest_evtchn;
-        rc = libxl__ev_evtchn_wait(gc, &dss->guest_evtchn);
+        dss2->guest_evtchn.callback = domain_suspend_common_wait_guest_evtchn;
+        rc = libxl__ev_evtchn_wait(gc, &dss2->guest_evtchn);
         if (rc) goto err;
 
-        rc = libxl__ev_time_register_rel(gc, &dss->guest_timeout,
+        rc = libxl__ev_time_register_rel(gc, &dss2->guest_timeout,
                                          suspend_common_wait_guest_timeout,
                                          60*1000);
         if (rc) goto err;
@@ -1128,7 +1131,7 @@ static void domain_suspend_callback_common(libxl__egc *egc,
         return;
     }
 
-    if (dss->hvm && (!hvm_pvdrv || hvm_s_state)) {
+    if (dss2->hvm && (!hvm_pvdrv || hvm_s_state)) {
         LOG(DEBUG, "Calling xc_domain_shutdown on HVM domain");
         ret = xc_domain_shutdown(CTX->xch, domid, SHUTDOWN_suspend);
         if (ret < 0) {
@@ -1136,55 +1139,55 @@ static void domain_suspend_callback_common(libxl__egc *egc,
             goto err;
         }
         /* The guest does not (need to) respond to this sort of request. */
-        dss->guest_responded = 1;
-        domain_suspend_common_wait_guest(egc, dss);
+        dss2->guest_responded = 1;
+        domain_suspend_common_wait_guest(egc, dss2);
         return;
     }
 
     LOG(DEBUG, "issuing %s suspend request via XenBus control node",
-        dss->hvm ? "PVHVM" : "PV");
+        dss2->hvm ? "PVHVM" : "PV");
 
     libxl__domain_pvcontrol_write(gc, XBT_NULL, domid, "suspend");
 
-    dss->pvcontrol.path = libxl__domain_pvcontrol_xspath(gc, domid);
-    if (!dss->pvcontrol.path) goto err;
+    dss2->pvcontrol.path = libxl__domain_pvcontrol_xspath(gc, domid);
+    if (!dss2->pvcontrol.path) goto err;
 
-    dss->pvcontrol.ao = ao;
-    dss->pvcontrol.what = "guest acknowledgement of suspend request";
-    dss->pvcontrol.timeout_ms = 60 * 1000;
-    dss->pvcontrol.callback = domain_suspend_common_pvcontrol_suspending;
-    libxl__xswait_start(gc, &dss->pvcontrol);
+    dss2->pvcontrol.ao = ao;
+    dss2->pvcontrol.what = "guest acknowledgement of suspend request";
+    dss2->pvcontrol.timeout_ms = 60 * 1000;
+    dss2->pvcontrol.callback = domain_suspend_common_pvcontrol_suspending;
+    libxl__xswait_start(gc, &dss2->pvcontrol);
     return;
 
  err:
-    domain_suspend_common_failed(egc, dss);
+    domain_suspend_common_failed(egc, dss2);
 }
 
 static void domain_suspend_common_wait_guest_evtchn(libxl__egc *egc,
-        libxl__ev_evtchn *evev)
+                                                    libxl__ev_evtchn *evev)
 {
-    libxl__domain_suspend_state *dss = CONTAINER_OF(evev, *dss, guest_evtchn);
-    STATE_AO_GC(dss->ao);
+    libxl__domain_suspend_state2 *dss2 = CONTAINER_OF(evev, *dss2, guest_evtchn);
+    STATE_AO_GC(dss2->ao);
     /* If we should be done waiting, suspend_common_wait_guest_check
      * will end up calling domain_suspend_common_guest_suspended or
      * domain_suspend_common_failed, both of which cancel the evtchn
      * wait.  So re-enable it now. */
-    libxl__ev_evtchn_wait(gc, &dss->guest_evtchn);
-    suspend_common_wait_guest_check(egc, dss);
+    libxl__ev_evtchn_wait(gc, &dss2->guest_evtchn);
+    suspend_common_wait_guest_check(egc, dss2);
 }
 
 static void domain_suspend_common_pvcontrol_suspending(libxl__egc *egc,
       libxl__xswait_state *xswa, int rc, const char *state)
 {
-    libxl__domain_suspend_state *dss = CONTAINER_OF(xswa, *dss, pvcontrol);
-    STATE_AO_GC(dss->ao);
+    libxl__domain_suspend_state2 *dss2 = CONTAINER_OF(xswa, *dss2, pvcontrol);
+    STATE_AO_GC(dss2->ao);
     xs_transaction_t t = 0;
 
     if (!rc && !domain_suspend_pvcontrol_acked(state))
         /* keep waiting */
         return;
 
-    libxl__xswait_stop(gc, &dss->pvcontrol);
+    libxl__xswait_stop(gc, &dss2->pvcontrol);
 
     if (rc == ERROR_TIMEDOUT) {
         /*
@@ -1227,56 +1230,56 @@ static void domain_suspend_common_pvcontrol_suspending(libxl__egc *egc,
     LOG(DEBUG, "guest acknowledged suspend request");
 
     libxl__xs_transaction_abort(gc, &t);
-    dss->guest_responded = 1;
-    domain_suspend_common_wait_guest(egc,dss);
+    dss2->guest_responded = 1;
+    domain_suspend_common_wait_guest(egc,dss2);
     return;
 
  err:
     libxl__xs_transaction_abort(gc, &t);
-    domain_suspend_common_failed(egc, dss);
+    domain_suspend_common_failed(egc, dss2);
     return;
 }
 
 static void domain_suspend_common_wait_guest(libxl__egc *egc,
-                                             libxl__domain_suspend_state *dss)
+                                             libxl__domain_suspend_state2 *dss2)
 {
-    STATE_AO_GC(dss->ao);
+    STATE_AO_GC(dss2->ao);
     int rc;
 
     LOG(DEBUG, "wait for the guest to suspend");
 
-    rc = libxl__ev_xswatch_register(gc, &dss->guest_watch,
+    rc = libxl__ev_xswatch_register(gc, &dss2->guest_watch,
                                     suspend_common_wait_guest_watch,
                                     "@releaseDomain");
     if (rc) goto err;
 
-    rc = libxl__ev_time_register_rel(gc, &dss->guest_timeout,
+    rc = libxl__ev_time_register_rel(gc, &dss2->guest_timeout,
                                      suspend_common_wait_guest_timeout,
                                      60*1000);
     if (rc) goto err;
     return;
 
  err:
-    domain_suspend_common_failed(egc, dss);
+    domain_suspend_common_failed(egc, dss2);
 }
 
 static void suspend_common_wait_guest_watch(libxl__egc *egc,
       libxl__ev_xswatch *xsw, const char *watch_path, const char *event_path)
 {
-    libxl__domain_suspend_state *dss = CONTAINER_OF(xsw, *dss, guest_watch);
-    suspend_common_wait_guest_check(egc, dss);
+    libxl__domain_suspend_state2 *dss2 = CONTAINER_OF(xsw, *dss2, guest_watch);
+    suspend_common_wait_guest_check(egc, dss2);
 }
 
 static void suspend_common_wait_guest_check(libxl__egc *egc,
-        libxl__domain_suspend_state *dss)
+                                            libxl__domain_suspend_state2 *dss2)
 {
-    STATE_AO_GC(dss->ao);
+    STATE_AO_GC(dss2->ao);
     xc_domaininfo_t info;
     int ret;
     int shutdown_reason;
 
     /* Convenience aliases */
-    const uint32_t domid = dss->domid;
+    const uint32_t domid = dss2->domid;
 
     ret = xc_domain_getinfolist(CTX->xch, domid, 1, &info);
     if (ret < 0) {
@@ -1303,59 +1306,59 @@ static void suspend_common_wait_guest_check(libxl__egc *egc,
     }
 
     LOG(DEBUG, "guest has suspended");
-    domain_suspend_common_guest_suspended(egc, dss);
+    domain_suspend_common_guest_suspended(egc, dss2);
     return;
 
  err:
-    domain_suspend_common_failed(egc, dss);
+    domain_suspend_common_failed(egc, dss2);
 }
 
 static void suspend_common_wait_guest_timeout(libxl__egc *egc,
       libxl__ev_time *ev, const struct timeval *requested_abs)
 {
-    libxl__domain_suspend_state *dss = CONTAINER_OF(ev, *dss, guest_timeout);
-    STATE_AO_GC(dss->ao);
+    libxl__domain_suspend_state2 *dss2 = CONTAINER_OF(ev, *dss2, guest_timeout);
+    STATE_AO_GC(dss2->ao);
     LOG(ERROR, "guest did not suspend, timed out");
-    domain_suspend_common_failed(egc, dss);
+    domain_suspend_common_failed(egc, dss2);
 }
 
 static void domain_suspend_common_guest_suspended(libxl__egc *egc,
-                                         libxl__domain_suspend_state *dss)
+                                            libxl__domain_suspend_state2 *dss2)
 {
-    STATE_AO_GC(dss->ao);
+    STATE_AO_GC(dss2->ao);
     int ret;
 
-    libxl__ev_evtchn_cancel(gc, &dss->guest_evtchn);
-    libxl__ev_xswatch_deregister(gc, &dss->guest_watch);
-    libxl__ev_time_deregister(gc, &dss->guest_timeout);
+    libxl__ev_evtchn_cancel(gc, &dss2->guest_evtchn);
+    libxl__ev_xswatch_deregister(gc, &dss2->guest_watch);
+    libxl__ev_time_deregister(gc, &dss2->guest_timeout);
 
-    if (dss->hvm) {
-        ret = libxl__domain_suspend_device_model(gc, dss);
+    if (dss2->hvm) {
+        ret = libxl__domain_suspend_device_model(gc, dss2);
         if (ret) {
             LOG(ERROR, "libxl__domain_suspend_device_model failed ret=%d", ret);
-            domain_suspend_common_failed(egc, dss);
+            domain_suspend_common_failed(egc, dss2);
             return;
         }
     }
-    domain_suspend_common_done(egc, dss, 1);
+    domain_suspend_common_done(egc, dss2, 1);
 }
 
 static void domain_suspend_common_failed(libxl__egc *egc,
-                                         libxl__domain_suspend_state *dss)
+                                         libxl__domain_suspend_state2 *dss2)
 {
-    domain_suspend_common_done(egc, dss, 0);
+    domain_suspend_common_done(egc, dss2, 0);
 }
 
 static void domain_suspend_common_done(libxl__egc *egc,
-                                       libxl__domain_suspend_state *dss,
+                                       libxl__domain_suspend_state2 *dss2,
                                        bool ok)
 {
     EGC_GC;
-    assert(!libxl__xswait_inuse(&dss->pvcontrol));
-    libxl__ev_evtchn_cancel(gc, &dss->guest_evtchn);
-    libxl__ev_xswatch_deregister(gc, &dss->guest_watch);
-    libxl__ev_time_deregister(gc, &dss->guest_timeout);
-    dss->callback_common_done(egc, dss, ok);
+    assert(!libxl__xswait_inuse(&dss2->pvcontrol));
+    libxl__ev_evtchn_cancel(gc, &dss2->guest_evtchn);
+    libxl__ev_xswatch_deregister(gc, &dss2->guest_watch);
+    libxl__ev_time_deregister(gc, &dss2->guest_timeout);
+    dss2->callback_common_done(egc, dss2, ok);
 }
 
 static inline char *physmap_path(libxl__gc *gc, uint32_t domid,
@@ -1448,19 +1451,24 @@ static void libxl__domain_suspend_callback(void *data)
     libxl__egc *egc = shs->egc;
     libxl__domain_suspend_state *dss = CONTAINER_OF(shs, *dss, shs);
 
-    dss->callback_common_done = domain_suspend_callback_common_done;
-    domain_suspend_callback_common(egc, dss);
+    /* Convenience aliases */
+    libxl__domain_suspend_state2 *dss2 = &dss->dss2;
+
+    dss2->callback_common_done = domain_suspend_callback_common_done;
+    domain_suspend_callback_common(egc, dss2);
 }
 
 static void domain_suspend_callback_common_done(libxl__egc *egc,
-                                libxl__domain_suspend_state *dss, int ok)
+                                libxl__domain_suspend_state2 *dss2, int ok)
 {
+    libxl__domain_suspend_state *dss = CONTAINER_OF(dss2, *dss, dss2);
+
     libxl__xc_domain_saverestore_async_callback_done(egc, &dss->shs, ok);
 }
 
 /*----- remus callbacks -----*/
 static void remus_domain_suspend_callback_common_done(libxl__egc *egc,
-                                libxl__domain_suspend_state *dss, int ok);
+                                libxl__domain_suspend_state2 *dss2, int ok);
 static void remus_device_postsuspend_cb(libxl__egc *egc,
                                         libxl__checkpoint_device_state *cds,
                                         int rc);
@@ -1474,13 +1482,18 @@ static void libxl__remus_domain_suspend_callback(void *data)
     libxl__egc *egc = shs->egc;
     libxl__domain_suspend_state *dss = CONTAINER_OF(shs, *dss, shs);
 
-    dss->callback_common_done = remus_domain_suspend_callback_common_done;
-    domain_suspend_callback_common(egc, dss);
+    /* Convenience aliases */
+    libxl__domain_suspend_state2 *const dss2 = &dss->dss2;
+
+    dss2->callback_common_done = remus_domain_suspend_callback_common_done;
+    domain_suspend_callback_common(egc, dss2);
 }
 
 static void remus_domain_suspend_callback_common_done(libxl__egc *egc,
-                                libxl__domain_suspend_state *dss, int ok)
+                                libxl__domain_suspend_state2 *dss2, int ok)
 {
+    libxl__domain_suspend_state *dss = CONTAINER_OF(dss2, *dss, dss2);
+
     if (!ok)
         goto out;
 
@@ -1622,6 +1635,11 @@ static void remus_next_checkpoint(libxl__egc *egc, libxl__ev_time *ev,
 }
 
 /*----- main code for suspending, in order of execution -----*/
+void libxl__domain_suspend2(libxl__egc *egc,
+                            libxl__domain_suspend_state2 *dss2)
+{
+    domain_suspend_callback_common(egc, dss2);
+}
 
 void libxl__domain_suspend(libxl__egc *egc, libxl__domain_suspend_state *dss)
 {
@@ -1637,20 +1655,23 @@ void libxl__domain_suspend(libxl__egc *egc, libxl__domain_suspend_state *dss)
     const libxl_domain_remus_info *const r_info = dss->remus;
     libxl__srm_save_autogen_callbacks *const callbacks =
         &dss->shs.callbacks.save.a;
+    libxl__domain_suspend_state2 *dss2 = &dss->dss2;
 
     logdirty_init(&dss->logdirty);
-    libxl__xswait_init(&dss->pvcontrol);
-    libxl__ev_evtchn_init(&dss->guest_evtchn);
-    libxl__ev_xswatch_init(&dss->guest_watch);
-    libxl__ev_time_init(&dss->guest_timeout);
+    libxl__xswait_init(&dss2->pvcontrol);
+    libxl__ev_evtchn_init(&dss2->guest_evtchn);
+    libxl__ev_xswatch_init(&dss2->guest_watch);
+    libxl__ev_time_init(&dss2->guest_timeout);
 
     switch (type) {
     case LIBXL_DOMAIN_TYPE_HVM: {
         dss->hvm = 1;
+        dss2->hvm = 1;
         break;
     }
     case LIBXL_DOMAIN_TYPE_PV:
         dss->hvm = 0;
+        dss2->hvm = 0;
         break;
     default:
         abort();
@@ -1660,10 +1681,13 @@ void libxl__domain_suspend(libxl__egc *egc, libxl__domain_suspend_state *dss)
           | (debug ? XCFLAGS_DEBUG : 0)
           | (dss->hvm ? XCFLAGS_HVM : 0);
 
-    dss->guest_evtchn.port = -1;
-    dss->guest_evtchn_lockfd = -1;
-    dss->guest_responded = 0;
-    dss->dm_savefile = libxl__device_model_savefile(gc, domid);
+    dss2->guest_evtchn.port = -1;
+    dss2->guest_evtchn_lockfd = -1;
+    dss2->guest_responded = 0;
+    dss2->dm_savefile = libxl__device_model_savefile(gc, domid);
+    dss2->domid = domid;
+    dss2->ao = ao;
+    dss2->save_dm = 1;
 
     if (r_info != NULL) {
         dss->interval = r_info->interval;
@@ -1674,11 +1698,11 @@ void libxl__domain_suspend(libxl__egc *egc, libxl__domain_suspend_state *dss)
     port = xs_suspend_evtchn_port(dss->domid);
 
     if (port >= 0) {
-        dss->guest_evtchn.port =
+        dss2->guest_evtchn.port =
             xc_suspend_evtchn_init_exclusive(CTX->xch, CTX->xce,
-                                  dss->domid, port, &dss->guest_evtchn_lockfd);
+                                  dss->domid, port, &dss2->guest_evtchn_lockfd);
 
-        if (dss->guest_evtchn.port < 0) {
+        if (dss2->guest_evtchn.port < 0) {
             LOG(WARN, "Suspend event channel initialization failed");
             rc = ERROR_FAIL;
             goto out;
@@ -1717,10 +1741,10 @@ void libxl__xc_domain_save_done(libxl__egc *egc, void *dss_void,
 
     if (retval) {
         LOGEV(ERROR, errnoval, "saving domain: %s",
-                         dss->guest_responded ?
+                         dss->dss2.guest_responded ?
                          "domain responded to suspend request" :
                          "domain did not respond to suspend request");
-        if ( !dss->guest_responded )
+        if ( !dss->dss2.guest_responded )
             rc = ERROR_GUEST_TIMEDOUT;
         else
             rc = ERROR_FAIL;
@@ -1728,7 +1752,7 @@ void libxl__xc_domain_save_done(libxl__egc *egc, void *dss_void,
     }
 
     if (type == LIBXL_DOMAIN_TYPE_HVM) {
-        rc = libxl__domain_suspend_device_model(gc, dss);
+        rc = libxl__domain_suspend_device_model(gc, &dss->dss2);
         if (rc) goto out;
 
         libxl__domain_save_device_model(egc, dss, domain_suspend_done);
@@ -1756,7 +1780,7 @@ void libxl__domain_save_device_model(libxl__egc *egc,
     dss->save_dm_callback = callback;
 
     /* Convenience aliases */
-    const char *const filename = dss->dm_savefile;
+    const char *const filename = dss->dss2.dm_savefile;
     const int fd = dss->fd;
 
     libxl__datacopier_state *dc = &dss->save_dm_datacopier;
@@ -1812,7 +1836,7 @@ static void save_device_model_datacopier_done(libxl__egc *egc,
     STATE_AO_GC(dss->ao);
 
     /* Convenience aliases */
-    const char *const filename = dss->dm_savefile;
+    const char *const filename = dss->dss2.dm_savefile;
     int our_rc = 0;
     int rc;
 
@@ -1842,12 +1866,13 @@ static void domain_suspend_done(libxl__egc *egc,
 
     /* Convenience aliases */
     const uint32_t domid = dss->domid;
+    libxl__domain_suspend_state2 *const dss2 = &dss->dss2;
 
-    libxl__ev_evtchn_cancel(gc, &dss->guest_evtchn);
+    libxl__ev_evtchn_cancel(gc, &dss2->guest_evtchn);
 
-    if (dss->guest_evtchn.port > 0)
+    if (dss2->guest_evtchn.port > 0)
         xc_suspend_evtchn_release(CTX->xch, CTX->xce, domid,
-                           dss->guest_evtchn.port, &dss->guest_evtchn_lockfd);
+                           dss2->guest_evtchn.port, &dss2->guest_evtchn_lockfd);
 
     if (dss->remus) {
         /*
tools/libxl/libxl_internal.h +29 -10
index bb2aaed..881f3b9 100644
@@ -2656,6 +2656,7 @@ _hidden int libxl__netbuffer_enabled(libxl__gc *gc);
 /*----- Domain suspend (save) state structure -----*/
 
 typedef struct libxl__domain_suspend_state libxl__domain_suspend_state;
+typedef struct libxl__domain_suspend_state2 libxl__domain_suspend_state2;
 
 typedef void libxl__domain_suspend_cb(libxl__egc*,
                                       libxl__domain_suspend_state*, int rc);
@@ -2670,6 +2671,29 @@ typedef struct libxl__logdirty_switch {
     libxl__ev_time timeout;
 } libxl__logdirty_switch;
 
+/*
+ * libxl__domain_suspend_state is for saving guest, not
+ * for suspending guest. We need to an independent API
+ * to suspend guest only.
+ */
+struct libxl__domain_suspend_state2 {
+    /* set by caller of libxl__domain_suspend2 */
+    libxl__ao *ao;
+
+    uint32_t domid;
+    libxl__ev_evtchn guest_evtchn;;
+    int guest_evtchn_lockfd;
+    int hvm;
+    const char *dm_savefile;
+    void (*callback_common_done)(libxl__egc*,
+                                 libxl__domain_suspend_state2*, int ok);
+    int save_dm;
+    int guest_responded;
+    libxl__xswait_state pvcontrol;
+    libxl__ev_xswatch guest_watch;
+    libxl__ev_time guest_timeout;
+};
+
 struct libxl__domain_suspend_state {
     /* set by caller of libxl__domain_suspend */
     libxl__ao *ao;
@@ -2682,15 +2706,9 @@ struct libxl__domain_suspend_state {
     int debug;
     const libxl_domain_remus_info *remus;
     /* private */
-    libxl__ev_evtchn guest_evtchn;
-    int guest_evtchn_lockfd;
+    libxl__domain_suspend_state2 dss2;
     int hvm;
     int xcflags;
-    int guest_responded;
-    libxl__xswait_state pvcontrol;
-    libxl__ev_xswatch guest_watch;
-    libxl__ev_time guest_timeout;
-    const char *dm_savefile;
     /* for Remus */
     struct {
         libxl__checkpoint_device_state cds;
@@ -2702,8 +2720,6 @@ struct libxl__domain_suspend_state {
     };
     libxl__save_helper_state shs;
     libxl__logdirty_switch logdirty;
-    void (*callback_common_done)(libxl__egc*,
-                                 struct libxl__domain_suspend_state*, int ok);
     /* private for libxl__domain_save_device_model */
     libxl__save_device_model_cb *save_dm_callback;
     libxl__datacopier_state save_dm_datacopier;
@@ -2975,6 +2991,9 @@ struct libxl__domain_create_state {
 
 /*----- Domain suspend (save) functions -----*/
 
+/* calls dss2->callback_common_done when done */
+_hidden void libxl__domain_suspend2(libxl__egc *egc,
+                                    libxl__domain_suspend_state2 *dss2);
 /* calls dss->callback when done */
 _hidden void libxl__domain_suspend(libxl__egc *egc,
                                    libxl__domain_suspend_state *dss);
@@ -3014,7 +3033,7 @@ _hidden void libxl__xc_domain_restore_done(libxl__egc *egc, void *dcs_void,
 
 /* Each time the dm needs to be saved, we must call suspend and then save */
 _hidden int libxl__domain_suspend_device_model(libxl__gc *gc,
-                                           libxl__domain_suspend_state *dss);
+                                           libxl__domain_suspend_state2 *dss2);
 _hidden void libxl__domain_save_device_model(libxl__egc *egc,
                                      libxl__domain_suspend_state *dss,
                                      libxl__save_device_model_cb *callback);
Signature · 1 line
1.9.3
#8 lore raw

RFC PATCH 8/25 Update libxl__domain_resume() for colo

In reply to Wen Congyang

Secondary vm is running in colo mode. So we will do the following things again and again:
1. suspend both primay vm and secondary vm
2. sync the state
3. resume both primary vm and secondary vm
We will send qemu's state each time in step2, and slave's qemu should read it each time before resuming secondary vm. libxl__domain_resume() doesn't read qemu's state. Add a new parameter to control whether we need to read qemu's state before resuming.

Note: we should update qemu to support it.

---
 tools/libxl/libxl.c          |  7 ++++---
 tools/libxl/libxl_dom.c      | 24 +++++++++++++++++++++---
 tools/libxl/libxl_internal.h |  8 ++++++--
 tools/libxl/libxl_qmp.c      | 10 ++++++++++
 4 files changed, 41 insertions(+), 8 deletions(-)
tools/libxl/libxl.c +4 -3
index fc60bb1..7ff1cb6 100644
@@ -466,7 +466,8 @@ int libxl_domain_rename(libxl_ctx *ctx, uint32_t domid,
     return rc;
 }
 
-int libxl__domain_resume(libxl__gc *gc, uint32_t domid, int suspend_cancel)
+int libxl__domain_resume(libxl__gc *gc, uint32_t domid,
+                         int suspend_cancel, int read_savefile)
 {
     int rc = 0;
 
@@ -483,7 +484,7 @@ int libxl__domain_resume(libxl__gc *gc, uint32_t domid, int suspend_cancel)
     }
 
     if (type == LIBXL_DOMAIN_TYPE_HVM) {
-        rc = libxl__domain_resume_device_model(gc, domid);
+        rc = libxl__domain_resume_device_model(gc, domid, read_savefile);
         if (rc) {
             LOG(ERROR, "failed to resume device model for domain %u:%d",
                 domid, rc);
@@ -503,7 +504,7 @@ int libxl_domain_resume(libxl_ctx *ctx, uint32_t domid, int suspend_cancel,
                         const libxl_asyncop_how *ao_how)
 {
     AO_CREATE(ctx, domid, ao_how);
-    int rc = libxl__domain_resume(gc, domid, suspend_cancel);
+    int rc = libxl__domain_resume(gc, domid, suspend_cancel, 0);
     libxl__ao_complete(egc, ao, rc);
     return AO_INPROGRESS;
 }
tools/libxl/libxl_dom.c +21 -3
index 035d25a..206c1dd 100644
@@ -1046,16 +1046,34 @@ int libxl__domain_suspend_device_model(libxl__gc *gc,
     return ret;
 }
 
-int libxl__domain_resume_device_model(libxl__gc *gc, uint32_t domid)
+int libxl__domain_resume_device_model(libxl__gc *gc, uint32_t domid,
+                                      int read_savefile)
 {
 
     switch (libxl__device_model_version_running(gc, domid)) {
     case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL: {
-        libxl__qemu_traditional_cmd(gc, domid, "continue");
+        if (read_savefile)
+            libxl__qemu_traditional_cmd(gc, domid, "resume");
+        else
+            libxl__qemu_traditional_cmd(gc, domid, "continue");
         libxl__wait_for_device_model_deprecated(gc, domid, "running", NULL, NULL, NULL);
         break;
     }
     case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN:
+        if (read_savefile) {
+            char *state_file;
+            int rc;
+
+            state_file = libxl__sprintf(NOGC,
+                                        XC_DEVICE_MODEL_RESTORE_FILE".%d",
+                                        domid);
+            /* This command only restores the device state */
+            rc = libxl__qmp_restore(gc, domid, state_file);
+            free(state_file);
+            if (rc)
+                return ERROR_FAIL;
+        }
+
         if (libxl__qmp_resume(gc, domid))
             return ERROR_FAIL;
         break;
@@ -1540,7 +1558,7 @@ static void remus_device_preresume_cb(libxl__egc *egc,
 
     if (!rc) {
         /* Resumes the domain and the device model */
-        if (!libxl__domain_resume(gc, dss->domid, /* Fast Suspend */1))
+        if (!libxl__domain_resume(gc, dss->domid, /* Fast Suspend */1, 0))
             ok = 1;
     }
     libxl__xc_domain_saverestore_async_callback_done(egc, &dss->shs, ok);
tools/libxl/libxl_internal.h +6 -2
index 881f3b9..35227d3 100644
@@ -994,12 +994,14 @@ _hidden int libxl__domain_rename(libxl__gc *gc, uint32_t domid,
 
 _hidden int libxl__toolstack_restore(uint32_t domid, const uint8_t *buf,
                                      uint32_t size, void *data);
-_hidden int libxl__domain_resume_device_model(libxl__gc *gc, uint32_t domid);
+_hidden int libxl__domain_resume_device_model(libxl__gc *gc,
+                                              uint32_t domid,
+                                              int read_savefile);
 
 _hidden void libxl__userdata_destroyall(libxl__gc *gc, uint32_t domid);
 
 _hidden int libxl__domain_resume(libxl__gc *gc, uint32_t domid,
-                                 int suspend_cancel);
+                                 int suspend_cancel, int read_savefile);
 
 /* returns 0 or 1, or a libxl error code */
 _hidden int libxl__domain_pvcontrol_available(libxl__gc *gc, uint32_t domid);
@@ -1585,6 +1587,8 @@ _hidden int libxl__qmp_stop(libxl__gc *gc, int domid);
 _hidden int libxl__qmp_resume(libxl__gc *gc, int domid);
 /* Save current QEMU state into fd. */
 _hidden int libxl__qmp_save(libxl__gc *gc, int domid, const char *filename);
+/* Load current QEMU state from fd. */
+_hidden int libxl__qmp_restore(libxl__gc *gc, int domid, const char *filename);
 /* Set dirty bitmap logging status */
 _hidden int libxl__qmp_set_global_dirty_log(libxl__gc *gc, int domid, bool enable);
 _hidden int libxl__qmp_insert_cdrom(libxl__gc *gc, int domid, const libxl_device_disk *disk);
tools/libxl/libxl_qmp.c +10 -0
index 5cc56b1..60a119d 100644
@@ -876,6 +876,16 @@ int libxl__qmp_save(libxl__gc *gc, int domid, const char *filename)
                            NULL, NULL);
 }
 
+int libxl__qmp_restore(libxl__gc *gc, int domid, const char *state_file)
+{
+    libxl__json_object *args = NULL;
+
+    qmp_parameters_add_string(gc, &args, "filename", (char *)state_file);
+
+    return qmp_run_command(gc, domid, "xen-load-devices-state", args,
+                           NULL, NULL);
+}
+
 static int qmp_change(libxl__gc *gc, libxl__qmp_handler *qmp,
                       char *device, char *target, char *arg)
 {
Signature · 1 line
1.9.3
#9 lore raw

RFC PATCH 9/25 Update libxl__domain_suspend_common_switch_qemu_logdirty() for colo

In reply to Wen Congyang

Secondary vm is running in colo mode. So we need to send secondary vm's dirty page information to master. libxl__domain_suspend_common_switch_qemu_logdirty() is to enable qemu logdirty. But it uses domain_suspend_state, and calls libxl__xc_domain_saverestore_async_callback_done() before exits.

Introduce a new API libxl__domain_common_switch_qemu_logdirty(). This API only uses libxl__logdirty_switch, and calls lds->callback before exits.

---
 tools/libxl/libxl_dom.c      | 79 +++++++++++++++++++++++++++-----------------
 tools/libxl/libxl_internal.h | 12 +++++--
 2 files changed, 59 insertions(+), 32 deletions(-)
tools/libxl/libxl_dom.c +49 -30
index 206c1dd..32db79f 100644
@@ -814,7 +814,7 @@ static void switch_logdirty_timeout(libxl__egc *egc, libxl__ev_time *ev,
 static void switch_logdirty_xswatch(libxl__egc *egc, libxl__ev_xswatch*,
                             const char *watch_path, const char *event_path);
 static void switch_logdirty_done(libxl__egc *egc,
-                                 libxl__domain_suspend_state *dss, int ok);
+                                 libxl__logdirty_switch *lds, int ok);
 
 static void logdirty_init(libxl__logdirty_switch *lds)
 {
@@ -825,12 +825,10 @@ static void logdirty_init(libxl__logdirty_switch *lds)
 
 static void domain_suspend_switch_qemu_xen_traditional_logdirty
                                (int domid, unsigned enable,
-                                libxl__save_helper_state *shs)
+                                libxl__logdirty_switch *lds,
+                                libxl__egc *egc)
 {
-    libxl__egc *egc = shs->egc;
-    libxl__domain_suspend_state *dss = CONTAINER_OF(shs, *dss, shs);
-    libxl__logdirty_switch *lds = &dss->logdirty;
-    STATE_AO_GC(dss->ao);
+    STATE_AO_GC(lds->ao);
     int rc;
     xs_transaction_t t = 0;
     const char *got;
@@ -891,64 +889,85 @@ static void domain_suspend_switch_qemu_xen_traditional_logdirty
  out:
     LOG(ERROR,"logdirty switch failed (rc=%d), aborting suspend",rc);
     libxl__xs_transaction_abort(gc, &t);
-    switch_logdirty_done(egc,dss,-1);
+    switch_logdirty_done(egc,lds,-1);
 }
 
 static void domain_suspend_switch_qemu_xen_logdirty
                                (int domid, unsigned enable,
-                                libxl__save_helper_state *shs)
+                                libxl__logdirty_switch *lds,
+                                libxl__egc *egc)
 {
-    libxl__egc *egc = shs->egc;
-    libxl__domain_suspend_state *dss = CONTAINER_OF(shs, *dss, shs);
-    STATE_AO_GC(dss->ao);
+    STATE_AO_GC(lds->ao);
     int rc;
 
     rc = libxl__qmp_set_global_dirty_log(gc, domid, enable);
     if (!rc) {
-        libxl__xc_domain_saverestore_async_callback_done(egc, shs, 0);
+        lds->callback(egc, lds, 0);
     } else {
         LOG(ERROR,"logdirty switch failed (rc=%d), aborting suspend",rc);
-        libxl__xc_domain_saverestore_async_callback_done(egc, shs, -1);
+        lds->callback(egc, lds, -1);
     }
 }
 
+static void libxl__domain_suspend_switch_qemu_logdirty_done
+                                (libxl__egc *egc,
+                                 libxl__logdirty_switch *lds,
+                                 int rc)
+{
+    libxl__domain_suspend_state *dss = CONTAINER_OF(lds, *dss, logdirty);
+
+    libxl__xc_domain_saverestore_async_callback_done(egc, &dss->shs, rc);
+}
+
 void libxl__domain_suspend_common_switch_qemu_logdirty
                                (int domid, unsigned enable, void *user)
 {
     libxl__save_helper_state *shs = user;
     libxl__egc *egc = shs->egc;
     libxl__domain_suspend_state *dss = CONTAINER_OF(shs, *dss, shs);
-    STATE_AO_GC(dss->ao);
+
+    /* convenience aliases */
+    libxl__logdirty_switch *const lds = &dss->logdirty;
+
+    lds->callback = libxl__domain_suspend_switch_qemu_logdirty_done;
+
+    libxl__domain_common_switch_qemu_logdirty(domid, enable, lds, egc);
+}
+
+void libxl__domain_common_switch_qemu_logdirty(int domid, unsigned enable,
+                                               libxl__logdirty_switch *lds,
+                                               libxl__egc *egc)
+{
+    STATE_AO_GC(lds->ao);
 
     switch (libxl__device_model_version_running(gc, domid)) {
     case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL:
-        domain_suspend_switch_qemu_xen_traditional_logdirty(domid, enable, shs);
+        domain_suspend_switch_qemu_xen_traditional_logdirty(domid, enable,
+                                                            lds, egc);
         break;
     case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN:
-        domain_suspend_switch_qemu_xen_logdirty(domid, enable, shs);
+        domain_suspend_switch_qemu_xen_logdirty(domid, enable, lds, egc);
         break;
     default:
         LOG(ERROR,"logdirty switch failed"
             ", no valid device model version found, aborting suspend");
-        libxl__xc_domain_saverestore_async_callback_done(egc, shs, -1);
+        lds->callback(egc, lds, -1);
     }
 }
 static void switch_logdirty_timeout(libxl__egc *egc, libxl__ev_time *ev,
                                     const struct timeval *requested_abs)
 {
-    libxl__domain_suspend_state *dss = CONTAINER_OF(ev, *dss, logdirty.timeout);
-    STATE_AO_GC(dss->ao);
+    libxl__logdirty_switch *lds = CONTAINER_OF(ev, *lds, timeout);
+    STATE_AO_GC(lds->ao);
     LOG(ERROR,"logdirty switch: wait for device model timed out");
-    switch_logdirty_done(egc,dss,-1);
+    switch_logdirty_done(egc,lds,-1);
 }
 
 static void switch_logdirty_xswatch(libxl__egc *egc, libxl__ev_xswatch *watch,
                             const char *watch_path, const char *event_path)
 {
-    libxl__domain_suspend_state *dss =
-        CONTAINER_OF(watch, *dss, logdirty.watch);
-    libxl__logdirty_switch *lds = &dss->logdirty;
-    STATE_AO_GC(dss->ao);
+    libxl__logdirty_switch *lds = CONTAINER_OF(watch, *lds, watch);
+    STATE_AO_GC(lds->ao);
     const char *got;
     xs_transaction_t t = 0;
     int rc;
@@ -992,24 +1011,23 @@ static void switch_logdirty_xswatch(libxl__egc *egc, libxl__ev_xswatch *watch,
     libxl__xs_transaction_abort(gc, &t);
 
     if (!rc) {
-        switch_logdirty_done(egc,dss,0);
+        switch_logdirty_done(egc,lds,0);
     } else if (rc < 0) {
         LOG(ERROR,"logdirty switch: failed (rc=%d)",rc);
-        switch_logdirty_done(egc,dss,-1);
+        switch_logdirty_done(egc,lds,-1);
     }
 }
 
 static void switch_logdirty_done(libxl__egc *egc,
-                                 libxl__domain_suspend_state *dss,
+                                 libxl__logdirty_switch *lds,
                                  int broke)
 {
-    STATE_AO_GC(dss->ao);
-    libxl__logdirty_switch *lds = &dss->logdirty;
+    STATE_AO_GC(lds->ao);
 
     libxl__ev_xswatch_deregister(gc, &lds->watch);
     libxl__ev_time_deregister(gc, &lds->timeout);
 
-    libxl__xc_domain_saverestore_async_callback_done(egc, &dss->shs, broke);
+    lds->callback(egc, lds, broke);
 }
 
 /*----- callbacks, called by xc_domain_save -----*/
@@ -1676,6 +1694,7 @@ void libxl__domain_suspend(libxl__egc *egc, libxl__domain_suspend_state *dss)
     libxl__domain_suspend_state2 *dss2 = &dss->dss2;
 
     logdirty_init(&dss->logdirty);
+    dss->logdirty.ao = ao;
     libxl__xswait_init(&dss2->pvcontrol);
     libxl__ev_evtchn_init(&dss2->guest_evtchn);
     libxl__ev_xswatch_init(&dss2->guest_watch);
tools/libxl/libxl_internal.h +10 -2
index 35227d3..2dd157c 100644
@@ -2667,13 +2667,18 @@ typedef void libxl__domain_suspend_cb(libxl__egc*,
 typedef void libxl__save_device_model_cb(libxl__egc*,
                                          libxl__domain_suspend_state*, int rc);
 
-typedef struct libxl__logdirty_switch {
+typedef struct libxl__logdirty_switch libxl__logdirty_switch;
+struct libxl__logdirty_switch {
+    /* set by caller of libxl__domain_common_switch_qemu_logdirty */
+    libxl__ao *ao;
+    void (*callback)(libxl__egc *egc, libxl__logdirty_switch *lds, int rc);
+
     const char *cmd;
     const char *cmd_path;
     const char *ret_path;
     libxl__ev_xswatch watch;
     libxl__ev_time timeout;
-} libxl__logdirty_switch;
+};
 
 /*
  * libxl__domain_suspend_state is for saving guest, not
@@ -3021,6 +3026,9 @@ void libxl__xc_domain_saverestore_async_callback_done(libxl__egc *egc,
 
 _hidden void libxl__domain_suspend_common_switch_qemu_logdirty
                                (int domid, unsigned int enable, void *data);
+_hidden void libxl__domain_common_switch_qemu_logdirty
+                                (int domid, unsigned int enable,
+                                 libxl__logdirty_switch *lds, libxl__egc *egc);
 _hidden int libxl__toolstack_save(uint32_t domid, uint8_t **buf,
         uint32_t *len, void *data);
 
Signature · 1 line
1.9.3
#10 lore raw

RFC PATCH 10/25 Introduce a new internal API libxl__domain_unpause()

In reply to Wen Congyang

The guest is paused after libxl_domain_create_restore(). Secondary vm is running in colo mode. So we need to unpause the guest. The current API libxl_domain_unpause() is not an internal API. Introduce a new API to support it.

---
 tools/libxl/libxl.c          | 21 +++++++++++++++------
 tools/libxl/libxl_internal.h |  1 +
 2 files changed, 16 insertions(+), 6 deletions(-)
tools/libxl/libxl.c +15 -6
index 7ff1cb6..86958fe 100644
@@ -975,9 +975,8 @@ out:
     return AO_INPROGRESS;
 }
 
-int libxl_domain_unpause(libxl_ctx *ctx, uint32_t domid)
+int libxl__domain_unpause(libxl__gc *gc, uint32_t domid)
 {
-    GC_INIT(ctx);
     char *path;
     char *state;
     int ret, rc = 0;
@@ -997,12 +996,22 @@ int libxl_domain_unpause(libxl_ctx *ctx, uint32_t domid)
                                          NULL, NULL, NULL);
         }
     }
-    ret = xc_domain_unpause(ctx->xch, domid);
-    if (ret<0) {
-        LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "unpausing domain %d", domid);
+
+    ret = xc_domain_unpause(CTX->xch, domid);
+    if (ret < 0) {
+        LOGE(ERROR, "unpausing domain %d", domid);
         rc = ERROR_FAIL;
     }
- out:
+
+out:
+    return rc;
+}
+
+int libxl_domain_unpause(libxl_ctx *ctx, uint32_t domid)
+{
+    GC_INIT(ctx);
+    int rc = libxl__domain_unpause(gc, domid);
+
     GC_FREE;
     return rc;
 }
tools/libxl/libxl_internal.h +1 -0
index 2dd157c..bfc9513 100644
@@ -1002,6 +1002,7 @@ _hidden void libxl__userdata_destroyall(libxl__gc *gc, uint32_t domid);
 
 _hidden int libxl__domain_resume(libxl__gc *gc, uint32_t domid,
                                  int suspend_cancel, int read_savefile);
+_hidden int libxl__domain_unpause(libxl__gc *gc, uint32_t domid);
 
 /* returns 0 or 1, or a libxl error code */
 _hidden int libxl__domain_pvcontrol_available(libxl__gc *gc, uint32_t domid);
Signature · 1 line
1.9.3
#11 lore raw

RFC PATCH 11/25 Update libxl__domain_unpause() to support qemu-xen

In reply to Wen Congyang

Currently, libxl__domain_unpause() only supports qemu-xen-traditional. Update it to support qemu-xen.

---
 tools/libxl/libxl.c          | 13 +++++--------
 tools/libxl/libxl_dom.c      | 25 +++++++++++++++++++++++++
 tools/libxl/libxl_internal.h |  2 ++
 3 files changed, 32 insertions(+), 8 deletions(-)
tools/libxl/libxl.c +5 -8
index 86958fe..3fd31ed 100644
@@ -977,8 +977,6 @@ out:
 
 int libxl__domain_unpause(libxl__gc *gc, uint32_t domid)
 {
-    char *path;
-    char *state;
     int ret, rc = 0;
 
     libxl_domain_type type = libxl__domain_type(gc, domid);
@@ -988,12 +986,11 @@ int libxl__domain_unpause(libxl__gc *gc, uint32_t domid)
     }
 
     if (type == LIBXL_DOMAIN_TYPE_HVM) {
-        path = libxl__sprintf(gc, "/local/domain/0/device-model/%d/state", domid);
-        state = libxl__xs_read(gc, XBT_NULL, path);
-        if (state != NULL && !strcmp(state, "paused")) {
-            libxl__qemu_traditional_cmd(gc, domid, "continue");
-            libxl__wait_for_device_model_deprecated(gc, domid, "running",
-                                         NULL, NULL, NULL);
+        rc = libxl__domain_unpause_device_model(gc, domid);
+        if (rc < 0) {
+            LOG(ERROR, "failed to unpause device model for domain %u:%d",
+                domid, rc);
+            goto out;
         }
     }
 
tools/libxl/libxl_dom.c +25 -0
index 32db79f..d4bf8b3 100644
@@ -1942,6 +1942,31 @@ static void libxl__remus_teardown_done(libxl__egc *egc,
     dss->callback(egc, dss, rc);
 }
 
+int libxl__domain_unpause_device_model(libxl__gc *gc, uint32_t domid)
+{
+    char *path;
+    char *state;
+
+    switch (libxl__device_model_version_running(gc, domid)) {
+    case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL:
+        path = libxl__sprintf(gc, "/local/domain/0/device-model/%d/state", domid);
+        state = libxl__xs_read(gc, XBT_NULL, path);
+        if (state != NULL && !strcmp(state, "paused")) {
+            libxl__qemu_traditional_cmd(gc, domid, "continue");
+            libxl__wait_for_device_model_deprecated(gc, domid, "running",
+                                         NULL, NULL, NULL);
+        }
+    case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN:
+        if (libxl__qmp_resume(gc, domid))
+            return ERROR_FAIL;
+        break;
+    default:
+        return ERROR_FAIL;
+    }
+
+    return 0;
+}
+
 /*==================== Miscellaneous ====================*/
 
 char *libxl__uuid2string(libxl__gc *gc, const libxl_uuid uuid)
tools/libxl/libxl_internal.h +2 -0
index bfc9513..67c73a2 100644
@@ -997,6 +997,8 @@ _hidden int libxl__toolstack_restore(uint32_t domid, const uint8_t *buf,
 _hidden int libxl__domain_resume_device_model(libxl__gc *gc,
                                               uint32_t domid,
                                               int read_savefile);
+_hidden int libxl__domain_unpause_device_model(libxl__gc *gc,
+                                               uint32_t domid);
 
 _hidden void libxl__userdata_destroyall(libxl__gc *gc, uint32_t domid);
 
Signature · 1 line
1.9.3
#12 lore raw

RFC PATCH 12/25 support to resume uncooperative HVM guests

In reply to Wen Congyang

For PVHVM, the hypercall return code is 0, and it can be resumed in a new domain context.

For HVM, do nothing.

---
 tools/libxc/xc_resume.c | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)
tools/libxc/xc_resume.c +16 -4
index e67bebd..b862ce3 100644
@@ -109,6 +109,21 @@ static int xc_domain_resume_cooperative(xc_interface *xch, uint32_t domid)
     return do_domctl(xch, &domctl);
 }
 
+static int xc_domain_resume_hvm(xc_interface *xch, uint32_t domid)
+{
+    DECLARE_DOMCTL;
+
+    /*
+     * If it is PVHVM, the hypercall return code is 0, and resume
+     * it in a new domain context.
+     *
+     * If it is a HVM, do nothing.
+     */
+    domctl.cmd = XEN_DOMCTL_resumedomain;
+    domctl.domain = domid;
+    return do_domctl(xch, &domctl);
+}
+
 static int xc_domain_resume_any(xc_interface *xch, uint32_t domid)
 {
     DECLARE_DOMCTL;
@@ -138,10 +153,7 @@ static int xc_domain_resume_any(xc_interface *xch, uint32_t domid)
      */
 #if defined(__i386__) || defined(__x86_64__)
     if ( info.hvm )
-    {
-        ERROR("Cannot resume uncooperative HVM guests");
-        return rc;
-    }
+        return xc_domain_resume_hvm(xch, domid);
 
     if ( xc_domain_get_guest_width(xch, domid, &dinfo->guest_width) != 0 )
     {
Signature · 1 line
1.9.3
#13 lore raw

RFC PATCH 13/25 update datecopier to support sending data only

In reply to Wen Congyang

datacopier is to read some data and write it out. If we have some data to send it over network, we cannot use datacopier. Update it to support this case.

---
 tools/libxl/libxl_aoutils.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
tools/libxl/libxl_aoutils.c +5 -3
index b10d2e1..3e0c0ae 100644
@@ -309,9 +309,11 @@ int libxl__datacopier_start(libxl__datacopier_state *dc)
 
     libxl__datacopier_init(dc);
 
-    rc = libxl__ev_fd_register(gc, &dc->toread, datacopier_readable,
-                               dc->readfd, POLLIN);
-    if (rc) goto out;
+    if (dc->readfd >= 0) {
+        rc = libxl__ev_fd_register(gc, &dc->toread, datacopier_readable,
+                                   dc->readfd, POLLIN);
+        if (rc) goto out;
+    }
 
     rc = libxl__ev_fd_register(gc, &dc->towrite, datacopier_writable,
                                dc->writefd, POLLOUT);
Signature · 1 line
1.9.3
#14 lore raw

RFC PATCH 14/25 introduce a new API to aync read data from fd

In reply to Wen Congyang

In colo mode, we will read some data from an fd.
Introduce a new API to avoid redundant codes.

---
 tools/libxl/libxl_aoutils.c  | 73 ++++++++++++++++++++++++++++++++++++++++++++
 tools/libxl/libxl_internal.h | 30 ++++++++++++++++++
 2 files changed, 103 insertions(+)
tools/libxl/libxl_aoutils.c +73 -0
index 3e0c0ae..2d36403 100644
@@ -542,3 +542,76 @@ bool libxl__async_exec_inuse(const libxl__async_exec_state *aes)
     assert(time_inuse == child_inuse);
     return child_inuse;
 }
+
+
+/*----- data reader -----*/
+
+static void libxl__datareader_init(libxl__datareader_state *drs)
+{
+    assert(drs->ao);
+    libxl__ev_fd_init(&drs->toread);
+    drs->used = 0;
+}
+
+static void libxl__datareader_kill(libxl__datareader_state *drs)
+{
+    STATE_AO_GC(drs->ao);
+
+    libxl__ev_fd_deregister(gc, &drs->toread);
+}
+
+static void datareader_callback(libxl__egc *egc, libxl__datareader_state *drs,
+                                ssize_t size, int errnoval)
+{
+    libxl__datareader_kill(drs);
+    drs->callback(egc, drs, size, errnoval);
+}
+
+static void datareader_readable(libxl__egc *egc, libxl__ev_fd *ev,
+                                int fd, short events, short revents)
+{
+    libxl__datareader_state *drs = CONTAINER_OF(ev, *drs, toread);
+    STATE_AO_GC(drs->ao);
+    int r;
+
+    if (revents & ~POLLIN) {
+        LOG(ERROR, "unexpected poll event 0x%x (should be POLLIN) on %s",
+            revents, drs->readwhat);
+        datareader_callback(egc, drs, -1, 0);
+        return;
+    }
+
+    assert(revents & POLLIN);
+    while (1) {
+        r = read(ev->fd, drs->buf + drs->used, drs->readsize - drs->used);
+        if (r < 0) {
+            if (errno == EINTR)
+                continue;
+            if (errno == EWOULDBLOCK)
+                break;
+            LOGE(ERROR, "error reading %s",
+                 drs->readwhat);
+            datareader_callback(egc, drs, 0, errno);
+            return;
+        }
+        if (r == 0) {
+            datareader_callback(egc, drs, drs->used, 0);
+            break;
+        }
+
+        drs->used += r;
+    }
+}
+
+int libxl__datareader_start(libxl__datareader_state *drs)
+{
+    int rc;
+    STATE_AO_GC(drs->ao);
+
+    libxl__datareader_init(drs);
+
+    rc = libxl__ev_fd_register(gc, &drs->toread, datareader_readable,
+                               drs->readfd, POLLIN);
+
+    return rc;
+}
tools/libxl/libxl_internal.h +30 -0
index 67c73a2..5914953 100644
@@ -2097,6 +2097,36 @@ void libxl__async_exec_init(libxl__async_exec_state *aes);
 int libxl__async_exec_start(libxl__gc *gc, libxl__async_exec_state *aes);
 bool libxl__async_exec_inuse(const libxl__async_exec_state *aes);
 
+/*----- datareader: read data from one fd to buffer -----*/
+
+typedef struct libxl__datareader_state libxl__datareader_state;
+
+/*
+ * real_size>=1 means all data was read
+ * real_size==0 means failure happened when reading, errnoval is valid, logged
+ * real_size==-1 means some other internal failure, errnoval not valid, logged
+ * In all cases reader is killed before calling this callback
+ */
+typedef void libxl__datareader_callback(libxl__egc *egc,
+     libxl__datareader_state *drs, ssize_t real_size, int errnoval);
+
+struct libxl__datareader_state {
+    /* caller must fill these in, and they must all remain valid */
+    libxl__ao *ao;
+    int readfd;
+    ssize_t readsize;
+    /* for error msgs */
+    const char *readwhat;
+    libxl__datareader_callback *callback;
+    /* It must contain enough space to store readsize bytes */
+    void *buf;
+    /* remaining fields are private to datareader */
+    libxl__ev_fd toread;
+    ssize_t used;
+};
+
+_hidden int libxl__datareader_start(libxl__datareader_state *drs);
+
 /*----- device addition/removal -----*/
 
 typedef struct libxl__ao_device libxl__ao_device;
Signature · 1 line
1.9.3
#15 lore raw

RFC PATCH 15/25 Update libxl_save_msgs_gen.pl to support return data from xl to xc

In reply to Wen Congyang

Currently, all callbacks return an integer value or void. We cannot return some data to xc via callback. Update libxl_save_msgs_gen.pl to support this case.

---
 tools/libxl/libxl_internal.h       |  3 ++
 tools/libxl/libxl_save_callout.c   | 31 ++++++++++++++++++
 tools/libxl/libxl_save_helper.c    | 17 ++++++++++
 tools/libxl/libxl_save_msgs_gen.pl | 65 ++++++++++++++++++++++++++++++++++----
 4 files changed, 109 insertions(+), 7 deletions(-)
tools/libxl/libxl_internal.h +3 -0
index 5914953..9ff93e6 100644
@@ -3055,6 +3055,9 @@ _hidden void libxl__xc_domain_save_done(libxl__egc*, void *dss_void,
  * When they are ready to indicate completion, they call this. */
 void libxl__xc_domain_saverestore_async_callback_done(libxl__egc *egc,
                            libxl__save_helper_state *shs, int return_value);
+void libxl__xc_domain_saverestore_async_callback_done_with_data(libxl__egc *egc,
+                           libxl__save_helper_state *shs,
+                           const void *data, uint64_t size);
 
 
 _hidden void libxl__domain_suspend_common_switch_qemu_logdirty
tools/libxl/libxl_save_callout.c +31 -0
index 1c9f806..0c09d94 100644
@@ -145,6 +145,15 @@ void libxl__xc_domain_saverestore_async_callback_done(libxl__egc *egc,
     shs->egc = 0;
 }
 
+void libxl__xc_domain_saverestore_async_callback_done_with_data(libxl__egc *egc,
+                           libxl__save_helper_state *shs,
+                           const void *data, uint64_t size)
+{
+    shs->egc = egc;
+    libxl__srm_callout_sendreply_data(data, size, shs);
+    shs->egc = 0;
+}
+
 /*----- helper execution -----*/
 
 static void run_helper(libxl__egc *egc, libxl__save_helper_state *shs,
@@ -370,6 +379,28 @@ void libxl__srm_callout_sendreply(int r, void *user)
         helper_failed(egc, shs, ERROR_FAIL);
 }
 
+void libxl__srm_callout_sendreply_data(const void *data, uint64_t size, void *user)
+{
+    libxl__save_helper_state *shs = user;
+    libxl__egc *egc = shs->egc;
+    STATE_AO_GC(shs->ao);
+    int errnoval;
+
+    errnoval = libxl_write_exactly(CTX, libxl__carefd_fd(shs->pipes[0]),
+                                   &size, sizeof(size), shs->stdin_what,
+                                   "callback return data length");
+    if (errnoval)
+        goto out;
+
+    errnoval = libxl_write_exactly(CTX, libxl__carefd_fd(shs->pipes[0]),
+                                   data, size, shs->stdin_what,
+                                   "callback return data");
+
+out:
+    if (errnoval)
+        helper_failed(egc, shs, ERROR_FAIL);
+}
+
 void libxl__srm_callout_callback_log(uint32_t level, uint32_t errnoval,
                   const char *context, const char *formatted, void *user)
 {
tools/libxl/libxl_save_helper.c +17 -0
index 74826a1..44c5807 100644
@@ -155,6 +155,23 @@ int helper_getreply(void *user)
     return v;
 }
 
+uint8_t *helper_getreply_data(void *user)
+{
+    uint64_t size;
+    int r = read_exactly(0, &size, sizeof(size));
+    uint8_t *data;
+
+    if (r <= 0)
+        exit(-2);
+
+    data = helper_allocbuf(size, user);
+    r = read_exactly(0, data, size);
+    if (r <= 0)
+        exit(-2);
+
+    return data;
+}
+
 /*----- other callbacks -----*/
 
 static int toolstack_save_fd;
tools/libxl/libxl_save_msgs_gen.pl +58 -7

135 lines not on this page · raw message

Signature · 1 line
1.9.3
#16 lore raw

RFC PATCH 16/25 Allow slave sends data to master

In reply to Wen Congyang

In colo mode, slave needs to send data to master, but the io_fd only can be written in master, and only can be read in slave. Save recv_fd in domain_suspend_state, and send_fd in domain_create_state.

---
 tools/libxl/libxl.c          |  2 +-
 tools/libxl/libxl.h          |  3 ++-
 tools/libxl/libxl_create.c   | 14 ++++++++++----
 tools/libxl/libxl_internal.h |  2 ++
 tools/libxl/libxl_types.idl  |  7 +++++++
 tools/libxl/xl_cmdimpl.c     |  7 +++++++
 6 files changed, 29 insertions(+), 6 deletions(-)
tools/libxl/libxl.c +1 -1
index 3fd31ed..6e6781e 100644
@@ -815,7 +815,7 @@ int libxl_domain_remus_start(libxl_ctx *ctx, libxl_domain_remus_info *info,
     dss->callback = remus_failover_cb;
     dss->domid = domid;
     dss->fd = send_fd;
-    /* TODO do something with recv_fd */
+    dss->recv_fd = recv_fd;
     dss->type = type;
     dss->live = 1;
     dss->debug = 0;
tools/libxl/libxl.h +2 -1
index 81905b3..8274b9d 100644
@@ -813,7 +813,8 @@ int static inline libxl_domain_create_restore_0x040200(
     LIBXL_EXTERNAL_CALLERS_ONLY
 {
     libxl_domain_restore_params params;
-    params.checkpointed_stream = 0;
+    params.checkpointed_stream = LIBXL_CHECKPOINTED_STREAM_NONE;
+    params.send_fd = -1;
 
     return libxl_domain_create_restore(
         ctx, d_config, domid, restore_fd, &params, ao_how, aop_console_how);
tools/libxl/libxl_create.c +10 -4
index 0686f96..c277fd4 100644
@@ -1393,8 +1393,8 @@ static void domain_create_cb(libxl__egc *egc,
                              int rc, uint32_t domid);
 
 static int do_domain_create(libxl_ctx *ctx, libxl_domain_config *d_config,
-                            uint32_t *domid,
-                            int restore_fd, int checkpointed_stream,
+                            uint32_t *domid, int restore_fd,
+                            int send_fd, int checkpointed_stream,
                             const libxl_asyncop_how *ao_how,
                             const libxl_asyncprogress_how *aop_console_how)
 {
@@ -1405,6 +1405,7 @@ static int do_domain_create(libxl_ctx *ctx, libxl_domain_config *d_config,
     cdcs->dcs.ao = ao;
     cdcs->dcs.guest_config = d_config;
     cdcs->dcs.restore_fd = restore_fd;
+    cdcs->dcs.send_fd = send_fd;
     cdcs->dcs.callback = domain_create_cb;
     cdcs->dcs.checkpointed_stream = checkpointed_stream;
     libxl__ao_progress_gethow(&cdcs->dcs.aop_console_how, aop_console_how);
@@ -1433,7 +1434,7 @@ int libxl_domain_create_new(libxl_ctx *ctx, libxl_domain_config *d_config,
                             const libxl_asyncop_how *ao_how,
                             const libxl_asyncprogress_how *aop_console_how)
 {
-    return do_domain_create(ctx, d_config, domid, -1, 0,
+    return do_domain_create(ctx, d_config, domid, -1, -1, 0,
                             ao_how, aop_console_how);
 }
 
@@ -1443,7 +1444,12 @@ int libxl_domain_create_restore(libxl_ctx *ctx, libxl_domain_config *d_config,
                                 const libxl_asyncop_how *ao_how,
                                 const libxl_asyncprogress_how *aop_console_how)
 {
-    return do_domain_create(ctx, d_config, domid, restore_fd,
+    int send_fd = -1;
+
+    if (params->checkpointed_stream == LIBXL_CHECKPOINTED_STREAM_COLO)
+        send_fd = params->send_fd;
+
+    return do_domain_create(ctx, d_config, domid, restore_fd, send_fd,
                             params->checkpointed_stream, ao_how, aop_console_how);
 }
 
tools/libxl/libxl_internal.h +2 -0
index 9ff93e6..92e0801 100644
@@ -2743,6 +2743,7 @@ struct libxl__domain_suspend_state {
 
     uint32_t domid;
     int fd;
+    int recv_fd;
     libxl_domain_type type;
     int live;
     int debug;
@@ -3015,6 +3016,7 @@ struct libxl__domain_create_state {
     libxl__ao *ao;
     libxl_domain_config *guest_config;
     int restore_fd;
+    int send_fd;
     libxl__domain_create_cb *callback;
     libxl_asyncprogress_how aop_console_how;
     /* private to domain_create */
tools/libxl/libxl_types.idl +7 -0
index dc9f78e..1e1a62e 100644
@@ -177,6 +177,12 @@ libxl_vendor_device = Enumeration("vendor_device", [
     (0, "NONE"),
     (1, "XENSERVER"),
     ])
+
+libxl_checkpointed_stream = Enumeration("checkpointed_stream", [
+    (0, "NONE"),
+    (1, "REMUS"),
+    (2, "COLO"),
+    ], init_val = 0)
 #
 # Complex libxl types
 #
@@ -303,6 +309,7 @@ libxl_domain_create_info = Struct("domain_create_info",[
 
 libxl_domain_restore_params = Struct("domain_restore_params", [
     ("checkpointed_stream", integer),
+    ("send_fd", integer),
     ])
 
 libxl_domain_sched_params = Struct("domain_sched_params",[
tools/libxl/xl_cmdimpl.c +7 -0
index 167b65b..22b7964 100644
@@ -151,6 +151,7 @@ struct domain_create {
     const char *extra_config; /* extra config string */
     const char *restore_file;
     int migrate_fd; /* -1 means none */
+    int send_fd; /* -1 means none */
     char **migration_domname_r; /* from malloc */
 };
 
@@ -1991,6 +1992,7 @@ static uint32_t create_domain(struct domain_create *dom_info)
     void *config_data = 0;
     int config_len = 0;
     int restore_fd = -1;
+    int send_fd = -1;
     const libxl_asyncprogress_how *autoconnect_console_how;
     struct save_file_header hdr;
 
@@ -2007,6 +2009,7 @@ static uint32_t create_domain(struct domain_create *dom_info)
         if (migrate_fd >= 0) {
             restore_source = "<incoming migration stream>";
             restore_fd = migrate_fd;
+            send_fd = dom_info->send_fd;
         } else {
             restore_source = restore_file;
             restore_fd = open(restore_file, O_RDONLY);
@@ -2168,6 +2171,7 @@ start:
     if ( restoring ) {
         libxl_domain_restore_params params;
         params.checkpointed_stream = dom_info->checkpointed_stream;
+        params.send_fd = send_fd;
         ret = libxl_domain_create_restore(ctx, &d_config,
                                           &domid, restore_fd,
                                           &params,
@@ -3703,6 +3707,7 @@ static void migrate_receive(int debug, int daemonize, int monitor,
     dom_info.monitor = monitor;
     dom_info.paused = 1;
     dom_info.migrate_fd = recv_fd;
+    dom_info.send_fd = send_fd;
     dom_info.migration_domname_r = &migration_domname;
     dom_info.checkpointed_stream = remus;
 
@@ -3873,6 +3878,7 @@ int main_restore(int argc, char **argv)
     dom_info.config_file = config_file;
     dom_info.restore_file = checkpoint_file;
     dom_info.migrate_fd = -1;
+    dom_info.send_fd = -1;
     dom_info.vnc = vnc;
     dom_info.vncautopass = vncautopass;
     dom_info.console_autoconnect = console_autoconnect;
@@ -4312,6 +4318,7 @@ int main_create(int argc, char **argv)
     dom_info.config_file = filename;
     dom_info.extra_config = extra_config;
     dom_info.migrate_fd = -1;
+    dom_info.send_fd = -1;
     dom_info.vnc = vnc;
     dom_info.vncautopass = vncautopass;
     dom_info.console_autoconnect = console_autoconnect;
Signature · 1 line
1.9.3
#17 lore raw

RFC PATCH 17/25 secondary vm suspend/resume/checkpoint code

In reply to Wen Congyang

Secondary vm is running in colo mode. So we will do
the following things again and again:
1. Resume secondary vm
a. Send LIBXL_COLO_SVM_READY to master
b. If it is resumed the first time, call libxl__xc_domain_restore_done()
to build the secondary vm. We should also enable secondary vm's logdirty. Otherwise, call libxl__domain_resume() to resume secondary vm.
c. Send LIBXL_COLO_SVM_RESUMED to master
2. Wait a new checkpoint
a. Read LIBXL_COLO_NEW_CHECKPOINT from master
3. Suspend secondary vm
a. Suspend secondary vm
b. Get secondary vm's dirty page information
c. Send LIBXL_COLO_SVM_SUSPENDED to master
d. Send secondary vm's dirty page information to master(count + pfn list)

---
 tools/libxc/xenguest.h             |  20 +
 tools/libxl/Makefile               |   1 +
 tools/libxl/libxl_colo.h           |  38 ++
 tools/libxl/libxl_colo_restore.c   | 883 +++++++++++++++++++++++++++++++++++++
 tools/libxl/libxl_create.c         | 116 ++++-
 tools/libxl/libxl_dom.c            |   2 +-
 tools/libxl/libxl_internal.h       |  22 +
 tools/libxl/libxl_save_callout.c   |   6 +-
 tools/libxl/libxl_save_msgs_gen.pl |   6 +-
 9 files changed, 1087 insertions(+), 7 deletions(-)
 create mode 100644 tools/libxl/libxl_colo.h
 create mode 100644 tools/libxl/libxl_colo_restore.c
tools/libxc/xenguest.h +20 -0
index 40bbac8..d3061c7 100644
@@ -91,6 +91,26 @@ int xc_domain_save(xc_interface *xch, int io_fd, uint32_t dom, uint32_t max_iter
 
 /* callbacks provided by xc_domain_restore */
 struct restore_callbacks {
+    /* Called after a new checkpoint to suspend the guest.
+     */
+    int (*suspend)(void* data);
+
+    /* Called after the secondary vm is ready to resume.
+     * Callback function resumes the guest & the device model,
+     *  returns to xc_domain_restore.
+     */
+    int (*postcopy)(void* data);
+
+    /* callback to wait a new checkpoint
+     *
+     * returns:
+     * 0: terminate checkpointing gracefully
+     * 1: take another checkpoint */
+    int (*checkpoint)(void* data);
+
+    /* Enable qemu-dm logging dirty pages to xen */
+    int (*switch_qemu_logdirty)(int domid, unsigned enable, void *data); /* HVM only */
+
     /* callback to restore toolstack specific data */
     int (*toolstack_restore)(uint32_t domid, const uint8_t *buf,
             uint32_t size, void* data);
tools/libxl/Makefile +1 -0
index a33497d..9642500 100644
@@ -57,6 +57,7 @@ LIBXL_OBJS-y += libxl_nonetbuffer.o
 endif
 
 LIBXL_OBJS-y += libxl_checkpoint_device.o libxl_remus_disk_drbd.o
+LIBXL_OBJS-y += libxl_colo_restore.o
 
 LIBXL_OBJS-$(CONFIG_X86) += libxl_cpuid.o libxl_x86.o
 LIBXL_OBJS-$(CONFIG_ARM) += libxl_nocpuid.o libxl_arm.o
tools/libxl/libxl_colo.h new file +38 -0
new file mode 100644
index 0000000..91df275
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2014 FUJITSU LIMITED
+ * Author: Wen Congyang <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; version 2.1 only. with the special
+ * exception on linking described in file LICENSE.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ */
+
+#ifndef LIBXL_COLO_H
+#define LIBXL_COLO_H
+
+/*
+ * values to control suspend/resume primary vm and secondary vm
+ * at the same time
+ */
+enum {
+    LIBXL_COLO_NEW_CHECKPOINT = 1,
+    LIBXL_COLO_SVM_SUSPENDED,
+    LIBXL_COLO_SVM_READY,
+    LIBXL_COLO_SVM_RESUMED,
+};
+
+extern void libxl__colo_restore_done(libxl__egc *egc, void *dcs_void,
+                                     int ret, int retval, int errnoval);
+extern void libxl__colo_restore_setup(libxl__egc *egc,
+                                      libxl__colo_restore_state *crs);
+extern void libxl__colo_restore_teardown(libxl__egc *egc,
+                                         libxl__colo_restore_state *crs,
+                                         int rc);
+
+#endif
tools/libxl/libxl_colo_restore.c new file +883 -0

883 lines not on this page · raw message

tools/libxl/libxl_create.c +114 -2

146 lines not on this page · raw message

tools/libxl/libxl_dom.c +1 -1
index d4bf8b3..4ea2607 100644
@@ -816,7 +816,7 @@ static void switch_logdirty_xswatch(libxl__egc *egc, libxl__ev_xswatch*,
 static void switch_logdirty_done(libxl__egc *egc,
                                  libxl__logdirty_switch *lds, int ok);
 
-static void logdirty_init(libxl__logdirty_switch *lds)
+void logdirty_init(libxl__logdirty_switch *lds)
 {
     lds->cmd_path = 0;
     libxl__ev_xswatch_init(&lds->watch);
tools/libxl/libxl_internal.h +22 -0
index 92e0801..a1f3ec8 100644
@@ -2712,6 +2712,7 @@ struct libxl__logdirty_switch {
     libxl__ev_xswatch watch;
     libxl__ev_time timeout;
 };
+_hidden void logdirty_init(libxl__logdirty_switch *lds);
 
 /*
  * libxl__domain_suspend_state is for saving guest, not
@@ -3011,6 +3012,26 @@ typedef void libxl__domain_create_cb(libxl__egc *egc,
                                      libxl__domain_create_state*,
                                      int rc, uint32_t domid);
 
+/* colo related structure */
+typedef struct libxl__colo_restore_state libxl__colo_restore_state;
+typedef void libxl__colo_callback(libxl__egc *,
+                                  libxl__colo_restore_state *, int rc);
+struct libxl__colo_restore_state {
+    /* must set by caller of libxl__colo_(setup|teardown) */
+    libxl__ao *ao;
+    uint32_t domid;
+    int send_fd;
+    int recv_fd;
+    int hvm;
+    int pae;
+    int superpages;
+    libxl__colo_callback *callback;
+
+    /* private, colo restore checkpoint state */
+    libxl__domain_create_cb *saved_cb;
+    void *crcs;
+};
+
 struct libxl__domain_create_state {
     /* filled in by user */
     libxl__ao *ao;
@@ -3023,6 +3044,7 @@ struct libxl__domain_create_state {
     int guest_domid;
     int checkpointed_stream;
     libxl__domain_build_state build_state;
+    libxl__colo_restore_state crs;
     libxl__bootloader_state bl;
     libxl__stub_dm_spawn_state dmss;
         /* If we're not doing stubdom, we use only dmss.dm,
tools/libxl/libxl_save_callout.c +5 -1
index 0c09d94..e251181 100644
@@ -15,6 +15,7 @@
 #include "libxl_osdeps.h"
 
 #include "libxl_internal.h"
+#include "libxl_colo.h"
 
 /* stream_fd is as from the caller (eventually, the application).
  * It may be 0, 1 or 2, in which case we need to dup it elsewhere.
@@ -65,7 +66,10 @@ void libxl__xc_domain_restore(libxl__egc *egc, libxl__domain_create_state *dcs,
     dcs->shs.ao = ao;
     dcs->shs.domid = domid;
     dcs->shs.recv_callback = libxl__srm_callout_received_restore;
-    dcs->shs.completion_callback = libxl__xc_domain_restore_done;
+    if (dcs->checkpointed_stream == LIBXL_CHECKPOINTED_STREAM_COLO)
+        dcs->shs.completion_callback = libxl__colo_restore_done;
+    else
+        dcs->shs.completion_callback = libxl__xc_domain_restore_done;
     dcs->shs.caller_state = dcs;
     dcs->shs.need_results = 1;
     dcs->shs.toolstack_data_file = 0;
tools/libxl/libxl_save_msgs_gen.pl +3 -3
index 41ee000..0239cac 100755
@@ -24,9 +24,9 @@ our @msgs = (
                                                  STRING doing_what),
                                                 'unsigned long', 'done',
                                                 'unsigned long', 'total'] ],
-    [  3, 'scxA',   "suspend", [] ],
-    [  4, 'scxA',   "postcopy", [] ],
-    [  5, 'scxA',   "checkpoint", [] ],
+    [  3, 'srcxA',   "suspend", [] ],
+    [  4, 'srcxA',   "postcopy", [] ],
+    [  5, 'srcxA',   "checkpoint", [] ],
     [  6, 'scxA',   "switch_qemu_logdirty",  [qw(int domid
                                               unsigned enable)] ],
     #                toolstack_save          done entirely `by hand'
Signature · 1 line
1.9.3
#18 lore raw

RFC PATCH 18/25 primary vm suspend/get_dirty_pfn/resume/checkpoint code

In reply to Wen Congyang

We will do the following things again and again:
1. Suspend primary vm
a. Suspend primary vm
b. do postsuspend
c. Read LIBXL_COLO_SVM_SUSPENDED to master
d. Read secondary vm's dirty page information to master(count + pfn list)
2. Get dirty pfn list
a. Return secondary vm's dirty pfn list
3. Resume primary vm
a. Read LIBXL_COLO_SVM_READY from slave
b. Do presume
c. Resume primary vm
d. Read LIBXL_COLO_SVM_RESUMED from slave
4. Wait a new checkpoint
a. Wait a new checkpoint(not implemented)
b. Send LIBXL_COLO_NEW_CHECKPOINT to slave

---
 tools/libxc/xenguest.h             |  12 +
 tools/libxl/Makefile               |   2 +-
 tools/libxl/libxl.c                |  18 ++
 tools/libxl/libxl_colo.h           |  10 +
 tools/libxl/libxl_colo_save.c      | 585 +++++++++++++++++++++++++++++++++++++
 tools/libxl/libxl_dom.c            |  13 +-
 tools/libxl/libxl_internal.h       |  39 ++-
 tools/libxl/libxl_save_msgs_gen.pl |   1 +
 tools/libxl/libxl_types.idl        |   1 +
 9 files changed, 670 insertions(+), 11 deletions(-)
 create mode 100644 tools/libxl/libxl_colo_save.c
tools/libxc/xenguest.h +12 -0
index d3061c7..1aeaad2 100644
@@ -72,6 +72,18 @@ struct save_callbacks {
      */
     int (*toolstack_save)(uint32_t domid, uint8_t **buf, uint32_t *len, void *data);
 
+    /* Called after the guest is suspended.
+     *
+     * returns the list of dirty pfn:
+     *  struct {
+     *      uint64_t count;
+     *      uint64_t pfn[];
+     *  };
+     *
+     *  Note: the caller must free the return value.
+     */
+    uint8_t *(*get_dirty_pfn)(void *data);
+
     /* to be provided as the last argument to each callback function */
     void* data;
 };
tools/libxl/Makefile +1 -1
index 9642500..6b01a94 100644
@@ -57,7 +57,7 @@ LIBXL_OBJS-y += libxl_nonetbuffer.o
 endif
 
 LIBXL_OBJS-y += libxl_checkpoint_device.o libxl_remus_disk_drbd.o
-LIBXL_OBJS-y += libxl_colo_restore.o
+LIBXL_OBJS-y += libxl_colo_restore.o libxl_colo_save.o
 
 LIBXL_OBJS-$(CONFIG_X86) += libxl_cpuid.o libxl_x86.o
 LIBXL_OBJS-$(CONFIG_ARM) += libxl_nocpuid.o libxl_arm.o
tools/libxl/libxl.c +18 -0
index 6e6781e..2ba6798 100644
@@ -17,6 +17,7 @@
 #include "libxl_osdeps.h"
 
 #include "libxl_internal.h"
+#include "libxl_colo.h"
 
 #define PAGE_TO_MEMKB(pages) ((pages) * 4)
 #define BACKEND_STRING_SIZE 5
@@ -823,8 +824,25 @@ int libxl_domain_remus_start(libxl_ctx *ctx, libxl_domain_remus_info *info,
 
     assert(info);
 
+    if (type != LIBXL_DOMAIN_TYPE_HVM && info->colo) {
+        /* colo only supports hvm now */
+        rc = ERROR_FAIL;
+        goto out;
+    }
+
     /* Convenience aliases */
     libxl__checkpoint_device_state *const cds = &dss->cds;
+    libxl__colo_save_state *const css = &dss->css;
+
+    if (info->colo) {
+        css->cds.ao = ao;
+        css->cds.domid = domid;
+        css->cds.saved_rc = 0;
+
+        /* Point of no return */
+        libxl__colo_save_setup(egc, css);
+        return AO_INPROGRESS;
+    }
 
     if (info->netbuf) {
         if (!libxl__netbuffer_enabled(gc)) {
tools/libxl/libxl_colo.h +10 -0
index 91df275..26a2563 100644
@@ -35,4 +35,14 @@ extern void libxl__colo_restore_teardown(libxl__egc *egc,
                                          libxl__colo_restore_state *crs,
                                          int rc);
 
+extern void libxl__colo_save_domain_suspend_callback(void *data);
+extern void libxl__colo_save_domain_resume_callback(void *data);
+extern void libxl__colo_save_domain_checkpoint_callback(void *data);
+extern void libxl__colo_save_get_dirty_pfn_callback(void *data);
+extern void libxl__colo_save_setup(libxl__egc *egc,
+                                   libxl__colo_save_state *css);
+extern void libxl__colo_save_teardown(libxl__egc *egc,
+                                      libxl__colo_save_state *css,
+                                      int rc);
+
 #endif
tools/libxl/libxl_colo_save.c new file +585 -0

585 lines not on this page · raw message

tools/libxl/libxl_dom.c +11 -2
index 4ea2607..f51e701 100644
@@ -19,6 +19,7 @@
 
 #include "libxl_internal.h"
 #include "libxl_arch.h"
+#include "libxl_colo.h"
 
 #include <xc_dom.h>
 #include <xen/hvm/hvm_info_table.h>
@@ -1747,7 +1748,12 @@ void libxl__domain_suspend(libxl__egc *egc, libxl__domain_suspend_state *dss)
     }
 
     memset(callbacks, 0, sizeof(*callbacks));
-    if (r_info != NULL) {
+    if (r_info != NULL && r_info->colo) {
+        callbacks->suspend = libxl__colo_save_domain_suspend_callback;
+        callbacks->postcopy = libxl__colo_save_domain_resume_callback;
+        callbacks->checkpoint = libxl__colo_save_domain_checkpoint_callback;
+        callbacks->get_dirty_pfn = libxl__colo_save_get_dirty_pfn_callback;
+    } else if (r_info != NULL) {
         callbacks->suspend = libxl__remus_domain_suspend_callback;
         callbacks->postcopy = libxl__remus_domain_resume_callback;
         callbacks->checkpoint = libxl__remus_domain_checkpoint_callback;
@@ -1911,7 +1917,10 @@ static void domain_suspend_done(libxl__egc *egc,
         xc_suspend_evtchn_release(CTX->xch, CTX->xce, domid,
                            dss2->guest_evtchn.port, &dss2->guest_evtchn_lockfd);
 
-    if (dss->remus) {
+    if (dss->remus && dss->remus->colo) {
+        libxl__colo_save_teardown(egc, &dss->css, rc);
+        return;
+    } else if (dss->remus) {
         /*
          * With Remus, if we reach this point, it means either
          * backup died or some network error occurred preventing us
tools/libxl/libxl_internal.h +31 -8
index a1f3ec8..20f7da8 100644
@@ -2690,6 +2690,25 @@ extern const libxl__checkpoint_device_subkind_ops remus_device_drbd_disk;
 
 _hidden int libxl__netbuffer_enabled(libxl__gc *gc);
 
+/*----- colo related state structure -----*/
+typedef struct libxl__colo_save_state libxl__colo_save_state;
+struct libxl__colo_save_state {
+    libxl__checkpoint_device_state cds;
+    int send_fd;
+    int recv_fd;
+
+    /* private */
+    libxl__datacopier_state dc;
+    libxl__datareader_state drs;
+    uint8_t section;
+    uint64_t count;
+    uint64_t *buff;
+    /* read section and count, and then store it in temp_buff */
+    uint8_t temp_buff[9];
+    void (*callback)(libxl__egc *, libxl__colo_save_state *);
+    bool svm_running;
+};
+
 /*----- Domain suspend (save) state structure -----*/
 
 typedef struct libxl__domain_suspend_state libxl__domain_suspend_state;
@@ -2753,14 +2772,18 @@ struct libxl__domain_suspend_state {
     libxl__domain_suspend_state2 dss2;
     int hvm;
     int xcflags;
-    /* for Remus */
-    struct {
-        libxl__checkpoint_device_state cds;
-        const char *netbufscript;
-        /* used for Remus checkpoint */
-        libxl__ev_time checkpoint_timeout;
-        /* checkpoint interval */
-        int interval;
+    union {
+        /* for Remus */
+        struct {
+            libxl__checkpoint_device_state cds;
+            const char *netbufscript;
+            /* used for Remus checkpoint */
+            libxl__ev_time checkpoint_timeout;
+            /* checkpoint interval */
+            int interval;
+        };
+        /* for COLO */
+        libxl__colo_save_state css;
     };
     libxl__save_helper_state shs;
     libxl__logdirty_switch logdirty;
tools/libxl/libxl_save_msgs_gen.pl +1 -0
index 0239cac..fbb2d67 100755
@@ -36,6 +36,7 @@ our @msgs = (
                                               'unsigned long', 'console_mfn'] ],
     [  9, 'srW',    "complete",              [qw(int retval
                                                  int errnoval)] ],
+    [ 10, 'scxAB',  "get_dirty_pfn", [] ],
 );
 
 #----------------------------------------
tools/libxl/libxl_types.idl +1 -0
index 1e1a62e..6b21dcb 100644
@@ -600,6 +600,7 @@ libxl_domain_remus_info = Struct("domain_remus_info",[
     ("netbuf",       bool),
     ("netbufscript", string),
     ("diskbuf",      bool),
+    ("colo",         bool)
     ])
 
 libxl_event_type = Enumeration("event_type", [
Signature · 1 line
1.9.3
#19 lore raw

RFC PATCH 19/25 xc_domain_save: flush cache before calling callbacks->postcopy() in colo mode

In reply to Wen Congyang

In colo mode, secondary vm is running. We will use the io_fd to ensure that both primary vm and secondary vm are resumed at the same time. So we should call postcopy later.

---
 tools/libxc/xc_domain_save.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)
tools/libxc/xc_domain_save.c +14 -2
index 254fdb3..61caa47 100644
@@ -2078,10 +2078,15 @@ int xc_domain_save(xc_interface *xch, int io_fd, uint32_t dom, uint32_t max_iter
  out_rc:
     completed = 1;
 
-    if ( !rc && callbacks->postcopy )
+    /*
+     * COLO: secondary vm is running. We will use the io_fd to
+     * ensure that both primary vm and secondary vm are resumed
+     * at the same time. So we should call postcopy later.
+     */
+    if ( !rc && callbacks->postcopy && !callbacks->get_dirty_pfn )
         callbacks->postcopy(callbacks->data);
 
-    /* guest has been resumed. Now we can compress data
+    /* Remus: guest has been resumed. Now we can compress data
      * at our own pace.
      */
     if (!rc && compressing)
@@ -2109,6 +2114,13 @@ int xc_domain_save(xc_interface *xch, int io_fd, uint32_t dom, uint32_t max_iter
 
     discard_file_cache(xch, io_fd, 1 /* flush */);
 
+    /*
+     * COLO: send qemu device state and resume both
+     * primary vm and secondary vm now.
+     */
+    if ( !rc && callbacks->postcopy && callbacks->get_dirty_pfn )
+        callbacks->postcopy(callbacks->data);
+
     /* Enable compression now, finally */
     compressing = (flags & XCFLAGS_CHECKPOINT_COMPRESS);
 
Signature · 1 line
1.9.3
#20 lore raw

RFC PATCH 20/25 COLO: xc related codes

In reply to Wen Congyang

Save:
1. send XC_SAVE_ID_LAST_CHECKPOINT, so secondary vm can be resumed
2. call callbacks->get_dirty_pfn() after suspend primary vm if we are doing checkpoint.

Restore:
1. call the callbacks resume/checkpoint/suspend if secondary vm's status is the same as primary vm's status.
2. zero out tdata because we will use it zero out pagebuf.tdata.

---
 tools/libxc/xc_domain_restore.c | 44 ++++++++++++++++++++++++++++++++--
 tools/libxc/xc_domain_save.c    | 52 +++++++++++++++++++++++++++++++++++++++--
 2 files changed, 92 insertions(+), 4 deletions(-)
tools/libxc/xc_domain_restore.c +42 -2
index 32a3e72..6e025f0 100644
@@ -1454,7 +1454,7 @@ int xc_domain_restore(xc_interface *xch, int io_fd, uint32_t dom,
     int nraces = 0;
 
     /* The new domain's shared-info frame number. */
-    unsigned long shared_info_frame;
+    unsigned long shared_info_frame = 0;
     unsigned char shared_info_page[PAGE_SIZE]; /* saved contents from file */
     shared_info_any_t *old_shared_info = 
         (shared_info_any_t *)shared_info_page;
@@ -1504,6 +1504,8 @@ int xc_domain_restore(xc_interface *xch, int io_fd, uint32_t dom,
 
     DPRINTF("%s: starting restore of new domid %u", __func__, dom);
 
+    n = m = 0;
+
     pagebuf_init(&pagebuf);
     memset(&tailbuf, 0, sizeof(tailbuf));
     tailbuf.ishvm = hvm;
@@ -1629,7 +1631,6 @@ int xc_domain_restore(xc_interface *xch, int io_fd, uint32_t dom,
      * We uncanonicalise page tables as we go.
      */
 
-    n = m = 0;
  loadpages:
     for ( ; ; )
     {
@@ -1793,6 +1794,7 @@ int xc_domain_restore(xc_interface *xch, int io_fd, uint32_t dom,
         goto finish;
     }
 
+new_checkpoint:
     // DPRINTF("Buffered checkpoint\n");
 
     if ( pagebuf_get(xch, ctx, &pagebuf, io_fd, dom) ) {
@@ -2292,6 +2294,7 @@ int xc_domain_restore(xc_interface *xch, int io_fd, uint32_t dom,
             free(tdata.data);
             goto out;
         }
+        memset(&tdata, 0, sizeof(tdata));
     }
 
     /* Dump the QEMU state to a state file for QEMU to load */
@@ -2357,6 +2360,43 @@ int xc_domain_restore(xc_interface *xch, int io_fd, uint32_t dom,
     rc = 0;
 
  out:
+    if ( !rc && callbacks->checkpoint )
+    {
+#define HANDLE_CALLBACK_RETURN_VALUE(frc)                   \
+    do {                                                    \
+        if ( frc == 0 )                                     \
+        {                                                   \
+            /* Some internal error happens */               \
+            rc = 1;                                         \
+            goto out;                                       \
+        }                                                   \
+        else if ( frc == 2 )                                \
+        {                                                   \
+            /* Reading/writing error, do failover */        \
+            rc = 0;                                         \
+            goto failover;                                  \
+        }                                                   \
+    } while (0)
+        /* COLO */
+
+        /* TODO: call restore_results */
+
+        /* Resume secondary vm */
+        frc = callbacks->postcopy(callbacks->data);
+        HANDLE_CALLBACK_RETURN_VALUE(frc);
+
+        /* wait for new checkpoint */
+        frc = callbacks->checkpoint(callbacks->data);
+        HANDLE_CALLBACK_RETURN_VALUE(frc);
+
+        /* suspend secondary vm */
+        frc = callbacks->suspend(callbacks->data);
+        HANDLE_CALLBACK_RETURN_VALUE(frc);
+
+        goto new_checkpoint;
+    }
+
+failover:
     if ( (rc != 0) && (dom != 0) )
         xc_domain_destroy(xch, dom);
     xc_hypercall_buffer_free(xch, ctxt);
tools/libxc/xc_domain_save.c +50 -2

88 lines not on this page · raw message

Signature · 1 line
1.9.3
#21 lore raw

RFC PATCH 21/25 send store mfn and console mfn to xl before resuming secondary vm

In reply to Wen Congyang

We will call libxl__xc_domain_restore_done() to rebuild secondary vm. But we need store mfn and console mfn when rebuilding secondary vm. So make restore_results is a function pointers in callbacks struct and struct {save,restore}_callbacks, and use this callback to send store mfn and console mfn to xl.

---
 tools/libxc/xc_domain_restore.c    | 2 +-
 tools/libxc/xenguest.h             | 8 ++++++++
 tools/libxl/libxl_colo_restore.c   | 5 -----
 tools/libxl/libxl_create.c         | 1 +
 tools/libxl/libxl_save_msgs_gen.pl | 2 +-
 5 files changed, 11 insertions(+), 7 deletions(-)
tools/libxc/xc_domain_restore.c +1 -1
index 6e025f0..dc66d89 100644
@@ -2379,7 +2379,7 @@ new_checkpoint:
     } while (0)
         /* COLO */
 
-        /* TODO: call restore_results */
+        callbacks->restore_results(*store_mfn, *console_mfn, callbacks->data);
 
         /* Resume secondary vm */
         frc = callbacks->postcopy(callbacks->data);
tools/libxc/xenguest.h +8 -0
index 1aeaad2..be8afd4 100644
@@ -123,6 +123,14 @@ struct restore_callbacks {
     /* Enable qemu-dm logging dirty pages to xen */
     int (*switch_qemu_logdirty)(int domid, unsigned enable, void *data); /* HVM only */
 
+    /*
+     * callback to send store mfn and console mfn to xl
+     * if we want to resume vm before xc_domain_save()
+     * exits.
+     */
+    void (*restore_results)(unsigned long store_mfn, unsigned long console_mfn,
+                            void *data);
+
     /* callback to restore toolstack specific data */
     int (*toolstack_restore)(uint32_t domid, const uint8_t *buf,
             uint32_t size, void* data);
tools/libxl/libxl_colo_restore.c +0 -5
index ebbd6b9..aea3feb 100644
@@ -133,11 +133,6 @@ static void colo_resume_vm(libxl__egc *egc,
         return;
     }
 
-    /*
-     * TODO: get store mfn and console mfn
-     *  We should call the callback restore_results in
-     *  xc_domain_restore() before resuming the guest.
-     */
     libxl__xc_domain_restore_done(egc, dcs, 0, 0, 0);
 
     return;
tools/libxl/libxl_create.c +1 -0
index 73708c5..677a98a 100644
@@ -1048,6 +1048,7 @@ static void domcreate_bootloader_done(libxl__egc *egc,
         rc = ERROR_INVAL;
         goto out;
     }
+    callbacks->restore_results = libxl__srm_callout_callback_restore_results;
 
     if (checkpointed_stream == LIBXL_CHECKPOINTED_STREAM_COLO) {
         crs->ao = ao;
tools/libxl/libxl_save_msgs_gen.pl +1 -1
index fbb2d67..2ecd25d 100755
@@ -32,7 +32,7 @@ our @msgs = (
     #                toolstack_save          done entirely `by hand'
     [  7, 'rcxW',   "toolstack_restore",     [qw(uint32_t domid
                                                 BLOCK tsdata)] ],
-    [  8, 'r',      "restore_results",       ['unsigned long', 'store_mfn',
+    [  8, 'rcx',    "restore_results",       ['unsigned long', 'store_mfn',
                                               'unsigned long', 'console_mfn'] ],
     [  9, 'srW',    "complete",              [qw(int retval
                                                  int errnoval)] ],
Signature · 1 line
1.9.3
#22 lore raw

RFC PATCH 22/25 implement the cmdline for COLO

In reply to Wen Congyang

Add a new option -c to the command 'xl remus'. If you want to use COLO HA instead of Remus HA, please use -c option.

Update man pages to reflect the addition of a new option to 'xl remus' command.

Also add a new option -c to the internal command 'xl migrate-receive'.

---
 docs/man/xl.pod.1         |  9 ++++++++-
 tools/libxl/xl_cmdimpl.c  | 47 ++++++++++++++++++++++++++++++++++++++---------
 tools/libxl/xl_cmdtable.c |  3 ++-
 3 files changed, 48 insertions(+), 11 deletions(-)
docs/man/xl.pod.1 +8 -1
index 547e8a2..accdbe5 100644
@@ -427,12 +427,15 @@ Print huge (!) amount of debug during the migration process.
 
 =item B<remus> [I<OPTIONS>] I<domain-id> I<host>
 
-Enable Remus HA for domain. By default B<xl> relies on ssh as a transport
+Enable Remus HA or COLO HA for domain. By default B<xl> relies on ssh as a transport
 mechanism between the two hosts.
 
 N.B: Remus support in xl is still in experimental (proof-of-concept) phase.
      Disk buffering support is limited to drbd disks.
 
+     COLO support in xl is still in experimental (proof-of-concept) phase.
+     There is no support for network or disk at the moment.
+
 B<OPTIONS>
 
 =over 4
@@ -473,6 +476,10 @@ If empty, run <host> instead of ssh <host> xl migrate-receive -r [-e].
 On the new host, do not wait in the background (on <host>) for the death
 of the domain. See the corresponding option of the I<create> subcommand.
 
+=item B<-c>
+
+Enable COLO HA. It is conflict with B<-i> and B<-b>.
+
 =back
 
 =item B<pause> I<domain-id>
tools/libxl/xl_cmdimpl.c +38 -9

129 lines not on this page · raw message

tools/libxl/xl_cmdtable.c +2 -1
index 246aa11..b91b638 100644
@@ -495,7 +495,8 @@ struct cmd_spec cmd_table[] = {
       "                        to sh. If empty, run <host> instead of \n"
       "                        ssh <host> xl migrate-receive -r [-e]\n"
       "-e                      Do not wait in the background (on <host>) for the death\n"
-      "                        of the domain."
+      "                        of the domain.\n"
+      "-c                      Enable COLO HA. It is conflict with -i and -b"
     },
 #endif
     { "devd",
Signature · 1 line
1.9.3
#23 lore raw

RFC PATCH 23/25 HACK: do checkpoint per 20ms

In reply to Wen Congyang
---
 tools/libxl/libxl_colo_save.c | 19 ++++++++++++++++++-
 tools/libxl/libxl_internal.h  |  3 +++
 2 files changed, 21 insertions(+), 1 deletion(-)
tools/libxl/libxl_colo_save.c +18 -1
index aef6f97..3118f5d 100644
@@ -43,6 +43,8 @@ void libxl__colo_save_setup(libxl__egc *egc, libxl__colo_save_state *css)
     css->cds.callback = colo_save_setup_done;
     css->svm_running = false;
 
+    libxl__ev_time_init(&css->timeout);
+
     libxl__checkpoint_devices_setup(egc, &css->cds);
 }
 
@@ -450,6 +452,8 @@ out:
 static void colo_device_commit_cb(libxl__egc *egc,
                                   libxl__checkpoint_device_state *cds,
                                   int rc);
+static void colo_next_checkpoint(libxl__egc *egc, libxl__ev_time *ev,
+                                  const struct timeval *requested_abs);
 static void colo_start_new_checkpoint(libxl__egc *egc,
                                       libxl__checkpoint_device_state *cds,
                                       int rc);
@@ -485,13 +489,26 @@ static void colo_device_commit_cb(libxl__egc *egc,
     }
 
     /* TODO: wait a new checkpoint */
-    colo_start_new_checkpoint(egc, cds, 0);
+    rc = libxl__ev_time_register_rel(gc, &css->timeout,
+                                     colo_next_checkpoint,
+                                     20);
+    if (rc)
+        goto out;
+
     return;
 
 out:
     libxl__xc_domain_saverestore_async_callback_done(egc, &dss->shs, 0);
 }
 
+static void colo_next_checkpoint(libxl__egc *egc, libxl__ev_time *ev,
+                                  const struct timeval *requested_abs)
+{
+    libxl__colo_save_state *css = CONTAINER_OF(ev, *css, timeout);
+
+    colo_start_new_checkpoint(egc, &css->cds, 0);
+}
+
 static void colo_start_new_checkpoint(libxl__egc *egc,
                                       libxl__checkpoint_device_state *cds,
                                       int rc)
tools/libxl/libxl_internal.h +3 -0
index 20f7da8..2fafe1c 100644
@@ -2707,6 +2707,9 @@ struct libxl__colo_save_state {
     uint8_t temp_buff[9];
     void (*callback)(libxl__egc *, libxl__colo_save_state *);
     bool svm_running;
+
+    /* hack */
+    libxl__ev_time timeout;
 };
 
 /*----- Domain suspend (save) state structure -----*/
Signature · 1 line
1.9.3
#24 lore raw

RFC PATCH 24/25 fix vm entry fail

In reply to Wen Congyang

In colo mode, secondary vm is running, so VM_ENTRY_INTR_INFO may valid before restoring vmcs. If there is no pending event after restoring vm, we should clear it.

---
 xen/arch/x86/hvm/vmx/vmx.c | 7 +++++++
 1 file changed, 7 insertions(+)
xen/arch/x86/hvm/vmx/vmx.c +7 -0
index 2caa04a..eb73412 100644
@@ -526,6 +526,13 @@ static int vmx_vmcs_restore(struct vcpu *v, struct hvm_hw_cpu *c)
             vmx_vmcs_exit(v);
         }
     }
+    else
+    {
+        vmx_vmcs_enter(v);
+        __vmwrite(VM_ENTRY_INTR_INFO, 0);
+        __vmwrite(VM_ENTRY_EXCEPTION_ERROR_CODE, 0);
+        vmx_vmcs_exit(v);
+    }
 
     return 0;
 }
Signature · 1 line
1.9.3
#25 lore raw

Re: [RFC Patch 24/25] fix vm entry fail

Hi,

Quoted 5 lines · Wen Congyang

In colo mode, secondary vm is running, so VM_ENTRY_INTR_INFO may valid before restoring vmcs. If there is no pending event after restoring vm, we should clear it.

This looks correct but incomplete -- we should also clear this state for the other cases where we don't explicitly set it. I've done this below, and also copied the fix to the equivalent SVM code. Can you test that it works for you?

Cheers,

Tim.

commit c9e81a06c02ffc45594798616409335fc09cd32f

Author: Wen Congyang <[email protected]>
Date:   Fri Jul 18 19:39:09 2014 +0800

x86/hvm: Always set pending event injection when loading VMC[BS] state.

In colo mode, secondary vm is running, so VM_ENTRY_INTR_INFO may valid before restoring vmcs. If there is no pending event after restoring vm, we should clear it.

Also clear pending software exceptions.
Copy the fix to SVM as well.

xen/arch/x86/hvm/svm/svm.c +9 -7
index 76616ac..6551b38 100644
@@ -321,16 +321,18 @@ static int svm_vmcb_restore(struct vcpu *v, struct hvm_hw_cpu *c)
         vmcb_set_h_cr3(vmcb, pagetable_get_paddr(p2m_get_pagetable(p2m)));
     }
 
-    if ( c->pending_valid ) 
+    if ( c->pending_valid
+         && hvm_event_needs_reinjection(c->pending_type, c->pending_vector) )
     {
         gdprintk(XENLOG_INFO, "Re-injecting %#"PRIx32", %#"PRIx32"\n",
                  c->pending_event, c->error_code);
-
-        if ( hvm_event_needs_reinjection(c->pending_type, c->pending_vector) )
-        {
-            vmcb->eventinj.bytes = c->pending_event;
-            vmcb->eventinj.fields.errorcode = c->error_code;
-        }
+        vmcb->eventinj.bytes = c->pending_event;
+        vmcb->eventinj.fields.errorcode = c->error_code;
+    }
+    else
+    {
+        vmcb->eventinj.bytes = 0;
+        vmcb->eventinj.fields.errorcode = 0;
     }
 
     vmcb->cleanbits.bytes = 0;
xen/arch/x86/hvm/vmx/vmx.c +12 -13
index 2caa04a..cfc4801 100644
@@ -509,23 +509,22 @@ static int vmx_vmcs_restore(struct vcpu *v, struct hvm_hw_cpu *c)
 
     __vmwrite(GUEST_DR7, c->dr7);
 
-    vmx_vmcs_exit(v);
-
-    paging_update_paging_modes(v);
-
-    if ( c->pending_valid )
+    if ( c->pending_valid
+         && hvm_event_needs_reinjection(c->pending_type, c->pending_vector) )
     {
         gdprintk(XENLOG_INFO, "Re-injecting %#"PRIx32", %#"PRIx32"\n",
                  c->pending_event, c->error_code);
-
-        if ( hvm_event_needs_reinjection(c->pending_type, c->pending_vector) )
-        {
-            vmx_vmcs_enter(v);
-            __vmwrite(VM_ENTRY_INTR_INFO, c->pending_event);
-            __vmwrite(VM_ENTRY_EXCEPTION_ERROR_CODE, c->error_code);
-            vmx_vmcs_exit(v);
-        }
+        __vmwrite(VM_ENTRY_INTR_INFO, c->pending_event);
+        __vmwrite(VM_ENTRY_EXCEPTION_ERROR_CODE, c->error_code);
     }
+    else
+    {
+        __vmwrite(VM_ENTRY_INTR_INFO, 0);
+        __vmwrite(VM_ENTRY_EXCEPTION_ERROR_CODE, 0);
+    }
+    vmx_vmcs_exit(v);
+
+    paging_update_paging_modes(v);
 
     return 0;
 }
#26 lore raw

Re: [RFC Patch 24/25] fix vm entry fail

At 07/24/2014 06:40 PM, Tim Deegan Write:

Quoted 7 lines

Hi,

Quoted 3 lines · Wen Congyang

In colo mode, secondary vm is running, so VM_ENTRY_INTR_INFO may valid before restoring vmcs. If there is no pending event after restoring vm, we should clear it.

Quoted 6 lines
Quoted 1 line

This looks correct but incomplete -- we should also clear this state for the other cases where we don't explicitly set it. I've done this below, and also copied the fix to the equivalent SVM code. Can you test that it works for you?

Thanks, I will test vmx related codes later(I don't have amd cpu now).

Thanks
Wen Congyang

Quoted 94 lines

Cheers,

Tim.

commit c9e81a06c02ffc45594798616409335fc09cd32f

Author: Wen Congyang <[email protected]>
Date:   Fri Jul 18 19:39:09 2014 +0800

x86/hvm: Always set pending event injection when loading VMC[BS] state.

In colo mode, secondary vm is running, so VM_ENTRY_INTR_INFO may valid before restoring vmcs. If there is no pending event after restoring vm, we should clear it.

Also clear pending software exceptions.
Copy the fix to SVM as well.

xen/arch/x86/hvm/svm/svm.c +9 -7
index 76616ac..6551b38 100644
@@ -321,16 +321,18 @@ static int svm_vmcb_restore(struct vcpu *v, struct hvm_hw_cpu *c)
         vmcb_set_h_cr3(vmcb, pagetable_get_paddr(p2m_get_pagetable(p2m)));
     }
 
-    if ( c->pending_valid ) 
+    if ( c->pending_valid
+         && hvm_event_needs_reinjection(c->pending_type, c->pending_vector) )
     {
         gdprintk(XENLOG_INFO, "Re-injecting %#"PRIx32", %#"PRIx32"\n",
                  c->pending_event, c->error_code);
-
-        if ( hvm_event_needs_reinjection(c->pending_type, c->pending_vector) )
-        {
-            vmcb->eventinj.bytes = c->pending_event;
-            vmcb->eventinj.fields.errorcode = c->error_code;
-        }
+        vmcb->eventinj.bytes = c->pending_event;
+        vmcb->eventinj.fields.errorcode = c->error_code;
+    }
+    else
+    {
+        vmcb->eventinj.bytes = 0;
+        vmcb->eventinj.fields.errorcode = 0;
     }
 
     vmcb->cleanbits.bytes = 0;
xen/arch/x86/hvm/vmx/vmx.c +12 -13
index 2caa04a..cfc4801 100644
@@ -509,23 +509,22 @@ static int vmx_vmcs_restore(struct vcpu *v, struct hvm_hw_cpu *c)
 
     __vmwrite(GUEST_DR7, c->dr7);
 
-    vmx_vmcs_exit(v);
-
-    paging_update_paging_modes(v);
-
-    if ( c->pending_valid )
+    if ( c->pending_valid
+         && hvm_event_needs_reinjection(c->pending_type, c->pending_vector) )
     {
         gdprintk(XENLOG_INFO, "Re-injecting %#"PRIx32", %#"PRIx32"\n",
                  c->pending_event, c->error_code);
-
-        if ( hvm_event_needs_reinjection(c->pending_type, c->pending_vector) )
-        {
-            vmx_vmcs_enter(v);
-            __vmwrite(VM_ENTRY_INTR_INFO, c->pending_event);
-            __vmwrite(VM_ENTRY_EXCEPTION_ERROR_CODE, c->error_code);
-            vmx_vmcs_exit(v);
-        }
+        __vmwrite(VM_ENTRY_INTR_INFO, c->pending_event);
+        __vmwrite(VM_ENTRY_EXCEPTION_ERROR_CODE, c->error_code);
     }
+    else
+    {
+        __vmwrite(VM_ENTRY_INTR_INFO, 0);
+        __vmwrite(VM_ENTRY_EXCEPTION_ERROR_CODE, 0);
+    }
+    vmx_vmcs_exit(v);
+
+    paging_update_paging_modes(v);
 
     return 0;
 }

.

Signature · 29 lines
ÒÔÉϤǤ¹
¤è¤í¤·¤¯¤ªîФ¤¤·¤Þ¤¹
Ώ¾Ñó
--------------------------------------------------
Wen Congyang
Development Dept.I
Nanjing Fujitsu Nanda Software Tech. Co., Ltd.(FNST)
No. 6 Wenzhu Road, Nanjing, 210012, China
Postcode: 210012
TEL£º+86+25-86630566-8503
FUJITSU INTERNAL£º79955-8503
FAX£º+86+25-83317685
Mail£º[email protected]
--------------------------------------------------
This communication is for use by the intended recipient(s) only and
may contain information that is privileged, confidential and
exempt from disclosure under applicable law.
If you are not an intended recipient of this communication,
you are hereby notified that any dissemination,
distribution or copying hereof is strictly prohibited.
If you have received this communication in error,
please notify me by reply e-mail,
permanently delete this communication from your system,
and destroy any hard copies you may have printed.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#27 lore raw

Re: [RFC Patch 24/25] fix vm entry fail

In reply to Tim Deegan

At 07/24/2014 06:40 PM, Tim Deegan Write:

Quoted 7 lines

Hi,

Quoted 3 lines · Wen Congyang

In colo mode, secondary vm is running, so VM_ENTRY_INTR_INFO may valid before restoring vmcs. If there is no pending event after restoring vm, we should clear it.

Quoted 6 lines
Quoted 1 line

This looks correct but incomplete -- we should also clear this state for the other cases where we don't explicitly set it. I've done this below, and also copied the fix to the equivalent SVM code. Can you test that it works for you?

Sorry for later reply.

COLO for upstream is not finished, and I cannot reproduce this bug. So, I use old version colo(based on xen 4.1), and test this patch. I works for me.

Thanks for your help
Wen Congyang

Quoted 94 lines

Cheers,

Tim.

commit c9e81a06c02ffc45594798616409335fc09cd32f

Author: Wen Congyang <[email protected]>
Date:   Fri Jul 18 19:39:09 2014 +0800

x86/hvm: Always set pending event injection when loading VMC[BS] state.

In colo mode, secondary vm is running, so VM_ENTRY_INTR_INFO may valid before restoring vmcs. If there is no pending event after restoring vm, we should clear it.

Also clear pending software exceptions.
Copy the fix to SVM as well.

xen/arch/x86/hvm/svm/svm.c +9 -7
index 76616ac..6551b38 100644
@@ -321,16 +321,18 @@ static int svm_vmcb_restore(struct vcpu *v, struct hvm_hw_cpu *c)
         vmcb_set_h_cr3(vmcb, pagetable_get_paddr(p2m_get_pagetable(p2m)));
     }
 
-    if ( c->pending_valid ) 
+    if ( c->pending_valid
+         && hvm_event_needs_reinjection(c->pending_type, c->pending_vector) )
     {
         gdprintk(XENLOG_INFO, "Re-injecting %#"PRIx32", %#"PRIx32"\n",
                  c->pending_event, c->error_code);
-
-        if ( hvm_event_needs_reinjection(c->pending_type, c->pending_vector) )
-        {
-            vmcb->eventinj.bytes = c->pending_event;
-            vmcb->eventinj.fields.errorcode = c->error_code;
-        }
+        vmcb->eventinj.bytes = c->pending_event;
+        vmcb->eventinj.fields.errorcode = c->error_code;
+    }
+    else
+    {
+        vmcb->eventinj.bytes = 0;
+        vmcb->eventinj.fields.errorcode = 0;
     }
 
     vmcb->cleanbits.bytes = 0;
xen/arch/x86/hvm/vmx/vmx.c +12 -13
index 2caa04a..cfc4801 100644
@@ -509,23 +509,22 @@ static int vmx_vmcs_restore(struct vcpu *v, struct hvm_hw_cpu *c)
 
     __vmwrite(GUEST_DR7, c->dr7);
 
-    vmx_vmcs_exit(v);
-
-    paging_update_paging_modes(v);
-
-    if ( c->pending_valid )
+    if ( c->pending_valid
+         && hvm_event_needs_reinjection(c->pending_type, c->pending_vector) )
     {
         gdprintk(XENLOG_INFO, "Re-injecting %#"PRIx32", %#"PRIx32"\n",
                  c->pending_event, c->error_code);
-
-        if ( hvm_event_needs_reinjection(c->pending_type, c->pending_vector) )
-        {
-            vmx_vmcs_enter(v);
-            __vmwrite(VM_ENTRY_INTR_INFO, c->pending_event);
-            __vmwrite(VM_ENTRY_EXCEPTION_ERROR_CODE, c->error_code);
-            vmx_vmcs_exit(v);
-        }
+        __vmwrite(VM_ENTRY_INTR_INFO, c->pending_event);
+        __vmwrite(VM_ENTRY_EXCEPTION_ERROR_CODE, c->error_code);
     }
+    else
+    {
+        __vmwrite(VM_ENTRY_INTR_INFO, 0);
+        __vmwrite(VM_ENTRY_EXCEPTION_ERROR_CODE, 0);
+    }
+    vmx_vmcs_exit(v);
+
+    paging_update_paging_modes(v);
 
     return 0;
 }

.

#28 lore raw

RFC PATCH 25/25 sync mmu before resuming secondary vm

In reply to Wen Congyang

In out test, we find secondary vm will be bluescreen due to memory related problem. If we sync mmu, the problem will disappear.

TODO: only vmx+ept is done.

---
 tools/libxc/xc_domain.c            |  9 +++++++++
 tools/libxc/xenctrl.h              |  2 ++
 tools/libxl/libxl_colo_restore.c   |  6 +++++-
 xen/arch/x86/domctl.c              | 15 +++++++++++++++
 xen/arch/x86/hvm/save.c            |  6 ++++++
 xen/arch/x86/hvm/vmx/vmcs.c        |  8 ++++++++
 xen/arch/x86/hvm/vmx/vmx.c         |  1 +
 xen/include/asm-x86/hvm/hvm.h      |  1 +
 xen/include/asm-x86/hvm/vmx/vmcs.h |  1 +
 xen/include/public/domctl.h        |  1 +
 xen/include/xen/hvm/save.h         |  2 ++
 11 files changed, 51 insertions(+), 1 deletion(-)
tools/libxc/xc_domain.c +9 -0
index 0230c6c..0b47bdd 100644
@@ -2123,6 +2123,15 @@ int xc_domain_set_max_evtchn(xc_interface *xch, uint32_t domid,
     return do_domctl(xch, &domctl);
 }
 
+int xc_domain_hvm_sync_mmu(xc_interface *xch, uint32_t domid)
+{
+    DECLARE_DOMCTL;
+
+    domctl.cmd = XEN_DOMCTL_hvm_sync_mmu;
+    domctl.domain = domid;
+    return do_domctl(xch, &domctl);
+}
+
 /*
  * Local variables:
  * mode: C
tools/libxc/xenctrl.h +2 -0
index 3578b09..a83364a 100644
@@ -961,6 +961,8 @@ int xc_domain_set_virq_handler(xc_interface *xch, uint32_t domid, int virq);
 int xc_domain_set_max_evtchn(xc_interface *xch, uint32_t domid,
                              uint32_t max_port);
 
+int xc_domain_hvm_sync_mmu(xc_interface *xch, uint32_t domid);
+
 /*
  * CPUPOOL MANAGEMENT FUNCTIONS
  */
tools/libxl/libxl_colo_restore.c +5 -1
index aea3feb..730b492 100644
@@ -124,11 +124,15 @@ static void colo_resume_vm(libxl__egc *egc,
     STATE_AO_GC(crs->ao);
 
     if (!crs->saved_cb) {
-        /* TODO: sync mmu for hvm? */
+        rc = xc_domain_hvm_sync_mmu(CTX->xch, crs->domid);
+        if (rc)
+            goto fail;
+
         rc = libxl__domain_resume(gc, crs->domid, 0, 1);
         if (rc)
             LOG(ERROR, "cannot resume secondary vm");
 
+fail:
         crcs->callback(egc, crcs, rc);
         return;
     }
xen/arch/x86/domctl.c +15 -0
index d62c715..d0dfad7 100644
@@ -1395,6 +1395,21 @@ long arch_do_domctl(
     }
     break;
 
+    case XEN_DOMCTL_hvm_sync_mmu:
+    {
+        struct domain *d;
+
+        ret = -ESRCH;
+        d = rcu_lock_domain_by_id(domctl->domain);
+        if ( d != NULL )
+        {
+            arch_hvm_sync_mmu(d);
+            rcu_unlock_domain(d);
+            ret = 0;
+        }
+    }
+    break;
+
     default:
         ret = iommu_do_domctl(domctl, d, u_domctl);
         break;
xen/arch/x86/hvm/save.c +6 -0
index 6af19be..7a07ebf 100644
@@ -79,6 +79,12 @@ int arch_hvm_load(struct domain *d, struct hvm_save_header *hdr)
     return 0;
 }
 
+void arch_hvm_sync_mmu(struct domain *d)
+{
+    if (hvm_funcs.sync_mmu)
+        hvm_funcs.sync_mmu(d);
+}
+
 /*
  * Local variables:
  * mode: C
xen/arch/x86/hvm/vmx/vmcs.c +8 -0
index 8ffc562..4be9b4d 100644
@@ -596,6 +596,14 @@ void vmx_cpu_down(void)
     local_irq_restore(flags);
 }
 
+void vmx_sync_mmu(struct domain *d)
+{
+    ept_sync_domain(p2m_get_hostp2m(d));
+
+    /* flush tlb */
+    flush_all(FLUSH_TLB_GLOBAL);
+}
+
 struct foreign_vmcs {
     struct vcpu *v;
     unsigned int count;
xen/arch/x86/hvm/vmx/vmx.c +1 -0
index eb73412..b46b4dd 100644
@@ -1719,6 +1719,7 @@ static struct hvm_function_table __initdata vmx_function_table = {
     .event_pending        = vmx_event_pending,
     .cpu_up               = vmx_cpu_up,
     .cpu_down             = vmx_cpu_down,
+    .sync_mmu             = vmx_sync_mmu,
     .cpuid_intercept      = vmx_cpuid_intercept,
     .wbinvd_intercept     = vmx_wbinvd_intercept,
     .fpu_dirty_intercept  = vmx_fpu_dirty_intercept,
xen/include/asm-x86/hvm/hvm.h +1 -0
index 0ebd478..b4f89a7 100644
@@ -151,6 +151,7 @@ struct hvm_function_table {
 
     int  (*cpu_up)(void);
     void (*cpu_down)(void);
+    void (*sync_mmu)(struct domain *d);
 
     /* Copy up to 15 bytes from cached instruction bytes at current rIP. */
     unsigned int (*get_insn_bytes)(struct vcpu *v, uint8_t *buf);
xen/include/asm-x86/hvm/vmx/vmcs.h +1 -0
index 215d93c..664741a 100644
@@ -29,6 +29,7 @@ extern int  vmx_cpu_up_prepare(unsigned int cpu);
 extern void vmx_cpu_dead(unsigned int cpu);
 extern int  vmx_cpu_up(void);
 extern void vmx_cpu_down(void);
+extern void vmx_sync_mmu(struct domain *d);
 extern void vmx_save_host_msrs(void);
 
 struct vmcs_struct {
xen/include/public/domctl.h +1 -0
index 5b11bbf..11e5a26 100644
@@ -1008,6 +1008,7 @@ struct xen_domctl {
 #define XEN_DOMCTL_cacheflush                    71
 #define XEN_DOMCTL_get_vcpu_msrs                 72
 #define XEN_DOMCTL_set_vcpu_msrs                 73
+#define XEN_DOMCTL_hvm_sync_mmu                  74
 #define XEN_DOMCTL_gdbsx_guestmemio            1000
 #define XEN_DOMCTL_gdbsx_pausevcpu             1001
 #define XEN_DOMCTL_gdbsx_unpausevcpu           1002
xen/include/xen/hvm/save.h +2 -0
index ae6f0bb..049fdb8 100644
@@ -135,4 +135,6 @@ struct hvm_save_header;
 void arch_hvm_save(struct domain *d, struct hvm_save_header *hdr);
 int arch_hvm_load(struct domain *d, struct hvm_save_header *hdr);
 
+void arch_hvm_sync_mmu(struct domain *d);
+
 #endif /* __XEN_HVM_SAVE_H__ */
Signature · 1 line
1.9.3
#29 lore raw

Re: [RFC Patch 25/25] sync mmu before resuming secondary vm

Quoted 2 lines · Wen Congyang

In out test, we find secondary vm will be bluescreen due to memory related problem. If we sync mmu, the problem will disappear.

Erk. Do you understand _why_ this happens? Do you need both the TLB flush and the EPT flush to fix it?

The TLB flush sounds plausible because the migration may have changed some pagetables and you've elided any TLB flushes that happened on the source. For that case I think I'd prefer to make the TLB flush implicit in the HVM load operation, e.g., by putting a call to hvm_asid_flush_vcpu(v) into hvm_load_cpu_ctxt() (on the grounds that the TLB is part of the vcpu state).

Cheers,

Tim.

Quoted 199 lines

TODO: only vmx+ept is done.

---
 tools/libxc/xc_domain.c            |  9 +++++++++
 tools/libxc/xenctrl.h              |  2 ++
 tools/libxl/libxl_colo_restore.c   |  6 +++++-
 xen/arch/x86/domctl.c              | 15 +++++++++++++++
 xen/arch/x86/hvm/save.c            |  6 ++++++
 xen/arch/x86/hvm/vmx/vmcs.c        |  8 ++++++++
 xen/arch/x86/hvm/vmx/vmx.c         |  1 +
 xen/include/asm-x86/hvm/hvm.h      |  1 +
 xen/include/asm-x86/hvm/vmx/vmcs.h |  1 +
 xen/include/public/domctl.h        |  1 +
 xen/include/xen/hvm/save.h         |  2 ++
 11 files changed, 51 insertions(+), 1 deletion(-)
tools/libxc/xc_domain.c +9 -0
index 0230c6c..0b47bdd 100644
@@ -2123,6 +2123,15 @@ int xc_domain_set_max_evtchn(xc_interface *xch, uint32_t domid,
     return do_domctl(xch, &domctl);
 }
 
+int xc_domain_hvm_sync_mmu(xc_interface *xch, uint32_t domid)
+{
+    DECLARE_DOMCTL;
+
+    domctl.cmd = XEN_DOMCTL_hvm_sync_mmu;
+    domctl.domain = domid;
+    return do_domctl(xch, &domctl);
+}
+
 /*
  * Local variables:
  * mode: C
tools/libxc/xenctrl.h +2 -0
index 3578b09..a83364a 100644
@@ -961,6 +961,8 @@ int xc_domain_set_virq_handler(xc_interface *xch, uint32_t domid, int virq);
 int xc_domain_set_max_evtchn(xc_interface *xch, uint32_t domid,
                              uint32_t max_port);
 
+int xc_domain_hvm_sync_mmu(xc_interface *xch, uint32_t domid);
+
 /*
  * CPUPOOL MANAGEMENT FUNCTIONS
  */
tools/libxl/libxl_colo_restore.c +5 -1
index aea3feb..730b492 100644
@@ -124,11 +124,15 @@ static void colo_resume_vm(libxl__egc *egc,
     STATE_AO_GC(crs->ao);
 
     if (!crs->saved_cb) {
-        /* TODO: sync mmu for hvm? */
+        rc = xc_domain_hvm_sync_mmu(CTX->xch, crs->domid);
+        if (rc)
+            goto fail;
+
         rc = libxl__domain_resume(gc, crs->domid, 0, 1);
         if (rc)
             LOG(ERROR, "cannot resume secondary vm");
 
+fail:
         crcs->callback(egc, crcs, rc);
         return;
     }
xen/arch/x86/domctl.c +15 -0
index d62c715..d0dfad7 100644
@@ -1395,6 +1395,21 @@ long arch_do_domctl(
     }
     break;
 
+    case XEN_DOMCTL_hvm_sync_mmu:
+    {
+        struct domain *d;
+
+        ret = -ESRCH;
+        d = rcu_lock_domain_by_id(domctl->domain);
+        if ( d != NULL )
+        {
+            arch_hvm_sync_mmu(d);
+            rcu_unlock_domain(d);
+            ret = 0;
+        }
+    }
+    break;
+
     default:
         ret = iommu_do_domctl(domctl, d, u_domctl);
         break;
xen/arch/x86/hvm/save.c +6 -0
index 6af19be..7a07ebf 100644
@@ -79,6 +79,12 @@ int arch_hvm_load(struct domain *d, struct hvm_save_header *hdr)
     return 0;
 }
 
+void arch_hvm_sync_mmu(struct domain *d)
+{
+    if (hvm_funcs.sync_mmu)
+        hvm_funcs.sync_mmu(d);
+}
+
 /*
  * Local variables:
  * mode: C
xen/arch/x86/hvm/vmx/vmcs.c +8 -0
index 8ffc562..4be9b4d 100644
@@ -596,6 +596,14 @@ void vmx_cpu_down(void)
     local_irq_restore(flags);
 }
 
+void vmx_sync_mmu(struct domain *d)
+{
+    ept_sync_domain(p2m_get_hostp2m(d));
+
+    /* flush tlb */
+    flush_all(FLUSH_TLB_GLOBAL);
+}
+
 struct foreign_vmcs {
     struct vcpu *v;
     unsigned int count;
xen/arch/x86/hvm/vmx/vmx.c +1 -0
index eb73412..b46b4dd 100644
@@ -1719,6 +1719,7 @@ static struct hvm_function_table __initdata vmx_function_table = {
     .event_pending        = vmx_event_pending,
     .cpu_up               = vmx_cpu_up,
     .cpu_down             = vmx_cpu_down,
+    .sync_mmu             = vmx_sync_mmu,
     .cpuid_intercept      = vmx_cpuid_intercept,
     .wbinvd_intercept     = vmx_wbinvd_intercept,
     .fpu_dirty_intercept  = vmx_fpu_dirty_intercept,
xen/include/asm-x86/hvm/hvm.h +1 -0
index 0ebd478..b4f89a7 100644
@@ -151,6 +151,7 @@ struct hvm_function_table {
 
     int  (*cpu_up)(void);
     void (*cpu_down)(void);
+    void (*sync_mmu)(struct domain *d);
 
     /* Copy up to 15 bytes from cached instruction bytes at current rIP. */
     unsigned int (*get_insn_bytes)(struct vcpu *v, uint8_t *buf);
xen/include/asm-x86/hvm/vmx/vmcs.h +1 -0
index 215d93c..664741a 100644
@@ -29,6 +29,7 @@ extern int  vmx_cpu_up_prepare(unsigned int cpu);
 extern void vmx_cpu_dead(unsigned int cpu);
 extern int  vmx_cpu_up(void);
 extern void vmx_cpu_down(void);
+extern void vmx_sync_mmu(struct domain *d);
 extern void vmx_save_host_msrs(void);
 
 struct vmcs_struct {
xen/include/public/domctl.h +1 -0
index 5b11bbf..11e5a26 100644
@@ -1008,6 +1008,7 @@ struct xen_domctl {
 #define XEN_DOMCTL_cacheflush                    71
 #define XEN_DOMCTL_get_vcpu_msrs                 72
 #define XEN_DOMCTL_set_vcpu_msrs                 73
+#define XEN_DOMCTL_hvm_sync_mmu                  74
 #define XEN_DOMCTL_gdbsx_guestmemio            1000
 #define XEN_DOMCTL_gdbsx_pausevcpu             1001
 #define XEN_DOMCTL_gdbsx_unpausevcpu           1002
xen/include/xen/hvm/save.h +2 -0
index ae6f0bb..049fdb8 100644
@@ -135,4 +135,6 @@ struct hvm_save_header;
 void arch_hvm_save(struct domain *d, struct hvm_save_header *hdr);
 int arch_hvm_load(struct domain *d, struct hvm_save_header *hdr);
 
+void arch_hvm_sync_mmu(struct domain *d);
+
 #endif /* __XEN_HVM_SAVE_H__ */
Signature · 7 lines
1.9.3


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#30 lore raw

Re: [RFC Patch 25/25] sync mmu before resuming secondary vm

At 07/24/2014 06:59 PM, Tim Deegan Write:

Quoted 7 lines
Quoted 2 lines · Wen Congyang

In out test, we find secondary vm will be bluescreen due to memory related problem. If we sync mmu, the problem will disappear.

Erk. Do you understand _why_ this happens? Do you need both the TLB flush and the EPT flush to fix it?

Quoted 6 lines

The TLB flush sounds plausible because the migration may have changed some pagetables and you've elided any TLB flushes that happened on the source. For that case I think I'd prefer to make the TLB flush implicit in the HVM load operation, e.g., by putting a call to hvm_asid_flush_vcpu(v) into hvm_load_cpu_ctxt() (on the grounds that the TLB is part of the vcpu state).

Hmm, I don't investigate this problem deeply. I will try you suggestion.

Thanks
Wen Congyang

Quoted 206 lines

Cheers,

Tim.

Quoted 199 lines

TODO: only vmx+ept is done.

---
 tools/libxc/xc_domain.c            |  9 +++++++++
 tools/libxc/xenctrl.h              |  2 ++
 tools/libxl/libxl_colo_restore.c   |  6 +++++-
 xen/arch/x86/domctl.c              | 15 +++++++++++++++
 xen/arch/x86/hvm/save.c            |  6 ++++++
 xen/arch/x86/hvm/vmx/vmcs.c        |  8 ++++++++
 xen/arch/x86/hvm/vmx/vmx.c         |  1 +
 xen/include/asm-x86/hvm/hvm.h      |  1 +
 xen/include/asm-x86/hvm/vmx/vmcs.h |  1 +
 xen/include/public/domctl.h        |  1 +
 xen/include/xen/hvm/save.h         |  2 ++
 11 files changed, 51 insertions(+), 1 deletion(-)
tools/libxc/xc_domain.c +9 -0
index 0230c6c..0b47bdd 100644
@@ -2123,6 +2123,15 @@ int xc_domain_set_max_evtchn(xc_interface *xch, uint32_t domid,
     return do_domctl(xch, &domctl);
 }
 
+int xc_domain_hvm_sync_mmu(xc_interface *xch, uint32_t domid)
+{
+    DECLARE_DOMCTL;
+
+    domctl.cmd = XEN_DOMCTL_hvm_sync_mmu;
+    domctl.domain = domid;
+    return do_domctl(xch, &domctl);
+}
+
 /*
  * Local variables:
  * mode: C
tools/libxc/xenctrl.h +2 -0
index 3578b09..a83364a 100644
@@ -961,6 +961,8 @@ int xc_domain_set_virq_handler(xc_interface *xch, uint32_t domid, int virq);
 int xc_domain_set_max_evtchn(xc_interface *xch, uint32_t domid,
                              uint32_t max_port);
 
+int xc_domain_hvm_sync_mmu(xc_interface *xch, uint32_t domid);
+
 /*
  * CPUPOOL MANAGEMENT FUNCTIONS
  */
tools/libxl/libxl_colo_restore.c +5 -1
index aea3feb..730b492 100644
@@ -124,11 +124,15 @@ static void colo_resume_vm(libxl__egc *egc,
     STATE_AO_GC(crs->ao);
 
     if (!crs->saved_cb) {
-        /* TODO: sync mmu for hvm? */
+        rc = xc_domain_hvm_sync_mmu(CTX->xch, crs->domid);
+        if (rc)
+            goto fail;
+
         rc = libxl__domain_resume(gc, crs->domid, 0, 1);
         if (rc)
             LOG(ERROR, "cannot resume secondary vm");
 
+fail:
         crcs->callback(egc, crcs, rc);
         return;
     }
xen/arch/x86/domctl.c +15 -0
index d62c715..d0dfad7 100644
@@ -1395,6 +1395,21 @@ long arch_do_domctl(
     }
     break;
 
+    case XEN_DOMCTL_hvm_sync_mmu:
+    {
+        struct domain *d;
+
+        ret = -ESRCH;
+        d = rcu_lock_domain_by_id(domctl->domain);
+        if ( d != NULL )
+        {
+            arch_hvm_sync_mmu(d);
+            rcu_unlock_domain(d);
+            ret = 0;
+        }
+    }
+    break;
+
     default:
         ret = iommu_do_domctl(domctl, d, u_domctl);
         break;
xen/arch/x86/hvm/save.c +6 -0
index 6af19be..7a07ebf 100644
@@ -79,6 +79,12 @@ int arch_hvm_load(struct domain *d, struct hvm_save_header *hdr)
     return 0;
 }
 
+void arch_hvm_sync_mmu(struct domain *d)
+{
+    if (hvm_funcs.sync_mmu)
+        hvm_funcs.sync_mmu(d);
+}
+
 /*
  * Local variables:
  * mode: C
xen/arch/x86/hvm/vmx/vmcs.c +8 -0
index 8ffc562..4be9b4d 100644
@@ -596,6 +596,14 @@ void vmx_cpu_down(void)
     local_irq_restore(flags);
 }
 
+void vmx_sync_mmu(struct domain *d)
+{
+    ept_sync_domain(p2m_get_hostp2m(d));
+
+    /* flush tlb */
+    flush_all(FLUSH_TLB_GLOBAL);
+}
+
 struct foreign_vmcs {
     struct vcpu *v;
     unsigned int count;
xen/arch/x86/hvm/vmx/vmx.c +1 -0
index eb73412..b46b4dd 100644
@@ -1719,6 +1719,7 @@ static struct hvm_function_table __initdata vmx_function_table = {
     .event_pending        = vmx_event_pending,
     .cpu_up               = vmx_cpu_up,
     .cpu_down             = vmx_cpu_down,
+    .sync_mmu             = vmx_sync_mmu,
     .cpuid_intercept      = vmx_cpuid_intercept,
     .wbinvd_intercept     = vmx_wbinvd_intercept,
     .fpu_dirty_intercept  = vmx_fpu_dirty_intercept,
xen/include/asm-x86/hvm/hvm.h +1 -0
index 0ebd478..b4f89a7 100644
@@ -151,6 +151,7 @@ struct hvm_function_table {
 
     int  (*cpu_up)(void);
     void (*cpu_down)(void);
+    void (*sync_mmu)(struct domain *d);
 
     /* Copy up to 15 bytes from cached instruction bytes at current rIP. */
     unsigned int (*get_insn_bytes)(struct vcpu *v, uint8_t *buf);
xen/include/asm-x86/hvm/vmx/vmcs.h +1 -0
index 215d93c..664741a 100644
@@ -29,6 +29,7 @@ extern int  vmx_cpu_up_prepare(unsigned int cpu);
 extern void vmx_cpu_dead(unsigned int cpu);
 extern int  vmx_cpu_up(void);
 extern void vmx_cpu_down(void);
+extern void vmx_sync_mmu(struct domain *d);
 extern void vmx_save_host_msrs(void);
 
 struct vmcs_struct {
xen/include/public/domctl.h +1 -0
index 5b11bbf..11e5a26 100644
@@ -1008,6 +1008,7 @@ struct xen_domctl {
 #define XEN_DOMCTL_cacheflush                    71
 #define XEN_DOMCTL_get_vcpu_msrs                 72
 #define XEN_DOMCTL_set_vcpu_msrs                 73
+#define XEN_DOMCTL_hvm_sync_mmu                  74
 #define XEN_DOMCTL_gdbsx_guestmemio            1000
 #define XEN_DOMCTL_gdbsx_pausevcpu             1001
 #define XEN_DOMCTL_gdbsx_unpausevcpu           1002
xen/include/xen/hvm/save.h +2 -0
index ae6f0bb..049fdb8 100644
@@ -135,4 +135,6 @@ struct hvm_save_header;
 void arch_hvm_save(struct domain *d, struct hvm_save_header *hdr);
 int arch_hvm_load(struct domain *d, struct hvm_save_header *hdr);
 
+void arch_hvm_sync_mmu(struct domain *d);
+
 #endif /* __XEN_HVM_SAVE_H__ */
Signature · 7 lines
1.9.3


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

.

Signature · 29 lines
ÒÔÉϤǤ¹
¤è¤í¤·¤¯¤ªîФ¤¤·¤Þ¤¹
Ώ¾Ñó
--------------------------------------------------
Wen Congyang
Development Dept.I
Nanjing Fujitsu Nanda Software Tech. Co., Ltd.(FNST)
No. 6 Wenzhu Road, Nanjing, 210012, China
Postcode: 210012
TEL£º+86+25-86630566-8503
FUJITSU INTERNAL£º79955-8503
FAX£º+86+25-83317685
Mail£º[email protected]
--------------------------------------------------
This communication is for use by the intended recipient(s) only and
may contain information that is privileged, confidential and
exempt from disclosure under applicable law.
If you are not an intended recipient of this communication,
you are hereby notified that any dissemination,
distribution or copying hereof is strictly prohibited.
If you have received this communication in error,
please notify me by reply e-mail,
permanently delete this communication from your system,
and destroy any hard copies you may have printed.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#31 lore raw

Re: [RFC Patch 25/25] sync mmu before resuming secondary vm

In reply to Tim Deegan

At 07/24/2014 06:59 PM, Tim Deegan Write:

Quoted 6 lines
Quoted 2 lines · Wen Congyang

In out test, we find secondary vm will be bluescreen due to memory related problem. If we sync mmu, the problem will disappear.

Erk. Do you understand _why_ this happens? Do you need both the TLB flush and the EPT flush to fix it?

I cannot reproduce this problem now. But Some user processes will exited due to memory problem.

Secondary vm is running like this:
1. running
2. stop
3. update the the state(both memory and device)
4. continue running

Before step4, I think the tlb for the guest is out-of-data. I don't have any knowledge about EPT. So I don't know if the ept is out-of-data too.

Anyway, I will remove this patch in next version.

Thanks
Wen Congyang

Quoted 12 lines

The TLB flush sounds plausible because the migration may have changed some pagetables and you've elided any TLB flushes that happened on the source. For that case I think I'd prefer to make the TLB flush implicit in the HVM load operation, e.g., by putting a call to hvm_asid_flush_vcpu(v) into hvm_load_cpu_ctxt() (on the grounds that the TLB is part of the vcpu state).

Cheers,

Tim.

#32 lore raw

[RFC Patch 26/25] Introduce "xen-load-devices-state"

In reply to Wen Congyang

introduce a "xen-load-devices-state" QAPI command that can be used to load the state of all devices, but not the RAM or the block devices of the VM.

---
 qapi-schema.json |  18 ++++++++
 qmp-commands.hx  |  27 ++++++++++++
 savevm.c         | 126 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 171 insertions(+)
qapi-schema.json +18 -0
index 391356f..c569856 100644
@@ -4689,3 +4689,21 @@
               'btn'     : 'InputBtnEvent',
               'rel'     : 'InputMoveEvent',
               'abs'     : 'InputMoveEvent' } }
+
+##
+# @xen-load-devices-state:
+#
+# Load the state of all devices from file. The RAM and the block devices
+# of the VM are not loaded by this command.
+#
+# @filename: the file to load the state of the devices from as binary
+# data. See xen-save-devices-state.txt for a description of the binary
+# format.
+#
+# Returns: Nothing on success
+#          If @filename cannot be opened, OpenFileFailed
+#          If an I/O error occurs while reading the file, IOError
+#
+# Since: 2.0
+##
+{ 'command': 'xen-load-devices-state', 'data': {'filename': 'str'} }
qmp-commands.hx +27 -0
index ed3ab92..b796be5 100644
@@ -586,6 +586,33 @@ Example:
 EQMP
 
     {
+        .name       = "xen-load-devices-state",
+        .args_type  = "filename:F",
+        .mhandler.cmd_new = qmp_marshal_input_xen_load_devices_state,
+    },
+
+SQMP
+xen-load-devices-state
+-------
+
+Load the state of all devices from file. The RAM and the block devices
+of the VM are not loaded by this command.
+
+Arguments:
+
+- "filename": the file to load the state of the devices from as binary
+data. See xen-save-devices-state.txt for a description of the binary
+format.
+
+Example:
+
+-> { "execute": "xen-load-devices-state",
+     "arguments": { "filename": "/tmp/resume" } }
+<- { "return": {} }
+
+EQMP
+
+    {
         .name       = "xen-set-global-dirty-log",
         .args_type  = "enable:b",
         .mhandler.cmd_new = qmp_marshal_input_xen_set_global_dirty_log,
savevm.c +126 -0

138 lines not on this page · raw message

Signature · 1 line
1.9.0
#33 lore raw
In reply to Wen Congyang

At 07/18/2014 07:38 PM, Wen Congyang Wrote:

Quoted 30 lines

Virtual machine (VM) replication is a well known technique for providing application-agnostic software-implemented hardware fault tolerance - "non-stop service". Currently, remus provides this function, but it buffers all output packets, and the latency is unacceptable.

In xen summit 2012, We introduce a new VM replication solution: colo (COarse-grain LOck-stepping virtual machine). The presentation is in the following URL:
http://www.slideshare.net/xen_com_mgr/colo-coarsegrain-lockstepping-virtual-machines-for-nonstop-service

Here is the summary of the solution:

Quoted 1 line

From the client's point of view, as long as the client observes identical

responses from the primary and secondary VMs, according to the service semantics, then the secondary vm is a valid replica of the primary vm, and can successfully take over when a hardware failure of the primary vm is detected.

This patchset is RFC, and implements the frame of colo:
1. Both primary vm and secondary vm are running
2. do checkoint

This patchset is based on remus-v15, and use migration v1. Only supports hvm guest now.

TODO list:
1. rebase to remus-v17 or newer
2. support migration v2
3. nic/disk replication
4. support pvm

Quoted 8 lines

Patch 1-3: bugfix
Patch 4-6: temporarily update remus to reuse remus device codes Patch 7-14: update some APIs which will be used by colo
Patch 15-22: colo related codes
Patch 23: Hack patch, just for test
Patch 24-25: bugfix. We find this bug before rebasing colo to newest xen.
But we don't trigger this bug now.
Patch 26: A patch for qemu-xen

I also put the codes in github:
https://github.com/wencongyang/xen/tree/colo

Quoted 73 lines

Hong Tao (1):
copy the correct page to memory

Wen Congyang (24):
csum the correct page
don't zero out ioreq page
don't touch remus in remus_device
rename remus device to checkpoint device
adjust the indentation
Refactor domain_suspend_callback_common()
Update libxl__domain_resume() for colo
Update libxl__domain_suspend_common_switch_qemu_logdirty() for colo Introduce a new internal API libxl__domain_unpause() Update libxl__domain_unpause() to support qemu-xen support to resume uncooperative HVM guests
update datecopier to support sending data only
introduce a new API to aync read data from fd
Update libxl_save_msgs_gen.pl to support return data from xl to xc Allow slave sends data to master
secondary vm suspend/resume/checkpoint code
primary vm suspend/get_dirty_pfn/resume/checkpoint code
xc_domain_save: flush cache before calling callbacks->postcopy() in
colo mode
COLO: xc related codes
send store mfn and console mfn to xl before resuming secondary vm implement the cmdline for COLO
HACK: do checkpoint per 20ms
fix vm entry fail
sync mmu before resuming secondary vm

 docs/man/xl.pod.1                                  |   9 +-
 tools/libxc/xc_domain.c                            |   9 +
 tools/libxc/xc_domain_restore.c                    |  74 +-
 tools/libxc/xc_domain_save.c                       |  66 +-
 tools/libxc/xc_resume.c                            |  20 +-
 tools/libxc/xenctrl.h                              |   2 +
 tools/libxc/xenguest.h                             |  40 +
 tools/libxl/Makefile                               |   3 +-
 tools/libxl/libxl.c                                | 102 ++-
 tools/libxl/libxl.h                                |   3 +-
 tools/libxl/libxl_aoutils.c                        |  81 +-
 ...xl_remus_device.c => libxl_checkpoint_device.c} | 266 ++++---
 tools/libxl/libxl_colo.h                           |  48 ++
 tools/libxl/libxl_colo_restore.c                   | 882 +++++++++++++++++++++
 tools/libxl/libxl_colo_save.c                      | 602 ++++++++++++++
 tools/libxl/libxl_create.c                         | 131 ++-
 tools/libxl/libxl_dom.c                            | 424 ++++++----
 tools/libxl/libxl_internal.h                       | 262 ++++--
 tools/libxl/libxl_netbuffer.c                      |  85 +-
 tools/libxl/libxl_nonetbuffer.c                    |  14 +-
 tools/libxl/libxl_qmp.c                            |  10 +
 tools/libxl/libxl_remus_disk_drbd.c                |  54 +-
 tools/libxl/libxl_save_callout.c                   |  37 +-
 tools/libxl/libxl_save_helper.c                    |  17 +
 tools/libxl/libxl_save_msgs_gen.pl                 |  74 +-
 tools/libxl/libxl_types.idl                        |  12 +-
 tools/libxl/xl_cmdimpl.c                           |  54 +-
 tools/libxl/xl_cmdtable.c                          |   3 +-
 xen/arch/x86/domctl.c                              |  15 +
 xen/arch/x86/hvm/save.c                            |   6 +
 xen/arch/x86/hvm/vmx/vmcs.c                        |   8 +
 xen/arch/x86/hvm/vmx/vmx.c                         |   8 +
 xen/include/asm-x86/hvm/hvm.h                      |   1 +
 xen/include/asm-x86/hvm/vmx/vmcs.h                 |   1 +
 xen/include/public/domctl.h                        |   1 +
 xen/include/xen/hvm/save.h                         |   2 +
 36 files changed, 2895 insertions(+), 531 deletions(-)
 rename tools/libxl/{libxl_remus_device.c => libxl_checkpoint_device.c} (47%)
 create mode 100644 tools/libxl/libxl_colo.h
 create mode 100644 tools/libxl/libxl_colo_restore.c
 create mode 100644 tools/libxl/libxl_colo_save.c
#34 lore raw
In reply to Wen Congyang
Quoted 21 lines · Wen Congyang

Virtual machine (VM) replication is a well known technique for providing application-agnostic software-implemented hardware fault tolerance - "non-stop service". Currently, remus provides this function, but it buffers all output packets, and the latency is unacceptable.

In xen summit 2012, We introduce a new VM replication solution: colo (COarse-grain LOck-stepping virtual machine). The presentation is in the following URL:
http://www.slideshare.net/xen_com_mgr/colo-coarsegrain-lockstepping-virtual-machines-for-nonstop-service

Here is the summary of the solution:

Quoted 1 line

From the client's point of view, as long as the client observes identical

responses from the primary and secondary VMs, according to the service semantics, then the secondary vm is a valid replica of the primary vm, and can successfully take over when a hardware failure of the primary vm is detected.

This patchset is RFC, and implements the frame of colo:
1. Both primary vm and secondary vm are running
2. do checkoint

Quoted 8 lines

This patchset is based on remus-v15, and use migration v1. Only supports hvm guest now.

TODO list:
1. rebase to remus-v17 or newer
2. support migration v2
3. nic/disk replication
4. support pvm

This is an interesting set of patches. One query I have is what you mean by "support migration v2".

While I am developing migration v2, the old legacy code is left in place for easier testing and development purposes, but when the migration v2 code does finally get committed, the legacy migration code will be deleted.

The legacy code is unfit for purpose and entirely replaced by v2, in a backwards-compatible manor given the included conversion script (not that that matters for Remus/colo).

~Andrew

#35 lore raw

At 2014/7/18 22:18, Andrew Cooper Wrote:

Quoted 34 lines · Wen Congyang
Quoted 21 lines

Virtual machine (VM) replication is a well known technique for providing application-agnostic software-implemented hardware fault tolerance - "non-stop service". Currently, remus provides this function, but it buffers all output packets, and the latency is unacceptable.

In xen summit 2012, We introduce a new VM replication solution: colo (COarse-grain LOck-stepping virtual machine). The presentation is in the following URL:
http://www.slideshare.net/xen_com_mgr/colo-coarsegrain-lockstepping-virtual-machines-for-nonstop-service

Here is the summary of the solution:

Quoted 1 line

From the client's point of view, as long as the client observes identical

responses from the primary and secondary VMs, according to the service semantics, then the secondary vm is a valid replica of the primary vm, and can successfully take over when a hardware failure of the primary vm is detected.

This patchset is RFC, and implements the frame of colo:
1. Both primary vm and secondary vm are running
2. do checkoint

Quoted 8 lines

This patchset is based on remus-v15, and use migration v1. Only supports hvm guest now.

TODO list:
1. rebase to remus-v17 or newer
2. support migration v2
3. nic/disk replication
4. support pvm

This is an interesting set of patches. One query I have is what you mean by "support migration v2".

Quoted 8 lines

While I am developing migration v2, the old legacy code is left in place for easier testing and development purposes, but when the migration v2 code does finally get committed, the legacy migration code will be deleted.

The legacy code is unfit for purpose and entirely replaced by v2, in a backwards-compatible manor given the included conversion script (not that that matters for Remus/colo).

We use migration to implement remus/colo. If migration v2 is merged into upstream xen, I think I need to add codes to migration v2, and make colo can work with migration v2.

Thanks
Wen Congyang

Quoted 8 lines

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel