[PATCH v6 3/7] liveupdate: luo_session: support incremental session serialization

From: Pasha Tatashin

Date: Wed Nov 18 2026 - 16:29:21 EST


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@xxxxxxxxxx>
---
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