From: Roger Pau Monne Date: Mon, 27 Jul 2020 09:13:39 +0000 (+0200) Subject: xen/balloon: fix accounting in alloc_xenballooned_pages error path X-Git-Tag: v5.10.7~1694^2~29 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1951fa33ec259abdf3497bfee7b63e7ddbb1a394;p=platform%2Fkernel%2Flinux-rpi.git xen/balloon: fix accounting in alloc_xenballooned_pages error path 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é Reviewed-by: Juergen Gross Cc: stable@vger.kernel.org Link: https://lore.kernel.org/r/20200727091342.52325-2-roger.pau@citrix.com Signed-off-by: Juergen Gross --- diff --git a/drivers/xen/balloon.c b/drivers/xen/balloon.c index 77c5756..3cb10ed 100644 --- a/drivers/xen/balloon.c +++ b/drivers/xen/balloon.c @@ -630,6 +630,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);