Skip to contentSkip to conversation

kho, liveupdate: KHO/LUO observability

PATCH In review Chris Down 3 participants 14 messages Nov 28 – Nov 29

Subsystems (6)
lore
Share & tools
lore

Chris Down

author
#0 lore raw

v2 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 sequence number helps us understand what is happening on which hosts. The series exposes:

- whether the new kernel accepted the incoming handover
- how much of the preserved memory has been restored
- 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.

Pratyush's "kho: housekeeping" series
(https://lore.kernel.org/r/[email protected])
renames kexec_handover.c and kexec_handover_internal.h and changes kernel/liveupdate/Makefile. This series changes the same three files, so whichever lands second needs a rebase.

v2:

- Rebase onto the current liveupdate next
- Free the metadata page without reordering kho_init(), now that kho/in/sub_fdts is gone (Pasha)
- Drop the Fixes tag from the metadata page patch (Pasha)
- Drop the bootmem size patch and its selftest (Pratyush)
- Move the KHO files to /sys/kernel/kho/incoming/, set up by KHO in kho_sysfs.c, so kexec_core.c is no longer touched (Mike)
- Add tags from Breno and Pasha

v1: https://lore.kernel.org/r/[email protected]

Chris Down (7):
kho: Reclaim the metadata page left reserved after kexec
liveupdate: Make failed retrieves distinguishable from dropped files selftests/liveupdate: Catch incorrect file accounting across 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 ++++
 Documentation/ABI/testing/sysfs-kernel-kho    |  21 ++
 Documentation/admin-guide/mm/kho.rst          |  11 +
 Documentation/userspace-api/liveupdate.rst    |   8 +
 MAINTAINERS                                   |   3 +
 kernel/liveupdate/Makefile                    |   2 +-
 kernel/liveupdate/kexec_handover.c            |  26 ++
 kernel/liveupdate/kexec_handover_internal.h   |  10 +
 kernel/liveupdate/kho_sysfs.c                 |  70 +++++
 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/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 +
 18 files changed, 585 insertions(+), 3 deletions(-)
 create mode 100644 Documentation/ABI/testing/sysfs-class-misc-liveupdate
 create mode 100644 Documentation/ABI/testing/sysfs-kernel-kho
 create mode 100644 kernel/liveupdate/kho_sysfs.c
 create mode 100644 tools/testing/selftests/liveupdate/luo_handover_stats.c

base-commit: a8d435799f3c87231bca0c245fd9e60f31e45135

Signature · 1 line
2.56.1
author
#1 lore raw

PATCH v2 1/7 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.

---
 kernel/liveupdate/kexec_handover.c | 2 ++
 1 file changed, 2 insertions(+)
kernel/liveupdate/kexec_handover.c +2 -0
index 38e65d210cb9..233c126f6352 100644
@@ -1814,6 +1814,8 @@ 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_restore_free(metadata);
 }
 
 /*
Signature · 1 line
2.56.1
author
#4 lore raw

PATCH v2 2/7 liveupdate: Make failed retrieves distinguishable from dropped files

In reply to Chris Down

At 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
new file mode 100644
index 000000000000..25e3b49d7aeb
@@ -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
index cdd74627ab75..39bbb91d0dd4 100644
@@ -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
index a946fbbd74f0..5c74e7dfcdc0 100644
@@ -15524,6 +15524,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
index 9bda37b0dc4f..f8eee426d0bc 100644
@@ -545,6 +545,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.
@@ -613,7 +623,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;
 	}
 
@@ -627,7 +637,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;
 }
@@ -724,6 +734,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
index dac6644bfb18..504963fc9898 100644
@@ -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
index f1b86f701238..88959cc5bb8b 100644
@@ -547,6 +547,7 @@ int __init luo_session_setup_incoming(u64 sessions_pa)
 		return err;
 
 	sh->active = true;
+	luo_incoming_stats.state = LUO_INCOMING_PENDING;
 	return 0;
 }
 
@@ -581,6 +582,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;
 }
 
@@ -624,12 +628,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.56.1
author
#6 lore raw

PATCH v2 3/7 selftests/liveupdate: Catch incorrect file accounting across kexec

In reply to Chris Down

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.

---
 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
index 634211c66652..78a4419ff610 100644
@@ -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
index fb08bd58b9b9..31bd8f0ec3a9 100644
@@ -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
index c3d828cfd63b..b2f38d694664 100755
@@ -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
index 70a8d978077a..eaab277eb978 100755
@@ -150,6 +150,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
@@ -162,6 +163,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.56.1
author
#7 lore raw

PATCH v2 4/7 kho: Expose rejected handovers that look like cold boots

In reply to Chris Down

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.

Let's add /sys/kernel/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.

KHO has no sysfs directory yet, so this adds /sys/kernel/kho in its own file, kho_sysfs.c. It is set up separately from kho_init(), because kho_init() returns early when KHO is disabled, and a rejected handover still needs to be reported then.

---
 .../ABI/testing/sysfs-class-misc-liveupdate   |  3 ++
 Documentation/ABI/testing/sysfs-kernel-kho    | 11 ++++
 Documentation/admin-guide/mm/kho.rst          |  8 +++
 MAINTAINERS                                   |  2 +
 kernel/liveupdate/Makefile                    |  2 +-
 kernel/liveupdate/kexec_handover.c            |  9 ++++
 kernel/liveupdate/kexec_handover_internal.h   |  8 +++
 kernel/liveupdate/kho_sysfs.c                 | 54 +++++++++++++++++++
 8 files changed, 96 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/ABI/testing/sysfs-kernel-kho
 create mode 100644 kernel/liveupdate/kho_sysfs.c
Documentation/ABI/testing/sysfs-class-misc-liveupdate +3 -0
index 25e3b49d7aeb..8c3814ee3d37 100644
@@ -19,6 +19,9 @@ Description:	read only
 		"deserialized"  The sessions can be retrieved.
 		"failed"        Deserialization failed. Opening
 		                /dev/liveupdate returns -EIO.
+
+		See /sys/kernel/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-kho new file +11 -0
new file mode 100644
index 000000000000..21488e35d1f3
@@ -0,0 +1,11 @@
+What:		/sys/kernel/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.
+Users:		system monitoring
Documentation/admin-guide/mm/kho.rst +8 -0
index 4281da6be5fa..8810813a5d0a 100644
@@ -81,6 +81,14 @@ 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/kho/incoming/state``
+    Status of the incoming KHO handover.
+
+See Documentation/ABI/testing/sysfs-kernel-kho for the sysfs ABI.
+
 debugfs Interfaces
 ==================
 
MAINTAINERS +2 -0
index 5c74e7dfcdc0..baf39fcc0e87 100644
@@ -14779,6 +14779,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-kernel-kho
 F:	Documentation/admin-guide/mm/kho.rst
 F:	Documentation/core-api/kho/*
 F:	include/asm-generic/kexec_handover.h
@@ -14786,6 +14787,7 @@ F:	include/linux/kexec_handover.h
 F:	include/linux/kho/
 F:	include/linux/kho_block.h
 F:	kernel/liveupdate/kexec_handover*
+F:	kernel/liveupdate/kho_sysfs.c
 F:	lib/test_kho.c
 F:	tools/testing/selftests/kho/
 
kernel/liveupdate/Makefile +1 -1
index d9f469462556..6de82ffe8d40 100644
@@ -7,7 +7,7 @@ luo-y :=								\
 		luo_flb.o						\
 		luo_session.o
 
-obj-$(CONFIG_KEXEC_HANDOVER)		+= kexec_handover.o
+obj-$(CONFIG_KEXEC_HANDOVER)		+= kexec_handover.o kho_sysfs.o
 obj-$(CONFIG_KEXEC_HANDOVER_DEBUGFS)	+= kexec_handover_debugfs.o
 
 obj-$(CONFIG_LIVEUPDATE)		+= luo.o
kernel/liveupdate/kexec_handover.c +9 -0
index 233c126f6352..aff96aa401f8 100644
@@ -102,6 +102,7 @@ struct kho_in {
 	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;
 };
@@ -1744,6 +1745,7 @@ err:
 	 */
 	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)
