diff --git a/drivers/xen/balloon.c b/drivers/xen/balloon.c index 05f9f5983ee1..e8976b51c42b 100644 --- a/drivers/xen/balloon.c +++ b/drivers/xen/balloon.c @@ -694,6 +694,12 @@ int alloc_xenballooned_pages(int nr_pages, struct page **pages) out_undo: mutex_unlock(&balloon_mutex); free_xenballooned_pages(pgno, pages); + /* + * NB: free_xenballooned_pages will only subtract pgno pages, but since + * target_unpopulated is incremented with nr_pages at the start we need + * to remove the remaining ones also, or accounting will be screwed. + */ + balloon_stats.target_unpopulated -= nr_pages - pgno; return ret; } EXPORT_SYMBOL(alloc_xenballooned_pages);