Skip to content

Commit bbe6145

Browse files
roygergregkh
authored andcommitted
xen/balloon: fix accounting in alloc_xenballooned_pages error path
commit 1951fa3 upstream. target_unpopulated is incremented with nr_pages at the start of the function, but the call to free_xenballooned_pages will only subtract pgno number of pages, and thus the rest need to be subtracted before returning or else accounting will be skewed. Signed-off-by: Roger Pau Monné <roger.pau@citrix.com> Reviewed-by: Juergen Gross <jgross@suse.com> Cc: stable@vger.kernel.org Link: https://lore.kernel.org/r/20200727091342.52325-2-roger.pau@citrix.com Signed-off-by: Juergen Gross <jgross@suse.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 8e22f68 commit bbe6145

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

drivers/xen/balloon.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,12 @@ int alloc_xenballooned_pages(int nr_pages, struct page **pages)
632632
out_undo:
633633
mutex_unlock(&balloon_mutex);
634634
free_xenballooned_pages(pgno, pages);
635+
/*
636+
* NB: free_xenballooned_pages will only subtract pgno pages, but since
637+
* target_unpopulated is incremented with nr_pages at the start we need
638+
* to remove the remaining ones also, or accounting will be screwed.
639+
*/
640+
balloon_stats.target_unpopulated -= nr_pages - pgno;
635641
return ret;
636642
}
637643
EXPORT_SYMBOL(alloc_xenballooned_pages);

0 commit comments

Comments
 (0)