Skip to contentSkip to conversation

Fix rcu domain locking for transitive grants

PATCH In review George Dunlap 4 participants 9 messages Mar 8, 2011

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix rcu domain locking for transitive grants

When acquiring a transitive grant for copy then the owning domain needs to be locked down as well as the granting domain. This was being done, but the unlocking was not. The acquire code now stores the struct domain * of the owning domain (rather than the domid) in the active entry in the granting domain. The release code then does the unlock on the owning domain. Note that I believe I also fixed a bug where, for non-transitive grants the active entry contained a reference to the acquiring domain rather than the granting domain. From my reading of the code this would stop the release code for transitive grants from terminating its recursion correctly.

xen/common/grant_table.c +24 -29
diff -r f071d8e9f744 -r 14211e98efac xen/common/grant_table.c
@@ -1626,11 +1626,10 @@
     struct active_grant_entry *act;
     unsigned long r_frame;
     uint16_t *status;
-    domid_t trans_domid;
     grant_ref_t trans_gref;
     int released_read;
     int released_write;
-    struct domain *trans_dom;
+    struct domain *td;
 
     released_read = 0;
     released_write = 0;
@@ -1644,15 +1643,13 @@
     if (rd->grant_table->gt_version == 1)
     {
         status = &sha->flags;
-        trans_domid = rd->domain_id;
-        /* Shut the compiler up.  This'll never be used, because
-           trans_domid == rd->domain_id, but gcc doesn't know that. */
-        trans_gref = 0x1234567;
+        td = rd;
+        trans_gref = gref;
     }
     else
     {
         status = &status_entry(rd->grant_table, gref);
-        trans_domid = act->trans_dom;
+        td = act->trans_domain;
         trans_gref = act->trans_gref;
     }
 
@@ -1680,21 +1677,16 @@
 
     spin_unlock(&rd->grant_table->lock);
 
-    if ( trans_domid != rd->domain_id )
+    if ( td != rd )
     {
-        if ( released_write || released_read )
-        {
-            trans_dom = rcu_lock_domain_by_id(trans_domid);
-            if ( trans_dom != NULL )
-            {
-                /* Recursive calls, but they're tail calls, so it's
-                   okay. */
-                if ( released_write )
-                    __release_grant_for_copy(trans_dom, trans_gref, 0);
-                else if ( released_read )
-                    __release_grant_for_copy(trans_dom, trans_gref, 1);
-            }
-        }
+        /* Recursive calls, but they're tail calls, so it's
+           okay. */
+        if ( released_write )
+            __release_grant_for_copy(td, trans_gref, 0);
+        else if ( released_read )
+            __release_grant_for_copy(td, trans_gref, 1);
+
+	rcu_unlock_domain(td);
     }
 }
 
@@ -1731,7 +1723,7 @@
     uint32_t old_pin;
     domid_t trans_domid;
     grant_ref_t trans_gref;
-    struct domain *rrd;
+    struct domain *td;
     unsigned long gfn;
     unsigned long grant_frame;
     unsigned trans_page_off;
@@ -1785,8 +1777,8 @@
                                status) ) != GNTST_okay )
              goto unlock_out;
 
-        trans_domid = ld->domain_id;
-        trans_gref = 0;
+        td = rd;
+        trans_gref = gref;
         if ( sha2 && (shah->flags & GTF_type_mask) == GTF_transitive )
         {
             if ( !allow_transitive )
@@ -1808,14 +1800,15 @@
                that you don't need to go out of your way to avoid it
                in the guest. */
 
-            rrd = rcu_lock_domain_by_id(trans_domid);
-            if ( rrd == NULL )
+            /* We need to leave the rrd locked during the grant copy */
+            td = rcu_lock_domain_by_id(trans_domid);
+            if ( td == NULL )
                 PIN_FAIL(unlock_out, GNTST_general_error,
                          "transitive grant referenced bad domain %d\n",
                          trans_domid);
             spin_unlock(&rd->grant_table->lock);
 
-            rc = __acquire_grant_for_copy(rrd, trans_gref, rd,
+            rc = __acquire_grant_for_copy(td, trans_gref, rd,
                                           readonly, &grant_frame,
                                           &trans_page_off, &trans_length,
                                           0, &ignore);
@@ -1823,6 +1816,7 @@
             spin_lock(&rd->grant_table->lock);
             if ( rc != GNTST_okay ) {
                 __fixup_status_for_pin(act, status);
+	        rcu_unlock_domain(td);
                 spin_unlock(&rd->grant_table->lock);
                 return rc;
             }
@@ -1834,6 +1828,7 @@
             if ( act->pin != old_pin )
             {
                 __fixup_status_for_pin(act, status);
+	        rcu_unlock_domain(td);
                 spin_unlock(&rd->grant_table->lock);
                 return __acquire_grant_for_copy(rd, gref, ld, readonly,
                                                 frame, page_off, length,
@@ -1845,7 +1840,7 @@
                sub-page, but we always treat it as one because that
                blocks mappings of transitive grants. */
             is_sub_page = 1;
-            *owning_domain = rrd;
+            *owning_domain = td;
             act->gfn = -1ul;
         }
         else if ( sha1 )
@@ -1891,7 +1886,7 @@
             act->is_sub_page = is_sub_page;
             act->start = trans_page_off;
             act->length = trans_length;
-            act->trans_dom = trans_domid;
+            act->trans_domain = td;
             act->trans_gref = trans_gref;
             act->frame = grant_frame;
         }
xen/include/xen/grant_table.h +1 -1
diff -r f071d8e9f744 -r 14211e98efac xen/include/xen/grant_table.h
@@ -32,7 +32,7 @@
 struct active_grant_entry {
     u32           pin;    /* Reference count information.             */
     domid_t       domid;  /* Domain being granted access.             */
-    domid_t       trans_dom;
+    struct domain *trans_domain;
     uint32_t      trans_gref;
     unsigned long frame;  /* Frame being granted.                     */
     unsigned long gfn;    /* Guest's idea of the frame being granted. */
#1 lore raw

This should be backported to the 4.1 branch; it causes a hypervisor BUG() if guests are using netchannel2 transtiive grants to talk to each other when debug mode is on.

-George

Quoted 171 lines · George Dunlap

When acquiring a transitive grant for copy then the owning domain needs to be locked down as well as the granting domain. This was being done, but the unlocking was not. The acquire code now stores the struct domain * of the owning domain (rather than the domid) in the active entry in the granting domain. The release code then does the unlock on the owning domain. Note that I believe I also fixed a bug where, for non-transitive grants the active entry contained a reference to the acquiring domain rather than the granting domain. From my reading of the code this would stop the release code for transitive grants from terminating its recursion correctly.

diff -r f071d8e9f744 -r 14211e98efac xen/common/grant_table.c

xen/common/grant_table.c  Tue Mar 08 14:39:03 2011 +0000 renamed from xen/common/grant_table.c  Tue Mar 08 10:23:52 2011 +0000 +3 -6
@@ -1626,11 +1626,10 @@
     struct active_grant_entry *act;
     unsigned long r_frame;
     uint16_t *status;
-    domid_t trans_domid;
     grant_ref_t trans_gref;
     int released_read;
     int released_write;
-    struct domain *trans_dom;
+    struct domain *td;
 
     released_read = 0;
     released_write = 0;
@@ -1644,15 +1643,13 @@
     if (rd->grant_table->gt_version == 1)
     {
         status = &sha->flags;
-        trans_domid = rd->domain_id;
-        /* Shut the compiler up.  This'll never be used, because
-           trans_domid == rd->domain_id, but gcc doesn't know that. */
-        trans_gref = 0x1234567;
+        td = rd;
+        trans_gref = gref;
     }

    else
    {
        status = &status_entry(rd->grant_table, gref);
-        trans_domid = act->trans_dom;
+        td = act->trans_domain;
        trans_gref = act->trans_gref;
    }

xen/common/grant_table.c  Tue Mar 08 14:39:03 2011 +0000 renamed from xen/common/grant_table.c  Tue Mar 08 10:23:52 2011 +0000 +12 -17
@@ -1680,21 +1677,16 @@
 
     spin_unlock(&rd->grant_table->lock);
 
-    if ( trans_domid != rd->domain_id )
+    if ( td != rd )
     {
-        if ( released_write || released_read )
-        {
-            trans_dom = rcu_lock_domain_by_id(trans_domid);
-            if ( trans_dom != NULL )
-            {
-                /* Recursive calls, but they're tail calls, so it's
-                   okay. */
-                if ( released_write )
-                    __release_grant_for_copy(trans_dom, trans_gref, 0);
-                else if ( released_read )
-                    __release_grant_for_copy(trans_dom, trans_gref, 1);
-            }
-        }
+        /* Recursive calls, but they're tail calls, so it's
+           okay. */
+        if ( released_write )
+            __release_grant_for_copy(td, trans_gref, 0);
+        else if ( released_read )
+            __release_grant_for_copy(td, trans_gref, 1);
+
+       rcu_unlock_domain(td);
     }
  }
 
@@ -1731,7 +1723,7 @@
     uint32_t old_pin;
     domid_t trans_domid;
     grant_ref_t trans_gref;
-    struct domain *rrd;
+    struct domain *td;
     unsigned long gfn;
     unsigned long grant_frame;
     unsigned trans_page_off;
@@ -1785,8 +1777,8 @@
                                status) ) != GNTST_okay )
              goto unlock_out;
 
