tools/xenctx: Correct use of xc_domain_{, un}pause()
authorAndrew Cooper <andrew.cooper3@citrix.com>
Fri, 4 Jul 2014 16:06:20 +0000 (17:06 +0100)
committerIan Campbell <ian.campbell@citrix.com>
Thu, 10 Jul 2014 10:20:07 +0000 (11:20 +0100)
The previous code never worked correctly.  There was a TOCTOU race between
checking dominfo and pausing the domain.

Since c/s 3eb1c708, Xen properly reference counts pause hypercalls, so
unconditionally pause and unpause the domain.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
CC: Ian Campbell <Ian.Campbell@citrix.com>
CC: Ian Jackson <Ian.Jackson@eu.citrix.com>
CC: George Dunlap <george.dunlap@eu.citrix.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
tools/xentrace/xenctx.c

index 82bd7895596daa03abb9c184cf081bf3887c927c..4ed120a6a83d45da9ba45e768bca1e06aebab6a4 100644 (file)
@@ -91,7 +91,6 @@ static struct xenctx {
     int do_stack;
 #endif
     int kernel_start_set;
-    int self_paused;
     xc_dominfo_t dominfo;
 } xenctx;
 
@@ -1273,13 +1272,10 @@ int main(int argc, char **argv)
         exit(-1);
     }
 
-    if (!xenctx.dominfo.paused) {
-        ret = xc_domain_pause(xenctx.xc_handle, xenctx.domid);
-        if (ret < 0) {
-            perror("xc_domain_pause");
-            exit(-1);
-        }
-        xenctx.self_paused = 1;
+    ret = xc_domain_pause(xenctx.xc_handle, xenctx.domid);
+    if (ret < 0) {
+        perror("xc_domain_pause");
+        exit(-1);
     }
 
 #ifndef NO_TRANSLATION
@@ -1303,12 +1299,10 @@ int main(int argc, char **argv)
     if ( do_default )
         dump_ctx(vcpu);
 
-    if (xenctx.self_paused) {
-        ret = xc_domain_unpause(xenctx.xc_handle, xenctx.domid);
-        if (ret < 0) {
-            perror("xc_domain_unpause");
-            exit(-1);
-        }
+    ret = xc_domain_unpause(xenctx.xc_handle, xenctx.domid);
+    if (ret < 0) {
+        perror("xc_domain_unpause");
+        exit(-1);
     }
 
     ret = xc_interface_close(xenctx.xc_handle);