From: Andres Lagar-Cavilla <andres@lagarcavilla.org>
To: xen-devel@lists.xen.org
Cc: andres@gridcentric.ca, tim@xen.org
Subject: [PATCH 3 of 6] x86/mm/shadow: fix potential p2m/paging deadlock when emulating page table writes
Date: Fri, 13 Apr 2012 12:22:21 -0400 [thread overview]
Message-ID: <964c6cbad92639029f4a.1334334141@xdev.gridcentric.ca> (raw)
In-Reply-To: <patchbomb.1334334138@xdev.gridcentric.ca>
xen/arch/x86/mm/shadow/multi.c | 25 +++++++++++++++++++++++++
1 files changed, 25 insertions(+), 0 deletions(-)
Signed-off-by: Andres Lagar-Cavilla <andres@lagarcavilla.org>
diff -r f8fd4a4239a8 -r 964c6cbad926 xen/arch/x86/mm/shadow/multi.c
--- a/xen/arch/x86/mm/shadow/multi.c
+++ b/xen/arch/x86/mm/shadow/multi.c
@@ -5033,9 +5033,21 @@ sh_x86_emulate_write(struct vcpu *v, uns
if ( (vaddr & (bytes - 1)) && !is_hvm_vcpu(v) )
return X86EMUL_UNHANDLEABLE;
+ /* To prevent a shadow mode deadlock, we need to hold the p2m from here
+ * onwards. emulate_unmap_dest may need to verify the pte that is being
+ * written to here, and thus get_gfn on the gfn contained in the payload
+ * that is being written here. p2m_lock is recursive, so all is well on
+ * that regard. Further, holding the p2m lock ensures the page table gfn
+ * being written to won't go away (although that could be achieved with
+ * a page reference, as done elsewhere).
+ */
+ p2m_lock(p2m_get_hostp2m(v->domain));
addr = emulate_map_dest(v, vaddr, bytes, sh_ctxt);
if ( emulate_map_dest_failed(addr) )
+ {
+ p2m_unlock(p2m_get_hostp2m(v->domain));
return (long)addr;
+ }
paging_lock(v->domain);
memcpy(addr, src, bytes);
@@ -5059,6 +5071,7 @@ sh_x86_emulate_write(struct vcpu *v, uns
emulate_unmap_dest(v, addr, bytes, sh_ctxt);
shadow_audit_tables(v);
paging_unlock(v->domain);
+ p2m_unlock(p2m_get_hostp2m(v->domain));
return X86EMUL_OKAY;
}
@@ -5075,9 +5088,14 @@ sh_x86_emulate_cmpxchg(struct vcpu *v, u
if ( (vaddr & (bytes - 1)) && !is_hvm_vcpu(v) )
return X86EMUL_UNHANDLEABLE;
+ /* see comment in sh_x86_emulate_write. */
+ p2m_lock(p2m_get_hostp2m(v->domain));
addr = emulate_map_dest(v, vaddr, bytes, sh_ctxt);
if ( emulate_map_dest_failed(addr) )
+ {
+ p2m_unlock(p2m_get_hostp2m(v->domain));
return (long)addr;
+ }
paging_lock(v->domain);
switch ( bytes )
@@ -5101,6 +5119,7 @@ sh_x86_emulate_cmpxchg(struct vcpu *v, u
emulate_unmap_dest(v, addr, bytes, sh_ctxt);
shadow_audit_tables(v);
paging_unlock(v->domain);
+ p2m_unlock(p2m_get_hostp2m(v->domain));
return rv;
}
@@ -5119,9 +5138,14 @@ sh_x86_emulate_cmpxchg8b(struct vcpu *v,
if ( (vaddr & 7) && !is_hvm_vcpu(v) )
return X86EMUL_UNHANDLEABLE;
+ /* see comment in sh_x86_emulate_write. */
+ p2m_lock(p2m_get_hostp2m(v->domain));
addr = emulate_map_dest(v, vaddr, 8, sh_ctxt);
if ( emulate_map_dest_failed(addr) )
+ {
+ p2m_unlock(p2m_get_hostp2m(v->domain));
return (long)addr;
+ }
old = (((u64) old_hi) << 32) | (u64) old_lo;
new = (((u64) new_hi) << 32) | (u64) new_lo;
@@ -5135,6 +5159,7 @@ sh_x86_emulate_cmpxchg8b(struct vcpu *v,
emulate_unmap_dest(v, addr, 8, sh_ctxt);
shadow_audit_tables(v);
paging_unlock(v->domain);
+ p2m_unlock(p2m_get_hostp2m(v->domain));
return rv;
}
#endif
next prev parent reply other threads:[~2012-04-13 16:22 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-04-13 16:22 [PATCH 0 of 6] x86/mm/shadow: fixes and synchronized p2m lookups Andres Lagar-Cavilla
2012-04-13 16:22 ` [PATCH 1 of 6] x86/mm: Print stack trace on a an mm-locks deadlock panic Andres Lagar-Cavilla
2012-04-18 15:55 ` Tim Deegan
2012-04-18 15:58 ` Andres Lagar-Cavilla
2012-04-13 16:22 ` [PATCH 2 of 6] x86/mm/shadow: enclose an OOS function in the proper conditional ifdef Andres Lagar-Cavilla
2012-04-14 14:08 ` Gianluca Guida
2012-04-18 15:52 ` Tim Deegan
2012-04-13 16:22 ` Andres Lagar-Cavilla [this message]
2012-04-18 16:13 ` [PATCH 3 of 6] x86/mm/shadow: fix potential p2m/paging deadlock when emulating page table writes Tim Deegan
2012-04-18 16:25 ` Andres Lagar-Cavilla
2012-04-19 14:51 ` Tim Deegan
2012-04-19 15:07 ` Andres Lagar-Cavilla
2012-04-13 16:22 ` [PATCH 4 of 6] x86/mm/shadow: fix p2m/paging deadlock when updating shadow mode Andres Lagar-Cavilla
2012-04-13 16:22 ` [PATCH 5 of 6] x86/mm/shadow: fix p2m/paging deadlock when updating shadow cr3 Andres Lagar-Cavilla
2012-04-13 16:22 ` [PATCH 6 of 6] x86/mm: Locking p2m lookups in shadow mode Andres Lagar-Cavilla
2012-04-18 16:03 ` Tim Deegan
2012-04-13 17:35 ` [PATCH 0 of 6] x86/mm/shadow: fixes and synchronized p2m lookups Tim Deegan
2012-04-13 17:37 ` Andres Lagar-Cavilla
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=964c6cbad92639029f4a.1334334141@xdev.gridcentric.ca \
--to=andres@lagarcavilla.org \
--cc=andres@gridcentric.ca \
--cc=tim@xen.org \
--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).