-        trans_domid = ld->domain_id;
-        trans_gref = 0;
+        td = rd;
+        trans_gref = gref;
         if ( sha2 && (shah->flags & GTF_type_mask) == GTF_transitive )
         {
             if ( !allow_transitive )
@@ -1808,14 +1800,15 @@

               that you don't need to go out of your way to avoid it in the guest. */

-            rrd = rcu_lock_domain_by_id(trans_domid);
-            if ( rrd == NULL )
+            /* We need to leave the rrd locked during the grant copy */
+            td = rcu_lock_domain_by_id(trans_domid);
+            if ( td == NULL )
                PIN_FAIL(unlock_out, GNTST_general_error, "transitive grant referenced bad domain %d\n", trans_domid); spin_unlock(&rd->grant_table->lock);

-            rc = __acquire_grant_for_copy(rrd, trans_gref, rd,
+            rc = __acquire_grant_for_copy(td, trans_gref, rd, readonly, &grant_frame, &trans_page_off, &trans_length, 0, &ignore);

xen/common/grant_table.c  Tue Mar 08 14:39:03 2011 +0000 renamed from xen/common/grant_table.c  Tue Mar 08 10:23:52 2011 +0000 +2 -0
@@ -1823,6 +1816,7 @@
             spin_lock(&rd->grant_table->lock);
             if ( rc != GNTST_okay ) {
                 __fixup_status_for_pin(act, status);
+               rcu_unlock_domain(td);
                 spin_unlock(&rd->grant_table->lock);
                 return rc;
             }
@@ -1834,6 +1828,7 @@
             if ( act->pin != old_pin )
             {
                 __fixup_status_for_pin(act, status);
+               rcu_unlock_domain(td);
                 spin_unlock(&rd->grant_table->lock);
                 return __acquire_grant_for_copy(rd, gref, ld, readonly,
                                                 frame, page_off, length,
@@ -1845,7 +1840,7 @@

               sub-page, but we always treat it as one because that blocks mappings of transitive grants. */ is_sub_page = 1;
-            *owning_domain = rrd;
+            *owning_domain = td;
            act->gfn = -1ul;
        }
        else if ( sha1 )

xen/common/grant_table.c  Tue Mar 08 14:39:03 2011 +0000 renamed from xen/common/grant_table.c  Tue Mar 08 10:23:52 2011 +0000 +1 -1
@@ -1891,7 +1886,7 @@
             act->is_sub_page = is_sub_page;
             act->start = trans_page_off;
             act->length = trans_length;
-            act->trans_dom = trans_domid;
+            act->trans_domain = td;
             act->trans_gref = trans_gref;
             act->frame = grant_frame;
         }

diff -r f071d8e9f744 -r 14211e98efac xen/include/xen/grant_table.h

xen/include/xen/grant_table.h     Tue Mar 08 14:39:03 2011 +0000 renamed from xen/include/xen/grant_table.h     Tue Mar 08 10:23:52 2011 +0000 +0 -0
@@ -32,7 +32,7 @@
  struct active_grant_entry {

    u32           pin;    /* Reference count information.             */ domid_t       domid;  /* Domain being granted access.             */
-    domid_t       trans_dom;
+    struct domain *trans_domain;
    uint32_t      trans_gref;
    unsigned long frame;  /* Frame being granted.                     */ unsigned long gfn;    /* Guest's idea of the frame being granted. */

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#2 lore raw
Quoted 3 lines · George Dunlap

This should be backported to the 4.1 branch; it causes a hypervisor BUG() if guests are using netchannel2 transtiive grants to talk to each other when debug mode is on.

I stubbed out the preemption checking stuff in 4.1 branch (it's not really needed since there are no users of waitqueues in 4.1), so this patch is not required. And that's fortunate, since it's quite non-trivial.

-- Keir

Quoted 180 lines

-George

Quoted 166 lines · George Dunlap

When acquiring a transitive grant for copy then the owning domain needs to be locked down as well as the granting domain. This was being done, but the unlocking was not. The acquire code now stores the struct domain * of the owning domain (rather than the domid) in the active entry in the granting domain. The release code then does the unlock on the owning domain. Note that I believe I also fixed a bug where, for non-transitive grants the active entry contained a reference to the acquiring domain rather than the granting domain. From my reading of the code this would stop the release code for transitive grants from terminating its recursion correctly.

diff -r f071d8e9f744 -r 14211e98efac xen/common/grant_table.c

xen/common/grant_table.c  Tue Mar 08 14:39:03 2011 +0000 renamed from xen/common/grant_table.c  Tue Mar 08 10:23:52 2011 +0000 +3 -6
@@ -1626,11 +1626,10 @@
     struct active_grant_entry *act;
     unsigned long r_frame;
     uint16_t *status;
-    domid_t trans_domid;
     grant_ref_t trans_gref;
     int released_read;
     int released_write;
-    struct domain *trans_dom;
+    struct domain *td;
 
     released_read = 0;
     released_write = 0;
@@ -1644,15 +1643,13 @@
     if (rd->grant_table->gt_version == 1)
     {
         status = &sha->flags;
-        trans_domid = rd->domain_id;
-        /* Shut the compiler up.  This'll never be used, because
-           trans_domid == rd->domain_id, but gcc doesn't know that. */
-        trans_gref = 0x1234567;
+        td = rd;
+        trans_gref = gref;
     }

    else
    {
        status = &status_entry(rd->grant_table, gref);
-        trans_domid = act->trans_dom;
+        td = act->trans_domain;
        trans_gref = act->trans_gref;
    }

xen/common/grant_table.c  Tue Mar 08 14:39:03 2011 +0000 renamed from xen/common/grant_table.c  Tue Mar 08 10:23:52 2011 +0000 +12 -17
@@ -1680,21 +1677,16 @@
 
     spin_unlock(&rd->grant_table->lock);
 
-    if ( trans_domid != rd->domain_id )
+    if ( td != rd )
     {
-        if ( released_write || released_read )
-        {
-            trans_dom = rcu_lock_domain_by_id(trans_domid);
-            if ( trans_dom != NULL )
-            {
-                /* Recursive calls, but they're tail calls, so it's
-                   okay. */
-                if ( released_write )
-                    __release_grant_for_copy(trans_dom, trans_gref, 0);
-                else if ( released_read )
-                    __release_grant_for_copy(trans_dom, trans_gref, 1);
-            }
-        }
+        /* Recursive calls, but they're tail calls, so it's
+           okay. */
+        if ( released_write )
+            __release_grant_for_copy(td, trans_gref, 0);
+        else if ( released_read )
+            __release_grant_for_copy(td, trans_gref, 1);
+
+       rcu_unlock_domain(td);
     }
  }
 
@@ -1731,7 +1723,7 @@
     uint32_t old_pin;
     domid_t trans_domid;
     grant_ref_t trans_gref;
-    struct domain *rrd;
+    struct domain *td;
     unsigned long gfn;
     unsigned long grant_frame;
     unsigned trans_page_off;
@@ -1785,8 +1777,8 @@
                                status) ) != GNTST_okay )
              goto unlock_out;
 
-        trans_domid = ld->domain_id;
-        trans_gref = 0;
+        td = rd;
+        trans_gref = gref;
         if ( sha2 && (shah->flags & GTF_type_mask) == GTF_transitive )
         {
             if ( !allow_transitive )
@@ -1808,14 +1800,15 @@

               that you don't need to go out of your way to avoid it in the guest. */

-            rrd = rcu_lock_domain_by_id(trans_domid);
-            if ( rrd == NULL )
+            /* We need to leave the rrd locked during the grant copy */
+            td = rcu_lock_domain_by_id(trans_domid);
+            if ( td == NULL )
                PIN_FAIL(unlock_out, GNTST_general_error, "transitive grant referenced bad domain %d\n", trans_domid); spin_unlock(&rd->grant_table->lock);

-            rc = __acquire_grant_for_copy(rrd, trans_gref, rd,
+            rc = __acquire_grant_for_copy(td, trans_gref, rd, readonly, &grant_frame, &trans_page_off, &trans_length, 0, &ignore);

xen/common/grant_table.c  Tue Mar 08 14:39:03 2011 +0000 renamed from xen/common/grant_table.c  Tue Mar 08 10:23:52 2011 +0000 +2 -0
@@ -1823,6 +1816,7 @@
             spin_lock(&rd->grant_table->lock);
             if ( rc != GNTST_okay ) {
                 __fixup_status_for_pin(act, status);
+               rcu_unlock_domain(td);
                 spin_unlock(&rd->grant_table->lock);
                 return rc;
             }
@@ -1834,6 +1828,7 @@
             if ( act->pin != old_pin )
             {
                 __fixup_status_for_pin(act, status);
+               rcu_unlock_domain(td);
                 spin_unlock(&rd->grant_table->lock);
                 return __acquire_grant_for_copy(rd, gref, ld, readonly,
                                                 frame, page_off, length,
@@ -1845,7 +1840,7 @@

               sub-page, but we always treat it as one because that blocks mappings of transitive grants. */ is_sub_page = 1;
-            *owning_domain = rrd;
+            *owning_domain = td;
            act->gfn = -1ul;
        }
        else if ( sha1 )

xen/common/grant_table.c  Tue Mar 08 14:39:03 2011 +0000 renamed from xen/common/grant_table.c  Tue Mar 08 10:23:52 2011 +0000 +1 -1
@@ -1891,7 +1886,7 @@
             act->is_sub_page = is_sub_page;
             act->start = trans_page_off;
             act->length = trans_length;
-            act->trans_dom = trans_domid;
+            act->trans_domain = td;
             act->trans_gref = trans_gref;
             act->frame = grant_frame;
         }

diff -r f071d8e9f744 -r 14211e98efac xen/include/xen/grant_table.h

xen/include/xen/grant_table.h     Tue Mar 08 14:39:03 2011 +0000 renamed from xen/include/xen/grant_table.h     Tue Mar 08 10:23:52 2011 +0000 +0 -0
@@ -32,7 +32,7 @@
  struct active_grant_entry {

    u32           pin;    /* Reference count information.             */ domid_t       domid;  /* Domain being granted access.             */
-    domid_t       trans_dom;
+    struct domain *trans_domain;
    uint32_t      trans_gref;
    unsigned long frame;  /* Frame being granted.                     */ unsigned long gfn;    /* Guest's idea of the frame being granted. */

Quoted 5 lines

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#3 lore raw
Quoted 9 lines · Keir Fraser
Quoted 3 lines · George Dunlap

This should be backported to the 4.1 branch; it causes a hypervisor BUG() if guests are using netchannel2 transtiive grants to talk to each other when debug mode is on.

I stubbed out the preemption checking stuff in 4.1 branch (it's not really needed since there are no users of waitqueues in 4.1), so this patch is not required. And that's fortunate, since it's quite non-trivial.

Are the rcu locks still noops then?

-George

Quoted 185 lines

-- Keir

Quoted 180 lines

-George

Quoted 166 lines · George Dunlap

When acquiring a transitive grant for copy then the owning domain needs to be locked down as well as the granting domain. This was being done, but the unlocking was not. The acquire code now stores the struct domain * of the owning domain (rather than the domid) in the active entry in the granting domain. The release code then does the unlock on the owning domain. Note that I believe I also fixed a bug where, for non-transitive grants the active entry contained a reference to the acquiring domain rather than the granting domain. From my reading of the code this would stop the release code for transitive grants from terminating its recursion correctly.

diff -r f071d8e9f744 -r 14211e98efac xen/common/grant_table.c

xen/common/grant_table.c Tue Mar 08 14:39:03 2011 +0000 renamed from xen/common/grant_table.c Tue Mar 08 10:23:52 2011 +0000 +24 -29
@@ -1626,11 +1626,10 @@
    struct active_grant_entry *act;
    unsigned long r_frame;
    uint16_t *status;
-    domid_t trans_domid;
    grant_ref_t trans_gref;
    int released_read;
    int released_write;
-    struct domain *trans_dom;
+    struct domain *td;
 
    released_read = 0;
    released_write = 0;
@@ -1644,15 +1643,13 @@
    if (rd->grant_table->gt_version == 1)
    {
        status = &sha->flags;
-        trans_domid = rd->domain_id;
-        /* Shut the compiler up.  This'll never be used, because
-           trans_domid == rd->domain_id, but gcc doesn't know that. */
-        trans_gref = 0x1234567;
+        td = rd;
+        trans_gref = gref;
    }
    else
    {
        status = &status_entry(rd->grant_table, gref);
-        trans_domid = act->trans_dom;
+        td = act->trans_domain;
        trans_gref = act->trans_gref;
    }
 
@@ -1680,21 +1677,16 @@
 
    spin_unlock(&rd->grant_table->lock);
 
-    if ( trans_domid != rd->domain_id )
+    if ( td != rd )
    {
-        if ( released_write || released_read )
-        {
-            trans_dom = rcu_lock_domain_by_id(trans_domid);
-            if ( trans_dom != NULL )
-            {
-                /* Recursive calls, but they're tail calls, so it's
-                   okay. */
-                if ( released_write )
-                    __release_grant_for_copy(trans_dom, trans_gref, 0);
-                else if ( released_read )
-                    __release_grant_for_copy(trans_dom, trans_gref, 1);
-            }
-        }
+        /* Recursive calls, but they're tail calls, so it's
+           okay. */
+        if ( released_write )
+            __release_grant_for_copy(td, trans_gref, 0);
+        else if ( released_read )
+            __release_grant_for_copy(td, trans_gref, 1);
+
+       rcu_unlock_domain(td);
    }
 }
 
@@ -1731,7 +1723,7 @@
    uint32_t old_pin;
    domid_t trans_domid;
    grant_ref_t trans_gref;
-    struct domain *rrd;
+    struct domain *td;
    unsigned long gfn;
    unsigned long grant_frame;
    unsigned trans_page_off;
@@ -1785,8 +1777,8 @@
                               status) ) != GNTST_okay )
             goto unlock_out;
 