@@ -1770,6 +1772,11 @@ static __init int kho_out_fdt_setup(void)
 	return err;
 }
 
+enum kho_incoming_state kho_in_state(void)
+{
+	return kho_in.state;
+}
+
 static void __init kho_in_kexec_metadata(void)
 {
 	struct kho_kexec_metadata *metadata;
@@ -1981,6 +1988,7 @@ err:
 	 */
 	kho_in.fdt_phys = 0;
 	kho_in.bootmem_phys = 0;
+	kho_in.state = KHO_INCOMING_FAILED;
 }
 
 void __init kho_memory_init(void)
@@ -2079,6 +2087,7 @@ unmap_bootmem:
 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");
 }
kernel/liveupdate/kexec_handover_internal.h +8 -0
index e9685e1ef6d7..b559f5d43116 100644
@@ -22,6 +22,14 @@ struct kho_debugfs {};
 extern struct kho_bootmem *kho_bootmem;
 extern unsigned int kho_bootmem_cnt;
 
+enum kho_incoming_state {
+	KHO_INCOMING_NONE,
+	KHO_INCOMING_REVIVED,
+	KHO_INCOMING_FAILED,
+};
+
+enum kho_incoming_state kho_in_state(void);
+
 #ifdef CONFIG_KEXEC_HANDOVER_DEBUGFS
 int kho_debugfs_init(void);
 void kho_in_debugfs_init(struct kho_debugfs *dbg, const void *fdt);
