* [PATCH] kho: Don't release incoming bootmem areas when kho_init() fails
@ 2026-11-08 3:40 Chris Down
2026-11-08 14:29 ` Pasha Tatashin
2026-11-09 10:09 ` Mike Rapoport
0 siblings, 2 replies; 4+ messages in thread
From: Chris Down @ 2026-11-08 3:40 UTC (permalink / raw)
To: rppt, pasha.tatashin, pratyush
Cc: graf, kexec, linux-mm, linux-kernel, kernel-team
kho_populate() adds the incoming bootmem areas without reserving
them. memblock_free_all() then hands the remainder to the buddy
allocator.
Unfortunately however, if kho_init() fails, err_free_bootmem
currently frees every area with free_reserved_area(). This can free
pages still backing early allocations or free buddy pages a second
time.
To fix this, let's only free the areas on a cold boot when
kho_reserve_bootmem() reserved them.
Fixes: c609c144b0e8 ("kexec: add KHO parsing support")
Cc: <stable@vger.kernel.org>
Signed-off-by: Chris Down <chris@chrisdown.name>
---
kernel/liveupdate/kexec_handover.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/kernel/liveupdate/kexec_handover.c b/kernel/liveupdate/kexec_handover.c
index 6f1f55fe3181..a566ad6634d8 100644
--- a/kernel/liveupdate/kexec_handover.c
+++ b/kernel/liveupdate/kexec_handover.c
@@ -1899,11 +1899,13 @@ static __init int kho_init(void)
kho_radix_destroy_tree(tree);
err_free_bootmem:
kho_out.fdt = NULL;
- for (int i = 0; i < kho_bootmem_cnt; i++) {
- void *start = __va(kho_bootmem[i].addr);
- void *end = start + kho_bootmem[i].size;
+ if (!fdt) {
+ 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, "");
+ free_reserved_area(start, end, -1, "");
+ }
}
kho_enable = false;
return err;
base-commit: fa4ad798f6f681031775266044ba1b0cf3c670bd
--
2.54.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] kho: Don't release incoming bootmem areas when kho_init() fails
2026-11-08 3:40 [PATCH] kho: Don't release incoming bootmem areas when kho_init() fails Chris Down
@ 2026-11-08 14:29 ` Pasha Tatashin
2026-11-09 10:09 ` Mike Rapoport
1 sibling, 0 replies; 4+ messages in thread
From: Pasha Tatashin @ 2026-11-08 14:29 UTC (permalink / raw)
To: Chris Down
Cc: rppt, pasha.tatashin, pratyush, graf, kexec, linux-mm,
linux-kernel, kernel-team
On Sat, 07 Nov 2026 19:40:50 -0800, Chris Down <chris@chrisdown.name> wrote:
> kho_populate() adds the incoming bootmem areas without reserving
> them. memblock_free_all() then hands the remainder to the buddy
> allocator.
>
> Unfortunately however, if kho_init() fails, err_free_bootmem
> currently frees every area with free_reserved_area(). This can free
> pages still backing early allocations or free buddy pages a second
> time.
>
> [...]
Reviewed-by: Pasha Tatashin <pasha.tatashin@soleen.com>
--
Pasha
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] kho: Don't release incoming bootmem areas when kho_init() fails
2026-11-08 3:40 [PATCH] kho: Don't release incoming bootmem areas when kho_init() fails Chris Down
2026-11-08 14:29 ` Pasha Tatashin
@ 2026-11-09 10:09 ` Mike Rapoport
2026-11-28 9:21 ` Chris Down
1 sibling, 1 reply; 4+ messages in thread
From: Mike Rapoport @ 2026-11-09 10:09 UTC (permalink / raw)
To: Chris Down
Cc: pasha.tatashin, pratyush, graf, kexec, linux-mm, linux-kernel,
kernel-team
Hi,
On Sat, Nov 07, 2026 at 07:40:50PM -0800, Chris Down wrote:
> kho_populate() adds the incoming bootmem areas without reserving
> them. memblock_free_all() then hands the remainder to the buddy
> allocator.
This paragraph is confusing.
It reads like kho_populate() should have reserved bootmem areas, but it
didn't.
> Unfortunately however, if kho_init() fails, err_free_bootmem
> currently frees every area with free_reserved_area(). This can free
> pages still backing early allocations or free buddy pages a second
> time.
Is this an issue you hit in practice or it was reported by a code analysis?
> To fix this, let's only free the areas on a cold boot when
> kho_reserve_bootmem() reserved them.
>
> Fixes: c609c144b0e8 ("kexec: add KHO parsing support")
> Cc: <stable@vger.kernel.org>
> Signed-off-by: Chris Down <chris@chrisdown.name>
> ---
> kernel/liveupdate/kexec_handover.c | 10 ++++++----
> 1 file changed, 6 insertions(+), 4 deletions(-)
>
> diff --git a/kernel/liveupdate/kexec_handover.c b/kernel/liveupdate/kexec_handover.c
> index 6f1f55fe3181..a566ad6634d8 100644
> --- a/kernel/liveupdate/kexec_handover.c
> +++ b/kernel/liveupdate/kexec_handover.c
> @@ -1899,11 +1899,13 @@ static __init int kho_init(void)
> kho_radix_destroy_tree(tree);
> err_free_bootmem:
> kho_out.fdt = NULL;
> - for (int i = 0; i < kho_bootmem_cnt; i++) {
> - void *start = __va(kho_bootmem[i].addr);
> - void *end = start + kho_bootmem[i].size;
> + if (!fdt) {
I think using !is_kho_boot() makes this clearer.
> + 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, "");
> + free_reserved_area(start, end, -1, "");
> + }
> }
> kho_enable = false;
> return err;
>
> base-commit: fa4ad798f6f681031775266044ba1b0cf3c670bd
> --
> 2.54.0
>
--
Sincerely yours,
Mike.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] kho: Don't release incoming bootmem areas when kho_init() fails
2026-11-09 10:09 ` Mike Rapoport
@ 2026-11-28 9:21 ` Chris Down
0 siblings, 0 replies; 4+ messages in thread
From: Chris Down @ 2026-11-28 9:21 UTC (permalink / raw)
To: Mike Rapoport
Cc: pasha.tatashin, pratyush, graf, kexec, linux-mm, linux-kernel,
kernel-team
Hi Mike,
Mike Rapoport writes:
>On Sat, Nov 07, 2026 at 07:40:50PM -0800, Chris Down wrote:
>> kho_populate() adds the incoming bootmem areas without reserving
>> them. memblock_free_all() then hands the remainder to the buddy
>> allocator.
>
>This paragraph is confusing.
>It reads like kho_populate() should have reserved bootmem areas, but it
>didn't.
Yeah, I can see how it reads that way. v2 will say who reserves the
areas on each kind of boot instead.
>> Unfortunately however, if kho_init() fails, err_free_bootmem
>> currently frees every area with free_reserved_area(). This can free
>> pages still backing early allocations or free buddy pages a second
>> time.
>
>Is this an issue you hit in practice or it was reported by a code analysis?
Just from reading the code, same as the reservation failure one.
Actually, I did find an amusingly simple way to trigger it to
demonstrate :-) With CONFIG_KEXEC_HANDOVER_DEBUGFS=y, kho_init() fails
when debugfs is disabled, so a KHO kexec into a kernel with debugfs=off
added to its command line is enough. From a quick check I did, the new
kernel then crashes in free_pcppages_bulk() under free_reserved_area()
and never gets to userspace. I'll add the trace to the v2 changelog.
kho_init() shouldn't really fail just because debugfs is off, so let me
fix that in v2 as well.
>> + if (!fdt) {
>
>I think using !is_kho_boot() makes this clearer.
Agreed, will do in v2.
Once the reservation failure v2 lets kho_mem_retrieve() fail and drop
the handover, is_kho_boot() will be false even though the bootmem was
inherited, so both this and the bootmem setup above it will have to
check for that instead. I'll change both in that series.
Thanks!
Chris
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-28 9:22 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-08 3:40 [PATCH] kho: Don't release incoming bootmem areas when kho_init() fails Chris Down
2026-11-08 14:29 ` Pasha Tatashin
2026-11-09 10:09 ` Mike Rapoport
2026-11-28 9:21 ` Chris Down
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®