-        trans_domid = ld->domain_id;
-        trans_gref = 0;
+        td = rd;
+        trans_gref = gref;
        if ( sha2 && (shah->flags & GTF_type_mask) == GTF_transitive )
        {
            if ( !allow_transitive )
@@ -1808,14 +1800,15 @@
               that you don't need to go out of your way to avoid it
               in the guest. */
 
-            rrd = rcu_lock_domain_by_id(trans_domid);
-            if ( rrd == NULL )
+            /* We need to leave the rrd locked during the grant copy */
+            td = rcu_lock_domain_by_id(trans_domid);
+            if ( td == NULL )
                PIN_FAIL(unlock_out, GNTST_general_error,
                         "transitive grant referenced bad domain %d\n",
                         trans_domid);
            spin_unlock(&rd->grant_table->lock);
 
-            rc = __acquire_grant_for_copy(rrd, trans_gref, rd,
+            rc = __acquire_grant_for_copy(td, trans_gref, rd,
                                          readonly, &grant_frame,
                                          &trans_page_off, &trans_length,
                                          0, &ignore);
@@ -1823,6 +1816,7 @@
            spin_lock(&rd->grant_table->lock);
            if ( rc != GNTST_okay ) {
                __fixup_status_for_pin(act, status);
+               rcu_unlock_domain(td);
                spin_unlock(&rd->grant_table->lock);
                return rc;
            }
@@ -1834,6 +1828,7 @@
            if ( act->pin != old_pin )
            {
                __fixup_status_for_pin(act, status);
+               rcu_unlock_domain(td);
                spin_unlock(&rd->grant_table->lock);
                return __acquire_grant_for_copy(rd, gref, ld, readonly,
                                                frame, page_off, length,
@@ -1845,7 +1840,7 @@
               sub-page, but we always treat it as one because that
               blocks mappings of transitive grants. */
            is_sub_page = 1;
-            *owning_domain = rrd;
+            *owning_domain = td;
            act->gfn = -1ul;
        }
        else if ( sha1 )
@@ -1891,7 +1886,7 @@
            act->is_sub_page = is_sub_page;
            act->start = trans_page_off;
            act->length = trans_length;
-            act->trans_dom = trans_domid;
+            act->trans_domain = td;
            act->trans_gref = trans_gref;
            act->frame = grant_frame;
        }

diff -r f071d8e9f744 -r 14211e98efac xen/include/xen/grant_table.h

xen/include/xen/grant_table.h Tue Mar 08 14:39:03 2011 +0000 renamed from xen/include/xen/grant_table.h Tue Mar 08 10:23:52 2011 +0000 +1 -1
@@ -32,7 +32,7 @@
 struct active_grant_entry {
    u32           pin;    /* Reference count information.             */
    domid_t       domid;  /* Domain being granted access.             */
-    domid_t       trans_dom;
+    struct domain *trans_domain;
    uint32_t      trans_gref;
    unsigned long frame;  /* Frame being granted.                     */
    unsigned long gfn;    /* Guest's idea of the frame being granted. */
Quoted 5 lines

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#4 lore raw
Quoted 7 lines · George Dunlap
Quoted 6 lines · Keir Fraser
Quoted 3 lines · George Dunlap

This should be backported to the 4.1 branch; it causes a hypervisor BUG() if guests are using netchannel2 transtiive grants to talk to each other when debug mode is on.

Quoted 5 lines
Quoted 3 lines

I stubbed out the preemption checking stuff in 4.1 branch (it's not really needed since there are no users of waitqueues in 4.1), so this patch is not required. And that's fortunate, since it's quite non-trivial.

Are the rcu locks still noops then?

Yes, since preempt_disable/enable are noops.

-- Keir

Quoted 190 lines

-George

Quoted 185 lines

-- Keir

Quoted 180 lines

-George

Quoted 166 lines · George Dunlap

When acquiring a transitive grant for copy then the owning domain needs to be locked down as well as the granting domain. This was being done, but the unlocking was not. The acquire code now stores the struct domain * of the owning domain (rather than the domid) in the active entry in the granting domain. The release code then does the unlock on the owning domain. Note that I believe I also fixed a bug where, for non-transitive grants the active entry contained a reference to the acquiring domain rather than the granting domain. From my reading of the code this would stop the release code for transitive grants from terminating its recursion correctly.

diff -r f071d8e9f744 -r 14211e98efac xen/common/grant_table.c

xen/common/grant_table.c Tue Mar 08 14:39:03 2011 +0000 renamed from xen/common/grant_table.c Tue Mar 08 10:23:52 2011 +0000 +24 -29
@@ -1626,11 +1626,10 @@
    struct active_grant_entry *act;
    unsigned long r_frame;
    uint16_t *status;
-    domid_t trans_domid;
    grant_ref_t trans_gref;
    int released_read;
    int released_write;
-    struct domain *trans_dom;
+    struct domain *td;
 
    released_read = 0;
    released_write = 0;
@@ -1644,15 +1643,13 @@
    if (rd->grant_table->gt_version == 1)
    {
        status = &sha->flags;
-        trans_domid = rd->domain_id;
-        /* Shut the compiler up.  This'll never be used, because
-           trans_domid == rd->domain_id, but gcc doesn't know that. */
-        trans_gref = 0x1234567;
+        td = rd;
+        trans_gref = gref;
    }
    else
    {
        status = &status_entry(rd->grant_table, gref);
-        trans_domid = act->trans_dom;
+        td = act->trans_domain;
        trans_gref = act->trans_gref;
    }
 
@@ -1680,21 +1677,16 @@
 
    spin_unlock(&rd->grant_table->lock);
 
-    if ( trans_domid != rd->domain_id )
+    if ( td != rd )
    {
-        if ( released_write || released_read )
-        {
-            trans_dom = rcu_lock_domain_by_id(trans_domid);
-            if ( trans_dom != NULL )
-            {
-                /* Recursive calls, but they're tail calls, so it's
-                   okay. */
-                if ( released_write )
-                    __release_grant_for_copy(trans_dom, trans_gref, 0);
-                else if ( released_read )
-                    __release_grant_for_copy(trans_dom, trans_gref, 1);
-            }
-        }
+        /* Recursive calls, but they're tail calls, so it's
+           okay. */
+        if ( released_write )
+            __release_grant_for_copy(td, trans_gref, 0);
+        else if ( released_read )
+            __release_grant_for_copy(td, trans_gref, 1);
+
+       rcu_unlock_domain(td);
    }
 }
 
@@ -1731,7 +1723,7 @@
    uint32_t old_pin;
    domid_t trans_domid;
    grant_ref_t trans_gref;
-    struct domain *rrd;
+    struct domain *td;
    unsigned long gfn;
    unsigned long grant_frame;
    unsigned trans_page_off;
@@ -1785,8 +1777,8 @@
                               status) ) != GNTST_okay )
             goto unlock_out;
 
