Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit a6aa4eb

Browse files
roygerjgross1
authored andcommitted
xen/x86: add extra pages to unpopulated-alloc if available
Commit 262fc47 ('xen/balloon: don't use PV mode extra memory for zone device allocations') removed the addition of the extra memory ranges to the unpopulated range allocator, using those only for the balloon driver. This forces the unpopulated allocator to attach hotplug ranges even when spare memory (as part of the extra memory ranges) is available. Furthermore, on PVH domains it defeats the purpose of commit 38620fc ('x86/xen: attempt to inflate the memory balloon on PVH'), as extra memory ranges would only be used to map foreign memory if the kernel is built without XEN_UNPOPULATED_ALLOC support. Fix this by adding a helpers that adds the extra memory ranges to the list of unpopulated pages, and zeroes the ranges so they are not also consumed by the balloon driver. This should have been part of 38620fc, hence the fixes tag. Note the current logic relies on unpopulated_init() (and hence arch_xen_unpopulated_init()) always being called ahead of balloon_init(), so that the extra memory regions are consumed by arch_xen_unpopulated_init(). Fixes: 38620fc ('x86/xen: attempt to inflate the memory balloon on PVH') Signed-off-by: Roger Pau Monné <roger.pau@citrix.com> Reviewed-by: Juergen Gross <jgross@suse.com> Link: https://lore.kernel.org/r/20240429155053.72509-1-roger.pau@citrix.com Signed-off-by: Juergen Gross <jgross@suse.com>
1 parent cdf9df0 commit a6aa4eb

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

arch/x86/xen/enlighten.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,3 +382,36 @@ void __init xen_add_extra_mem(unsigned long start_pfn, unsigned long n_pfns)
382382

383383
memblock_reserve(PFN_PHYS(start_pfn), PFN_PHYS(n_pfns));
384384
}
385+
386+
#ifdef CONFIG_XEN_UNPOPULATED_ALLOC
387+
int __init arch_xen_unpopulated_init(struct resource **res)
388+
{
389+
unsigned int i;
390+
391+
if (!xen_domain())
392+
return -ENODEV;
393+
394+
/* Must be set strictly before calling xen_free_unpopulated_pages(). */
395+
*res = &iomem_resource;
396+
397+
/*
398+
* Initialize with pages from the extra memory regions (see
399+
* arch/x86/xen/setup.c).
400+
*/
401+
for (i = 0; i < XEN_EXTRA_MEM_MAX_REGIONS; i++) {
402+
unsigned int j;
403+
404+
for (j = 0; j < xen_extra_mem[i].n_pfns; j++) {
405+
struct page *pg =
406+
pfn_to_page(xen_extra_mem[i].start_pfn + j);
407+
408+
xen_free_unpopulated_pages(1, &pg);
409+
}
410+
411+
/* Zero so region is not also added to the balloon driver. */
412+
xen_extra_mem[i].n_pfns = 0;
413+
}
414+
415+
return 0;
416+
}
417+
#endif

0 commit comments

Comments
 (0)