xen: Add versions of rcu_lock_*_domain without IS_PRIV
authorDaniel De Graaf <dgdegra@tycho.nsa.gov>
Mon, 15 Oct 2012 15:51:44 +0000 (16:51 +0100)
committerDaniel De Graaf <dgdegra@tycho.nsa.gov>
Mon, 15 Oct 2012 15:51:44 +0000 (16:51 +0100)
These functions will be used to avoid duplication of IS_PRIV calls
that will be introduced in XSM hooks. This also fixes a build error
with XSM enabled introduced by 25925:d1c3375c3f11 which depends on
this patch.

Signed-off-by: Daniel De Graaf <dgdegra@tycho.nsa.gov>
Committed-by: Keir Fraser <keir@xen.org>
xen/common/domain.c
xen/include/xen/sched.h

index a1aa05e03bd2684623a867874bbb1203c83df5d0..52489b3924db57f19f7165590fdbffc6802dd9a4 100644 (file)
@@ -420,6 +420,13 @@ struct domain *rcu_lock_domain_by_id(domid_t dom)
     return d;
 }
 
+struct domain *rcu_lock_domain_by_any_id(domid_t dom)
+{
+    if ( dom == DOMID_SELF )
+        return rcu_lock_current_domain();
+    return rcu_lock_domain_by_id(dom);
+}
+
 int rcu_lock_target_domain_by_id(domid_t dom, struct domain **d)
 {
     if ( dom == DOMID_SELF )
@@ -454,6 +461,20 @@ int rcu_lock_remote_target_domain_by_id(domid_t dom, struct domain **d)
     return 0;
 }
 
+int rcu_lock_remote_domain_by_id(domid_t dom, struct domain **d)
+{
+    if ( (*d = rcu_lock_domain_by_id(dom)) == NULL )
+        return -ESRCH;
+
+    if ( *d == current->domain )
+    {
+        rcu_unlock_domain(*d);
+        return -EPERM;
+    }
+
+    return 0;
+}
+
 int domain_kill(struct domain *d)
 {
     int rc = 0;
index 53804c87d58725ecf2173f93018f4704d70e2fc1..b0def4a424423f7bfff294706b011e78f9c69adf 100644 (file)
@@ -446,6 +446,11 @@ struct domain *domain_create(
  */
 struct domain *rcu_lock_domain_by_id(domid_t dom);
 
+/*
+ * As above function, but resolves DOMID_SELF to current domain
+ */
+struct domain *rcu_lock_domain_by_any_id(domid_t dom);
+
 /*
  * As above function, but accounts for current domain context:
  *  - Translates target DOMID_SELF into caller's domain id; and
@@ -460,6 +465,12 @@ int rcu_lock_target_domain_by_id(domid_t dom, struct domain **d);
  */
 int rcu_lock_remote_target_domain_by_id(domid_t dom, struct domain **d);
 
+/*
+ * As rcu_lock_domain_by_id(), but will fail EPERM or ESRCH rather than resolve
+ * to local domain.
+ */
+int rcu_lock_remote_domain_by_id(domid_t dom, struct domain **d);
+
 /* Finish a RCU critical region started by rcu_lock_domain_by_id(). */
 static inline void rcu_unlock_domain(struct domain *d)
 {