Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp2147415ybh; Fri, 24 Jul 2020 05:44:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJywIufK957/GCiIw+ABOwMUu1iWl6IpuWck0CMS+27bNdBk0rVHswW8mPtwaq1g94VjcWoS X-Received: by 2002:a17:906:4b46:: with SMTP id j6mr8657359ejv.403.1595594681209; Fri, 24 Jul 2020 05:44:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595594681; cv=none; d=google.com; s=arc-20160816; b=Q05Qa+2rc66zmK/Y10ezsx5wX/Xu9oXeykVIITCjM3nYBVqcDgrVjbA5Kiqw0BXS88 BPoo8BNpWHM/49tnJr4ueP1dKdEPmsXsytCIsrphamV54Xq9lev/NPx0EKJFtowMFAbm viZMeuQt/a7dSkmxCgo1J00qBm2oXl0q//lMnOd3vQHs59aUL1OnAno9W8BvyGBF8eej CaN4Y9AZUKhNt8Qm1W+aSSb/n4xHfmnKlXj1SiF5ETfoN/P3ZrSBvoik6dDtM8Bl2kfk oXYqcNUdPkD+Ci1yC6ZqlTu4ZK2ZcwDUZNPdUA14Oo1kaCUHakmWv2ACSBNEMRfVyH0g 3Nug== 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=wIv5sdx30C6iQWcYroiJZ3nxA8zBS7gvwKgCRy+Zw0I=; b=iRtsC27hVr/WEralrXrYTzGYXZ+dEc2HQMwj/nsJ9me7D0RHOIJhzGq4Mi9EMw8G/3 EpNLvc725QMNpDPDWM6y42FKOc0Ld1whwKiWTMpSuasY+yPj8pEuy2WHujbJj2oulrWL 1JxNyQ2aqC0XHmj6gJmGDJhflDRosEjPkRf2/DuPSHXDXN1CS3hXdYuOvwr32TTgOffG UwdwdxxF1eBkrlDNmHK35r3MvWhhzjbPYQ0wK7YLx+tfo73qGCy2myRGpfKcTjd1B6+l uB0OVrUE2MS5/mR8pkDZ+J5Gp2/9bXnxDKhnaX3CtL/G0qQo/eaoioBlbKwoMJlQXeYj 3usA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@citrix.com header.s=securemail header.b=deiS7u4X; 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 g12si433202edn.412.2020.07.24.05.44.18; Fri, 24 Jul 2020 05:44:41 -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=deiS7u4X; 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 S1726979AbgGXMmx (ORCPT + 99 others); Fri, 24 Jul 2020 08:42:53 -0400 Received: from esa4.hc3370-68.iphmx.com ([216.71.155.144]:26861 "EHLO esa4.hc3370-68.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726329AbgGXMmx (ORCPT ); Fri, 24 Jul 2020 08:42:53 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1595594572; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=aDtTphrzz9VOwTJvjWtl31/5xlDEnj/EJHimWB6gA4o=; b=deiS7u4XhPpWcyrTBguRa/HFybY2oT+527j9v9hDZYTj5QajGP0eDFIf e1sQ+lNHIXbFlx2ROI87387Q4aePbqj0QV1UOdE2rXSEJC29D3E+/qB+1 GGH+UiStNhEGpK7mKKCNQCvRSRrUc6kDbgbeYrtTshSp8kPd6IczNqZH0 U=; Authentication-Results: esa4.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none IronPort-SDR: KJCsrxedNsP6PXR2GRxBdY4JBtMMaZKb/2iWqx70jsyhvQVs2mJ4a6ODJl6e5Ze0n71njR8l7V 9U+neT0HVYP3POae1Ostbc3PyXtJbBN2r4zxUF0cQs6LBnJFr0VNVu/tNCJc9T1E4naoIb331o PnI7RkHi0XdVA2g0geZOyiF6+NKoWClGj8G1fo1E2jxpTrVvVikRzuiGwbtXCIN56qO7yeEIjv kh6FrSOIHklNuDPUeb45cpzlQ/2JrbYLIt+iJwQswgcnxS7Z13OFRECZhFNlp6l07ZlfxwhxDd Xyk= X-SBRS: 2.7 X-MesageID: 23987140 X-Ironport-Server: esa4.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.75,390,1589256000"; d="scan'208";a="23987140" From: Roger Pau Monne To: CC: Roger Pau Monne , , "Boris Ostrovsky" , Juergen Gross , Stefano Stabellini , Subject: [PATCH v2 1/4] xen/balloon: fix accounting in alloc_xenballooned_pages error path Date: Fri, 24 Jul 2020 14:42:38 +0200 Message-ID: <20200724124241.48208-2-roger.pau@citrix.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200724124241.48208-1-roger.pau@citrix.com> References: <20200724124241.48208-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é 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