* [PATCH v2 0/2] kho: handle failures to reserve preserved memory
@ 2026-12-02 6:32 Chris Down
2026-12-02 6:32 ` [PATCH v2 1/2] kho: skip bootmem setup in kho_init() if bootmem was inherited Chris Down
` (2 more replies)
0 siblings, 3 replies; 11+ messages in thread
From: Chris Down @ 2026-12-02 6:32 UTC (permalink / raw)
To: rppt, pasha.tatashin, pratyush
Cc: graf, kexec, linux-mm, linux-kernel, kernel-team
When a kernel boots with a handover, kho_preserved_memory_reserve()
reserves each range of preserved memory in memblock, but it ignores
failures. If one happens, memory that a KHO user still expects to
restore can be released to the page allocator. This needs memblock to
fail to grow its reserved array, so it's unlikely. But if it does
happen, the result is bad enough to be worth handling.
Patch 2 makes the walk stop on such a failure, so that
kho_mem_retrieve() drops the handover and the boot carries on without
it. For that to be safe, reserve_mem_kho_revive() now reserves its own
region, and patch 1 stops kho_init() from releasing inherited bootmem
areas after a failed retrieval.
From a quick check I did with one of the reservations forced to fail,
the kernel logs the failure and boots without the handover. The
reserve_mem region stays reserved, and a later KHO kexec out of that
kernel works.
v2:
- Drop the handover and carry on instead of panicking, with
reserve_mem_kho_revive() reserving its own region (Mike)
- Stop kho_init() from releasing inherited bootmem areas after a failed
retrieval, as a separate patch (Mike)
v1: https://lore.kernel.org/r/avQUquBK6cO6tUUI@chrisdown.name
Chris Down (2):
kho: skip bootmem setup in kho_init() if bootmem was inherited
kho: drop the handover if preserved memory can't be reserved
kernel/liveupdate/kho_core.c | 28 +++++++++++++++++++++++-----
mm/memblock.c | 8 ++++++++
2 files changed, 31 insertions(+), 5 deletions(-)
base-commit: ec459d99ed222228b3d601818fd1e24822a450d6
--
2.56.1
^ permalink raw reply [flat|nested] 11+ messages in thread* [PATCH v2 1/2] kho: skip bootmem setup in kho_init() if bootmem was inherited 2026-12-02 6:32 [PATCH v2 0/2] kho: handle failures to reserve preserved memory Chris Down @ 2026-12-02 6:32 ` Chris Down 2026-12-02 10:59 ` Pratyush Yadav 2026-12-03 6:32 ` sashiko-bot 2026-12-02 6:32 ` [PATCH v2 2/2] kho: drop the handover if preserved memory can't be reserved Chris Down 2026-12-02 11:24 ` [PATCH v2 0/2] kho: handle failures to reserve preserved memory Mike Rapoport 2 siblings, 2 replies; 11+ messages in thread From: Chris Down @ 2026-12-02 6:32 UTC (permalink / raw) To: rppt, pasha.tatashin, pratyush Cc: graf, kexec, linux-mm, linux-kernel, kernel-team 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@chrisdown.name> --- 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 ^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH v2 1/2] kho: skip bootmem setup in kho_init() if bootmem was inherited 2026-12-02 6:32 ` [PATCH v2 1/2] kho: skip bootmem setup in kho_init() if bootmem was inherited Chris Down @ 2026-12-02 10:59 ` Pratyush Yadav 2026-12-03 2:58 ` Chris Down 2026-12-03 6:32 ` sashiko-bot 1 sibling, 1 reply; 11+ messages in thread From: Pratyush Yadav @ 2026-12-02 10:59 UTC (permalink / raw) To: Chris Down Cc: rppt, pasha.tatashin, pratyush, graf, kexec, linux-mm, linux-kernel, kernel-team 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@chrisdown.name> > --- > 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 ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v2 1/2] kho: skip bootmem setup in kho_init() if bootmem was inherited 2026-12-02 10:59 ` Pratyush Yadav @ 2026-12-03 2:58 ` Chris Down 0 siblings, 0 replies; 11+ messages in thread From: Chris Down @ 2026-12-03 2:58 UTC (permalink / raw) To: Pratyush Yadav Cc: rppt, pasha.tatashin, graf, kexec, linux-mm, linux-kernel, kernel-team Hi Pratyush, Pratyush Yadav writes: >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? Yeah, it does, so "later" is wrong there. I'll change it to "even if the handover failed" in v3. >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? Good catch, thanks. I'll do that in v3. kho_memory_init() will also have to skip kho_reserve_bootmem() in that case, otherwise it reserves new areas that kho_init() then never releases. While looking at that I noticed that kho_account_incoming_bootmem() and kho_init()'s error path still check is_kho_boot() as well, so v3 will switch those over too. Thanks! Chris ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v2 1/2] kho: skip bootmem setup in kho_init() if bootmem was inherited 2026-12-02 6:32 ` [PATCH v2 1/2] kho: skip bootmem setup in kho_init() if bootmem was inherited Chris Down 2026-12-02 10:59 ` Pratyush Yadav @ 2026-12-03 6:32 ` sashiko-bot 1 sibling, 0 replies; 11+ messages in thread From: sashiko-bot @ 2026-12-03 6:32 UTC (permalink / raw) To: Chris Down, rppt, pasha.tatashin, pratyush Cc: graf, kexec, linux-mm, kernel-team Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Medium] kho: err_free_bootmem in kho_init() frees active inherited bootmem - [Medium] kho: kho_init() skips CMA accounting when kho_mem_retrieve() fails -- commit 8ab45df6c0cc32b7be0a781a67fbb61c13c0156f Author: Chris Down <chris@chrisdown.name> kho: skip bootmem setup in kho_init() if bootmem was inherited This commit changes kho_init() to check kho_in.bootmem_phys instead of fdt when deciding whether to skip releasing bootmem areas to CMA, so inherited bootmem is left alone even if kho_mem_retrieve() fails and clears kho_in.fdt_phys. > diff --git a/kernel/liveupdate/kho_core.c b/kernel/liveupdate/kho_core.c > index 15fb892a4412d..43ecef317cfdf 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); [Severity: Medium] Should the err_free_bootmem unwind path in kho_init() also check !kho_in.bootmem_phys instead of !is_kho_boot()? kernel/liveupdate/kho_core.c:kho_init() { ... err_free_bootmem: kho_out.fdt = NULL; if (!is_kho_boot()) { for (int i = 0; i < kho_bootmem_cnt; i++) { void *start = __va(kho_bootmem[i].addr); void *end = start + kho_bootmem[i].size; free_reserved_area(start, end, -1, ""); } } ... } Because is_kho_boot() checks kho_in.fdt_phys, if kho_mem_retrieve() fails and clears kho_in.fdt_phys, a subsequent failure in kho_init() will take this branch and call free_reserved_area() on the inherited kho_bootmem regions that the kernel booted out of and already released to the buddy allocator. [Severity: Medium] Should the call to kho_account_incoming_bootmem() at the start of kho_init() also test kho_in.bootmem_phys rather than is_kho_boot()? kernel/liveupdate/kho_core.c:kho_init() { ... if (is_kho_boot()) kho_account_incoming_bootmem(); ... } Before kho_mem_retrieve() runs, free_area_init() marks the inherited kho_bootmem pageblocks as MIGRATE_CMA, and memblock_free_all() releases their free pages into the MIGRATE_CMA buddy lists. When kho_mem_retrieve() fails and clears kho_in.fdt_phys, gating kho_account_incoming_bootmem() on is_kho_boot() while returning early on kho_in.bootmem_phys leaves those pageblocks unaccounted in zone->cma_pages and totalcma_pages, causing CmaFree to exceed CmaTotal in /proc/meminfo. -- Sashiko AI review · https://sashiko.dev/#/patchset/cover.1796126791.git.chris@chrisdown.name?part=1 ^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH v2 2/2] kho: drop the handover if preserved memory can't be reserved 2026-12-02 6:32 [PATCH v2 0/2] kho: handle failures to reserve preserved memory Chris Down 2026-12-02 6:32 ` [PATCH v2 1/2] kho: skip bootmem setup in kho_init() if bootmem was inherited Chris Down @ 2026-12-02 6:32 ` Chris Down 2026-12-02 11:14 ` Pratyush Yadav 2026-12-03 6:32 ` sashiko-bot 2026-12-02 11:24 ` [PATCH v2 0/2] kho: handle failures to reserve preserved memory Mike Rapoport 2 siblings, 2 replies; 11+ messages in thread From: Chris Down @ 2026-12-02 6:32 UTC (permalink / raw) To: rppt, pasha.tatashin, pratyush Cc: graf, kexec, linux-mm, linux-kernel, kernel-team 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: - 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@chrisdown.name> --- kernel/liveupdate/kho_core.c | 18 +++++++++++++++--- mm/memblock.c | 8 ++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/kernel/liveupdate/kho_core.c b/kernel/liveupdate/kho_core.c index 43ecef317cfd..a0429e85132b 100644 --- a/kernel/liveupdate/kho_core.c +++ b/kernel/liveupdate/kho_core.c @@ -623,6 +623,7 @@ static int __init kho_preserved_memory_reserve(unsigned long key, void *data) unsigned int order; phys_addr_t phys; u64 sz; + int err; phys = kho_decode_radix_key(key, &order); @@ -630,8 +631,14 @@ static int __init kho_preserved_memory_reserve(unsigned long key, void *data) page = kho_get_preserved_page(phys, order); /* Reserve the memory preserved in KHO in memblock */ - memblock_reserve(phys, sz); - memblock_reserved_mark_noinit(phys, sz); + err = memblock_reserve(phys, sz); + if (err) + return err; + + err = memblock_reserved_mark_noinit(phys, sz); + if (err) + return err; + info.magic = KHO_PAGE_MAGIC; info.order = order; page->private = info.page_private; @@ -1731,13 +1738,18 @@ static void __init kho_mem_retrieve(void) const struct kho_radix_walk_cb cb = { .leaf = kho_preserved_memory_reserve, }; + int err; - if (kho_radix_walk_tree(&kho_in.radix_tree, &cb, NULL)) + err = kho_radix_walk_tree(&kho_in.radix_tree, &cb, NULL); + if (err) goto err; return; err: + pr_warn("failed to reserve preserved memory: %pe, disabling KHO revival\n", + ERR_PTR(err)); + /* * Failed to initialize preserved memory. Clear FDT and radix so KHO * users don't treat it as a KHO boot. diff --git a/mm/memblock.c b/mm/memblock.c index a450092a80fb..7b29b657a348 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -2746,6 +2746,14 @@ static bool __init reserve_mem_kho_revive(const char *name, phys_addr_t size, return false; } + /* KHO reserves preserved memory, but not if it drops the handover. */ + err = memblock_reserve(*p_start, size); + if (err) { + pr_warn("KHO reserve-mem '%s' could not be reserved: %d\n", + name, err); + return false; + } + reserved_mem_add(*p_start, size, name); pr_info("Revived memory reservation '%s' from KHO\n", name); -- 2.56.1 ^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH v2 2/2] kho: drop the handover if preserved memory can't be reserved 2026-12-02 6:32 ` [PATCH v2 2/2] kho: drop the handover if preserved memory can't be reserved Chris Down @ 2026-12-02 11:14 ` Pratyush Yadav 2026-12-03 2:58 ` Chris Down 2026-12-03 6:32 ` sashiko-bot 1 sibling, 1 reply; 11+ messages in thread From: Pratyush Yadav @ 2026-12-02 11:14 UTC (permalink / raw) To: Chris Down Cc: rppt, pasha.tatashin, pratyush, graf, kexec, linux-mm, linux-kernel, kernel-team On Tue, Dec 01 2026, 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: > > - 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@chrisdown.name> > --- > kernel/liveupdate/kho_core.c | 18 +++++++++++++++--- > mm/memblock.c | 8 ++++++++ > 2 files changed, 23 insertions(+), 3 deletions(-) > [...] > diff --git a/mm/memblock.c b/mm/memblock.c > index a450092a80fb..7b29b657a348 100644 > --- a/mm/memblock.c > +++ b/mm/memblock.c > @@ -2746,6 +2746,14 @@ static bool __init reserve_mem_kho_revive(const char *name, phys_addr_t size, > return false; > } > > + /* KHO reserves preserved memory, but not if it drops the handover. */ Nit: I find this comment hard to read. Perhaps: KHO reserves the preserved memory, but that happens later. Handover failures can leave it unreserved. Or something to the tune of this? Other than this, Reviewed-by: Pratyush Yadav <pratyush@kernel.org> > + err = memblock_reserve(*p_start, size); > + if (err) { > + pr_warn("KHO reserve-mem '%s' could not be reserved: %d\n", > + name, err); > + return false; > + } > + > reserved_mem_add(*p_start, size, name); > pr_info("Revived memory reservation '%s' from KHO\n", name); -- Regards, Pratyush Yadav ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v2 2/2] kho: drop the handover if preserved memory can't be reserved 2026-12-02 11:14 ` Pratyush Yadav @ 2026-12-03 2:58 ` Chris Down 0 siblings, 0 replies; 11+ messages in thread From: Chris Down @ 2026-12-03 2:58 UTC (permalink / raw) To: Pratyush Yadav Cc: rppt, pasha.tatashin, graf, kexec, linux-mm, linux-kernel, kernel-team Hi Pratyush, Pratyush Yadav writes: >Perhaps: > > KHO reserves the preserved memory, but that happens later. Handover > failures can leave it unreserved. That's clearer, I'll use it in v3. Thanks for the review! Chris ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v2 2/2] kho: drop the handover if preserved memory can't be reserved 2026-12-02 6:32 ` [PATCH v2 2/2] kho: drop the handover if preserved memory can't be reserved Chris Down 2026-12-02 11:14 ` Pratyush Yadav @ 2026-12-03 6:32 ` sashiko-bot 1 sibling, 0 replies; 11+ messages in thread From: sashiko-bot @ 2026-12-03 6:32 UTC (permalink / raw) To: Chris Down, rppt, pasha.tatashin, pratyush Cc: graf, kexec, linux-mm, kernel-team Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [High] kho: kho_init() uses is_kho_boot() instead of kho_in.bootmem_phys -- commit 43513d95ccfc673fefadf352275abd473f3def20 Author: Chris Down <chris@chrisdown.name> kho: drop the handover if preserved memory can't be reserved This commit checks the return values of memblock_reserve() and memblock_reserved_mark_noinit() in kho_preserved_memory_reserve(), drops the KHO handover in kho_mem_retrieve() if either fails, and makes reserve_mem_kho_revive() reserve its own region in memblock. > diff --git a/kernel/liveupdate/kho_core.c b/kernel/liveupdate/kho_core.c > index 43ecef317cfdf..a0429e85132bc 100644 > --- a/kernel/liveupdate/kho_core.c > +++ b/kernel/liveupdate/kho_core.c [ ... ] > @@ -1731,13 +1738,18 @@ static void __init kho_mem_retrieve(void) > const struct kho_radix_walk_cb cb = { > .leaf = kho_preserved_memory_reserve, > }; > + int err; > > - if (kho_radix_walk_tree(&kho_in.radix_tree, &cb, NULL)) > + err = kho_radix_walk_tree(&kho_in.radix_tree, &cb, NULL); > + if (err) > goto err; > > return; > > err: > + pr_warn("failed to reserve preserved memory: %pe, disabling KHO revival\n", > + ERR_PTR(err)); > + > /* > * Failed to initialize preserved memory. Clear FDT and radix so KHO > * users don't treat it as a KHO boot. [Severity: High] When kho_mem_retrieve() drops the handover by clearing kho_in.fdt_phys while leaving kho_in.bootmem_phys set, is_kho_boot() becomes false even though the kernel is running out of inherited bootmem. Does that cause kho_init() to mishandle kho_bootmem in two places that still check is_kho_boot() instead of kho_in.bootmem_phys? kernel/liveupdate/kho_core.c:kho_init() { if (is_kho_boot()) kho_account_incoming_bootmem(); ... if (kho_in.bootmem_phys) return 0; ... err_free_bootmem: kho_out.fdt = NULL; if (!is_kho_boot()) { for (int i = 0; i < kho_bootmem_cnt; i++) { void *start = __va(kho_bootmem[i].addr); void *end = start + kho_bootmem[i].size; free_reserved_area(start, end, -1, ""); } } } First, if kho_init() fails and jumps to err_free_bootmem after the handover was dropped, !is_kho_boot() is true and free_reserved_area() is called on the inherited kho_bootmem ranges, which are actively in use by the running kernel and already released to the buddy allocator by memblock_free_all(). Second, on the normal path, kho_init() skips kho_account_incoming_bootmem() because is_kho_boot() is false and then returns early at if (kho_in.bootmem_phys), leaving zone->cma_pages and totalcma_pages uncounted for the inherited MIGRATE_CMA bootmem pageblocks. Checking kho_in.bootmem_phys in both places would match the early return in kho_init(). -- Sashiko AI review · https://sashiko.dev/#/patchset/cover.1796126791.git.chris@chrisdown.name?part=2 ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v2 0/2] kho: handle failures to reserve preserved memory 2026-12-02 6:32 [PATCH v2 0/2] kho: handle failures to reserve preserved memory Chris Down 2026-12-02 6:32 ` [PATCH v2 1/2] kho: skip bootmem setup in kho_init() if bootmem was inherited Chris Down 2026-12-02 6:32 ` [PATCH v2 2/2] kho: drop the handover if preserved memory can't be reserved Chris Down @ 2026-12-02 11:24 ` Mike Rapoport 2026-12-03 2:58 ` Chris Down 2 siblings, 1 reply; 11+ messages in thread From: Mike Rapoport @ 2026-12-02 11:24 UTC (permalink / raw) To: Chris Down Cc: pasha.tatashin, pratyush, graf, kexec, linux-mm, linux-kernel, kernel-team On Tue, Dec 01, 2026 at 10:32:07PM -0800, Chris Down wrote: > When a kernel boots with a handover, kho_preserved_memory_reserve() > reserves each range of preserved memory in memblock, but it ignores > failures. If one happens, memory that a KHO user still expects to > restore can be released to the page allocator. This needs memblock to > fail to grow its reserved array, so it's unlikely. But if it does > happen, the result is bad enough to be worth handling. If memblock_reserve() fails we are in a very unhappy place. Do you think we really should worry about KHO state when we won't pass through mm_core_init() anyway? > Patch 2 makes the walk stop on such a failure, so that > kho_mem_retrieve() drops the handover and the boot carries on without > it. For that to be safe, reserve_mem_kho_revive() now reserves its own > region, and patch 1 stops kho_init() from releasing inherited bootmem > areas after a failed retrieval. > > From a quick check I did with one of the reservations forced to fail, > the kernel logs the failure and boots without the handover. The > reserve_mem region stays reserved, and a later KHO kexec out of that > kernel works. > > v2: > > - Drop the handover and carry on instead of panicking, with > reserve_mem_kho_revive() reserving its own region (Mike) > - Stop kho_init() from releasing inherited bootmem areas after a failed > retrieval, as a separate patch (Mike) > > v1: https://lore.kernel.org/r/avQUquBK6cO6tUUI@chrisdown.name > > Chris Down (2): > kho: skip bootmem setup in kho_init() if bootmem was inherited > kho: drop the handover if preserved memory can't be reserved > > kernel/liveupdate/kho_core.c | 28 +++++++++++++++++++++++----- > mm/memblock.c | 8 ++++++++ > 2 files changed, 31 insertions(+), 5 deletions(-) > > > base-commit: ec459d99ed222228b3d601818fd1e24822a450d6 > -- > 2.56.1 > -- Sincerely yours, Mike. ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v2 0/2] kho: handle failures to reserve preserved memory 2026-12-02 11:24 ` [PATCH v2 0/2] kho: handle failures to reserve preserved memory Mike Rapoport @ 2026-12-03 2:58 ` Chris Down 0 siblings, 0 replies; 11+ messages in thread From: Chris Down @ 2026-12-03 2:58 UTC (permalink / raw) To: Mike Rapoport Cc: pasha.tatashin, pratyush, graf, kexec, linux-mm, linux-kernel, kernel-team Hi Mike, Mike Rapoport writes: >If memblock_reserve() fails we are in a very unhappy place. >Do you think we really should worry about KHO state when we won't pass >through mm_core_init() anyway? I am not an expert in memblock for sure, but as far as I can see the following can happen reasonably: 1. The memory map is allocated in mm_core_init_early(), so the walk has its memory already. 2. kho_memory_init() is the last thing before memblock_free_all(), so nothing between the walk and memblock_free_all() allocates from memblock. 3. memblock_free_all() may have to grow the reserved array itself, but it stops restricting allocations to bootmem before it does. Once it has run, the kernel has plenty to work with, including whatever the walk failed to reserve. Or am I missing something? I've now also managed to hit this without forcing the failure. I preserved a memfd whose 140000 pages are interleaved with another file's, so that each page is a range of its own, and used reserve_mem= to fill most of the next kernel's bootmem. Without the series, that kernel logs memblock: Failed to double reserved array from 131072 to 262144 entries ! for each range it can no longer reserve, and then boots to userspace as usual. Retrieving the memfd there fails with -EIO, with kho_restore_page() warning that the magic is gone. With the series, it logs the failure once, drops the handover and boots. It's still unlikely, since it needs badly fragmented preserved memory and a bootmem that's close to full, although it will get easier to hit if we manage to shrink bootmem. But the kernel doesn't die when it happens. It carries on with preserved memory in the page allocator, so I think it's worth handling, but please do tell me if there's context I'm missing here. Thanks, Chris ^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2026-12-03 6:32 UTC | newest] Thread overview: 11+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-12-02 6:32 [PATCH v2 0/2] kho: handle failures to reserve preserved memory Chris Down 2026-12-02 6:32 ` [PATCH v2 1/2] kho: skip bootmem setup in kho_init() if bootmem was inherited Chris Down 2026-12-02 10:59 ` Pratyush Yadav 2026-12-03 2:58 ` Chris Down 2026-12-03 6:32 ` sashiko-bot 2026-12-02 6:32 ` [PATCH v2 2/2] kho: drop the handover if preserved memory can't be reserved Chris Down 2026-12-02 11:14 ` Pratyush Yadav 2026-12-03 2:58 ` Chris Down 2026-12-03 6:32 ` sashiko-bot 2026-12-02 11:24 ` [PATCH v2 0/2] kho: handle failures to reserve preserved memory Mike Rapoport 2026-12-03 2:58 ` Chris Down
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox