Commit e8b3d1a8 authored by Roger Pau Monne's avatar Roger Pau Monne Committed by Kelsey Skunberg

xen/balloon: fix accounting in alloc_xenballooned_pages error path

BugLink: https://bugs.launchpad.net/bugs/1892822

commit 1951fa33 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: default avatarRoger Pau Monné <roger.pau@citrix.com>
Reviewed-by: default avatarJuergen Gross <jgross@suse.com>
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/r/20200727091342.52325-2-roger.pau@citrix.comSigned-off-by: default avatarJuergen Gross <jgross@suse.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarKhalid Elmously <khalid.elmously@canonical.com>
Signed-off-by: default avatarIan May <ian.may@canonical.com>
Signed-off-by: default avatarKelsey Skunberg <kelsey.skunberg@canonical.com>
parent d6cfb9e6
...@@ -683,6 +683,12 @@ int alloc_xenballooned_pages(int nr_pages, struct page **pages) ...@@ -683,6 +683,12 @@ int alloc_xenballooned_pages(int nr_pages, struct page **pages)
out_undo: out_undo:
mutex_unlock(&balloon_mutex); mutex_unlock(&balloon_mutex);
free_xenballooned_pages(pgno, pages); 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; return ret;
} }
EXPORT_SYMBOL(alloc_xenballooned_pages); EXPORT_SYMBOL(alloc_xenballooned_pages);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment