liveupdate: tighten handover cleanup and session lifetime
Subsystems (4)
v4 cover liveupdate: tighten handover cleanup and session lifetime
Hi Pasha,
this v4 keeps the simpler direction from your mail: outgoing handover is still driven by a boolean rebooting gate, refcount pinning of outgoing sessions during serialization, and session->mutex as the serialization point for in-flight mutations. There is no return to the earlier closing counter or a larger session state machine.
The main changes in this respin are:
- reshape the series into five commits, each building and standing on its own
- keep incoming session origin immutable and use retrieved only as the checked-out bit
- make FINISH and implicit close consume incoming sessions without reopening races through retrieve-by-name
- route deserialize failures through explicit rollback paths for sessions, files, and serialized memfd state
- validate KHO-preserved extents before walking serialized metadata
- harden incoming FLB lifetime and remaining teardown paths
Patches 1-4 keep the core session, kexec, deserialize and validation work separate. Patch 5 carries the remaining FLB and teardown fixes needed to match the final tree.
Oskar Gerlicz Kowalczuk (5):
liveupdate: block outgoing session updates during reboot
kexec: abort liveupdate handover on kernel_kexec() unwind
liveupdate: fail session restore on file deserialization errors
liveupdate: validate handover metadata before using it
liveupdate: harden FLB lifetime and remaining teardown paths
include/linux/kexec_handover.h | 13 + include/linux/liveupdate.h | 17 +- kernel/kexec_core.c | 4 + kernel/liveupdate/kexec_handover.c | 22 ++ kernel/liveupdate/luo_core.c | 16 +- kernel/liveupdate/luo_file.c | 237 ++++++++++++-- kernel/liveupdate/luo_flb.c | 116 +++++-- kernel/liveupdate/luo_internal.h | 14 +- kernel/liveupdate/luo_session.c | 500 ++++++++++++++++++++++++----- lib/tests/liveupdate.c | 2 + mm/memfd_luo.c | 160 +++++++-- 11 files changed, 934 insertions(+), 167 deletions(-)
Signature · 1 line
2.53.0
PATCH v4 1/5 liveupdate: block outgoing session updates during reboot
Block new outgoing session mutations with the rebooting gate and serialize in-flight operations with session->mutex. During serialization, pin the outgoing sessions with temporary references instead of relying on an auxiliary in-flight counter.
Also make incoming session origin immutable and use retrieved only as the "checked out by userspace" bit. This keeps FINISH, close(), and retrieve-by-name on a single lifetime model without reintroducing a larger session state machine.
--- kernel/liveupdate/luo_internal.h | 9 +- kernel/liveupdate/luo_session.c | 308 +++++++++++++++++++++++++------ 2 files changed, 259 insertions(+), 58 deletions(-)
kernel/liveupdate/luo_internal.h +7 -2
@@ -9,6 +9,7 @@#define _LINUX_LUO_INTERNAL_H#include <linux/liveupdate.h> +#include <linux/refcount.h> #include <linux/uaccess.h> struct luo_ucmd {
@@ -63,8 +64,10 @@ struct luo_file_set {* @list: A list_head member used to link this session into a global list * of either outgoing (to be preserved) or incoming (restored from * previous kernel) sessions. -* @retrieved: A boolean flag indicating whether this session has been -* retrieved by a consumer in the new kernel. +* @incoming: True for sessions restored from the previous kernel. This is +* immutable after publication and distinguishes incoming sessions +* from outgoing ones. +* @retrieved: True while an incoming session is checked out by userspace. * @file_set: A set of files that belong to this session. * @mutex: protects fields in the luo_session. */
@@ -72,8 +75,10 @@ struct luo_session {char name[LIVEUPDATE_SESSION_NAME_LENGTH ];struct luo_session_ser *ser;struct list_head list; +bool incoming;bool retrieved;struct luo_file_set file_set; +refcount_t refs;struct mutex mutex; };
kernel/liveupdate/luo_session.c +252 -56
467 lines not on this page · raw message
Signature · 1 line
2.53.0
PATCH v4 2/5 kexec: abort liveupdate handover on kernel_kexec() unwind
liveupdate_reboot() can freeze outgoing session state before the kexec transition completes. v2 only unwound that state when kernel_kexec() returned a non-zero error, which misses the preserve_context path where machine_kexec() can return to the old kernel with error == 0.
If that return path skips the abort, outgoing sessions remain stuck in the reboot state and later user space operations cannot make progress.
Treat every return to the original kernel after a prepared liveupdate handover as an unwind point and call liveupdate_reboot_abort() there as well.
--- include/linux/liveupdate.h | 5 +++++ kernel/kexec_core.c | 6 +++++- kernel/liveupdate/luo_core.c | 11 ++++++++++- kernel/liveupdate/luo_internal.h | 1 + kernel/liveupdate/luo_session.c | 30 ++++++++++++++++++++++++++++++ 5 files changed, 51 insertions(+), 2 deletions(-)
include/linux/liveupdate.h +5 -0
@@ -226,6 +226,7 @@ bool liveupdate_enabled(void);/* Called during kexec to tell LUO that entered into reboot */ int liveupdate_reboot (void ); +void liveupdate_reboot_abort (void );int liveupdate_register_file_handler (struct liveupdate_file_handler *fh);int liveupdate_unregister_file_handler (struct liveupdate_file_handler *fh);
@@ -250,6 +251,10 @@ static inline int liveupdate_reboot(void)return 0 ; } +static inline void liveupdate_reboot_abort (void ) +{ +} +static inline int liveupdate_register_file_handler (struct liveupdate_file_handler *fh) {return -EOPNOTSUPP ;
kernel/kexec_core.c +5 -1
@@ -1139,6 +1139,7 @@ bool kexec_load_permitted(int kexec_image_type)int kernel_kexec (void ) {int error =0 ; +bool liveupdate_prepared = false;if (!kexec_trylock ())return -EBUSY ;
@@ -1147,6 +1148,7 @@ int kernel_kexec(void) goto Unlock; } + liveupdate_prepared = true; error =liveupdate_reboot ();if (error) goto Unlock;
@@ -1230,7 +1232,9 @@ int kernel_kexec(void) }#endif - Unlock: +Unlock: +if (liveupdate_prepared) +liveupdate_reboot_abort ();kexec_unlock ();return error; }
kernel/liveupdate/luo_core.c +10 -1
@@ -233,8 +233,9 @@ int liveupdate_reboot(void) err =kho_finalize ();if (err) {pr_err ("kho_finalize failed %d\n" , err); +liveupdate_reboot_abort ();/* -* kho_finalize() may return libfdt errors, to aboid passing to +* kho_finalize() may return libfdt errors, to avoid passing to * userspace unknown errors, change this to EAGAIN. */ err = -EAGAIN ;
@@ -243,6 +244,14 @@ int liveupdate_reboot(void)return err; } +void liveupdate_reboot_abort (void ) +{ +if (!liveupdate_enabled ()) +return ; + +luo_session_abort_reboot (); +} +/** * liveupdate_enabled - Check if the live update feature is enabled. *
kernel/liveupdate/luo_internal.h +1 -0
@@ -87,6 +87,7 @@ int luo_session_retrieve(const char *name, struct file **filep);int __init luo_session_setup_outgoing (void *fdt);int __init luo_session_setup_incoming (void *fdt);int luo_session_serialize (void ); +void luo_session_abort_reboot (void );int luo_session_deserialize (void );bool luo_session_quiesce (void );void luo_session_resume (void );
kernel/liveupdate/luo_session.c +30 -0
@@ -294,6 +294,13 @@ static int luo_session_finish_retrieved(struct luo_session *session)return luo_file_finish (&session->file_set); } +static void luo_session_unfreeze_one (struct luo_session *session, +struct luo_session_ser *ser) +{ +guard (mutex)(&session->mutex); +luo_file_unfreeze (&session->file_set, &ser->file_set_ser); +} +static int luo_session_release (struct inode *inodep,struct file *filep) {struct luo_session *session = filep->private_data;
@@ -797,6 +804,29 @@ int luo_session_serialize(void) goto out_put_sessions; } +void luo_session_abort_reboot (void ) +{ +struct luo_session_header *sh = &luo_session_global.outgoing; +struct luo_session *session; +int i =0 ; + +guard (rwsem_write)(&sh->rwsem); +if (!READ_ONCE (sh->rebooting)) +return ; + +list_for_each_entry (session, &sh->list, list) { +if (i >= sh->header_ser->count) +break ; + +luo_session_unfreeze_one (session, &sh->ser[i]); +memset (&sh->ser[i],0 ,sizeof (sh->ser[i])); + i++; + } + + sh->header_ser->count =0 ; +luo_session_reboot_done (sh); +} +/** * luo_session_quiesce - Ensure no active sessions exist and lock session lists. *
Signature · 1 line
2.53.0
PATCH v4 3/5 liveupdate: fail session restore on file deserialization errors
Session restore can fail after inserting a partially constructed session into the incoming list. The v2 cleanup also reused finish-style teardown for that rollback path even though finish is the normal completion path for a fully restored session.
That can leave stale incoming sessions behind after a deserialize error and can run completion callbacks against state that was never fully rebuilt.
Require an explicit abort callback for file handlers, use it to unwind partially restored files, and route every deserialize failure through a single cleanup path that drops restored sessions, frees serialized file metadata and records the cached error code.
--- include/linux/liveupdate.h | 3 ++ kernel/liveupdate/luo_file.c | 67 +++++++++++++++++++++++--------- kernel/liveupdate/luo_internal.h | 1 + kernel/liveupdate/luo_session.c | 56 +++++++++++++++----------- mm/memfd_luo.c | 24 +++++++----- 5 files changed, 100 insertions(+), 51 deletions(-)
include/linux/liveupdate.h +3 -0
@@ -63,6 +63,8 @@ struct liveupdate_file_op_args {* finish, in order to do successful finish calls for all * resources in the session. * @finish: Required. Final cleanup in the new kernel. +* @abort: Required. Discard preserved state in the new kernel without +* completing finish(). * @owner: Module reference * * All operations (except can_preserve) receive a pointer to a
@@ -78,6 +80,7 @@ struct liveupdate_file_ops {int (*retrieve)(struct liveupdate_file_op_args *args);bool (*can_finish)(struct liveupdate_file_op_args *args);void (*finish)(struct liveupdate_file_op_args *args); +void (*abort)(struct liveupdate_file_op_args *args);struct module *owner; };
kernel/liveupdate/luo_file.c +48 -19
112 lines not on this page · raw message
kernel/liveupdate/luo_internal.h +1 -0
@@ -101,6 +101,7 @@ void luo_file_unfreeze(struct luo_file_set *file_set,int luo_retrieve_file (struct luo_file_set *file_set,u64 token,struct file **filep);int luo_file_finish (struct luo_file_set *file_set); +void luo_file_abort_deserialized (struct luo_file_set *file_set);int luo_file_deserialize (struct luo_file_set *file_set,struct luo_file_set_ser *file_set_ser);void luo_file_set_init (struct luo_file_set *file_set);
kernel/liveupdate/luo_session.c +33 -23
91 lines not on this page · raw message
mm/memfd_luo.c +15 -9
@@ -358,19 +358,11 @@ static void memfd_luo_discard_folios(const struct memfd_luo_folio_ser *folios_se } } -static void memfd_luo_finish (struct liveupdate_file_op_args *args) +static void memfd_luo_abort (struct liveupdate_file_op_args *args) {struct memfd_luo_folio_ser *folios_ser;struct memfd_luo_ser *ser; -/* -* If retrieve was successful, nothing to do. If it failed, retrieve() -* already cleaned up everything it could. So nothing to do there -* either. Only need to clean up when retrieve was not called. -*/ -if (args->retrieve_status) -return ; - ser =phys_to_virt (args->serialized_data);if (!ser)return ;
@@ -388,6 +380,19 @@ static void memfd_luo_finish(struct liveupdate_file_op_args *args)kho_restore_free (ser); } +static void memfd_luo_finish (struct liveupdate_file_op_args *args) +{ +/* +* If retrieve was successful, nothing to do. If it failed, retrieve() +* already cleaned up everything it could. So nothing to do there +* either. Only need to clean up when retrieve was not called. +*/ +if (args->retrieve_status) +return ; + +memfd_luo_abort (args); +} +static int memfd_luo_retrieve_folios (struct file *file,struct memfd_luo_folio_ser *folios_ser,u64 nr_folios)
@@ -532,6 +537,7 @@ static bool memfd_luo_can_preserve(struct liveupdate_file_handler *handler,static const struct liveupdate_file_ops memfd_luo_file_ops = { .freeze = memfd_luo_freeze, .finish = memfd_luo_finish, + .abort = memfd_luo_abort, .retrieve = memfd_luo_retrieve, .preserve = memfd_luo_preserve, .unpreserve = memfd_luo_unpreserve,
Signature · 1 line
2.53.0
PATCH v4 4/5 liveupdate: validate handover metadata before using it
The incoming handover path was still trusting counts and preserved addresses more than it should. Corrupted metadata could drive phys_to_virt() or kho_restore_free() with invalid addresses, and memfd restore could walk beyond the serialized folio array.
That turns malformed handover state into out-of-bounds iteration, invalid restore frees, or partially restored incoming state.
Validate session, file and FLB metadata before consuming it, reject non-restorable preserved addresses, and bound memfd folio restore by both the serialized size and the restored vmalloc backing.
--- include/linux/kexec_handover.h | 5 +++ kernel/liveupdate/kexec_handover.c | 13 +++++++ kernel/liveupdate/luo_file.c | 22 +++++++++--- kernel/liveupdate/luo_flb.c | 33 ++++++++++++++++-- kernel/liveupdate/luo_session.c | 29 ++++++++++++++-- mm/memfd_luo.c | 56 ++++++++++++++++++++++++++++-- 6 files changed, 147 insertions(+), 11 deletions(-)
include/linux/kexec_handover.h +5 -0
@@ -29,6 +29,7 @@ void kho_unpreserve_vmalloc(struct kho_vmalloc *preservation);void *kho_alloc_preserve (size_t size);void kho_unpreserve_free (void *mem);void kho_restore_free (void *mem); +bool kho_is_restorable_phys (phys_addr_t phys);struct folio *kho_restore_folio (phys_addr_t phys);struct page *kho_restore_pages (phys_addr_t phys,unsigned long nr_pages);void *kho_restore_vmalloc (const struct kho_vmalloc *preservation);
@@ -80,6 +81,10 @@ static inline void *kho_alloc_preserve(size_t size)static inline void kho_unpreserve_free (void *mem) { }static inline void kho_restore_free (void *mem) { } +static inline bool kho_is_restorable_phys (phys_addr_t phys) +{ +return false; +}static inline struct folio *kho_restore_folio (phys_addr_t phys) {
kernel/liveupdate/kexec_handover.c +13 -0
@@ -291,6 +291,19 @@ struct folio *kho_restore_folio(phys_addr_t phys) }EXPORT_SYMBOL_GPL (kho_restore_folio); +bool kho_is_restorable_phys (phys_addr_t phys) +{ +struct page *page =pfn_to_online_page (PHYS_PFN (phys)); +union kho_page_info info; + +if (!page || !PAGE_ALIGNED (phys)) +return false; + + info.page_private =READ_ONCE (page->private); +return info.magic ==KHO_PAGE_MAGIC && info.order <=MAX_PAGE_ORDER ; +} +EXPORT_SYMBOL_GPL (kho_is_restorable_phys); +/** * kho_restore_pages - restore list of contiguous order 0 pages. * @phys: physical address of the first page.
kernel/liveupdate/luo_file.c +18 -4
@@ -785,10 +785,17 @@ int luo_file_deserialize(struct luo_file_set *file_set,u64 i;int err; -if (!file_set_ser->files) { -WARN_ON (file_set_ser->count); -return 0 ; - } +if (!file_set_ser->count) +return file_set_ser->files ? -EINVAL :0 ; + +if (!file_set_ser->files) +return -EINVAL ; + +if (file_set_ser->count >LUO_FILE_MAX ) +return -EINVAL ; + +if (!kho_is_restorable_phys (file_set_ser->files)) +return -EINVAL ; file_set->count = file_set_ser->count; file_set->files =phys_to_virt (file_set_ser->files);
@@ -799,6 +806,13 @@ int luo_file_deserialize(struct luo_file_set *file_set,bool handler_found = false;struct luo_file *luo_file; +if (strnlen (file_ser[i].compatible, +sizeof (file_ser[i].compatible)) == +sizeof (file_ser[i].compatible)) { + err = -EINVAL ; + goto err_discard; + } +list_private_for_each_entry (fh, &luo_file_handler_list, list) {if (!strcmp (fh->compatible, file_ser[i].compatible)) { handler_found = true;
kernel/liveupdate/luo_flb.c +31 -2
@@ -165,7 +165,14 @@ static int luo_flb_retrieve_one(struct liveupdate_flb *flb)return -ENODATA ;for (int i =0 ; i < fh->header_ser->count; i++) { +if (strnlen (fh->ser[i].name,sizeof (fh->ser[i].name)) == +sizeof (fh->ser[i].name)) +return -EINVAL ; +if (!strcmp (fh->ser[i].name, flb->compatible)) { +if (!fh->ser[i].count) +return -EINVAL ; + private->incoming.data = fh->ser[i].data; private->incoming.count = fh->ser[i].count; found = true;
@@ -578,6 +585,7 @@ int __init luo_flb_setup_outgoing(void *fdt_out)int __init luo_flb_setup_incoming (void *fdt_in) { +struct luo_flb_header_ser *header_copy;struct luo_flb_header_ser *header_ser;int err, header_size, offset;const void *ptr;
@@ -609,10 +617,31 @@ int __init luo_flb_setup_incoming(void *fdt_in) } header_ser_pa =get_unaligned ((u64 *)ptr); +if (!header_ser_pa) { +pr_err ("FLB header address is missing\n" ); +return -EINVAL ; + } + +if (!kho_is_restorable_phys (header_ser_pa)) +return -EINVAL ; + header_ser =phys_to_virt (header_ser_pa); +if (header_ser->pgcnt !=LUO_FLB_PGCNT || header_ser->count >LUO_FLB_MAX ) { +kho_restore_free (header_ser); +return -EINVAL ; + } + + header_copy =kmemdup (header_ser, +sizeof (*header_copy) + + header_ser->count * +sizeof (*luo_flb_global.incoming.ser), +GFP_KERNEL ); +kho_restore_free (header_ser); +if (!header_copy) +return -ENOMEM ; - luo_flb_global.incoming.header_ser = header_ser; - luo_flb_global.incoming.ser = (void *)(header_ser +1 ); + luo_flb_global.incoming.header_ser = header_copy; + luo_flb_global.incoming.ser = (void *)(header_copy +1 ); luo_flb_global.incoming.active = true;return 0 ;
kernel/liveupdate/luo_session.c +26 -3
@@ -688,6 +688,14 @@ int __init luo_session_setup_incoming(void *fdt_in) } header_ser_pa =get_unaligned ((u64 *)ptr); +if (!header_ser_pa) { +pr_err ("Session header address is missing\n" ); +return -EINVAL ; + } + +if (!kho_is_restorable_phys (header_ser_pa)) +return -EINVAL ; + header_ser =phys_to_virt (header_ser_pa); luo_session_global.incoming.header_ser = header_ser;
@@ -712,9 +720,22 @@ int luo_session_deserialize(void)if (!sh->active)return err; +if (sh->header_ser->count >LUO_SESSION_MAX ) { +pr_warn ("Invalid session count %llu\n" , sh->header_ser->count); + err = -EINVAL ; + goto out_free_header; + } +for (int i =0 ; i < sh->header_ser->count; i++) {struct luo_session *session; +if (strnlen (sh->ser[i].name,sizeof (sh->ser[i].name)) == +sizeof (sh->ser[i].name)) { +pr_warn ("Session name is not NUL-terminated\n" ); + err = -EINVAL ; + goto out_discard; + } + session =luo_session_alloc (sh->ser[i].name);if (IS_ERR (session)) { pr_warn("Failed to allocate session [%s] during deserialization %pe\n",
@@ -743,9 +764,11 @@ int luo_session_deserialize(void) } out_free_header: -kho_restore_free (sh->header_ser); - sh->header_ser =NULL ; - sh->ser =NULL ; +if (sh->header_ser) { +kho_restore_free (sh->header_ser); + sh->header_ser =NULL ; + sh->ser =NULL ; + }return err;
mm/memfd_luo.c +54 -2
103 lines not on this page · raw message
Signature · 1 line
2.53.0
PATCH v4 5/5 liveupdate: harden FLB lifetime and remaining teardown paths
The earlier cleanup patches fix the primary deserialize rollback paths, but some teardown and lifetime edges are still open.
Incoming FLB objects can still race with finish(), copied incoming FLB metadata can be torn down while another thread scans it, and the remaining raw serialized file cleanup still needs a bounded, handler-aware abort path. The quiesce path also has to reject the /dev/liveupdate open window, not just non-empty session lists.
Tighten the remaining teardown paths by:
- making incoming FLB access hold the incoming lock until the caller drops it
- discarding copied incoming FLB metadata once the last incoming session is gone or rollback aborts it
- adding bounded raw serialized file cleanup and a known-format memfd abort helper
- teaching KHO about the size of a restorable block so cleanup and retrieve paths can validate preserved extents before walking them
- rejecting handler registration changes while /dev/liveupdate is busy
This leaves the series on the simpler rebooting + mutex + refcount model, while closing the remaining lifetime and cleanup holes around incoming teardown.
--- include/linux/kexec_handover.h | 8 ++ include/linux/liveupdate.h | 9 +- kernel/kexec_core.c | 2 +- kernel/liveupdate/kexec_handover.c | 15 ++- kernel/liveupdate/luo_core.c | 5 + kernel/liveupdate/luo_file.c | 156 ++++++++++++++++++++++++++--- kernel/liveupdate/luo_flb.c | 87 +++++++++++----- kernel/liveupdate/luo_internal.h | 3 + kernel/liveupdate/luo_session.c | 127 ++++++++++++++++++----- lib/tests/liveupdate.c | 2 + mm/memfd_luo.c | 128 ++++++++++++++++------- 11 files changed, 437 insertions(+), 105 deletions(-)
include/linux/kexec_handover.h +8 -0
@@ -2,6 +2,7 @@#ifndef LINUX_KEXEC_HANDOVER_H #define LINUX_KEXEC_HANDOVER_H +#include <linux/bug.h> #include <linux/err.h> #include <linux/errno.h> #include <linux/types.h>
@@ -30,6 +31,7 @@ void *kho_alloc_preserve(size_t size);void kho_unpreserve_free (void *mem);void kho_restore_free (void *mem);bool kho_is_restorable_phys (phys_addr_t phys); +size_t kho_restorable_size (phys_addr_t phys);struct folio *kho_restore_folio (phys_addr_t phys);struct page *kho_restore_pages (phys_addr_t phys,unsigned long nr_pages);void *kho_restore_vmalloc (const struct kho_vmalloc *preservation);
@@ -85,6 +87,12 @@ static inline bool kho_is_restorable_phys(phys_addr_t phys) {return false; } +static inline size_t kho_restorable_size (phys_addr_t phys) +{ +if (phys) +WARN_ON_ONCE (!IS_ENABLED (CONFIG_KEXEC_HANDOVER )); +return 0 ; +}static inline struct folio *kho_restore_folio (phys_addr_t phys) {
include/linux/liveupdate.h +8 -1
@@ -239,7 +239,10 @@ int liveupdate_register_flb(struct liveupdate_file_handler *fh,int liveupdate_unregister_flb (struct liveupdate_file_handler *fh,struct liveupdate_flb *flb); -int liveupdate_flb_get_incoming (struct liveupdate_flb *flb,void **objp); +int liveupdate_flb_get_incoming(struct liveupdate_flb *flb, void **objp) + __acquires(&ACCESS_PRIVATE(flb, private).incoming.lock); +void liveupdate_flb_put_incoming(struct liveupdate_flb *flb) + __releases(&ACCESS_PRIVATE(flb, private).incoming.lock);int liveupdate_flb_get_outgoing (struct liveupdate_flb *flb,void **objp);#else /* CONFIG_LIVEUPDATE */
@@ -286,6 +289,10 @@ static inline int liveupdate_flb_get_incoming(struct liveupdate_flb *flb,return -EOPNOTSUPP ; } +static inline void liveupdate_flb_put_incoming (struct liveupdate_flb *flb) +{ +} +static inline int liveupdate_flb_get_outgoing (struct liveupdate_flb *flb,void **objp) {
kernel/kexec_core.c +1 -1
@@ -1232,7 +1232,7 @@ int kernel_kexec(void) }#endif -Unlock: + Unlock:if (liveupdate_prepared)liveupdate_reboot_abort ();kexec_unlock ();
kernel/liveupdate/kexec_handover.c +12 -3
@@ -291,16 +291,25 @@ struct folio *kho_restore_folio(phys_addr_t phys) }EXPORT_SYMBOL_GPL (kho_restore_folio); -bool kho_is_restorable_phys (phys_addr_t phys) +size_t kho_restorable_size (phys_addr_t phys) {struct page *page =pfn_to_online_page (PHYS_PFN (phys));union kho_page_info info;if (!page || !PAGE_ALIGNED (phys)) -return false; +return 0 ; info.page_private =READ_ONCE (page->private); -return info.magic ==KHO_PAGE_MAGIC && info.order <=MAX_PAGE_ORDER ; +if (info.magic !=KHO_PAGE_MAGIC || info.order >MAX_PAGE_ORDER ) +return 0 ; + +return PAGE_SIZE << info.order; +} +EXPORT_SYMBOL_GPL (kho_restorable_size); + +bool kho_is_restorable_phys (phys_addr_t phys) +{ +return kho_restorable_size (phys) !=0 ; }EXPORT_SYMBOL_GPL (kho_is_restorable_phys);
kernel/liveupdate/luo_core.c +5 -0
@@ -451,6 +451,11 @@ static struct luo_device_state luo_dev = { .in_use = ATOMIC_INIT(0), }; +bool luo_device_busy (void ) +{ +return atomic_read (&luo_dev.in_use); +} +static int __init liveupdate_ioctl_init (void ) {if (!liveupdate_enabled ())
kernel/liveupdate/luo_file.c +144 -12
212 lines not on this page · raw message
kernel/liveupdate/luo_flb.c +64 -23
148 lines not on this page · raw message
kernel/liveupdate/luo_internal.h +3 -0
@@ -91,6 +91,7 @@ void luo_session_abort_reboot(void);int luo_session_deserialize (void );bool luo_session_quiesce (void );void luo_session_resume (void ); +bool luo_device_busy (void );int luo_preserve_file (struct luo_file_set *file_set,u64 token,int fd);void luo_file_unpreserve_files (struct luo_file_set *file_set);
@@ -102,6 +103,7 @@ int luo_retrieve_file(struct luo_file_set *file_set, u64 token, struct file **filep);int luo_file_finish (struct luo_file_set *file_set);void luo_file_abort_deserialized (struct luo_file_set *file_set); +void luo_file_abort_serialized (const struct luo_file_set_ser *file_set_ser);int luo_file_deserialize (struct luo_file_set *file_set,struct luo_file_set_ser *file_set_ser);void luo_file_set_init (struct luo_file_set *file_set);
@@ -112,6 +114,7 @@ void luo_flb_file_unpreserve(struct liveupdate_file_handler *fh);void luo_flb_file_finish (struct liveupdate_file_handler *fh);int __init luo_flb_setup_outgoing (void *fdt);int __init luo_flb_setup_incoming (void *fdt); +void luo_flb_discard_incoming (void );void luo_flb_serialize (void );#ifdef CONFIG_LIVEUPDATE_TEST
kernel/liveupdate/luo_session.c +100 -27
298 lines not on this page · raw message
lib/tests/liveupdate.c +2 -0
@@ -104,6 +104,8 @@ static void liveupdate_test_init(void)if (err && err != -ENODATA && err != -ENOENT ) {pr_err ("liveupdate_flb_get_incoming for %s failed: %pe\n" , flb->compatible,ERR_PTR (err)); + }else if (!err) { +liveupdate_flb_put_incoming (flb); } } initialized = true;
mm/memfd_luo.c +90 -38
188 lines not on this page · raw message
Signature · 1 line
2.53.0
Pasha Tatashin
maintainerQuoted 33 lines · Oskar Gerlicz Kowalczuk
Hi Pasha,
this v4 keeps the simpler direction from your mail: outgoing handover is still driven by a boolean rebooting gate, refcount pinning of outgoing sessions during serialization, and
session->mutexas the serialization point for in-flight mutations. There is no return to the earlier closing counter or a larger session state machine.The main changes in this respin are:
- reshape the series into five commits, each building and standing on its own
- keep incoming session origin immutable and use retrieved only as the checked-out bit
- make FINISH and implicit close consume incoming sessions without reopening races through retrieve-by-name
- route deserialize failures through explicit rollback paths for sessions, files, and serialized memfd state
- validate KHO-preserved extents before walking serialized metadata
- harden incoming FLB lifetime and remaining teardown pathsPatches 1-4 keep the core session, kexec, deserialize and validation work separate. Patch 5 carries the remaining FLB and teardown fixes needed to match the final tree.
Oskar Gerlicz Kowalczuk (5):
liveupdate: block outgoing session updates during reboot
kexec: abort liveupdate handover onkernel_kexec()unwind
liveupdate: fail session restore on file deserialization errors
liveupdate: validate handover metadata before using it
liveupdate: harden FLB lifetime and remaining teardown paths
Quoted 12 lines
include/linux/kexec_handover.h | 13 + include/linux/liveupdate.h | 17 +- kernel/kexec_core.c | 4 + kernel/liveupdate/kexec_handover.c | 22 ++ kernel/liveupdate/luo_core.c | 16 +- kernel/liveupdate/luo_file.c | 237 ++++++++++++-- kernel/liveupdate/luo_flb.c | 116 +++++-- kernel/liveupdate/luo_internal.h | 14 +- kernel/liveupdate/luo_session.c | 500 ++++++++++++++++++++++++----- lib/tests/liveupdate.c | 2 + mm/memfd_luo.c | 160 +++++++-- 11 files changed, 934 insertions(+), 167 deletions(-)
Hi Oskar,
This is a NAK.
This patch series is still significantly over-engineering solutions to straightforward problems, and the patches read as if they were mechanically generated rather than thoughtfully designed. The sheer volume of changes (nearly 1,000 lines) is unnecessary for what we are trying to achieve.
As I pointed out previously, we need to keep this simple. For example, the problem of preventing a return to userspace after a successful liveupdate_reboot() does not require inventing a new liveupdate_reboot_abort() function. It just requires placing the call where it's the last function allowed to return, with a simple exception for context-preserved kexec jumps. That is a trivial change:
- error = liveupdate_reboot();
- if (error)
- goto Unlock;
+ if (!kexec_image->preserve_context) {
+ error = liveupdate_reboot();
+ if (error)
+ goto Unlock;
+ }
The same principle applies to the other issues. You are doing rewrites when targeted fixes should be applied:
- Sessions mutating after entering the reboot() syscall?: This is a 14-line fix [1].
- Destroyed serialization race during liveupdate_reboot()? This is a 70-line fix [2].
I was hoping that v4 (BTW, why are we at v4 in just a week?) would include the patches I already provided, along with similarly scoped, minimal fixes for the deserialization path if needed. Instead, I am seeing another over-complicated rewrite.
Looking at deserialization, I am seeing, you are deleting a comment that explicitly explains our error-handling design:
- /*
- * Note on error handling: - * - * If deserialization fails (e.g., allocation failure or corrupt data), - * we intentionally skip cleanup of files that were already restored. - * - * A partial failure leaves the preserved state inconsistent. - * Implementing a safe "undo" to unwind complex dependencies (sessions, - * files, hardware state) is error-prone and provides little value, as - * the system is effectively in a broken state. - * - * We treat these resources as leaked. The expected recovery path is for - * userspace to detect the failure and trigger a reboot, which will - * reliably reset devices and reclaim memory. - */
You are adding a bunch of new functions to solve something we intentionally chose not to solve. Attempting to cleanly unwind and release incorrectly deserialized resources back to userspace is dangerous. It risks security violations and, in the worst-case scenario, customer data leaks. A failed deserialization means the system is broken; we leak the resources (make them unavailable) and rely on a reboot to reliably sanitize the state.
Please drop the over-engineered approaches. Use the patches provided, keep the fixes minimal, and do not alter established security boundaries like the deserialization error paths. Take your time to manually self-review your work, do not rely on AI to do everything for you.
[1] https://git.kernel.org/pub/scm/linux/kernel/git/tatashin/linux.git/commit/?h=luo-reboot-sync/rfc/1&id=d47b76707c4f352c3f70384d3d6a818e2875439a
[2] https://git.kernel.org/pub/scm/linux/kernel/git/tatashin/linux.git/commit/?h=luo-reboot-sync/rfc/1&id=f27a6a9364cd0a19067734eeb24ea4d290b72139
Pasha
Quoted 4 lines
--
2.53.0
Quoted 126 lines · Pasha Tatashin
Quoted 34 lines · Oskar Gerlicz Kowalczuk
Hi Pasha,
this v4 keeps the simpler direction from your mail: outgoing handover is still driven by a boolean rebooting gate, refcount pinning of outgoing sessions during serialization, and
session->mutexas the serialization point for in-flight mutations. There is no return to the earlier closing counter or a larger session state machine.The main changes in this respin are:
- reshape the series into five commits, each building and standing on its
own
- keep incoming session origin immutable and use retrieved only as the checked-out bit
- make FINISH and implicit close consume incoming sessions without reopening races through retrieve-by-name
- route deserialize failures through explicit rollback paths for sessions, files, and serialized memfd state
- validate KHO-preserved extents before walking serialized metadata
- harden incoming FLB lifetime and remaining teardown pathsPatches 1-4 keep the core session, kexec, deserialize and validation work separate. Patch 5 carries the remaining FLB and teardown fixes needed to match the final tree.
Oskar Gerlicz Kowalczuk (5):
liveupdate: block outgoing session updates during reboot
kexec: abort liveupdate handover onkernel_kexec()unwind
liveupdate: fail session restore on file deserialization errors
liveupdate: validate handover metadata before using it
liveupdate: harden FLB lifetime and remaining teardown pathsQuoted 13 lines
include/linux/kexec_handover.h | 13 + include/linux/liveupdate.h | 17 +- kernel/kexec_core.c | 4 + kernel/liveupdate/kexec_handover.c | 22 ++ kernel/liveupdate/luo_core.c | 16 +- kernel/liveupdate/luo_file.c | 237 ++++++++++++-- kernel/liveupdate/luo_flb.c | 116 +++++-- kernel/liveupdate/luo_internal.h | 14 +- kernel/liveupdate/luo_session.c | 500 ++++++++++++++++++++++++----- lib/tests/liveupdate.c | 2 + mm/memfd_luo.c | 160 +++++++-- 11 files changed, 934 insertions(+), 167 deletions(-)Hi Oskar,
This is a NAK.
This patch series is still significantly over-engineering solutions to straightforward problems, and the patches read as if they were mechanically generated rather than thoughtfully designed. The sheer volume of changes (nearly 1,000 lines) is unnecessary for what we are trying to achieve.
As I pointed out previously, we need to keep this simple. For example, the problem of preventing a return to userspace after a successful
liveupdate_reboot()does not require inventing a newliveupdate_reboot_abort()function. It just requires placing the call where it's the last function allowed to return, with a simple exception for context-preserved kexec jumps. That is a trivial change:(quoted diff) +5
-3- error = liveupdate_reboot(); - if (error) - goto Unlock; + if (!kexec_image->preserve_context) { + error = liveupdate_reboot(); + if (error) + goto Unlock; + }The same principle applies to the other issues. You are doing rewrites when targeted fixes should be applied:
- Sessions mutating after entering thereboot()syscall?: This is a 14-line fix [1].
- Destroyed serialization race duringliveupdate_reboot()? This is a 70-line fix [2].I was hoping that v4 (BTW, why are we at v4 in just a week?) would include the patches I already provided, along with similarly scoped, minimal fixes for the deserialization path if needed. Instead, I am seeing another over-complicated rewrite.
Looking at deserialization, I am seeing, you are deleting a comment that explicitly explains our error-handling design:
(quoted diff) +0
-4- /* - * Note on error handling: - * - * If deserialization fails (e.g., allocation failure orcorrupt data),
- * we intentionally skip cleanup of files that were already
restored.(quoted diff) +0
-3- * - * A partial failure leaves the preserved state inconsistent. - * Implementing a safe "undo" to unwind complex dependencies(sessions,
- * files, hardware state) is error-prone and provides little
value, as(quoted diff) +0
-3- * the system is effectively in a broken state. - * - * We treat these resources as leaked. The expected recoverypath is for
- * userspace to detect the failure and trigger a reboot, which
will(quoted diff) +0
-2- * reliably reset devices and reclaim memory. - */You are adding a bunch of new functions to solve something we intentionally chose not to solve. Attempting to cleanly unwind and release incorrectly deserialized resources back to userspace is dangerous. It risks security violations and, in the worst-case scenario, customer data leaks. A failed deserialization means the system is broken; we leak the resources (make them unavailable) and rely on a reboot to reliably sanitize the state.
Please drop the over-engineered approaches. Use the patches provided, keep the fixes minimal, and do not alter established security boundaries like the deserialization error paths. Take your time to manually self-review your work, do not rely on AI to do everything for you.
Quoted 9 lines
[1] https://git.kernel.org/pub/scm/linux/kernel/git/tatashin/linux.git/commit/?h=luo-reboot-sync/rfc/1&id=d47b76707c4f352c3f70384d3d6a818e2875439a
[2] https://git.kernel.org/pub/scm/linux/kernel/git/tatashin/linux.git/commit/?h=luo-reboot-sync/rfc/1&id=f27a6a9364cd0a19067734eeb24ea4d290b72139Pasha
Quoted 4 lines
--
2.53.0
Hi Pasha, thank you for the detailed feedback and for sharing your patches. I understand that my previous version was overcomplicated. I will rework the series to follow your approach and keep the changes minimal. I plan to send an updated version later today. Thanks, Oskar Gerlicz-Kowalczuk
Quoted 126 lines · Pasha Tatashin
Quoted 34 lines · Oskar Gerlicz Kowalczuk
Hi Pasha,
this v4 keeps the simpler direction from your mail: outgoing handover is still driven by a boolean rebooting gate, refcount pinning of outgoing sessions during serialization, and
session->mutexas the serialization point for in-flight mutations. There is no return to the earlier closing counter or a larger session state machine.The main changes in this respin are:
- reshape the series into five commits, each building and standing on its
own
- keep incoming session origin immutable and use retrieved only as the checked-out bit
- make FINISH and implicit close consume incoming sessions without reopening races through retrieve-by-name
- route deserialize failures through explicit rollback paths for sessions, files, and serialized memfd state
- validate KHO-preserved extents before walking serialized metadata
- harden incoming FLB lifetime and remaining teardown pathsPatches 1-4 keep the core session, kexec, deserialize and validation work separate. Patch 5 carries the remaining FLB and teardown fixes needed to match the final tree.
Oskar Gerlicz Kowalczuk (5):
liveupdate: block outgoing session updates during reboot
kexec: abort liveupdate handover onkernel_kexec()unwind
liveupdate: fail session restore on file deserialization errors
liveupdate: validate handover metadata before using it
liveupdate: harden FLB lifetime and remaining teardown pathsQuoted 13 lines
include/linux/kexec_handover.h | 13 + include/linux/liveupdate.h | 17 +- kernel/kexec_core.c | 4 + kernel/liveupdate/kexec_handover.c | 22 ++ kernel/liveupdate/luo_core.c | 16 +- kernel/liveupdate/luo_file.c | 237 ++++++++++++-- kernel/liveupdate/luo_flb.c | 116 +++++-- kernel/liveupdate/luo_internal.h | 14 +- kernel/liveupdate/luo_session.c | 500 ++++++++++++++++++++++++----- lib/tests/liveupdate.c | 2 + mm/memfd_luo.c | 160 +++++++-- 11 files changed, 934 insertions(+), 167 deletions(-)Hi Oskar,
This is a NAK.
This patch series is still significantly over-engineering solutions to straightforward problems, and the patches read as if they were mechanically generated rather than thoughtfully designed. The sheer volume of changes (nearly 1,000 lines) is unnecessary for what we are trying to achieve.
As I pointed out previously, we need to keep this simple. For example, the problem of preventing a return to userspace after a successful
liveupdate_reboot()does not require inventing a newliveupdate_reboot_abort()function. It just requires placing the call where it's the last function allowed to return, with a simple exception for context-preserved kexec jumps. That is a trivial change:(quoted diff) +5
-3- error = liveupdate_reboot(); - if (error) - goto Unlock; + if (!kexec_image->preserve_context) { + error = liveupdate_reboot(); + if (error) + goto Unlock; + }The same principle applies to the other issues. You are doing rewrites when targeted fixes should be applied:
- Sessions mutating after entering thereboot()syscall?: This is a 14-line fix [1].
- Destroyed serialization race duringliveupdate_reboot()? This is a 70-line fix [2].I was hoping that v4 (BTW, why are we at v4 in just a week?) would include the patches I already provided, along with similarly scoped, minimal fixes for the deserialization path if needed. Instead, I am seeing another over-complicated rewrite.
Looking at deserialization, I am seeing, you are deleting a comment that explicitly explains our error-handling design:
(quoted diff) +0
-4- /* - * Note on error handling: - * - * If deserialization fails (e.g., allocation failure orcorrupt data),
- * we intentionally skip cleanup of files that were already
restored.(quoted diff) +0
-3- * - * A partial failure leaves the preserved state inconsistent. - * Implementing a safe "undo" to unwind complex dependencies(sessions,
- * files, hardware state) is error-prone and provides little
value, as(quoted diff) +0
-3- * the system is effectively in a broken state. - * - * We treat these resources as leaked. The expected recoverypath is for
- * userspace to detect the failure and trigger a reboot, which
will(quoted diff) +0
-2- * reliably reset devices and reclaim memory. - */You are adding a bunch of new functions to solve something we intentionally chose not to solve. Attempting to cleanly unwind and release incorrectly deserialized resources back to userspace is dangerous. It risks security violations and, in the worst-case scenario, customer data leaks. A failed deserialization means the system is broken; we leak the resources (make them unavailable) and rely on a reboot to reliably sanitize the state.
Please drop the over-engineered approaches. Use the patches provided, keep the fixes minimal, and do not alter established security boundaries like the deserialization error paths. Take your time to manually self-review your work, do not rely on AI to do everything for you.
Quoted 9 lines
[1] https://git.kernel.org/pub/scm/linux/kernel/git/tatashin/linux.git/commit/?h=luo-reboot-sync/rfc/1&id=d47b76707c4f352c3f70384d3d6a818e2875439a
[2] https://git.kernel.org/pub/scm/linux/kernel/git/tatashin/linux.git/commit/?h=luo-reboot-sync/rfc/1&id=f27a6a9364cd0a19067734eeb24ea4d290b72139Pasha
Quoted 4 lines
--
2.53.0
Hi Pasha, thank you for the detailed feedback and for sharing your patches. I understand that my previous version was overcomplicated. I will rework the series to follow your approach and keep the changes minimal. I plan to send an updated version later today.
Thanks,
Oskar Gerlicz-Kowalczuk
Mike Rapoport
maintainerHi Oskar,
Quoted 7 lines · On Thu, Mar 26, 2026 at 07:47:03AM +0100, [email protected] wrote:
Quoted 1 line · Pasha Tatashin
On Tue, Mar 24, 2026 at 5:29 PM Oskar Gerlicz Kowalczuk
Hi Pasha, thank you for the detailed feedback and for sharing your patches. I understand that my previous version was overcomplicated. I will rework the series to follow your approach and keep the changes minimal. I plan to send an updated version later today.
When you are resending please make sure to avoid deep threading of the replies so that all patch emails would be In-Reply-To to the cover letter.
Quoted 3 lines
Thanks,
Oskar Gerlicz-Kowalczuk
Signature · 2 lines
Sincerely yours, Mike.
Pasha Tatashin
maintainerQuoted 11 lines · Mike Rapoport
Hi Oskar,
Quoted 7 lines · On Thu, Mar 26, 2026 at 07:47:03AM +0100, [email protected] wrote:
Quoted 1 line · Pasha Tatashin
On Tue, Mar 24, 2026 at 5:29 PM Oskar Gerlicz Kowalczuk
Hi Pasha, thank you for the detailed feedback and for sharing your patches. I understand that my previous version was overcomplicated. I will rework the series to follow your approach and keep the changes minimal. I plan to send an updated version later today.
Please take a few days to manually review the patches before sending them out; no need to rush them out today. As I mentioned earlier, it is very unusual for a series to iterate to v4 within a week.
Quoted 2 lines
When you are resending please make sure to avoid deep threading of the replies so that all patch emails would be In-Reply-To to the cover letter.
+1
Quoted 8 lines
Quoted 4 lines
Thanks,
Oskar Gerlicz-Kowalczuk--
Sincerely yours,
Mike.