[TOOLS] Fix pagetable-pinning loop in xc_linux_restore.
authorkaf24@firebug.cl.cam.ac.uk <kaf24@firebug.cl.cam.ac.uk>
Thu, 22 Jun 2006 13:12:01 +0000 (14:12 +0100)
committerkaf24@firebug.cl.cam.ac.uk <kaf24@firebug.cl.cam.ac.uk>
Thu, 22 Jun 2006 13:12:01 +0000 (14:12 +0100)
Previously it would not pin last PFN in physmap even if it was
a pagetable page.
Signed-off-by: Keir Fraser <keir@xensource.com>
tools/libxc/xc_linux_restore.c

index 88b60fe329ad0d0729fdfc2fc4bf549ff1bf8cb9..ad1d916d55e92f5de8f0a18c7cfcbee7da57524c 100644 (file)
@@ -572,18 +572,10 @@ int xc_linux_restore(int xc_handle, int io_fd,
     nr_pins = 0;
     for (i = 0; i < max_pfn; i++) {
 
-        if (i == (max_pfn-1) || nr_pins == MAX_PIN_BATCH) {
-            if (xc_mmuext_op(xc_handle, pin, nr_pins, dom) < 0) {
-                ERR("Failed to pin batch of %d page tables", nr_pins);
-                goto out;
-            }
-            nr_pins = 0;
-        }
-
         if ( (pfn_type[i] & LPINTAB) == 0 )
             continue;
 
-        switch(pfn_type[i]) {
+        switch (pfn_type[i]) {
 
         case (L1TAB|LPINTAB):
             pin[nr_pins].cmd = MMUEXT_PIN_L1_TABLE;
@@ -608,6 +600,20 @@ int xc_linux_restore(int xc_handle, int io_fd,
         pin[nr_pins].arg1.mfn = p2m[i];
         nr_pins++;
 
+        /* Batch full? Then flush. */
+        if (nr_pins == MAX_PIN_BATCH) {
+            if (xc_mmuext_op(xc_handle, pin, nr_pins, dom) < 0) {
+                ERR("Failed to pin batch of %d page tables", nr_pins);
+                goto out;
+            }
+            nr_pins = 0;
+        }
+    }
+
+    /* Flush final partial batch. */
+    if ((nr_pins != 0) && (xc_mmuext_op(xc_handle, pin, nr_pins, dom) < 0)) {
+        ERR("Failed to pin batch of %d page tables", nr_pins);
+        goto out;
     }
 
     DPRINTF("\b\b\b\b100%%\n");