Received: by 2002:a25:ca44:0:0:0:0:0 with SMTP id a65csp890387ybg; Mon, 27 Jul 2020 02:19:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwKeOR8C10H2Gs6bU97fNI46fNsMIC9QJwKeE9XPkL0Ej1g70TeQaOK+sGLJlYWZ1qlU08U X-Received: by 2002:a17:906:e2d6:: with SMTP id gr22mr9462443ejb.455.1595841579126; Mon, 27 Jul 2020 02:19:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595841579; cv=none; d=google.com; s=arc-20160816; b=UoGLmXDSpItgN3LwDrZo0A4mJVou2ZKuOgRI8Y1AvIyy6kpxiFpqeEZH+fNY2Rr0GN vzDZLO+SVLPlemzLom8jRbZzLe6i7Z8Q8/2pnqnUwarazO1AO0I2QWDArK+BqhmC26X8 peZ/E6wMZrZKEbgriGBk5JpJ+lQSCWWaBsENfhChQ1cGx/u4sRvJHzKXPNZaIGn3J74B w4AfBmJzceu2Z8Zr8/hJEgdIPK9JVro5eGCtUqzYWrYnto4uIDa6bT8WltGLZb8mvhtX +PkK0Xs6e5N56oEKCnkFSG6Qxsh5JkHrEB9eK2ISIGgEvEEogszqVBlcmxefTrn9pS3c jJgQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :ironport-sdr:dkim-signature; bh=pSJf0HMAsU51Ei8ZX7ck9NwRcKgOmJAMy+Zeka7jPZU=; b=ophqVkI4yJx8THVW0PO+l/QHCWt4MVxs4tWRJ002ed/l6HUAB9yZZpApzoj1774bLu yRZmM/ulTyAJLkCR0yGIWpkstJYrW2ZMc0wC7FQsbTGNdT6N2HVaxVoTtfIz2geGgicI J1TfTYCwu4s85AjC2THJ26YUF85PuqGCl6fMMK8bbb40si85zNO2Htrk4aPkWGWrMmTZ mwApHtej3cM2jR5/I8xYdp32YUBUFGNOfJCKRjhDCXmsWJVBOrze0NVCU7Cas3C0EgDx HXZGpQfS3V/nZSI1RbjwxpuKomQGZMZeNVQT9KU9x21CqV70Qj3Wn7yo/s/oefUO2Vk6 a+JQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@citrix.com header.s=securemail header.b="IfxfXrJ/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=citrix.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m14si415639edb.344.2020.07.27.02.19.17; Mon, 27 Jul 2020 02:19:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=fail header.i=@citrix.com header.s=securemail header.b="IfxfXrJ/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=citrix.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727888AbgG0JPF (ORCPT + 99 others); Mon, 27 Jul 2020 05:15:05 -0400 Received: from esa1.hc3370-68.iphmx.com ([216.71.145.142]:33530 "EHLO esa1.hc3370-68.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726278AbgG0JPF (ORCPT ); Mon, 27 Jul 2020 05:15:05 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1595841304; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=yXg+mOKMXOlPk9hYGg2gJuPP2ADAccszlFJ6TOt/+Ug=; b=IfxfXrJ/joTh9ku3J7FuyT0KyFAAzt4bHsRv/vFVYYBTRqQSPcbmj/IM v4cpmsGTUy+AKQexRzegb1s3RO+XY+BnQ4REx8EQwJsZKZiwvTtc6QgTX 4086FOVZ5PmNZxHJm4z4pidOJ84alp/+YAVPOAUPXKur+cJu/AUNYBt3k A=; Authentication-Results: esa1.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none IronPort-SDR: /lonDtJpry0GWq2IuiXzOVqYuyFYZER9q6g6pJnZVdsuhB60qYm8sw5ir81a6lE5JD3VvhAgnZ uuL5JM5gPHap68Oz7Fo4P5sHe+FH6rqD/766TtL7+nfxGgX5SQLd2SdX4TYFz/FTZ0ajYT3Xbt rB6divUhbolOgbljhK0WH+nMFJ5IRNvSU3I9OV+jZvZifd4q2AgNFuE8TTh/foBPfTGMsl9Jqf 0SJi+bG8Sd9zz8aeie0dIrsLOFQmPTiT1b5E8G3k8quqYAfiezZ6DqObqRbQGcB2zt1RJBuw1b Acc= X-SBRS: 2.7 X-MesageID: 23569857 X-Ironport-Server: esa1.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.75,402,1589256000"; d="scan'208";a="23569857" From: Roger Pau Monne To: CC: Roger Pau Monne , Juergen Gross , , Boris Ostrovsky , Stefano Stabellini , Subject: [PATCH v3 1/4] xen/balloon: fix accounting in alloc_xenballooned_pages error path Date: Mon, 27 Jul 2020 11:13:39 +0200 Message-ID: <20200727091342.52325-2-roger.pau@citrix.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200727091342.52325-1-roger.pau@citrix.com> References: <20200727091342.52325-1-roger.pau@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- Cc: Boris Ostrovsky Cc: Juergen Gross Cc: Stefano Stabellini Cc: xen-devel@lists.xenproject.org --- drivers/xen/balloon.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/xen/balloon.c b/drivers/xen/balloon.c index 77c57568e5d7..3cb10ed32557 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); -- 2.27.0