* [PATCH] xen/x86: add extra pages to unpopulated-alloc if available
@ 2024-04-29 15:50 Roger Pau Monne
2024-05-10 6:35 ` Jürgen Groß
0 siblings, 1 reply; 2+ messages in thread
From: Roger Pau Monne @ 2024-04-29 15:50 UTC (permalink / raw)
To: Juergen Gross, Roger Pau Monne, xen-devel, linux-kernel
Cc: Boris Ostrovsky, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
Dave Hansen, x86, H. Peter Anvin
Commit 262fc47ac174 ('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 38620fc4e893 ('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 38620fc4e893, 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: 38620fc4e893 ('x86/xen: attempt to inflate the memory balloon on PVH')
Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
---
There's a lot of duplication between the unpopulated allocator and the balloon
driver. I feel like the balloon driver should request any extra memory it
needs to the unpopulated allocator, so that the current helpers provided by the
XEN_BALLOON_MEMORY_HOTPLUG option could be replaced with wrappers around the
unpopulated handlers.
However this is much more work than strictly required here, and won't be
suitable for backport IMO. Hence the more contained fix presented in this
patch.
---
arch/x86/xen/enlighten.c | 33 +++++++++++++++++++++++++++++++++
1 file changed, 33 insertions(+)
diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
index a01ca255b0c6..b88722dfc4f8 100644
--- a/arch/x86/xen/enlighten.c
+++ b/arch/x86/xen/enlighten.c
@@ -382,3 +382,36 @@ void __init xen_add_extra_mem(unsigned long start_pfn, unsigned long n_pfns)
memblock_reserve(PFN_PHYS(start_pfn), PFN_PHYS(n_pfns));
}
+
+#ifdef CONFIG_XEN_UNPOPULATED_ALLOC
+int __init arch_xen_unpopulated_init(struct resource **res)
+{
+ unsigned int i;
+
+ if (!xen_domain())
+ return -ENODEV;
+
+ /* Must be set strictly before calling xen_free_unpopulated_pages(). */
+ *res = &iomem_resource;
+
+ /*
+ * Initialize with pages from the extra memory regions (see
+ * arch/x86/xen/setup.c).
+ */
+ for (i = 0; i < XEN_EXTRA_MEM_MAX_REGIONS; i++) {
+ unsigned int j;
+
+ for (j = 0; j < xen_extra_mem[i].n_pfns; j++) {
+ struct page *pg =
+ pfn_to_page(xen_extra_mem[i].start_pfn + j);
+
+ xen_free_unpopulated_pages(1, &pg);
+ }
+
+ /* Zero so region is not also added to the balloon driver. */
+ xen_extra_mem[i].n_pfns = 0;
+ }
+
+ return 0;
+}
+#endif
--
2.44.0
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] xen/x86: add extra pages to unpopulated-alloc if available
2024-04-29 15:50 [PATCH] xen/x86: add extra pages to unpopulated-alloc if available Roger Pau Monne
@ 2024-05-10 6:35 ` Jürgen Groß
0 siblings, 0 replies; 2+ messages in thread
From: Jürgen Groß @ 2024-05-10 6:35 UTC (permalink / raw)
To: Roger Pau Monne, xen-devel, linux-kernel
Cc: Boris Ostrovsky, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
Dave Hansen, x86, H. Peter Anvin
On 29.04.24 17:50, Roger Pau Monne wrote:
> Commit 262fc47ac174 ('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 38620fc4e893 ('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 38620fc4e893, 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: 38620fc4e893 ('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>
Juergen
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-05-10 6:35 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-29 15:50 [PATCH] xen/x86: add extra pages to unpopulated-alloc if available Roger Pau Monne
2024-05-10 6:35 ` Jürgen Groß
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®