kho: history: track previous kernel version and kexec boot count
Subsystems (7)
v9 cover kho: history: track previous kernel version and kexec boot count
Use Kexec Handover (KHO) to pass the previous kernel's version string and the number of kexec reboots since the last cold boot to the next kernel, and print it at boot time.
Example
=======
[ 0.000000] Linux version 6.19.0-rc3-upstream-00047-ge5d992347849 ... [ 0.000000] KHO: exec from: 6.19.0-rc4-next-20260107upstream-00004-g3071b0dc4498 (count 1)
Motivation
==========
Bugs that only reproduce when kexecing from specific kernel versions are difficult to diagnose. These issues occur when a buggy kernel kexecs into a new kernel, with the bug manifesting only in the second kernel.
Recent examples include:
* eb2266312507 ("x86/boot: Fix page table access in 5-level to 4-level paging transition")
* 77d48d39e991 ("efistub/tpm: Use ACPI reclaim memory for event log to avoid corruption")
* 64b45dd46e15 ("x86/efi: skip memattr table on kexec boot")
As kexec-based reboots become more common, these version-dependent bugs are appearing more frequently. At scale, correlating crashes to the previous kernel version is challenging, especially when issues only occur in specific transition scenarios.
Some bugs manifest only after multiple consecutive kexec reboots. Tracking the kexec count helps identify these cases (this metric is already used by live update sub-system).
KHO provides a reliable mechanism to pass information between kernels. By carrying the previous kernel's release string and kexec count forward, we can print this context at boot time to aid debugging.
The goal of this feature is to have this information being printed in early boot, so, users can trace back kernel releases in kexec. Systemd is not helpful because we cannot assume that the previous kernel has systemd or even write access to the disk (common when using Linux as bootloaders)
---
Changes in v9:
- Rebase on top of new KHO changes
- Fail and ignore subtree in case size is invalid (Pratyush)
- Separate kexec_metadata into a new file (Pratyush)
- Link to v8: https://patch.msgid.link/[email protected]
Changes in v8:
- Removed an unnecessary size variable (Mike)
- Moved some renaming to the proper rename patch (Mike)
- Link to v7: https://patch.msgid.link/[email protected]
Changes in v7:
- Persist blob size in KHO FDT as a "blob-size" property so the incoming kernel can determine blob sizes without assuming FDT format (Pratyush)
- Link to v6: https://patch.msgid.link/[email protected]
Changes in v6:
- s/UAPI/uABI (Mike)
- Expanded the rename of s/fdt/blob to kho_debugfs_* calls also (Mike)
- Link to v5: https://patch.msgid.link/[email protected]
Changes in v5:
- Add a patch to document the new feature.
- Change kho_add_subtree() to receive the size instad of guessing it.
- reworked some code path to make it more standard.
- Link to v4: https://patch.msgid.link/[email protected]
Changes in v4:
- Squashed everything in a single commit
- Moved from FDT to C structs (Pratyush)
- Usage of subtress intead of FDT directly (Pratyush)
- Renamed a bunch of variables and functions.
- Link to v3: https://patch.msgid.link/[email protected]
Changes in v3:
- Remove the extra CONFIG for this feature.
- Reworded some identifiers, properties and printks.
- Better documented the questions raised during v2.
- Link to v2: https://patch.msgid.link/[email protected]
Changes from v2 to v1 (RFC)
- Track the number of kexecs since cold boot (Pasha)
- Change the printk() order compared to KHO
- Rewording of the commit summary
- Link to RFC: https://patch.msgid.link/[email protected]
---
Breno Leitao (6):
kho: add size parameter to kho_add_subtree()
kho: rename fdt parameter to blob in kho_add/remove_subtree()
kho: persist blob size in KHO FDT
kho: fix kho_in_debugfs_init() to handle non-FDT blobs
kho: kexec-metadata: track previous kernel chain
kho: document kexec-metadata tracking feature
Documentation/admin-guide/mm/kho.rst | 41 +++++++- include/linux/kexec_handover.h | 13 +-- include/linux/kho/abi/kexec_handover.h | 20 +++- include/linux/kho/abi/kexec_metadata.h | 46 ++++++++ kernel/liveupdate/kexec_handover.c | 158 ++++++++++++++++++++++++---- kernel/liveupdate/kexec_handover_debugfs.c | 55 ++++++---- kernel/liveupdate/kexec_handover_internal.h | 15 +-- kernel/liveupdate/luo_core.c | 5 +- lib/test_kho.c | 5 +- mm/memblock.c | 4 +- 10 files changed, 298 insertions(+), 64 deletions(-)
---
base-commit: 5c9e55fecf9365890c64f14761a80f9413a3b1d1
change-id: 20251230-kho-7707e8a2ef1e
Best regards,
Signature · 1 line
Breno Leitao <[email protected]>
PATCH v9 1/6 kho: add size parameter to kho_add_subtree()
kho_add_subtree() assumes the fdt argument is always an FDT and calls fdt_totalsize() on it in the debugfs code path. This assumption will break if a caller passes arbitrary data instead of an FDT.
When CONFIG_KEXEC_HANDOVER_DEBUGFS is enabled, kho_debugfs_fdt_add() calls __kho_debugfs_fdt_add(), which executes:
f->wrapper.size = fdt_totalsize(fdt);
Fix this by adding an explicit size parameter to kho_add_subtree() so callers specify the blob size. This allows subtrees to contain arbitrary data formats, not just FDTs. Update all callers:
- memblock.c: use fdt_totalsize(fdt)
- luo_core.c: use fdt_totalsize(fdt_out)
- test_kho.c: use fdt_totalsize()
- kexec_handover.c (root fdt): use fdt_totalsize(kho_out.fdt)
Also update __kho_debugfs_fdt_add() to receive the size explicitly instead of computing it internally via fdt_totalsize(). In kho_in_debugfs_init(), pass fdt_totalsize() for the root FDT and sub-blobs since all current users are FDTs. A subsequent patch will persist the size in the KHO FDT so the incoming side can handle non-FDT blobs correctly.
--- include/linux/kexec_handover.h | 4 ++-- kernel/liveupdate/kexec_handover.c | 8 +++++--- kernel/liveupdate/kexec_handover_debugfs.c | 15 +++++++++------ kernel/liveupdate/kexec_handover_internal.h | 5 +++-- kernel/liveupdate/luo_core.c | 3 ++- lib/test_kho.c | 3 ++- mm/memblock.c | 2 +- 7 files changed, 24 insertions(+), 16 deletions(-)
include/linux/kexec_handover.h +2 -2
@@ -32,7 +32,7 @@ void kho_restore_free(void *mem);struct folio *kho_restore_folio (phys_addr_t phys);struct page *kho_restore_pages (phys_addr_t phys,unsigned long nr_pages);void *kho_restore_vmalloc (const struct kho_vmalloc *preservation); -int kho_add_subtree (const char *name,void *fdt); +int kho_add_subtree (const char *name,void *fdt,size_t size);void kho_remove_subtree (void *fdt);int kho_retrieve_subtree (const char *name,phys_addr_t *phys);
@@ -97,7 +97,7 @@ static inline void *kho_restore_vmalloc(const struct kho_vmalloc *preservation)return NULL ; } -static inline int kho_add_subtree (const char *name,void *fdt) +static inline int kho_add_subtree (const char *name,void *fdt,size_t size) {return -EOPNOTSUPP ; }
kernel/liveupdate/kexec_handover.c +5 -3
@@ -752,6 +752,7 @@ static void __init kho_reserve_scratch(void)* kho_add_subtree - record the physical address of a sub FDT in KHO root tree. * @name: name of the sub tree. * @fdt: the sub tree blob. +* @size: size of the blob in bytes. * * Creates a new child node named @name in KHO root FDT and records * the physical address of @fdt. The pages of @fdt must also be preserved
@@ -763,7 +764,7 @@ static void __init kho_reserve_scratch(void)* * Return: 0 on success, error code on failure */ -int kho_add_subtree (const char *name,void *fdt) +int kho_add_subtree (const char *name,void *fdt,size_t size) {phys_addr_t phys =virt_to_phys (fdt);void *root_fdt = kho_out.fdt;
@@ -788,7 +789,7 @@ int kho_add_subtree(const char *name, void *fdt)if (err <0 ) goto out_pack; -WARN_ON_ONCE (kho_debugfs_fdt_add (&kho_out.dbg, name, fdt, false)); +WARN_ON_ONCE (kho_debugfs_fdt_add (&kho_out.dbg, name, fdt, size, false)); out_pack:fdt_pack (root_fdt);
@@ -1452,7 +1453,8 @@ static __init int kho_init(void) }WARN_ON_ONCE (kho_debugfs_fdt_add (&kho_out.dbg,"fdt" , - kho_out.fdt, true)); + kho_out.fdt, +fdt_totalsize (kho_out.fdt), true));return 0 ;
kernel/liveupdate/kexec_handover_debugfs.c +9 -6
@@ -25,7 +25,7 @@ struct fdt_debugfs { };static int __kho_debugfs_fdt_add (struct list_head *list,struct dentry *dir, -const char *name,const void *fdt) +const char *name,const void *fdt,size_t size) {struct fdt_debugfs *f;struct dentry *file;
@@ -35,7 +35,7 @@ static int __kho_debugfs_fdt_add(struct list_head *list, struct dentry *dir,return -ENOMEM ; f->wrapper.data = (void *)fdt; - f->wrapper.size =fdt_totalsize (fdt); + f->wrapper.size = size; file =debugfs_create_blob (name,0400 , dir, &f->wrapper);if (IS_ERR (file)) {
@@ -50,7 +50,7 @@ static int __kho_debugfs_fdt_add(struct list_head *list, struct dentry *dir, }int kho_debugfs_fdt_add (struct kho_debugfs *dbg,const char *name, -const void *fdt,bool root) +const void *fdt,size_t size,bool root) {struct dentry *dir;
@@ -59,7 +59,7 @@ int kho_debugfs_fdt_add(struct kho_debugfs *dbg, const char *name,else dir = dbg->sub_fdt_dir; -return __kho_debugfs_fdt_add (&dbg->fdt_list, dir, name, fdt); +return __kho_debugfs_fdt_add (&dbg->fdt_list, dir, name, fdt, size); }void kho_debugfs_fdt_remove (struct kho_debugfs *dbg,void *fdt)
@@ -113,7 +113,8 @@ __init void kho_in_debugfs_init(struct kho_debugfs *dbg, const void *fdt) goto err_rmdir; } - err =__kho_debugfs_fdt_add (&dbg->fdt_list, dir,"fdt" , fdt); + err =__kho_debugfs_fdt_add (&dbg->fdt_list, dir,"fdt" , fdt, +fdt_totalsize (fdt));if (err) goto err_rmdir;
@@ -121,6 +122,7 @@ __init void kho_in_debugfs_init(struct kho_debugfs *dbg, const void *fdt)int len =0 ;const char *name =fdt_get_name (fdt, child,NULL );const u64 *fdt_phys; +void *sub_fdt; fdt_phys =fdt_getprop (fdt, child,KHO_FDT_SUB_TREE_PROP_NAME , &len);if (!fdt_phys)
@@ -130,8 +132,9 @@ __init void kho_in_debugfs_init(struct kho_debugfs *dbg, const void *fdt) name, len);continue ; } + sub_fdt =phys_to_virt (*fdt_phys); err =__kho_debugfs_fdt_add (&dbg->fdt_list, sub_fdt_dir, name, -phys_to_virt (*fdt_phys)); + sub_fdt,fdt_totalsize (sub_fdt));if (err) {pr_warn ("failed to add fdt %s to debugfs: %pe\n" , name,ERR_PTR (err));
kernel/liveupdate/kexec_handover_internal.h +3 -2
@@ -27,7 +27,7 @@ int 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);int kho_debugfs_fdt_add (struct kho_debugfs *dbg,const char *name, -const void *fdt,bool root); +const void *fdt,size_t size,bool root);void kho_debugfs_fdt_remove (struct kho_debugfs *dbg,void *fdt);#else static inline int kho_debugfs_init (void ) {return 0 ; }
@@ -35,7 +35,8 @@ 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 int kho_debugfs_fdt_add (struct kho_debugfs *dbg,const char *name, -const void *fdt,bool root) {return 0 ; } +const void *fdt,size_t size, +bool root) {return 0 ; }static inline void kho_debugfs_fdt_remove (struct kho_debugfs *dbg,void *fdt) { }#endif /* CONFIG_KEXEC_HANDOVER_DEBUGFS */
kernel/liveupdate/luo_core.c +2 -1
@@ -172,7 +172,8 @@ static int __init luo_fdt_setup(void)if (err) goto exit_free; - err =kho_add_subtree (LUO_FDT_KHO_ENTRY_NAME , fdt_out); + err =kho_add_subtree (LUO_FDT_KHO_ENTRY_NAME , fdt_out, +fdt_totalsize (fdt_out));if (err) goto exit_free; luo_global.fdt_out = fdt_out;
lib/test_kho.c +2 -1
@@ -143,7 +143,8 @@ static int kho_test_preserve(struct kho_test_state *state)if (err) goto err_unpreserve_data; - err =kho_add_subtree (KHO_TEST_FDT ,folio_address (state->fdt)); + err =kho_add_subtree (KHO_TEST_FDT ,folio_address (state->fdt), +fdt_totalsize (folio_address (state->fdt)));if (err) goto err_unpreserve_data;
mm/memblock.c +1 -1
@@ -2488,7 +2488,7 @@ static int __init prepare_kho_fdt(void)if (err) goto err_unpreserve_fdt; - err =kho_add_subtree (MEMBLOCK_KHO_FDT , fdt); + err =kho_add_subtree (MEMBLOCK_KHO_FDT , fdt,fdt_totalsize (fdt));if (err) goto err_unpreserve_fdt;
Signature · 1 line
2.52.0
Re: [PATCH v9 1/6] kho: add size parameter to kho_add_subtree()
Quoted 25 lines · Breno Leitao
kho_add_subtree()assumes the fdt argument is always an FDT and callsfdt_totalsize()on it in the debugfs code path. This assumption will break if a caller passes arbitrary data instead of an FDT.When
CONFIG_KEXEC_HANDOVER_DEBUGFSis enabled,kho_debugfs_fdt_add()calls__kho_debugfs_fdt_add(), which executes:f->wrapper.size = fdt_totalsize(fdt);Fix this by adding an explicit size parameter to
kho_add_subtree()so callers specify the blob size. This allows subtrees to contain arbitrary data formats, not just FDTs. Update all callers:-
memblock.c: usefdt_totalsize(fdt)
-luo_core.c: usefdt_totalsize(fdt_out)
-test_kho.c: usefdt_totalsize()
-kexec_handover.c(root fdt): usefdt_totalsize(kho_out.fdt)Also update
__kho_debugfs_fdt_add()to receive the size explicitly instead of computing it internally viafdt_totalsize(). Inkho_in_debugfs_init(), passfdt_totalsize()for the root FDT and sub-blobs since all current users are FDTs. A subsequent patch will persist the size in the KHO FDT so the incoming side can handle non-FDT blobs correctly.
Quoted 3 lines
Suggested-by Pratyush Yadav <[email protected]>Reviewed-by Mike Rapoport (Microsoft) <[email protected]>Signed-off-by Breno Leitao <[email protected]>
[...]
Signature · 2 lines
Regards, Pratyush Yadav
PATCH v9 2/6 kho: rename fdt parameter to blob in kho_add/remove_subtree()
In reply to Breno LeitaoSince kho_add_subtree() now accepts arbitrary data blobs (not just FDTs), rename the parameter from 'fdt' to 'blob' to better reflect its purpose. Apply the same rename to kho_remove_subtree() for consistency.
Also rename kho_debugfs_fdt_add() and kho_debugfs_fdt_remove() to kho_debugfs_blob_add() and kho_debugfs_blob_remove() respectively, with the same parameter rename from 'fdt' to 'blob'.
--- Documentation/admin-guide/mm/kho.rst | 2 +- include/linux/kexec_handover.h | 8 +++---- kernel/liveupdate/kexec_handover.c | 33 +++++++++++++++-------------- kernel/liveupdate/kexec_handover_debugfs.c | 25 +++++++++++----------- kernel/liveupdate/kexec_handover_internal.h | 16 +++++++------- 5 files changed, 43 insertions(+), 41 deletions(-)
Documentation/admin-guide/mm/kho.rst +1 -1
@@ -80,5 +80,5 @@ stabilized. it finished to interpret their metadata. ``/sys/kernel/debug/kho/in/sub_fdts/`` - Similar to ``kho/out/sub_fdts/``, but contains sub FDT blobs + Similar to ``kho/out/sub_fdts/``, but contains sub blobs of KHO producers passed from the old kernel.
include/linux/kexec_handover.h +4 -4
@@ -32,8 +32,8 @@ void kho_restore_free(void *mem);struct folio *kho_restore_folio (phys_addr_t phys);struct page *kho_restore_pages (phys_addr_t phys,unsigned long nr_pages);void *kho_restore_vmalloc (const struct kho_vmalloc *preservation); -int kho_add_subtree (const char *name,void *fdt,size_t size); -void kho_remove_subtree (void *fdt); +int kho_add_subtree (const char *name,void *blob,size_t size); +void kho_remove_subtree (void *blob);int kho_retrieve_subtree (const char *name,phys_addr_t *phys);void kho_memory_init (void );
@@ -97,12 +97,12 @@ static inline void *kho_restore_vmalloc(const struct kho_vmalloc *preservation)return NULL ; } -static inline int kho_add_subtree (const char *name,void *fdt,size_t size) +static inline int kho_add_subtree (const char *name,void *blob,size_t size) {return -EOPNOTSUPP ; } -static inline void kho_remove_subtree (void *fdt) { } +static inline void kho_remove_subtree (void *blob) { }static inline int kho_retrieve_subtree (const char *name,phys_addr_t *phys) {
kernel/liveupdate/kexec_handover.c +17 -16
@@ -749,13 +749,13 @@ static void __init kho_reserve_scratch(void) }/** -* kho_add_subtree - record the physical address of a sub FDT in KHO root tree. +* kho_add_subtree - record the physical address of a sub blob in KHO root tree. * @name: name of the sub tree. -* @fdt: the sub tree blob. +* @blob: the sub tree blob. * @size: size of the blob in bytes. * * Creates a new child node named @name in KHO root FDT and records -* the physical address of @fdt. The pages of @fdt must also be preserved +* the physical address of @blob. The pages of @blob must also be preserved * by KHO for the new kernel to retrieve it after kexec. * * A debugfs blob entry is also created at
@@ -764,9 +764,9 @@ static void __init kho_reserve_scratch(void)* * Return: 0 on success, error code on failure */ -int kho_add_subtree (const char *name,void *fdt,size_t size) +int kho_add_subtree (const char *name,void *blob,size_t size) { -phys_addr_t phys =virt_to_phys (fdt); +phys_addr_t phys =virt_to_phys (blob);void *root_fdt = kho_out.fdt;int err = -ENOMEM ;int off, fdt_err;
@@ -789,7 +789,8 @@ int kho_add_subtree(const char *name, void *fdt, size_t size)if (err <0 ) goto out_pack; -WARN_ON_ONCE (kho_debugfs_fdt_add (&kho_out.dbg, name, fdt, size, false)); +WARN_ON_ONCE (kho_debugfs_blob_add (&kho_out.dbg, name, blob, + size, false)); out_pack:fdt_pack (root_fdt);
@@ -798,9 +799,9 @@ int kho_add_subtree(const char *name, void *fdt, size_t size) }EXPORT_SYMBOL_GPL (kho_add_subtree); -void kho_remove_subtree (void *fdt) +void kho_remove_subtree (void *blob) { -phys_addr_t target_phys =virt_to_phys (fdt); +phys_addr_t target_phys =virt_to_phys (blob);void *root_fdt = kho_out.fdt;int off;int err;
@@ -822,7 +823,7 @@ void kho_remove_subtree(void *fdt)if ((phys_addr_t)*val == target_phys) {fdt_del_node (root_fdt, off); -kho_debugfs_fdt_remove (&kho_out.dbg, fdt); +kho_debugfs_blob_remove (&kho_out.dbg, blob);break ; } }
@@ -1310,11 +1311,11 @@ bool is_kho_boot(void)EXPORT_SYMBOL_GPL (is_kho_boot);/** -* kho_retrieve_subtree - retrieve a preserved sub FDT by its name. -* @name: the name of the sub FDT passed to kho_add_subtree(). -* @phys: if found, the physical address of the sub FDT is stored in @phys. +* kho_retrieve_subtree - retrieve a preserved sub blob by its name. +* @name: the name of the sub blob passed to kho_add_subtree(). +* @phys: if found, the physical address of the sub blob is stored in @phys. * -* Retrieve a preserved sub FDT named @name and store its physical +* Retrieve a preserved sub blob named @name and store its physical * address in @phys. * * Return: 0 on success, error code on failure
@@ -1452,9 +1453,9 @@ static __init int kho_init(void)return 0 ; } -WARN_ON_ONCE (kho_debugfs_fdt_add (&kho_out.dbg,"fdt" , - kho_out.fdt, -fdt_totalsize (kho_out.fdt), true)); +WARN_ON_ONCE (kho_debugfs_blob_add (&kho_out.dbg,"fdt" , + kho_out.fdt, +fdt_totalsize (kho_out.fdt), true));return 0 ;
kernel/liveupdate/kexec_handover_debugfs.c +13 -12
@@ -24,8 +24,9 @@ struct fdt_debugfs {struct dentry *file; }; -static int __kho_debugfs_fdt_add (struct list_head *list,struct dentry *dir, -const char *name,const void *fdt,size_t size) +static int __kho_debugfs_blob_add (struct list_head *list,struct dentry *dir, +const char *name,const void *blob, +size_t size) {struct fdt_debugfs *f;struct dentry *file;
@@ -34,7 +35,7 @@ static int __kho_debugfs_fdt_add(struct list_head *list, struct dentry *dir,if (!f)return -ENOMEM ; - f->wrapper.data = (void *)fdt; + f->wrapper.data = (void *)blob; f->wrapper.size = size; file =debugfs_create_blob (name,0400 , dir, &f->wrapper);
@@ -49,8 +50,8 @@ static int __kho_debugfs_fdt_add(struct list_head *list, struct dentry *dir,return 0 ; } -int kho_debugfs_fdt_add (struct kho_debugfs *dbg,const char *name, -const void *fdt,size_t size,bool root) +int kho_debugfs_blob_add (struct kho_debugfs *dbg,const char *name, +const void *blob,size_t size,bool root) {struct dentry *dir;
@@ -59,15 +60,15 @@ int kho_debugfs_fdt_add(struct kho_debugfs *dbg, const char *name,else dir = dbg->sub_fdt_dir; -return __kho_debugfs_fdt_add (&dbg->fdt_list, dir, name, fdt, size); +return __kho_debugfs_blob_add (&dbg->fdt_list, dir, name, blob, size); } -void kho_debugfs_fdt_remove (struct kho_debugfs *dbg,void *fdt) +void kho_debugfs_blob_remove (struct kho_debugfs *dbg,void *blob) {struct fdt_debugfs *ff;list_for_each_entry (ff, &dbg->fdt_list, list) { -if (ff->wrapper.data == fdt) { +if (ff->wrapper.data == blob) {debugfs_remove (ff->file);list_del (&ff->list);kfree (ff);
@@ -113,8 +114,8 @@ __init void kho_in_debugfs_init(struct kho_debugfs *dbg, const void *fdt) goto err_rmdir; } - err =__kho_debugfs_fdt_add (&dbg->fdt_list, dir,"fdt" , fdt, -fdt_totalsize (fdt)); + err =__kho_debugfs_blob_add (&dbg->fdt_list, dir,"fdt" , fdt, +fdt_totalsize (fdt));if (err) goto err_rmdir;
@@ -133,8 +134,8 @@ __init void kho_in_debugfs_init(struct kho_debugfs *dbg, const void *fdt)continue ; } sub_fdt =phys_to_virt (*fdt_phys); - err =__kho_debugfs_fdt_add (&dbg->fdt_list, sub_fdt_dir, name, - sub_fdt,fdt_totalsize (sub_fdt)); + err =__kho_debugfs_blob_add (&dbg->fdt_list, sub_fdt_dir, name, + sub_fdt,fdt_totalsize (sub_fdt));if (err) {pr_warn ("failed to add fdt %s to debugfs: %pe\n" , name,ERR_PTR (err));
kernel/liveupdate/kexec_handover_internal.h +8 -8
@@ -26,19 +26,19 @@ extern unsigned int kho_scratch_cnt;int 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); -int kho_debugfs_fdt_add (struct kho_debugfs *dbg,const char *name, -const void *fdt,size_t size,bool root); -void kho_debugfs_fdt_remove (struct kho_debugfs *dbg,void *fdt); +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_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 int kho_debugfs_fdt_add (struct kho_debugfs *dbg,const char *name, -const void *fdt,size_t size, -bool root) {return 0 ; } -static inline void kho_debugfs_fdt_remove (struct kho_debugfs *dbg, -void *fdt) { } +static inline int kho_debugfs_blob_add (struct kho_debugfs *dbg, +const char *name,const void *blob, +size_t size,bool root) {return 0 ; } +static inline void kho_debugfs_blob_remove (struct kho_debugfs *dbg, +void *blob) { }#endif /* CONFIG_KEXEC_HANDOVER_DEBUGFS */ #ifdef CONFIG_KEXEC_HANDOVER_DEBUG
Signature · 1 line
2.52.0
PATCH v9 3/6 kho: persist blob size in KHO FDT
In reply to Breno Leitaokho_add_subtree() accepts a size parameter but only forwards it to debugfs. The size is not persisted in the KHO FDT, so it is lost across kexec. This makes it impossible for the incoming kernel to determine the blob size without understanding the blob format.
Store the blob size as a "blob-size" property in the KHO FDT alongside the "preserved-data" physical address. This allows the receiving kernel to recover the size for any blob regardless of format.
Also extend kho_retrieve_subtree() with an optional size output parameter so callers can learn the blob size without needing to understand the blob format. Update all callers to pass NULL for the new parameter.
--- include/linux/kexec_handover.h | 5 +++-- include/linux/kho/abi/kexec_handover.h | 20 ++++++++++++++++---- kernel/liveupdate/kexec_handover.c | 27 ++++++++++++++++++++++----- kernel/liveupdate/kexec_handover_debugfs.c | 3 ++- kernel/liveupdate/luo_core.c | 2 +- lib/test_kho.c | 2 +- mm/memblock.c | 2 +- 7 files changed, 46 insertions(+), 15 deletions(-)
include/linux/kexec_handover.h +3 -2
@@ -34,7 +34,7 @@ struct page *kho_restore_pages(phys_addr_t phys, unsigned long nr_pages);void *kho_restore_vmalloc (const struct kho_vmalloc *preservation);int kho_add_subtree (const char *name,void *blob,size_t size);void kho_remove_subtree (void *blob); -int kho_retrieve_subtree (const char *name,phys_addr_t *phys); +int kho_retrieve_subtree (const char *name,phys_addr_t *phys,size_t *size);void kho_memory_init (void );
@@ -104,7 +104,8 @@ static inline int kho_add_subtree(const char *name, void *blob, size_t size)static inline void kho_remove_subtree (void *blob) { } -static inline int kho_retrieve_subtree (const char *name,phys_addr_t *phys) +static inline int kho_retrieve_subtree (const char *name,phys_addr_t *phys, +size_t *size) {return -EOPNOTSUPP ; }
include/linux/kho/abi/kexec_handover.h +16 -4
@@ -41,25 +41,28 @@* restore the preserved data.:: * * / { -* compatible = "kho-v2"; +* compatible = "kho-v3"; * * preserved-memory-map = <0x...>; * * <subnode-name-1> { * preserved-data = <0x...>; +* blob-size = <0x...>; * }; * * <subnode-name-2> { * preserved-data = <0x...>; +* blob-size = <0x...>; * }; * ... ... * <subnode-name-N> { * preserved-data = <0x...>; +* blob-size = <0x...>; * }; * }; * * Root KHO Node (/): -* - compatible: "kho-v2" +* - compatible: "kho-v3" * * Indentifies the overall KHO ABI version. *
@@ -78,16 +81,25 @@* * Physical address pointing to a subnode data blob that is also * being preserved. +* +* - blob-size: u64 +* +* Size in bytes of the preserved data blob. This is needed because +* blobs may use arbitrary formats (not just FDT), so the size +* cannot be determined from the blob content alone. */ /* The compatible string for the KHO FDT root node. */ -#define KHO_FDT_COMPATIBLE "kho-v2" +#define KHO_FDT_COMPATIBLE "kho-v3"/* The FDT property for the preserved memory map. */ #define KHO_FDT_MEMORY_MAP_PROP_NAME "preserved-memory-map"/* The FDT property for preserved data blobs. */ -#define KHO_FDT_SUB_TREE_PROP_NAME "preserved-data" +#define KHO_SUB_TREE_PROP_NAME "preserved-data" + +/* The FDT property for the size of preserved data blobs. */ +#define KHO_SUB_TREE_SIZE_PROP_NAME "blob-size"/** * DOC: Kexec Handover ABI for vmalloc Preservation
kernel/liveupdate/kexec_handover.c +22 -5
@@ -768,6 +768,7 @@ int kho_add_subtree(const char *name, void *blob, size_t size) {phys_addr_t phys =virt_to_phys (blob);void *root_fdt = kho_out.fdt; +u64 size_u64 = size;int err = -ENOMEM ;int off, fdt_err;
@@ -784,11 +785,16 @@ int kho_add_subtree(const char *name, void *blob, size_t size) goto out_pack; } - err =fdt_setprop (root_fdt, off,KHO_FDT_SUB_TREE_PROP_NAME , + err =fdt_setprop (root_fdt, off,KHO_SUB_TREE_PROP_NAME , &phys,sizeof (phys));if (err <0 ) goto out_pack; + err =fdt_setprop (root_fdt, off,KHO_SUB_TREE_SIZE_PROP_NAME , + &size_u64,sizeof (size_u64)); +if (err <0 ) + goto out_pack; +WARN_ON_ONCE (kho_debugfs_blob_add (&kho_out.dbg, name, blob, size, false));
@@ -817,7 +823,7 @@ void kho_remove_subtree(void *blob)const u64 *val;int len; - val =fdt_getprop (root_fdt, off,KHO_FDT_SUB_TREE_PROP_NAME , &len); + val =fdt_getprop (root_fdt, off,KHO_SUB_TREE_PROP_NAME , &len);if (!val || len !=sizeof (phys_addr_t))continue ;
@@ -1314,13 +1320,14 @@ EXPORT_SYMBOL_GPL(is_kho_boot);* kho_retrieve_subtree - retrieve a preserved sub blob by its name. * @name: the name of the sub blob passed to kho_add_subtree(). * @phys: if found, the physical address of the sub blob is stored in @phys. +* @size: if not NULL and found, the size of the sub blob is stored in @size. * * Retrieve a preserved sub blob named @name and store its physical -* address in @phys. +* address in @phys and optionally its size in @size. * * Return: 0 on success, error code on failure */ -int kho_retrieve_subtree (const char *name,phys_addr_t *phys) +int kho_retrieve_subtree (const char *name,phys_addr_t *phys,size_t *size) {const void *fdt =kho_get_fdt ();const u64 *val;
@@ -1336,12 +1343,22 @@ int kho_retrieve_subtree(const char *name, phys_addr_t *phys)if (offset <0 )return -ENOENT ; - val =fdt_getprop (fdt, offset,KHO_FDT_SUB_TREE_PROP_NAME , &len); + val =fdt_getprop (fdt, offset,KHO_SUB_TREE_PROP_NAME , &len);if (!val || len !=sizeof (*val))return -EINVAL ; *phys = (phys_addr_t)*val; + val =fdt_getprop (fdt, offset,KHO_SUB_TREE_SIZE_PROP_NAME , &len); +if (!val || len !=sizeof (*val)) { +pr_warn ("broken KHO subnode '%s': missing or invalid blob-size property\n" , + name); +return -EINVAL ; + } + +if (size) + *size = (size_t )*val; +return 0 ; }EXPORT_SYMBOL_GPL (kho_retrieve_subtree);
kernel/liveupdate/kexec_handover_debugfs.c +2 -1
@@ -125,7 +125,8 @@ __init void kho_in_debugfs_init(struct kho_debugfs *dbg, const void *fdt)const u64 *fdt_phys;void *sub_fdt; - fdt_phys =fdt_getprop (fdt, child,KHO_FDT_SUB_TREE_PROP_NAME , &len); + fdt_phys =fdt_getprop (fdt, child, +KHO_SUB_TREE_PROP_NAME , &len);if (!fdt_phys)continue ;if (len !=sizeof (*fdt_phys)) {
kernel/liveupdate/luo_core.c +1 -1
@@ -88,7 +88,7 @@ static int __init luo_early_startup(void) }/* Retrieve LUO subtree, and verify its format. */ - err =kho_retrieve_subtree (LUO_FDT_KHO_ENTRY_NAME , &fdt_phys); + err =kho_retrieve_subtree (LUO_FDT_KHO_ENTRY_NAME , &fdt_phys,NULL );if (err) {if (err != -ENOENT ) { pr_err("failed to retrieve FDT '%s' from KHO: %pe\n",
lib/test_kho.c +1 -1
@@ -319,7 +319,7 @@ static int __init kho_test_init(void)if (!kho_is_enabled ())return 0 ; - err =kho_retrieve_subtree (KHO_TEST_FDT , &fdt_phys); + err =kho_retrieve_subtree (KHO_TEST_FDT , &fdt_phys,NULL );if (!err) { err =kho_test_restore (fdt_phys);if (err)
mm/memblock.c +1 -1
@@ -2533,7 +2533,7 @@ static void *__init reserve_mem_kho_retrieve_fdt(void)if (fdt)return fdt; - err =kho_retrieve_subtree (MEMBLOCK_KHO_FDT , &fdt_phys); + err =kho_retrieve_subtree (MEMBLOCK_KHO_FDT , &fdt_phys,NULL );if (err) {if (err != -ENOENT ) pr_warn("failed to retrieve FDT '%s' from KHO: %d\n",
Signature · 1 line
2.52.0
Re: [PATCH v9 3/6] kho: persist blob size in KHO FDT
Quoted 9 lines · Breno Leitao
kho_add_subtree()accepts a size parameter but only forwards it to debugfs. The size is not persisted in the KHO FDT, so it is lost across kexec. This makes it impossible for the incoming kernel to determine the blob size without understanding the blob format.Store the blob size as a "blob-size" property in the KHO FDT alongside the "preserved-data" physical address. This allows the receiving kernel to recover the size for any blob regardless of format.
Quoted 7 lines
Also extend
kho_retrieve_subtree()with an optional size output parameter so callers can learn the blob size without needing to understand the blob format. Update all callers to pass NULL for the new parameter.Reviewed-by Mike Rapoport (Microsoft) <[email protected]>Signed-off-by Breno Leitao <[email protected]>
[...]
Signature · 2 lines
Regards, Pratyush Yadav
PATCH v9 4/6 kho: fix kho_in_debugfs_init() to handle non-FDT blobs
In reply to Breno Leitaokho_in_debugfs_init() calls fdt_totalsize() to determine blob sizes, which assumes all blobs are FDTs. This breaks for non-FDT blobs like struct kho_kexec_metadata.
Fix this by reading the "blob-size" property from the FDT (persisted by kho_add_subtree()) instead of calling fdt_totalsize(). Also rename local variables from fdt_phys/sub_fdt to blob_phys/blob for consistency with the non-FDT-specific naming.
--- kernel/liveupdate/kexec_handover_debugfs.c | 32 ++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 11 deletions(-)
kernel/liveupdate/kexec_handover_debugfs.c +21 -11
@@ -122,24 +122,34 @@ __init void kho_in_debugfs_init(struct kho_debugfs *dbg, const void *fdt)fdt_for_each_subnode (child, fdt,0 ) {int len =0 ;const char *name =fdt_get_name (fdt, child,NULL ); -const u64 *fdt_phys; -void *sub_fdt; +const u64 *blob_phys; +const u64 *blob_size; +void *blob; - fdt_phys =fdt_getprop (fdt, child, + blob_phys =fdt_getprop (fdt, child,KHO_SUB_TREE_PROP_NAME , &len); -if (!fdt_phys) +if (!blob_phys)continue ; -if (len !=sizeof (*fdt_phys)) { -pr_warn ("node %s prop fdt has invalid length: %d\n" , - name, len); +if (len !=sizeof (*blob_phys)) { +pr_warn ("node %s prop %s has invalid length: %d\n" , + name,KHO_SUB_TREE_PROP_NAME , len);continue ; } - sub_fdt =phys_to_virt (*fdt_phys); + + blob_size =fdt_getprop (fdt, child, +KHO_SUB_TREE_SIZE_PROP_NAME , &len); +if (!blob_size || len !=sizeof (*blob_size)) { +pr_warn ("node %s missing or invalid %s property\n" , + name,KHO_SUB_TREE_SIZE_PROP_NAME ); +continue ; + } + + blob =phys_to_virt (*blob_phys); err =__kho_debugfs_blob_add (&dbg->fdt_list, sub_fdt_dir, name, - sub_fdt,fdt_totalsize (sub_fdt)); + blob, *blob_size);if (err) { -pr_warn ("failed to add fdt %s to debugfs: %pe\n" , name, -ERR_PTR (err)); +pr_warn ("failed to add blob %s to debugfs: %pe\n" , + name,ERR_PTR (err));continue ; } }
Signature · 1 line
2.52.0
Re: [PATCH v9 4/6] kho: fix kho_in_debugfs_init() to handle non-FDT blobs
Quoted 10 lines · Breno Leitao
kho_in_debugfs_init()callsfdt_totalsize()to determine blob sizes, which assumes all blobs are FDTs. This breaks for non-FDT blobs like structkho_kexec_metadata.Fix this by reading the "blob-size" property from the FDT (persisted by
kho_add_subtree()) instead of callingfdt_totalsize(). Also rename local variables from fdt_phys/sub_fdt to blob_phys/blob for consistency with the non-FDT-specific naming.Signed-off-by Breno Leitao <[email protected]>
[...]
Signature · 2 lines
Regards, Pratyush Yadav
PATCH v9 5/6 kho: kexec-metadata: track previous kernel chain
In reply to Breno LeitaoUse Kexec Handover (KHO) to pass the previous kernel's version string and the number of kexec reboots since the last cold boot to the next kernel, and print it at boot time.
Example output:
[ 0.000000] KHO: exec from: 6.19.0-rc4-next-20260107 (count 1)
Motivation
==========
Bugs that only reproduce when kexecing from specific kernel versions are difficult to diagnose. These issues occur when a buggy kernel kexecs into a new kernel, with the bug manifesting only in the second kernel.
Recent examples include the following commits:
* commit eb2266312507 ("x86/boot: Fix page table access in 5-level to 4-level paging transition")
* commit 77d48d39e991 ("efistub/tpm: Use ACPI reclaim memory for event log to avoid corruption")
* commit 64b45dd46e15 ("x86/efi: skip memattr table on kexec boot")
As kexec-based reboots become more common, these version-dependent bugs are appearing more frequently. At scale, correlating crashes to the previous kernel version is challenging, especially when issues only occur in specific transition scenarios.
Implementation
==============
The kexec metadata is stored as a plain C struct (struct kho_kexec_metadata) rather than FDT format, for simplicity and direct field access. It is registered via kho_add_subtree() as a separate subtree, keeping it independent from the core KHO ABI. This design choice:
- Keeps the core KHO ABI minimal and stable
- Allows the metadata format to evolve independently
- Avoids requiring version bumps for all KHO consumers (LUO, etc.) when the metadata format changes
The struct kho_kexec_metadata contains two fields:
- previous_release: The kernel version that initiated the kexec
- kexec_count: Number of kexec boots since last cold boot
On cold boot, kexec_count starts at 0 and increments with each kexec. The count helps identify issues that only manifest after multiple consecutive kexec reboots.
--- include/linux/kho/abi/kexec_metadata.h | 46 ++++++++++++++++ kernel/liveupdate/kexec_handover.c | 98 ++++++++++++++++++++++++++++++++++ 2 files changed, 144 insertions(+)
include/linux/kho/abi/kexec_metadata.h new file +46 -0
@@ -0,0 +1,46 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +/** +* DOC: Kexec Metadata ABI +* +* The "kexec-metadata" subtree stores optional metadata about the kexec chain. +* It is registered via kho_add_subtree(), keeping it independent from the core +* KHO ABI. This allows the metadata format to evolve without affecting other +* KHO consumers. +* +* The metadata is stored as a plain C struct rather than FDT format for +* simplicity and direct field access. +* +* Copyright (c) 2026 Meta Platforms, Inc. and affiliates. +* Copyright (c) 2026 Breno Leitao <[email protected]> +*/ + +#ifndef _LINUX_KHO_ABI_KEXEC_METADATA_H +#define _LINUX_KHO_ABI_KEXEC_METADATA_H + +#include <linux/types.h> +#include <linux/utsname.h> + +#define KHO_KEXEC_METADATA_VERSION 1 + +/** +* struct kho_kexec_metadata - Kexec metadata passed between kernels +* @version: ABI version of this struct (must be first field) +* @previous_release: Kernel version string that initiated the kexec +* @kexec_count: Number of kexec boots since last cold boot +* +* This structure is preserved across kexec and allows the new kernel to +* identify which kernel it was booted from and how many kexec reboots +* have occurred. +* +* __NEW_UTS_LEN is part of uABI, so it safe to use it in here. +*/ +struct kho_kexec_metadata { +u32 version; +char previous_release[__NEW_UTS_LEN +1 ]; +u32 kexec_count; +} __packed; + +#define KHO_METADATA_NODE_NAME "kexec-metadata" + +#endif /* _LINUX_KHO_ABI_KEXEC_METADATA_H */
kernel/liveupdate/kexec_handover.c +98 -0
123 lines not on this page · raw message
Signature · 1 line
2.52.0
Re: [PATCH v9 5/6] kho: kexec-metadata: track previous kernel chain
Quoted 46 lines · Breno Leitao
Use Kexec Handover (KHO) to pass the previous kernel's version string and the number of kexec reboots since the last cold boot to the next kernel, and print it at boot time.
Example output:
[ 0.000000] KHO: exec from: 6.19.0-rc4-next-20260107 (count 1)Motivation
==========Bugs that only reproduce when kexecing from specific kernel versions are difficult to diagnose. These issues occur when a buggy kernel kexecs into a new kernel, with the bug manifesting only in the second kernel.
Recent examples include the following commits:
* commit
eb2266312507("x86/boot: Fix page table access in 5-level to 4-level paging transition")
* commit77d48d39e991("efistub/tpm: Use ACPI reclaim memory for event log to avoid corruption")
* commit64b45dd46e15("x86/efi: skip memattr table on kexec boot")As kexec-based reboots become more common, these version-dependent bugs are appearing more frequently. At scale, correlating crashes to the previous kernel version is challenging, especially when issues only occur in specific transition scenarios.
Implementation
==============The kexec metadata is stored as a plain C struct (struct
kho_kexec_metadata) rather than FDT format, for simplicity and direct field access. It is registered viakho_add_subtree()as a separate subtree, keeping it independent from the core KHO ABI. This design choice:- Keeps the core KHO ABI minimal and stable
- Allows the metadata format to evolve independently
- Avoids requiring version bumps for all KHO consumers (LUO, etc.) when the metadata format changesThe struct
kho_kexec_metadatacontains two fields:
-previous_release: The kernel version that initiated the kexec
-kexec_count: Number of kexec boots since last cold boot
Quoted 7 lines
On cold boot,
kexec_countstarts at 0 and increments with each kexec. The count helps identify issues that only manifest after multiple consecutive kexec reboots.Acked-by SeongJae Park <[email protected]>Reviewed-by Mike Rapoport (Microsoft) <[email protected]>Signed-off-by Breno Leitao <[email protected]>
[...]
Signature · 2 lines
Regards, Pratyush Yadav
PATCH v9 6/6 kho: document kexec-metadata tracking feature
In reply to Breno LeitaoAdd documentation for the kexec-metadata feature that tracks the previous kernel version and kexec boot count across kexec reboots. This helps diagnose bugs that only reproduce when kexecing from specific kernel versions.
--- Documentation/admin-guide/mm/kho.rst | 39 ++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+)
Documentation/admin-guide/mm/kho.rst +39 -0
@@ -42,6 +42,45 @@ For example, if you used ``reserve_mem`` command line parameter to create an early memory reservation, the new kernel will have that memory at the same physical address as the old kernel. +Kexec Metadata +============== + +KHO automatically tracks metadata about the kexec chain, passing information +about the previous kernel to the next kernel. This feature helps diagnose +bugs that only reproduce when kexecing from specific kernel versions. + +On each KHO kexec, the kernel logs the previous kernel's version and the +number of kexec reboots since the last cold boot:: + + [ 0.000000] KHO: exec from: 6.19.0-rc4-next-20260107 (count 1) + +The metadata includes: + +``previous_release`` + The kernel version string (from ``uname -r``) of the kernel that + initiated the kexec. + +``kexec_count`` + The number of kexec boots since the last cold boot. On cold boot, + this counter starts at 0 and increments with each kexec. This helps + identify issues that only manifest after multiple consecutive kexec + reboots. + +Use Cases +--------- + +This metadata is particularly useful for debugging kexec transition bugs, +where a buggy kernel kexecs into a new kernel and the bug manifests only +in the second kernel. Examples of such bugs include: + +- Memory corruption from the previous kernel affecting the new kernel +- Incorrect hardware state left by the previous kernel +- Firmware/ACPI state issues that only appear in kexec scenarios + +At scale, correlating crashes to the previous kernel version enables +faster root cause analysis when issues only occur in specific kernel +transition scenarios. + debugfs Interfaces ==================
Signature · 1 line
2.52.0
Pratyush Yadav
maintainerHi Andrew,
Quoted 3 lines · Breno Leitao
Use Kexec Handover (KHO) to pass the previous kernel's version string and the number of kexec reboots since the last cold boot to the next kernel, and print it at boot time.
This series is good to go I think. Please include it in the content for the next merge window.
[...]
Signature · 2 lines
Regards, Pratyush Yadav