Making a page sharable removes it from the previous owner's list. Making it
private adds it. These actions are similar to freeing or allocating a page.
Except that they were not minding the domain reference that is taken/dropped
when the first/last page is allocated/freed.
Without fixing this, a domain might remain zombie when destroyed if all its
pages are shared.
Signed-off-by: Andres Lagar-Cavilla <andres@lagarcavilla.org>
Acked-by: Tim Deegan <tim@xen.org>
Committed-by: Tim Deegan <tim@xen.org>
struct page_info *page,
int expected_refcnt)
{
+ int drop_dom_ref;
spin_lock(&d->page_alloc_lock);
/* Change page type and count atomically */
page_set_owner(page, dom_cow);
d->tot_pages--;
+ drop_dom_ref = (d->tot_pages == 0);
page_list_del(page, &d->page_list);
spin_unlock(&d->page_alloc_lock);
+
+ if ( drop_dom_ref )
+ put_domain(d);
return 0;
}
ASSERT(page_get_owner(page) == dom_cow);
page_set_owner(page, d);
- d->tot_pages++;
+ if ( d->tot_pages++ == 0 )
+ get_domain(d);
page_list_add_tail(page, &d->page_list);
spin_unlock(&d->page_alloc_lock);