]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
Partial revert "x86/xen: fix balloon target initialization for PVH dom0"
authorRoger Pau Monne <roger.pau@citrix.com>
Wed, 28 Jan 2026 11:05:08 +0000 (12:05 +0100)
committerJuergen Gross <jgross@suse.com>
Mon, 2 Feb 2026 06:31:22 +0000 (07:31 +0100)
This partially reverts commit 87af633689ce16ddb166c80f32b120e50b1295de so
the current memory target for PV guests is still fetched from
start_info->nr_pages, which matches exactly what the toolstack sets the
initial memory target to.

Using get_num_physpages() is possible on PV also, but needs adjusting to
take into account the ISA hole and the PFN at 0 not considered usable
memory despite being populated, and hence would need extra adjustments.
Instead of carrying those extra adjustments switch back to the previous
code.  That leaves Linux with a difference in how current memory target is
obtained for HVM vs PV, but that's better than adding extra logic just for
PV.

However if switching to start_info->nr_pages for PV domains we need to
differentiate between released pages (freed back to the hypervisor) as
opposed to pages in the physmap which are not populated to start with.
Introduce a new xen_unpopulated_pages to account for papges that have
never been populated, and hence in the PV case don't need subtracting.

Fixes: 87af633689ce ("x86/xen: fix balloon target initialization for PVH dom0")
Reported-by: James Dingwall <james@dingwall.me.uk>
Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Reviewed-by: Juergen Gross <jgross@suse.com>
Signed-off-by: Juergen Gross <jgross@suse.com>
Message-ID: <20260128110510.46425-2-roger.pau@citrix.com>

arch/x86/xen/enlighten.c
drivers/xen/balloon.c
drivers/xen/unpopulated-alloc.c
include/xen/xen.h

index 53282dc7d5ac5be611d0a56f3693c36ca5d2f435..23b91bf9b6630363d78c3abc6e04bdf3c92a91b5 100644 (file)
@@ -470,7 +470,7 @@ int __init arch_xen_unpopulated_init(struct resource **res)
                 * driver to know how much of the physmap is unpopulated and
                 * set an accurate initial memory target.
                 */
-               xen_released_pages += xen_extra_mem[i].n_pfns;
+               xen_unpopulated_pages += xen_extra_mem[i].n_pfns;
                /* Zero so region is not also added to the balloon driver. */
                xen_extra_mem[i].n_pfns = 0;
        }
index 49c3f992639435ce7f75f034c39764e388552e0a..8c44a25a7d2b95f0b2da89a7ec66641798d2a2bc 100644 (file)
@@ -724,6 +724,7 @@ static int __init balloon_add_regions(void)
 static int __init balloon_init(void)
 {
        struct task_struct *task;
+       unsigned long current_pages;
        int rc;
 
        if (!xen_domain())
@@ -731,12 +732,18 @@ static int __init balloon_init(void)
 
        pr_info("Initialising balloon driver\n");
 
-       if (xen_released_pages >= get_num_physpages()) {
-               WARN(1, "Released pages underflow current target");
-               return -ERANGE;
+       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 = get_num_physpages() - xen_released_pages;
+       balloon_stats.current_pages = current_pages;
        balloon_stats.target_pages  = balloon_stats.current_pages;
        balloon_stats.balloon_low   = 0;
        balloon_stats.balloon_high  = 0;
@@ -767,6 +774,10 @@ static int __init balloon_init(void)
        xen_balloon_init();
 
        return 0;
+
+ underflow:
+       WARN(1, "Released pages underflow current target");
+       return -ERANGE;
 }
 subsys_initcall(balloon_init);
 
index d6fc2aefe2646b398a96e5c549a35e49719653c8..1dc0b495c8e5973da126090dd3331f2e6eb026cc 100644 (file)
@@ -18,6 +18,9 @@ static unsigned int list_count;
 
 static struct resource *target_resource;
 
+/* Pages to subtract from the memory count when setting balloon target. */
+unsigned long xen_unpopulated_pages __initdata;
+
 /*
  * If arch is not happy with system "iomem_resource" being used for
  * the region allocation it can provide it's own view by creating specific
index 61854e3f283776b9e323b64b3d8d298330ae32cd..f280c5dcf923694d7ce69dae446649f435284c71 100644 (file)
@@ -69,11 +69,13 @@ extern u64 xen_saved_max_mem_size;
 #endif
 
 #ifdef CONFIG_XEN_UNPOPULATED_ALLOC
+extern unsigned long xen_unpopulated_pages;
 int xen_alloc_unpopulated_pages(unsigned int nr_pages, struct page **pages);
 void xen_free_unpopulated_pages(unsigned int nr_pages, struct page **pages);
 #include <linux/ioport.h>
 int arch_xen_unpopulated_init(struct resource **res);
 #else
+#define xen_unpopulated_pages 0UL
 #include <xen/balloon.h>
 static inline int xen_alloc_unpopulated_pages(unsigned int nr_pages,
                struct page **pages)