From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail.xenproject.org (mail.xenproject.org [104.130.215.37]) (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 C2265442FD3 for ; Thu, 30 Jul 2026 14:36:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=104.130.215.37 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785422171; cv=none; b=M92ZqXdHsqCm/3AgCKivV58renEi0KTtflCypxrn1hYaOwqE/8KNeSfQGP0yq1JqrmjG5/QDMCoWnNtdRIGnvkCXOZwqyrLRosocMQ0GLoihSAWxsfz11fjZrq+zARf3R8HfP1uy+cZvWf3cIR8CedbQhsYpqn9XDJHsaeGv/HU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785422171; c=relaxed/simple; bh=aPOtmE6AFtZlja9ctHVfBQZnBq0KXl2b13kpsG9IU00=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type; b=lq3zLke50IWBhzG8XYUNAsWcQL1+PxGlm7VXLWmErtn8QMFhvUKaeZONviM7CXLRbUbr8NcQaFEn6fAeEScWYe9enyYE4kpEgGo3Kl2btCe4k3Gl/iIMzKzX2OP/MG25HQ+pnjA9zNd9JJuG+UHnulhHKSsSN/DAWb0zY9kutz4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xenproject.org; spf=pass smtp.mailfrom=xenproject.org; dkim=pass (1024-bit key) header.d=xenproject.org header.i=@xenproject.org header.b=6bMq+RwC; arc=none smtp.client-ip=104.130.215.37 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xenproject.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=xenproject.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=xenproject.org header.i=@xenproject.org header.b="6bMq+RwC" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xenproject.org; s=20200302mail; h=Content-Transfer-Encoding:Content-Type: MIME-Version:Message-ID:Date:Subject:Cc:To:From; bh=iBt3Kyqbv5Z8niQb94/bnv7WIopzIJAkOYfQitXwDUA=; b=6bMq+RwCzioKwM9/j3L+CUqTvb 2tBMandGo3nMfI5kirBaoBeRA3pMaFevseyi2Lip1eekTPNZORCDsJQMrpkjI10Wsse+HTG3WzW3J RGGspv0ahsygIeSSsKYgfJDPJcnxBKKYOuMpFN/75+ZizX4MAI3uoKHZXyppteFEFxOY=; Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.96) (envelope-from ) id 1wpRrb-00H74k-1B; Thu, 30 Jul 2026 14:35:59 +0000 Received: from 224.pool85-54-217.dynamic.orange.es ([85.54.217.224] helo=localhost) by xenbits.xenproject.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wpRra-009ZGf-1y; Thu, 30 Jul 2026 14:35:58 +0000 From: Roger Pau Monne To: Juergen Gross , Roger Pau Monne , xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org Cc: Roger Pau Monne , Yannick Martin , "Thorsten Leemhuis" , Stefano Stabellini , Oleksandr Tyshchenko Subject: [PATCH] x86/xen: fix init of balloon stats for PV guests with memory != maxmem Date: Thu, 30 Jul 2026 16:35:47 +0200 Message-ID: <20260730143548.39320-1-roger@xenproject.org> X-Mailer: git-send-email 2.53.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The handling of extra memory regions done in balloon_add_regions() is not correct for PV guests, since the initial target is set to reflect the real memory the system has, not what's described on the memory map, which can be higher if memory != maxmem. Introduce separate logic for PV vs HVM in balloon_add_regions() and handle the extra region correctly by adding them to the total amount of pages, instead of subtracting from the current and target pages amounts. Fixes: 87af633689ce ("x86/xen: fix balloon target initialization for PVH dom0") Signed-off-by: Roger Pau Monné --- Cc: Yannick Martin Cc: "Thorsten Leemhuis" --- drivers/xen/balloon.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/drivers/xen/balloon.c b/drivers/xen/balloon.c index e7f1d4ca6d75..c20a1ff8292d 100644 --- a/drivers/xen/balloon.c +++ b/drivers/xen/balloon.c @@ -703,19 +703,26 @@ static int __init balloon_add_regions(void) balloon_append(pfn_to_page(pfn)); /* - * Extra regions are accounted for in the physmap, but need - * decreasing from current_pages and target_pages to balloon - * down the initial allocation, because they are already - * accounted for in total_pages. + * For HVM domains: extra regions are accounted for in the + * physmap, but need decreasing from current_pages and + * target_pages to balloon down the initial allocation, because + * they are already accounted for in total_pages. + * + * For PV domains: extra regions are not accounted for in the + * initial memory target, and hence need adding to the stats as + * additional unpopulated regions. */ pages = extra_pfn_end - start_pfn; - if (pages >= balloon_stats.current_pages || - pages >= balloon_stats.target_pages) { + if (xen_pv_domain()) { + balloon_stats.total_pages += pages; + } else if (pages >= balloon_stats.current_pages || + pages >= balloon_stats.target_pages) { WARN(1, "Extra pages underflow current target"); return -ERANGE; + } else { + balloon_stats.current_pages -= pages; + balloon_stats.target_pages -= pages; } - balloon_stats.current_pages -= pages; - balloon_stats.target_pages -= pages; } return 0; -- 2.53.0