Re: [PATCH v2 0/2] kho: handle failures to reserve preserved memory

From: Chris Down

Date: Wed Dec 02 2026 - 21:58:26 EST


Hi Mike,

Mike Rapoport writes:
>If memblock_reserve() fails we are in a very unhappy place.
>Do you think we really should worry about KHO state when we won't pass
>through mm_core_init() anyway?

I am not an expert in memblock for sure, but as far as I can see the
following can happen reasonably:

1. The memory map is allocated in mm_core_init_early(), so the walk has
its memory already.
2. kho_memory_init() is the last thing before memblock_free_all(), so
nothing between the walk and memblock_free_all() allocates from
memblock.
3. memblock_free_all() may have to grow the reserved array itself, but it
stops restricting allocations to bootmem before it does. Once it has
run, the kernel has plenty to work with, including whatever the walk
failed to reserve.

Or am I missing something?

I've now also managed to hit this without forcing the failure. I
preserved a memfd whose 140000 pages are interleaved with another
file's, so that each page is a range of its own, and used reserve_mem=
to fill most of the next kernel's bootmem. Without the series, that
kernel logs

memblock: Failed to double reserved array from 131072 to 262144 entries !

for each range it can no longer reserve, and then boots to userspace as
usual. Retrieving the memfd there fails with -EIO, with
kho_restore_page() warning that the magic is gone. With the series, it
logs the failure once, drops the handover and boots.

It's still unlikely, since it needs badly fragmented preserved memory
and a bootmem that's close to full, although it will get easier to hit
if we manage to shrink bootmem. But the kernel doesn't die when it
happens. It carries on with preserved memory in the page allocator, so
I think it's worth handling, but please do tell me if there's context
I'm missing here.

Thanks,

Chris