Skip to contentSkip to conversation

HVM save/restore clean up: new hyper-call clean

PATCH New Zhai, Edwin 1 participant 1 message Jan 19, 2007

lore
Share & tools
lore
#0 lore raw

PATCH 2/4 HVM save/restore clean up: new hyper-call clean

[PATCH 2/4] HVM save/restore clean up: new hyper-call clean

enable it for compat mode and move it to arch/x86/domctl.c

tools/libxc/xc_domain.c +28 -26
diff -r f639b9f51709 tools/libxc/xc_domain.c
@@ -238,45 +238,47 @@ int xc_domain_getinfolist(int xc_handle,
 /* get info from hvm guest for save */
 int xc_domain_hvm_getcontext(int xc_handle,
                              uint32_t domid,
-                             hvm_domain_context_t *hvm_ctxt)
-{
-    int rc;
+                             uint8_t *ctxt_buf)
+{
+    int ret;
     DECLARE_DOMCTL;
 
     domctl.cmd = XEN_DOMCTL_gethvmcontext;
     domctl.domain = (domid_t)domid;
-    set_xen_guest_handle(domctl.u.hvmcontext.ctxt, hvm_ctxt);
-
-    if ( (rc = mlock(hvm_ctxt, sizeof(*hvm_ctxt))) != 0 )
-        return rc;
-
-    rc = do_domctl(xc_handle, &domctl);
-
-    safe_munlock(hvm_ctxt, sizeof(*hvm_ctxt));
-
-    return rc;
+    set_xen_guest_handle(domctl.u.hvmcontext.buffer, ctxt_buf);
+
+    if ( (ret = lock_pages(ctxt_buf, HVM_CTXT_SIZE)) != 0 )
+        return ret;
+
+    ret = do_domctl(xc_handle, &domctl);
+
+    unlock_pages(ctxt_buf, HVM_CTXT_SIZE);
+
+    return (ret < 0 ? -1 : domctl.u.hvmcontext.size);
 }
 
 /* set info to hvm guest for restore */
 int xc_domain_hvm_setcontext(int xc_handle,
                              uint32_t domid,
-                             hvm_domain_context_t *hvm_ctxt)
-{
-    int rc;
+                             uint8_t *ctxt_buf,
+                             uint32_t size)
+{
+    int ret;
     DECLARE_DOMCTL;
 
     domctl.cmd = XEN_DOMCTL_sethvmcontext;
     domctl.domain = domid;
-    set_xen_guest_handle(domctl.u.hvmcontext.ctxt, hvm_ctxt);
-
-    if ( (rc = mlock(hvm_ctxt, sizeof(*hvm_ctxt))) != 0 )
-        return rc;
-
-    rc = do_domctl(xc_handle, &domctl);
-
-    safe_munlock(hvm_ctxt, sizeof(*hvm_ctxt));
-
-    return rc;
+    domctl.u.hvmcontext.size = size;
+    set_xen_guest_handle(domctl.u.hvmcontext.buffer, ctxt_buf);
+
+    if ( (ret = lock_pages(ctxt_buf, HVM_CTXT_SIZE)) != 0 )
+        return ret;
+
+    ret = do_domctl(xc_handle, &domctl);
+
+    unlock_pages(ctxt_buf, HVM_CTXT_SIZE);
+
+    return ret;
 }
 
 int xc_vcpu_getcontext(int xc_handle,
tools/libxc/xc_hvm_restore.c +17 -15
diff -r f639b9f51709 tools/libxc/xc_hvm_restore.c
@@ -87,7 +87,7 @@ int xc_hvm_restore(int xc_handle, int io
     xc_dominfo_t info;
     unsigned int rc = 1, n, i;
     uint32_t rec_len, nr_vcpus;
-    hvm_domain_context_t hvm_ctxt;
+    uint8_t *hvm_buf = NULL;
     unsigned long long v_end, memsize;
     unsigned long shared_page_nr;
 
@@ -127,8 +127,9 @@ int xc_hvm_restore(int xc_handle, int io
 
 
     p2m        = malloc(max_pfn * sizeof(xen_pfn_t));
-
-    if (p2m == NULL) {
+    hvm_buf    = malloc(HVM_CTXT_SIZE);
+
+    if (p2m == NULL || hvm_buf == NULL) {
         ERROR("memory alloc failed");
         errno = ENOMEM;
         goto out;
@@ -304,18 +305,18 @@ int xc_hvm_restore(int xc_handle, int io
         ERROR("error read hvm context size!\n");
         goto out;
     }
-    if (rec_len != sizeof(hvm_ctxt)) {
-        ERROR("hvm context size dismatch!\n");
-        goto out;
-    }
-
-    if (!read_exact(io_fd, &hvm_ctxt, sizeof(hvm_ctxt))) {
-        ERROR("error read hvm context!\n");
-        goto out;
-    }
-
-    if (( rc = xc_domain_hvm_setcontext(xc_handle, dom, &hvm_ctxt))) {
-        ERROR("error set hvm context!\n");
+    if (rec_len >= HVM_CTXT_SIZE) {
+        ERROR("wrong hvm buffer size!\n");
+        goto out;
+    }
+
+    if (!read_exact(io_fd, hvm_buf, rec_len)) {
+        ERROR("error read hvm buffer!\n");
+        goto out;
+    }
+
+    if (( rc = xc_domain_hvm_setcontext(xc_handle, dom, hvm_buf, rec_len))) {
+        ERROR("error set hvm buffer!\n");
         goto out;
     }
 
@@ -353,6 +354,7 @@ int xc_hvm_restore(int xc_handle, int io
     if ( (rc != 0) && (dom != 0) )
         xc_domain_destroy(xc_handle, dom);
     free(p2m);
+    free(hvm_buf);
 
     DPRINTF("Restore exit with rc=%d\n", rc);
 
tools/libxc/xc_hvm_save.c +29 -25

85 lines not on this page · raw message

tools/libxc/xenctrl.h +3 -2
diff -r f639b9f51709 tools/libxc/xenctrl.h
@@ -322,7 +322,7 @@ int xc_domain_getinfolist(int xc_handle,
  */
 int xc_domain_hvm_getcontext(int xc_handle,
                              uint32_t domid,
-                             hvm_domain_context_t *hvm_ctxt);
+                             uint8_t *ctxt_buf);
 
 /**
  * This function will set the context for hvm domain
@@ -334,7 +334,8 @@ int xc_domain_hvm_getcontext(int xc_hand
  */
 int xc_domain_hvm_setcontext(int xc_handle,
                              uint32_t domid,
-                             hvm_domain_context_t *hvm_ctxt);
+                             uint8_t *hvm_ctxt,
+                             uint32_t size);
 
 /**
  * This function returns information about the execution context of a
xen/arch/x86/domctl.c +76 -0

82 lines not on this page · raw message

xen/common/domctl.c +0 -73

85 lines not on this page · raw message

xen/include/asm-x86/hvm/domain.h +6 -2
diff -r f639b9f51709 xen/include/asm-x86/hvm/domain.h
@@ -26,6 +26,12 @@
 #include <asm/hvm/vlapic.h>
 #include <asm/hvm/io.h>
 #include <public/hvm/params.h>
+
+typedef struct hvm_domain_context {
+    uint32_t cur;
+    uint32_t size;
+    uint8_t data[HVM_CTXT_SIZE];
+} hvm_domain_context_t;
 
 typedef void SaveStateHandler(hvm_domain_context_t *h, void *opaque);
 typedef int LoadStateHandler(hvm_domain_context_t *h, void *opaque, int version_id);
@@ -58,8 +64,6 @@ struct hvm_domain {
     spinlock_t             pbuf_lock;
 
     uint64_t               params[HVM_NR_PARAMS];
-
-    struct hvm_domain_context *hvm_ctxt;
     HVMStateEntry *first_se;
 };
 
xen/include/public/domctl.h +5 -8
diff -r f639b9f51709 xen/include/public/domctl.h
@@ -387,18 +387,15 @@ typedef struct xen_domctl_settimeoffset 
 typedef struct xen_domctl_settimeoffset xen_domctl_settimeoffset_t;
 DEFINE_XEN_GUEST_HANDLE(xen_domctl_settimeoffset_t);
  
-#define HVM_CTXT_SIZE        6144
-typedef struct hvm_domain_context {
-    uint32_t cur;
-    uint32_t size;
-    uint8_t data[HVM_CTXT_SIZE];
-} hvm_domain_context_t;
-DEFINE_XEN_GUEST_HANDLE(hvm_domain_context_t);
+#define HVM_CTXT_SIZE        8192
 
 #define XEN_DOMCTL_gethvmcontext   33
 #define XEN_DOMCTL_sethvmcontext   34
 typedef struct xen_domctl_hvmcontext {
-    XEN_GUEST_HANDLE(hvm_domain_context_t) ctxt;  /* IN/OUT */
+    /*IN/OUT variables*/
+    uint32_t size;
+    /*IN/OUT variables*/
+    XEN_GUEST_HANDLE(uint8_t) buffer;  /* IN/OUT */
 } xen_domctl_hvmcontext_t;
 DEFINE_XEN_GUEST_HANDLE(xen_domctl_hvmcontext_t);