mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Li Chen <me@linux.beauty>
To: Pasha Tatashin <pasha.tatashin@soleen.com>,
	Mike Rapoport <rppt@kernel.org>,
	Pratyush Yadav <pratyush@kernel.org>,
	linux-kernel@vger.kernel.org
Cc: Li Chen <me@linux.beauty>
Subject: [PATCH v1 1/3] liveupdate: track post-kexec restore window
Date: Fri, 30 Jan 2026 22:51:17 +0800	[thread overview]
Message-ID: <20260130145122.368748-2-me@linux.beauty> (raw)
In-Reply-To: <20260130145122.368748-1-me@linux.beauty>

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@linux.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


  reply	other threads:[~2026-01-30 14:52 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-30 14:51 [PATCH v1 0/3] liveupdate: suppress TCP RST during " Li Chen
2026-01-30 14:51 ` Li Chen [this message]
2026-01-30 14:51 ` [PATCH v1 2/3] liveupdate: bound and control " Li Chen
2026-01-30 14:51 ` [PATCH v1 3/3] liveupdate: suppress TCP RST during " Li Chen
2026-01-31  1:05   ` Jakub Kicinski
2026-02-01  1:44     ` Li Chen
2026-02-03  0:53       ` Jakub Kicinski
2026-02-03  3:15         ` Li Chen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260130145122.368748-2-me@linux.beauty \
    --to=me@linux.beauty \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pasha.tatashin@soleen.com \
    --cc=pratyush@kernel.org \
    --cc=rppt@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®