From: "Marek Marczykowski-Górecki" <marmarek@invisiblethingslab.com>
To: xen-devel <xen-devel@lists.xenproject.org>
Cc: Juergen Gross <jgross@suse.com>,
Boris Ostrovsky <boris.ostrovsky@oracle.com>,
Andrew Morton <akpm@linux-foundation.org>,
David Hildenbrand <david@kernel.org>
Subject: Excluding init_on_free for pages for initial balloon down (Xen)
Date: Sun, 1 Mar 2026 16:04:17 +0100 [thread overview]
Message-ID: <aaRVcVmtv2UBD-GF@mail-itl> (raw)
[-- Attachment #1: Type: text/plain, Size: 3650 bytes --]
Hi,
Some time ago I made a change to disable scrubbing pages that are
ballooned out during system boot. I'll paste the whole commit message as
it's relevant here:
197ecb3802c0 xen/balloon: add runtime control for scrubbing ballooned out pages
Scrubbing pages on initial balloon down can take some time, especially
in nested virtualization case (nested EPT is slow). When HVM/PVH guest is
started with memory= significantly lower than maxmem=, all the extra
pages will be scrubbed before returning to Xen. But since most of them
weren't used at all at that point, Xen needs to populate them first
(from populate-on-demand pool). In nested virt case (Xen inside KVM)
this slows down the guest boot by 15-30s with just 1.5GB needed to be
returned to Xen.
Add runtime parameter to enable/disable it, to allow initially disabling
scrubbing, then enable it back during boot (for example in initramfs).
Such usage relies on assumption that a) most pages ballooned out during
initial boot weren't used at all, and b) even if they were, very few
secrets are in the guest at that time (before any serious userspace
kicks in).
Convert CONFIG_XEN_SCRUB_PAGES to CONFIG_XEN_SCRUB_PAGES_DEFAULT (also
enabled by default), controlling default value for the new runtime
switch.
Now, I face the same issue with init_on_free/init_on_alloc (not sure
which one applies here, probably the latter one), which several
distributions enable by default. The result is (see timestamps):
[2026-02-24 01:12:55] [ 7.485151] xen:balloon: Waiting for initial ballooning down having finished.
[2026-02-24 01:14:14] [ 86.581510] xen:balloon: Initial ballooning down finished.
But here the situation is a bit more complicated:
init_on_free/init_on_alloc applies to any pages, not just those for
balloon driver. I see two approaches to solve the issue:
1. Similar to xen_scrub_pages=, add a runtime switch for
init_on_free/init_on_alloc, then force them off during boot, and
re-enable early in initramfs.
2. Somehow adjust balloon driver to bypass init_on_alloc when ballooning
a page out.
The first approach is likely easier to implement, but also has some
drawbacks: it may result in some kernel structures that are allocated
early to remain with garbage data in uninitialized places. While it may
not matter during early boot, such structures may survive for quite some
time, and maybe attacker can use them later on to exploit some other
bug. This wasn't really a concern with xen_scrub_pages, as those pages
were immediately ballooned out.
The second approach sounds architecturally better, and maybe
init_on_alloc could be always bypassed during balloon out? The balloon
driver can scrub the page on its own already (which is enabled by
default). That of course assumes the issue is only about init_on_alloc,
not init_on_free (or both) - which I haven't really confirmed yet...
If going this way, I see the balloon driver does basically
alloc_page(GFP_BALLOON), where GFP_BALLOON is:
/* When ballooning out (allocating memory to return to Xen) we don't really
want the kernel to try too hard since that can trigger the oom killer. */
#define GFP_BALLOON \
(GFP_HIGHUSER | __GFP_NOWARN | __GFP_NORETRY | __GFP_NOMEMALLOC)
Would that be about adding some new flag here? Or maybe there is already
one for this purpose?
Any opinions?
PS issue tracked at https://github.com/QubesOS/qubes-issues/issues/10723
--
Best Regards,
Marek Marczykowski-Górecki
Invisible Things Lab
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
next reply other threads:[~2026-03-01 15:04 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-01 15:04 Marek Marczykowski-Górecki [this message]
2026-03-02 6:36 ` Excluding init_on_free for pages for initial balloon down (Xen) Jürgen Groß
2026-03-02 8:40 ` David Hildenbrand (Arm)
2026-03-02 11:01 ` Marek Marczykowski-Górecki
2026-03-02 11:05 ` Jan Beulich
2026-03-02 11:11 ` Marek Marczykowski-Górecki
2026-03-02 14:54 ` David Hildenbrand (Arm)
2026-03-02 15:11 ` Marek Marczykowski-Górecki
2026-03-02 15:21 ` Jürgen Groß
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aaRVcVmtv2UBD-GF@mail-itl \
--to=marmarek@invisiblethingslab.com \
--cc=akpm@linux-foundation.org \
--cc=boris.ostrovsky@oracle.com \
--cc=david@kernel.org \
--cc=jgross@suse.com \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.