[PATCH v2 1/2] kho: skip bootmem setup in kho_init() if bootmem was inherited

From: Chris Down

Date: Wed Dec 02 2026 - 01:32:16 EST


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.
+ */
+ if (kho_in.bootmem_phys)
return 0;
- }

for (int i = 0; i < kho_bootmem_cnt; i++) {
unsigned long base_pfn = PHYS_PFN(kho_bootmem[i].addr);
--
2.56.1