From: "Radim Krčmář" <rkrcmar@redhat.com>
To: xen-devel@lists.xen.org
Cc: keir.fraser@citrix.com, kaf24@firebug.cl.cam.ac.uk,
JBeulich@suse.com, "Radim Krčmář" <rkrcmar@redhat.com>
Subject: [PATCH] gnttab: fix page_alloc + grant_table deadlock
Date: Thu, 31 Oct 2013 21:29:16 +0100 [thread overview]
Message-ID: <1383251356-31631-1-git-send-email-rkrcmar@redhat.com> (raw)
AB/BA deaclock between d->page_alloc_lock and d->grant_table->lock
happened in this scenario: (names are original)
gnttab_transfer(): | gnttab_setup_table():
spin_lock(&e->page_alloc_lock); + spin_lock(>->lock);
gnttab_prepare_for_transfer(): | gnttab_grow_table():
| gnttab_create_shared_page():
| share_xen_page_with_guest():
spin_lock(&rgt->lock); + spin_lock(&d->page_alloc_lock);
The patch takes grant_table->lock first in gnttab_transfer() and keeps
it longer, which also saves one unlock()+lock().
Based on analysis from Ulrich Obergfell <uobergfe@redhat.com>.
Signed-off-by: Radim Krčmář <rkrcmar@redhat.com>
---
xen/common/grant_table.c | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)
diff --git a/xen/common/grant_table.c b/xen/common/grant_table.c
index f42bc7a..fa46a8b 100644
--- a/xen/common/grant_table.c
+++ b/xen/common/grant_table.c
@@ -1434,6 +1434,7 @@ gnttab_query_size(
/*
* Check that the given grant reference (rd,ref) allows 'ld' to transfer
* ownership of a page frame. If so, lock down the grant entry.
+ * rd's grant table lock must be held by the caller.
*/
static int
gnttab_prepare_for_transfer(
@@ -1444,8 +1445,6 @@ gnttab_prepare_for_transfer(
union grant_combo scombo, prev_scombo, new_scombo;
int retries = 0;
- spin_lock(&rgt->lock);
-
if ( rgt->gt_version == 0 )
{
gdprintk(XENLOG_INFO,
@@ -1495,11 +1494,9 @@ gnttab_prepare_for_transfer(
scombo = prev_scombo;
}
- spin_unlock(&rgt->lock);
return 1;
fail:
- spin_unlock(&rgt->lock);
return 0;
}
@@ -1617,6 +1614,7 @@ gnttab_transfer(
page = new_page;
}
+ spin_lock(&e->grant_table->lock);
spin_lock(&e->page_alloc_lock);
/*
@@ -1635,6 +1633,7 @@ gnttab_transfer(
"or is dying (%d)\n",
e->tot_pages, e->max_pages, gop.ref, e->is_dying);
spin_unlock(&e->page_alloc_lock);
+ spin_unlock(&e->grant_table->lock);
rcu_unlock_domain(e);
put_gfn(d, gop.mfn);
page->count_info &= ~(PGC_count_mask|PGC_allocated);
@@ -1655,8 +1654,6 @@ gnttab_transfer(
TRACE_1D(TRC_MEM_PAGE_GRANT_TRANSFER, e->domain_id);
/* Tell the guest about its new page frame. */
- spin_lock(&e->grant_table->lock);
-
if ( e->grant_table->gt_version == 1 )
{
grant_entry_v1_t *sha = &shared_entry_v1(e->grant_table, gop.ref);
--
1.8.4.2
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel
next reply other threads:[~2013-10-31 20:29 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-10-31 20:29 Radim Krčmář [this message]
2013-11-05 20:46 ` [PATCH] gnttab: fix page_alloc + grant_table deadlock Matt Wilson
2013-11-06 8:57 ` Jan Beulich
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1383251356-31631-1-git-send-email-rkrcmar@redhat.com \
--to=rkrcmar@redhat.com \
--cc=JBeulich@suse.com \
--cc=kaf24@firebug.cl.cam.ac.uk \
--cc=keir.fraser@citrix.com \
--cc=xen-devel@lists.xen.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).