xen: Simplify callers of boot_vcpu(). In VCPUOP_up, check
authorKeir Fraser <keir@xen.org>
Fri, 20 Jan 2012 10:13:55 +0000 (10:13 +0000)
committerKeir Fraser <keir@xen.org>
Fri, 20 Jan 2012 10:13:55 +0000 (10:13 +0000)
is_initialised under the per-domain lock.

Signed-off-by: Keir Fraser <keir@xen.org>
xen/arch/x86/hvm/hvm.c
xen/common/compat/domain.c
xen/common/domain.c

index 01c1411e0bf8102fbd963ee8df7876ed2b52d26f..554afa3ac927d7e088ab780f7184502ec23c0e87 100644 (file)
@@ -685,11 +685,7 @@ static int hvm_load_cpu_ctxt(struct domain *d, hvm_domain_context_t *h)
     }
 
     /* Need to init this vcpu before loading its contents */
-    rc = 0;
-    domain_lock(d);
-    if ( !v->is_initialised )
-        rc = boot_vcpu(d, vcpuid, NULL);
-    domain_unlock(d);
+    rc = boot_vcpu(d, vcpuid, NULL);
     if ( rc != 0 )
         return rc;
 
index 67e0e5e3161c53091ce6467e46d9f6b48dd2f316..cf8c6df25454b44956e2c61b0cbef6a3368dba47 100644 (file)
@@ -46,11 +46,7 @@ int compat_vcpu_op(int cmd, int vcpuid, XEN_GUEST_HANDLE(void) arg)
             break;
         }
 
-        domain_lock(d);
-        rc = -EEXIST;
-        if ( !v->is_initialised )
-            rc = boot_vcpu(d, vcpuid, cmp_ctxt);
-        domain_unlock(d);
+        rc = boot_vcpu(d, vcpuid, cmp_ctxt);
 
         xfree(cmp_ctxt);
         break;
index 52a63efb82c6aeb58f3bbb271636ca12cc0bb432..2cc6ab150c561711e818baf15eae1535d9ddbee1 100644 (file)
@@ -781,10 +781,13 @@ void domain_unpause_by_systemcontroller(struct domain *d)
 int boot_vcpu(struct domain *d, int vcpuid, vcpu_guest_context_u ctxt)
 {
     struct vcpu *v = d->vcpu[vcpuid];
+    int rc;
 
-    BUG_ON(v->is_initialised);
+    domain_lock(d);
+    rc = v->is_initialised ? -EEXIST : arch_set_info_guest(v, ctxt);
+    domain_unlock(d);
 
-    return arch_set_info_guest(v, ctxt);
+    return rc;
 }
 
 void vcpu_reset(struct vcpu *v)
@@ -844,23 +847,23 @@ long do_vcpu_op(int cmd, int vcpuid, XEN_GUEST_HANDLE(void) arg)
             return -EFAULT;
         }
 
-        domain_lock(d);
-        rc = -EEXIST;
-        if ( !v->is_initialised )
-            rc = boot_vcpu(d, vcpuid, ctxt);
-        domain_unlock(d);
+        rc = boot_vcpu(d, vcpuid, ctxt);
 
         free_vcpu_guest_context(ctxt);
         break;
 
-    case VCPUOP_up:
+    case VCPUOP_up: {
+        bool_t wake = 0;
+        domain_lock(d);
         if ( !v->is_initialised )
-            return -EINVAL;
-
-        if ( test_and_clear_bit(_VPF_down, &v->pause_flags) )
+            rc = -EINVAL;
+        else
+            wake = test_and_clear_bit(_VPF_down, &v->pause_flags);
+        domain_unlock(d);
+        if ( wake )
             vcpu_wake(v);
-
         break;
+    }
 
     case VCPUOP_down:
         if ( !test_and_set_bit(_VPF_down, &v->pause_flags) )