/* 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;
}
p2m_access_t a;
p2m_type_t ot;
mfn_t omfn;
+ unsigned long pg_type;
if ( !paging_mode_translate(p2m->domain) )
return 0;
* 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));