aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTim Deegan <tim@xen.org>2012-02-16 15:42:59 +0000
committerTim Deegan <tim@xen.org>2012-02-16 15:42:59 +0000
commitaab3d7142016948afb21e260a89a1c879b0c3ca7 (patch)
tree7d16ce72063ad6b16b1216341638e2c61855d9b1
parent819e844385469bf8933d245fdb63b6e4727bfb09 (diff)
downloadxen-aab3d7142016948afb21e260a89a1c879b0c3ca7.tar.gz
xen-aab3d7142016948afb21e260a89a1c879b0c3ca7.tar.bz2
xen-aab3d7142016948afb21e260a89a1c879b0c3ca7.zip
x86/mm: Make asserts on types and counts of shared pages more accurate
Signed-off-by: Andres Lagar-Cavilla <andres@lagarcavilla.org> Signed-off-by: Tim Deegan <tim@xen.org> Committed-by: Tim Deegan <tim@xen.org>
-rw-r--r--xen/arch/x86/mm/mem_sharing.c4
-rw-r--r--xen/arch/x86/mm/p2m.c8
2 files changed, 9 insertions, 3 deletions
diff --git a/xen/arch/x86/mm/mem_sharing.c b/xen/arch/x86/mm/mem_sharing.c
index 38ef870bf9..36a50e58d4 100644
--- a/xen/arch/x86/mm/mem_sharing.c
+++ b/xen/arch/x86/mm/mem_sharing.c
@@ -201,7 +201,9 @@ static struct page_info* mem_sharing_lookup(unsigned long mfn)
/* Count has to be at least two, because we're called
* with the mfn locked (1) and this is supposed to be
* a shared page (1). */
- ASSERT((page->u.inuse.type_info & PGT_count_mask) >= 2);
+ unsigned long t = read_atomic(&page->u.inuse.type_info);
+ ASSERT((t & PGT_type_mask) == PGT_shared_page);
+ ASSERT((t & PGT_count_mask) >= 2);
ASSERT(get_gpfn_from_mfn(mfn) == SHARED_M2P_ENTRY);
return page;
}
diff --git a/xen/arch/x86/mm/p2m.c b/xen/arch/x86/mm/p2m.c
index 233853b493..fd1ef34a73 100644
--- a/xen/arch/x86/mm/p2m.c
+++ b/xen/arch/x86/mm/p2m.c
@@ -735,6 +735,7 @@ set_shared_p2m_entry(struct domain *d, unsigned long gfn, mfn_t mfn)
p2m_access_t a;
p2m_type_t ot;
mfn_t omfn;
+ unsigned long pg_type;
if ( !paging_mode_translate(p2m->domain) )
return 0;
@@ -745,8 +746,11 @@ set_shared_p2m_entry(struct domain *d, unsigned long gfn, mfn_t mfn)
* sharable first */
ASSERT(p2m_is_shared(ot));
ASSERT(mfn_valid(omfn));
- if ( ((mfn_to_page(omfn)->u.inuse.type_info & PGT_type_mask)
- != PGT_shared_page) )
+ /* Set the m2p entry to invalid only if there are no further type
+ * refs to this page as shared */
+ pg_type = read_atomic(&(mfn_to_page(omfn)->u.inuse.type_info));
+ if ( (pg_type & PGT_count_mask) == 0
+ || (pg_type & PGT_type_mask) != PGT_shared_page )
set_gpfn_from_mfn(mfn_x(omfn), INVALID_M2P_ENTRY);
P2M_DEBUG("set shared %lx %lx\n", gfn, mfn_x(mfn));