Kexec Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/2] kho: fixes for kho_init() failures
@ 2026-11-28  9:21 Chris Down
  2026-11-28  9:21 ` [PATCH v2 1/2] kho: don't release incoming bootmem areas when kho_init() fails Chris Down
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Chris Down @ 2026-11-28  9:21 UTC (permalink / raw)
  To: rppt, pasha.tatashin, pratyush
  Cc: graf, kexec, linux-mm, linux-kernel, kernel-team

When kho_init() fails on a KHO boot, its error path frees the bootmem
areas that were inherited from the previous kernel, even though the
running kernel was loaded into them and is still using them. The new
kernel then oopses in kho_init() and panics.

The easiest way to get there turned out to be debugfs=off. With
CONFIG_KEXEC_HANDOVER_DEBUGFS=y, kho_init() fails when it can't create
its debugfs entries, so a KHO kexec into a kernel with debugfs disabled
is enough to hit the panic. That's a bug in its own right, because it
means KHO and LUO can't be used at all on a kernel that has debugfs
disabled, although nothing in KHO needs debugfs any more.

This series stops the error path from freeing bootmem areas that it
didn't reserve, and stops kho_init() from failing when debugfs is
disabled.

v2:

- Use is_kho_boot() instead of checking fdt (Mike)
- Say who reserves the bootmem areas on each kind of boot (Mike)
- Describe how to trigger it and add the oops (Mike)
- Add a patch so that kho_init() doesn't fail when debugfs is disabled
- Rebase onto liveupdate/fixes

v1: https://lore.kernel.org/r/au_vQhHAcJbkryXN@chrisdown.name

Chris Down (2):
  kho: don't release incoming bootmem areas when kho_init() fails
  kho: don't fail kho_init() when debugfs is disabled

 kernel/liveupdate/kexec_handover.c          | 19 ++++++++-----------
 kernel/liveupdate/kexec_handover_debugfs.c  | 19 +++++++++++--------
 kernel/liveupdate/kexec_handover_internal.h |  8 ++++----
 3 files changed, 23 insertions(+), 23 deletions(-)


base-commit: fa1c0f103fd68558613d3df76e222463c6e4fc37
-- 
2.56.1



^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2 1/2] kho: don't release incoming bootmem areas when kho_init() fails
  2026-11-28  9:21 [PATCH v2 0/2] kho: fixes for kho_init() failures Chris Down
@ 2026-11-28  9:21 ` Chris Down
  2026-11-28  9:21 ` [PATCH v2 2/2] kho: don't fail kho_init() when debugfs is disabled Chris Down
  2026-11-28  9:28 ` [PATCH v2 0/2] kho: fixes for kho_init() failures sashiko-bot
  2 siblings, 0 replies; 4+ messages in thread
