[PATCH v4 11/19] liveupdate: Add feature header to struct luo_file_set_ser

From: Tarun Sahu

Date: Tue Nov 10 2026 - 00:10:24 EST


Precede struct luo_file_set_ser with struct kho_ser_hdr via
DECLARE_KHO_SER so future file-set metadata features can append fields
to struct luo_file_set_ser without breaking compatibility between
adjacent kernels.

Reserve space for both the session feature header and the file-set
feature header in each session block-set entry, initialize the file-set
feature header in luo_file_freeze(), and validate incoming required
features in luo_file_deserialize() before accessing payload fields.

Signed-off-by: Tarun Sahu <tarunsahu@xxxxxxxxxx>
---
include/linux/kho/abi/luo.h | 15 ++++++++-------
kernel/liveupdate/luo_file.c | 32 ++++++++++++++++++++++----------
kernel/liveupdate/luo_internal.h | 7 ++++---
kernel/liveupdate/luo_session.c | 14 +++++++-------
4 files changed, 41 insertions(+), 27 deletions(-)

diff --git a/include/linux/kho/abi/luo.h b/include/linux/kho/abi/luo.h
index 425c52c494f1..bd19211c64e1 100644
--- a/include/linux/kho/abi/luo.h
+++ b/include/linux/kho/abi/luo.h
@@ -112,21 +112,21 @@ static_assert(!IS_ENABLED(CONFIG_64BIT) ||
* @count: The total number of files that were part of this session during
* serialization. Used for iteration and validation during
* restoration.
+ *
+ * Preceded by &struct kho_ser_hdr.
*/
struct luo_file_set_ser {
u64 files;
u64 count;
};

-static_assert(sizeof(struct luo_file_set_ser) == 16);
-static_assert(!IS_ENABLED(CONFIG_64BIT) ||
- __alignof__(struct luo_file_set_ser) == 8);
+DECLARE_KHO_SER(luo_file_set_ser, 16, 0, 0);

/**
* struct luo_session_ser - Represents the serialized metadata for a LUO session.
- * @name: The unique name of the session, provided by the userspace at
- * the time of session creation.
- * @file_set_ser: Serialized pointer to the files belonging to this session.
+ * @name: The unique name of the session, provided by the userspace at
+ * the time of session creation.
+ * @file_set_fhdr: Serialized pointer to the files belonging to this session.
*
* This structure is used to package session-specific metadata for transfer
* between kernels via Kexec Handover. An array of these structures (one per
@@ -137,7 +137,8 @@ static_assert(!IS_ENABLED(CONFIG_64BIT) ||
*/
struct luo_session_ser {
char name[LIVEUPDATE_SESSION_NAME_LENGTH];
- DECLARE_KHOSER_PTR(file_set_ser, struct luo_file_set_ser *);
+ DECLARE_KHOSER_PTR(file_set_fhdr,
+ DECLARE_KHO_SER_HDR(luo_file_set_ser, *));
};

DECLARE_KHO_SER(luo_session_ser, 72, 0, 0);
diff --git a/kernel/liveupdate/luo_file.c b/kernel/liveupdate/luo_file.c
index a39992da504f..02d09a80d785 100644
--- a/kernel/liveupdate/luo_file.c
+++ b/kernel/liveupdate/luo_file.c
@@ -440,8 +440,8 @@ 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.
+ * @file_set_fhdr: Where to put the serialized file_set.
*
* 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
@@ -472,12 +472,14 @@ static void __luo_file_unfreeze(struct luo_file_set *file_set,
* 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)
+ DECLARE_KHO_SER_HDR(luo_file_set_ser, *file_set_fhdr))
{
+ struct luo_file_set_ser *file_set_ser;
struct luo_file *luo_file;
struct kho_block_set_it it;
int err;

+ kho_ser_init(file_set_fhdr, luo_file_set_ser);
if (!file_set->count)
return 0;

@@ -506,6 +508,7 @@ int luo_file_freeze(struct luo_file_set *file_set,
file_ser->token = luo_file->token;
}

+ file_set_ser = kho_ser_payload(file_set_fhdr, luo_file_set_ser);
file_set_ser->count = file_set->count;
file_set_ser->files = kho_block_set_head_pa(&file_set->block_set);

@@ -519,8 +522,8 @@ 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.
+ * @file_set_fhdr: Serialized file_set.
*
* 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
@@ -534,13 +537,13 @@ int luo_file_freeze(struct luo_file_set *file_set,
* 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)
+ DECLARE_KHO_SER_HDR(luo_file_set_ser, *file_set_fhdr))
{
if (!file_set->count)
return;

__luo_file_unfreeze(file_set, NULL);
- memset(file_set_ser, 0, sizeof(*file_set_ser));
+ memset(file_set_fhdr, 0, kho_ser_size(luo_file_set_ser));
}

/**
@@ -780,8 +783,8 @@ static int luo_file_deserialize_one(struct luo_file_set *file_set,

/**
* luo_file_deserialize - Reconstructs the list of preserved files in the new kernel.
- * @file_set: The incoming file_set to fill with deserialized data.
- * @file_set_ser: Serialized KHO file_set data from the previous kernel.
+ * @file_set: The incoming file_set to fill with deserialized data.
+ * @file_set_fhdr: Serialized KHO file_set data from the previous kernel.
*
* This function is called during the early boot process of the new kernel. It
* takes the raw, contiguous memory block of 'struct luo_file_ser' entries,
@@ -804,12 +807,21 @@ static int luo_file_deserialize_one(struct luo_file_set *file_set,
* Context: Called from session deserialization.
*/
int luo_file_deserialize(struct luo_file_set *file_set,
- struct luo_file_set_ser *file_set_ser)
+ DECLARE_KHO_SER_HDR(luo_file_set_ser, *file_set_fhdr))
{
+ struct luo_file_set_ser *file_set_ser;
struct luo_file_ser *file_ser;
struct kho_block_set_it it;
int err;

+ if (!file_set_fhdr)
+ return -EINVAL;
+
+ err = kho_ser_validate(file_set_fhdr, luo_file_set_ser);
+ if (err)
+ return err;
+
+ file_set_ser = kho_ser_payload(file_set_fhdr, luo_file_set_ser);
if (!file_set_ser->files) {
WARN_ON(file_set_ser->count);
return 0;
diff --git a/kernel/liveupdate/luo_internal.h b/kernel/liveupdate/luo_internal.h
index dac6644bfb18..e22a8cf39d91 100644
--- a/kernel/liveupdate/luo_internal.h
+++ b/kernel/liveupdate/luo_internal.h
@@ -8,6 +8,7 @@
#ifndef _LINUX_LUO_INTERNAL_H
#define _LINUX_LUO_INTERNAL_H

+#include <linux/kho/abi/luo.h>
#include <linux/liveupdate.h>
#include <linux/uaccess.h>
#include <linux/kho_block.h>
@@ -104,14 +105,14 @@ 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);
+ DECLARE_KHO_SER_HDR(luo_file_set_ser, *file_set_fhdr));
void luo_file_unfreeze(struct luo_file_set *file_set,
- struct luo_file_set_ser *file_set_ser);
+ DECLARE_KHO_SER_HDR(luo_file_set_ser, *file_set_fhdr));
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);
int luo_file_deserialize(struct luo_file_set *file_set,
- struct luo_file_set_ser *file_set_ser);
+ DECLARE_KHO_SER_HDR(luo_file_set_ser, *file_set_fhdr));
void luo_file_set_init(struct luo_file_set *file_set);
void luo_file_set_destroy(struct luo_file_set *file_set);

diff --git a/kernel/liveupdate/luo_session.c b/kernel/liveupdate/luo_session.c
index 641bd67ce76e..6513fde3ecfe 100644
--- a/kernel/liveupdate/luo_session.c
+++ b/kernel/liveupdate/luo_session.c
@@ -132,7 +132,7 @@ struct luo_session_global {
};

#define LUO_SESSION_SER_SIZE (kho_ser_size(luo_session_ser) + \
- sizeof(struct luo_file_set_ser))
+ kho_ser_size(luo_file_set_ser))

static struct luo_session_global luo_session_global = {
.incoming = {
@@ -227,7 +227,7 @@ static void luo_session_unfreeze_one(struct luo_session *session,
{
guard(mutex)(&session->mutex);
luo_file_unfreeze(&session->file_set,
- KHOSER_LOAD_PTR(ser->file_set_ser));
+ KHOSER_LOAD_PTR(ser->file_set_fhdr));
}

static int luo_session_freeze_one(struct luo_session *session,
@@ -235,7 +235,7 @@ static int luo_session_freeze_one(struct luo_session *session,
{
guard(mutex)(&session->mutex);
return luo_file_freeze(&session->file_set,
- KHOSER_LOAD_PTR(ser->file_set_ser));
+ KHOSER_LOAD_PTR(ser->file_set_fhdr));
}

static int luo_session_release(struct inode *inodep, struct file *filep)
@@ -560,14 +560,14 @@ int __init luo_session_setup_incoming(u64 sessions_pa)
static struct luo_session_ser *
luo_session_ser_init(DECLARE_KHO_SER_HDR(luo_session_ser, *fhdr))
{
- struct luo_file_set_ser *file_set_ser;
+ DECLARE_KHO_SER_HDR(luo_file_set_ser, *file_set_fhdr);
struct luo_session_ser *ser;

kho_ser_init(fhdr, luo_session_ser);
- file_set_ser = (void *)fhdr + kho_ser_size(luo_session_ser);
+ file_set_fhdr = (void *)fhdr + kho_ser_size(luo_session_ser);

ser = kho_ser_payload(fhdr, luo_session_ser);
- KHOSER_STORE_PTR(ser->file_set_ser, file_set_ser);
+ KHOSER_STORE_PTR(ser->file_set_fhdr, file_set_fhdr);

return ser;
}
@@ -601,7 +601,7 @@ static int luo_session_deserialize_one(struct luo_session_header *sh,

scoped_guard(mutex, &session->mutex) {
err = luo_file_deserialize(&session->file_set,
- KHOSER_LOAD_PTR(ser->file_set_ser));
+ KHOSER_LOAD_PTR(ser->file_set_fhdr));
}
if (err) {
pr_warn("Failed to deserialize files for session [%s] %pe\n",
--
2.56.0.506.g506a7eabc5-goog