xen/x86: fix initial memory balloon target
[ Upstream commit 74287971dbb3fe322bb316afd9e7fb5807e23bee ] 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: 87af633689ce ('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> Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
7810600b06
commit
3d6e3849b6
@@ -696,15 +696,18 @@ static int __init balloon_add_regions(void)
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Extra regions are accounted for in the physmap, but need
|
* Extra regions are accounted for in the physmap, but need
|
||||||
* decreasing from current_pages to balloon down the initial
|
* decreasing from current_pages and target_pages to balloon
|
||||||
* allocation, because they are already accounted for in
|
* down the initial allocation, because they are already
|
||||||
* total_pages.
|
* accounted for in total_pages.
|
||||||
*/
|
*/
|
||||||
if (extra_pfn_end - start_pfn >= balloon_stats.current_pages) {
|
pages = extra_pfn_end - start_pfn;
|
||||||
|
if (pages >= balloon_stats.current_pages ||
|
||||||
|
pages >= balloon_stats.target_pages) {
|
||||||
WARN(1, "Extra pages underflow current target");
|
WARN(1, "Extra pages underflow current target");
|
||||||
return -ERANGE;
|
return -ERANGE;
|
||||||
}
|
}
|
||||||
balloon_stats.current_pages -= extra_pfn_end - start_pfn;
|
balloon_stats.current_pages -= pages;
|
||||||
|
balloon_stats.target_pages -= pages;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
Reference in New Issue
Block a user