kernel/liveupdate/kho_sysfs.c new file +54 -0

54 lines not on this page · raw message

Signature · 1 line
2.56.1
author
#9 lore raw

PATCH v2 5/7 kho: Report how much handover memory is preserved and restored

In reply to Chris Down

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 through kho_restore_page(), so KHO can count both easily. Let's add preserved_size and restored_size, in bytes, to /sys/kernel/kho/incoming/.

For example, after a live update preserving a 64 MiB memfd:

                     preserved_size  restored_size
    before retrieval       67403776           8192
    after finish           67403776       67395584

The 8 KiB left are the incoming KHO FDT and LUO's FLB header.

---
 Documentation/ABI/testing/sysfs-kernel-kho  | 10 ++++++++++
 Documentation/admin-guide/mm/kho.rst        |  3 +++
 kernel/liveupdate/kexec_handover.c          | 15 +++++++++++++++
 kernel/liveupdate/kexec_handover_internal.h |  2 ++
 kernel/liveupdate/kho_sysfs.c               | 16 ++++++++++++++++
 5 files changed, 46 insertions(+)
Documentation/ABI/testing/sysfs-kernel-kho +10 -0
index 21488e35d1f3..a8251d663ce6 100644
@@ -9,3 +9,13 @@ Description:	read only
 		           the walk of its preserved memory map.
 		"failed"   The kernel rejected the handover.
 Users:		system monitoring
+
+What:		/sys/kernel/kho/incoming/preserved_size
+What:		/sys/kernel/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".
+Users:		system monitoring
Documentation/admin-guide/mm/kho.rst +3 -0
index 8810813a5d0a..a12c1398eff2 100644
@@ -87,6 +87,9 @@ sysfs Interfaces
 ``/sys/kernel/kho/incoming/state``
     Status of the incoming KHO handover.
 
+``/sys/kernel/kho/incoming/preserved_size`` and ``restored_size``
+    Bytes preserved by the previous kernel and bytes restored through KHO.
+
 See Documentation/ABI/testing/sysfs-kernel-kho for the sysfs ABI.
 
 debugfs Interfaces
kernel/liveupdate/kexec_handover.c +15 -0
index aff96aa401f8..5d9b724ab754 100644
@@ -103,6 +103,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;
 };