-        trans_domid = ld->domain_id;
-        trans_gref = 0;
+        td = rd;
+        trans_gref = gref;
        if ( sha2 && (shah->flags & GTF_type_mask) == GTF_transitive )
        {
            if ( !allow_transitive )
@@ -1808,14 +1800,15 @@
               that you don't need to go out of your way to avoid it
               in the guest. */
 
-            rrd = rcu_lock_domain_by_id(trans_domid);
-            if ( rrd == NULL )
+            /* We need to leave the rrd locked during the grant copy */
+            td = rcu_lock_domain_by_id(trans_domid);
+            if ( td == NULL )
                PIN_FAIL(unlock_out, GNTST_general_error,
                         "transitive grant referenced bad domain %d\n",
                         trans_domid);
            spin_unlock(&rd->grant_table->lock);
 
-            rc = __acquire_grant_for_copy(rrd, trans_gref, rd,
+            rc = __acquire_grant_for_copy(td, trans_gref, rd,
                                          readonly, &grant_frame,
                                          &trans_page_off, &trans_length,
                                          0, &ignore);
@@ -1823,6 +1816,7 @@
            spin_lock(&rd->grant_table->lock);
            if ( rc != GNTST_okay ) {
                __fixup_status_for_pin(act, status);
+               rcu_unlock_domain(td);
                spin_unlock(&rd->grant_table->lock);
                return rc;
            }
@@ -1834,6 +1828,7 @@
            if ( act->pin != old_pin )
            {
                __fixup_status_for_pin(act, status);
+               rcu_unlock_domain(td);
                spin_unlock(&rd->grant_table->lock);
                return __acquire_grant_for_copy(rd, gref, ld, readonly,
                                                frame, page_off, length,
@@ -1845,7 +1840,7 @@
               sub-page, but we always treat it as one because that
               blocks mappings of transitive grants. */
            is_sub_page = 1;
-            *owning_domain = rrd;
+            *owning_domain = td;
            act->gfn = -1ul;
        }
        else if ( sha1 )
@@ -1891,7 +1886,7 @@
            act->is_sub_page = is_sub_page;
            act->start = trans_page_off;
            act->length = trans_length;
-            act->trans_dom = trans_domid;
+            act->trans_domain = td;
            act->trans_gref = trans_gref;
            act->frame = grant_frame;
        }

diff -r f071d8e9f744 -r 14211e98efac xen/include/xen/grant_table.h

xen/include/xen/grant_table.h Tue Mar 08 14:39:03 2011 +0000 renamed from xen/include/xen/grant_table.h Tue Mar 08 10:23:52 2011 +0000 +1 -1
@@ -32,7 +32,7 @@
 struct active_grant_entry {
    u32           pin;    /* Reference count information.             */
    domid_t       domid;  /* Domain being granted access.             */
-    domid_t       trans_dom;
+    struct domain *trans_domain;
    uint32_t      trans_gref;
    unsigned long frame;  /* Frame being granted.                     */
    unsigned long gfn;    /* Guest's idea of the frame being granted. */
Quoted 5 lines

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#5 lore raw
In reply to Keir Fraser

I still think this patch should stand. The locking around transitive grants is just borked and if someone actually does implement the rcu locks in future they will get a nasty surprise.

Paul

Quoted 242 lines

-----Original Message-----
From: [email protected] [mailto:xen-devel- [email protected]] On Behalf Of Keir Fraser
Sent: 08 March 2011 15:39
To: George Dunlap; [email protected]
Subject: Re: [Xen-devel] [PATCH] Fix rcu domain locking for transitive grants

Quoted 1 line · George Dunlap

This should be backported to the 4.1 branch; it causes a

hypervisor

Quoted 2 lines

BUG() if guests are using netchannel2 transtiive grants to talk to each other when debug mode is on.

I stubbed out the preemption checking stuff in 4.1 branch (it's not really needed since there are no users of waitqueues in 4.1), so this patch is not required. And that's fortunate, since it's quite non-trivial.

-- Keir

Quoted 7 lines

-George

Quoted 3 lines · George Dunlap

When acquiring a transitive grant for copy then the owning domain needs to be locked down as well as the granting domain. This was being done, but the unlocking was not. The acquire code now

stores

Quoted 1 line
Quoted 1 line

the struct domain * of the owning domain (rather than the domid)

in

Quoted 1 line
Quoted 1 line

the active entry in the granting domain. The release code then

does the unlock on the owning domain.

Quoted 2 lines
Quoted 2 lines

Note that I believe I also fixed a bug where, for non-transitive grants the active entry contained a reference to the acquiring

domain

Quoted 2 lines
Quoted 2 lines

rather than the granting domain. From my reading of the code this would stop the release code for transitive grants from

terminating

Quoted 19 lines
Quoted 19 lines

its recursion correctly.

diff -r f071d8e9f744 -r 14211e98efac xen/common/grant_table.c

xen/common/grant_table.c  Tue Mar 08 14:39:03 2011 +0000 renamed from xen/common/grant_table.c  Tue Mar 08 10:23:52 2011 +0000 +1 -2
@@ -1626,11 +1626,10 @@
     struct active_grant_entry *act;
     unsigned long r_frame;
     uint16_t *status;
-    domid_t trans_domid;
     grant_ref_t trans_gref;
     int released_read;
     int released_write;
-    struct domain *trans_dom;
+    struct domain *td;
 
Quoted 9 lines

xen/common/grant_table.c  Tue Mar 08 14:39:03 2011 +0000 line 1649

Quoted 9 lines
xen/common/grant_table.c  Tue Mar 08 14:39:03 2011 +0000 renamed from xen/common/grant_table.c  Tue Mar 08 10:23:52 2011 +0000 +0 -3
     released_read = 0;
     released_write = 0;
@@ -1644,15 +1643,13 @@
     if (rd->grant_table->gt_version == 1)
     {
         status = &sha->flags;
-        trans_domid = rd->domain_id;
-        /* Shut the compiler up.  This'll never be used, because
-           trans_domid == rd->domain_id, but gcc doesn't know

that.

Quoted 17 lines
Quoted 17 lines
xen/common/grant_table.c  Tue Mar 08 14:39:03 2011 +0000 renamed from xen/common/grant_table.c  Tue Mar 08 10:23:52 2011 +0000 +2 -1
 */
-        trans_gref = 0x1234567;
+        td = rd;
+        trans_gref = gref;
     }

    else
    {
        status = &status_entry(rd->grant_table, gref);
-        trans_domid = act->trans_dom;
+        td = act->trans_domain;
        trans_gref = act->trans_gref;
    }

xen/common/grant_table.c  Tue Mar 08 14:39:03 2011 +0000 renamed from xen/common/grant_table.c  Tue Mar 08 10:23:52 2011 +0000 +0 -0
@@ -1680,21 +1677,16 @@
 
     spin_unlock(&rd->grant_table->lock);
 
Quoted 9 lines

xen/common/grant_table.c  Tue Mar 08 14:39:03 2011 +0000 line 1690

Quoted 9 lines
xen/common/grant_table.c  Tue Mar 08 14:39:03 2011 +0000 renamed from xen/common/grant_table.c  Tue Mar 08 10:23:52 2011 +0000 +1 -7
-    if ( trans_domid != rd->domain_id )
+    if ( td != rd )
     {
-        if ( released_write || released_read )
-        {
-            trans_dom = rcu_lock_domain_by_id(trans_domid);
-            if ( trans_dom != NULL )
-            {
-                /* Recursive calls, but they're tail calls, so

it's

Quoted 3 lines

xen/common/grant_table.c  Tue Mar 08 14:39:03 2011 +0000 line 1693

Quoted 3 lines
xen/common/grant_table.c  Tue Mar 08 14:39:03 2011 +0000 renamed from xen/common/grant_table.c  Tue Mar 08 10:23:52 2011 +0000 +0 -3
-                   okay. */
-                if ( released_write )
-                    __release_grant_for_copy(trans_dom,

trans_gref,

Quoted 3 lines

xen/common/grant_table.c  Tue Mar 08 14:39:03 2011 +0000 line 1696

Quoted 3 lines
xen/common/grant_table.c  Tue Mar 08 14:39:03 2011 +0000 renamed from xen/common/grant_table.c  Tue Mar 08 10:23:52 2011 +0000 +0 -2
 0);
-                else if ( released_read )
-                    __release_grant_for_copy(trans_dom,

trans_gref,

Quoted 27 lines
Quoted 27 lines
xen/common/grant_table.c  Tue Mar 08 14:39:03 2011 +0000 renamed from xen/common/grant_table.c  Tue Mar 08 10:23:52 2011 +0000 +8 -2
 1);
-            }
-        }
+        /* Recursive calls, but they're tail calls, so it's
+           okay. */
+        if ( released_write )
+            __release_grant_for_copy(td, trans_gref, 0);
+        else if ( released_read )
+            __release_grant_for_copy(td, trans_gref, 1);
+
+       rcu_unlock_domain(td);
     }

 }

xen/common/grant_table.c  Tue Mar 08 14:39:03 2011 +0000 renamed from xen/common/grant_table.c  Tue Mar 08 10:23:52 2011 +0000 +1 -1
@@ -1731,7 +1723,7 @@
     uint32_t old_pin;
     domid_t trans_domid;
     grant_ref_t trans_gref;
-    struct domain *rrd;
+    struct domain *td;
     unsigned long gfn;
     unsigned long grant_frame;
     unsigned trans_page_off;
@@ -1785,8 +1777,8 @@
                                status) ) != GNTST_okay )
              goto unlock_out;
 
