Re: [PATCH v2 2/2] kho: drop the handover if preserved memory can't be reserved
From: Mike Rapoport
Date: Thu Dec 03 2026 - 06:57:15 EST
Hi Chris,
On Tue, Dec 01, 2026 at 10:32:11PM -0800, 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:
Do you mind adding a few words about how unlikely it is? :)
> - 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(-)
--
Sincerely yours,
Mike.