From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 61B09548549; Wed, 9 Sep 2026 14:35:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788964535; cv=none; b=WLuMFyLy9mv/vaGWgPrE81Qs1jaGfPrYzeLKEvwdxQ8ukxAUcGEnswcaSejjnNgLCo/E728ZOnr07cidL/DxSqU9tOL4cRcU15wsf+n8zQtmFgSLfJsBbDg9EKNNGlEs2LfTAW7AZI0GeWPvI+ql/PUVhKc+xsxBc0bBVzPRbhc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788964535; c=relaxed/simple; bh=rIvLL0szk647jW78qgkDY1DS65HlLO/J1qEK5fxxG8s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=sPnKvdMF9FmqleSF2SFy3MFJhqLpKEK/CUAjAJt+Rq8IsqwRRWyH80SzXHBZrmmP6QXV9RXHBeNN8uVyABsPGKDNgRsVgDORGwE78D0ECNi5wdJLBhkPqAtJVfDZPfoSKfxb4XxUeqa8MJ3JkYf7NDkDAPaYrQD9VOPfA0JoEIM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=cxh8+HNd; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="cxh8+HNd" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BC7611F00A3A; Wed, 9 Sep 2026 14:35:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1788964534; bh=1r2UocrPsBE/y9QH9mWnuWCUdSbA4/MKGmUY6VpA+mA=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=cxh8+HNdHg1Gl6s0eY0OudhPiNuTUyAIQSMzmZkKDB1R6eI0DCkFWeAs2fDkzFyXp 4ml3mEcMYa6UtNtOJHq97R8au41I0qZ0mcMEUK6qdWvy9Kzf+44EFXfbUPpf9+eBkh SvAD2O/YixtLnY6QyYuVbHpY/a8Hu3n610mdkigg= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Juergen Gross , Sasha Levin Subject: [PATCH 6.18 456/583] xen/balloon: improve accuracy of initial balloon target for dom0 Date: Wed, 9 Sep 2026 15:42:21 +0200 Message-ID: <20260909134253.732311363@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260909134237.773280130@linuxfoundation.org> References: <20260909134237.773280130@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Roger Pau Monne [ Upstream commit b13cd24c15d74f6dfcddf0d53ae6efb58d3f0461 ] The dom0 balloon target set by the toolstack is the value returned by XENMEM_current_reservation. Do the same in the kernel balloon driver and set the current allocation to the value returned by XENMEM_current_reservation. On my test system this causes the kernel balloon driver target to exactly match the value set by the toolstack in xenstore. Note this approach can be used by both PV and PVH dom0s, as the toolstack always uses XENMEM_current_reservation to set the initial target regardless of the dom0 type. Signed-off-by: Roger Pau Monné Reviewed-by: Juergen Gross Signed-off-by: Juergen Gross Message-ID: <20260128110510.46425-3-roger.pau@citrix.com> Stable-dep-of: 5d00a11d484e ("x86/xen: fix init of balloon stats again") Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/xen/balloon.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) --- a/drivers/xen/balloon.c +++ b/drivers/xen/balloon.c @@ -724,7 +724,8 @@ static int __init balloon_add_regions(vo static int __init balloon_init(void) { struct task_struct *task; - unsigned long current_pages; + long current_pages = 0; + domid_t domid = DOMID_SELF; int rc; if (!xen_domain()) @@ -732,15 +733,21 @@ static int __init balloon_init(void) pr_info("Initialising balloon driver\n"); - if (xen_pv_domain()) { - if (xen_released_pages >= xen_start_info->nr_pages) - goto underflow; - current_pages = min(xen_start_info->nr_pages - - xen_released_pages, max_pfn); - } else { - if (xen_unpopulated_pages >= get_num_physpages()) - goto underflow; - current_pages = get_num_physpages() - xen_unpopulated_pages; + if (xen_initial_domain()) + current_pages = HYPERVISOR_memory_op(XENMEM_current_reservation, + &domid); + if (current_pages <= 0) { + if (xen_pv_domain()) { + if (xen_released_pages >= xen_start_info->nr_pages) + goto underflow; + current_pages = min(xen_start_info->nr_pages - + xen_released_pages, max_pfn); + } else { + if (xen_unpopulated_pages >= get_num_physpages()) + goto underflow; + current_pages = get_num_physpages() - + xen_unpopulated_pages; + } } balloon_stats.current_pages = current_pages;