Re: [PATCH v2 1/2] kho: skip bootmem setup in kho_init() if bootmem was inherited
From: Pratyush Yadav
Date: Wed Dec 02 2026 - 05:59:09 EST
On Tue, Dec 01 2026, Chris Down wrote:
> On a cold boot, kho_reserve_bootmem() reserves the bootmem areas in
> memblock, and kho_init() later releases them to the page allocator as
> CMA. A kernel that was handed its bootmem areas by the previous kernel
> boots out of them instead. kho_init() must leave them alone.
>
> kho_init() tells the two cases apart by whether there is a handover
> FDT. That doesn't work if kho_mem_retrieve() fails. It clears
> kho_in.fdt_phys so that KHO users don't treat the boot as a KHO boot,
> but the bootmem areas are still the inherited ones. kho_init() would
> then run init_cma_reserved_pageblock() over memory that is in use.
>
> Nothing makes kho_mem_retrieve() fail at the moment, but the next
> patch does. Test kho_in.bootmem_phys instead, which is what
> kho_memory_init() uses to choose between retrieving the handover and
> reserving new bootmem areas.
>
> Signed-off-by: Chris Down <chris@xxxxxxxxxxxxxx>
> ---
> kernel/liveupdate/kho_core.c | 10 ++++++++--
> 1 file changed, 8 insertions(+), 2 deletions(-)
>
> diff --git a/kernel/liveupdate/kho_core.c b/kernel/liveupdate/kho_core.c
> index 15fb892a4412..43ecef317cfd 100644
> --- a/kernel/liveupdate/kho_core.c
> +++ b/kernel/liveupdate/kho_core.c
> @@ -1928,10 +1928,16 @@ static __init int kho_init(void)
> if (err)
> goto err_free_fdt;
>
> - if (fdt) {
> + if (fdt)
> kho_in_debugfs_init(&kho_in.dbg, fdt);
> +
> + /*
> + * We've booted from the inherited bootmem. That means this kernel is
> + * already using it. As such, leave it alone even if the handover is
> + * dropped later.
Nit: I don't understand what "even if handover is dropped later" means.
Doesn't the handover get dropped _before_ kho_init()?
Also, perhaps "even if the handover fails" is better?
> + */
> + if (kho_in.bootmem_phys)
kho_memory_init_early() clears kho_in.bootmem_phys on failure. So this
doesn't work. It clears it because kho_memory_init() uses to check if it
should even try to retrieve preserved memory.
Perhaps it should only clear fdt_phys and kho_memory_init() should check
fdt_phys instead?
> return 0;
> - }
>
> for (int i = 0; i < kho_bootmem_cnt; i++) {
> unsigned long base_pfn = PHYS_PFN(kho_bootmem[i].addr);
--
Regards,
Pratyush Yadav