From: Chris Down <chris@chrisdown.name>
To: rppt@kernel.org, pasha.tatashin@soleen.com, pratyush@kernel.org
Cc: graf@amazon.com, kexec@lists.infradead.org, linux-mm@kvack.org,
linux-kernel@vger.kernel.org, kernel-team@meta.com
Subject: [PATCH v2 1/2] kho: don't release incoming bootmem areas when kho_init() fails
Date: Sat, 28 Nov 2026 01:21:49 -0800 [thread overview]
Message-ID: <c9c7b0465b1b27312eaa170692836dd30541bba0.1795835884.git.chris@chrisdown.name> (raw)
In-Reply-To: <cover.1795835884.git.chris@chrisdown.name>
On a non-KHO boot, kho_reserve_bootmem() reserves the bootmem areas in
memblock, and they stay reserved until kho_init() releases them as CMA.
On a KHO boot, the bootmem areas are inherited from the previous kernel.
kexec loads the new kernel into them. kho_populate() adds them to
memblock as free memory, because early allocations are made from them.
Whatever is still free afterwards goes to the buddy allocator like any
other memory.
Unfortunately however, if kho_init() fails, err_free_bootmem currently
frees every area with free_reserved_area() on both kinds of boot. On a
KHO boot this frees pages that are still in use, the kernel image among
them, and frees buddy pages a second time.
With CONFIG_KEXEC_HANDOVER_DEBUGFS=y, kho_init() fails if debugfs is
disabled, so a KHO kexec into a kernel with debugfs=off added to its
command line is enough to hit this. In a VM, the new kernel then oopses
in kho_init() and panics.
BUG: kernel NULL pointer dereference, address: 0000000000000008
RIP: 0010:free_pcppages_bulk+0x10f/0x280
Call Trace:
free_frozen_page_commit+0x1fa/0x430
__free_frozen_pages+0x205/0x600
__free_reserved_area+0x7b/0x120
free_reserved_area+0x89/0xe0
kho_init+0x301/0x3e0
do_one_initcall+0x89/0x260
kernel_init_freeable+0x1e0/0x250
kernel_init+0x1f/0x140
Kernel panic - not syncing: Attempted to kill init! exitcode=0x00000009
To fix this, let's only free the areas when this isn't a KHO boot,
because that's when kho_reserve_bootmem() reserved them.
With this applied, kho_init() still fails after the same kexec, but the
kernel boots and the bootmem areas are left alone. A non-KHO boot with
debugfs=off still frees the areas it reserved.
Fixes: c609c144b0e8 ("kexec: add KHO parsing support")
Cc: <stable@vger.kernel.org>
Reviewed-by: Pasha Tatashin <pasha.tatashin@soleen.com>
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 42c6609a1766..663dd22e7172 100644
--- a/kernel/liveupdate/kexec_handover.c
+++ b/kernel/liveupdate/kexec_handover.c
@@ -1899,11 +1899,13 @@ err_free_kho_radix_tree:
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 (!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, "");
+ free_reserved_area(start, end, -1, "");
+ }
}
kho_enable = false;
return err;
--
2.56.1
next prev parent reply other threads:[~2026-11-28 9:21 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-28 9:21 [PATCH v2 0/2] kho: fixes for kho_init() failures Chris Down
2026-11-28 9:21 ` Chris Down [this message]
2026-11-28 9:21 ` [PATCH v2 2/2] kho: don't fail kho_init() when debugfs is disabled Chris Down
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=c9c7b0465b1b27312eaa170692836dd30541bba0.1795835884.git.chris@chrisdown.name \
--to=chris@chrisdown.name \
--cc=graf@amazon.com \
--cc=kernel-team@meta.com \
--cc=kexec@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=pasha.tatashin@soleen.com \
--cc=pratyush@kernel.org \
--cc=rppt@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®