@@ -545,6 +547,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;
 }
 
@@ -636,6 +639,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;
 }
@@ -1746,6 +1750,7 @@ err:
 	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)
@@ -1777,6 +1782,16 @@ enum kho_incoming_state kho_in_state(void)
 	return kho_in.state;
 }
 
+u64 kho_in_preserved_size(void)
+{
+	return (u64)kho_in.preserved_pages << PAGE_SHIFT;
+}
+
+u64 kho_in_restored_size(void)
+{
+	return (u64)atomic_long_read(&kho_in.restored_pages) << PAGE_SHIFT;
+}
+
 static void __init kho_in_kexec_metadata(void)
 {
 	struct kho_kexec_metadata *metadata;
kernel/liveupdate/kexec_handover_internal.h +2 -0
index b559f5d43116..9e2d1b0ef753 100644
@@ -29,6 +29,8 @@ enum kho_incoming_state {
 };
 
 enum kho_incoming_state kho_in_state(void);
+u64 kho_in_preserved_size(void);
+u64 kho_in_restored_size(void);
 
 #ifdef CONFIG_KEXEC_HANDOVER_DEBUGFS
 int kho_debugfs_init(void);
kernel/liveupdate/kho_sysfs.c +16 -0
index eb2e4ce72f20..e87a417d9254 100644
@@ -21,8 +21,24 @@ 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", kho_in_preserved_size());
+}
+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)
+{
+	return sysfs_emit(buf, "%llu\n", kho_in_restored_size());
+}
+static struct kobj_attribute restored_size_attr = __ATTR_RO(restored_size);
+
 static struct attribute *incoming_attrs[] = {
 	&state_attr.attr,
+	&preserved_size_attr.attr,
+	&restored_size_attr.attr,
 	NULL
 };
 
Signature · 1 line
2.56.1
author
#11 lore raw

PATCH v2 6/7 liveupdate: Expose the sequence number for consecutive live updates

In reply to Chris Down

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.

---
 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
index 8c3814ee3d37..023961a42b29 100644
@@ -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
index 39bbb91d0dd4..61c246371200 100644
@@ -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
index ba174e9aae03..3ca7b3875247 100644
@@ -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.56.1
author
#12 lore raw

PATCH v2 7/7 selftests/liveupdate: Check handover revival, sequence and memory stats

In reply to Chris Down

Extend 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
index f18df79dda55..850d2fbb1dcd 100644
@@ -10,6 +10,7 @@
 #include <libliveupdate.h>
 
 #define INCOMING_DIR "/sys/class/misc/liveupdate/incoming/"
+#define KHO_INCOMING_DIR "/sys/kernel/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.56.1
#2 lore raw

Re: [PATCH v2 1/7] kho: Reclaim the metadata page left reserved after kexec

In reply to Chris Down
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Low] kho: missing Fixes trailer for metadata page leak in kho_in_kexec_metadata() --

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Low] kho: missing Fixes trailer for metadata page leak in kho_in_kexec_metadata()
--

commit 7e9850ca466f4abcb7e3445a206026f7ef5a38d7
Author: Chris Down <[email protected]>

Quoted 7 lines

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.

Quoted 5 lines

Free it with kho_restore_free() once copying is complete.

[Severity: Low]
This fixes a metadata page leak in kho_in_kexec_metadata(). Should it include:

Fixes 76aa46b9e404 ("kho: kexec-metadata: track previous kernel chain")
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#13 lore raw
In reply to Chris Down
Sashiko has finished reviewing this 7-patch series:

Sashiko has finished reviewing this 7-patch series:

- Patches 2-7: no issues found.
- Patch 1 ("kho: Reclaim the metadata page left reserved after k..."): 1 potential issue (1 Low)

A detailed review has been sent as a separate reply to patch 1.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]
maintainer
#3 lore raw

Re: [PATCH v2 1/7] kho: Reclaim the metadata page left reserved after kexec

