Re: [PATCH v2 2/2] kho: drop the handover if preserved memory can't be reserved

From: Pratyush Yadav

Date: Wed Dec 02 2026 - 06:14:18 EST


On Tue, Dec 01 2026, Chris Down wrote:

> kho_preserved_memory_reserve() reserves each range of preserved memory
> in memblock and marks it noinit, but ignores both return values. Either
> can fail when memblock has to grow its reserved array and can't find
> room for the new one, which is unlikely but possible. The boot then
> goes on as if the range were reserved, and two things can follow:
>
> - If the reservation failed, memblock_free_all() hands the range to the
> page allocator with the previous kernel's data still in it, while its
> KHO user still expects to restore it. A memfd preserved through LUO
> can then get back pages that belong to someone else. Oh dear!
> - If only the noinit marking failed, the struct pages can be
> initialised later, wiping the KHO magic, so restoring the range fails.
>
> Let's return the error instead. The walk then stops, and
> kho_mem_retrieve() logs the failure and drops the handover. The boot
> carries on without it. Ranges that the walk had already reserved stay
> reserved, since freeing them would need the same array growth that
> just failed. The rest of the preserved memory is released like any
> other free memory.
>
> reserve_mem= revives its regions from the handover before
> mm_core_init(), and relies on the walk to reserve them. They have to
> stay reserved when the handover is dropped, so make
> reserve_mem_kho_revive() reserve its region itself.
>
> Fixes: fc33e4b44b27 ("kexec: enable KHO support for memory preservation")
> Signed-off-by: Chris Down <chris@xxxxxxxxxxxxxx>
> ---
> kernel/liveupdate/kho_core.c | 18 +++++++++++++++---
> mm/memblock.c | 8 ++++++++
> 2 files changed, 23 insertions(+), 3 deletions(-)
>
[...]
> diff --git a/mm/memblock.c b/mm/memblock.c
> index a450092a80fb..7b29b657a348 100644
> --- a/mm/memblock.c
> +++ b/mm/memblock.c
> @@ -2746,6 +2746,14 @@ static bool __init reserve_mem_kho_revive(const char *name, phys_addr_t size,
> return false;
> }
>
> + /* KHO reserves preserved memory, but not if it drops the handover. */

Nit: I find this comment hard to read.

Perhaps:

KHO reserves the preserved memory, but that happens later. Handover
failures can leave it unreserved.

Or something to the tune of this?

Other than this,

Reviewed-by: Pratyush Yadav <pratyush@xxxxxxxxxx>

> + err = memblock_reserve(*p_start, size);
> + if (err) {
> + pr_warn("KHO reserve-mem '%s' could not be reserved: %d\n",
> + name, err);
> + return false;
> + }
> +
> reserved_mem_add(*p_start, size, name);
> pr_info("Revived memory reservation '%s' from KHO\n", name);

--
Regards,
Pratyush Yadav