Quoted 5 lines
Quoted 5 lines
xen/common/grant_table.c  Tue Mar 08 14:39:03 2011 +0000 renamed from xen/common/grant_table.c  Tue Mar 08 10:23:52 2011 +0000 +2 -2
-        trans_domid = ld->domain_id;
-        trans_gref = 0;
+        td = rd;
+        trans_gref = gref;

        if ( sha2 && (shah->flags & GTF_type_mask) ==

GTF_transitive

Quoted 5 lines
Quoted 5 lines

)
        {
            if ( !allow_transitive )

xen/common/grant_table.c  Tue Mar 08 14:39:03 2011 +0000 renamed from xen/common/grant_table.c  Tue Mar 08 10:23:52 2011 +0000 +0 -0
@@ -1808,14 +1800,15 @@

               that you don't need to go out of your way to avoid

it

Quoted 5 lines
Quoted 5 lines

               in the guest. */

-            rrd = rcu_lock_domain_by_id(trans_domid);
-            if ( rrd == NULL )
+            /* We need to leave the rrd locked during the grant

copy

Quoted 26 lines
Quoted 26 lines

+ */
+            td = rcu_lock_domain_by_id(trans_domid);
+            if ( td == NULL )
                PIN_FAIL(unlock_out, GNTST_general_error, "transitive grant referenced bad domain %d\n",
                         trans_domid); spin_unlock(&rd->grant_table->lock);

-            rc = __acquire_grant_for_copy(rrd, trans_gref, rd,
+            rc = __acquire_grant_for_copy(td, trans_gref, rd, readonly, &grant_frame, &trans_page_off, &trans_length,
                                          0, &ignore); @@ -1823,6 +1816,7 @@
            spin_lock(&rd->grant_table->lock);
            if ( rc != GNTST_okay ) { __fixup_status_for_pin(act, status);
+               rcu_unlock_domain(td); spin_unlock(&rd->grant_table->lock); return rc;
            }

xen/common/grant_table.c  Tue Mar 08 14:39:03 2011 +0000 renamed from xen/common/grant_table.c  Tue Mar 08 10:23:52 2011 +0000 +0 -0
@@ -1834,6 +1828,7 @@
             if ( act->pin != old_pin )
             {
Quoted 8 lines
Quoted 8 lines
xen/common/grant_table.c  Tue Mar 08 14:39:03 2011 +0000 renamed from xen/common/grant_table.c  Tue Mar 08 10:23:52 2011 +0000 +1 -0
                 __fixup_status_for_pin(act, status);
+               rcu_unlock_domain(td);
                 spin_unlock(&rd->grant_table->lock);
                 return __acquire_grant_for_copy(rd, gref, ld,
 readonly,

                                                frame, page_off, length, @@ -1845,7 +1840,7 @@
               sub-page, but we always treat it as one because

that

Quoted 9 lines
Quoted 9 lines

               blocks mappings of transitive grants. */ is_sub_page = 1;
-            *owning_domain = rrd;
+            *owning_domain = td;
            act->gfn = -1ul;
        }
        else if ( sha1 )

xen/common/grant_table.c  Tue Mar 08 14:39:03 2011 +0000 renamed from xen/common/grant_table.c  Tue Mar 08 10:23:52 2011 +0000 +0 -0
@@ -1891,7 +1886,7 @@
             act->is_sub_page = is_sub_page;
Quoted 8 lines
Quoted 8 lines
xen/common/grant_table.c  Tue Mar 08 14:39:03 2011 +0000 renamed from xen/common/grant_table.c  Tue Mar 08 10:23:52 2011 +0000 +1 -1
             act->start = trans_page_off;
             act->length = trans_length;
-            act->trans_dom = trans_domid;
+            act->trans_domain = td;
             act->trans_gref = trans_gref;
             act->frame = grant_frame;
         }

diff -r f071d8e9f744 -r 14211e98efac

xen/include/xen/grant_table.h

Quoted 7 lines
Quoted 7 lines

--- a/xen/include/xen/grant_table.h     Tue Mar 08 10:23:52 2011 +0000
+++ b/xen/include/xen/grant_table.h     Tue Mar 08 14:39:03 2011 +++ +0000

xen/common/grant_table.c  Tue Mar 08 14:39:03 2011 +0000 renamed from xen/common/grant_table.c  Tue Mar 08 10:23:52 2011 +0000 +0 -0
@@ -32,7 +32,7 @@
  struct active_grant_entry {

    u32           pin;    /* Reference count

information.

Quoted 2 lines
Quoted 2 lines

*/
    domid_t       domid;  /* Domain being granted

access.

Quoted 5 lines
Quoted 5 lines

*/
-    domid_t       trans_dom;
+    struct domain *trans_domain;
    uint32_t      trans_gref;
    unsigned long frame;  /* Frame being

granted.

Quoted 2 lines
Quoted 2 lines

*/
    unsigned long gfn;    /* Guest's idea of the frame being

granted.

Quoted 8 lines
Quoted 7 lines

*/

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

Quoted 4 lines

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#6 lore raw
Quoted 3 lines · Paul Durrant

I still think this patch should stand. The locking around transitive grants is just borked and if someone actually does implement the rcu locks in future they will get a nasty surprise.

It will stand, in xen-unstable.

K.

Quoted 244 lines

Paul

Quoted 242 lines

-----Original Message-----
From: [email protected] [mailto:xen-devel- [email protected]] On Behalf Of Keir Fraser
Sent: 08 March 2011 15:39
To: George Dunlap; [email protected]
Subject: Re: [Xen-devel] [PATCH] Fix rcu domain locking for transitive grants

Quoted 1 line · George Dunlap

This should be backported to the 4.1 branch; it causes a

hypervisor

Quoted 2 lines

BUG() if guests are using netchannel2 transtiive grants to talk to each other when debug mode is on.

I stubbed out the preemption checking stuff in 4.1 branch (it's not really needed since there are no users of waitqueues in 4.1), so this patch is not required. And that's fortunate, since it's quite non-trivial.

-- Keir

Quoted 7 lines

-George

Quoted 3 lines · George Dunlap

When acquiring a transitive grant for copy then the owning domain needs to be locked down as well as the granting domain. This was being done, but the unlocking was not. The acquire code now

stores

Quoted 1 line
Quoted 1 line

the struct domain * of the owning domain (rather than the domid)

in

Quoted 1 line
Quoted 1 line

the active entry in the granting domain. The release code then

does the unlock on the owning domain.

Quoted 2 lines
Quoted 2 lines

Note that I believe I also fixed a bug where, for non-transitive grants the active entry contained a reference to the acquiring

domain

Quoted 2 lines
Quoted 2 lines

rather than the granting domain. From my reading of the code this would stop the release code for transitive grants from

terminating

Quoted 19 lines
Quoted 19 lines

its recursion correctly.

diff -r f071d8e9f744 -r 14211e98efac xen/common/grant_table.c

xen/common/grant_table.c  Tue Mar 08 14:39:03 2011 +0000 renamed from xen/common/grant_table.c  Tue Mar 08 10:23:52 2011 +0000 +1 -2
@@ -1626,11 +1626,10 @@
     struct active_grant_entry *act;
     unsigned long r_frame;
     uint16_t *status;
-    domid_t trans_domid;
     grant_ref_t trans_gref;
     int released_read;
     int released_write;
-    struct domain *trans_dom;
+    struct domain *td;
 
Quoted 9 lines

xen/common/grant_table.c  Tue Mar 08 14:39:03 2011 +0000 line 1649

Quoted 9 lines
xen/common/grant_table.c  Tue Mar 08 14:39:03 2011 +0000 renamed from xen/common/grant_table.c  Tue Mar 08 10:23:52 2011 +0000 +0 -3
     released_read = 0;
     released_write = 0;
@@ -1644,15 +1643,13 @@
     if (rd->grant_table->gt_version == 1)
     {
         status = &sha->flags;
-        trans_domid = rd->domain_id;
-        /* Shut the compiler up.  This'll never be used, because
-           trans_domid == rd->domain_id, but gcc doesn't know

that.

Quoted 17 lines
Quoted 17 lines
xen/common/grant_table.c  Tue Mar 08 14:39:03 2011 +0000 renamed from xen/common/grant_table.c  Tue Mar 08 10:23:52 2011 +0000 +2 -1
 */
-        trans_gref = 0x1234567;
+        td = rd;
+        trans_gref = gref;
     }

    else
    {
        status = &status_entry(rd->grant_table, gref);
-        trans_domid = act->trans_dom;
+        td = act->trans_domain;
        trans_gref = act->trans_gref;
    }

xen/common/grant_table.c  Tue Mar 08 14:39:03 2011 +0000 renamed from xen/common/grant_table.c  Tue Mar 08 10:23:52 2011 +0000 +0 -0
@@ -1680,21 +1677,16 @@
 
     spin_unlock(&rd->grant_table->lock);
 
Quoted 9 lines

xen/common/grant_table.c  Tue Mar 08 14:39:03 2011 +0000 line 1690

Quoted 9 lines
xen/common/grant_table.c  Tue Mar 08 14:39:03 2011 +0000 renamed from xen/common/grant_table.c  Tue Mar 08 10:23:52 2011 +0000 +1 -7
-    if ( trans_domid != rd->domain_id )
+    if ( td != rd )
     {
-        if ( released_write || released_read )
-        {
-            trans_dom = rcu_lock_domain_by_id(trans_domid);
-            if ( trans_dom != NULL )
-            {
-                /* Recursive calls, but they're tail calls, so

it's

Quoted 3 lines

xen/common/grant_table.c  Tue Mar 08 14:39:03 2011 +0000 line 1693

Quoted 3 lines
xen/common/grant_table.c  Tue Mar 08 14:39:03 2011 +0000 renamed from xen/common/grant_table.c  Tue Mar 08 10:23:52 2011 +0000 +0 -3
-                   okay. */
-                if ( released_write )
-                    __release_grant_for_copy(trans_dom,

trans_gref,

Quoted 3 lines

xen/common/grant_table.c  Tue Mar 08 14:39:03 2011 +0000 line 1696

Quoted 3 lines
xen/common/grant_table.c  Tue Mar 08 14:39:03 2011 +0000 renamed from xen/common/grant_table.c  Tue Mar 08 10:23:52 2011 +0000 +0 -2
 0);
-                else if ( released_read )
-                    __release_grant_for_copy(trans_dom,

trans_gref,

Quoted 27 lines
Quoted 27 lines
xen/common/grant_table.c  Tue Mar 08 14:39:03 2011 +0000 renamed from xen/common/grant_table.c  Tue Mar 08 10:23:52 2011 +0000 +8 -2
 1);
-            }
-        }
+        /* Recursive calls, but they're tail calls, so it's
+           okay. */
+        if ( released_write )
+            __release_grant_for_copy(td, trans_gref, 0);
+        else if ( released_read )
+            __release_grant_for_copy(td, trans_gref, 1);
+
+       rcu_unlock_domain(td);
     }

 }

xen/common/grant_table.c  Tue Mar 08 14:39:03 2011 +0000 renamed from xen/common/grant_table.c  Tue Mar 08 10:23:52 2011 +0000 +1 -1
@@ -1731,7 +1723,7 @@
     uint32_t old_pin;
     domid_t trans_domid;
     grant_ref_t trans_gref;
-    struct domain *rrd;
+    struct domain *td;
     unsigned long gfn;
     unsigned long grant_frame;
     unsigned trans_page_off;
@@ -1785,8 +1777,8 @@
                                status) ) != GNTST_okay )
              goto unlock_out;
 
