Currently the function will pointlessly acquire and release the global 'heap_lock' in this case.
NOTE: No caller yet calls domain_adjust_tot_pages() with a zero 'pages' argument, but a subsequent patch will make this possible. Signed-off-by: Paul Durrant <pdurr...@amazon.com> --- Cc: Andrew Cooper <andrew.coop...@citrix.com> Cc: George Dunlap <george.dun...@eu.citrix.com> Cc: Ian Jackson <ian.jack...@eu.citrix.com> Cc: Jan Beulich <jbeul...@suse.com> Cc: Julien Grall <jul...@xen.org> Cc: Konrad Rzeszutek Wilk <konrad.w...@oracle.com> Cc: Stefano Stabellini <sstabell...@kernel.org> Cc: Wei Liu <w...@xen.org> v6: - Modify memory_exchange() v5: - Split out from the subsequent 'make MEMF_no_refcount pages safe to assign' patch as requested by Jan --- xen/common/memory.c | 3 +-- xen/common/page_alloc.c | 3 +++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/xen/common/memory.c b/xen/common/memory.c index c7d2bac452..a4a5374d26 100644 --- a/xen/common/memory.c +++ b/xen/common/memory.c @@ -727,8 +727,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); - drop_dom_ref = (dec_count && - !domain_adjust_tot_pages(d, -dec_count)); + drop_dom_ref = !domain_adjust_tot_pages(d, -dec_count); spin_unlock(&d->page_alloc_lock); if ( drop_dom_ref ) diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c index 919a270587..135e15bae0 100644 --- a/xen/common/page_alloc.c +++ b/xen/common/page_alloc.c @@ -460,6 +460,9 @@ unsigned long domain_adjust_tot_pages(struct domain *d, long pages) { long dom_before, dom_after, dom_claimed, sys_before, sys_after; + if ( !pages ) + goto out; + ASSERT(spin_is_locked(&d->page_alloc_lock)); d->tot_pages += pages; -- 2.20.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel