[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] x86/xen: fix init of balloon stats for PV guests with memory != maxmem



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é <roger@xxxxxxxxxxxxxx>
---
Cc: Yannick Martin <yannick.martin@xxxxxxxxx>
Cc: "Thorsten Leemhuis" <regressions@xxxxxxxxxxxxx>
---
 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




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.