* pages when it is dying.
*/
if ( unlikely(e->is_dying) ||
- unlikely(e->tot_pages >= e->max_pages) )
+ unlikely(e->tot_pages >= e->max_pages) ||
+ unlikely(!(e->tot_pages + 1)) )
{
spin_unlock(&e->page_alloc_lock);
e->domain_id);
else
gdprintk(XENLOG_INFO,
- "Transferee d%d has no headroom (tot %u, max %u)\n",
- e->domain_id, e->tot_pages, e->max_pages);
+ "Transferee %pd has no headroom (tot %u, max %u)\n",
+ e, e->tot_pages, e->max_pages);
gop.status = GNTST_general_error;
goto unlock_and_copyback;
if ( !(memflags & MEMF_no_refcount) )
{
- if ( unlikely((d->tot_pages + (1 << order)) > d->max_pages) )
+ unsigned int nr = 1u << order;
+
+ if ( unlikely(d->tot_pages > d->max_pages) )
+ {
+ gprintk(XENLOG_INFO, "Inconsistent allocation for %pd: %u > %u\n",
+ d, d->tot_pages, d->max_pages);
+ rc = -EPERM;
+ goto out;
+ }
+
+ if ( unlikely(nr > d->max_pages - d->tot_pages) )
{
if ( !tmem_enabled() || order != 0 || d->tot_pages != d->max_pages )
- gprintk(XENLOG_INFO, "Over-allocation for domain %u: "
- "%u > %u\n", d->domain_id,
- d->tot_pages + (1 << order), d->max_pages);
+ gprintk(XENLOG_INFO, "Over-allocation for %pd: %Lu > %u\n",
+ d, d->tot_pages + 0ull + nr, d->max_pages);
rc = -E2BIG;
goto out;
}
- if ( unlikely(domain_adjust_tot_pages(d, 1 << order) == (1 << order)) )
+ if ( unlikely(domain_adjust_tot_pages(d, nr) == nr) )
get_knownalive_domain(d);
}