All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 1/4] x86/mem_sharing: reorder when pages are unlocked and released
@ 2019-04-26 17:21 ` Tamas K Lengyel
  0 siblings, 0 replies; 74+ messages in thread
From: Tamas K Lengyel @ 2019-04-26 17:21 UTC (permalink / raw)
  To: xen-devel
  Cc: Tamas K Lengyel, Wei Liu, George Dunlap, Andrew Cooper,
	Jan Beulich, Roger Pau Monne

Calling _put_page_type while also holding the page_lock
for that page can cause a deadlock.

Signed-off-by: Tamas K Lengyel <tamas@tklengyel.com>
Cc: Jan Beulich <jbeulich@suse.com>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>
Cc: George Dunlap <george.dunlap@eu.citrix.com>
Cc: Wei Liu <wei.liu2@citrix.com>
Cc: Roger Pau Monne <roger.pau@citrix.com>
---
v3: simplified patch by keeping the additional references already in-place
---
 xen/arch/x86/mm/mem_sharing.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/xen/arch/x86/mm/mem_sharing.c b/xen/arch/x86/mm/mem_sharing.c
index dfc279d371..e2f74ac770 100644
--- a/xen/arch/x86/mm/mem_sharing.c
+++ b/xen/arch/x86/mm/mem_sharing.c
@@ -648,10 +648,6 @@ static int page_make_private(struct domain *d, struct page_info *page)
         return -EBUSY;
     }
 
-    /* We can only change the type if count is one */
-    /* Because we are locking pages individually, we need to drop
-     * the lock here, while the page is typed. We cannot risk the 
-     * race of page_unlock and then put_page_type. */
     expected_type = (PGT_shared_page | PGT_validated | PGT_locked | 2);
     if ( page->u.inuse.type_info != expected_type )
     {
@@ -660,12 +656,12 @@ static int page_make_private(struct domain *d, struct page_info *page)
         return -EEXIST;
     }
 
-    /* Drop the final typecount */
-    put_page_and_type(page);
-
     /* Now that we've dropped the type, we can unlock */
     mem_sharing_page_unlock(page);
 
+    /* Drop the final typecount */
+    put_page_and_type(page);
+
     /* Change the owner */
     ASSERT(page_get_owner(page) == dom_cow);
     page_set_owner(page, d);
@@ -900,6 +896,7 @@ static int share_pages(struct domain *sd, gfn_t sgfn, shr_handle_t sh,
     p2m_type_t smfn_type, cmfn_type;
     struct two_gfns tg;
     struct rmap_iterator ri;
+    unsigned long put_count = 0;
 
     get_two_gfns(sd, sgfn, &smfn_type, NULL, &smfn,
                  cd, cgfn, &cmfn_type, NULL, &cmfn, 0, &tg);
@@ -984,7 +981,7 @@ static int share_pages(struct domain *sd, gfn_t sgfn, shr_handle_t sh,
          * Don't change the type of rmap for the client page. */
         rmap_del(gfn, cpage, 0);
         rmap_add(gfn, spage);
-        put_page_and_type(cpage);
+        put_count++;
         d = get_domain_by_id(gfn->domain);
         BUG_ON(!d);
         BUG_ON(set_shared_p2m_entry(d, gfn->gfn, smfn));
@@ -999,6 +996,10 @@ static int share_pages(struct domain *sd, gfn_t sgfn, shr_handle_t sh,
     mem_sharing_page_unlock(secondpg);
     mem_sharing_page_unlock(firstpg);
 
+    BUG_ON(!put_count);
+    while ( put_count-- )
+        put_page_and_type(cpage);
+
     /* Free the client page */
     if(test_and_clear_bit(_PGC_allocated, &cpage->count_info))
         put_page(cpage);
@@ -1167,8 +1168,8 @@ int __mem_sharing_unshare_page(struct domain *d,
     {
         if ( !last_gfn )
             mem_sharing_gfn_destroy(page, d, gfn_info);
-        put_page_and_type(page);
         mem_sharing_page_unlock(page);
+        put_page_and_type(page);
         if ( last_gfn )
         {
             if ( !get_page(page, dom_cow) )
-- 
2.20.1


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply related	[flat|nested] 74+ messages in thread

end of thread, other threads:[~2019-05-02  7:25 UTC | newest]

Thread overview: 74+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-26 17:21 [PATCH v3 1/4] x86/mem_sharing: reorder when pages are unlocked and released Tamas K Lengyel
2019-04-26 17:21 ` [Xen-devel] " Tamas K Lengyel
2019-04-26 17:21 ` [PATCH v3 2/4] x86/mem_sharing: introduce and use page_lock_memshr instead of page_lock Tamas K Lengyel
2019-04-26 17:21   ` [Xen-devel] " Tamas K Lengyel
2019-04-29 15:18   ` Jan Beulich
2019-04-29 15:18     ` [Xen-devel] " Jan Beulich
2019-04-29 16:35     ` Tamas K Lengyel
2019-04-29 16:35       ` [Xen-devel] " Tamas K Lengyel
2019-04-30  7:15       ` Jan Beulich
2019-04-30  7:15         ` [Xen-devel] " Jan Beulich
2019-04-30  8:28         ` Tamas K Lengyel
2019-04-30  8:28           ` [Xen-devel] " Tamas K Lengyel
2019-04-30  8:44           ` Jan Beulich
2019-04-30  8:44             ` [Xen-devel] " Jan Beulich
2019-04-30 14:19             ` Tamas K Lengyel
2019-04-30 14:19               ` [Xen-devel] " Tamas K Lengyel
2019-04-30 14:43             ` George Dunlap
2019-04-30 14:43               ` [Xen-devel] " George Dunlap
2019-04-30 14:46               ` Tamas K Lengyel
2019-04-30 14:46                 ` [Xen-devel] " Tamas K Lengyel
2019-04-30 15:06               ` Jan Beulich
2019-04-30 15:06                 ` [Xen-devel] " Jan Beulich
2019-04-30 16:03                 ` George Dunlap
2019-04-30 16:03                   ` [Xen-devel] " George Dunlap
2019-05-02  7:24                   ` Jan Beulich
2019-05-02  7:24                     ` [Xen-devel] " Jan Beulich
2019-04-29 16:42     ` George Dunlap
2019-04-29 16:42       ` [Xen-devel] " George Dunlap
2019-04-30  7:13       ` Jan Beulich
2019-04-30  7:13         ` [Xen-devel] " Jan Beulich
2019-04-26 17:21 ` [PATCH v3 3/4] x86/mem_sharing: enable mem_share audit mode only in debug builds Tamas K Lengyel
2019-04-26 17:21   ` [Xen-devel] " Tamas K Lengyel
2019-04-29 14:57   ` Jan Beulich
2019-04-29 14:57     ` [Xen-devel] " Jan Beulich
2019-04-29 15:31     ` Tamas K Lengyel
2019-04-29 15:31       ` [Xen-devel] " Tamas K Lengyel
2019-04-26 17:21 ` [PATCH v3 4/4] x86/mem_sharing: compile mem_sharing subsystem only when kconfig is enabled Tamas K Lengyel
2019-04-26 17:21   ` [Xen-devel] " Tamas K Lengyel
2019-04-29 15:32   ` Jan Beulich
2019-04-29 15:32     ` [Xen-devel] " Jan Beulich
2019-04-29 15:49     ` Tamas K Lengyel
2019-04-29 15:49       ` [Xen-devel] " Tamas K Lengyel
2019-04-29 14:32 ` [PATCH v3 1/4] x86/mem_sharing: reorder when pages are unlocked and released George Dunlap
2019-04-29 14:32   ` [Xen-devel] " George Dunlap
2019-04-29 14:46   ` George Dunlap
2019-04-29 14:46     ` [Xen-devel] " George Dunlap
2019-04-29 14:49     ` Andrew Cooper
2019-04-29 14:49       ` [Xen-devel] " Andrew Cooper
2019-04-29 14:54       ` George Dunlap
2019-04-29 14:54         ` [Xen-devel] " George Dunlap
2019-04-29 15:37         ` Tamas K Lengyel
2019-04-29 15:37           ` [Xen-devel] " Tamas K Lengyel
2019-04-29 15:01 ` Jan Beulich
2019-04-29 15:01   ` [Xen-devel] " Jan Beulich
2019-04-29 15:41   ` Tamas K Lengyel
2019-04-29 15:41     ` [Xen-devel] " Tamas K Lengyel
2019-04-29 15:52     ` George Dunlap
2019-04-29 15:52       ` [Xen-devel] " George Dunlap
2019-04-29 16:05       ` Tamas K Lengyel
2019-04-29 16:05         ` [Xen-devel] " Tamas K Lengyel
2019-04-29 16:14         ` Jan Beulich
2019-04-29 16:14           ` [Xen-devel] " Jan Beulich
2019-04-29 16:22           ` George Dunlap
2019-04-29 16:22             ` [Xen-devel] " George Dunlap
2019-04-29 16:26           ` Tamas K Lengyel
2019-04-29 16:26             ` [Xen-devel] " Tamas K Lengyel
2019-04-29 16:29             ` George Dunlap
2019-04-29 16:29               ` [Xen-devel] " George Dunlap
2019-04-29 16:36               ` Tamas K Lengyel
2019-04-29 16:36                 ` [Xen-devel] " Tamas K Lengyel
2019-04-29 15:44 ` George Dunlap
2019-04-29 15:44   ` [Xen-devel] " George Dunlap
2019-04-29 15:58   ` Tamas K Lengyel
2019-04-29 15:58     ` [Xen-devel] " Tamas K Lengyel

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.