Skip to contentSkip to conversation

Remaining prerequisite patches for COLO

PATCH In review Wei Liu 3 participants 8 messages Mar 31, 2016 – Apr 1, 2016

lore
Share & tools
lore

Wei Liu

author
#0 lore raw

cover Remaining prerequisite patches for COLO

Konrad Rzeszutek Wilk (1):
libxc: Document xc_domain_resume

Wen Congyang (1):
libxc: support to resume uncooperative HVM guests

 tools/libxc/include/xenctrl.h | 50 +++++++++++++++++++++++++++++++++++++++++++
 tools/libxc/xc_resume.c       | 25 ++++++++++++++++++----
 2 files changed, 71 insertions(+), 4 deletions(-)
Signature · 7 lines
2.1.4


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

PATCH 1/2 libxc: support to resume uncooperative HVM guests

From: Wen Congyang <[email protected]>

Before this patch:
1. Suspend
a. PVHVM and PV: we use the same way to suspend the guest (send the
suspend request to the guest). If the guest doesn't support evtchn, the xenstore variant will be used, suspending the guest via XenBus control node.
b. Pure HVM: we call xc_domain_shutdown(..., SHUTDOWN_suspend) to suspend
the guest.

2. Resume:
a. Fast path (fast=1)
Do not change the guest state. We call libxl__domain_resume(.., 1) which calls xc_domain_resume(..., 1 /* fast=1*/) to resume the guest.
PV: Modify the return code to 1, and than call the domctl:
XEN_DOMCTL_resumedomain
PVHVM: same with PV
Pure HVM: Do nothing in modify_returncode, and than call the domctl:
XEN_DOMCTL_resumedomain
b. Slow path (fast=0)
Used when the guest's state have been changed. Will call libxl__domain_resume(..., 0) to resume the guest.
PV: Update start info, and reset all secondary CPU states. Than call
the domctl: XEN_DOMCTL_resumedomain
PVHVM: Can not be resumed. You will get the following error message:
"Cannot resume uncooperative HVM guests"
Pure HVM: Same with PVHVM

After this patch:
1. Suspend
Unchanged.

2. Resume
a. Fast path
Unchanged.
b. Slow path
PV: Unchanged.
PVHVM: Call XEN_DOMCTL_resumedomain to resume the guest. Because we
don't modify the return code, PV drivers will disconnect and reconnect.
The guest ends up doing the XENMAPSPACE_shared_info XENMEM_add_to_physmap hypercall and resetting all of its CPU states to point to the shared_info (except the ones past 32). That is the Linux kernel does that - regardless whether the SCHEDOP_shutdown:SHUTDOWN_suspend returns 1 or not.
Pure HVM: Call XEN_DOMCTL_resumedomain to resume the guest.

Under COLO, we will update the guest's state (modify memory, CPU registers, device state etc). In this case, we cannot use the fast path to resume it. Keep the return code 0, and use the slow path to resume the guest.

[ wei: reformat commit message a bit ]
---
 tools/libxc/xc_resume.c | 25 +++++++++++++++++++++----
 1 file changed, 21 insertions(+), 4 deletions(-)
tools/libxc/xc_resume.c +21 -4
index 5bf4cf0..6bf7d9c 100644
@@ -109,6 +109,26 @@ 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;
+
+    /*
+     * The domctl XEN_DOMCTL_resumedomain unpause each vcpu. After
+     * the domctl, the guest will run.
+     *
+     * If it is PVHVM, the guest called the hypercall
+     *    SCHEDOP_shutdown:SHUTDOWN_suspend
+     * to suspend itself. We don't modify the return code, so the PV driver
+     * will disconnect and reconnect.
+     *
+     * If it is a HVM, the guest will continue running.
+     */
+    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 +158,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 · 7 lines
2.1.4


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

Re: [PATCH 1/2] libxc: support to resume uncooperative HVM guests

tools/libxc/xc_resume.c static int xc_domain_resume_any(xc_interface *xch, uint32_t domid) · line 161

Quoted 3 lines · Wei Liu
tools/libxc/xc_resume.c +2 -0
+static int xc_domain_resume_hvm(xc_interface *xch, uint32_t domid)
 #if defined(__i386__) || defined(__x86_64__)
+        return xc_domain_resume_hvm(xch, domid);

This causes a build error no non-x86.

[ 334s] xc_resume.c:112:12: error: 'xc_domain_resume_hvm' defined but not used [-Werror=unused-function] [ 334s] static int xc_domain_resume_hvm(xc_interface *xch, uint32_t domid)

Olaf

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

author
#3 lore raw

Re: [PATCH 1/2] libxc: support to resume uncooperative HVM guests

Quoted 11 lines · Olaf Hering

Review

Quoted 3 lines · Wei Liu
(quoted diff) +2 -0
+static int xc_domain_resume_hvm(xc_interface *xch, uint32_t domid)
 #if defined(__i386__) || defined(__x86_64__)
+        return xc_domain_resume_hvm(xch, domid);

This causes a build error no non-x86.

