From patchwork Thu Aug 20 09:22:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 265721 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C0F7CC433E1 for ; Thu, 20 Aug 2020 10:13:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9257C206DA for ; Thu, 20 Aug 2020 10:13:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597918425; bh=jrA0NLSJYBtPwEl1GYecAenm6raFtFrU0WbZuuDPXxM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=qsH6C8cLRJO+jEsZLNZliK5W8dk20dmixykJ6UyW2Fr3JpPfPmUiwSEXY22UZRtL+ amJUkDUjXXcTNLFwK0NIW/qi/XZVJSX0JohW5KFuAlh6XBx2M9zOl0Mr9mDh3ahIqI gQWWZEDZUSdtYMC81U5eEBbq6clKHpu+cql8HY4s= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731100AbgHTKNo (ORCPT ); Thu, 20 Aug 2020 06:13:44 -0400 Received: from mail.kernel.org ([198.145.29.99]:58760 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726949AbgHTKNm (ORCPT ); Thu, 20 Aug 2020 06:13:42 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 2A6B2206DA; Thu, 20 Aug 2020 10:13:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597918421; bh=jrA0NLSJYBtPwEl1GYecAenm6raFtFrU0WbZuuDPXxM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Sf2+xayv/enYDmBpHQBlJnqAP1B4qIyOO+bNTDX40iuZTAYwrNkpwCwrqh0nm54rI rqarDgJUq/CtwIYZmMWPKdiS+HwLdAh/FiUODvEfyNVejJKbUZxcAbAPufLz9urH+T DC0bYOHbwvoPmWfzkzr7IDyQ9SNnUaj5bhLa8BfI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Juergen Gross Subject: [PATCH 4.14 164/228] xen/balloon: fix accounting in alloc_xenballooned_pages error path Date: Thu, 20 Aug 2020 11:22:19 +0200 Message-Id: <20200820091615.772363228@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200820091607.532711107@linuxfoundation.org> References: <20200820091607.532711107@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Roger Pau Monne commit 1951fa33ec259abdf3497bfee7b63e7ddbb1a394 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é 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 Signed-off-by: Greg Kroah-Hartman --- drivers/xen/balloon.c | 6 ++++++ 1 file changed, 6 insertions(+) --- a/drivers/xen/balloon.c +++ b/drivers/xen/balloon.c @@ -695,6 +695,12 @@ int alloc_xenballooned_pages(int nr_page 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);