Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp1159292ybh; Thu, 23 Jul 2020 01:48:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzzbzMUvNl9xkM/GhWFd5wlhkNcT/98POCO7h6Hz+bsaeYj+jt8qOJ5Aje94D6AtbDI9zsp X-Received: by 2002:a17:906:fad4:: with SMTP id lu20mr3249020ejb.1.1595494118340; Thu, 23 Jul 2020 01:48:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595494118; cv=none; d=google.com; s=arc-20160816; b=tsDN5z4AWLc17IU6WAzOEJGOeMagtiGXOSEo6fz6xpWfP5825mny3IyVEsob4WkWKo 6QAwypaKOayQBGVr7Kw5GpI/YvVatF9JSB/ZUfQnUivNK4oDfQC0tjyE8yzEdrejKjr1 5NeRtd2g/JsMNxy/4RqJ1z1sAENaBOys18USaOjwCQsoeAaDMInk0Bgdeiv25yAlf1vf q/walDkAyhH3W3GmbivBhkGUhHzlzLgJ60f4g8uLikSBN8QZTQHVKvybtw7K+D64idfJ Xp7cAYbdbB62VNREmsXJMTngXaQScTmO8NxWEIdVgZ35FG8PfLjoC8Lr/Z9kVVwLsh2p 7p0w== 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=Zmgt/wt/HPLa0b/KQ+hTs0EePzP224uZb/jJtkeIuPZQjWH4eRhT1+eWWvHYtpCg/G JOJUIVGJkgbRk2+VeRLatLxVHQZRmdGLP8tlgMYZpg1mYcvbyKb/qMpBT2LrZrz/aycP u/9WrafX2NJ1QBHUE9kQwAfR+w/qf1lSWbbwydZGnIDO2rA/3HfidVH+fWyPbeQ3jYKB u1qlco5mtdABZlfieWjxZeVZ5psWISM/skc0xoWnuiNyzXmbbsd9ybhycH6rfkBJRzPc 8tsZxCf4D+AfcDo47QoTQpKFOW/VDxI7kJEVMkeRyL8REJUWnTTwsEFreIes3mWN/p/K 3A2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@citrix.com header.s=securemail header.b=b6wZQEGm; 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 l5si1564249ejc.351.2020.07.23.01.48.16; Thu, 23 Jul 2020 01:48:38 -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=b6wZQEGm; 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 S1727854AbgGWIpt (ORCPT + 99 others); Thu, 23 Jul 2020 04:45:49 -0400 Received: from esa5.hc3370-68.iphmx.com ([216.71.155.168]:61712 "EHLO esa5.hc3370-68.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726594AbgGWIpt (ORCPT ); Thu, 23 Jul 2020 04:45:49 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1595493948; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=aDtTphrzz9VOwTJvjWtl31/5xlDEnj/EJHimWB6gA4o=; b=b6wZQEGmZWStkfKyti4GBbz0WWwaFToj3oXH50Dc5Ty2wHGwQGPzS+w3 KC7yI0fp36BEaFMjsOFncsCdyTKFEHla5ezcBiZR2YIf9nmrqUmBwYILq 9+POO+HsJYvudui6q4858IbiXTDWKo6sHazy48WtWaREb4HBBBmnyxNQ8 I=; Authentication-Results: esa5.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none IronPort-SDR: FWgaZAI6RoWQ6RqerM/hehVavtzAH7kBf/6J3Itw9DAyS7asko2A0WA2QUDT8/3hNJsqelSZhx aGmvB+UAcjhoS8QAFOir6owrVHYiklIGssIJbF2bknAmpy3xPWKLguU8S9RRbMH3bf0+cva/3N uWbogJ0Gm1FH42uL71Ft0fG/1RAiD2Rw7MHlwe8wv+Cn7R/dGiTSxubqWMgwlXk5nExHTGmjb4 pCwIbJGW/hdprKdJesLAO/DCcfjT/aOM9VhVGAf07YUdfu+XW0GCx/J8nODk0DNNXrGa4pMW2b 11g= X-SBRS: 2.7 X-MesageID: 23212752 X-Ironport-Server: esa5.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.75,386,1589256000"; d="scan'208";a="23212752" From: Roger Pau Monne To: CC: Roger Pau Monne , , "Boris Ostrovsky" , Juergen Gross , Stefano Stabellini , Subject: [PATCH 1/3] xen/balloon: fix accounting in alloc_xenballooned_pages error path Date: Thu, 23 Jul 2020 10:45:21 +0200 Message-ID: <20200723084523.42109-2-roger.pau@citrix.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200723084523.42109-1-roger.pau@citrix.com> References: <20200723084523.42109-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