In reply to [email protected]
Quoted 22 lines · On Sun, Nov 29, 2026 at 06:28:32PM +0000, [email protected] wrote:

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Low] kho: missing Fixes trailer for metadata page leak in kho_in_kexec_metadata()
--

commit 7e9850ca466f4abcb7e3445a206026f7ef5a38d7
Author: Chris Down <[email protected]>

Quoted 7 lines

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.

Quoted 5 lines

Free it with kho_restore_free() once copying is complete.

Quoted 5 lines

[Severity: Low]
This fixes a metadata page leak in kho_in_kexec_metadata(). Should it include:

Fixes 76aa46b9e404 ("kho: kexec-metadata: track previous kernel chain")

Nah, it's not worth the hassle.

Quoted 2 lines
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Signature · 2 lines
Sincerely yours,
Mike.
maintainer
#5 lore raw

Re: [PATCH v2 2/7] liveupdate: Make failed retrieves distinguishable from dropped files

In reply to Chris Down

Hi Chris,

Quoted 2 lines · Chris Down

Subject: [PATCH v2 2/7] liveupdate: Make failed retrieves distinguishable from dropped files

IMHO the subject should mention sysfs as it's the major user visible change here. Another comment about it below.

Quoted 7 lines

At 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.

We are not as strict as x86 about the imperative mood, but still it's preferable :)

Quoted 32 lines

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 +0 -0
new file mode 100644
index 000000000000..25e3b49d7aeb

Documentation/ABI/testing/sysfs-class-misc-liveupdate line 1

Quoted 1 line
Documentation/ABI/testing/sysfs-class-misc-liveupdate new file +1 -0
@@ -0,0 +1,44 @@
+What:		/sys/class/misc/liveupdate/incoming/

I wonder if we want to link this from /sys/kernel/liveupdate or that would be too much?

Quoted 11 lines
Documentation/ABI/testing/sysfs-class-misc-liveupdate new file +11 -0
+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]

Documentation/ABI/testing/sysfs-class-misc-liveupdate line 22

Quoted 10 lines
Documentation/ABI/testing/sysfs-class-misc-liveupdate new file +10 -0
+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

I'd suggest splitting this into two patches: the first would add sysfs plumbing and /state and the second would add the counters.

Than it will be easier to bikeshed about sysfs layout, attribute names :)

Documentation/ABI/testing/sysfs-class-misc-liveupdate line 25

Quoted 3 lines
Documentation/ABI/testing/sysfs-class-misc-liveupdate new file +3 -0
+
+What:		/sys/class/misc/liveupdate/incoming/sessions
+What:		/sys/class/misc/liveupdate/incoming/files

For instance, I suspect that 'sessions' and 'files' would grow new attrs, so maybe it's worth giving each a directory?

Even though is more of boilerplate for a little value today, we'd avoid multiple file_<attr> and session_<attr> later.

Documentation/ABI/testing/sysfs-class-misc-liveupdate line 36

Quoted 11 lines
Documentation/ABI/testing/sysfs-class-misc-liveupdate new file +11 -0
+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

And these would be

/sys/class/misc/liveupdate/incoming/files/count /sys/class/misc/liveupdate/incoming/files/retrieved /sys/class/misc/liveupdate/incoming/files/failed /sys/class/misc/liveupdate/incoming/files/dropped

and we also could easily add

/sys/class/misc/liveupdate/incoming/sessions/files_count

sometime later.

Quoted 13 lines
Documentation/ABI/testing/sysfs-class-misc-liveupdate new file +8 -0
+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 +0 -0
index cdd74627ab75..39bbb91d0dd4 100644

Documentation/userspace-api/liveupdate.rst For details, see: · line 52

Quoted 8 lines
Documentation/userspace-api/liveupdate.rst +5 -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``.

Maybe

``/sys/class/misc/liveupdate/incoming`` allows monitoring of incoming session and file retrievals without opening ``/dev/liveupdate``.

Quoted 4 lines
Documentation/userspace-api/liveupdate.rst +2 -0
+See Documentation/ABI/testing/sysfs-class-misc-liveupdate for the sysfs ABI.
+
 See Also
 ========
Signature · 2 lines
Sincerely yours,
Mike.
maintainer
#8 lore raw

Re: [PATCH v2 4/7] kho: Expose rejected handovers that look like cold boots

In reply to Chris Down

Hi Chris,

Quoted 1 line · Chris Down

Subject: [PATCH v2 4/7] kho: Expose rejected handovers that look like cold boots

Maybe

expose handover status in sysfs

kernel/liveupdate/kexec_handover.c err:

Quoted 23 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.

Let's add /sys/kernel/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.

KHO has no sysfs directory yet, so this adds /sys/kernel/kho in its own file, kho_sysfs.c. It is set up separately from kho_init(), because kho_init() returns early when KHO is disabled, and a rejected handover still needs to be reported then.

kernel/liveupdate/kexec_handover.c +0 -0
@@ -1744,6 +1745,7 @@ err:

/* static void __init kho_mem_retrieve(void) */

kernel/liveupdate/kexec_handover.c unmap_bootmem:

Quoted 16 lines
kernel/liveupdate/kexec_handover.c +2 -0
 	 */
 	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)
@@ -1981,6 +1988,7 @@ err:
 	 */
 	kho_in.fdt_phys = 0;
 	kho_in.bootmem_phys = 0;
+	kho_in.state = KHO_INCOMING_FAILED;
 }
 
 void __init kho_memory_init(void)
@@ -2079,6 +2087,7 @@ unmap_bootmem:

/* void __init kho_populate(phys_addr_t fdt_phys, ...) */

kernel/liveupdate/kexec_handover.c unmap_bootmem: · line 2090

Quoted 4 lines
kernel/liveupdate/kexec_handover.c +1 -0
 unmap_fdt:
 	early_memunmap(fdt, fdt_len);
 report:
+	kho_in.state = populated ? KHO_INCOMING_REVIVED : KHO_INCOMING_FAILED;

This is too early to say "REVIVED" here.

Although the state stays REVIVED unless we overwrite later with FAILED if something goes wrong, I think it's better to make it explicit there.

Maybe even start with FAILED unconditionally in kho_populate() and only reset it to REVIVED in kho_memory_init().

That way the state starts with NONE, then if kho_populate() is called we know that's a KHO boot, and from there it's FAILED until proven otherwise.

This way we won't need to chase the points that should reset REVIVED to FAILED after kho_populate() or check the current state before changing it.

kernel/liveupdate/kexec_handover_internal.h struct kho_debugfs {}; · line 26

Quoted 13 lines
kernel/liveupdate/kexec_handover.c +0 -0
 	if (!populated)
 		pr_warn("disabling KHO revival\n");
 }
kernel/liveupdate/kexec_handover_internal.h +2 -0
index e9685e1ef6d7..b559f5d43116 100644
@@ -22,6 +22,14 @@ struct kho_debugfs {};
 extern struct kho_bootmem *kho_bootmem;
 extern unsigned int kho_bootmem_cnt;
 
+enum kho_incoming_state {
+	KHO_INCOMING_NONE,

This one is never set. Can we stick an explicit state = KHO_INCOMING_NONE at the declaration of struct kho_in for clarity?

Quoted 9 lines
kernel/liveupdate/kexec_handover_internal.h +6 -0
+	KHO_INCOMING_REVIVED,
+	KHO_INCOMING_FAILED,
+};
+
+enum kho_incoming_state kho_in_state(void);
+
 #ifdef CONFIG_KEXEC_HANDOVER_DEBUGFS
 int kho_debugfs_init(void);
 void kho_in_debugfs_init(struct kho_debugfs *dbg, const void *fdt);
Signature · 2 lines
Sincerely yours,
Mike.
maintainer
#10 lore raw

Re: [PATCH v2 5/7] kho: Report how much handover memory is preserved and restored