[ 334s] xc_resume.c:112:12: error: 'xc_domain_resume_hvm' defined but not used [-Werror=unused-function] [ 334s] static int xc_domain_resume_hvm(xc_interface *xch, uint32_t domid)

Does this work?

From 6f3252a82168d0025c585dbbaf5817f42f5d1e85 Mon Sep 17 00:00:00 2001
From: Wei Liu <[email protected]>
Date: Fri, 1 Apr 2016 17:07:52 +0100
Subject: [PATCH] libxc: xc_domain_resume_hvm is used by x86 only

The call site is enclosed by x86 define guards.

---
 tools/libxc/xc_resume.c | 2 ++
 1 file changed, 2 insertions(+)
tools/libxc/xc_resume.c +2 -0
index 6bf7d9c..2b6c308 100644
@@ -109,6 +109,7 @@ static int xc_domain_resume_cooperative(xc_interface *xch, uint32_t domid)
     return do_domctl(xch, &domctl);
 }
 
+#if defined(__i386__) || defined(__x86_64__)
 static int xc_domain_resume_hvm(xc_interface *xch, uint32_t domid)
 {
     DECLARE_DOMCTL;
@@ -128,6 +129,7 @@ static int xc_domain_resume_hvm(xc_interface *xch, uint32_t domid)
     domctl.domain = domid;
     return do_domctl(xch, &domctl);
 }
+#endif
 
 static int xc_domain_resume_any(xc_interface *xch, uint32_t domid)
 {
Signature · 6 lines
2.1.4

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

Re: [PATCH 1/2] libxc: support to resume uncooperative HVM guests

Quoted 5 lines · Olaf Hering
Quoted 1 line · Wei Liu

Does this work?

Most likely yes.

Yes, this change fixes it. Thanks.
There is another failure on arm now, see the other mail "arm: staging build error in libxl helper_setcallbacks_restore".

Olaf

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

author
#6 lore raw

PATCH 2/2 libxc: Document xc_domain_resume

In reply to Wei Liu

From: Konrad Rzeszutek Wilk <[email protected]>

Document the save and suspend mechanism.

---
 tools/libxc/include/xenctrl.h | 50 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 50 insertions(+)
tools/libxc/include/xenctrl.h +50 -0
index a9e4dc1..013a3a3 100644
@@ -565,6 +565,56 @@ int xc_domain_destroy(xc_interface *xch,
  * This function resumes a suspended domain. The domain should have
  * been previously suspended.
  *
+ * Note that there are 'xc_domain_suspend' as suspending a domain
+ * is quite the endeavour.
+ *
+ * For the purpose of this explanation there are three guests:
+ * PV (using hypercalls for privilgied operations), HVM
+ * (fully hardware virtualized guests using emulated devices for everything),
+ * and PVHVM (PV aware with hardware virtualisation).
+ *
+ * HVM guest are the simplest - they suspend via S3 / S4 and resume from
+ * S3 / S4. Upon resume they have to re-negotiate with the emulated devices.
+ *
+ * PV and PVHVM communicate via hypercalls for suspend (and resume).
+ * For suspend the toolstack initiates the process by writing an value
+ * in XenBus "control/shutdown" with the string "suspend".
+ *
+ * The PV guest stashes anything it deems neccessary in 'struct
+ * start_info' in case of failure (PVHVM may ignore this) and calls
+ * the SCHEDOP_shutdown::SHUTDOWN_suspend hypercall (for PV as
+ * argument it passes the MFN to 'struct start_info').
+ *
+ * And then the guest is suspended.
+ *
+ * The checkpointing or notifying a guest that the suspend failed or
+ * cancelled (in case of checkpoint) is by having the
+ * SCHEDOP_shutdown::SHUTDOWN_suspend hypercall return a non-zero
+ * value.
+ *
+ * The PV and PVHVM resume path are similar. For PV it would be
+ * similar to bootup - figure out where the 'struct start_info' is (or
+ * if the suspend was cancelled aka checkpointed - reuse the saved
+ * values).
+ *
+ * From here on they differ depending whether the guest is PV or PVHVM
+ * in specifics but follow overall the same path:
+ *  - PV: Bringing up the vCPUS,
+ *  - PVHVM: Setup vector callback,
+ *  - Bring up vCPU runstates,
+ *  - Remap the grant tables if checkpointing or setup from scratch,
+ *
+ *
+ * If the resume was not checkpointing (or if suspend was succesful) we would
+ * setup the PV timers and the different PV events. Lastly the PV drivers
+ * re-negotiate with the backend.
+ *
+ * This function would return before the guest started resuming. That is
+ * the guest would be in non-running state and its vCPU context would be
+ * in the the SCHEDOP_shutdown::SHUTDOWN_suspend hypercall return path
+ * (for PV and PVHVM). For HVM it would be in would be in QEMU emulated
+ * BIOS handling S3 suspend.
+ *
  * @parm xch a handle to an open hypervisor interface
  * @parm domid the domain id to resume
  * @parm fast use cooperative resume (guest must support this)
Signature · 7 lines
2.1.4


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