Quoted 5 lines
Quoted 5 lines
xen/common/grant_table.c  Tue Mar 08 14:39:03 2011 +0000 renamed from xen/common/grant_table.c  Tue Mar 08 10:23:52 2011 +0000 +2 -2
-        trans_domid = ld->domain_id;
-        trans_gref = 0;
+        td = rd;
+        trans_gref = gref;

        if ( sha2 && (shah->flags & GTF_type_mask) ==

GTF_transitive

Quoted 5 lines
Quoted 5 lines

)
        {
            if ( !allow_transitive )

xen/common/grant_table.c  Tue Mar 08 14:39:03 2011 +0000 renamed from xen/common/grant_table.c  Tue Mar 08 10:23:52 2011 +0000 +0 -0
@@ -1808,14 +1800,15 @@

               that you don't need to go out of your way to avoid

it

Quoted 5 lines
Quoted 5 lines

               in the guest. */

-            rrd = rcu_lock_domain_by_id(trans_domid);
-            if ( rrd == NULL )
+            /* We need to leave the rrd locked during the grant

copy

Quoted 26 lines
Quoted 26 lines

+ */
+            td = rcu_lock_domain_by_id(trans_domid);
+            if ( td == NULL )
                PIN_FAIL(unlock_out, GNTST_general_error, "transitive grant referenced bad domain %d\n",
                         trans_domid); spin_unlock(&rd->grant_table->lock);

-            rc = __acquire_grant_for_copy(rrd, trans_gref, rd,
+            rc = __acquire_grant_for_copy(td, trans_gref, rd, readonly, &grant_frame, &trans_page_off, &trans_length,
                                          0, &ignore); @@ -1823,6 +1816,7 @@
            spin_lock(&rd->grant_table->lock);
            if ( rc != GNTST_okay ) { __fixup_status_for_pin(act, status);
+               rcu_unlock_domain(td); spin_unlock(&rd->grant_table->lock); return rc;
            }

xen/common/grant_table.c  Tue Mar 08 14:39:03 2011 +0000 renamed from xen/common/grant_table.c  Tue Mar 08 10:23:52 2011 +0000 +0 -0
@@ -1834,6 +1828,7 @@
             if ( act->pin != old_pin )
             {
Quoted 8 lines
Quoted 8 lines
xen/common/grant_table.c  Tue Mar 08 14:39:03 2011 +0000 renamed from xen/common/grant_table.c  Tue Mar 08 10:23:52 2011 +0000 +1 -0
                 __fixup_status_for_pin(act, status);
+               rcu_unlock_domain(td);
                 spin_unlock(&rd->grant_table->lock);
                 return __acquire_grant_for_copy(rd, gref, ld,
 readonly,

                                                frame, page_off, length, @@ -1845,7 +1840,7 @@
               sub-page, but we always treat it as one because

that

Quoted 9 lines
Quoted 9 lines

               blocks mappings of transitive grants. */ is_sub_page = 1;
-            *owning_domain = rrd;
+            *owning_domain = td;
            act->gfn = -1ul;
        }
        else if ( sha1 )

xen/common/grant_table.c  Tue Mar 08 14:39:03 2011 +0000 renamed from xen/common/grant_table.c  Tue Mar 08 10:23:52 2011 +0000 +0 -0
@@ -1891,7 +1886,7 @@
             act->is_sub_page = is_sub_page;
Quoted 8 lines
Quoted 8 lines
xen/common/grant_table.c  Tue Mar 08 14:39:03 2011 +0000 renamed from xen/common/grant_table.c  Tue Mar 08 10:23:52 2011 +0000 +1 -1
             act->start = trans_page_off;
             act->length = trans_length;
-            act->trans_dom = trans_domid;
+            act->trans_domain = td;
             act->trans_gref = trans_gref;
             act->frame = grant_frame;
         }

diff -r f071d8e9f744 -r 14211e98efac

xen/include/xen/grant_table.h

Quoted 7 lines
Quoted 7 lines

--- a/xen/include/xen/grant_table.h     Tue Mar 08 10:23:52 2011 +0000
+++ b/xen/include/xen/grant_table.h     Tue Mar 08 14:39:03 2011 +++ +0000

xen/common/grant_table.c  Tue Mar 08 14:39:03 2011 +0000 renamed from xen/common/grant_table.c  Tue Mar 08 10:23:52 2011 +0000 +0 -0
@@ -32,7 +32,7 @@
  struct active_grant_entry {

    u32           pin;    /* Reference count

information.

Quoted 2 lines
Quoted 2 lines

*/
    domid_t       domid;  /* Domain being granted

access.

Quoted 5 lines
Quoted 5 lines

*/
-    domid_t       trans_dom;
+    struct domain *trans_domain;
    uint32_t      trans_gref;
    unsigned long frame;  /* Frame being

granted.

Quoted 2 lines
Quoted 2 lines

*/
    unsigned long gfn;    /* Guest's idea of the frame being

granted.

Quoted 8 lines
Quoted 7 lines

*/

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

Quoted 4 lines

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#7 lore raw
In reply to Paul Durrant

As I understood him, Keir was saying he wasn't going to apply it 4.1 -- at least not before the official release. (Perhaps in 4.1.1?)

I don't really understand the logic of having locks which act as noops at all -- I think no matter what, if someone decides to implement RCU, they're in for a boatload of nasty surprises. It seems to me like the current locks will be little more than a hint to whatever future dev does that work that this is an area that they might want to look at. But it seems to me like they'll end up having to write the locks and locking disciplines from scratch anyway.

-George

Quoted 246 lines · Paul Durrant

I still think this patch should stand. The locking around transitive grants is just borked and if someone actually does implement the rcu locks in future they will get a nasty surprise.

Paul

Quoted 242 lines

-----Original Message-----
From: [email protected] [mailto:xen-devel- [email protected]] On Behalf Of Keir Fraser
Sent: 08 March 2011 15:39
To: George Dunlap; [email protected]
Subject: Re: [Xen-devel] [PATCH] Fix rcu domain locking for transitive grants

Quoted 1 line · George Dunlap

This should be backported to the 4.1 branch; it causes a

hypervisor

Quoted 2 lines

BUG() if guests are using netchannel2 transtiive grants to talk to each other when debug mode is on.

I stubbed out the preemption checking stuff in 4.1 branch (it's not really needed since there are no users of waitqueues in 4.1), so this patch is not required. And that's fortunate, since it's quite non-trivial.

-- Keir

Quoted 7 lines

-George

Quoted 3 lines · George Dunlap

When acquiring a transitive grant for copy then the owning domain needs to be locked down as well as the granting domain. This was being done, but the unlocking was not. The acquire code now

stores

Quoted 1 line
Quoted 1 line

the struct domain * of the owning domain (rather than the domid)

in

Quoted 1 line
Quoted 1 line

the active entry in the granting domain. The release code then

does the unlock on the owning domain.

Quoted 2 lines
Quoted 2 lines

Note that I believe I also fixed a bug where, for non-transitive grants the active entry contained a reference to the acquiring

domain

Quoted 2 lines
Quoted 2 lines

rather than the granting domain. From my reading of the code this would stop the release code for transitive grants from

terminating

Quoted 19 lines
Quoted 19 lines

its recursion correctly.

diff -r f071d8e9f744 -r 14211e98efac xen/common/grant_table.c

xen/common/grant_table.c Tue Mar 08 14:39:03 2011 +0000 renamed from xen/common/grant_table.c Tue Mar 08 10:23:52 2011 +0000 +1 -2
@@ -1626,11 +1626,10 @@
    struct active_grant_entry *act;
    unsigned long r_frame;
    uint16_t *status;
-    domid_t trans_domid;
    grant_ref_t trans_gref;
    int released_read;
    int released_write;
-    struct domain *trans_dom;
+    struct domain *td;
 
Quoted 9 lines

xen/common/grant_table.c Tue Mar 08 14:39:03 2011 +0000 line 1649

Quoted 9 lines
xen/common/grant_table.c Tue Mar 08 14:39:03 2011 +0000 renamed from xen/common/grant_table.c Tue Mar 08 10:23:52 2011 +0000 +0 -3
    released_read = 0;
    released_write = 0;
@@ -1644,15 +1643,13 @@
    if (rd->grant_table->gt_version == 1)
    {
        status = &sha->flags;
-        trans_domid = rd->domain_id;
-        /* Shut the compiler up.  This'll never be used, because
-           trans_domid == rd->domain_id, but gcc doesn't know

that.

Quoted 17 lines
Quoted 17 lines
xen/common/grant_table.c Tue Mar 08 14:39:03 2011 +0000 renamed from xen/common/grant_table.c Tue Mar 08 10:23:52 2011 +0000 +3 -2
 */
-        trans_gref = 0x1234567;
+        td = rd;
+        trans_gref = gref;
    }
    else
    {
        status = &status_entry(rd->grant_table, gref);
-        trans_domid = act->trans_dom;
+        td = act->trans_domain;
        trans_gref = act->trans_gref;
    }
@@ -1680,21 +1677,16 @@
 
    spin_unlock(&rd->grant_table->lock);
 
Quoted 9 lines

xen/common/grant_table.c Tue Mar 08 14:39:03 2011 +0000 line 1690

Quoted 9 lines
xen/common/grant_table.c Tue Mar 08 14:39:03 2011 +0000 renamed from xen/common/grant_table.c Tue Mar 08 10:23:52 2011 +0000 +1 -7
-    if ( trans_domid != rd->domain_id )
+    if ( td != rd )
    {
-        if ( released_write || released_read )
-        {
-            trans_dom = rcu_lock_domain_by_id(trans_domid);
-            if ( trans_dom != NULL )
-            {
-                /* Recursive calls, but they're tail calls, so

it's

Quoted 3 lines

xen/common/grant_table.c Tue Mar 08 14:39:03 2011 +0000 line 1693

Quoted 3 lines
xen/common/grant_table.c Tue Mar 08 14:39:03 2011 +0000 renamed from xen/common/grant_table.c Tue Mar 08 10:23:52 2011 +0000 +0 -3
-                   okay. */
-                if ( released_write )
-                    __release_grant_for_copy(trans_dom,

trans_gref,

Quoted 3 lines

xen/common/grant_table.c Tue Mar 08 14:39:03 2011 +0000 line 1696

Quoted 3 lines
xen/common/grant_table.c Tue Mar 08 14:39:03 2011 +0000 renamed from xen/common/grant_table.c Tue Mar 08 10:23:52 2011 +0000 +0 -2
 0);
-                else if ( released_read )
-                    __release_grant_for_copy(trans_dom,

trans_gref,

Quoted 27 lines
Quoted 27 lines
xen/common/grant_table.c Tue Mar 08 14:39:03 2011 +0000 renamed from xen/common/grant_table.c Tue Mar 08 10:23:52 2011 +0000 +8 -2
 1);
-            }
-        }
+        /* Recursive calls, but they're tail calls, so it's
+           okay. */
+        if ( released_write )
+            __release_grant_for_copy(td, trans_gref, 0);
+        else if ( released_read )
+            __release_grant_for_copy(td, trans_gref, 1);
+
+       rcu_unlock_domain(td);
    }

}

xen/common/grant_table.c Tue Mar 08 14:39:03 2011 +0000 renamed from xen/common/grant_table.c Tue Mar 08 10:23:52 2011 +0000 +1 -1
@@ -1731,7 +1723,7 @@
    uint32_t old_pin;
    domid_t trans_domid;
    grant_ref_t trans_gref;
-    struct domain *rrd;
+    struct domain *td;
    unsigned long gfn;
    unsigned long grant_frame;
    unsigned trans_page_off;
@@ -1785,8 +1777,8 @@
                               status) ) != GNTST_okay )
             goto unlock_out;
 
