Skip to content

Commit 7428797

Browse files
roygerjgross1
authored andcommitted
xen/x86: fix initial memory balloon target
When adding extra memory regions as ballooned pages also adjust the balloon target, otherwise when the balloon driver is started it will populate memory to match the target value and consume all the extra memory regions added. This made the usage of the Xen `dom0_mem=,max:` command line parameter for dom0 not work as expected, as the target won't be adjusted and when the balloon is started it will populate memory straight to the 'max:' value. It would equally affect domUs that have memory != maxmem. Kernels built with CONFIG_XEN_UNPOPULATED_ALLOC are not affected, because the extra memory regions are consumed by the unpopulated allocation driver, and then balloon_add_regions() becomes a no-op. Reported-by: John <jw@nuclearfallout.net> Fixes: 87af633 ('x86/xen: fix balloon target initialization for PVH dom0') Signed-off-by: Roger Pau Monné <roger.pau@citrix.com> Reviewed-by: Juergen Gross <jgross@suse.com> Tested-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com> Message-ID: <20250514080427.28129-1-roger.pau@citrix.com> Signed-off-by: Juergen Gross <jgross@suse.com>
1 parent d24c6b7 commit 7428797

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

drivers/xen/balloon.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -704,15 +704,18 @@ static int __init balloon_add_regions(void)
704704

705705
/*
706706
* Extra regions are accounted for in the physmap, but need
707-
* decreasing from current_pages to balloon down the initial
708-
* allocation, because they are already accounted for in
709-
* total_pages.
707+
* decreasing from current_pages and target_pages to balloon
708+
* down the initial allocation, because they are already
709+
* accounted for in total_pages.
710710
*/
711-
if (extra_pfn_end - start_pfn >= balloon_stats.current_pages) {
711+
pages = extra_pfn_end - start_pfn;
712+
if (pages >= balloon_stats.current_pages ||
713+
pages >= balloon_stats.target_pages) {
712714
WARN(1, "Extra pages underflow current target");
713715
return -ERANGE;
714716
}
715-
balloon_stats.current_pages -= extra_pfn_end - start_pfn;
717+
balloon_stats.current_pages -= pages;
718+
balloon_stats.target_pages -= pages;
716719
}
717720

718721
return 0;

0 commit comments

Comments
 (0)