aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--xen/arch/x86/mm.c4
-rw-r--r--xen/arch/x86/mm/mem_sharing.c4
-rw-r--r--xen/common/grant_table.c2
-rw-r--r--xen/common/memory.c2
-rw-r--r--xen/common/page_alloc.c10
-rw-r--r--xen/include/xen/mm.h2
6 files changed, 16 insertions, 8 deletions
diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c
index 3657b258cd..c474e587ec 100644
--- a/xen/arch/x86/mm.c
+++ b/xen/arch/x86/mm.c
@@ -3843,7 +3843,7 @@ int donate_page(
{
if ( d->tot_pages >= d->max_pages )
goto fail;
- d->tot_pages++;
+ domain_adjust_tot_pages(d, 1);
}
page->count_info = PGC_allocated | 1;
@@ -3893,7 +3893,7 @@ int steal_page(
} while ( (y = cmpxchg(&page->count_info, x, x | 1)) != x );
/* Unlink from original owner. */
- if ( !(memflags & MEMF_no_refcount) && !--d->tot_pages )
+ if ( !(memflags & MEMF_no_refcount) && !domain_adjust_tot_pages(d, -1) )
drop_dom_ref = 1;
page_list_del(page, &d->page_list);
diff --git a/xen/arch/x86/mm/mem_sharing.c b/xen/arch/x86/mm/mem_sharing.c
index 510328554e..e91aac5cfd 100644
--- a/xen/arch/x86/mm/mem_sharing.c
+++ b/xen/arch/x86/mm/mem_sharing.c
@@ -639,7 +639,7 @@ static int page_make_sharable(struct domain *d,
}
page_set_owner(page, dom_cow);
- d->tot_pages--;
+ domain_adjust_tot_pages(d, -1);
drop_dom_ref = (d->tot_pages == 0);
page_list_del(page, &d->page_list);
spin_unlock(&d->page_alloc_lock);
@@ -680,7 +680,7 @@ static int page_make_private(struct domain *d, struct page_info *page)
ASSERT(page_get_owner(page) == dom_cow);
page_set_owner(page, d);
- if ( d->tot_pages++ == 0 )
+ if ( domain_adjust_tot_pages(d, 1) == 1 )
get_domain(d);
page_list_add_tail(page, &d->page_list);
spin_unlock(&d->page_alloc_lock);
diff --git a/xen/common/grant_table.c b/xen/common/grant_table.c
index e5064f40df..ce66d7598f 100644
--- a/xen/common/grant_table.c
+++ b/xen/common/grant_table.c
@@ -1667,7 +1667,7 @@ gnttab_transfer(
}
/* Okay, add the page to 'e'. */
- if ( unlikely(e->tot_pages++ == 0) )
+ if ( unlikely(domain_adjust_tot_pages(e, 1) == 1) )
get_knownalive_domain(e);
page_list_add_tail(page, &e->page_list);
page_set_owner(page, e);
diff --git a/xen/common/memory.c b/xen/common/memory.c
index c8541c4f9e..c8c1ef2896 100644
--- a/xen/common/memory.c
+++ b/xen/common/memory.c
@@ -465,7 +465,7 @@ static long memory_exchange(XEN_GUEST_HANDLE_PARAM(xen_memory_exchange_t) arg)
(j * (1UL << exch.out.extent_order)));
spin_lock(&d->page_alloc_lock);
- d->tot_pages -= dec_count;
+ domain_adjust_tot_pages(d, -dec_count);
drop_dom_ref = (dec_count && !d->tot_pages);
spin_unlock(&d->page_alloc_lock);
diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c
index 15ebc6656b..e273bb7eff 100644
--- a/xen/common/page_alloc.c
+++ b/xen/common/page_alloc.c
@@ -239,6 +239,12 @@ static long midsize_alloc_zone_pages;
static DEFINE_SPINLOCK(heap_lock);
+unsigned long domain_adjust_tot_pages(struct domain *d, long pages)
+{
+ ASSERT(spin_is_locked(&d->page_alloc_lock));
+ return d->tot_pages += pages;
+}
+
static unsigned long init_node_heap(int node, unsigned long mfn,
unsigned long nr, bool_t *use_tail)
{
@@ -1291,7 +1297,7 @@ int assign_pages(
if ( unlikely(d->tot_pages == 0) )
get_knownalive_domain(d);
- d->tot_pages += 1 << order;
+ domain_adjust_tot_pages(d, 1 << order);
}
for ( i = 0; i < (1 << order); i++ )
@@ -1375,7 +1381,7 @@ void free_domheap_pages(struct page_info *pg, unsigned int order)
page_list_del2(&pg[i], &d->page_list, &d->arch.relmem_list);
}
- d->tot_pages -= 1 << order;
+ domain_adjust_tot_pages(d, -(1 << order));
drop_dom_ref = (d->tot_pages == 0);
spin_unlock_recursive(&d->page_alloc_lock);
diff --git a/xen/include/xen/mm.h b/xen/include/xen/mm.h
index 64a0cc15f2..00b191527f 100644
--- a/xen/include/xen/mm.h
+++ b/xen/include/xen/mm.h
@@ -48,6 +48,8 @@ void free_xenheap_pages(void *v, unsigned int order);
#define alloc_xenheap_page() (alloc_xenheap_pages(0,0))
#define free_xenheap_page(v) (free_xenheap_pages(v,0))
+unsigned long domain_adjust_tot_pages(struct domain *d, long pages);
+
/* Domain suballocator. These functions are *not* interrupt-safe.*/
void init_domheap_pages(paddr_t ps, paddr_t pe);
struct page_info *alloc_domheap_pages(