kho, liveupdate: KHO/LUO observability
Subsystems (7)
cover kho, liveupdate: KHO/LUO observability
At Meta, we are moving towards using live update on hypervisors whose VMs can't be migrated away first. We also want to preserve service fd stores across systemctl kexec.
Our kernel rollout is driven by health checks from each host. For example, an increase in rejected handovers or retrieval failures may be a reason to stop a rollout, and the bootmem size and sequence number help us understand what is happening on which hosts. The series exposes:
- how much memory KHO set aside
- whether the new kernel accepted the incoming handover
- whether LUO could give back the state that userspace handed over
We expose these in sysfs so the collector can read them without opening /dev/liveupdate, which starts deserialisation, or depending on debugfs or the kernel log.
I also noticed that the incoming kexec metadata page stays reserved after boot, so free it once its contents have been copied.
Chris Down (9):
kho: Reclaim the metadata page left reserved after kexec
kho: Make bootmem reservations visible to fleet monitoring
liveupdate: Make failed retrieves distinguishable from dropped files selftests/liveupdate: Catch incorrect file accounting across kexec selftests/kho: Catch missing or zero bootmem reports before kexec
kho: Expose rejected handovers that look like cold boots
kho: Report how much handover memory is preserved and restored
liveupdate: Expose the sequence number for consecutive live updates selftests/liveupdate: Check handover revival, sequence and memory
stats
.../ABI/testing/sysfs-class-misc-liveupdate | 56 ++++ .../ABI/testing/sysfs-kernel-kexec-kdump | 30 ++ Documentation/admin-guide/mm/kho.rst | 19 +- Documentation/userspace-api/liveupdate.rst | 8 + MAINTAINERS | 1 + include/linux/kexec_handover.h | 3 + kernel/kexec_core.c | 26 +- kernel/liveupdate/kexec_handover.c | 82 +++++- kernel/liveupdate/luo_core.c | 58 ++++ kernel/liveupdate/luo_file.c | 16 +- kernel/liveupdate/luo_internal.h | 34 +++ kernel/liveupdate/luo_session.c | 6 + tools/testing/selftests/kho/init.c | 24 ++ tools/testing/selftests/kho/vmtest.sh | 1 + tools/testing/selftests/liveupdate/Makefile | 1 + tools/testing/selftests/liveupdate/init.c | 5 + .../selftests/liveupdate/luo_handover_stats.c | 258 ++++++++++++++++++ .../selftests/liveupdate/run-vmtests.sh | 1 + tools/testing/selftests/liveupdate/vmtest.sh | 2 + 19 files changed, 624 insertions(+), 7 deletions(-) create mode 100644 Documentation/ABI/testing/sysfs-class-misc-liveupdate create mode 100644 tools/testing/selftests/liveupdate/luo_handover_stats.c
base-commit: a0dc8eddbfdb6dd9c5c2b70eb66ab49cb1978425
Signature · 1 line
2.54.0
PATCH 1/9 kho: Reclaim the metadata page left reserved after kexec
After a KHO kexec, the new kernel keeps the page holding the previous kernel's kexec metadata reserved for as long as it runs. It only needs the page once, since kho_in_kexec_metadata() copies the previous release and the kexec count out of it at boot, and nothing reads it again.
Free it with kho_restore_free() once copying is complete.
--- Documentation/admin-guide/mm/kho.rst | 4 +++- kernel/liveupdate/kexec_handover.c | 10 +++++++--- 2 files changed, 10 insertions(+), 4 deletions(-)
Documentation/admin-guide/mm/kho.rst +3 -1
@@ -120,4 +120,6 @@ stabilized. ``/sys/kernel/debug/kho/in/sub_fdts/`` Similar to ``kho/out/sub_fdts/``, but contains sub blobs - of KHO producers passed from the old kernel. + of KHO producers passed from the old kernel. A blob disappears + once the kernel has read and freed it, as ``kexec-metadata`` does + during boot.
kernel/liveupdate/kexec_handover.c +7 -3
@@ -1808,6 +1808,9 @@ static void __init kho_in_kexec_metadata(void)pr_info ("exec from: %s (count %u)\n" , kho_in.previous_release, kho_in.kexec_count); + +kho_debugfs_blob_remove (&kho_in.dbg, metadata); +kho_restore_free (metadata); }/*
@@ -1885,14 +1888,15 @@ static __init int kho_init(void)if (err) goto err_free_fdt; +if (fdt) +kho_in_debugfs_init (&kho_in.dbg, fdt); + err =kho_kexec_metadata_init (fdt);if (err) goto err_free_fdt; -if (fdt) { -kho_in_debugfs_init (&kho_in.dbg, fdt); +if (fdt)return 0 ; - }for (int i =0 ; i < kho_bootmem_cnt; i++) {unsigned long base_pfn =PHYS_PFN (kho_bootmem[i].addr);
Signature · 1 line
2.54.0
Re: [PATCH 1/9] kho: Reclaim the metadata page left reserved after kexec
Quoted 4 lines · Chris Down
After a KHO kexec, the new kernel keeps the page holding the previous kernel's kexec metadata reserved for as long as it runs. It only needs the page once, since
kho_in_kexec_metadata()copies the previous release and the kexec count out of it at boot, and nothing reads it again.
Good catch.
Quoted 5 lines
Free it with
kho_restore_free()once copying is complete.Fixes 76aa46b9e404 ("kho: kexec-metadata: track previous kernel chain")Signed-off-by Chris Down <[email protected]>
Re: [PATCH 1/9] kho: Reclaim the metadata page left reserved after kexec
In reply to Chris DownQuoted 8 lines
After a KHO kexec, the new kernel keeps the page holding the previous kernel's kexec metadata reserved for as long as it runs. It only needs the page once, since
kho_in_kexec_metadata()copies the previous release and the kexec count out of it at boot, and nothing reads it again.Free it with
kho_restore_free()once copying is complete.Fixes 76aa46b9e404 ("kho: kexec-metadata: track previous kernel chain")
Do we really need to apply this to stable? It behaves correctly, and your patch performs a minor optimization by releasing a single page back to the system.
Quoted 29 lines
Signed-off-by Chris Down <[email protected]>Documentation/admin-guide/mm/kho.rst +3
-1@@ -120,4 +120,6 @@ stabilized. ``/sys/kernel/debug/kho/in/sub_fdts/`` Similar to ``kho/out/sub_fdts/``, but contains sub blobs - of KHO producers passed from the old kernel. + of KHO producers passed from the old kernel. A blob disappears + once the kernel has read and freed it, as ``kexec-metadata`` does + during boot.kernel/liveupdate/kexec_handover.c +3
-0@@ -1782,6 +1782,9 @@ static void __init kho_in_kexec_metadata(void)pr_info ("exec from: %s (count %u)\n" , kho_in.previous_release, kho_in.kexec_count); + +kho_debugfs_blob_remove (&kho_in.dbg, metadata); +kho_restore_free (metadata); }/*
kernel/liveupdate/kexec_handover.c static __init int kho_init(void) · line 1867
Quoted 6 lines
kernel/liveupdate/kexec_handover.c +3
-0@@ -1859,14 +1862,15 @@ static __init int kho_init(void)if (err) goto err_free_fdt; +if (fdt) +kho_in_debugfs_init (&kho_in.dbg, fdt); +
so add debugfs node here.
kernel/liveupdate/kexec_handover.c static __init int kho_init(void) · line 1894
Quoted 1 line
kernel/liveupdate/kexec_handover.c +0
-0err =kho_kexec_metadata_init (fdt);
Remove the kexec metadata node here. While this is somewhat unintuitive, I do not see a better alternative.
kernel/liveupdate/kexec_handover.c static __init int kho_init(void) · line 1902
Quoted 11 lines
kernel/liveupdate/kexec_handover.c +1
-3if (err) goto err_free_fdt; -if (fdt) { -kho_in_debugfs_init (&kho_in.dbg, fdt); +if (fdt)return 0 ; - }for (int i =0 ; i < kho_bootmem_cnt; i++) {unsigned long base_pfn =PHYS_PFN (kho_bootmem[i].addr);
Signature · 1 line
Pasha
Re: [PATCH 1/9] kho: Reclaim the metadata page left reserved after kexec
Hi Pasha,
Quoted 5 lines · Pasha Tatashin
Quoted 1 line
Fixes 76aa46b9e404 ("kho: kexec-metadata: track previous kernel chain")Do we really need to apply this to stable? It behaves correctly, and your patch performs a minor optimization by releasing a single page back to the system.
No, I don't think it's worth a backport, since it's only one page per boot. I'll drop the Fixes tag in v2.
Thanks for the review!
Chris
[email protected]
AI reviewRe: [PATCH 1/9] kho: Reclaim the metadata page left reserved after kexec
In reply to Chris DownSashiko has reviewed this patch and found no issues.
Quoted 9 lines
After a KHO kexec, the new kernel keeps the page holding the previous kernel's kexec metadata reserved for as long as it runs. It only needs the page once, since
kho_in_kexec_metadata()copies the previous release and the kexec count out of it at boot, and nothing reads it again.Free it with
kho_restore_free()once copying is complete.Fixes 76aa46b9e404 ("kho: kexec-metadata: track previous kernel chain")Signed-off-by Chris Down <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Pasha Tatashin
maintainerRe: [PATCH 1/9] kho: Reclaim the metadata page left reserved after kexec
In reply to Chris DownQuoted 46 lines · Chris Down
After a KHO kexec, the new kernel keeps the page holding the previous kernel's kexec metadata reserved for as long as it runs. It only needs the page once, since
kho_in_kexec_metadata()copies the previous release and the kexec count out of it at boot, and nothing reads it again.Free it with
kho_restore_free()once copying is complete.Fixes 76aa46b9e404 ("kho: kexec-metadata: track previous kernel chain")Signed-off-by Chris Down <[email protected]>--- Documentation/admin-guide/mm/kho.rst | 4 +++- kernel/liveupdate/kexec_handover.c | 10 +++++++--- 2 files changed, 10 insertions(+), 4 deletions(-)Documentation/admin-guide/mm/kho.rst +3
-1@@ -120,4 +120,6 @@ stabilized. ``/sys/kernel/debug/kho/in/sub_fdts/`` Similar to ``kho/out/sub_fdts/``, but contains sub blobs - of KHO producers passed from the old kernel. + of KHO producers passed from the old kernel. A blob disappears + once the kernel has read and freed it, as ``kexec-metadata`` does + during boot.kernel/liveupdate/kexec_handover.c +5
-0@@ -1808,6 +1808,9 @@ static void __init kho_in_kexec_metadata(void)pr_info ("exec from: %s (count %u)\n" , kho_in.previous_release, kho_in.kexec_count); + +kho_debugfs_blob_remove (&kho_in.dbg, metadata); +kho_restore_free (metadata); }/* @@ -1885,14 +1888,15 @@ static __init int kho_init(void)if (err) goto err_free_fdt; +if (fdt) +kho_in_debugfs_init (&kho_in.dbg, fdt);
kernel/liveupdate/kexec_handover.c static __init int kho_init(void) · line 1895
Quoted 10 lines
kernel/liveupdate/kexec_handover.c +2
-3+ err =kho_kexec_metadata_init (fdt);if (err) goto err_free_fdt; -if (fdt) { -kho_in_debugfs_init (&kho_in.dbg, fdt); +if (fdt)return 0 ; - }
This re-ordering can be removed, now that we applied:
https://lore.kernel.org/all/179508700586.361583.12491114908870226409.b4-ty@b4/
Quoted 3 lines
kernel/liveupdate/kexec_handover.c +0
-0for (int i =0 ; i < kho_bootmem_cnt; i++) {unsigned long base_pfn =PHYS_PFN (kho_bootmem[i].addr);
Signature · 1 line
Pasha
PATCH 2/9 kho: Make bootmem reservations visible to fleet monitoring
In reply to Chris DownWe want to use live update at Meta to upgrade hypervisors whose VMs can't be migrated away first. But this poses a problem: whether we can enable KHO on a class of host depends on how much memory it leaves available for unmovable allocations. In an early test, a 64 GiB host with hugetlb_cma=6G set aside about 30 GiB of bootmem, which the running kernel can only use for movable allocations.
The reservation varies with the kernel, memory size, NUMA layout and command line. Our fleet collector needs the actual size from each host so we can decide where to enable KHO and catch a kernel release that takes those hosts over their bootmem budget.
Today the collector would have to sum kho/out/bootmem_len in debugfs, which isn't a userspace ABI. In /proc/meminfo, free bootmem contributes to CmaFree, but the reservation doesn't contribute to CmaTotal. The cma count in /proc/zoneinfo includes bootmem after a cold boot but not after a KHO kexec. On an 8 GiB QEMU guest booted with kho_bootmem=32M,1536M,512M:
CmaTotal CmaFree zoneinfo cma (all zones)
cold boot 0 kB 2127872 kB 2129920 kB
KHO kexec 0 kB 881336 kB 0 kBEven if bootmem becomes a CMA area, CmaTotal will still include other areas such as hugetlb CMA, so inferring the bootmem size is still error-prone.
Let's report the total bootmem reservation in bytes at /sys/kernel/kexec/kho_bootmem_size.
--- .../ABI/testing/sysfs-kernel-kexec-kdump | 8 ++++++++ Documentation/admin-guide/mm/kho.rst | 9 +++++++++ include/linux/kexec_handover.h | 1 + kernel/kexec_core.c | 13 +++++++++++++ kernel/liveupdate/kexec_handover.c | 15 +++++++++++++++ 5 files changed, 46 insertions(+)
Documentation/ABI/testing/sysfs-kernel-kexec-kdump +8 -0
@@ -59,3 +59,11 @@ Description: read only to the crash (kdump) kernel. It lists the start and end physical addresses of CMA regions assigned for crashkernel use. User: kdump service + +What: /sys/kernel/kexec/kho_bootmem_size +Date: Nov 2026 +Contact: [email protected] +Description: read only + Total size of the KHO bootmem regions in bytes. Returns 0 + when KHO is disabled. +User: system monitoring
Documentation/admin-guide/mm/kho.rst +9 -0
@@ -81,6 +81,15 @@ At scale, correlating crashes to the previous kernel version enables faster root cause analysis when issues only occur in specific kernel transition scenarios. +sysfs Interfaces +================ + +``/sys/kernel/kexec/kho_bootmem_size`` + Total size of the KHO bootmem regions in bytes, or 0 when KHO is + disabled. + +See Documentation/ABI/testing/sysfs-kernel-kexec-kdump for the sysfs ABI. + debugfs Interfaces ==================
include/linux/kexec_handover.h +1 -0
@@ -40,6 +40,7 @@ void kho_populate(phys_addr_t fdt_phys, u64 fdt_len, phys_addr_t bootmem_phys, u64 bootmem_len);bool kho_bootmem_overlap (phys_addr_t phys,size_t size); +phys_addr_t kho_bootmem_size (void );static inline enum migratetype kho_bootmem_migratetype (unsigned long pfn,enum migratetype mt)
kernel/kexec_core.c +13 -0
@@ -13,6 +13,7 @@#include <linux/slab.h> #include <linux/fs.h> #include <linux/kexec.h> +#include <linux/kexec_handover.h> #include <linux/mutex.h> #include <linux/list.h> #include <linux/liveupdate.h>
@@ -1324,6 +1325,15 @@ static struct kobj_attribute crash_elfcorehdr_size_attr = __ATTR_RO(crash_elfcor#endif /* CONFIG_CRASH_HOTPLUG */ #endif /* CONFIG_CRASH_DUMP */ +#ifdef CONFIG_KEXEC_HANDOVER +static ssize_t kho_bootmem_size_show (struct kobject *kobj, +struct kobj_attribute *attr,char *buf) +{ +return sysfs_emit (buf,"%llu\n" , (unsigned long long )kho_bootmem_size ()); +} +static struct kobj_attribute kho_bootmem_size_attr =__ATTR_RO (kho_bootmem_size); +#endif +static struct attribute *kexec_attrs[] = { &loaded_attr.attr, #ifdef CONFIG_CRASH_DUMP
@@ -1335,6 +1345,9 @@ static struct attribute *kexec_attrs[] = {#ifdef CONFIG_CRASH_HOTPLUG &crash_elfcorehdr_size_attr.attr,#endif +#endif +#ifdef CONFIG_KEXEC_HANDOVER + &kho_bootmem_size_attr.attr, #endifNULL };
kernel/liveupdate/kexec_handover.c +15 -0
@@ -942,6 +942,21 @@ static void __init kho_reserve_bootmem(void) kho_enable = false; } +phys_addr_t kho_bootmem_size (void ) +{ +phys_addr_t size =0 ; +unsigned int i; + +/* kho_init() can disable KHO without clearing kho_bootmem_cnt. */ +if (!kho_enable) +return 0 ; + +for (i =0 ; i < kho_bootmem_cnt; i++) + size += kho_bootmem[i].size; + +return size; +} +/* * Look for free blocks of 1G. This is a heuristic chosen to work efficiently * with large systems with hundreds of gigabytes of memory. It will work poorly
Signature · 1 line
2.54.0
Pasha Tatashin
maintainerRe: [PATCH 2/9] kho: Make bootmem reservations visible to fleet monitoring
Quoted 2 lines
We want to use live update at Meta to upgrade hypervisors whose VMs can't be migrated away first. But this poses a problem: whether we can
Awesome.
Quoted 9 lines
enable KHO on a class of host depends on how much memory it leaves available for unmovable allocations. In an early test, a 64 GiB host with hugetlb_cma=6G set aside about 30 GiB of bootmem, which the running kernel can only use for movable allocations.
The reservation varies with the kernel, memory size, NUMA layout and command line. Our fleet collector needs the actual size from each host so we can decide where to enable KHO and catch a kernel release that takes those hosts over their bootmem budget.
HM, that works for cold boot not for live update :-)
Quoted 4 lines
Today the collector would have to sum kho/out/bootmem_len in debugfs, which isn't a userspace ABI. In
/proc/meminfo, free bootmem contributes to CmaFree, but the reservation doesn't contribute to CmaTotal. The cma
Is this a different bug?
Quoted 22 lines
count in
/proc/zoneinfoincludes bootmem after a cold boot but not after a KHO kexec. On an 8 GiB QEMU guest booted with kho_bootmem=32M,1536M,512M:CmaTotal CmaFree zoneinfo cma (all zones) cold boot 0 kB 2127872 kB 2129920 kB KHO kexec 0 kB 881336 kB 0 kBEven if bootmem becomes a CMA area, CmaTotal will still include other areas such as hugetlb CMA, so inferring the bootmem size is still error-prone.
Let's report the total bootmem reservation in bytes at
/sys/kernel/kexec/kho_bootmem_size.Signed-off-by Chris Down <[email protected]>Documentation/ABI/testing/sysfs-kernel-kexec-kdump +0
-0
Documentation/ABI/testing/sysfs-kernel-kexec-kdump Description: read only · line 63
Quoted 5 lines
Documentation/ABI/testing/sysfs-kernel-kexec-kdump +2
-0@@ -59,3 +59,11 @@ Description: read only to the crash (kdump) kernel. It lists the start and end physical addresses of CMA regions assigned for crashkernel use. User: kdump service + +What: /sys/kernel/kexec/kho_bootmem_size
I have some concerns about exposing this as a stable API. What if we get rid of bootmem or make it resizable? We only recently renamed it from scratch to bootmem, and we have been exploring for way to optimize it.
I would keep this exposed under /sys/kernel/debug/kho/bootmem_size for now, and not worry about it being stable.
Quoted 52 lines
Documentation/ABI/testing/sysfs-kernel-kexec-kdump +6
-0+Date: Nov 2026 +Contact: [email protected] +Description: read only + Total size of the KHO bootmem regions in bytes. Returns 0 + when KHO is disabled. +User: system monitoringDocumentation/admin-guide/mm/kho.rst +9
-0@@ -81,6 +81,15 @@ At scale, correlating crashes to the previous kernel version enables faster root cause analysis when issues only occur in specific kernel transition scenarios. +sysfs Interfaces +================ + +``/sys/kernel/kexec/kho_bootmem_size`` + Total size of the KHO bootmem regions in bytes, or 0 when KHO is + disabled. + +See Documentation/ABI/testing/sysfs-kernel-kexec-kdump for the sysfs ABI. + debugfs Interfaces ==================include/linux/kexec_handover.h +1
-0@@ -40,6 +40,7 @@ void kho_populate(phys_addr_t fdt_phys, u64 fdt_len, phys_addr_t bootmem_phys, u64 bootmem_len);bool kho_bootmem_overlap (phys_addr_t phys,size_t size); +phys_addr_t kho_bootmem_size (void );static inline enum migratetype kho_bootmem_migratetype (unsigned long pfn,enum migratetype mt)kernel/kexec_core.c +1
-0@@ -13,6 +13,7 @@#include <linux/slab.h> #include <linux/fs.h> #include <linux/kexec.h> +#include <linux/kexec_handover.h> #include <linux/mutex.h> #include <linux/list.h> #include <linux/liveupdate.h> @@ -1324,6 +1325,15 @@ static struct kobj_attribute crash_elfcorehdr_size_attr = __ATTR_RO(crash_elfcor#endif /* CONFIG_CRASH_HOTPLUG */
kernel/kexec_core.c static struct kobj_attribute crash_elfcorehdr_size_attr = __ATTR_RO(crash_elfcor · line 1335
Quoted 10 lines
kernel/kexec_core.c +8
-0#endif /* CONFIG_CRASH_DUMP */ +#ifdef CONFIG_KEXEC_HANDOVER +static ssize_t kho_bootmem_size_show (struct kobject *kobj, +struct kobj_attribute *attr,char *buf) +{ +return sysfs_emit (buf,"%llu\n" , (unsigned long long )kho_bootmem_size ()); +} +static struct kobj_attribute kho_bootmem_size_attr =__ATTR_RO (kho_bootmem_size); +#endif
Keeping it together with the rest of KHO code would be better.
Signature · 1 line
Pasha
Re: [PATCH 2/9] kho: Make bootmem reservations visible to fleet monitoring
Hi Pasha,
Quoted 6 lines · Pasha Tatashin
Quoted 4 lines
The reservation varies with the kernel, memory size, NUMA layout and command line. Our fleet collector needs the actual size from each host so we can decide where to enable KHO and catch a kernel release that takes those hosts over their bootmem budget.
HM, that works for cold boot not for live update :-)
Yeah, that's true :-) A kernel we live update into just inherits the areas, so we'd only see a release change the size once hosts cold boot into it. I'll say that in the changelog in v2.
Quoted 5 lines
Quoted 3 lines
Today the collector would have to sum kho/out/bootmem_len in debugfs, which isn't a userspace ABI. In
/proc/meminfo, free bootmem contributes to CmaFree, but the reservation doesn't contribute to CmaTotal. The cmaIs this a different bug?
I think so, yes. Bootmem pageblocks are MIGRATE_CMA, so their free pages are counted in NR_FREE_CMA_PAGES, but totalcma_pages only counts the areas that mm/cma.c knows about.
zone->cma_pages is a separate problem. It only gets bootmem added by init_cma_reserved_pageblock() in kho_init(), and on a KHO boot we return before we get there.
I can send patches for those separately if you agree that bootmem should be counted in both. It wouldn't give us the bootmem size though, because CmaTotal would still include any other CMA areas.
Quoted 6 lines
I have some concerns about exposing this as a stable API. What if we get rid of bootmem or make it resizable? We only recently renamed it from scratch to bootmem, and we have been exploring for way to optimize it.
I would keep this exposed under
/sys/kernel/debug/kho/bootmem_sizefor now, and not worry about it being stable.
That's fair. I'll move it to /sys/kernel/debug/kho/bootmem_size in v2, and we can look at sysfs again once bootmem has settled down.
Quoted 1 line
Keeping it together with the rest of KHO code would be better.
Will do, it'll go in kexec_handover_debugfs.c next to the other bootmem files.
The kho_incoming files in 6/9 are already in kexec_handover.c, but kexec_core.c still adds the group to /sys/kernel/kexec. Is that ok, or would you rather KHO set that up itself as well?
Thanks!
Chris
Mike Rapoport
maintainerRe: [PATCH 2/9] kho: Make bootmem reservations visible to fleet monitoring
Hi Chris,
Quoted 24 lines · Chris Down
Hi Pasha,
Quoted 6 lines · Pasha Tatashin
Quoted 4 lines
The reservation varies with the kernel, memory size, NUMA layout and command line. Our fleet collector needs the actual size from each host so we can decide where to enable KHO and catch a kernel release that takes those hosts over their bootmem budget.
HM, that works for cold boot not for live update :-)
Yeah, that's true :-) A kernel we live update into just inherits the areas, so we'd only see a release change the size once hosts cold boot into it. I'll say that in the changelog in v2.
Quoted 5 lines
Quoted 3 lines
Today the collector would have to sum kho/out/bootmem_len in debugfs, which isn't a userspace ABI. In
/proc/meminfo, free bootmem contributes to CmaFree, but the reservation doesn't contribute to CmaTotal. The cmaIs this a different bug?
I think so, yes. Bootmem pageblocks are
MIGRATE_CMA, so their free pages are counted inNR_FREE_CMA_PAGES, buttotalcma_pagesonly counts the areas thatmm/cma.cknows about.
Quoted 6 lines
zone->cma_pagesis a separate problem. It only gets bootmem added byinit_cma_reserved_pageblock()inkho_init(), and on a KHO boot we return before we get there.I can send patches for those separately if you agree that bootmem should be counted in both.
Yes, please :)
Quoted 7 lines
It wouldn't give us the bootmem size though, because CmaTotal would still include any other CMA areas.
Quoted 4 lines
I have some concerns about exposing this as a stable API. What if we get rid of bootmem or make it resizable? We only recently renamed it from scratch to bootmem, and we have been exploring for way to optimize it.
Quoted 5 lines
Quoted 2 lines
I would keep this exposed under
/sys/kernel/debug/kho/bootmem_sizefor now, and not worry about it being stable.That's fair. I'll move it to
/sys/kernel/debug/kho/bootmem_sizein v2, and we can look at sysfs again once bootmem has settled down.
The sysfs vs debugfs argument applies to anything KHO/LUO right now.
But we'll need sysfs at some point to lift the requirement for debugfs mount.
Quoted 7 lines
Quoted 1 line
Keeping it together with the rest of KHO code would be better.
Will do, it'll go in
kexec_handover_debugfs.cnext to the other bootmem files.The
kho_incomingfiles in 6/9 are already inkexec_handover.c, butkexec_core.cstill adds the group to/sys/kernel/kexec. Is that ok, or would you rather KHO set that up itself as well?
We'll need sysfs at some point to lift the requirement for debugfs mount. And I think it can live in /sys/kernel/kho and there we can have incoming and outgoing and the implementation can be in kernel/liveupdate/kho-sysfs.[ch]
BTW, kexec_handover_debugfs.c was initially given the "full" name because it lived along kexec_* in kernel. These days I believe we can make it kho-debugfs.c
I promise to look at the rest of the series Really Soon :)
Quoted 3 lines
Thanks!
Chris
Signature · 2 lines
Sincerely yours, Mike.
[email protected]
AI reviewRe: [PATCH 2/9] kho: Make bootmem reservations visible to fleet monitoring
In reply to Chris DownThank you for your contribution! Sashiko AI review found no new issues in this patch, but noticed 1 related pre-existing issue it does not introduce: - [Critical] kho: scratch memory corruption on…
Thank you for your contribution! Sashiko AI review found no new issues in this patch, but noticed 1 related pre-existing issue it does not introduce:
- [Critical] kho: scratch memory corruption on error path in kho_init()
[1]
--
commit 96d77d1af62b4778bf7f34ac023280de65f57337
Author: Chris Down <[email protected]>
kho: Make bootmem reservations visible to fleet monitoring
This commit exposes the total KHO bootmem reservation size in bytes via a new read-only sysfs attribute at /sys/kernel/kexec/kho_bootmem_size.
Quoted 12 lines
kernel/liveupdate/kexec_handover.c +4
-0@@ -942,6 +942,21 @@ static void __init kho_reserve_bootmem(void) kho_enable = false; } +phys_addr_t kho_bootmem_size (void ) +{ +phys_addr_t size =0 ; +unsigned int i;
kernel/liveupdate/kexec_handover.c static void __init kho_reserve_bootmem(void) · line 958
Quoted 10 lines
kernel/liveupdate/kexec_handover.c +10
-0+ +/* kho_init() can disable KHO without clearing kho_bootmem_cnt. */ +if (!kho_enable) +return 0 ; + +for (i =0 ; i < kho_bootmem_cnt; i++) + size += kho_bootmem[i].size; + +return size; +}
[Severity: Critical]
This problem wasn't introduced by this patch, but on the kho_init() error path referenced by this comment, can err_free_bootmem corrupt active memory during a KHO kexec boot [1]?
During a KHO boot (when fdt is non-NULL), early memblock allocations are served from the incoming kho_bootmem regions, and memblock_free_all() releases the remaining unallocated bootmem pages to the buddy allocator. While the normal path in kho_init() returns early when fdt is non-NULL before converting kho_bootmem to CMA, the error path frees every kho_bootmem region unconditionally:
kernel/liveupdate/kexec_handover.c:kho_init() {
...
if (fdt)
return 0;
...
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;
free_reserved_area(start, end, -1, "");
}
kho_enable = false;
return err;
}If an initialization step such as kho_alloc_preserve() fails on a KHO boot, free_reserved_area() runs on pages that are either in use by early-boot allocations or already managed by the buddy allocator, causing use-after-free and double free memory corruption.
[1] https://sashiko.dev/#/bug/linux-5ae80b0f-97ab-4112-a0a4-c767da72f4a8
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
PATCH 3/9 liveupdate: Make failed retrieves distinguishable from dropped files
In reply to Chris DownAt Meta, we want to use live update to upgrade hypervisors in place and preserve service fd stores across systemctl kexec. Our kernel rollout stops automatically when host health checks fail.
We need it to stop if the new kernel can't give back state that a VMM or service handed over. We also want to track files that userspace never asks for.
Today the process that tries a retrieve sees its error, but a fleet collector can't see that error or tell whether a session went unclaimed. Opening /dev/liveupdate to check would itself trigger deserialisation on the first open and can get in the way of the real restorer because the device is exclusive-open. The collector polls procfs and sysfs, so it needs a result it can read after the event.
Let's expose the incoming deserialisation state and aggregate session and file counts under /sys/class/misc/liveupdate/incoming/. A collector can stop the rollout on state=failed or files_failed > 0, and track files that were dropped or are still held. The session owner already knows which VM or service it belongs to, so there is no need to expose session names.
--- .../ABI/testing/sysfs-class-misc-liveupdate | 44 ++++++++++++++++ Documentation/userspace-api/liveupdate.rst | 7 +++ MAINTAINERS | 1 + kernel/liveupdate/luo_core.c | 50 +++++++++++++++++++ kernel/liveupdate/luo_file.c | 16 +++++- kernel/liveupdate/luo_internal.h | 34 +++++++++++++ kernel/liveupdate/luo_session.c | 6 +++ 7 files changed, 156 insertions(+), 2 deletions(-) create mode 100644 Documentation/ABI/testing/sysfs-class-misc-liveupdate
Documentation/ABI/testing/sysfs-class-misc-liveupdate new file +44 -0
@@ -0,0 +1,44 @@ +What: /sys/class/misc/liveupdate/incoming/ +Date: Nov 2026 +Contact: [email protected] +Description: + Incoming Live Update Orchestrator (LUO) state and counters. + Present when live update is enabled. Each attribute is read + independently. +Users: system monitoring + +What: /sys/class/misc/liveupdate/incoming/state +Date: Nov 2026 +Contact: [email protected] +Description: read only + Status of incoming LUO sessions: + + "none" No sessions were handed over. + "pending" Deserialization has not finished. It + starts on the first open of /dev/liveupdate. + "deserialized" The sessions can be retrieved. + "failed" Deserialization failed. Opening + /dev/liveupdate returns -EIO. +Users: system monitoring + +What: /sys/class/misc/liveupdate/incoming/sessions +What: /sys/class/misc/liveupdate/incoming/files +Date: Nov 2026 +Contact: [email protected] +Description: read only + Number of sessions deserialized and number of files in + those sessions, respectively. Counts can be partial while + state is "pending" or after it changes to "failed". +Users: system monitoring + +What: /sys/class/misc/liveupdate/incoming/files_retrieved +What: /sys/class/misc/liveupdate/incoming/files_failed +What: /sys/class/misc/liveupdate/incoming/files_dropped +Date: Nov 2026 +Contact: [email protected] +Description: read only + Number of successful retrieves, permanent retrieve failures, + and files discarded at session finish without a recorded + retrieve outcome, respectively. Retrieves and failures are + counted when they occur. +Users: system monitoring
Documentation/userspace-api/liveupdate.rst +7 -0
@@ -45,6 +45,13 @@ For details, see: - `sd_pid_notify_with_fds(3) <https://www.freedesktop.org/software/systemd/man/latest/sd_pid_notify_with_fds.html>`_ +Monitoring +========== + +Read ``/sys/class/misc/liveupdate/incoming/`` to monitor incoming +sessions and file retrievals without opening ``/dev/liveupdate``. +See Documentation/ABI/testing/sysfs-class-misc-liveupdate for the sysfs ABI. + See Also ========
MAINTAINERS +1 -0
@@ -15523,6 +15523,7 @@ L: [email protected] L: [email protected] S: Maintained T: git git://git.kernel.org/pub/scm/linux/kernel/git/liveupdate/linux.git +F: Documentation/ABI/testing/sysfs-class-misc-liveupdate F: Documentation/core-api/liveupdate.rst F: Documentation/mm/memfd_preservation.rst F: Documentation/userspace-api/liveupdate.rst
kernel/liveupdate/luo_core.c +50 -0
67 lines not on this page · raw message
kernel/liveupdate/luo_file.c +14 -2
@@ -543,6 +543,16 @@ void luo_file_unfreeze(struct luo_file_set *file_set,memset (file_set_ser,0 ,sizeof (*file_set_ser)); } +/* Record the first retrieve result. A negative status is permanent. */ +static void luo_file_set_retrieve_status (struct luo_file *luo_file,int status) +{ + luo_file->retrieve_status = status; +if (status >0 ) +atomic_long_inc (&luo_incoming_stats.files_retrieved); +else +atomic_long_inc (&luo_incoming_stats.files_failed); +} +/** * luo_retrieve_file - Restores a preserved file from a file_set by its token. * @file_set: The file_set from which to retrieve the file.
@@ -611,7 +621,7 @@ int luo_retrieve_file(struct luo_file_set *file_set, u64 token, err = luo_file->fh->ops->retrieve (&args);if (err) {/* Keep the error code for later use. */ - luo_file->retrieve_status = err; +luo_file_set_retrieve_status (luo_file, err);return err; }
@@ -624,7 +634,7 @@ int luo_retrieve_file(struct luo_file_set *file_set, u64 token, luo_file->file, GFP_KERNEL)); *filep = luo_file->file; - luo_file->retrieve_status =1 ; +luo_file_set_retrieve_status (luo_file,1 );return 0 ; }
@@ -719,6 +729,8 @@ int luo_file_finish(struct luo_file_set *file_set) struct luo_file, list);luo_file_finish_one (file_set, luo_file); +if (!luo_file->retrieve_status) +atomic_long_inc (&luo_incoming_stats.files_dropped);if (luo_file->file) { xa_erase(&luo_preserved_files,
kernel/liveupdate/luo_internal.h +34 -0
@@ -77,6 +77,40 @@ struct luo_session {extern struct rw_semaphore luo_register_rwlock; +/** +* enum luo_incoming_state - Deserialization state of incoming sessions +* @LUO_INCOMING_NONE: No incoming sessions. +* @LUO_INCOMING_PENDING: Deserialization has not finished. +* @LUO_INCOMING_DESERIALIZED: Sessions are ready to retrieve. +* @LUO_INCOMING_FAILED: Deserialization failed. +*/ +enum luo_incoming_state { +LUO_INCOMING_NONE , +LUO_INCOMING_PENDING , +LUO_INCOMING_DESERIALIZED , +LUO_INCOMING_FAILED , +}; + +/** +* struct luo_incoming_stats - Incoming session and file counters +* @state: Deserialization state. +* @sessions: Sessions deserialized. +* @files: Files in deserialized sessions. +* @files_retrieved: Files retrieved. +* @files_failed: Permanent retrieve failures. +* @files_dropped: Files discarded without a retrieve outcome. +*/ +struct luo_incoming_stats { +enum luo_incoming_state state; +atomic_long_t sessions; +atomic_long_t files; +atomic_long_t files_retrieved; +atomic_long_t files_failed; +atomic_long_t files_dropped; +}; + +extern struct luo_incoming_stats luo_incoming_stats; +static inline struct liveupdate_session *luo_session_from_file_set (struct luo_file_set *file_set) {struct luo_session *session;
kernel/liveupdate/luo_session.c +6 -0
@@ -549,6 +549,7 @@ int __init luo_session_setup_incoming(u64 sessions_pa)return err; sh->active = true; + luo_incoming_stats.state =LUO_INCOMING_PENDING ;return 0 ; }
@@ -583,6 +584,9 @@ static int luo_session_deserialize_one(struct luo_session_header *sh,return err; } +atomic_long_inc (&luo_incoming_stats.sessions); +atomic_long_add (session->file_set.count, &luo_incoming_stats.files); +return 0 ; }
@@ -626,12 +630,14 @@ int luo_session_deserialize(void) }kho_block_set_destroy (&sh->block_set); +WRITE_ONCE (luo_incoming_stats.state,LUO_INCOMING_DESERIALIZED );return 0 ; save_err:kho_block_set_destroy (&sh->block_set); saved_err = err; +WRITE_ONCE (luo_incoming_stats.state,LUO_INCOMING_FAILED );return err; }
Signature · 1 line
2.54.0
[email protected]
AI reviewRe: [PATCH 3/9] liveupdate: Make failed retrieves distinguishable from dropped files
Thank you for your contribution! Sashiko AI review found no new issues in this patch, but noticed 2 related pre-existing issues it does not introduce: - [Critical] liveupdate: uninitialized file…
Thank you for your contribution! Sashiko AI review found no new issues in this patch, but noticed 2 related pre-existing issues it does not introduce:
- [Critical] liveupdate: uninitialized file pointer in luo_session_retrieve_fd() [1]
- [High] liveupdate: pointer used as XArray index in luo_preserve_file()
[2]
--
commit acd081aa3a5ef33bac09be5e151d1de15512ea3e
Author: Chris Down <[email protected]>
liveupdate: Make failed retrieves distinguishable from dropped files
This commit exposes incoming live update deserialization state and session and file retrieval counters under /sys/class/misc/liveupdate/incoming/.
Quoted 22 lines
kernel/liveupdate/luo_file.c +10
-0@@ -543,6 +543,16 @@ void luo_file_unfreeze(struct luo_file_set *file_set,memset (file_set_ser,0 ,sizeof (*file_set_ser)); } +/* Record the first retrieve result. A negative status is permanent. */ +static void luo_file_set_retrieve_status (struct luo_file *luo_file,int status) +{ + luo_file->retrieve_status = status; +if (status >0 ) +atomic_long_inc (&luo_incoming_stats.files_retrieved); +else +atomic_long_inc (&luo_incoming_stats.files_failed); +} +/** * luo_retrieve_file - Restores a preserved file from a file_set by its token. * @file_set: The file_set from which to retrieve the file.
kernel/liveupdate/luo_file.c int luo_retrieve_file(struct luo_file_set *file_set, u64 token, · line 626
Quoted 7 lines
kernel/liveupdate/luo_file.c +1
-1@@ -611,7 +621,7 @@ int luo_retrieve_file(struct luo_file_set *file_set, u64 token, err = luo_file->fh->ops->retrieve (&args);if (err) {/* Keep the error code for later use. */ - luo_file->retrieve_status = err; +luo_file_set_retrieve_status (luo_file, err);return err; }
[Severity: Critical]
This problem wasn't introduced by this patch, but can a positive return from fh->ops->retrieve() cause luo_session_retrieve_fd() to pass an uninitialized struct file pointer to fd_install() [1]?
If fh->ops->retrieve() returns a positive value, luo_retrieve_file() returns without initializing *filep (and luo_file_set_retrieve_status() records it as a retrieved file with status > 0). luo_session_retrieve_fd() only checks for negative errors before installing the stack variable into the process file descriptor table:
kernel/liveupdate/luo_session.c:luo_session_retrieve_fd() {
...
struct file *file;
...
err = luo_retrieve_file(&session->file_set, argp->token, &file);
mutex_unlock(&session->mutex);
if (err < 0)
goto err_put_fd;
err = luo_ucmd_respond(ucmd, sizeof(*argp));
if (err)
goto err_put_file;
fd_install(argp->fd, file);
}luo_ioctl_retrieve_session() has the same pattern with luo_session_retrieve(). Any subsequent syscall on the installed fd dereferences the uninitialized stack pointer.
kernel/liveupdate/luo_file.c int luo_retrieve_file(struct luo_file_set *file_set, u64 token, · line 640
Quoted 9 lines
kernel/liveupdate/luo_file.c +1
-1@@ -624,7 +634,7 @@ int luo_retrieve_file(struct luo_file_set *file_set, u64 token, luo_file->file, GFP_KERNEL)); *filep = luo_file->file; - luo_file->retrieve_status =1 ; +luo_file_set_retrieve_status (luo_file,1 );return 0 ; }
[Severity: High]
This problem wasn't introduced by this patch, but why does luo_preserved_files use raw kernel pointers from luo_get_id() as XArray indices [2]?
kernel/liveupdate/luo_file.c:luo_get_id() {
return fh->ops->get_id ? fh->ops->get_id(file) : (unsigned long)file;
}Both luo_preserve_file() and luo_retrieve_file() pass luo_get_id() directly as the index to xa_insert(&luo_preserved_files, ...). Because XArray is a radix tree designed for dense small integer indices, indexing it by sparse 64-bit pointer values forces the allocation of up to 11 levels of intermediate tree nodes per entry, wasting memory and risking OOM.
[1] https://sashiko.dev/#/bug/linux-65e3446e-27d6-4415-82bb-0036dcc7aa0b
[2] https://sashiko.dev/#/bug/linux-80cdb953-2e71-4aca-9067-108b66f83aaa
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
PATCH 4/9 selftests/liveupdate: Catch incorrect file accounting across kexec
In reply to Chris DownCheck that each retrieve is counted while the session is still open. Finishing the session should count its unretrieved file as dropped, while a file in an unclaimed session should still be held.
--- tools/testing/selftests/liveupdate/Makefile | 1 + tools/testing/selftests/liveupdate/init.c | 5 + .../selftests/liveupdate/luo_handover_stats.c | 198 ++++++++++++++++++ .../selftests/liveupdate/run-vmtests.sh | 1 + tools/testing/selftests/liveupdate/vmtest.sh | 2 + 5 files changed, 207 insertions(+) create mode 100644 tools/testing/selftests/liveupdate/luo_handover_stats.c
tools/testing/selftests/liveupdate/Makefile +1 -0
@@ -2,6 +2,7 @@ TEST_GEN_PROGS += liveupdate +TEST_GEN_PROGS_EXTENDED += luo_handover_stats TEST_GEN_PROGS_EXTENDED += luo_kexec_simple TEST_GEN_PROGS_EXTENDED += luo_multi_session TEST_GEN_PROGS_EXTENDED += luo_stress_sessions
tools/testing/selftests/liveupdate/init.c +5 -0
@@ -37,6 +37,11 @@ static int mount_filesystems(void)return -1 ; } +if (mount ("sysfs" ,"/sys" ,"sysfs" ,0 ,NULL ) <0 ) { +fprintf (stderr,"INIT: Failed to mount sysfs\n" ); +return -1 ; + } +return 0 ; }
tools/testing/selftests/liveupdate/luo_handover_stats.c new file +198 -0
198 lines not on this page · raw message
tools/testing/selftests/liveupdate/run-vmtests.sh +1 -0
@@ -16,6 +16,7 @@ failed=0 skipped=0 TEST_NAMES=( + "luo_handover_stats" "luo_kexec_simple" "luo_multi_session" "luo_stress_files"
tools/testing/selftests/liveupdate/vmtest.sh +2 -0
@@ -145,6 +145,7 @@ function mkinitrd() { cat > "$workspace_dir/cpio_list_inner" <<EOF dir /dev 0755 0 0 dir /proc 0755 0 0 +dir /sys 0755 0 0 dir /debugfs 0755 0 0 nod /dev/console 0600 0 0 c 5 1 file /init $workspace_dir/init 0755 0 0
@@ -157,6 +158,7 @@ EOF cat > "$workspace_dir/cpio_list" <<EOF dir /dev 0755 0 0 dir /proc 0755 0 0 +dir /sys 0755 0 0 dir /debugfs 0755 0 0 nod /dev/console 0600 0 0 c 5 1 file /init $workspace_dir/init 0755 0 0
Signature · 1 line
2.54.0
[email protected]
AI reviewRe: [PATCH 4/9] selftests/liveupdate: Catch incorrect file accounting across kexec
Sashiko has reviewed this patch and found no issues.
Quoted 5 lines
Check that each retrieve is counted while the session is still open. Finishing the session should count its unretrieved file as dropped, while a file in an unclaimed session should still be held.
Signed-off-by Chris Down <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
PATCH 5/9 selftests/kho: Catch missing or zero bootmem reports before kexec
In reply to Chris DownThe KHO vmtest can pass even if the bootmem size is no longer visible to userspace. Let's fail if /sys/kernel/kexec/kho_bootmem_size can't be read or reports zero on the KHO-enabled boot.
--- tools/testing/selftests/kho/init.c | 24 ++++++++++++++++++++++++ tools/testing/selftests/kho/vmtest.sh | 1 + 2 files changed, 25 insertions(+)
tools/testing/selftests/kho/init.c +24 -0
@@ -18,9 +18,30 @@ static int mount_filesystems(void)if (mount ("debugfs" ,"/debugfs" ,"debugfs" ,0 ,NULL ) <0 )return -1 ; +if (mount ("sysfs" ,"/sys" ,"sysfs" ,0 ,NULL ) <0 ) +return -1 ; +return mount ("proc" ,"/proc" ,"proc" ,0 ,NULL ); } +static int check_bootmem_size (void ) +{ +char buf[32 ]; +ssize_t len; +int fd; + + fd =open ("/sys/kernel/kexec/kho_bootmem_size" ,O_RDONLY ); +if (fd <0 ) +return -1 ; + + len =read (fd, buf,sizeof (buf)); +close (fd); +if (len <=0 ) +return -1 ; + +return buf[0 ] =='0' ?-1 :0 ; +} +static long kexec_file_load (int kernel_fd,int initrd_fd,unsigned long cmdline_len,const char *cmdline,unsigned long flags)
@@ -61,6 +82,9 @@ int main(int argc, char *argv[])if (mount_filesystems ()) goto err_reboot; +if (check_bootmem_size ()) + goto err_reboot; +if (kexec_load ()) goto err_reboot;
tools/testing/selftests/kho/vmtest.sh +1 -0
@@ -95,6 +95,7 @@ function mkinitrd() { dir /dev 0755 0 0 dir /proc 0755 0 0 dir /debugfs 0755 0 0 +dir /sys 0755 0 0 nod /dev/console 0600 0 0 c 5 1 file /init $tmp_dir/init 0755 0 0 file /kernel $kernel 0644 0 0
Signature · 1 line
2.54.0
[email protected]
AI reviewRe: [PATCH 5/9] selftests/kho: Catch missing or zero bootmem reports before kexec
Sashiko has reviewed this patch and found no issues.
Quoted 5 lines
The KHO vmtest can pass even if the bootmem size is no longer visible to userspace. Let's fail if
/sys/kernel/kexec/kho_bootmem_sizecan't be read or reports zero on the KHO-enabled boot.Signed-off-by Chris Down <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
PATCH 6/9 kho: Expose rejected handovers that look like cold boots
In reply to Chris DownAt Meta, our rollout needs to stop if the new kernel rejects the KHO handover. For example, if it doesn't recognise the handover FDT's compatible string, it can boot normally with all the preserved state lost. LUO's incoming/state reads "none", as on a cold boot. We log "disabling KHO revival", but our fleet collector reads procfs and sysfs and can't rely on kernel logs from every host.
Let's add /sys/kernel/kexec/kho_incoming/state so the collector can tell a rejected handover from an ordinary boot. "revived" means the kernel accepted the handover and completed the preserved memory map walk. LUO reports the outcome of restoring sessions separately.
--- .../ABI/testing/sysfs-class-misc-liveupdate | 3 ++ .../ABI/testing/sysfs-kernel-kexec-kdump | 12 +++++++ Documentation/admin-guide/mm/kho.rst | 3 ++ include/linux/kexec_handover.h | 2 ++ kernel/kexec_core.c | 13 ++++++- kernel/liveupdate/kexec_handover.c | 34 +++++++++++++++++++ 6 files changed, 66 insertions(+), 1 deletion(-)
Documentation/ABI/testing/sysfs-class-misc-liveupdate +3 -0
@@ -19,6 +19,9 @@ Description: read only "deserialized" The sessions can be retrieved. "failed" Deserialization failed. Opening /dev/liveupdate returns -EIO. + + See /sys/kernel/kexec/kho_incoming/state for the status of + the underlying KHO handover. Users: system monitoring What: /sys/class/misc/liveupdate/incoming/sessions
Documentation/ABI/testing/sysfs-kernel-kexec-kdump +12 -0
@@ -67,3 +67,15 @@ Description: read only Total size of the KHO bootmem regions in bytes. Returns 0 when KHO is disabled. User: system monitoring + +What: /sys/kernel/kexec/kho_incoming/state +Date: Nov 2026 +Contact: [email protected] +Description: read only + Status of the incoming KHO handover: + + "none" No handover was passed to this kernel. + "revived" The kernel accepted the handover and completed + the walk of its preserved memory map. + "failed" The kernel rejected the handover. +User: system monitoring
Documentation/admin-guide/mm/kho.rst +3 -0
@@ -88,6 +88,9 @@ sysfs Interfaces Total size of the KHO bootmem regions in bytes, or 0 when KHO is disabled. +``/sys/kernel/kexec/kho_incoming/state`` + Status of the incoming KHO handover. + See Documentation/ABI/testing/sysfs-kernel-kexec-kdump for the sysfs ABI. debugfs Interfaces
include/linux/kexec_handover.h +2 -0
@@ -42,6 +42,8 @@ void kho_populate(phys_addr_t fdt_phys, u64 fdt_len, phys_addr_t bootmem_phys,bool kho_bootmem_overlap (phys_addr_t phys,size_t size);phys_addr_t kho_bootmem_size (void ); +extern const struct attribute_group kho_incoming_attr_group; +static inline enum migratetype kho_bootmem_migratetype (unsigned long pfn,enum migratetype mt) {
kernel/kexec_core.c +12 -1
@@ -1372,7 +1372,18 @@ static struct kexec_link_entry kexec_links[] = { };static struct kobject *kexec_kobj; -ATTRIBUTE_GROUPS (kexec); + +static const struct attribute_group kexec_group = { + .attrs = kexec_attrs, +}; + +static const struct attribute_group *kexec_groups[] = { + &kexec_group, +#ifdef CONFIG_KEXEC_HANDOVER + &kho_incoming_attr_group, +#endif +NULL +};static int __init init_kexec_sysctl (void ) {
kernel/liveupdate/kexec_handover.c +34 -0
@@ -19,6 +19,7 @@#include <linux/kexec.h> #include <linux/kexec_handover.h> #include <linux/kho_radix_tree.h> +#include <linux/kobject.h> #include <linux/utsname.h> #include <linux/kho/abi/kexec_handover.h> #include <linux/kho/abi/kexec_metadata.h>
@@ -97,11 +98,18 @@ static struct kho_out kho_out = { }, }; +enum kho_incoming_state { +KHO_INCOMING_NONE , +KHO_INCOMING_REVIVED , +KHO_INCOMING_FAILED , +}; +struct kho_in {phys_addr_t fdt_phys;phys_addr_t bootmem_phys;char previous_release[__NEW_UTS_LEN +1 ];u32 kexec_count; +enum kho_incoming_state state;struct kho_debugfs dbg;struct kho_radix_tree radix_tree; };
@@ -957,6 +965,29 @@ phys_addr_t kho_bootmem_size(void)return size; } +static const char *const kho_incoming_state_names[] = { + [KHO_INCOMING_NONE ] ="none" , + [KHO_INCOMING_REVIVED ] ="revived" , + [KHO_INCOMING_FAILED ] ="failed" , +}; + +static ssize_t state_show (struct kobject *kobj,struct kobj_attribute *attr, +char *buf) +{ +return sysfs_emit (buf,"%s\n" , kho_incoming_state_names[kho_in.state]); +} +static struct kobj_attribute state_attr =__ATTR_RO (state); + +static struct attribute *kho_incoming_attrs[] = { + &state_attr.attr, +NULL +}; + +const struct attribute_group kho_incoming_attr_group = { + .name ="kho_incoming" , + .attrs = kho_incoming_attrs, +}; +/* * Look for free blocks of 1G. This is a heuristic chosen to work efficiently * with large systems with hundreds of gigabytes of memory. It will work poorly
@@ -1753,6 +1784,7 @@ static void __init kho_mem_retrieve(void)*/ kho_in.fdt_phys =0 ; kho_in.radix_tree.root =NULL ; + kho_in.state =KHO_INCOMING_FAILED ; }static __init int kho_out_fdt_setup (void )
@@ -1992,6 +2024,7 @@ void __init kho_memory_init_early(void)*/ kho_in.fdt_phys =0 ; kho_in.bootmem_phys =0 ; + kho_in.state =KHO_INCOMING_FAILED ; }void __init kho_memory_init (void )
@@ -2090,6 +2123,7 @@ void __init kho_populate(phys_addr_t fdt_phys, u64 fdt_len, unmap_fdt:early_memunmap (fdt, fdt_len); report: + kho_in.state = populated ?KHO_INCOMING_REVIVED :KHO_INCOMING_FAILED ;if (!populated)pr_warn ("disabling KHO revival\n" ); }
Signature · 1 line
2.54.0
[email protected]
AI reviewRe: [PATCH 6/9] kho: Expose rejected handovers that look like cold boots
Sashiko has reviewed this patch and found no issues.
Quoted 7 lines
At Meta, our rollout needs to stop if the new kernel rejects the KHO handover. For example, if it doesn't recognise the handover FDT's compatible string, it can boot normally with all the preserved state lost. LUO's incoming/state reads "none", as on a cold boot. We log "disabling KHO revival", but our fleet collector reads procfs and sysfs and can't rely on kernel logs from every host.
Quoted 6 lines
Let's add
/sys/kernel/kexec/kho_incoming/stateso the collector can tell a rejected handover from an ordinary boot. "revived" means the kernel accepted the handover and completed the preserved memory map walk. LUO reports the outcome of restoring sessions separately.Signed-off-by Chris Down <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
PATCH 7/9 kho: Report how much handover memory is preserved and restored
In reply to Chris DownMost memory the previous kernel preserved stays reserved until its user restores it through KHO, either to use it again or to free it. If nothing does, it stays reserved for as long as the kernel runs. On a hypervisor host that can be gigabytes, but amusingly nothing really shows it reliably. The host simply has less memory than it should, which is not exactly obvious.
All preserved memory is reserved in kho_preserved_memory_reserve(), and everything restored through KHO goes through kho_restore_page(), so KHO can count both easily. Let's add preserved_size and restored_size, in bytes, to /sys/kernel/kexec/kho_incoming/.
For example, after a live update preserving a 64 MiB memfd:
preserved_size restored_size
before retrieval 67403776 8192
after retrieval 67403776 67395584The 8 KiB left are the incoming KHO FDT and LUO's FLB header.
--- .../ABI/testing/sysfs-kernel-kexec-kdump | 10 ++++++++ Documentation/admin-guide/mm/kho.rst | 3 +++ kernel/liveupdate/kexec_handover.c | 23 +++++++++++++++++++ 3 files changed, 36 insertions(+)
Documentation/ABI/testing/sysfs-kernel-kexec-kdump +10 -0
@@ -79,3 +79,13 @@ Description: read only the walk of its preserved memory map. "failed" The kernel rejected the handover. User: system monitoring + +What: /sys/kernel/kexec/kho_incoming/preserved_size +What: /sys/kernel/kexec/kho_incoming/restored_size +Date: Nov 2026 +Contact: [email protected] +Description: read only + Bytes preserved by the previous kernel and bytes restored + through KHO, respectively. Both are 0 unless the incoming + state is "revived". +User: system monitoring
Documentation/admin-guide/mm/kho.rst +3 -0
@@ -91,6 +91,9 @@ sysfs Interfaces ``/sys/kernel/kexec/kho_incoming/state`` Status of the incoming KHO handover. +``/sys/kernel/kexec/kho_incoming/preserved_size`` and ``restored_size`` + Bytes preserved by the previous kernel and bytes restored through KHO. + See Documentation/ABI/testing/sysfs-kernel-kexec-kdump for the sysfs ABI. debugfs Interfaces
kernel/liveupdate/kexec_handover.c +23 -0
@@ -110,6 +110,8 @@ struct kho_in {char previous_release[__NEW_UTS_LEN +1 ];u32 kexec_count;enum kho_incoming_state state; +unsigned long preserved_pages; +atomic_long_t restored_pages;struct kho_debugfs dbg;struct kho_radix_tree radix_tree; };
@@ -552,6 +554,7 @@ static struct page *kho_restore_page(phys_addr_t phys, bool is_folio,kho_init_pages (page, nr_pages);adjust_managed_page_count (page, nr_pages); +atomic_long_add (nr_pages, &kho_in.restored_pages);return page; }
@@ -643,6 +646,7 @@ static int __init kho_preserved_memory_reserve(unsigned long key, void *data) info.magic =KHO_PAGE_MAGIC ; info.order = order; page->private = info.page_private; + kho_in.preserved_pages +=1UL << order;return 0 ; }
@@ -978,8 +982,26 @@ static ssize_t state_show(struct kobject *kobj, struct kobj_attribute *attr, }static struct kobj_attribute state_attr =__ATTR_RO (state); +static ssize_t preserved_size_show (struct kobject *kobj, +struct kobj_attribute *attr,char *buf) +{ +return sysfs_emit (buf,"%llu\n" , (u64 )kho_in.preserved_pages <<PAGE_SHIFT ); +} +static struct kobj_attribute preserved_size_attr =__ATTR_RO (preserved_size); + +static ssize_t restored_size_show (struct kobject *kobj, +struct kobj_attribute *attr,char *buf) +{ +u64 pages =atomic_long_read (&kho_in.restored_pages); + +return sysfs_emit (buf,"%llu\n" , pages <<PAGE_SHIFT ); +} +static struct kobj_attribute restored_size_attr =__ATTR_RO (restored_size); +static struct attribute *kho_incoming_attrs[] = { &state_attr.attr, + &preserved_size_attr.attr, + &restored_size_attr.attr,NULL };
@@ -1785,6 +1807,7 @@ static void __init kho_mem_retrieve(void) kho_in.fdt_phys =0 ; kho_in.radix_tree.root =NULL ; kho_in.state =KHO_INCOMING_FAILED ; + kho_in.preserved_pages =0 ; }static __init int kho_out_fdt_setup (void )
Signature · 1 line
2.54.0
[email protected]
AI reviewRe: [PATCH 7/9] kho: Report how much handover memory is preserved and restored
Sashiko has reviewed this patch and found no issues.
Quoted 14 lines
Most memory the previous kernel preserved stays reserved until its user restores it through KHO, either to use it again or to free it. If nothing does, it stays reserved for as long as the kernel runs. On a hypervisor host that can be gigabytes, but amusingly nothing really shows it reliably. The host simply has less memory than it should, which is not exactly obvious.
All preserved memory is reserved in
kho_preserved_memory_reserve(), and everything restored through KHO goes throughkho_restore_page(), so KHO can count both easily. Let's addpreserved_sizeandrestored_size, in bytes, to/sys/kernel/kexec/kho_incoming/.For example, after a live update preserving a 64 MiB memfd:
Quoted 7 lines
preserved_size restored_size before retrieval 67403776 8192 after retrieval 67403776 67395584The 8 KiB left are the incoming KHO FDT and LUO's FLB header.
Signed-off-by Chris Down <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=7
PATCH 8/9 liveupdate: Expose the sequence number for consecutive live updates
In reply to Chris DownExport LUO's live update sequence number, so that fleet monitoring can compare hosts on their first live update with hosts that have been through several.
We want this because some bugs, like memory corruption, may only show up after several live updates in a row.
--- Documentation/ABI/testing/sysfs-class-misc-liveupdate | 9 +++++++++ Documentation/userspace-api/liveupdate.rst | 1 + kernel/liveupdate/luo_core.c | 8 ++++++++ 3 files changed, 18 insertions(+)
Documentation/ABI/testing/sysfs-class-misc-liveupdate +9 -0
@@ -24,6 +24,15 @@ Description: read only the underlying KHO handover. Users: system monitoring +What: /sys/class/misc/liveupdate/incoming/liveupdate_num +Date: Nov 2026 +Contact: [email protected] +Description: read only + LUO sequence number passed by the previous kernel. Reads 0 + if no LUO state was handed over, 1 after the first live + update in a sequence, and increments with each update. +Users: system monitoring + What: /sys/class/misc/liveupdate/incoming/sessions What: /sys/class/misc/liveupdate/incoming/files Date: Nov 2026
Documentation/userspace-api/liveupdate.rst +1 -0
@@ -50,6 +50,7 @@ Monitoring Read ``/sys/class/misc/liveupdate/incoming/`` to monitor incoming sessions and file retrievals without opening ``/dev/liveupdate``. +``liveupdate_num`` gives the LUO sequence number for the current boot. See Documentation/ABI/testing/sysfs-class-misc-liveupdate for the sysfs ABI. See Also
kernel/liveupdate/luo_core.c +8 -0
@@ -441,6 +441,13 @@ static ssize_t state_show(struct device *dev, struct device_attribute *attr, }static DEVICE_ATTR_RO (state); +static ssize_t liveupdate_num_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +return sysfs_emit (buf,"%llu\n" , luo_global.liveupdate_num); +} +static DEVICE_ATTR_RO (liveupdate_num); +#define LUO_INCOMING_ATTR_RO (_name) \ static ssize_t _name##_show(struct device *dev, \ struct device_attribute *attr, char *buf) \
@@ -458,6 +465,7 @@ LUO_INCOMING_ATTR_RO(files_dropped);static struct attribute *luo_incoming_attrs[] = { &dev_attr_state.attr, + &dev_attr_liveupdate_num.attr, &dev_attr_sessions.attr, &dev_attr_files.attr, &dev_attr_files_retrieved.attr,
Signature · 1 line
2.54.0
[email protected]
AI reviewRe: [PATCH 8/9] liveupdate: Expose the sequence number for consecutive live updates
Sashiko has reviewed this patch and found no issues.
Quoted 8 lines
Export LUO's live update sequence number, so that fleet monitoring can compare hosts on their first live update with hosts that have been through several.
We want this because some bugs, like memory corruption, may only show up after several live updates in a row.
Signed-off-by Chris Down <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=8
PATCH 9/9 selftests/liveupdate: Check handover revival, sequence and memory stats
In reply to Chris DownExtend the handover stats test to cover the new files. On the first boot, kho_incoming/state should be none, liveupdate_num 0, and both KHO sizes 0. After the kexec, the handover should be revived and liveupdate_num should be 1.
restored_size should grow by at least a page each time a memfd is retrieved or dropped. The memfd in the unclaimed session is retrieved last, once everything else is done.
--- .../selftests/liveupdate/luo_handover_stats.c | 74 +++++++++++++++++-- 1 file changed, 67 insertions(+), 7 deletions(-)
tools/testing/selftests/liveupdate/luo_handover_stats.c +67 -7
@@ -10,6 +10,7 @@#include <libliveupdate.h> #define INCOMING_DIR "/sys/class/misc/liveupdate/incoming/" +#define KHO_INCOMING_DIR "/sys/kernel/kexec/kho_incoming/"#define SESSION_CLAIMED "stats-claimed"#define SESSION_UNCLAIMED "stats-unclaimed"
@@ -28,13 +29,13 @@/* The first open starts deserialization. */ static char state_before_open[16 ]; -static void read_incoming (const char *name,char *buf,size_t len) +static void read_sysfs (const char *dir,const char *name,char *buf,size_t len) {char path[128 ];ssize_t n;int fd; -snprintf (path,sizeof (path),INCOMING_DIR "%s" , name); +snprintf (path,sizeof (path),"%s%s" , dir, name); fd =open (path,O_RDONLY );if (fd <0 )fail_exit ("open %s" , path);
@@ -54,6 +55,11 @@ static void read_incoming(const char *name, char *buf, size_t len) buf[n -1 ] ='\0' ; } +static void read_incoming (const char *name,char *buf,size_t len) +{ +read_sysfs (INCOMING_DIR , name, buf, len); +} +static void expect_state (const char *state,const char *expected) {if (strcmp (state, expected))
@@ -61,13 +67,13 @@ static void expect_state(const char *state, const char *expected) expected); } -static unsigned long long read_number (const char *name) +static unsigned long long read_number (const char *dir,const char *name) {unsigned long long val =0 ;char buf[32 ];char *p; -read_incoming (name, buf,sizeof (buf)); +read_sysfs (dir, name, buf,sizeof (buf));for (p = buf; *p >='0' && *p <='9' ; p++) {if (val > (ULLONG_MAX - (*p -'0' )) /10 )break ;
@@ -75,19 +81,45 @@ static unsigned long long read_number(const char *name) }if (p == buf || *p)ksft_exit_fail_msg ("%s%s reads '%s', not a 64-bit unsigned number\n" , -INCOMING_DIR , name, buf); + dir, name, buf);return val; }static void expect_count (const char *name,unsigned long long expected) { -unsigned long long val =read_number (name); +unsigned long long val =read_number (INCOMING_DIR , name);if (val != expected)ksft_exit_fail_msg ("%s is %llu, expected %llu\n" , name, val, expected); } +static void expect_kho_state (const char *expected) +{ +char state[16 ]; + +read_sysfs (KHO_INCOMING_DIR ,"state" , state,sizeof (state)); +if (strcmp (state, expected)) +ksft_exit_fail_msg ("kho_incoming/state is '%s', expected '%s'\n" , + state, expected); +} + +static unsigned long long kho_size (const char *name) +{ +return read_number (KHO_INCOMING_DIR , name); +} + +static unsigned long long expect_more_restored (unsigned long long prev) +{ +unsigned long long restored =kho_size ("restored_size" ); + +if (restored < prev +getpagesize () || + restored >kho_size ("preserved_size" )) +ksft_exit_fail_msg ("restored_size went from %llu to %llu\n" , + prev, restored); +return restored; +} +static void expect_counts (long retrieved,long dropped) {char state[16 ];
@@ -111,6 +143,10 @@ static void run_stage_1(int luo_fd)expect_state (state_before_open,"none" );expect_count ("sessions" ,0 );expect_count ("files" ,0 ); +expect_count ("liveupdate_num" ,0 ); +expect_kho_state ("none" ); +if (kho_size ("preserved_size" ) ||kho_size ("restored_size" )) +ksft_exit_fail_msg ("KHO sizes aren't 0 on a cold boot\n" );create_state_file (luo_fd,STATE_SESSION_NAME ,STATE_MEMFD_TOKEN ,2 );
@@ -144,11 +180,16 @@ static void run_stage_1(int luo_fd)static void run_stage_2 (int luo_fd,int state_session_fd) { -int claimed_fd, mfd, stage; +int claimed_fd, unclaimed_fd, mfd, stage; +unsigned long long restored;ksft_print_msg ("[STAGE 2] Checking state before and after the first open...\n" );expect_state (state_before_open,"pending" );expect_counts (0 ,0 ); +expect_count ("liveupdate_num" ,1 ); +expect_kho_state ("revived" ); +if (!kho_size ("preserved_size" )) +ksft_exit_fail_msg ("kho_incoming/preserved_size is 0\n" );restore_and_read_stage (state_session_fd,STATE_MEMFD_TOKEN , &stage);if (stage !=2 )
@@ -163,6 +204,7 @@ static void run_stage_2(int luo_fd, int state_session_fd)if (claimed_fd <0 )fail_exit ("luo_retrieve_session for '%s'" ,SESSION_CLAIMED ); + restored =kho_size ("restored_size" ); mfd =restore_and_verify_memfd (claimed_fd,MFD_RETRIEVED_TOKEN ,MFD_RETRIEVED_DATA );if (mfd <0 )
@@ -170,6 +212,7 @@ static void run_stage_2(int luo_fd, int state_session_fd) MFD_RETRIEVED_TOKEN);close (mfd);expect_counts (2 ,0 ); + restored =expect_more_restored (restored);ksft_print_msg ("[STAGE 2] Finishing '%s'...\n" ,SESSION_CLAIMED );if (luo_session_finish (claimed_fd) <0 )
@@ -177,6 +220,7 @@ static void run_stage_2(int luo_fd, int state_session_fd)close (claimed_fd);expect_counts (2 ,1 ); +expect_more_restored (restored);ksft_print_msg ("[STAGE 2] Finishing the state session...\n" );if (luo_session_finish (state_session_fd) <0 )
@@ -185,6 +229,22 @@ static void run_stage_2(int luo_fd, int state_session_fd)/* Finishing the state session must not drop anything. */ expect_counts (2 ,1 ); + restored =kho_size ("restored_size" ); + +ksft_print_msg ("[STAGE 2] Retrieving the memfd in '%s'...\n" , +SESSION_UNCLAIMED ); + unclaimed_fd =luo_retrieve_session (luo_fd,SESSION_UNCLAIMED ); +if (unclaimed_fd <0 ) +fail_exit ("luo_retrieve_session for '%s'" ,SESSION_UNCLAIMED ); + mfd =restore_and_verify_memfd (unclaimed_fd,MFD_UNCLAIMED_TOKEN , +MFD_UNCLAIMED_DATA ); +if (mfd <0 ) +fail_exit ("restore_and_verify_memfd for token %#x" , +MFD_UNCLAIMED_TOKEN ); +close (mfd); +close (unclaimed_fd); +expect_counts (3 ,1 ); +expect_more_restored (restored);ksft_print_msg ("\n--- HANDOVER STATS TEST PASSED ---\n" ); }
Signature · 1 line
2.54.0
[email protected]
AI reviewRe: [PATCH 9/9] selftests/liveupdate: Check handover revival, sequence and memory stats
Sashiko has reviewed this patch and found no issues.
Quoted 10 lines
Extend the handover stats test to cover the new files. On the first boot, kho_incoming/state should be none,
liveupdate_num0, and both KHO sizes 0. After the kexec, the handover should be revived andliveupdate_numshould be 1.
restored_sizeshould grow by at least a page each time a memfd is retrieved or dropped. The memfd in the unclaimed session is retrieved last, once everything else is done.Signed-off-by Chris Down <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=9