In reply to Chris Down
Quoted 91 lines · Chris Down

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 through kho_restore_page(), so KHO can count both easily. Let's add preserved_size and restored_size, in bytes, to /sys/kernel/kho/incoming/.

For example, after a live update preserving a 64 MiB memfd:

                     preserved_size  restored_size
    before retrieval       67403776           8192
    after finish           67403776       67395584

The 8 KiB left are the incoming KHO FDT and LUO's FLB header.

---
 Documentation/ABI/testing/sysfs-kernel-kho  | 10 ++++++++++
 Documentation/admin-guide/mm/kho.rst        |  3 +++
 kernel/liveupdate/kexec_handover.c          | 15 +++++++++++++++
 kernel/liveupdate/kexec_handover_internal.h |  2 ++
 kernel/liveupdate/kho_sysfs.c               | 16 ++++++++++++++++
 5 files changed, 46 insertions(+)
Documentation/ABI/testing/sysfs-kernel-kho +10 -0
index 21488e35d1f3..a8251d663ce6 100644
@@ -9,3 +9,13 @@ Description:	read only
 		           the walk of its preserved memory map.
 		"failed"   The kernel rejected the handover.
 Users:		system monitoring
+
+What:		/sys/kernel/kho/incoming/preserved_size
+What:		/sys/kernel/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".
+Users:		system monitoring
Documentation/admin-guide/mm/kho.rst +3 -0
index 8810813a5d0a..a12c1398eff2 100644
@@ -87,6 +87,9 @@ sysfs Interfaces
 ``/sys/kernel/kho/incoming/state``
     Status of the incoming KHO handover.
 
+``/sys/kernel/kho/incoming/preserved_size`` and ``restored_size``
+    Bytes preserved by the previous kernel and bytes restored through KHO.
+
 See Documentation/ABI/testing/sysfs-kernel-kho for the sysfs ABI.
 
 debugfs Interfaces
kernel/liveupdate/kexec_handover.c +4 -0
index aff96aa401f8..5d9b724ab754 100644
@@ -103,6 +103,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;
 };
@@ -545,6 +547,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;
 }
 
@@ -636,6 +639,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;
 }

kernel/liveupdate/kexec_handover.c err: · line 1753

Quoted 4 lines
kernel/liveupdate/kexec_handover.c +1 -0
@@ -1746,6 +1750,7 @@ err:
 	kho_in.fdt_phys = 0;
 	kho_in.radix_tree.root = NULL;
 	kho_in.state = KHO_INCOMING_FAILED;
+	kho_in.preserved_pages = 0;

I'm not sure we need to reset that if kho_mem_retrieve() fails. The memory is still preserved by the previous kernel.

kernel/liveupdate/kexec_handover.c enum kho_incoming_state kho_in_state(void) · line 1787

Quoted 10 lines
kernel/liveupdate/kexec_handover.c +3 -0
 }
 
 static __init int kho_out_fdt_setup(void)
@@ -1777,6 +1782,16 @@ enum kho_incoming_state kho_in_state(void)
 	return kho_in.state;
 }
 
+u64 kho_in_preserved_size(void)
+{
+	return (u64)kho_in.preserved_pages << PAGE_SHIFT;

Any reason to declare .reserved_pages as unsigned long and cast here? And since KHO depends on CONFIG_64BIT, why do we need to return u64 here?

I don't mind either, but let's remove the casting :)

kernel/liveupdate/kexec_handover.c enum kho_incoming_state kho_in_state(void) · line 1792

Quoted 5 lines
kernel/liveupdate/kexec_handover.c +5 -0
+}
+
+u64 kho_in_restored_size(void)
+{
+	return (u64)atomic_long_read(&kho_in.restored_pages) << PAGE_SHIFT;

I'd add a local variable to make this clearer.

Quoted 5 lines
kernel/liveupdate/kexec_handover.c +2 -0
+}
+
 static void __init kho_in_kexec_metadata(void)
 {
 	struct kho_kexec_metadata *metadata;
Signature · 2 lines
Sincerely yours,
Mike.