Quoted 5 lines

xen/common/grant_table.c Tue Mar 08 14:39:03 2011 +0000 line 1782

Quoted 5 lines
xen/common/grant_table.c Tue Mar 08 14:39:03 2011 +0000 renamed from xen/common/grant_table.c Tue Mar 08 10:23:52 2011 +0000 +2 -2
-        trans_domid = ld->domain_id;
-        trans_gref = 0;
+        td = rd;
+        trans_gref = gref;
        if ( sha2 && (shah->flags & GTF_type_mask) ==

GTF_transitive

Quoted 5 lines

xen/common/grant_table.c Tue Mar 08 14:39:03 2011 +0000 line 1800

Quoted 5 lines
xen/common/grant_table.c Tue Mar 08 14:39:03 2011 +0000 renamed from xen/common/grant_table.c Tue Mar 08 10:23:52 2011 +0000 +0 -0
 )
        {

if ( !allow_transitive )

xen/common/grant_table.c Tue Mar 08 14:39:03 2011 +0000 renamed from xen/common/grant_table.c Tue Mar 08 10:23:52 2011 +0000 +0 -0
@@ -1808,14 +1800,15 @@
               that you don't need to go out of your way to avoid

it

Quoted 5 lines

xen/common/grant_table.c Tue Mar 08 14:39:03 2011 +0000 line 1803

Quoted 5 lines
xen/common/grant_table.c Tue Mar 08 14:39:03 2011 +0000 renamed from xen/common/grant_table.c Tue Mar 08 10:23:52 2011 +0000 +1 -2
               in the guest. */
 
-            rrd = rcu_lock_domain_by_id(trans_domid);
-            if ( rrd == NULL )
+            /* We need to leave the rrd locked during the grant

copy

Quoted 26 lines
Quoted 26 lines
xen/common/grant_table.c Tue Mar 08 14:39:03 2011 +0000 renamed from xen/common/grant_table.c Tue Mar 08 10:23:52 2011 +0000 +4 -1
+ */
+            td = rcu_lock_domain_by_id(trans_domid);
+            if ( td == NULL )
                PIN_FAIL(unlock_out, GNTST_general_error,
                         "transitive grant referenced bad domain
 %d\n",
                         trans_domid);
            spin_unlock(&rd->grant_table->lock);
 
-            rc = __acquire_grant_for_copy(rrd, trans_gref, rd,
+            rc = __acquire_grant_for_copy(td, trans_gref, rd,
                                          readonly, &grant_frame,
                                          &trans_page_off,

&trans_length,

                                          0, &ignore); @@ -1823,6
+1816,7 @@
            spin_lock(&rd->grant_table->lock);
            if ( rc != GNTST_okay ) {
                __fixup_status_for_pin(act, status);
xen/common/grant_table.c Tue Mar 08 14:39:03 2011 +0000 renamed from xen/common/grant_table.c Tue Mar 08 10:23:52 2011 +0000 +1 -0
+               rcu_unlock_domain(td);
                spin_unlock(&rd->grant_table->lock);
                return rc;
            }
@@ -1834,6 +1828,7 @@
            if ( act->pin != old_pin )
            {
Quoted 8 lines
Quoted 8 lines
xen/common/grant_table.c Tue Mar 08 14:39:03 2011 +0000 renamed from xen/common/grant_table.c Tue Mar 08 10:23:52 2011 +0000 +1 -0
                __fixup_status_for_pin(act, status);
+               rcu_unlock_domain(td);
                spin_unlock(&rd->grant_table->lock);
                return __acquire_grant_for_copy(rd, gref, ld,
 readonly,

frame, page_off,
length, @@ -1845,7 +1840,7 @@
sub-page, but we always treat it as one because

that

Quoted 9 lines
Quoted 9 lines

blocks mappings of transitive grants. */
is_sub_page = 1;

xen/common/grant_table.c Tue Mar 08 14:39:03 2011 +0000 renamed from xen/common/grant_table.c Tue Mar 08 10:23:52 2011 +0000 +1 -1
-            *owning_domain = rrd;
+            *owning_domain = td;
            act->gfn = -1ul;
        }
        else if ( sha1 )
@@ -1891,7 +1886,7 @@
            act->is_sub_page = is_sub_page;
Quoted 8 lines
Quoted 8 lines
xen/common/grant_table.c Tue Mar 08 14:39:03 2011 +0000 renamed from xen/common/grant_table.c Tue Mar 08 10:23:52 2011 +0000 +1 -1
            act->start = trans_page_off;
            act->length = trans_length;
-            act->trans_dom = trans_domid;
+            act->trans_domain = td;
            act->trans_gref = trans_gref;
            act->frame = grant_frame;
        }

diff -r f071d8e9f744 -r 14211e98efac

xen/include/xen/grant_table.h

Quoted 7 lines

xen/common/grant_table.c Tue Mar 08 14:39:03 2011 +0000 line 33

Quoted 7 lines

--- a/xen/include/xen/grant_table.h Tue Mar 08 10:23:52 2011
+0000
+++ b/xen/include/xen/grant_table.h Tue Mar 08 14:39:03 2011
+++ +0000

xen/common/grant_table.c Tue Mar 08 14:39:03 2011 +0000 renamed from xen/common/grant_table.c Tue Mar 08 10:23:52 2011 +0000 +0 -0
@@ -32,7 +32,7 @@
 struct active_grant_entry {
    u32           pin;    /* Reference count

information.

Quoted 2 lines

xen/common/grant_table.c Tue Mar 08 14:39:03 2011 +0000 line 35

Quoted 2 lines
xen/common/grant_table.c Tue Mar 08 14:39:03 2011 +0000 renamed from xen/common/grant_table.c Tue Mar 08 10:23:52 2011 +0000 +0 -0
 */
    domid_t       domid;  /* Domain being granted

access.

Quoted 5 lines
Quoted 5 lines
xen/common/grant_table.c Tue Mar 08 14:39:03 2011 +0000 renamed from xen/common/grant_table.c Tue Mar 08 10:23:52 2011 +0000 +1 -1
 */
-    domid_t       trans_dom;
+    struct domain *trans_domain;
    uint32_t      trans_gref;

unsigned long frame; /* Frame being

granted.

Quoted 2 lines
Quoted 2 lines

*/
unsigned long gfn; /* Guest's idea of the frame being

granted.

Quoted 8 lines
Quoted 7 lines

*/

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

Quoted 4 lines

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#8 lore raw
Quoted 10 lines · George Dunlap

As I understood him, Keir was saying he wasn't going to apply it 4.1 -- at least not before the official release. (Perhaps in 4.1.1?)

I don't really understand the logic of having locks which act as noops at all -- I think no matter what, if someone decides to implement RCU, they're in for a boatload of nasty surprises. It seems to me like the current locks will be little more than a hint to whatever future dev does that work that this is an area that they might want to look at. But it seems to me like they'll end up having to write the locks and locking disciplines from scratch anyway.

There is no doubt that it has been a lot easier to fix up a few bugs in the existing no-op RCU read-lock usage than retrofit RCU read locks from scratch, for the waitqueue work.

-- Keir

Quoted 253 lines

-George

Quoted 248 lines · Paul Durrant

I still think this patch should stand. The locking around transitive grants is just borked and if someone actually does implement the rcu locks in future they will get a nasty surprise.

Paul

Quoted 242 lines

-----Original Message-----
From: [email protected] [mailto:xen-devel- [email protected]] On Behalf Of Keir Fraser
Sent: 08 March 2011 15:39
To: George Dunlap; [email protected]
Subject: Re: [Xen-devel] [PATCH] Fix rcu domain locking for transitive grants

Quoted 1 line · George Dunlap

This should be backported to the 4.1 branch; it causes a

hypervisor

Quoted 2 lines

BUG() if guests are using netchannel2 transtiive grants to talk to each other when debug mode is on.

I stubbed out the preemption checking stuff in 4.1 branch (it's not really needed since there are no users of waitqueues in 4.1), so this patch is not required. And that's fortunate, since it's quite non-trivial.

-- Keir

Quoted 7 lines

-George

Quoted 3 lines · George Dunlap

When acquiring a transitive grant for copy then the owning domain needs to be locked down as well as the granting domain. This was being done, but the unlocking was not. The acquire code now

stores

Quoted 1 line
Quoted 1 line

the struct domain * of the owning domain (rather than the domid)

in

Quoted 1 line
Quoted 1 line

the active entry in the granting domain. The release code then

does the unlock on the owning domain.

Quoted 2 lines
Quoted 2 lines

Note that I believe I also fixed a bug where, for non-transitive grants the active entry contained a reference to the acquiring

domain

Quoted 2 lines
Quoted 2 lines

rather than the granting domain. From my reading of the code this would stop the release code for transitive grants from

terminating

Quoted 19 lines
Quoted 19 lines

its recursion correctly.

diff -r f071d8e9f744 -r 14211e98efac xen/common/grant_table.c

xen/common/grant_table.c Tue Mar 08 14:39:03 2011 +0000 renamed from xen/common/grant_table.c Tue Mar 08 10:23:52 2011 +0000 +1 -2
@@ -1626,11 +1626,10 @@
    struct active_grant_entry *act;
    unsigned long r_frame;
    uint16_t *status;
-    domid_t trans_domid;
    grant_ref_t trans_gref;
    int released_read;
    int released_write;
-    struct domain *trans_dom;
+    struct domain *td;
 
Quoted 9 lines

xen/common/grant_table.c Tue Mar 08 14:39:03 2011 +0000 line 1649

Quoted 9 lines
xen/common/grant_table.c Tue Mar 08 14:39:03 2011 +0000 renamed from xen/common/grant_table.c Tue Mar 08 10:23:52 2011 +0000 +0 -3
    released_read = 0;
    released_write = 0;
@@ -1644,15 +1643,13 @@
    if (rd->grant_table->gt_version == 1)
    {
        status = &sha->flags;
-        trans_domid = rd->domain_id;
-        /* Shut the compiler up.  This'll never be used, because
-           trans_domid == rd->domain_id, but gcc doesn't know

that.

Quoted 17 lines
Quoted 17 lines
xen/common/grant_table.c Tue Mar 08 14:39:03 2011 +0000 renamed from xen/common/grant_table.c Tue Mar 08 10:23:52 2011 +0000 +3 -2
 */
-        trans_gref = 0x1234567;
+        td = rd;
+        trans_gref = gref;
    }
    else
    {
        status = &status_entry(rd->grant_table, gref);
-        trans_domid = act->trans_dom;
+        td = act->trans_domain;
        trans_gref = act->trans_gref;
    }
@@ -1680,21 +1677,16 @@
 
    spin_unlock(&rd->grant_table->lock);
 
Quoted 9 lines

xen/common/grant_table.c Tue Mar 08 14:39:03 2011 +0000 line 1690

Quoted 9 lines
xen/common/grant_table.c Tue Mar 08 14:39:03 2011 +0000 renamed from xen/common/grant_table.c Tue Mar 08 10:23:52 2011 +0000 +1 -7
-    if ( trans_domid != rd->domain_id )
+    if ( td != rd )
    {
-        if ( released_write || released_read )
-        {
-            trans_dom = rcu_lock_domain_by_id(trans_domid);
-            if ( trans_dom != NULL )
-            {
-                /* Recursive calls, but they're tail calls, so

it's

Quoted 3 lines

xen/common/grant_table.c Tue Mar 08 14:39:03 2011 +0000 line 1693

Quoted 3 lines
xen/common/grant_table.c Tue Mar 08 14:39:03 2011 +0000 renamed from xen/common/grant_table.c Tue Mar 08 10:23:52 2011 +0000 +0 -3
-                   okay. */
-                if ( released_write )
-                    __release_grant_for_copy(trans_dom,

trans_gref,

Quoted 3 lines

xen/common/grant_table.c Tue Mar 08 14:39:03 2011 +0000 line 1696

Quoted 3 lines
xen/common/grant_table.c Tue Mar 08 14:39:03 2011 +0000 renamed from xen/common/grant_table.c Tue Mar 08 10:23:52 2011 +0000 +0 -2
 0);
-                else if ( released_read )
-                    __release_grant_for_copy(trans_dom,

trans_gref,

Quoted 27 lines
Quoted 27 lines
xen/common/grant_table.c Tue Mar 08 14:39:03 2011 +0000 renamed from xen/common/grant_table.c Tue Mar 08 10:23:52 2011 +0000 +8 -2
 1);
-            }
-        }
+        /* Recursive calls, but they're tail calls, so it's
+           okay. */
+        if ( released_write )
+            __release_grant_for_copy(td, trans_gref, 0);
+        else if ( released_read )
+            __release_grant_for_copy(td, trans_gref, 1);
+
+       rcu_unlock_domain(td);
    }

}

xen/common/grant_table.c Tue Mar 08 14:39:03 2011 +0000 renamed from xen/common/grant_table.c Tue Mar 08 10:23:52 2011 +0000 +1 -1
@@ -1731,7 +1723,7 @@
    uint32_t old_pin;
    domid_t trans_domid;
    grant_ref_t trans_gref;
-    struct domain *rrd;
+    struct domain *td;
    unsigned long gfn;
    unsigned long grant_frame;
    unsigned trans_page_off;
@@ -1785,8 +1777,8 @@
                               status) ) != GNTST_okay )
             goto unlock_out;
 