From: Chris Down @ 2026-11-28  9:21 UTC (permalink / raw)
  To: rppt, pasha.tatashin, pratyush
  Cc: graf, kexec, linux-mm, linux-kernel, kernel-team

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



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH v2 2/2] kho: don't fail kho_init() when debugfs is disabled
  2026-11-28  9:21 [PATCH v2 0/2] kho: fixes for kho_init() failures Chris Down
  2026-11-28  9:21 ` [PATCH v2 1/2] kho: don't release incoming bootmem areas when kho_init() fails Chris Down
@ 2026-11-28  9:21 ` Chris Down
  2026-11-28  9:28 ` [PATCH v2 0/2] kho: fixes for kho_init() failures sashiko-bot
  2 siblings, 0 replies; 4+ messages in thread
From: Chris Down @ 2026-11-28  9:21 UTC (permalink / raw)
  To: rppt, pasha.tatashin, pratyush
  Cc: graf, kexec, linux-mm, linux-kernel, kernel-team

kho_init() fails if kho_debugfs_init() or kho_out_debugfs_init() can't
create their debugfs entries, and a failed kho_init() turns KHO off.
That made sense while KHO could only be finalised through debugfs, but
commit 03d3963464a4 ("kho: make debugfs interface optional") made the
debugfs interface optional, and these days KHO doesn't need any of its
files to work.

This is a problem because debugfs can be disabled at boot with
debugfs=off, or by default with CONFIG_DEBUG_FS_ALLOW_NONE, in which
case every attempt to create a debugfs entry returns -EPERM. Given that
CONFIG_KEXEC_HANDOVER_DEBUGFS defaults to y when KHO is built in, KHO
and LUO can't be used at all on such a kernel. With kho=on liveupdate=on
debugfs=off, /dev/liveupdate never appears and a kexec hands nothing
over. kho_init() doesn't log why, so the only sign of it is the
WARN_ON_ONCE() that LUO then trips in kho_radix_add_key().

So, let's carry on without the debugfs entries when they can't be
created, as kho_in_debugfs_init() already does for the incoming FDT.

Two things then run without KHO's debugfs directories for the first
time. kho_debugfs_blob_add() would fail and trip the WARN_ON_ONCE() in
its callers, so let's make it do nothing when it has no directory to add
the blob to. kho_in_debugfs_init() would log an error on every KHO boot,
so let's make it return early when the kho directory doesn't exist.

With this applied, test_kho and luo_kexec_simple both get their state
back across a KHO kexec between two kernels booted with debugfs=off.

Fixes: 03d3963464a4 ("kho: make debugfs interface optional")
Signed-off-by: Chris Down <chris@chrisdown.name>
---
 kernel/liveupdate/kexec_handover.c          |  9 ++-------
 kernel/liveupdate/kexec_handover_debugfs.c  | 19 +++++++++++--------
 kernel/liveupdate/kexec_handover_internal.h |  8 ++++----
 3 files changed, 17 insertions(+), 19 deletions(-)

diff --git a/kernel/liveupdate/kexec_handover.c b/kernel/liveupdate/kexec_handover.c
index 663dd22e7172..4cee37ad9426 100644
--- a/kernel/liveupdate/kexec_handover.c
+++ b/kernel/liveupdate/kexec_handover.c
@@ -1847,13 +1847,8 @@ static __init int kho_init(void)
 		goto err_free_kho_radix_tree;
 	}
 
-	err = kho_debugfs_init();
-	if (err)
-		goto err_free_fdt;
-
-	err = kho_out_debugfs_init(&kho_out.dbg);
-	if (err)
-		goto err_free_fdt;
+	kho_debugfs_init();
+	kho_out_debugfs_init(&kho_out.dbg);
 
 	err = kho_out_fdt_setup();
 	if (err)
diff --git a/kernel/liveupdate/kexec_handover_debugfs.c b/kernel/liveupdate/kexec_handover_debugfs.c
index 3a91c47ad7a6..cedfc955391a 100644
--- a/kernel/liveupdate/kexec_handover_debugfs.c
+++ b/kernel/liveupdate/kexec_handover_debugfs.c
@@ -59,6 +59,10 @@ int kho_debugfs_blob_add(struct kho_debugfs *dbg, const char *name,
 	else
 		dir = dbg->sub_fdt_dir;
 
+	/* The directories are NULL if they could not be created. */
+	if (!dir)
+		return 0;
+
 	return __kho_debugfs_blob_add(&dbg->fdt_list, dir, name, blob, size);
 }
 
@@ -101,6 +105,9 @@ __init void kho_in_debugfs_init(struct kho_debugfs *dbg, const void *fdt)
 
 	INIT_LIST_HEAD(&dbg->fdt_list);
 
+	if (IS_ERR(debugfs_root))
+		return;
+
 	dir = debugfs_create_dir("in", debugfs_root);
 	if (IS_ERR(dir)) {
 		err = PTR_ERR(dir);
@@ -129,7 +136,7 @@ err_out:
 	}
 }
 
-__init int kho_out_debugfs_init(struct kho_debugfs *dbg)
+__init void kho_out_debugfs_init(struct kho_debugfs *dbg)
 {
 	struct dentry *dir, *f, *sub_fdt_dir;
 
@@ -137,7 +144,7 @@ __init int kho_out_debugfs_init(struct kho_debugfs *dbg)
 
 	dir = debugfs_create_dir("out", debugfs_root);
 	if (IS_ERR(dir))
-		return -ENOMEM;
+		return;
 
 	sub_fdt_dir = debugfs_create_dir("sub_fdts", dir);
 	if (IS_ERR(sub_fdt_dir))
@@ -155,17 +162,13 @@ __init int kho_out_debugfs_init(struct kho_debugfs *dbg)
 
 	dbg->dir = dir;
 	dbg->sub_fdt_dir = sub_fdt_dir;
-	return 0;
+	return;
 
 err_rmdir:
 	debugfs_remove_recursive(dir);
-	return -ENOENT;
 }
 
-__init int kho_debugfs_init(void)
+__init void kho_debugfs_init(void)
 {
 	debugfs_root = debugfs_create_dir("kho", NULL);
-	if (IS_ERR(debugfs_root))
-		return -ENOENT;
-	return 0;
 }
diff --git a/kernel/liveupdate/kexec_handover_internal.h b/kernel/liveupdate/kexec_handover_internal.h
index e9685e1ef6d7..424467a98da2 100644
--- a/kernel/liveupdate/kexec_handover_internal.h
+++ b/kernel/liveupdate/kexec_handover_internal.h
@@ -23,17 +23,17 @@ extern struct kho_bootmem *kho_bootmem;
 extern unsigned int kho_bootmem_cnt;
 
 #ifdef CONFIG_KEXEC_HANDOVER_DEBUGFS
-int kho_debugfs_init(void);
+void kho_debugfs_init(void);
 void kho_in_debugfs_init(struct kho_debugfs *dbg, const void *fdt);
-int kho_out_debugfs_init(struct kho_debugfs *dbg);
+void kho_out_debugfs_init(struct kho_debugfs *dbg);
 int kho_debugfs_blob_add(struct kho_debugfs *dbg, const char *name,
 			 const void *blob, size_t size, bool root);
 void kho_debugfs_blob_remove(struct kho_debugfs *dbg, void *blob);
 #else
-static inline int kho_debugfs_init(void) { return 0; }
+static inline void kho_debugfs_init(void) { }
 static inline void kho_in_debugfs_init(struct kho_debugfs *dbg,
 				       const void *fdt) { }
-static inline int kho_out_debugfs_init(struct kho_debugfs *dbg) { return 0; }
+static inline void kho_out_debugfs_init(struct kho_debugfs *dbg) { }
 static inline int kho_debugfs_blob_add(struct kho_debugfs *dbg,
 				       const char *name, const void *blob,
 				       size_t size, bool root) { return 0; }
-- 
2.56.1



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2 0/2] kho: fixes for kho_init() failures
  2026-11-28  9:21 [PATCH v2 0/2] kho: fixes for kho_init() failures Chris Down
  2026-11-28  9:21 ` [PATCH v2 1/2] kho: don't release incoming bootmem areas when kho_init() fails Chris Down
  2026-11-28  9:21 ` [PATCH v2 2/2] kho: don't fail kho_init() when debugfs is disabled Chris Down
@ 2026-11-28  9:28 ` sashiko-bot
  2 siblings, 0 replies; 4+ messages in thread
From: sashiko-bot @ 2026-11-28  9:28 UTC (permalink / raw)
  To: Chris Down, rppt, pasha.tatashin, pratyush; +Cc: graf, kexec, kernel-team

Sashiko has reviewed this 2-patch series and found no issues.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1795835884.git.chris@chrisdown.name


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-11-28  9:28 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-28  9:21 [PATCH v2 0/2] kho: fixes for kho_init() failures Chris Down
2026-11-28  9:21 ` [PATCH v2 1/2] kho: don't release incoming bootmem areas when kho_init() fails Chris Down
2026-11-28  9:21 ` [PATCH v2 2/2] kho: don't fail kho_init() when debugfs is disabled Chris Down
2026-11-28  9:28 ` [PATCH v2 0/2] kho: fixes for kho_init() failures sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox