On Fri, Dec 19, 2025 at 3:41 PM Mike Rapoport <[email protected]> wrote:
>
> On Thu, Dec 18, 2025 at 10:08:54PM -0500, Pasha Tatashin wrote:
> > If the previous kernel enabled KHO but did not call kho_finalize()
> > (e.g., CONFIG_LIVEUPDATE=n or userspace skipped the finalization step),
> > the 'preserved-memory-map' property in the FDT remains empty/zero.
> >
> > Previously, kho_populate() would succeed regardless of the memory map's
> > state, reserving the incoming scratch regions in memblock. However,
> > kho_memory_init() would later fail to deserialize the empty map. By that
> > time, the scratch regions were already registered, leading to partial
> > initialization and subsequent list corruption (double-free) during
> > kho_init().
> >
> > Move the validation of the preserved memory map earlier into
> > kho_populate(). If the memory map is empty/NULL:
> > 1. Abort kho_populate() immediately with -ENOENT.
> > 2. Do not register or reserve the incoming scratch memory, allowing the new
> >    kernel to reclaim those pages as standard free memory.
> > 3. Leave the global 'kho_in' state uninitialized.
> >
> > Consequently, kho_memory_init() sees no active KHO context
> > (kho_in.mem_chunks_phys is 0) and falls back to kho_reserve_scratch(),
> > allocating fresh scratch memory as if it were a standard cold boot.
> >
> > Fixes: de51999e687c ("kho: allow memory preservation state updates after 
> > finalization")
> > Reported-by: Ricardo <[email protected]>
>
> I believe Ricardo has a real email ;-)

Oops :-)

>
> > Closes: 
> > https://lore.kernel.org/all/[email protected]
> > Signed-off-by: Pasha Tatashin <[email protected]>
> > ---
> > Changes v2:
> > - Removed phys_to_virt() from kho_populate().
> >
> >  kernel/liveupdate/kexec_handover.c | 39 ++++++++++++++++--------------
> >  1 file changed, 21 insertions(+), 18 deletions(-)
> >
> > diff --git a/kernel/liveupdate/kexec_handover.c 
> > b/kernel/liveupdate/kexec_handover.c
> > index 9dc51fab604f..6ba554208c81 100644
> > --- a/kernel/liveupdate/kexec_handover.c
> > +++ b/kernel/liveupdate/kexec_handover.c
> > @@ -460,27 +460,23 @@ static void __init deserialize_bitmap(unsigned int 
> > order,
> >       }
> >  }
> >
> > -/* Return true if memory was deserizlied */
> > -static bool __init kho_mem_deserialize(const void *fdt)
> > +/* Returns head of preserved physical memory chunks pointer from FDT */
> > +static phys_addr_t __init kho_get_mem_chunks_phys(const void *fdt)
>
> Let's s/mem_chunks/mem_map/ everywhere please.
> And the comment would become
>
> /* Returns physical address of the preserved memory map from FDT */

Sure, I will send version 3 soon.

>
> Other than that
>
> Reviewed-by: Mike Rapoport (Microsoft) <[email protected]>

Thanks,
Pasha

Reply via email to