[PATCH v3 1/3] kho: don't use is_kho_boot() to check for inherited bootmem
From: Chris Down
Date: Sat Dec 05 2026 - 23:15:22 EST
On a KHO boot, kho_init() adds the inherited bootmem areas to the CMA
counters, as nothing else counts them. If kho_init() fails, its error
path frees the bootmem areas that kho_reserve_bootmem() reserved, but
leaves inherited ones alone, as the kernel is running out of them.
Both check is_kho_boot() to tell the two cases apart. That doesn't
work if the handover fails. is_kho_boot() is then false, but the
bootmem areas are still the inherited ones. kho_init() would leave
them out of the CMA counters, and its error path would free them with
free_reserved_area() while they are in use.
Nothing makes that happen at the moment, but the patch after next
does. Test kho_in.bootmem_phys in both places instead. For now the two
tests always give the same answer, so this doesn't change behaviour on
its own.
That later patch is only safe with this one applied, so this has the
same Fixes: tag to make sure that a backport doesn't go out without it.
Fixes: fc33e4b44b27 ("kexec: enable KHO support for memory preservation")
Signed-off-by: Chris Down <chris@xxxxxxxxxxxxxx>
---
kernel/liveupdate/kho_core.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/kernel/liveupdate/kho_core.c b/kernel/liveupdate/kho_core.c
index 15fb892a4412..342099d4dea2 100644
--- a/kernel/liveupdate/kho_core.c
+++ b/kernel/liveupdate/kho_core.c
@@ -1901,7 +1901,7 @@ static __init int kho_init(void)
const void *fdt = kho_get_fdt();
int err = 0;
- if (is_kho_boot())
+ if (kho_in.bootmem_phys)
kho_account_incoming_bootmem();
if (!kho_enable)
@@ -1965,7 +1965,7 @@ err_free_kho_radix_tree:
kho_radix_destroy_tree(tree);
err_free_bootmem:
kho_out.fdt = NULL;
- if (!is_kho_boot()) {
+ if (!kho_in.bootmem_phys) {
for (int i = 0; i < kho_bootmem_cnt; i++) {
void *start = __va(kho_bootmem[i].addr);
void *end = start + kho_bootmem[i].size;
--
2.56.1