[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20260130145122.368748-2-me@linux.beauty>
Date: Fri, 30 Jan 2026 22:51:17 +0800
From: Li Chen <me@...ux.beauty>
To: Pasha Tatashin <pasha.tatashin@...een.com>,
Mike Rapoport <rppt@...nel.org>,
Pratyush Yadav <pratyush@...nel.org>,
linux-kernel@...r.kernel.org
Cc: Li Chen <me@...ux.beauty>
Subject: [PATCH v1 1/3] liveupdate: track post-kexec restore window
A kexec-based live update introduces a window after the new kernel boots
where userspace needs to retrieve and restore preserved sessions.
Provide liveupdate_restore_in_progress() backed by a counter of incoming
sessions left, and make session finishing idempotent to avoid double
finish paths causing counter underflow.
Signed-off-by: Li Chen <me@...ux.beauty>
---
include/linux/liveupdate.h | 11 +++++++++
kernel/liveupdate/luo_core.c | 2 ++
kernel/liveupdate/luo_internal.h | 4 ++++
kernel/liveupdate/luo_session.c | 41 +++++++++++++++++++++++++++++++-
4 files changed, 57 insertions(+), 1 deletion(-)
diff --git a/include/linux/liveupdate.h b/include/linux/liveupdate.h
index ed81e7b31a9f..406a6e2dd4a1 100644
--- a/include/linux/liveupdate.h
+++ b/include/linux/liveupdate.h
@@ -217,6 +217,12 @@ struct liveupdate_flb {
/* Return true if live update orchestrator is enabled */
bool liveupdate_enabled(void);
+/*
+ * Return true during a kexec-based live update boot while userspace is still
+ * restoring preserved sessions/resources.
+ */
+bool liveupdate_restore_in_progress(void);
+
/* Called during kexec to tell LUO that entered into reboot */
int liveupdate_reboot(void);
@@ -238,6 +244,11 @@ static inline bool liveupdate_enabled(void)
return false;
}
+static inline bool liveupdate_restore_in_progress(void)
+{
+ return false;
+}
+
static inline int liveupdate_reboot(void)
{
return 0;
diff --git a/kernel/liveupdate/luo_core.c b/kernel/liveupdate/luo_core.c
index 7a9ef16b37d8..19c91843fbdb 100644
--- a/kernel/liveupdate/luo_core.c
+++ b/kernel/liveupdate/luo_core.c
@@ -128,6 +128,8 @@ static int __init luo_early_startup(void)
if (err)
return err;
+ luo_session_restore_window_init();
+
err = luo_flb_setup_incoming(luo_global.fdt_in);
return err;
diff --git a/kernel/liveupdate/luo_internal.h b/kernel/liveupdate/luo_internal.h
index 6115d6a4054d..8aa4c5b0101b 100644
--- a/kernel/liveupdate/luo_internal.h
+++ b/kernel/liveupdate/luo_internal.h
@@ -72,6 +72,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.
+ * @finished: A boolean flag indicating whether this session has been
+ * successfully finished in the new kernel.
* @file_set: A set of files that belong to this session.
* @mutex: protects fields in the luo_session.
*/
@@ -80,6 +82,7 @@ struct luo_session {
struct luo_session_ser *ser;
struct list_head list;
bool retrieved;
+ bool finished;
struct luo_file_set file_set;
struct mutex mutex;
};
@@ -88,6 +91,7 @@ int luo_session_create(const char *name, struct file **filep);
int luo_session_retrieve(const char *name, struct file **filep);
int __init luo_session_setup_outgoing(void *fdt);
int __init luo_session_setup_incoming(void *fdt);
+void __init luo_session_restore_window_init(void);
int luo_session_serialize(void);
int luo_session_deserialize(void);
bool luo_session_quiesce(void);
diff --git a/kernel/liveupdate/luo_session.c b/kernel/liveupdate/luo_session.c
index dbdbc3bd7929..e1d1ab795c40 100644
--- a/kernel/liveupdate/luo_session.c
+++ b/kernel/liveupdate/luo_session.c
@@ -50,6 +50,7 @@
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+#include <linux/atomic.h>
#include <linux/anon_inodes.h>
#include <linux/cleanup.h>
#include <linux/err.h>
@@ -117,6 +118,31 @@ static struct luo_session_global luo_session_global = {
},
};
+static atomic_long_t liveupdate_incoming_sessions_left = ATOMIC_LONG_INIT(0);
+
+bool liveupdate_restore_in_progress(void)
+{
+ return atomic_long_read(&liveupdate_incoming_sessions_left) > 0;
+}
+
+void __init luo_session_restore_window_init(void)
+{
+ struct luo_session_header *sh = &luo_session_global.incoming;
+ u64 count;
+
+ if (!sh->active)
+ return;
+
+ count = sh->header_ser->count;
+ if (count > LUO_SESSION_MAX) {
+ pr_warn("incoming session count %llu exceeds max %lu\n",
+ count, LUO_SESSION_MAX);
+ count = LUO_SESSION_MAX;
+ }
+
+ atomic_long_set(&liveupdate_incoming_sessions_left, (long)count);
+}
+
static struct luo_session *luo_session_alloc(const char *name)
{
struct luo_session *session = kzalloc(sizeof(*session), GFP_KERNEL);
@@ -182,8 +208,21 @@ static void luo_session_remove(struct luo_session_header *sh,
static int luo_session_finish_one(struct luo_session *session)
{
+ int err;
+
guard(mutex)(&session->mutex);
- return luo_file_finish(&session->file_set);
+ if (session->finished)
+ return 0;
+
+ err = luo_file_finish(&session->file_set);
+ if (err)
+ return err;
+
+ session->finished = true;
+ if (session->retrieved)
+ atomic_long_dec(&liveupdate_incoming_sessions_left);
+
+ return 0;
}
static void luo_session_unfreeze_one(struct luo_session *session,
--
2.52.0
Powered by blists - more mailing lists