* [PATCH v6 1/7] liveupdate: Move file_set_ser handling to luo_session_serialize()
2026-11-18 21:28 [PATCH v6 0/7] liveupdate: Add LIVEUPDATE_SESSION_FREEZE ioctl Pasha Tatashin
@ 2026-11-18 21:28 ` Pasha Tatashin
2026-11-18 21:32 ` sashiko-bot
2026-11-18 21:28 ` [PATCH v6 2/7] kho: link outgoing blocks lazily in kho_block Pasha Tatashin
` (5 subsequent siblings)
6 siblings, 1 reply; 18+ messages in thread
From: Pasha Tatashin @ 2026-11-18 21:28 UTC (permalink / raw)
To: linux-kselftest, rppt, shuah, skhan, linux-doc, vipinsh,
linux-kernel, corbet, linux-api, pasha.tatashin, dmatlack, kexec,
pratyush, rdunlap, graf
In preparation for allowing userspace to freeze a session explicitly
before kexec reboot, luo_file_freeze() and luo_file_unfreeze() need to
be called on session->file_set before any struct luo_session_ser entry
is reserved in luo_session_serialize().
Currently, struct luo_session_ser is populated and cleared across two
layers: luo_session_serialize() writes and clears ser->name, while
luo_file_freeze() and luo_file_unfreeze() write and clear
ser->file_set_ser.
Drop the struct luo_file_set_ser pointer parameter from
luo_file_freeze() and luo_file_unfreeze() (and struct luo_session_ser
from luo_session_freeze_one() and luo_session_unfreeze_one()), and
populate and clear all fields of struct luo_session_ser in
luo_session_serialize().
Signed-off-by: Pasha Tatashin <pasha.tatashin@soleen.com>
---
kernel/liveupdate/luo_file.c | 24 ++++++++----------------
kernel/liveupdate/luo_internal.h | 6 ++----
kernel/liveupdate/luo_session.c | 19 ++++++++++---------
3 files changed, 20 insertions(+), 29 deletions(-)
diff --git a/kernel/liveupdate/luo_file.c b/kernel/liveupdate/luo_file.c
index a39992da504f..988eb313a135 100644
--- a/kernel/liveupdate/luo_file.c
+++ b/kernel/liveupdate/luo_file.c
@@ -440,8 +440,7 @@ static void __luo_file_unfreeze(struct luo_file_set *file_set,
/**
* luo_file_freeze - Freezes all preserved files and serializes their metadata.
- * @file_set: The file_set whose files are to be frozen.
- * @file_set_ser: Where to put the serialized file_set.
+ * @file_set: The file_set whose files are to be frozen.
*
* This function is called from the reboot() syscall path, just before the
* kernel transitions to the new image via kexec. Its purpose is to perform the
@@ -457,8 +456,8 @@ static void __luo_file_unfreeze(struct luo_file_set *file_set,
*
* 2. Serializes Metadata: After a successful freeze, it copies the final file
* metadata—the handler's compatible string, the user token, and the final
- * private data handle—into the pre-allocated contiguous memory buffer
- * (file_set->files) that will be handed over to the next kernel via KHO.
+ * private data handle—into the pre-allocated serialization blocks
+ * (file_set->block_set) that will be handed over to the next kernel via KHO.
*
* Error Handling (Rollback):
* This function is atomic. If any handler's .freeze() operation fails, the
@@ -471,8 +470,7 @@ static void __luo_file_unfreeze(struct luo_file_set *file_set,
* Context: Called only from the liveupdate_reboot() path.
* Return: 0 on success, or a negative errno on failure.
*/
-int luo_file_freeze(struct luo_file_set *file_set,
- struct luo_file_set_ser *file_set_ser)
+int luo_file_freeze(struct luo_file_set *file_set)
{
struct luo_file *luo_file;
struct kho_block_set_it it;
@@ -506,9 +504,6 @@ int luo_file_freeze(struct luo_file_set *file_set,
file_ser->token = luo_file->token;
}
- file_set_ser->count = file_set->count;
- file_set_ser->files = kho_block_set_head_pa(&file_set->block_set);
-
return 0;
err_unfreeze:
@@ -519,28 +514,25 @@ int luo_file_freeze(struct luo_file_set *file_set,
/**
* luo_file_unfreeze - Unfreezes all files in a file_set and clear serialization
- * @file_set: The file_set whose files are to be unfrozen.
- * @file_set_ser: Serialized file_set.
+ * @file_set: The file_set whose files are to be unfrozen.
*
* This function rolls back the state of all files in a file_set after the
* freeze phase has begun but must be aborted. It is the counterpart to
* luo_file_freeze().
*
* It invokes the __luo_file_unfreeze() helper with a NULL argument, which
- * signals the helper to iterate through all files in the file_set and call
- * their respective .unfreeze() handler callbacks.
+ * signals the helper to iterate through all files in the file_set, call their
+ * respective .unfreeze() handler callbacks, and clear the serialized blocks.
*
* Context: This is called when the live update is aborted during
* the reboot() syscall, after luo_file_freeze() has been called.
*/
-void luo_file_unfreeze(struct luo_file_set *file_set,
- struct luo_file_set_ser *file_set_ser)
+void luo_file_unfreeze(struct luo_file_set *file_set)
{
if (!file_set->count)
return;
__luo_file_unfreeze(file_set, NULL);
- memset(file_set_ser, 0, sizeof(*file_set_ser));
}
/**
diff --git a/kernel/liveupdate/luo_internal.h b/kernel/liveupdate/luo_internal.h
index dac6644bfb18..01a172cd9d7a 100644
--- a/kernel/liveupdate/luo_internal.h
+++ b/kernel/liveupdate/luo_internal.h
@@ -103,10 +103,8 @@ int luo_session_deserialize(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);
-int luo_file_freeze(struct luo_file_set *file_set,
- struct luo_file_set_ser *file_set_ser);
-void luo_file_unfreeze(struct luo_file_set *file_set,
- struct luo_file_set_ser *file_set_ser);
+int luo_file_freeze(struct luo_file_set *file_set);
+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);
diff --git a/kernel/liveupdate/luo_session.c b/kernel/liveupdate/luo_session.c
index 74bc66929f4b..6dea35911181 100644
--- a/kernel/liveupdate/luo_session.c
+++ b/kernel/liveupdate/luo_session.c
@@ -219,18 +219,16 @@ static int luo_session_finish_one(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)
+static void luo_session_unfreeze_one(struct luo_session *session)
{
guard(mutex)(&session->mutex);
- luo_file_unfreeze(&session->file_set, &ser->file_set_ser);
+ luo_file_unfreeze(&session->file_set);
}
-static int luo_session_freeze_one(struct luo_session *session,
- struct luo_session_ser *ser)
+static int luo_session_freeze_one(struct luo_session *session)
{
guard(mutex)(&session->mutex);
- return luo_file_freeze(&session->file_set, &ser->file_set_ser);
+ return luo_file_freeze(&session->file_set);
}
static int luo_session_release(struct inode *inodep, struct file *filep)
@@ -657,13 +655,16 @@ int luo_session_serialize(void)
goto err_undo;
}
- err = luo_session_freeze_one(session, ser);
+ err = luo_session_freeze_one(session);
if (err) {
kho_block_set_it_prev(&it);
goto err_undo;
}
strscpy(ser->name, session->name, sizeof(ser->name));
+ ser->file_set_ser.count = session->file_set.count;
+ ser->file_set_ser.files =
+ kho_block_set_head_pa(&session->file_set.block_set);
}
if (sh->count > 0)
@@ -676,8 +677,8 @@ int luo_session_serialize(void)
list_for_each_entry_continue_reverse(session, &sh->list, list) {
struct luo_session_ser *ser = kho_block_set_it_prev(&it);
- luo_session_unfreeze_one(session, ser);
- memset(ser->name, 0, sizeof(ser->name));
+ luo_session_unfreeze_one(session);
+ memset(ser, 0, sizeof(*ser));
}
up_write(&sh->rwsem);
up_write(&luo_session_serialize_rwsem);
base-commit: 079c138d2b6870bb658b6e638077264aefc03833
--
2.56.1.708.g77570a6a1d-goog
^ permalink raw reply related [flat|nested] 18+ messages in thread* Re: [PATCH v6 1/7] liveupdate: Move file_set_ser handling to luo_session_serialize()
2026-11-18 21:28 ` [PATCH v6 1/7] liveupdate: Move file_set_ser handling to luo_session_serialize() Pasha Tatashin
@ 2026-11-18 21:32 ` sashiko-bot
0 siblings, 0 replies; 18+ messages in thread
From: sashiko-bot @ 2026-11-18 21:32 UTC (permalink / raw)
To: Pasha Tatashin, rppt, shuah, skhan, vipinsh, corbet, dmatlack,
kexec, pratyush, rdunlap, graf
> In preparation for allowing userspace to freeze a session explicitly
> before kexec reboot, luo_file_freeze() and luo_file_unfreeze() need to
> be called on session->file_set before any struct luo_session_ser entry
> is reserved in luo_session_serialize().
>
> Currently, struct luo_session_ser is populated and cleared across two
> layers: luo_session_serialize() writes and clears ser->name, while
> luo_file_freeze() and luo_file_unfreeze() write and clear
> ser->file_set_ser.
>
> Drop the struct luo_file_set_ser pointer parameter from
> luo_file_freeze() and luo_file_unfreeze() (and struct luo_session_ser
> from luo_session_freeze_one() and luo_session_unfreeze_one()), and
> populate and clear all fields of struct luo_session_ser in
> luo_session_serialize().
>
> Signed-off-by: Pasha Tatashin <pasha.tatashin@soleen.com>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261118212845.2855249-1-pasha.tatashin@soleen.com?part=1
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH v6 2/7] kho: link outgoing blocks lazily in kho_block
2026-11-18 21:28 [PATCH v6 0/7] liveupdate: Add LIVEUPDATE_SESSION_FREEZE ioctl Pasha Tatashin
2026-11-18 21:28 ` [PATCH v6 1/7] liveupdate: Move file_set_ser handling to luo_session_serialize() Pasha Tatashin
@ 2026-11-18 21:28 ` Pasha Tatashin
2026-11-18 21:37 ` sashiko-bot
2026-11-19 11:03 ` Mike Rapoport
2026-11-18 21:28 ` [PATCH v6 3/7] liveupdate: luo_session: support incremental session serialization Pasha Tatashin
` (4 subsequent siblings)
6 siblings, 2 replies; 18+ messages in thread
From: Pasha Tatashin @ 2026-11-18 21:28 UTC (permalink / raw)
To: linux-kselftest, rppt, shuah, skhan, linux-doc, vipinsh,
linux-kernel, corbet, linux-api, pasha.tatashin, dmatlack, kexec,
pratyush, rdunlap, graf
Currently, kho_block_add() links each preallocated block onto the
serialized chain immediately, even while it is still empty. This
assumes all preallocated blocks are populated together before the
chain is referenced by KHO.
When sessions are serialized incrementally ahead of reboot, extra
blocks may be preallocated for sessions that have not been serialized
yet. Keeping those blocks linked leaves empty trailing blocks on the
KHO chain.
Keep preallocated outgoing blocks unlinked in kho_block_add() and link
each block lazily in kho_block_set_it_reserve_entry() when advancing
into it. Also unlink blocks in kho_block_set_clear() and stop at
unlinked blocks in kho_block_set_it_read_entry().
Signed-off-by: Pasha Tatashin <pasha.tatashin@soleen.com>
---
kernel/liveupdate/kho_block.c | 38 +++++++++++++++++++++++------------
1 file changed, 25 insertions(+), 13 deletions(-)
diff --git a/kernel/liveupdate/kho_block.c b/kernel/liveupdate/kho_block.c
index 0d2a342ef422..21cee45fa1cc 100644
--- a/kernel/liveupdate/kho_block.c
+++ b/kernel/liveupdate/kho_block.c
@@ -16,6 +16,11 @@
* array of serialized entries. Multiple blocks are linked together via a
* physical pointer in the header, forming a linked list that can be easily
* traversed in both the current and the next kernel.
+ *
+ * Outgoing blocks preallocated via kho_block_set_grow() remain unlinked until
+ * entries are reserved via kho_block_set_it_reserve_entry(). This allows
+ * entries to be serialized incrementally without exposing empty trailing blocks
+ * on the physical chain.
*/
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
@@ -79,7 +84,7 @@ static struct kho_block_header_ser *kho_block_alloc_ser(struct kho_block_set *bs
static int kho_block_add(struct kho_block_set *bs,
struct kho_block_header_ser *ser)
{
- struct kho_block *block, *last;
+ struct kho_block *block;
if (bs->nblocks >= KHO_MAX_BLOCKS)
return -ENOSPC;
@@ -89,15 +94,11 @@ static int kho_block_add(struct kho_block_set *bs,
return -ENOMEM;
block->ser = ser;
- last = list_last_entry_or_null(&bs->blocks, struct kho_block, list);
+ if (list_empty(&bs->blocks))
+ bs->head_pa = virt_to_phys(ser);
list_add_tail(&block->list, &bs->blocks);
bs->nblocks++;
- if (last)
- last->ser->next = virt_to_phys(ser);
- else
- bs->head_pa = virt_to_phys(ser);
-
return 0;
}
@@ -144,9 +145,9 @@ static void kho_block_set_shrink_one(struct kho_block_set *bs)
* @bs: The block set.
* @count: The target number of valid entries to accommodate.
*
- * Dynamically preallocates and links preserved memory blocks if the target
- * entry count exceeds the current total capacity of the set, ensuring they
- * are available during serialization/deserialization.
+ * Dynamically preallocates preserved memory blocks if the target entry count
+ * exceeds the current total capacity of the set, ensuring they are available
+ * during serialization/deserialization.
*
* Context: Caller must hold a lock protecting the block set.
* Return: 0 on success, or a negative errno on failure.
@@ -312,12 +313,15 @@ void kho_block_set_destroy(struct kho_block_set *bs)
/**
* kho_block_set_clear - Clear all serialized data in a block set.
* @bs: The block set to clear.
+ *
+ * Resets entry counts, unlinks blocks, and zeroes all entry payloads.
*/
void kho_block_set_clear(struct kho_block_set *bs)
{
struct kho_block *block;
list_for_each_entry(block, &bs->blocks, list) {
+ block->ser->next = 0;
block->ser->count = 0;
memset(block->ser + 1, 0, KHO_BLOCK_SIZE - sizeof(*block->ser));
}
@@ -340,14 +344,16 @@ void kho_block_set_it_init(struct kho_block_set_it *it, struct kho_block_set *bs
* @it: The block iterator.
*
* Reserves a slot in the current block during state serialization to add a new
- * entry, advancing the internal index. If the current block is full, it
- * automatically moves to the next block in the set.
+ * entry, advancing the internal index. If the current block is full, it moves
+ * to the next preallocated block and links it onto the serialized chain via
+ * the previous block's header.
*
* Return: A pointer to the reserved entry slot, or NULL if the block set's
* capacity is fully exhausted.
*/
void *kho_block_set_it_reserve_entry(struct kho_block_set_it *it)
{
+ struct kho_block *prev = NULL;
void *entry;
if (!it->block)
@@ -356,12 +362,16 @@ void *kho_block_set_it_reserve_entry(struct kho_block_set_it *it)
if (it->i == it->bs->count_per_block) {
if (list_is_last(&it->block->list, &it->bs->blocks))
return NULL;
+ prev = it->block;
it->block = list_next_entry(it->block, list);
it->i = 0;
}
entry = kho_block_entry(it, it->i++);
it->block->ser->count = it->i;
+ if (prev)
+ prev->ser->next = virt_to_phys(it->block->ser);
+
return entry;
}
@@ -381,7 +391,9 @@ void *kho_block_set_it_read_entry(struct kho_block_set_it *it)
return NULL;
if (it->i == it->block->ser->count) {
- if (list_is_last(&it->block->list, &it->bs->blocks))
+ if (!it->block->ser->next)
+ return NULL;
+ if (WARN_ON_ONCE(list_is_last(&it->block->list, &it->bs->blocks)))
return NULL;
it->block = list_next_entry(it->block, list);
it->i = 0;
--
2.56.1.708.g77570a6a1d-goog
^ permalink raw reply related [flat|nested] 18+ messages in thread* Re: [PATCH v6 2/7] kho: link outgoing blocks lazily in kho_block
2026-11-18 21:28 ` [PATCH v6 2/7] kho: link outgoing blocks lazily in kho_block Pasha Tatashin
@ 2026-11-18 21:37 ` sashiko-bot
2026-11-19 11:03 ` Mike Rapoport
1 sibling, 0 replies; 18+ messages in thread
From: sashiko-bot @ 2026-11-18 21:37 UTC (permalink / raw)
To: Pasha Tatashin, rppt, shuah, skhan, vipinsh, corbet, dmatlack,
kexec, pratyush, rdunlap, graf
> Currently, kho_block_add() links each preallocated block onto the
> serialized chain immediately, even while it is still empty. This
> assumes all preallocated blocks are populated together before the
> chain is referenced by KHO.
>
> When sessions are serialized incrementally ahead of reboot, extra
> blocks may be preallocated for sessions that have not been serialized
> yet. Keeping those blocks linked leaves empty trailing blocks on the
> KHO chain.
>
> Keep preallocated outgoing blocks unlinked in kho_block_add() and link
> each block lazily in kho_block_set_it_reserve_entry() when advancing
> into it. Also unlink blocks in kho_block_set_clear() and stop at
> unlinked blocks in kho_block_set_it_read_entry().
>
> Signed-off-by: Pasha Tatashin <pasha.tatashin@soleen.com>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261118212845.2855249-1-pasha.tatashin@soleen.com?part=2
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH v6 2/7] kho: link outgoing blocks lazily in kho_block
2026-11-18 21:28 ` [PATCH v6 2/7] kho: link outgoing blocks lazily in kho_block Pasha Tatashin
2026-11-18 21:37 ` sashiko-bot
@ 2026-11-19 11:03 ` Mike Rapoport
1 sibling, 0 replies; 18+ messages in thread
From: Mike Rapoport @ 2026-11-19 11:03 UTC (permalink / raw)
To: Pasha Tatashin
Cc: linux-kselftest, rppt, shuah, skhan, linux-doc, vipinsh,
linux-kernel, corbet, linux-api, dmatlack, kexec, pratyush,
rdunlap, graf
Hi,
> Currently, kho_block_add() links each preallocated block onto the
> serialized chain immediately, even while it is still empty. This
> assumes all preallocated blocks are populated together before the
> chain is referenced by KHO.
>
> When sessions are serialized incrementally ahead of reboot, extra
> blocks may be preallocated for sessions that have not been serialized
> yet. Keeping those blocks linked leaves empty trailing blocks on the
> KHO chain.
>
> Keep preallocated outgoing blocks unlinked in kho_block_add() and link
> each block lazily in kho_block_set_it_reserve_entry() when advancing
> into it. Also unlink blocks in kho_block_set_clear() and stop at
> unlinked blocks in kho_block_set_it_read_entry().
>
> Signed-off-by: Pasha Tatashin <pasha.tatashin@soleen.com>
> ---
> kernel/liveupdate/kho_block.c | 38 +++++++++++++++++++++++------------
> 1 file changed, 25 insertions(+), 13 deletions(-)
>
> diff --git a/kernel/liveupdate/kho_block.c b/kernel/liveupdate/kho_block.c
> index 0d2a342ef4228..21cee45fa1cc0 100644
> --- a/kernel/liveupdate/kho_block.c
> +++ b/kernel/liveupdate/kho_block.c
> @@ -16,6 +16,11 @@
> * array of serialized entries. Multiple blocks are linked together via a
> * physical pointer in the header, forming a linked list that can be easily
> * traversed in both the current and the next kernel.
> + *
> + * Outgoing blocks preallocated via kho_block_set_grow() remain unlinked until
> + * entries are reserved via kho_block_set_it_reserve_entry(). This allows
> + * entries to be serialized incrementally without exposing empty trailing blocks
> + * on the physical chain.
With the kho-ro preparation dropped, I don't see what the empty linked
blocks break. Every session is serialized in luo_session_serialize() before
kexec, and nblocks always matches ceil(count / entries per block), so by the
time the chain is handed over all the preallocated blocks are populated.
Empty trailing blocks exist only for a short while before reboot and nobody
looks at them. If they did reach the next kernel, kho_block_set_restore()
would refuse them anyway.
It only matters if something reads the chain while sessions are being
serialized, and that's kho-ro. So either describe here what actually goes
wrong without this patch, or move it to the kho-ro series where it's needed.
--
Sincerely yours,
Mike.
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH v6 3/7] liveupdate: luo_session: support incremental session serialization
2026-11-18 21:28 [PATCH v6 0/7] liveupdate: Add LIVEUPDATE_SESSION_FREEZE ioctl Pasha Tatashin
2026-11-18 21:28 ` [PATCH v6 1/7] liveupdate: Move file_set_ser handling to luo_session_serialize() Pasha Tatashin
2026-11-18 21:28 ` [PATCH v6 2/7] kho: link outgoing blocks lazily in kho_block Pasha Tatashin
@ 2026-11-18 21:28 ` Pasha Tatashin
2026-11-18 21:33 ` sashiko-bot
2026-11-18 21:28 ` [PATCH v6 4/7] liveupdate: luo_flb: serialize outgoing FLBs incrementally Pasha Tatashin
` (3 subsequent siblings)
6 siblings, 1 reply; 18+ messages in thread
From: Pasha Tatashin @ 2026-11-18 21:28 UTC (permalink / raw)
To: linux-kselftest, rppt, shuah, skhan, linux-doc, vipinsh,
linux-kernel, corbet, linux-api, pasha.tatashin, dmatlack, kexec,
pratyush, rdunlap, graf
In preparation for committing frozen sessions ahead of reboot, allow
sessions to be serialized into sh->block_set individually. Introduce
luo_session_serialize_one() to append a single session to sh->block_set
and mark it serialized. Update luo_session_serialize() to freeze all
remaining unserialized sessions first, rolling back on failure, and
then serialize each one via luo_session_serialize_one().
Signed-off-by: Pasha Tatashin <pasha.tatashin@soleen.com>
---
kernel/liveupdate/luo_internal.h | 3 ++
kernel/liveupdate/luo_session.c | 71 ++++++++++++++++++++------------
2 files changed, 47 insertions(+), 27 deletions(-)
diff --git a/kernel/liveupdate/luo_internal.h b/kernel/liveupdate/luo_internal.h
index 01a172cd9d7a..77dac2742877 100644
--- a/kernel/liveupdate/luo_internal.h
+++ b/kernel/liveupdate/luo_internal.h
@@ -64,6 +64,8 @@ struct luo_file_set {
* previous kernel) sessions.
* @retrieved: A boolean flag indicating whether this session has been
* retrieved by a consumer in the new kernel.
+ * @serialized: A boolean flag indicating whether this outgoing session has
+ * been serialized into KHO.
* @file_set: A set of files that belong to this session.
* @mutex: protects fields in the luo_session.
*/
@@ -71,6 +73,7 @@ struct luo_session {
char name[LIVEUPDATE_SESSION_NAME_LENGTH];
struct list_head list;
bool retrieved;
+ bool serialized;
struct luo_file_set file_set;
struct mutex mutex;
};
diff --git a/kernel/liveupdate/luo_session.c b/kernel/liveupdate/luo_session.c
index 6dea35911181..56d7f76c0282 100644
--- a/kernel/liveupdate/luo_session.c
+++ b/kernel/liveupdate/luo_session.c
@@ -108,6 +108,8 @@ static DECLARE_RWSEM(luo_session_serialize_rwsem);
* @rwsem: A read-write semaphore providing synchronized access to the
* session list and other fields in this structure.
* @block_set: The set of serialization blocks.
+ * @it: Iterator tracking the next slot in @block_set for outgoing
+ * session serialization.
* @sessions_pa: Points to the location of sessions_pa within struct luo_ser.
* @active: Set to true when first initialized. If previous kernel did not
* send session data, active stays false for incoming.
@@ -117,6 +119,7 @@ struct luo_session_header {
struct list_head list;
struct rw_semaphore rwsem;
struct kho_block_set block_set;
+ struct kho_block_set_it it;
u64 *sessions_pa;
bool active;
};
@@ -203,6 +206,33 @@ static int luo_session_insert(struct luo_session_header *sh,
return 0;
}
+static void luo_session_serialize_one(struct luo_session *session)
+{
+ struct luo_session_header *sh = &luo_session_global.outgoing;
+ struct luo_session_ser *ser;
+
+ lockdep_assert_held_write(&sh->rwsem);
+ lockdep_assert_held(&session->mutex);
+
+ if (!*sh->sessions_pa)
+ kho_block_set_it_init(&sh->it, &sh->block_set);
+
+ /* This should not fail normally as blocks were pre-allocated */
+ ser = kho_block_set_it_reserve_entry(&sh->it);
+ if (WARN_ON_ONCE(!ser))
+ return;
+
+ strscpy(ser->name, session->name, sizeof(ser->name));
+ ser->file_set_ser.count = session->file_set.count;
+ ser->file_set_ser.files =
+ kho_block_set_head_pa(&session->file_set.block_set);
+
+ if (!*sh->sessions_pa)
+ *sh->sessions_pa = kho_block_set_head_pa(&sh->block_set);
+
+ session->serialized = true;
+}
+
static void luo_session_remove(struct luo_session_header *sh,
struct luo_session *session)
{
@@ -637,48 +667,35 @@ int luo_session_serialize(void)
{
struct luo_session_header *sh = &luo_session_global.outgoing;
struct luo_session *session;
- struct kho_block_set_it it;
int err;
down_write(&luo_session_serialize_rwsem);
down_write(&sh->rwsem);
- *sh->sessions_pa = 0;
-
- kho_block_set_it_init(&it, &sh->block_set);
list_for_each_entry(session, &sh->list, list) {
- struct luo_session_ser *ser = kho_block_set_it_reserve_entry(&it);
-
- /* This should not fail normally as blocks were pre-allocated */
- if (WARN_ON_ONCE(!ser)) {
- err = -ENOSPC;
- goto err_undo;
- }
-
+ if (session->serialized)
+ continue;
err = luo_session_freeze_one(session);
- if (err) {
- kho_block_set_it_prev(&it);
- goto err_undo;
- }
+ if (err)
+ goto err_unfreeze;
+ }
- strscpy(ser->name, session->name, sizeof(ser->name));
- ser->file_set_ser.count = session->file_set.count;
- ser->file_set_ser.files =
- kho_block_set_head_pa(&session->file_set.block_set);
+ list_for_each_entry(session, &sh->list, list) {
+ if (session->serialized)
+ continue;
+ mutex_lock(&session->mutex);
+ luo_session_serialize_one(session);
+ mutex_unlock(&session->mutex);
}
- if (sh->count > 0)
- *sh->sessions_pa = kho_block_set_head_pa(&sh->block_set);
up_write(&sh->rwsem);
return 0;
-err_undo:
+err_unfreeze:
list_for_each_entry_continue_reverse(session, &sh->list, list) {
- struct luo_session_ser *ser = kho_block_set_it_prev(&it);
-
- luo_session_unfreeze_one(session);
- memset(ser, 0, sizeof(*ser));
+ if (!session->serialized)
+ luo_session_unfreeze_one(session);
}
up_write(&sh->rwsem);
up_write(&luo_session_serialize_rwsem);
--
2.56.1.708.g77570a6a1d-goog
^ permalink raw reply related [flat|nested] 18+ messages in thread* Re: [PATCH v6 3/7] liveupdate: luo_session: support incremental session serialization
2026-11-18 21:28 ` [PATCH v6 3/7] liveupdate: luo_session: support incremental session serialization Pasha Tatashin
@ 2026-11-18 21:33 ` sashiko-bot
0 siblings, 0 replies; 18+ messages in thread
From: sashiko-bot @ 2026-11-18 21:33 UTC (permalink / raw)
To: Pasha Tatashin, rppt, shuah, skhan, vipinsh, corbet, dmatlack,
kexec, pratyush, rdunlap, graf
> In preparation for committing frozen sessions ahead of reboot, allow
> sessions to be serialized into sh->block_set individually. Introduce
> luo_session_serialize_one() to append a single session to sh->block_set
> and mark it serialized. Update luo_session_serialize() to freeze all
> remaining unserialized sessions first, rolling back on failure, and
> then serialize each one via luo_session_serialize_one().
>
> Signed-off-by: Pasha Tatashin <pasha.tatashin@soleen.com>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261118212845.2855249-1-pasha.tatashin@soleen.com?part=3
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH v6 4/7] liveupdate: luo_flb: serialize outgoing FLBs incrementally
2026-11-18 21:28 [PATCH v6 0/7] liveupdate: Add LIVEUPDATE_SESSION_FREEZE ioctl Pasha Tatashin
` (2 preceding siblings ...)
2026-11-18 21:28 ` [PATCH v6 3/7] liveupdate: luo_session: support incremental session serialization Pasha Tatashin
@ 2026-11-18 21:28 ` Pasha Tatashin
2026-11-18 21:34 ` sashiko-bot
2026-11-19 11:03 ` Mike Rapoport
2026-11-18 21:28 ` [PATCH v6 5/7] liveupdate: Add LIVEUPDATE_SESSION_FREEZE ioctl to freeze sessions early Pasha Tatashin
` (2 subsequent siblings)
6 siblings, 2 replies; 18+ messages in thread
From: Pasha Tatashin @ 2026-11-18 21:28 UTC (permalink / raw)
To: linux-kselftest, rppt, shuah, skhan, linux-doc, vipinsh,
linux-kernel, corbet, linux-api, pasha.tatashin, dmatlack, kexec,
pratyush, rdunlap, graf
Currently, outgoing FLB metadata is written in a single pass by
luo_flb_serialize() during liveupdate_reboot(). When sessions are
serialized ahead of reboot, any FLBs their files depend on must also
be serialized at that time so the outgoing KHO state stays consistent.
Serialize each file's FLB dependencies from luo_session_serialize_one(),
appending new FLB entries or incrementing the serialized file count in
place. Since every serialized session now updates its FLBs as it is
serialized, drop the separate luo_flb_serialize() pass from
liveupdate_reboot().
Because serialized sessions never unpreserve their files, FLB
serialization is one-way: once an FLB is serialized, its .unpreserve()
callback will not run and its root handle from .preserve() remains
fixed for the rest of the boot.
Signed-off-by: Pasha Tatashin <pasha.tatashin@soleen.com>
---
kernel/liveupdate/luo_core.c | 10 +--
kernel/liveupdate/luo_file.c | 15 +++++
kernel/liveupdate/luo_flb.c | 102 ++++++++++++++++++++-----------
kernel/liveupdate/luo_internal.h | 3 +-
kernel/liveupdate/luo_session.c | 2 +
5 files changed, 85 insertions(+), 47 deletions(-)
diff --git a/kernel/liveupdate/luo_core.c b/kernel/liveupdate/luo_core.c
index 1b2bda22902d..9fef5161a1f3 100644
--- a/kernel/liveupdate/luo_core.c
+++ b/kernel/liveupdate/luo_core.c
@@ -219,18 +219,10 @@ late_initcall(luo_late_startup);
*/
int liveupdate_reboot(void)
{
- int err;
-
if (!liveupdate_enabled())
return 0;
- err = luo_session_serialize();
- if (err)
- return err;
-
- luo_flb_serialize();
-
- return 0;
+ return luo_session_serialize();
}
/**
diff --git a/kernel/liveupdate/luo_file.c b/kernel/liveupdate/luo_file.c
index 988eb313a135..cdd3c466e5ac 100644
--- a/kernel/liveupdate/luo_file.c
+++ b/kernel/liveupdate/luo_file.c
@@ -380,6 +380,21 @@ void luo_file_unpreserve_files(struct luo_file_set *file_set)
kho_block_set_destroy(&file_set->block_set);
}
+/**
+ * luo_file_serialize_flbs - Serialize FLBs for all preserved files in a file_set.
+ * @file_set: The file_set being serialized.
+ *
+ * Iterates through all preserved files in @file_set and serializes their
+ * associated FLB metadata into the outgoing KHO FLB array.
+ */
+void luo_file_serialize_flbs(struct luo_file_set *file_set)
+{
+ struct luo_file *luo_file;
+
+ list_for_each_entry(luo_file, &file_set->files_list, list)
+ luo_flb_file_serialize(luo_file->fh);
+}
+
static int luo_file_freeze_one(struct luo_file_set *file_set,
struct luo_file *luo_file)
{
diff --git a/kernel/liveupdate/luo_flb.c b/kernel/liveupdate/luo_flb.c
index cd715a7c1d99..4ac534171d42 100644
--- a/kernel/liveupdate/luo_flb.c
+++ b/kernel/liveupdate/luo_flb.c
@@ -34,6 +34,12 @@
* This reference-counted approach ensures that shared state is saved exactly
* once and restored exactly once, regardless of how many files depend on it,
* and that its lifecycle is correctly managed across the kexec transition.
+ *
+ * Serialization: Outgoing FLB metadata is serialized into the KHO FLB array
+ * incrementally as sessions are serialized. Once serialized, the FLB's
+ * .unpreserve() callback is never invoked and its root KHO handle from
+ * .preserve() remains fixed, while later sessions may still update per-FD
+ * state in the shared live object under the FLB handler's own locking.
*/
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
@@ -72,6 +78,13 @@ static struct luo_flb_global luo_flb_global = {
.list = LIST_HEAD_INIT(luo_flb_global.list),
};
+/*
+ * Serializes updates to luo_flb_global.outgoing.header_ser and .ser[].
+ * Lock hierarchy:
+ * luo_register_rwlock -> private->outgoing.lock -> luo_flb_ser_lock
+ */
+static DEFINE_MUTEX(luo_flb_ser_lock);
+
/*
* struct luo_flb_link - Links an FLB definition to a file handler's internal
* list of dependencies.
@@ -104,6 +117,32 @@ static struct luo_flb_private *luo_flb_get_private(struct liveupdate_flb *flb)
return private;
}
+static void luo_flb_serialize_one(const struct liveupdate_flb *flb, u64 data)
+{
+ struct luo_flb_header *fh = &luo_flb_global.outgoing;
+ u64 nr;
+
+ guard(mutex)(&luo_flb_ser_lock);
+ if (!fh->active)
+ return;
+
+ nr = fh->header_ser->count;
+ for (u64 i = 0; i < nr; i++) {
+ if (!strcmp(fh->ser[i].name, flb->compatible)) {
+ fh->ser[i].count++;
+ return;
+ }
+ }
+
+ if (WARN_ON_ONCE(nr >= LUO_FLB_MAX))
+ return;
+
+ strscpy(fh->ser[nr].name, flb->compatible, sizeof(fh->ser[nr].name));
+ fh->ser[nr].data = data;
+ fh->ser[nr].count = 1;
+ fh->header_ser->count = nr + 1;
+}
+
static int luo_flb_file_preserve_one(struct liveupdate_flb *flb)
{
struct luo_flb_private *private = luo_flb_get_private(flb);
@@ -296,6 +335,32 @@ void luo_flb_file_unpreserve(struct liveupdate_file_handler *fh)
liveupdate_flb_put_outgoing(iter->flb);
}
+/**
+ * luo_flb_file_serialize - Serialize FLB metadata for a preserved file's handler.
+ * @fh: The file handler of the preserved file being serialized.
+ *
+ * Adds each FLB associated with @fh to the outgoing KHO FLB array on first
+ * use, or increments its serialized file reference count by one.
+ *
+ * Context: Called when a session containing preserved files is serialized.
+ */
+void luo_flb_file_serialize(struct liveupdate_file_handler *fh)
+{
+ struct list_head *flb_list = &ACCESS_PRIVATE(fh, flb_list);
+ struct luo_flb_link *iter;
+
+ guard(rwsem_read)(&luo_register_rwlock);
+ list_for_each_entry(iter, flb_list, list) {
+ struct luo_flb_private *private = luo_flb_get_private(iter->flb);
+
+ scoped_guard(mutex, &private->outgoing.lock) {
+ if (WARN_ON_ONCE(!refcount_read(&private->outgoing.count)))
+ continue;
+ luo_flb_serialize_one(iter->flb, private->outgoing.data);
+ }
+ }
+}
+
/**
* luo_flb_file_finish - Notifies FLBs that a dependent file has been finished.
* @fh: The file handler for the finished file.
@@ -587,40 +652,3 @@ void __init luo_flb_setup_incoming(u64 flbs_pa)
luo_flb_global.incoming.ser = (void *)(header_ser + 1);
luo_flb_global.incoming.active = true;
}
-
-/**
- * luo_flb_serialize - Serializes all active FLB objects for KHO.
- *
- * This function is called from the reboot path. It iterates through all
- * registered File-Lifecycle-Bound (FLB) objects. For each FLB that has been
- * preserved (i.e., its reference count is greater than zero), it writes its
- * metadata into the memory region designated for Kexec Handover.
- *
- * The serialized data includes the FLB's compatibility string, its opaque
- * data handle, and the final reference count. This allows the new kernel to
- * find the appropriate handler and reconstruct the FLB's state.
- *
- * Context: Called from liveupdate_reboot() just before kho_finalize().
- */
-void luo_flb_serialize(void)
-{
- struct luo_flb_header *fh = &luo_flb_global.outgoing;
- struct liveupdate_flb *gflb;
- int i = 0;
-
- guard(rwsem_read)(&luo_register_rwlock);
- list_private_for_each_entry(gflb, &luo_flb_global.list, private.list) {
- struct luo_flb_private *private = luo_flb_get_private(gflb);
- long count = refcount_read(&private->outgoing.count);
-
- if (count > 0) {
- strscpy(fh->ser[i].name, gflb->compatible,
- sizeof(fh->ser[i].name));
- fh->ser[i].data = private->outgoing.data;
- fh->ser[i].count = count;
- i++;
- }
- }
-
- fh->header_ser->count = i;
-}
diff --git a/kernel/liveupdate/luo_internal.h b/kernel/liveupdate/luo_internal.h
index 77dac2742877..3d948279f018 100644
--- a/kernel/liveupdate/luo_internal.h
+++ b/kernel/liveupdate/luo_internal.h
@@ -106,6 +106,7 @@ int luo_session_deserialize(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);
+void luo_file_serialize_flbs(struct luo_file_set *file_set);
int luo_file_freeze(struct luo_file_set *file_set);
void luo_file_unfreeze(struct luo_file_set *file_set);
int luo_retrieve_file(struct luo_file_set *file_set, u64 token,
@@ -118,11 +119,11 @@ void luo_file_set_destroy(struct luo_file_set *file_set);
int luo_flb_file_preserve(struct liveupdate_file_handler *fh);
void luo_flb_file_unpreserve(struct liveupdate_file_handler *fh);
+void luo_flb_file_serialize(struct liveupdate_file_handler *fh);
void luo_flb_file_finish(struct liveupdate_file_handler *fh);
void luo_flb_unregister_all(struct liveupdate_file_handler *fh);
int __init luo_flb_setup_outgoing(u64 *flbs_pa);
void __init luo_flb_setup_incoming(u64 flbs_pa);
-void luo_flb_serialize(void);
#ifdef CONFIG_LIVEUPDATE_TEST
void liveupdate_test_register(struct liveupdate_file_handler *fh);
diff --git a/kernel/liveupdate/luo_session.c b/kernel/liveupdate/luo_session.c
index 56d7f76c0282..013386534b69 100644
--- a/kernel/liveupdate/luo_session.c
+++ b/kernel/liveupdate/luo_session.c
@@ -222,6 +222,8 @@ static void luo_session_serialize_one(struct luo_session *session)
if (WARN_ON_ONCE(!ser))
return;
+ luo_file_serialize_flbs(&session->file_set);
+
strscpy(ser->name, session->name, sizeof(ser->name));
ser->file_set_ser.count = session->file_set.count;
ser->file_set_ser.files =
--
2.56.1.708.g77570a6a1d-goog
^ permalink raw reply related [flat|nested] 18+ messages in thread* Re: [PATCH v6 4/7] liveupdate: luo_flb: serialize outgoing FLBs incrementally
2026-11-18 21:28 ` [PATCH v6 4/7] liveupdate: luo_flb: serialize outgoing FLBs incrementally Pasha Tatashin
@ 2026-11-18 21:34 ` sashiko-bot
2026-11-19 11:03 ` Mike Rapoport
1 sibling, 0 replies; 18+ messages in thread
From: sashiko-bot @ 2026-11-18 21:34 UTC (permalink / raw)
To: Pasha Tatashin, rppt, shuah, skhan, vipinsh, corbet, dmatlack,
kexec, pratyush, rdunlap, graf
> Currently, outgoing FLB metadata is written in a single pass by
> luo_flb_serialize() during liveupdate_reboot(). When sessions are
> serialized ahead of reboot, any FLBs their files depend on must also
> be serialized at that time so the outgoing KHO state stays consistent.
>
> Serialize each file's FLB dependencies from luo_session_serialize_one(),
> appending new FLB entries or incrementing the serialized file count in
> place. Since every serialized session now updates its FLBs as it is
> serialized, drop the separate luo_flb_serialize() pass from
> liveupdate_reboot().
>
> Because serialized sessions never unpreserve their files, FLB
> serialization is one-way: once an FLB is serialized, its .unpreserve()
> callback will not run and its root handle from .preserve() remains
> fixed for the rest of the boot.
>
> Signed-off-by: Pasha Tatashin <pasha.tatashin@soleen.com>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261118212845.2855249-1-pasha.tatashin@soleen.com?part=4
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH v6 4/7] liveupdate: luo_flb: serialize outgoing FLBs incrementally
2026-11-18 21:28 ` [PATCH v6 4/7] liveupdate: luo_flb: serialize outgoing FLBs incrementally Pasha Tatashin
2026-11-18 21:34 ` sashiko-bot
@ 2026-11-19 11:03 ` Mike Rapoport
1 sibling, 0 replies; 18+ messages in thread
From: Mike Rapoport @ 2026-11-19 11:03 UTC (permalink / raw)
To: Pasha Tatashin
Cc: linux-kselftest, rppt, shuah, skhan, linux-doc, vipinsh,
linux-kernel, corbet, linux-api, dmatlack, kexec, pratyush,
rdunlap, graf
Hi,
> Currently, outgoing FLB metadata is written in a single pass by
> luo_flb_serialize() during liveupdate_reboot(). When sessions are
> serialized ahead of reboot, any FLBs their files depend on must also
> be serialized at that time so the outgoing KHO state stays consistent.
>
> Serialize each file's FLB dependencies from luo_session_serialize_one(),
> appending new FLB entries or incrementing the serialized file count in
> place. Since every serialized session now updates its FLBs as it is
> serialized, drop the separate luo_flb_serialize() pass from
> liveupdate_reboot().
>
> Because serialized sessions never unpreserve their files, FLB
> serialization is one-way: once an FLB is serialized, its .unpreserve()
> callback will not run and its root handle from .preserve() remains
> fixed for the rest of the boot.
>
> Signed-off-by: Pasha Tatashin <pasha.tatashin@soleen.com>
> ---
> kernel/liveupdate/luo_core.c | 10 +--
> kernel/liveupdate/luo_file.c | 15 +++++
> kernel/liveupdate/luo_flb.c | 102 ++++++++++++++++++++-----------
> kernel/liveupdate/luo_internal.h | 3 +-
> kernel/liveupdate/luo_session.c | 2 +
> 5 files changed, 85 insertions(+), 47 deletions(-)
>
> diff --git a/kernel/liveupdate/luo_core.c b/kernel/liveupdate/luo_core.c
> index 1b2bda22902d2..9fef5161a1f3d 100644
> --- a/kernel/liveupdate/luo_core.c
> +++ b/kernel/liveupdate/luo_core.c
> @@ -219,18 +219,10 @@ late_initcall(luo_late_startup);
> */
> int liveupdate_reboot(void)
> {
> - int err;
> -
> if (!liveupdate_enabled())
> return 0;
>
> - err = luo_session_serialize();
> - if (err)
> - return err;
> -
> - luo_flb_serialize();
> -
> - return 0;
> + return luo_session_serialize();
> }
>
> /**
> diff --git a/kernel/liveupdate/luo_file.c b/kernel/liveupdate/luo_file.c
> index 988eb313a135f..cdd3c466e5ac3 100644
> --- a/kernel/liveupdate/luo_file.c
> +++ b/kernel/liveupdate/luo_file.c
> @@ -380,6 +380,21 @@ void luo_file_unpreserve_files(struct luo_file_set *file_set)
> kho_block_set_destroy(&file_set->block_set);
> }
>
> +/**
> + * luo_file_serialize_flbs - Serialize FLBs for all preserved files in a file_set.
> + * @file_set: The file_set being serialized.
> + *
> + * Iterates through all preserved files in @file_set and serializes their
> + * associated FLB metadata into the outgoing KHO FLB array.
> + */
> +void luo_file_serialize_flbs(struct luo_file_set *file_set)
> +{
> + struct luo_file *luo_file;
> +
> + list_for_each_entry(luo_file, &file_set->files_list, list)
> + luo_flb_file_serialize(luo_file->fh);
> +}
> +
> static int luo_file_freeze_one(struct luo_file_set *file_set,
> struct luo_file *luo_file)
> {
> diff --git a/kernel/liveupdate/luo_flb.c b/kernel/liveupdate/luo_flb.c
> index cd715a7c1d992..4ac534171d423 100644
> --- a/kernel/liveupdate/luo_flb.c
> +++ b/kernel/liveupdate/luo_flb.c
> @@ -34,6 +34,12 @@
> * This reference-counted approach ensures that shared state is saved exactly
> * once and restored exactly once, regardless of how many files depend on it,
> * and that its lifecycle is correctly managed across the kexec transition.
> + *
> + * Serialization: Outgoing FLB metadata is serialized into the KHO FLB array
> + * incrementally as sessions are serialized. Once serialized, the FLB's
> + * .unpreserve() callback is never invoked and its root KHO handle from
> + * .preserve() remains fixed, while later sessions may still update per-FD
> + * state in the shared live object under the FLB handler's own locking.
> */
>
> #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
> @@ -72,6 +78,13 @@ static struct luo_flb_global luo_flb_global = {
> .list = LIST_HEAD_INIT(luo_flb_global.list),
> };
>
> +/*
> + * Serializes updates to luo_flb_global.outgoing.header_ser and .ser[].
> + * Lock hierarchy:
> + * luo_register_rwlock -> private->outgoing.lock -> luo_flb_ser_lock
> + */
> +static DEFINE_MUTEX(luo_flb_ser_lock);
Why is this needed? luo_flb_file_serialize() is called only from
luo_session_serialize_one() and that runs with sh->rwsem held for write, so
all the writers to the outgoing FLB block set are already serialized.
I'd drop the mutex and add lockdep_assert_held_write() for the outer lock,
or at least mention sh->rwsem in the lock hierarchy comment above.
Currently it lists only the inner part of the hierarchy, which is confusing.
--
Sincerely yours,
Mike.
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH v6 5/7] liveupdate: Add LIVEUPDATE_SESSION_FREEZE ioctl to freeze sessions early
2026-11-18 21:28 [PATCH v6 0/7] liveupdate: Add LIVEUPDATE_SESSION_FREEZE ioctl Pasha Tatashin
` (3 preceding siblings ...)
2026-11-18 21:28 ` [PATCH v6 4/7] liveupdate: luo_flb: serialize outgoing FLBs incrementally Pasha Tatashin
@ 2026-11-18 21:28 ` Pasha Tatashin
2026-11-18 21:36 ` sashiko-bot
2026-11-19 11:03 ` Mike Rapoport
2026-11-18 21:28 ` [PATCH v6 6/7] selftests: liveupdate: Add unit tests for LIVEUPDATE_SESSION_FREEZE Pasha Tatashin
2026-11-18 21:28 ` [PATCH v6 7/7] selftests: liveupdate: Test LIVEUPDATE_SESSION_FREEZE across kexec Pasha Tatashin
6 siblings, 2 replies; 18+ messages in thread
From: Pasha Tatashin @ 2026-11-18 21:28 UTC (permalink / raw)
To: linux-kselftest, rppt, shuah, skhan, linux-doc, vipinsh,
linux-kernel, corbet, linux-api, pasha.tatashin, dmatlack, kexec,
pratyush, rdunlap, graf
Add the LIVEUPDATE_SESSION_FREEZE ioctl on outgoing session FDs. Once
frozen, no additional files can be preserved in the session and
repeated freeze calls return -EBUSY.
Currently, LUO freezes sessions only during reboot(LINUX_REBOOT_CMD_KEXEC),
serially under global write locks. On hosts running multiple workloads
such as VMs, freezing sessions early under their per-session mutexes
lets workloads freeze in parallel as they pause ahead of kexec,
reducing blackout time.
By default, session lifetime remains tied to the session FD: closing
the FD before reboot unfreezes and unpreserves the session, while
keeping it open skips late auto-freeze at kexec.
Add optional flag LIVEUPDATE_SESSION_FREEZE_COMMIT to serialize the
frozen session and its FLBs immediately and transfer ownership to LUO
until reboot. Committed sessions survive closing the session FD,
allowing processes to hand off preserved state and exit prior to kexec.
Signed-off-by: Pasha Tatashin <pasha.tatashin@soleen.com>
---
Documentation/userspace-api/liveupdate.rst | 20 ++++++
include/linux/liveupdate.h | 2 +-
include/uapi/linux/liveupdate.h | 38 ++++++++++++
kernel/liveupdate/luo_file.c | 37 +++++------
kernel/liveupdate/luo_internal.h | 3 +
kernel/liveupdate/luo_session.c | 71 ++++++++++++++++++++--
6 files changed, 146 insertions(+), 25 deletions(-)
diff --git a/Documentation/userspace-api/liveupdate.rst b/Documentation/userspace-api/liveupdate.rst
index cdd74627ab75..c298b5d0dfe7 100644
--- a/Documentation/userspace-api/liveupdate.rst
+++ b/Documentation/userspace-api/liveupdate.rst
@@ -22,6 +22,26 @@ change, so compatibility is not guaranteed when kexec rebooting between
different kernel versions. This is expected to change and stabilize in a future
version.
+Session Freeze
+==============
+
+By default, LUO freezes active sessions during reboot, and an outgoing session
+stays alive only while its session fd remains open. Closing the fd before
+reboot aborts preservation and releases the session's resources.
+
+Userspace can freeze an outgoing session earlier with LIVEUPDATE_SESSION_FREEZE
+once it is done preserving and modifying the session's files:
+
+- Freeze: freezes the session's preserved files, allowing sessions to freeze
+ concurrently ahead of reboot. The session remains tied to its fd, so closing
+ the fd before reboot rolls back and releases the session.
+
+- Freeze and commit: userspace can optionally set
+ LIVEUPDATE_SESSION_FREEZE_COMMIT in flags to commit the frozen session. This
+ serializes the session and its FLBs into the outgoing KHO state immediately
+ and hands ownership to LUO. Once committed, the session survives closing its
+ fd until reboot, allowing processes to exit before kexec.
+
Userspace Integration
=====================
diff --git a/include/linux/liveupdate.h b/include/linux/liveupdate.h
index 6051abc0612c..ead033c59c22 100644
--- a/include/linux/liveupdate.h
+++ b/include/linux/liveupdate.h
@@ -59,7 +59,7 @@ struct liveupdate_file_op_args {
* compatible with the given file.
* @preserve: Required. Performs state-saving for the file.
* @unpreserve: Required. Cleans up any resources allocated by @preserve.
- * @freeze: Optional. Final actions just before kernel transition.
+ * @freeze: Optional. Final actions on session freeze or reboot.
* @unfreeze: Optional. Undo freeze operations.
* @retrieve: Required. Restores the file in the new kernel.
* @can_finish: Optional. Check if this FD can finish, i.e. all restoration
diff --git a/include/uapi/linux/liveupdate.h b/include/uapi/linux/liveupdate.h
index 4043d4038712..ac456f4014c5 100644
--- a/include/uapi/linux/liveupdate.h
+++ b/include/uapi/linux/liveupdate.h
@@ -60,6 +60,7 @@ enum {
LIVEUPDATE_CMD_SESSION_RETRIEVE_FD = 0x41,
LIVEUPDATE_CMD_SESSION_FINISH = 0x42,
LIVEUPDATE_CMD_SESSION_GET_NAME = 0x43,
+ LIVEUPDATE_CMD_SESSION_FREEZE = 0x44,
};
/**
@@ -236,4 +237,41 @@ struct liveupdate_session_get_name {
#define LIVEUPDATE_SESSION_GET_NAME \
_IO(LIVEUPDATE_IOCTL_TYPE, LIVEUPDATE_CMD_SESSION_GET_NAME)
+/**
+ * enum liveupdate_session_freeze_flags - Flags for LIVEUPDATE_SESSION_FREEZE
+ * @LIVEUPDATE_SESSION_FREEZE_COMMIT: Commit the frozen session so it is
+ * serialized immediately and survives
+ * closing the session FD until reboot.
+ */
+enum liveupdate_session_freeze_flags {
+ LIVEUPDATE_SESSION_FREEZE_COMMIT = 1 << 0,
+};
+
+/**
+ * struct liveupdate_session_freeze - ioctl(LIVEUPDATE_SESSION_FREEZE)
+ * @size: Input; sizeof(struct liveupdate_session_freeze)
+ * @flags: Input; Bitmask of enum liveupdate_session_freeze_flags.
+ *
+ * Freezes an outgoing session before kexec reboot. Once frozen, no further
+ * files can be preserved in the session and repeated freeze calls return
+ * -EBUSY. Calling this on an incoming session returns -EINVAL.
+ *
+ * With @flags set to 0, session lifetime stays tied to the session FD:
+ * closing the FD before reboot unfreezes and unpreserves the session.
+ *
+ * With %LIVEUPDATE_SESSION_FREEZE_COMMIT set, the frozen session is
+ * serialized immediately and ownership transfers to LUO until reboot.
+ * Closing the FD or another session failing to freeze during reboot will
+ * not unfreeze or unpreserve a committed session.
+ *
+ * Return: 0 on success, negative error code on failure.
+ */
+struct liveupdate_session_freeze {
+ __u32 size;
+ __u32 flags;
+};
+
+#define LIVEUPDATE_SESSION_FREEZE \
+ _IO(LIVEUPDATE_IOCTL_TYPE, LIVEUPDATE_CMD_SESSION_FREEZE)
+
#endif /* _UAPI_LIVEUPDATE_H */
diff --git a/kernel/liveupdate/luo_file.c b/kernel/liveupdate/luo_file.c
index cdd3c466e5ac..2cbac44d37cc 100644
--- a/kernel/liveupdate/luo_file.c
+++ b/kernel/liveupdate/luo_file.c
@@ -31,9 +31,8 @@
* - unpreserve(): Cleans up any resources allocated by .preserve(), called
* if the preservation process is aborted before the reboot (i.e. session is
* closed).
- * - freeze(): A final pre-reboot opportunity to prepare the state for kexec.
- * We are already in reboot syscall, and therefore userspace cannot mutate
- * the file anymore.
+ * - freeze(): Prepares the final state for kexec, invoked either on an
+ * explicit session freeze or during the reboot() syscall.
* - unfreeze(): Undoes the actions of .freeze(), called if the live update
* is aborted after the freeze phase.
* - retrieve(): Reconstructs the file in the new kernel from the preserved
@@ -48,7 +47,7 @@
* handler, calls its .preserve() operation, and creates an internal &struct
* luo_file to track the live state.
*
- * 2. Freeze (Pre-Reboot): Just before the kexec, luo_file_freeze() is called.
+ * 2. Freeze (Pre-Reboot): When a session freezes, luo_file_freeze() is called.
* It iterates through all preserved files, calls their respective .freeze()
* operation, and serializes their final metadata (compatible string, token,
* and data handle) into a contiguous memory block for KHO.
@@ -77,12 +76,15 @@
* descriptor), the session's release handler calls
* luo_file_unpreserve_files(). This invokes the .unpreserve() callback on
* all preserved files, ensuring all allocated resources are cleaned up and
- * returning the system to a clean state.
+ * returning the system to a clean state. If the session was frozen early
+ * without committing, its files are unfrozen first. Committed sessions stay
+ * preserved until reboot even after the session FD is closed.
*
* 2. Freeze Failure: During the reboot() syscall, if any handler's .freeze()
* op fails, the .unfreeze() op is invoked on all previously *successful*
* freezes to roll back their state. The reboot() syscall then returns an
- * error to userspace, canceling the live update.
+ * error to userspace, canceling the live update. On an explicit session
+ * freeze, only that session's frozen files are rolled back via .unfreeze().
*
* 3. Finish Failure: In the new kernel, if a handler's .finish() op fails,
* the luo_file_finish() operation is aborted. LUO retains ownership of
@@ -457,9 +459,9 @@ static void __luo_file_unfreeze(struct luo_file_set *file_set,
* luo_file_freeze - Freezes all preserved files and serializes their metadata.
* @file_set: The file_set whose files are to be frozen.
*
- * This function is called from the reboot() syscall path, just before the
- * kernel transitions to the new image via kexec. Its purpose is to perform the
- * final preparation and serialization of all preserved files in the file_set.
+ * This function is called on explicit session freeze or from the reboot()
+ * syscall path to perform final preparation and serialization of all
+ * preserved files in the file_set.
*
* It iterates through each preserved file in FIFO order (the order of
* preservation) and performs two main actions:
@@ -476,13 +478,12 @@ static void __luo_file_unfreeze(struct luo_file_set *file_set,
*
* Error Handling (Rollback):
* This function is atomic. If any handler's .freeze() operation fails, the
- * entire live update is aborted. The __luo_file_unfreeze() helper is
- * immediately called to invoke the .unfreeze() op on all files that were
- * successfully frozen before the point of failure, rolling them back to a
- * running state. The function then returns an error, causing the reboot()
- * syscall to fail.
+ * __luo_file_unfreeze() helper is immediately called to invoke the .unfreeze()
+ * op on all files that were successfully frozen before the point of failure,
+ * rolling them back to an unfrozen state, and an error is returned to the
+ * caller, canceling the live update if called from the reboot() path.
*
- * Context: Called only from the liveupdate_reboot() path.
+ * Context: Called on explicit session freeze or from liveupdate_reboot().
* Return: 0 on success, or a negative errno on failure.
*/
int luo_file_freeze(struct luo_file_set *file_set)
@@ -532,15 +533,15 @@ int luo_file_freeze(struct luo_file_set *file_set)
* @file_set: The file_set whose files are to be unfrozen.
*
* This function rolls back the state of all files in a file_set after the
- * freeze phase has begun but must be aborted. It is the counterpart to
- * luo_file_freeze().
+ * freeze phase has begun. It is the counterpart to luo_file_freeze().
*
* It invokes the __luo_file_unfreeze() helper with a NULL argument, which
* signals the helper to iterate through all files in the file_set, call their
* respective .unfreeze() handler callbacks, and clear the serialized blocks.
*
* Context: This is called when the live update is aborted during
- * the reboot() syscall, after luo_file_freeze() has been called.
+ * the reboot() syscall, after luo_file_freeze() has been called,
+ * or when a frozen uncommitted session is released before kexec.
*/
void luo_file_unfreeze(struct luo_file_set *file_set)
{
diff --git a/kernel/liveupdate/luo_internal.h b/kernel/liveupdate/luo_internal.h
index 3d948279f018..bd3f0d192621 100644
--- a/kernel/liveupdate/luo_internal.h
+++ b/kernel/liveupdate/luo_internal.h
@@ -66,6 +66,8 @@ struct luo_file_set {
* retrieved by a consumer in the new kernel.
* @serialized: A boolean flag indicating whether this outgoing session has
* been serialized into KHO.
+ * @user_frozen: A boolean flag indicating whether this session has been
+ * frozen explicitly from userspace.
* @file_set: A set of files that belong to this session.
* @mutex: protects fields in the luo_session.
*/
@@ -74,6 +76,7 @@ struct luo_session {
struct list_head list;
bool retrieved;
bool serialized;
+ bool user_frozen;
struct luo_file_set file_set;
struct mutex mutex;
};
diff --git a/kernel/liveupdate/luo_session.c b/kernel/liveupdate/luo_session.c
index 013386534b69..bf58718fa61b 100644
--- a/kernel/liveupdate/luo_session.c
+++ b/kernel/liveupdate/luo_session.c
@@ -34,10 +34,11 @@
* 1. Creation: A userspace agent calls `luo_session_create()` to create a
* new, empty session and receives a file descriptor for it.
*
- * 2. Serialization: When the `reboot(LINUX_REBOOT_CMD_KEXEC)` syscall is
- * made, `luo_session_serialize()` is called. It iterates through all
- * active sessions and writes their metadata into a memory area preserved
- * by KHO.
+ * 2. Serialization: Sessions may be frozen ahead of reboot via
+ * `LIVEUPDATE_SESSION_FREEZE`, and optionally committed to serialize
+ * their metadata into KHO immediately so they survive closing the FD.
+ * When `reboot(LINUX_REBOOT_CMD_KEXEC)` is called,
+ * `luo_session_serialize()` freezes and serializes any remaining sessions.
*
* 3. Deserialization (in new kernel): After kexec, `luo_session_deserialize()`
* runs, reading the serialized data and creating a list of `struct
@@ -254,12 +255,21 @@ static int luo_session_finish_one(struct luo_session *session)
static void luo_session_unfreeze_one(struct luo_session *session)
{
guard(mutex)(&session->mutex);
- luo_file_unfreeze(&session->file_set);
+ /*
+ * Only unfreeze sessions that were auto-frozen by
+ * luo_session_freeze_one(); sessions frozen explicitly by
+ * userspace stay frozen until the session FD is closed.
+ */
+ if (!session->user_frozen)
+ luo_file_unfreeze(&session->file_set);
}
static int luo_session_freeze_one(struct luo_session *session)
{
guard(mutex)(&session->mutex);
+ if (session->user_frozen)
+ return 0;
+
return luo_file_freeze(&session->file_set);
}
@@ -280,8 +290,13 @@ static int luo_session_release(struct inode *inodep, struct file *filep)
}
sh = &luo_session_global.incoming;
} else {
- scoped_guard(mutex, &session->mutex)
+ scoped_guard(mutex, &session->mutex) {
+ if (session->serialized)
+ return 0;
+ if (session->user_frozen)
+ luo_file_unfreeze(&session->file_set);
luo_file_unpreserve_files(&session->file_set);
+ }
sh = &luo_session_global.outgoing;
}
@@ -298,6 +313,9 @@ static int luo_session_preserve_fd(struct luo_session *session,
int err;
guard(mutex)(&session->mutex);
+ if (session->user_frozen)
+ return -EBUSY;
+
err = luo_preserve_file(&session->file_set, argp->token, argp->fd);
if (err)
return err;
@@ -371,11 +389,50 @@ static int luo_session_get_name(struct luo_session *session,
return luo_ucmd_respond(ucmd, sizeof(*argp));
}
+static int luo_session_freeze(struct luo_session *session,
+ struct luo_ucmd *ucmd)
+{
+ struct liveupdate_session_freeze *argp = ucmd->cmd;
+ int err;
+
+ if (argp->flags & ~LIVEUPDATE_SESSION_FREEZE_COMMIT)
+ return -EOPNOTSUPP;
+
+ scoped_guard(mutex, &session->mutex) {
+ if (session->user_frozen)
+ return -EBUSY;
+
+ err = luo_file_freeze(&session->file_set);
+ if (err)
+ return err;
+
+ err = luo_ucmd_respond(ucmd, sizeof(*argp));
+ if (err) {
+ luo_file_unfreeze(&session->file_set);
+ return err;
+ }
+
+ session->user_frozen = true;
+ }
+
+ if (argp->flags & LIVEUPDATE_SESSION_FREEZE_COMMIT) {
+ struct luo_session_header *sh = &luo_session_global.outgoing;
+
+ guard(rwsem_write)(&sh->rwsem);
+ guard(mutex)(&session->mutex);
+
+ luo_session_serialize_one(session);
+ }
+
+ return 0;
+}
+
union ucmd_buffer {
struct liveupdate_session_finish finish;
struct liveupdate_session_preserve_fd preserve;
struct liveupdate_session_retrieve_fd retrieve;
struct liveupdate_session_get_name get_name;
+ struct liveupdate_session_freeze freeze;
};
/* Type of sessions the ioctl applies to. */
@@ -413,6 +470,8 @@ static const struct luo_ioctl_op luo_session_ioctl_ops[] = {
struct liveupdate_session_retrieve_fd, token, LUO_IOCTL_INCOMING),
IOCTL_OP(LIVEUPDATE_SESSION_GET_NAME, luo_session_get_name,
struct liveupdate_session_get_name, name, LUO_IOCTL_ALL),
+ IOCTL_OP(LIVEUPDATE_SESSION_FREEZE, luo_session_freeze,
+ struct liveupdate_session_freeze, flags, LUO_IOCTL_OUTGOING),
};
static bool luo_ioctl_type_valid(struct luo_session *session,
--
2.56.1.708.g77570a6a1d-goog
^ permalink raw reply related [flat|nested] 18+ messages in thread* Re: [PATCH v6 5/7] liveupdate: Add LIVEUPDATE_SESSION_FREEZE ioctl to freeze sessions early
2026-11-18 21:28 ` [PATCH v6 5/7] liveupdate: Add LIVEUPDATE_SESSION_FREEZE ioctl to freeze sessions early Pasha Tatashin
@ 2026-11-18 21:36 ` sashiko-bot
2026-11-19 11:03 ` Mike Rapoport
1 sibling, 0 replies; 18+ messages in thread
From: sashiko-bot @ 2026-11-18 21:36 UTC (permalink / raw)
To: Pasha Tatashin, rppt, shuah, skhan, vipinsh, corbet, dmatlack,
kexec, pratyush, rdunlap, graf
> Add the LIVEUPDATE_SESSION_FREEZE ioctl on outgoing session FDs. Once
> frozen, no additional files can be preserved in the session and
> repeated freeze calls return -EBUSY.
>
> Currently, LUO freezes sessions only during reboot(LINUX_REBOOT_CMD_KEXEC),
> serially under global write locks. On hosts running multiple workloads
> such as VMs, freezing sessions early under their per-session mutexes
> lets workloads freeze in parallel as they pause ahead of kexec,
> reducing blackout time.
>
> By default, session lifetime remains tied to the session FD: closing
> the FD before reboot unfreezes and unpreserves the session, while
> keeping it open skips late auto-freeze at kexec.
>
> Add optional flag LIVEUPDATE_SESSION_FREEZE_COMMIT to serialize the
> frozen session and its FLBs immediately and transfer ownership to LUO
> until reboot. Committed sessions survive closing the session FD,
> allowing processes to hand off preserved state and exit prior to kexec.
>
> Signed-off-by: Pasha Tatashin <pasha.tatashin@soleen.com>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261118212845.2855249-1-pasha.tatashin@soleen.com?part=5
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH v6 5/7] liveupdate: Add LIVEUPDATE_SESSION_FREEZE ioctl to freeze sessions early
2026-11-18 21:28 ` [PATCH v6 5/7] liveupdate: Add LIVEUPDATE_SESSION_FREEZE ioctl to freeze sessions early Pasha Tatashin
2026-11-18 21:36 ` sashiko-bot
@ 2026-11-19 11:03 ` Mike Rapoport
1 sibling, 0 replies; 18+ messages in thread
From: Mike Rapoport @ 2026-11-19 11:03 UTC (permalink / raw)
To: Pasha Tatashin
Cc: linux-kselftest, rppt, shuah, skhan, linux-doc, vipinsh,
linux-kernel, corbet, linux-api, dmatlack, kexec, pratyush,
rdunlap, graf
Hi,
> Add the LIVEUPDATE_SESSION_FREEZE ioctl on outgoing session FDs. Once
> frozen, no additional files can be preserved in the session and
> repeated freeze calls return -EBUSY.
>
> Currently, LUO freezes sessions only during reboot(LINUX_REBOOT_CMD_KEXEC),
> serially under global write locks. On hosts running multiple workloads
> such as VMs, freezing sessions early under their per-session mutexes
> lets workloads freeze in parallel as they pause ahead of kexec,
> reducing blackout time.
>
> By default, session lifetime remains tied to the session FD: closing
> the FD before reboot unfreezes and unpreserves the session, while
> keeping it open skips late auto-freeze at kexec.
>
> Add optional flag LIVEUPDATE_SESSION_FREEZE_COMMIT to serialize the
> frozen session and its FLBs immediately and transfer ownership to LUO
> until reboot. Committed sessions survive closing the session FD,
> allowing processes to hand off preserved state and exit prior to kexec.
>
> Signed-off-by: Pasha Tatashin <pasha.tatashin@soleen.com>
> ---
> Documentation/userspace-api/liveupdate.rst | 20 ++++++
> include/linux/liveupdate.h | 2 +-
> include/uapi/linux/liveupdate.h | 38 ++++++++++++
> kernel/liveupdate/luo_file.c | 37 +++++------
> kernel/liveupdate/luo_internal.h | 3 +
> kernel/liveupdate/luo_session.c | 71 ++++++++++++++++++++--
> 6 files changed, 146 insertions(+), 25 deletions(-)
>
> diff --git a/Documentation/userspace-api/liveupdate.rst b/Documentation/userspace-api/liveupdate.rst
> index cdd74627ab75b..c298b5d0dfe75 100644
> --- a/Documentation/userspace-api/liveupdate.rst
> +++ b/Documentation/userspace-api/liveupdate.rst
> @@ -22,6 +22,26 @@ change, so compatibility is not guaranteed when kexec rebooting between
> different kernel versions. This is expected to change and stabilize in a future
> version.
>
> +Session Freeze
> +==============
> +
> +By default, LUO freezes active sessions during reboot, and an outgoing session
> +stays alive only while its session fd remains open. Closing the fd before
> +reboot aborts preservation and releases the session's resources.
> +
> +Userspace can freeze an outgoing session earlier with LIVEUPDATE_SESSION_FREEZE
> +once it is done preserving and modifying the session's files:
> +
> +- Freeze: freezes the session's preserved files, allowing sessions to freeze
> + concurrently ahead of reboot. The session remains tied to its fd, so closing
> + the fd before reboot rolls back and releases the session.
> +
> +- Freeze and commit: userspace can optionally set
> + LIVEUPDATE_SESSION_FREEZE_COMMIT in flags to commit the frozen session. This
> + serializes the session and its FLBs into the outgoing KHO state immediately
> + and hands ownership to LUO. Once committed, the session survives closing its
> + fd until reboot, allowing processes to exit before kexec.
> +
> Userspace Integration
> =====================
>
> diff --git a/include/linux/liveupdate.h b/include/linux/liveupdate.h
> index 6051abc0612ce..ead033c59c22d 100644
> --- a/include/linux/liveupdate.h
> +++ b/include/linux/liveupdate.h
> @@ -59,7 +59,7 @@ struct liveupdate_file_op_args {
> * compatible with the given file.
> * @preserve: Required. Performs state-saving for the file.
> * @unpreserve: Required. Cleans up any resources allocated by @preserve.
> - * @freeze: Optional. Final actions just before kernel transition.
> + * @freeze: Optional. Final actions on session freeze or reboot.
> * @unfreeze: Optional. Undo freeze operations.
> * @retrieve: Required. Restores the file in the new kernel.
> * @can_finish: Optional. Check if this FD can finish, i.e. all restoration
> diff --git a/include/uapi/linux/liveupdate.h b/include/uapi/linux/liveupdate.h
> index 4043d40387125..ac456f4014c5d 100644
> --- a/include/uapi/linux/liveupdate.h
> +++ b/include/uapi/linux/liveupdate.h
> @@ -60,6 +60,7 @@ enum {
> LIVEUPDATE_CMD_SESSION_RETRIEVE_FD = 0x41,
> LIVEUPDATE_CMD_SESSION_FINISH = 0x42,
> LIVEUPDATE_CMD_SESSION_GET_NAME = 0x43,
> + LIVEUPDATE_CMD_SESSION_FREEZE = 0x44,
> };
>
> /**
> @@ -236,4 +237,41 @@ struct liveupdate_session_get_name {
> #define LIVEUPDATE_SESSION_GET_NAME \
> _IO(LIVEUPDATE_IOCTL_TYPE, LIVEUPDATE_CMD_SESSION_GET_NAME)
>
> +/**
> + * enum liveupdate_session_freeze_flags - Flags for LIVEUPDATE_SESSION_FREEZE
> + * @LIVEUPDATE_SESSION_FREEZE_COMMIT: Commit the frozen session so it is
> + * serialized immediately and survives
> + * closing the session FD until reboot.
> + */
> +enum liveupdate_session_freeze_flags {
> + LIVEUPDATE_SESSION_FREEZE_COMMIT = 1 << 0,
> +};
> +
> +/**
> + * struct liveupdate_session_freeze - ioctl(LIVEUPDATE_SESSION_FREEZE)
> + * @size: Input; sizeof(struct liveupdate_session_freeze)
> + * @flags: Input; Bitmask of enum liveupdate_session_freeze_flags.
> + *
> + * Freezes an outgoing session before kexec reboot. Once frozen, no further
> + * files can be preserved in the session and repeated freeze calls return
> + * -EBUSY. Calling this on an incoming session returns -EINVAL.
> + *
> + * With @flags set to 0, session lifetime stays tied to the session FD:
> + * closing the FD before reboot unfreezes and unpreserves the session.
> + *
> + * With %LIVEUPDATE_SESSION_FREEZE_COMMIT set, the frozen session is
> + * serialized immediately and ownership transfers to LUO until reboot.
> + * Closing the FD or another session failing to freeze during reboot will
> + * not unfreeze or unpreserve a committed session.
Once a session is committed and its fd is closed, there's no way back. The
memory stays preserved, the name returns -EEXIST, and if the update is
aborted the session will be handed over on whatever next kexec happens.
How is userspace expected to recover from an aborted live update after it
committed some sessions? Should there be a way to reclaim or discard a
committed session, e.g. by reopening it by name or by a separate command?
> + *
> + * Return: 0 on success, negative error code on failure.
> + */
> +struct liveupdate_session_freeze {
> + __u32 size;
> + __u32 flags;
> +};
> +
> +#define LIVEUPDATE_SESSION_FREEZE \
> + _IO(LIVEUPDATE_IOCTL_TYPE, LIVEUPDATE_CMD_SESSION_FREEZE)
> +
> #endif /* _UAPI_LIVEUPDATE_H */
> diff --git a/kernel/liveupdate/luo_file.c b/kernel/liveupdate/luo_file.c
> index cdd3c466e5ac3..2cbac44d37cce 100644
> --- a/kernel/liveupdate/luo_file.c
> +++ b/kernel/liveupdate/luo_file.c
> @@ -31,9 +31,8 @@
> * - unpreserve(): Cleans up any resources allocated by .preserve(), called
> * if the preservation process is aborted before the reboot (i.e. session is
> * closed).
> - * - freeze(): A final pre-reboot opportunity to prepare the state for kexec.
> - * We are already in reboot syscall, and therefore userspace cannot mutate
> - * the file anymore.
> + * - freeze(): Prepares the final state for kexec, invoked either on an
GitHub Copilot <copilot@localhost>:
The removed sentence was the only place documenting what .freeze() may
assume. With early freeze userspace still has the files and can keep using
them after freeze returns. For example, memfd_luo_freeze() snapshots f_pos,
and the memfd documentation says the current file position is preserved,
which is no longer true if the file is used after the freeze.
memfd is fine otherwise because size and folios are pinned at preserve time,
but please spell out in the liveupdate_file_ops kernel-doc that a file may
be accessed after .freeze() and that handlers must not rely on it being
quiescent.
> + * explicit session freeze or during the reboot() syscall.
> * - unfreeze(): Undoes the actions of .freeze(), called if the live update
> * is aborted after the freeze phase.
> * - retrieve(): Reconstructs the file in the new kernel from the preserved
> @@ -48,7 +47,7 @@
> * handler, calls its .preserve() operation, and creates an internal &struct
> * luo_file to track the live state.
> *
> - * 2. Freeze (Pre-Reboot): Just before the kexec, luo_file_freeze() is called.
> + * 2. Freeze (Pre-Reboot): When a session freezes, luo_file_freeze() is called.
> * It iterates through all preserved files, calls their respective .freeze()
> * operation, and serializes their final metadata (compatible string, token,
> * and data handle) into a contiguous memory block for KHO.
> @@ -77,12 +76,15 @@
> * descriptor), the session's release handler calls
> * luo_file_unpreserve_files(). This invokes the .unpreserve() callback on
> * all preserved files, ensuring all allocated resources are cleaned up and
> - * returning the system to a clean state.
> + * returning the system to a clean state. If the session was frozen early
> + * without committing, its files are unfrozen first. Committed sessions stay
> + * preserved until reboot even after the session FD is closed.
> *
> * 2. Freeze Failure: During the reboot() syscall, if any handler's .freeze()
> * op fails, the .unfreeze() op is invoked on all previously *successful*
> * freezes to roll back their state. The reboot() syscall then returns an
> - * error to userspace, canceling the live update.
> + * error to userspace, canceling the live update. On an explicit session
> + * freeze, only that session's frozen files are rolled back via .unfreeze().
> *
> * 3. Finish Failure: In the new kernel, if a handler's .finish() op fails,
> * the luo_file_finish() operation is aborted. LUO retains ownership of
> @@ -457,9 +459,9 @@ static void __luo_file_unfreeze(struct luo_file_set *file_set,
> * luo_file_freeze - Freezes all preserved files and serializes their metadata.
> * @file_set: The file_set whose files are to be frozen.
> *
> - * This function is called from the reboot() syscall path, just before the
> - * kernel transitions to the new image via kexec. Its purpose is to perform the
> - * final preparation and serialization of all preserved files in the file_set.
> + * This function is called on explicit session freeze or from the reboot()
> + * syscall path to perform final preparation and serialization of all
> + * preserved files in the file_set.
> *
> * It iterates through each preserved file in FIFO order (the order of
> * preservation) and performs two main actions:
> @@ -476,13 +478,12 @@ static void __luo_file_unfreeze(struct luo_file_set *file_set,
> *
> * Error Handling (Rollback):
> * This function is atomic. If any handler's .freeze() operation fails, the
> - * entire live update is aborted. The __luo_file_unfreeze() helper is
> - * immediately called to invoke the .unfreeze() op on all files that were
> - * successfully frozen before the point of failure, rolling them back to a
> - * running state. The function then returns an error, causing the reboot()
> - * syscall to fail.
> + * __luo_file_unfreeze() helper is immediately called to invoke the .unfreeze()
> + * op on all files that were successfully frozen before the point of failure,
> + * rolling them back to an unfrozen state, and an error is returned to the
> + * caller, canceling the live update if called from the reboot() path.
> *
> - * Context: Called only from the liveupdate_reboot() path.
> + * Context: Called on explicit session freeze or from liveupdate_reboot().
> * Return: 0 on success, or a negative errno on failure.
> */
> int luo_file_freeze(struct luo_file_set *file_set)
> @@ -532,15 +533,15 @@ int luo_file_freeze(struct luo_file_set *file_set)
> * @file_set: The file_set whose files are to be unfrozen.
> *
> * This function rolls back the state of all files in a file_set after the
> - * freeze phase has begun but must be aborted. It is the counterpart to
> - * luo_file_freeze().
> + * freeze phase has begun. It is the counterpart to luo_file_freeze().
> *
> * It invokes the __luo_file_unfreeze() helper with a NULL argument, which
> * signals the helper to iterate through all files in the file_set, call their
> * respective .unfreeze() handler callbacks, and clear the serialized blocks.
> *
> * Context: This is called when the live update is aborted during
> - * the reboot() syscall, after luo_file_freeze() has been called.
> + * the reboot() syscall, after luo_file_freeze() has been called,
> + * or when a frozen uncommitted session is released before kexec.
> */
> void luo_file_unfreeze(struct luo_file_set *file_set)
> {
> diff --git a/kernel/liveupdate/luo_internal.h b/kernel/liveupdate/luo_internal.h
> index 3d948279f018c..bd3f0d1926218 100644
> --- a/kernel/liveupdate/luo_internal.h
> +++ b/kernel/liveupdate/luo_internal.h
> @@ -66,6 +66,8 @@ struct luo_file_set {
> * retrieved by a consumer in the new kernel.
> * @serialized: A boolean flag indicating whether this outgoing session has
> * been serialized into KHO.
> + * @user_frozen: A boolean flag indicating whether this session has been
> + * frozen explicitly from userspace.
> * @file_set: A set of files that belong to this session.
> * @mutex: protects fields in the luo_session.
> */
> @@ -74,6 +76,7 @@ struct luo_session {
> struct list_head list;
> bool retrieved;
> bool serialized;
> + bool user_frozen;
> struct luo_file_set file_set;
> struct mutex mutex;
> };
> diff --git a/kernel/liveupdate/luo_session.c b/kernel/liveupdate/luo_session.c
> index 013386534b698..bf58718fa61ba 100644
> --- a/kernel/liveupdate/luo_session.c
> +++ b/kernel/liveupdate/luo_session.c
> @@ -34,10 +34,11 @@
> * 1. Creation: A userspace agent calls `luo_session_create()` to create a
> * new, empty session and receives a file descriptor for it.
> *
> - * 2. Serialization: When the `reboot(LINUX_REBOOT_CMD_KEXEC)` syscall is
> - * made, `luo_session_serialize()` is called. It iterates through all
> - * active sessions and writes their metadata into a memory area preserved
> - * by KHO.
> + * 2. Serialization: Sessions may be frozen ahead of reboot via
> + * `LIVEUPDATE_SESSION_FREEZE`, and optionally committed to serialize
> + * their metadata into KHO immediately so they survive closing the FD.
> + * When `reboot(LINUX_REBOOT_CMD_KEXEC)` is called,
> + * `luo_session_serialize()` freezes and serializes any remaining sessions.
> *
> * 3. Deserialization (in new kernel): After kexec, `luo_session_deserialize()`
> * runs, reading the serialized data and creating a list of `struct
> @@ -254,12 +255,21 @@ static int luo_session_finish_one(struct luo_session *session)
> static void luo_session_unfreeze_one(struct luo_session *session)
> {
> guard(mutex)(&session->mutex);
> - luo_file_unfreeze(&session->file_set);
> + /*
> + * Only unfreeze sessions that were auto-frozen by
> + * luo_session_freeze_one(); sessions frozen explicitly by
> + * userspace stay frozen until the session FD is closed.
> + */
> + if (!session->user_frozen)
> + luo_file_unfreeze(&session->file_set);
> }
>
> static int luo_session_freeze_one(struct luo_session *session)
> {
> guard(mutex)(&session->mutex);
> + if (session->user_frozen)
> + return 0;
> +
> return luo_file_freeze(&session->file_set);
> }
>
> @@ -280,8 +290,13 @@ static int luo_session_release(struct inode *inodep, struct file *filep)
> }
> sh = &luo_session_global.incoming;
> } else {
> - scoped_guard(mutex, &session->mutex)
> + scoped_guard(mutex, &session->mutex) {
> + if (session->serialized)
> + return 0;
> + if (session->user_frozen)
> + luo_file_unfreeze(&session->file_set);
> luo_file_unpreserve_files(&session->file_set);
> + }
> sh = &luo_session_global.outgoing;
> }
>
> @@ -298,6 +313,9 @@ static int luo_session_preserve_fd(struct luo_session *session,
> int err;
>
> guard(mutex)(&session->mutex);
> + if (session->user_frozen)
> + return -EBUSY;
> +
> err = luo_preserve_file(&session->file_set, argp->token, argp->fd);
> if (err)
> return err;
> @@ -371,11 +389,50 @@ static int luo_session_get_name(struct luo_session *session,
> return luo_ucmd_respond(ucmd, sizeof(*argp));
> }
>
> +static int luo_session_freeze(struct luo_session *session,
> + struct luo_ucmd *ucmd)
> +{
> + struct liveupdate_session_freeze *argp = ucmd->cmd;
> + int err;
> +
> + if (argp->flags & ~LIVEUPDATE_SESSION_FREEZE_COMMIT)
> + return -EOPNOTSUPP;
> +
> + scoped_guard(mutex, &session->mutex) {
> + if (session->user_frozen)
> + return -EBUSY;
This means that a session frozen without COMMIT can never be committed. A
VMM that freezes early to shorten the blackout time has to decide right
then whether the session is handed off.
Can we allow COMMIT on a session that is user_frozen but not yet
serialized? That would let userspace freeze early and commit later, which
looks like a more natural flow.
> +
> + err = luo_file_freeze(&session->file_set);
> + if (err)
> + return err;
> +
> + err = luo_ucmd_respond(ucmd, sizeof(*argp));
> + if (err) {
> + luo_file_unfreeze(&session->file_set);
> + return err;
> + }
> +
> + session->user_frozen = true;
> + }
> +
> + if (argp->flags & LIVEUPDATE_SESSION_FREEZE_COMMIT) {
> + struct luo_session_header *sh = &luo_session_global.outgoing;
> +
> + guard(rwsem_write)(&sh->rwsem);
> + guard(mutex)(&session->mutex);
> +
> + luo_session_serialize_one(session);
The response is already copied to userspace above and
luo_session_serialize_one() returns void, so if it fails the ioctl still
reports success.
AFAIU the failure there is a WARN that shouldn't happen because the
capacity is reserved in sh->count, so this is minor, but having
luo_session_serialize_one() return an error and responding after the
commit would be cleaner.
--
Sincerely yours,
Mike.
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH v6 6/7] selftests: liveupdate: Add unit tests for LIVEUPDATE_SESSION_FREEZE
2026-11-18 21:28 [PATCH v6 0/7] liveupdate: Add LIVEUPDATE_SESSION_FREEZE ioctl Pasha Tatashin
` (4 preceding siblings ...)
2026-11-18 21:28 ` [PATCH v6 5/7] liveupdate: Add LIVEUPDATE_SESSION_FREEZE ioctl to freeze sessions early Pasha Tatashin
@ 2026-11-18 21:28 ` Pasha Tatashin
2026-11-18 21:34 ` sashiko-bot
2026-11-18 21:28 ` [PATCH v6 7/7] selftests: liveupdate: Test LIVEUPDATE_SESSION_FREEZE across kexec Pasha Tatashin
6 siblings, 1 reply; 18+ messages in thread
From: Pasha Tatashin @ 2026-11-18 21:28 UTC (permalink / raw)
To: linux-kselftest, rppt, shuah, skhan, linux-doc, vipinsh,
linux-kernel, corbet, linux-api, pasha.tatashin, dmatlack, kexec,
pratyush, rdunlap, graf
Add a luo_session_freeze() helper and unit tests in liveupdate.c for
LIVEUPDATE_SESSION_FREEZE. Verify negative cases (unsupported flags,
double freeze, and preserving files after freeze), that closing a
frozen uncommitted session unfreezes and returns resources, and that
closing a committed session retains LUO ownership of the session and
its preserved files.
Signed-off-by: Pasha Tatashin <pasha.tatashin@soleen.com>
---
.../liveupdate/lib/include/libliveupdate.h | 1 +
.../selftests/liveupdate/lib/lu_utils.c | 13 +++
.../testing/selftests/liveupdate/liveupdate.c | 107 ++++++++++++++++++
3 files changed, 121 insertions(+)
diff --git a/tools/testing/selftests/liveupdate/lib/include/libliveupdate.h b/tools/testing/selftests/liveupdate/lib/include/libliveupdate.h
index fa07fed08364..34657d6eb67b 100644
--- a/tools/testing/selftests/liveupdate/lib/include/libliveupdate.h
+++ b/tools/testing/selftests/liveupdate/lib/include/libliveupdate.h
@@ -26,6 +26,7 @@ int luo_create_session(int luo_fd, const char *name);
int luo_retrieve_session(int luo_fd, const char *name);
int luo_session_finish(int session_fd);
int luo_get_session_name(int session_fd, char *name, size_t name_len);
+int luo_session_freeze(int session_fd, __u32 flags);
int luo_ensure_nofile_limit(long min_limit);
int luo_session_preserve_fd(int session_fd, int fd, __u64 token);
diff --git a/tools/testing/selftests/liveupdate/lib/lu_utils.c b/tools/testing/selftests/liveupdate/lib/lu_utils.c
index 74d41115c281..51384374305d 100644
--- a/tools/testing/selftests/liveupdate/lib/lu_utils.c
+++ b/tools/testing/selftests/liveupdate/lib/lu_utils.c
@@ -198,6 +198,19 @@ int luo_session_finish(int session_fd)
return 0;
}
+int luo_session_freeze(int session_fd, __u32 flags)
+{
+ struct liveupdate_session_freeze arg = {
+ .size = sizeof(arg),
+ .flags = flags,
+ };
+
+ if (ioctl(session_fd, LIVEUPDATE_SESSION_FREEZE, &arg) < 0)
+ return -errno;
+
+ return 0;
+}
+
void create_state_file(int luo_fd, const char *session_name, int token,
int next_stage)
{
diff --git a/tools/testing/selftests/liveupdate/liveupdate.c b/tools/testing/selftests/liveupdate/liveupdate.c
index 2dedd5fc2534..4b0c0fb1be87 100644
--- a/tools/testing/selftests/liveupdate/liveupdate.c
+++ b/tools/testing/selftests/liveupdate/liveupdate.c
@@ -530,4 +530,111 @@ TEST_F(liveupdate_device, preserve_many_files)
ASSERT_EQ(close(session_fd), 0);
}
+/*
+ * Test Case: Session Freeze
+ *
+ * Verifies LIVEUPDATE_SESSION_FREEZE with flags == 0: unsupported flags return
+ * -EOPNOTSUPP, repeated freeze and post-freeze preserve return -EBUSY, and
+ * closing the session FD unfreezes the session and returns all resources.
+ */
+TEST_F(liveupdate_device, session_freeze)
+{
+ int session_fd, mem_fd1, mem_fd2;
+
+ self->fd1 = open(LIVEUPDATE_DEV, O_RDWR);
+ if (self->fd1 < 0 && errno == ENOENT)
+ SKIP(return, "%s does not exist", LIVEUPDATE_DEV);
+ ASSERT_GE(self->fd1, 0);
+
+ session_fd = luo_create_session(self->fd1, "session-freeze");
+ ASSERT_GE(session_fd, 0);
+
+ mem_fd1 = memfd_create("freeze-memfd-1", 0);
+ ASSERT_GE(mem_fd1, 0);
+ ASSERT_EQ(luo_session_preserve_fd(session_fd, mem_fd1, 0x1111), 0);
+
+ /* Unsupported flag bits must fail with -EOPNOTSUPP */
+ EXPECT_EQ(luo_session_freeze(session_fd, 1U << 1), -EOPNOTSUPP);
+
+ /* Freeze the session */
+ ASSERT_EQ(luo_session_freeze(session_fd, 0), 0);
+
+ /* Subsequent freeze attempts must fail with -EBUSY */
+ EXPECT_EQ(luo_session_freeze(session_fd, 0), -EBUSY);
+ EXPECT_EQ(luo_session_freeze(session_fd,
+ LIVEUPDATE_SESSION_FREEZE_COMMIT),
+ -EBUSY);
+
+ /* Preserving a file after freeze must fail with -EBUSY */
+ mem_fd2 = memfd_create("freeze-memfd-2", 0);
+ ASSERT_GE(mem_fd2, 0);
+ EXPECT_EQ(luo_session_preserve_fd(session_fd, mem_fd2, 0x2222), -EBUSY);
+
+ /* Closing the session FD must unfreeze and unpreserve resources */
+ ASSERT_EQ(close(session_fd), 0);
+
+ session_fd = luo_create_session(self->fd1, "session-freeze");
+ ASSERT_GE(session_fd, 0);
+ ASSERT_EQ(luo_session_preserve_fd(session_fd, mem_fd1, 0x1111), 0);
+
+ ASSERT_EQ(close(session_fd), 0);
+ ASSERT_EQ(close(mem_fd1), 0);
+ ASSERT_EQ(close(mem_fd2), 0);
+}
+
+/*
+ * Test Case: Session Freeze and Commit
+ *
+ * Verifies LIVEUPDATE_SESSION_FREEZE with LIVEUPDATE_SESSION_FREEZE_COMMIT:
+ * once committed, the frozen session is serialized into KHO and survives
+ * closing the session FD with ownership retained by LUO until reboot.
+ */
+TEST_F(liveupdate_device, session_freeze_commit)
+{
+ char name[LIVEUPDATE_SESSION_NAME_LENGTH];
+ int session_fd, session_fd2, mem_fd1, mem_fd2;
+
+ self->fd1 = open(LIVEUPDATE_DEV, O_RDWR);
+ if (self->fd1 < 0 && errno == ENOENT)
+ SKIP(return, "%s does not exist", LIVEUPDATE_DEV);
+ ASSERT_GE(self->fd1, 0);
+
+ snprintf(name, sizeof(name), "freeze-commit-%d", getpid());
+ session_fd = luo_create_session(self->fd1, name);
+ ASSERT_GE(session_fd, 0);
+
+ mem_fd1 = memfd_create("freeze-commit-memfd-1", 0);
+ ASSERT_GE(mem_fd1, 0);
+ ASSERT_EQ(luo_session_preserve_fd(session_fd, mem_fd1, 0x1111), 0);
+
+ /* Freeze and commit the session */
+ ASSERT_EQ(luo_session_freeze(session_fd,
+ LIVEUPDATE_SESSION_FREEZE_COMMIT), 0);
+
+ /* Subsequent freeze attempts must fail with -EBUSY */
+ EXPECT_EQ(luo_session_freeze(session_fd, 0), -EBUSY);
+ EXPECT_EQ(luo_session_freeze(session_fd,
+ LIVEUPDATE_SESSION_FREEZE_COMMIT),
+ -EBUSY);
+
+ /* Preserving a file after freeze must fail with -EBUSY */
+ mem_fd2 = memfd_create("freeze-commit-memfd-2", 0);
+ ASSERT_GE(mem_fd2, 0);
+ EXPECT_EQ(luo_session_preserve_fd(session_fd, mem_fd2, 0x2222), -EBUSY);
+
+ /* Closing the session FD must retain LUO ownership of session & files */
+ ASSERT_EQ(close(session_fd), 0);
+
+ EXPECT_EQ(luo_create_session(self->fd1, name), -EEXIST);
+
+ session_fd2 = luo_create_session(self->fd1, "freeze-commit-check");
+ ASSERT_GE(session_fd2, 0);
+ EXPECT_EQ(luo_session_preserve_fd(session_fd2, mem_fd1, 0x3333),
+ -EBUSY);
+
+ ASSERT_EQ(close(session_fd2), 0);
+ ASSERT_EQ(close(mem_fd1), 0);
+ ASSERT_EQ(close(mem_fd2), 0);
+}
+
TEST_HARNESS_MAIN
--
2.56.1.708.g77570a6a1d-goog
^ permalink raw reply related [flat|nested] 18+ messages in thread* Re: [PATCH v6 6/7] selftests: liveupdate: Add unit tests for LIVEUPDATE_SESSION_FREEZE
2026-11-18 21:28 ` [PATCH v6 6/7] selftests: liveupdate: Add unit tests for LIVEUPDATE_SESSION_FREEZE Pasha Tatashin
@ 2026-11-18 21:34 ` sashiko-bot
0 siblings, 0 replies; 18+ messages in thread
From: sashiko-bot @ 2026-11-18 21:34 UTC (permalink / raw)
To: Pasha Tatashin, rppt, shuah, skhan, vipinsh, corbet, dmatlack,
kexec, pratyush, rdunlap, graf
> Add a luo_session_freeze() helper and unit tests in liveupdate.c for
> LIVEUPDATE_SESSION_FREEZE. Verify negative cases (unsupported flags,
> double freeze, and preserving files after freeze), that closing a
> frozen uncommitted session unfreezes and returns resources, and that
> closing a committed session retains LUO ownership of the session and
> its preserved files.
>
> Signed-off-by: Pasha Tatashin <pasha.tatashin@soleen.com>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261118212845.2855249-1-pasha.tatashin@soleen.com?part=6
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH v6 7/7] selftests: liveupdate: Test LIVEUPDATE_SESSION_FREEZE across kexec
2026-11-18 21:28 [PATCH v6 0/7] liveupdate: Add LIVEUPDATE_SESSION_FREEZE ioctl Pasha Tatashin
` (5 preceding siblings ...)
2026-11-18 21:28 ` [PATCH v6 6/7] selftests: liveupdate: Add unit tests for LIVEUPDATE_SESSION_FREEZE Pasha Tatashin
@ 2026-11-18 21:28 ` Pasha Tatashin
2026-11-18 21:34 ` sashiko-bot
6 siblings, 1 reply; 18+ messages in thread
From: Pasha Tatashin @ 2026-11-18 21:28 UTC (permalink / raw)
To: linux-kselftest, rppt, shuah, skhan, linux-doc, vipinsh,
linux-kernel, corbet, linux-api, pasha.tatashin, dmatlack, kexec,
pratyush, rdunlap, graf
Extend luo_multi_session.c to exercise auto-frozen, kept-open frozen,
closed uncommitted frozen, and closed committed sessions together across
a kexec reboot, and verify that freezing an incoming session returns
-EINVAL.
Signed-off-by: Pasha Tatashin <pasha.tatashin@soleen.com>
---
.../selftests/liveupdate/luo_multi_session.c | 36 ++++++++++++++++++-
1 file changed, 35 insertions(+), 1 deletion(-)
diff --git a/tools/testing/selftests/liveupdate/luo_multi_session.c b/tools/testing/selftests/liveupdate/luo_multi_session.c
index aac24a5f5ce3..3b09cd63c832 100644
--- a/tools/testing/selftests/liveupdate/luo_multi_session.c
+++ b/tools/testing/selftests/liveupdate/luo_multi_session.c
@@ -15,14 +15,17 @@
#define SESSION_EMPTY_2 "multi-test-empty-2"
#define SESSION_FILES_1 "multi-test-files-1"
#define SESSION_FILES_2 "multi-test-files-2"
+#define SESSION_CLOSED "multi-test-closed"
#define MFD1_TOKEN 0x1001
#define MFD2_TOKEN 0x2002
#define MFD3_TOKEN 0x3003
+#define MFD_CLOSED_TOKEN 0x4004
#define MFD1_DATA "Data for session files 1"
#define MFD2_DATA "First file for session files 2"
#define MFD3_DATA "Second file for session files 2"
+#define MFD_CLOSED_DATA "Closed session data"
#define STATE_SESSION_NAME "kexec_multi_state"
#define STATE_MEMFD_TOKEN 998
@@ -30,7 +33,7 @@
/* Stage 1: Executed before the kexec reboot. */
static void run_stage_1(int luo_fd)
{
- int s_empty1_fd, s_empty2_fd, s_files1_fd, s_files2_fd;
+ int s_empty1_fd, s_empty2_fd, s_files1_fd, s_files2_fd, s_closed_fd;
ksft_print_msg("[STAGE 1] Starting pre-kexec setup for multi-session test...\n");
@@ -57,6 +60,8 @@ static void run_stage_1(int luo_fd)
fail_exit("create_and_preserve_memfd for token %#x",
MFD1_TOKEN);
}
+ if (luo_session_freeze(s_files1_fd, 0) < 0)
+ fail_exit("luo_session_freeze for '%s'", SESSION_FILES_1);
ksft_print_msg("[STAGE 1] Creating session '%s' with two memfds...\n",
SESSION_FILES_2);
@@ -72,6 +77,25 @@ static void run_stage_1(int luo_fd)
fail_exit("create_and_preserve_memfd for token %#x",
MFD3_TOKEN);
}
+ if (luo_session_freeze(s_files2_fd,
+ LIVEUPDATE_SESSION_FREEZE_COMMIT) < 0) {
+ fail_exit("luo_session_freeze for '%s'", SESSION_FILES_2);
+ }
+ close(s_files2_fd);
+
+ ksft_print_msg("[STAGE 1] Creating frozen uncommitted session '%s' and closing FD...\n",
+ SESSION_CLOSED);
+ s_closed_fd = luo_create_session(luo_fd, SESSION_CLOSED);
+ if (s_closed_fd < 0)
+ fail_exit("luo_create_session for '%s'", SESSION_CLOSED);
+ if (create_and_preserve_memfd(s_closed_fd, MFD_CLOSED_TOKEN,
+ MFD_CLOSED_DATA) < 0) {
+ fail_exit("create_and_preserve_memfd for token %#x",
+ MFD_CLOSED_TOKEN);
+ }
+ if (luo_session_freeze(s_closed_fd, 0) < 0)
+ fail_exit("luo_session_freeze for '%s'", SESSION_CLOSED);
+ close(s_closed_fd);
close(luo_fd);
daemonize_and_wait();
@@ -91,6 +115,13 @@ static void run_stage_2(int luo_fd, int state_session_fd)
stage);
}
+ ksft_print_msg("[STAGE 2] Verifying closed uncommitted session '%s' was not preserved...\n",
+ SESSION_CLOSED);
+ if (luo_retrieve_session(luo_fd, SESSION_CLOSED) != -ENOENT) {
+ fail_exit("Expected -ENOENT for closed uncommitted session '%s'",
+ SESSION_CLOSED);
+ }
+
ksft_print_msg("[STAGE 2] Retrieving all sessions...\n");
s_empty1_fd = luo_retrieve_session(luo_fd, SESSION_EMPTY_1);
if (s_empty1_fd < 0)
@@ -108,6 +139,9 @@ static void run_stage_2(int luo_fd, int state_session_fd)
if (s_files2_fd < 0)
fail_exit("luo_retrieve_session for '%s'", SESSION_FILES_2);
+ if (luo_session_freeze(s_files2_fd, 0) != -EINVAL)
+ fail_exit("luo_session_freeze on incoming session did not return -EINVAL");
+
ksft_print_msg("[STAGE 2] Verifying contents of session '%s'...\n",
SESSION_FILES_1);
mfd1 = restore_and_verify_memfd(s_files1_fd, MFD1_TOKEN, MFD1_DATA);
--
2.56.1.708.g77570a6a1d-goog
^ permalink raw reply related [flat|nested] 18+ messages in thread* Re: [PATCH v6 7/7] selftests: liveupdate: Test LIVEUPDATE_SESSION_FREEZE across kexec
2026-11-18 21:28 ` [PATCH v6 7/7] selftests: liveupdate: Test LIVEUPDATE_SESSION_FREEZE across kexec Pasha Tatashin
@ 2026-11-18 21:34 ` sashiko-bot
0 siblings, 0 replies; 18+ messages in thread
From: sashiko-bot @ 2026-11-18 21:34 UTC (permalink / raw)
To: Pasha Tatashin, rppt, shuah, skhan, vipinsh, corbet, dmatlack,
kexec, pratyush, rdunlap, graf
> Extend luo_multi_session.c to exercise auto-frozen, kept-open frozen,
> closed uncommitted frozen, and closed committed sessions together across
> a kexec reboot, and verify that freezing an incoming session returns
> -EINVAL.
>
> Signed-off-by: Pasha Tatashin <pasha.tatashin@soleen.com>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261118212845.2855249-1-pasha.tatashin@soleen.com?part=7
^ permalink raw reply [flat|nested] 18+ messages in thread