Quoted 5 lines

xen/common/grant_table.c Tue Mar 08 14:39:03 2011 +0000 line 1782

Quoted 5 lines
xen/common/grant_table.c Tue Mar 08 14:39:03 2011 +0000 renamed from xen/common/grant_table.c Tue Mar 08 10:23:52 2011 +0000 +2 -2
-        trans_domid = ld->domain_id;
-        trans_gref = 0;
+        td = rd;
+        trans_gref = gref;
        if ( sha2 && (shah->flags & GTF_type_mask) ==

GTF_transitive

Quoted 5 lines

xen/common/grant_table.c Tue Mar 08 14:39:03 2011 +0000 line 1800

Quoted 5 lines
xen/common/grant_table.c Tue Mar 08 14:39:03 2011 +0000 renamed from xen/common/grant_table.c Tue Mar 08 10:23:52 2011 +0000 +0 -0
 )
        {

if ( !allow_transitive )

xen/common/grant_table.c Tue Mar 08 14:39:03 2011 +0000 renamed from xen/common/grant_table.c Tue Mar 08 10:23:52 2011 +0000 +0 -0
@@ -1808,14 +1800,15 @@
               that you don't need to go out of your way to avoid

it

Quoted 5 lines

xen/common/grant_table.c Tue Mar 08 14:39:03 2011 +0000 line 1803

Quoted 5 lines
xen/common/grant_table.c Tue Mar 08 14:39:03 2011 +0000 renamed from xen/common/grant_table.c Tue Mar 08 10:23:52 2011 +0000 +1 -2
               in the guest. */
 
-            rrd = rcu_lock_domain_by_id(trans_domid);
-            if ( rrd == NULL )
+            /* We need to leave the rrd locked during the grant

copy

Quoted 26 lines
Quoted 26 lines
xen/common/grant_table.c Tue Mar 08 14:39:03 2011 +0000 renamed from xen/common/grant_table.c Tue Mar 08 10:23:52 2011 +0000 +4 -1
+ */
+            td = rcu_lock_domain_by_id(trans_domid);
+            if ( td == NULL )
                PIN_FAIL(unlock_out, GNTST_general_error,
                         "transitive grant referenced bad domain
 %d\n",
                         trans_domid);
            spin_unlock(&rd->grant_table->lock);
 
-            rc = __acquire_grant_for_copy(rrd, trans_gref, rd,
+            rc = __acquire_grant_for_copy(td, trans_gref, rd,
                                          readonly, &grant_frame,
                                          &trans_page_off,

&trans_length,

                                          0, &ignore); @@ -1823,6
+1816,7 @@
            spin_lock(&rd->grant_table->lock);
            if ( rc != GNTST_okay ) {
                __fixup_status_for_pin(act, status);
xen/common/grant_table.c Tue Mar 08 14:39:03 2011 +0000 renamed from xen/common/grant_table.c Tue Mar 08 10:23:52 2011 +0000 +1 -0
+               rcu_unlock_domain(td);
                spin_unlock(&rd->grant_table->lock);
                return rc;
            }
@@ -1834,6 +1828,7 @@
            if ( act->pin != old_pin )
            {
Quoted 8 lines
Quoted 8 lines
xen/common/grant_table.c Tue Mar 08 14:39:03 2011 +0000 renamed from xen/common/grant_table.c Tue Mar 08 10:23:52 2011 +0000 +1 -0
                __fixup_status_for_pin(act, status);
+               rcu_unlock_domain(td);
                spin_unlock(&rd->grant_table->lock);
                return __acquire_grant_for_copy(rd, gref, ld,
 readonly,

frame, page_off,
length, @@ -1845,7 +1840,7 @@
sub-page, but we always treat it as one because

that

Quoted 9 lines
Quoted 9 lines

blocks mappings of transitive grants. */
is_sub_page = 1;

xen/common/grant_table.c Tue Mar 08 14:39:03 2011 +0000 renamed from xen/common/grant_table.c Tue Mar 08 10:23:52 2011 +0000 +1 -1
-            *owning_domain = rrd;
+            *owning_domain = td;
            act->gfn = -1ul;
        }
        else if ( sha1 )
@@ -1891,7 +1886,7 @@
            act->is_sub_page = is_sub_page;
Quoted 8 lines
Quoted 8 lines
xen/common/grant_table.c Tue Mar 08 14:39:03 2011 +0000 renamed from xen/common/grant_table.c Tue Mar 08 10:23:52 2011 +0000 +1 -1
            act->start = trans_page_off;
            act->length = trans_length;
-            act->trans_dom = trans_domid;
+            act->trans_domain = td;
            act->trans_gref = trans_gref;
            act->frame = grant_frame;
        }

diff -r f071d8e9f744 -r 14211e98efac

xen/include/xen/grant_table.h

Quoted 7 lines

xen/common/grant_table.c Tue Mar 08 14:39:03 2011 +0000 line 33

Quoted 7 lines

--- a/xen/include/xen/grant_table.h Tue Mar 08 10:23:52 2011
+0000
+++ b/xen/include/xen/grant_table.h Tue Mar 08 14:39:03 2011
+++ +0000

xen/common/grant_table.c Tue Mar 08 14:39:03 2011 +0000 renamed from xen/common/grant_table.c Tue Mar 08 10:23:52 2011 +0000 +0 -0
@@ -32,7 +32,7 @@
 struct active_grant_entry {
    u32           pin;    /* Reference count

information.

Quoted 2 lines

xen/common/grant_table.c Tue Mar 08 14:39:03 2011 +0000 line 35

Quoted 2 lines
xen/common/grant_table.c Tue Mar 08 14:39:03 2011 +0000 renamed from xen/common/grant_table.c Tue Mar 08 10:23:52 2011 +0000 +0 -0
 */
    domid_t       domid;  /* Domain being granted

access.

Quoted 5 lines
Quoted 5 lines
xen/common/grant_table.c Tue Mar 08 14:39:03 2011 +0000 renamed from xen/common/grant_table.c Tue Mar 08 10:23:52 2011 +0000 +1 -1
 */
-    domid_t       trans_dom;
+    struct domain *trans_domain;
    uint32_t      trans_gref;

unsigned long frame; /* Frame being

granted.

Quoted 2 lines
Quoted 2 lines

*/
unsigned long gfn; /* Guest's idea of the frame being

granted.

Quoted 8 lines
Quoted 7 lines

*/

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

Quoted 4 lines

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel