All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v6 0/5] liveupdate: serialization safety and race fixes
@ 2026-05-27 20:27 Pasha Tatashin
  2026-05-27 20:27 ` [PATCH v6 1/5] liveupdate: skip serialization for context-preserving kexec Pasha Tatashin
                   ` (5 more replies)
  0 siblings, 6 replies; 9+ messages in thread
From: Pasha Tatashin @ 2026-05-27 20:27 UTC (permalink / raw)
  To: rppt, sourabhjain, jbouron, akpm, error27, bhe, linux-kernel,
	pasha.tatashin, rafael.j.wysocki, piliu, kexec, pratyush,
	skhawaja, graf, mario.limonciello

This series addresses several issues related to the synchronization
between the reboot process and LUO session management.

1. Skip LUO serialization for context-preserving kexec: A
preserve_context kexec returns to the current kernel, which is unrelated
to live update where state is passed to the next kernel. Skipping
serialization avoids unnecessary work and prevents sessions from being
left in a frozen state upon return.

2. Fix TOCTOU race in luo_session_retrieve(): Extend the rwsem lock
scope to prevent a session from being released between lookup and
mutex acquisition.

3. Block session mutations during reboot: During the reboot() syscall,
user processes may still be running concurrently and attempting to
mutate sessions. To prevent this, we introduce luo_session_serialize_rwsem.
All mutation operations (create, retrieve, release, ioctl) hold the
read lock. The serialization process holds the write lock indefinitely
on success, effectively freezing the subsystem.

4. Fix use-after-free in luo_file_unpreserve_files(): Reorder module_put()
to ensure the file handler module remains pinned while its operations
are being accessed during cleanup.

5. Remove unused ser field from struct luo_session: Clean up the
session structure by removing a field that was never utilized.

Tree: git.kernel.org/pub/scm/linux/kernel/git/tatashin/linux.git Branch:
luo-reboot-sync/v6

Changes in v6:
- Added lock hierarchy documentation (Pratyush)
- Collected Reviewed-by from Pratyush Yadav for patches #2, #4, and #5.

Pasha Tatashin (5):
  liveupdate: skip serialization for context-preserving kexec
  liveupdate: fix TOCTOU race in luo_session_retrieve()
  liveupdate: block session mutations during reboot
  liveupdate: fix u-a-f in luo_file_unpreserve_files() and
    luo_file_finish()
  liveupdate: Remove unused ser field from struct luo_session

 kernel/kexec_core.c              |  8 ++--
 kernel/liveupdate/luo_file.c     |  5 ++-
 kernel/liveupdate/luo_internal.h |  2 -
 kernel/liveupdate/luo_session.c  | 67 +++++++++++++++++++++++++++-----
 4 files changed, 66 insertions(+), 16 deletions(-)


base-commit: 3a29a9841f4bfb79840f7d1f8115cc7b25e744e3
-- 
2.53.0



^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH v6 1/5] liveupdate: skip serialization for context-preserving kexec
  2026-05-27 20:27 [PATCH v6 0/5] liveupdate: serialization safety and race fixes Pasha Tatashin
@ 2026-05-27 20:27 ` Pasha Tatashin
  2026-05-27 20:27 ` [PATCH v6 2/5] liveupdate: fix TOCTOU race in luo_session_retrieve() Pasha Tatashin
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 9+ messages in thread
From: Pasha Tatashin @ 2026-05-27 20:27 UTC (permalink / raw)
  To: rppt, sourabhjain, jbouron, akpm, error27, bhe, linux-kernel,
	pasha.tatashin, rafael.j.wysocki, piliu, kexec, pratyush,
	skhawaja, graf, mario.limonciello

A preserve_context kexec returns to the current kernel, which is
unrelated to live update where the state is passed to the next kernel.
Skip liveupdate_reboot() in this case to avoid serialization and prevent
sessions from being left in a frozen state upon return.

Fixes: db8bed8082dc ("kexec: call liveupdate_reboot() before kexec")
Reported-by: Oskar Gerlicz Kowalczuk <oskar@gerlicz.space>
Reviewed-by: Pratyush Yadav (Google) <pratyush@kernel.org>
Acked-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
Signed-off-by: Pasha Tatashin <pasha.tatashin@soleen.com>
---
 kernel/kexec_core.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/kernel/kexec_core.c b/kernel/kexec_core.c
index a43d2da0fe3e..dc770b9a6d05 100644
--- a/kernel/kexec_core.c
+++ b/kernel/kexec_core.c
@@ -1146,9 +1146,11 @@ int kernel_kexec(void)
 		goto Unlock;
 	}
 
-	error = liveupdate_reboot();
-	if (error)
-		goto Unlock;
+	if (!kexec_image->preserve_context) {
+		error = liveupdate_reboot();
+		if (error)
+			goto Unlock;
+	}
 
 #ifdef CONFIG_KEXEC_JUMP
 	if (kexec_image->preserve_context) {
-- 
2.53.0



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v6 2/5] liveupdate: fix TOCTOU race in luo_session_retrieve()
  2026-05-27 20:27 [PATCH v6 0/5] liveupdate: serialization safety and race fixes Pasha Tatashin
  2026-05-27 20:27 ` [PATCH v6 1/5] liveupdate: skip serialization for context-preserving kexec Pasha Tatashin
@ 2026-05-27 20:27 ` Pasha Tatashin
  2026-05-27 20:27 ` [PATCH v6 3/5] liveupdate: block session mutations during reboot Pasha Tatashin
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 9+ messages in thread
From: Pasha Tatashin @ 2026-05-27 20:27 UTC (permalink / raw)
  To: rppt, sourabhjain, jbouron, akpm, error27, bhe, linux-kernel,
	pasha.tatashin, rafael.j.wysocki, piliu, kexec, pratyush,
	skhawaja, graf, mario.limonciello

Extend the scope of the rwsem_read lock in luo_session_retrieve() to
overlap with the acquisition of the session mutex. This prevents a
concurrent thread from releasing and freeing the session between the
lookup and the mutex lock.

Fixes: 0153094d03df ("liveupdate: luo_session: add sessions support")
Acked-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
Reviewed-by: Pratyush Yadav (Google) <pratyush@kernel.org>
Signed-off-by: Pasha Tatashin <pasha.tatashin@soleen.com>
---
 kernel/liveupdate/luo_session.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/kernel/liveupdate/luo_session.c b/kernel/liveupdate/luo_session.c
index 74c39d93d45a..169131642939 100644
--- a/kernel/liveupdate/luo_session.c
+++ b/kernel/liveupdate/luo_session.c
@@ -443,12 +443,11 @@ int luo_session_retrieve(const char *name, struct file **filep)
 	struct luo_session *it;
 	int err;
 
-	scoped_guard(rwsem_read, &sh->rwsem) {
-		list_for_each_entry(it, &sh->list, list) {
-			if (!strncmp(it->name, name, sizeof(it->name))) {
-				session = it;
-				break;
-			}
+	guard(rwsem_read)(&sh->rwsem);
+	list_for_each_entry(it, &sh->list, list) {
+		if (!strncmp(it->name, name, sizeof(it->name))) {
+			session = it;
+			break;
 		}
 	}
 
-- 
2.53.0



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v6 3/5] liveupdate: block session mutations during reboot
  2026-05-27 20:27 [PATCH v6 0/5] liveupdate: serialization safety and race fixes Pasha Tatashin
  2026-05-27 20:27 ` [PATCH v6 1/5] liveupdate: skip serialization for context-preserving kexec Pasha Tatashin
  2026-05-27 20:27 ` [PATCH v6 2/5] liveupdate: fix TOCTOU race in luo_session_retrieve() Pasha Tatashin
@ 2026-05-27 20:27 ` Pasha Tatashin
  2026-05-28 14:20   ` Pratyush Yadav
  2026-05-27 20:27 ` [PATCH v6 4/5] liveupdate: fix u-a-f in luo_file_unpreserve_files() and luo_file_finish() Pasha Tatashin
                   ` (2 subsequent siblings)
  5 siblings, 1 reply; 9+ messages in thread
From: Pasha Tatashin @ 2026-05-27 20:27 UTC (permalink / raw)
  To: rppt, sourabhjain, jbouron, akpm, error27, bhe, linux-kernel,
	pasha.tatashin, rafael.j.wysocki, piliu, kexec, pratyush,
	skhawaja, graf, mario.limonciello

During the reboot() syscall, user processes may still be running
concurrently and attempting to mutate sessions (e.g., creating,
retrieving, or releasing sessions). To prevent this, introduce
luo_session_serialize_rwsem to synchronize mutations with the
serialization process.

All session mutation operations (create, retrieve, release, ioctl) take
the read lock. The serialization process (luo_session_serialize) takes
the write lock and holds it indefinitely on success. This effectively
freezes the LUO session subsystem during the transition to the new
kernel. If serialization fails, the lock is released to allow recovery.

Fixes: 0153094d03df ("liveupdate: luo_session: add sessions support")
Reported-by: Oskar Gerlicz Kowalczuk <oskar@gerlicz.space>
Acked-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
Signed-off-by: Pasha Tatashin <pasha.tatashin@soleen.com>
---
 kernel/liveupdate/luo_session.c | 56 +++++++++++++++++++++++++++++++--
 1 file changed, 53 insertions(+), 3 deletions(-)

diff --git a/kernel/liveupdate/luo_session.c b/kernel/liveupdate/luo_session.c
index 169131642939..c9bdad2e5ae7 100644
--- a/kernel/liveupdate/luo_session.c
+++ b/kernel/liveupdate/luo_session.c
@@ -46,6 +46,38 @@
  * 4.  Retrieval: A userspace agent in the new kernel can then call
  *     `luo_session_retrieve()` with a session name to get a new file
  *     descriptor and access the preserved state.
+ *
+ * Locking:
+ *
+ * The LUO session subsystem uses a three-tier locking hierarchy to ensure thread
+ * safety and prevent deadlocks during concurrent session mutations and kexec
+ * serialization:
+ *
+ * 1. `luo_session_serialize_rwsem` (global rwsem):
+ *    Protects session mutations (creation, retrieval, release, and ioctls)
+ *    against the serialization process during reboot.
+ *
+ *    - Readers: Taken by any path modifying or accessing session state (e.g.,
+ *      `luo_session_create()`, `luo_session_retrieve()`, `luo_session_release()`,
+ *      and `luo_session_ioctl()`).
+ *    - Writer: Taken by the serialization process (`luo_session_serialize()`)
+ *      during reboot. On success, the write lock is held indefinitely to freeze
+ *      the subsystem. On failure, it is released to allow recovery.
+ *
+ * 2. `luo_session_header->rwsem` (per-list rwsem):
+ *    Synchronizes list-level operations for the incoming and outgoing session headers.
+ *
+ *    - Writer: Taken during list mutation operations (inserting or removing a
+ *      session from the list).
+ *    - Reader: Taken when traversing the list (e.g., retrieving a session by name).
+ *
+ * 3. `luo_session->mutex` (per-session mutex):
+ *    Protects the internal state and file sets of an individual session. It is
+ *    acquired during per-session operations such as preserving, retrieving,
+ *    or freezing files.
+ *
+ * Lock Hierarchy:
+ *   `luo_session_serialize_rwsem` -> `luo_session_header->rwsem` -> `luo_session->mutex`
  */
 
 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
@@ -75,6 +107,13 @@
 		sizeof(struct luo_session_header_ser)) /		\
 		sizeof(struct luo_session_ser))
 
+/*
+ * Protects session mutations during serialization. All session mutation
+ * operations must hold the read lock. The serialization process holds the write
+ * lock indefinitely on success to block all concurrent and future mutations.
+ */
+static DECLARE_RWSEM(luo_session_serialize_rwsem);
+
 /**
  * struct luo_session_header - Header struct for managing LUO sessions.
  * @count:      The number of sessions currently tracked in the @list.
@@ -205,6 +244,7 @@ static int luo_session_release(struct inode *inodep, struct file *filep)
 	struct luo_session *session = filep->private_data;
 	struct luo_session_header *sh;
 
+	guard(rwsem_read)(&luo_session_serialize_rwsem);
 	/* If retrieved is set, it means this session is from incoming list */
 	if (session->retrieved) {
 		int err = luo_session_finish_one(session);
@@ -382,6 +422,7 @@ static long luo_session_ioctl(struct file *filep, unsigned int cmd,
 	if (ret)
 		return ret;
 
+	guard(rwsem_read)(&luo_session_serialize_rwsem);
 	return op->execute(session, &ucmd);
 }
 
@@ -417,14 +458,17 @@ int luo_session_create(const char *name, struct file **filep)
 	if (IS_ERR(session))
 		return PTR_ERR(session);
 
+	down_read(&luo_session_serialize_rwsem);
 	err = luo_session_insert(&luo_session_global.outgoing, session);
 	if (err)
 		goto err_free;
 
-	scoped_guard(mutex, &session->mutex)
-		err = luo_session_getfile(session, filep);
+	mutex_lock(&session->mutex);
+	err = luo_session_getfile(session, filep);
+	mutex_unlock(&session->mutex);
 	if (err)
 		goto err_remove;
+	up_read(&luo_session_serialize_rwsem);
 
 	return 0;
 
@@ -432,6 +476,7 @@ int luo_session_create(const char *name, struct file **filep)
 	luo_session_remove(&luo_session_global.outgoing, session);
 err_free:
 	luo_session_free(session);
+	up_read(&luo_session_serialize_rwsem);
 
 	return err;
 }
@@ -443,6 +488,7 @@ int luo_session_retrieve(const char *name, struct file **filep)
 	struct luo_session *it;
 	int err;
 
+	guard(rwsem_read)(&luo_session_serialize_rwsem);
 	guard(rwsem_read)(&sh->rwsem);
 	list_for_each_entry(it, &sh->list, list) {
 		if (!strncmp(it->name, name, sizeof(it->name))) {
@@ -615,7 +661,8 @@ int luo_session_serialize(void)
 	int i = 0;
 	int err;
 
-	guard(rwsem_write)(&sh->rwsem);
+	down_write(&luo_session_serialize_rwsem);
+	down_write(&sh->rwsem);
 	list_for_each_entry(session, &sh->list, list) {
 		err = luo_session_freeze_one(session, &sh->ser[i]);
 		if (err)
@@ -626,6 +673,7 @@ int luo_session_serialize(void)
 		i++;
 	}
 	sh->header_ser->count = sh->count;
+	up_write(&sh->rwsem);
 
 	return 0;
 
@@ -635,6 +683,8 @@ int luo_session_serialize(void)
 		luo_session_unfreeze_one(session, &sh->ser[i]);
 		memset(sh->ser[i].name, 0, sizeof(sh->ser[i].name));
 	}
+	up_write(&sh->rwsem);
+	up_write(&luo_session_serialize_rwsem);
 
 	return err;
 }
-- 
2.53.0



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v6 4/5] liveupdate: fix u-a-f in luo_file_unpreserve_files() and luo_file_finish()
  2026-05-27 20:27 [PATCH v6 0/5] liveupdate: serialization safety and race fixes Pasha Tatashin
                   ` (2 preceding siblings ...)
  2026-05-27 20:27 ` [PATCH v6 3/5] liveupdate: block session mutations during reboot Pasha Tatashin
@ 2026-05-27 20:27 ` Pasha Tatashin
  2026-05-27 20:27 ` [PATCH v6 5/5] liveupdate: Remove unused ser field from struct luo_session Pasha Tatashin
  2026-05-28 15:08 ` [PATCH v6 0/5] liveupdate: serialization safety and race fixes Mike Rapoport
  5 siblings, 0 replies; 9+ messages in thread
From: Pasha Tatashin @ 2026-05-27 20:27 UTC (permalink / raw)
  To: rppt, sourabhjain, jbouron, akpm, error27, bhe, linux-kernel,
	pasha.tatashin, rafael.j.wysocki, piliu, kexec, pratyush,
	skhawaja, graf, mario.limonciello

In luo_file_unpreserve_files() and luo_file_finish(), reorder
module_put() and xa_erase() to ensure the file handler module remains
pinned while its operations are being accessed.

Specifically, luo_get_id() dereferences fh->ops->get_id, so the module
reference must be held until after xa_erase() (which calls luo_get_id)
completes.

For luo_file_finish(), this requires moving the module_put() call out of
the luo_file_finish_one() helper and into the main loop of
luo_file_finish() itself.

Fixes: 00d0b372374f ("liveupdate: prevent double management of files")
Acked-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
Reviewed-by: Pratyush Yadav (Google) <pratyush@kernel.org>
Signed-off-by: Pasha Tatashin <pasha.tatashin@soleen.com>
---
 kernel/liveupdate/luo_file.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/kernel/liveupdate/luo_file.c b/kernel/liveupdate/luo_file.c
index a0a419085e28..208987502f73 100644
--- a/kernel/liveupdate/luo_file.c
+++ b/kernel/liveupdate/luo_file.c
@@ -385,10 +385,11 @@ void luo_file_unpreserve_files(struct luo_file_set *file_set)
 		args.private_data = luo_file->private_data;
 		luo_file->fh->ops->unpreserve(&args);
 		luo_flb_file_unpreserve(luo_file->fh);
-		module_put(luo_file->fh->ops->owner);
 
 		xa_erase(&luo_preserved_files,
 			 luo_get_id(luo_file->fh, luo_file->file));
+		module_put(luo_file->fh->ops->owner);
+
 		list_del(&luo_file->list);
 		file_set->count--;
 
@@ -677,7 +678,6 @@ static void luo_file_finish_one(struct luo_file_set *file_set,
 
 	luo_file->fh->ops->finish(&args);
 	luo_flb_file_finish(luo_file->fh);
-	module_put(luo_file->fh->ops->owner);
 }
 
 /**
@@ -738,6 +738,7 @@ int luo_file_finish(struct luo_file_set *file_set)
 				 luo_get_id(luo_file->fh, luo_file->file));
 			fput(luo_file->file);
 		}
+		module_put(luo_file->fh->ops->owner);
 		list_del(&luo_file->list);
 		file_set->count--;
 		mutex_destroy(&luo_file->mutex);
-- 
2.53.0



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v6 5/5] liveupdate: Remove unused ser field from struct luo_session
  2026-05-27 20:27 [PATCH v6 0/5] liveupdate: serialization safety and race fixes Pasha Tatashin
                   ` (3 preceding siblings ...)
  2026-05-27 20:27 ` [PATCH v6 4/5] liveupdate: fix u-a-f in luo_file_unpreserve_files() and luo_file_finish() Pasha Tatashin
@ 2026-05-27 20:27 ` Pasha Tatashin
  2026-05-28 15:08 ` [PATCH v6 0/5] liveupdate: serialization safety and race fixes Mike Rapoport
  5 siblings, 0 replies; 9+ messages in thread
From: Pasha Tatashin @ 2026-05-27 20:27 UTC (permalink / raw)
  To: rppt, sourabhjain, jbouron, akpm, error27, bhe, linux-kernel,
	pasha.tatashin, rafael.j.wysocki, piliu, kexec, pratyush,
	skhawaja, graf, mario.limonciello

The ser field in struct luo_session was intended to point to the
serialized data for a session, but it was never actually utilized in the
implementation. All serialization and deserialization logic consistently
uses the pointers maintained in struct luo_session_header.

Remove the dead field to clean up the structure.

Acked-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
Reviewed-by: Pratyush Yadav (Google) <pratyush@kernel.org>
Signed-off-by: Pasha Tatashin <pasha.tatashin@soleen.com>
---
 kernel/liveupdate/luo_internal.h | 2 --
 1 file changed, 2 deletions(-)

diff --git a/kernel/liveupdate/luo_internal.h b/kernel/liveupdate/luo_internal.h
index 875844d7a41d..dd53d4a7277e 100644
--- a/kernel/liveupdate/luo_internal.h
+++ b/kernel/liveupdate/luo_internal.h
@@ -59,7 +59,6 @@ struct luo_file_set {
  * struct luo_session - Represents an active or incoming Live Update session.
  * @name:       A unique name for this session, used for identification and
  *              retrieval.
- * @ser:        Pointer to the serialized data for this session.
  * @list:       A list_head member used to link this session into a global list
  *              of either outgoing (to be preserved) or incoming (restored from
  *              previous kernel) sessions.
@@ -70,7 +69,6 @@ struct luo_file_set {
  */
 struct luo_session {
 	char name[LIVEUPDATE_SESSION_NAME_LENGTH];
-	struct luo_session_ser *ser;
 	struct list_head list;
 	bool retrieved;
 	struct luo_file_set file_set;
-- 
2.53.0



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH v6 3/5] liveupdate: block session mutations during reboot
  2026-05-27 20:27 ` [PATCH v6 3/5] liveupdate: block session mutations during reboot Pasha Tatashin
@ 2026-05-28 14:20   ` Pratyush Yadav
  2026-05-28 14:51     ` Mike Rapoport
  0 siblings, 1 reply; 9+ messages in thread
From: Pratyush Yadav @ 2026-05-28 14:20 UTC (permalink / raw)
  To: Pasha Tatashin
  Cc: rppt, sourabhjain, jbouron, akpm, error27, bhe, linux-kernel,
	rafael.j.wysocki, piliu, kexec, pratyush, skhawaja, graf,
	mario.limonciello

On Wed, May 27 2026, Pasha Tatashin wrote:

> During the reboot() syscall, user processes may still be running
> concurrently and attempting to mutate sessions (e.g., creating,
> retrieving, or releasing sessions). To prevent this, introduce
> luo_session_serialize_rwsem to synchronize mutations with the
> serialization process.
>
> All session mutation operations (create, retrieve, release, ioctl) take
> the read lock. The serialization process (luo_session_serialize) takes
> the write lock and holds it indefinitely on success. This effectively
> freezes the LUO session subsystem during the transition to the new
> kernel. If serialization fails, the lock is released to allow recovery.
>
> Fixes: 0153094d03df ("liveupdate: luo_session: add sessions support")
> Reported-by: Oskar Gerlicz Kowalczuk <oskar@gerlicz.space>
> Acked-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
> Signed-off-by: Pasha Tatashin <pasha.tatashin@soleen.com>
> ---
>  kernel/liveupdate/luo_session.c | 56 +++++++++++++++++++++++++++++++--
>  1 file changed, 53 insertions(+), 3 deletions(-)
>
> diff --git a/kernel/liveupdate/luo_session.c b/kernel/liveupdate/luo_session.c
> index 169131642939..c9bdad2e5ae7 100644
> --- a/kernel/liveupdate/luo_session.c
> +++ b/kernel/liveupdate/luo_session.c
> @@ -46,6 +46,38 @@
>   * 4.  Retrieval: A userspace agent in the new kernel can then call
>   *     `luo_session_retrieve()` with a session name to get a new file
>   *     descriptor and access the preserved state.
> + *
> + * Locking:
> + *
> + * The LUO session subsystem uses a three-tier locking hierarchy to ensure thread
> + * safety and prevent deadlocks during concurrent session mutations and kexec
> + * serialization:
> + *
> + * 1. `luo_session_serialize_rwsem` (global rwsem):
> + *    Protects session mutations (creation, retrieval, release, and ioctls)
> + *    against the serialization process during reboot.
> + *
> + *    - Readers: Taken by any path modifying or accessing session state (e.g.,
> + *      `luo_session_create()`, `luo_session_retrieve()`, `luo_session_release()`,
> + *      and `luo_session_ioctl()`).
> + *    - Writer: Taken by the serialization process (`luo_session_serialize()`)
> + *      during reboot. On success, the write lock is held indefinitely to freeze
> + *      the subsystem. On failure, it is released to allow recovery.
> + *
> + * 2. `luo_session_header->rwsem` (per-list rwsem):
> + *    Synchronizes list-level operations for the incoming and outgoing session headers.
> + *
> + *    - Writer: Taken during list mutation operations (inserting or removing a
> + *      session from the list).
> + *    - Reader: Taken when traversing the list (e.g., retrieving a session by name).
> + *
> + * 3. `luo_session->mutex` (per-session mutex):
> + *    Protects the internal state and file sets of an individual session. It is
> + *    acquired during per-session operations such as preserving, retrieving,
> + *    or freezing files.
> + *
> + * Lock Hierarchy:
> + *   `luo_session_serialize_rwsem` -> `luo_session_header->rwsem` -> `luo_session->mutex`
>   */
>  
>  #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
> @@ -75,6 +107,13 @@
>  		sizeof(struct luo_session_header_ser)) /		\
>  		sizeof(struct luo_session_ser))
>  
> +/*
> + * Protects session mutations during serialization. All session mutation
> + * operations must hold the read lock. The serialization process holds the write
> + * lock indefinitely on success to block all concurrent and future mutations.
> + */

Nit: this comment is redundant now. I guess you can remove this when
applying.

Reviewed-by: Pratyush Yadav (Google) <pratyush@kernel.org>

> +static DECLARE_RWSEM(luo_session_serialize_rwsem);
> +
>  /**
>   * struct luo_session_header - Header struct for managing LUO sessions.
>   * @count:      The number of sessions currently tracked in the @list.
[...]

-- 
Regards,
Pratyush Yadav


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v6 3/5] liveupdate: block session mutations during reboot
  2026-05-28 14:20   ` Pratyush Yadav
@ 2026-05-28 14:51     ` Mike Rapoport
  0 siblings, 0 replies; 9+ messages in thread
From: Mike Rapoport @ 2026-05-28 14:51 UTC (permalink / raw)
  To: Pratyush Yadav
  Cc: Pasha Tatashin, sourabhjain, jbouron, akpm, error27, bhe,
	linux-kernel, rafael.j.wysocki, piliu, kexec, skhawaja, graf,
	mario.limonciello

On Thu, May 28, 2026 at 04:20:53PM +0200, Pratyush Yadav wrote:
> On Wed, May 27 2026, Pasha Tatashin wrote:
> 
> > During the reboot() syscall, user processes may still be running
> > concurrently and attempting to mutate sessions (e.g., creating,
> > retrieving, or releasing sessions). To prevent this, introduce
> > luo_session_serialize_rwsem to synchronize mutations with the
> > serialization process.
> >
> > All session mutation operations (create, retrieve, release, ioctl) take
> > the read lock. The serialization process (luo_session_serialize) takes
> > the write lock and holds it indefinitely on success. This effectively
> > freezes the LUO session subsystem during the transition to the new
> > kernel. If serialization fails, the lock is released to allow recovery.
> >
> > Fixes: 0153094d03df ("liveupdate: luo_session: add sessions support")
> > Reported-by: Oskar Gerlicz Kowalczuk <oskar@gerlicz.space>
> > Acked-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
> > Signed-off-by: Pasha Tatashin <pasha.tatashin@soleen.com>
> > ---
> >  kernel/liveupdate/luo_session.c | 56 +++++++++++++++++++++++++++++++--
> >  1 file changed, 53 insertions(+), 3 deletions(-)
> >  
> > +/*
> > + * Protects session mutations during serialization. All session mutation
> > + * operations must hold the read lock. The serialization process holds the write
> > + * lock indefinitely on success to block all concurrent and future mutations.
> > + */
> 
> Nit: this comment is redundant now. I guess you can remove this when
> applying.

Done :)
 
> Reviewed-by: Pratyush Yadav (Google) <pratyush@kernel.org>
> 
> > +static DECLARE_RWSEM(luo_session_serialize_rwsem);
> > +
> >  /**
> >   * struct luo_session_header - Header struct for managing LUO sessions.
> >   * @count:      The number of sessions currently tracked in the @list.
> [...]
> 
> -- 
> Regards,
> Pratyush Yadav

-- 
Sincerely yours,
Mike.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v6 0/5] liveupdate: serialization safety and race fixes
  2026-05-27 20:27 [PATCH v6 0/5] liveupdate: serialization safety and race fixes Pasha Tatashin
                   ` (4 preceding siblings ...)
  2026-05-27 20:27 ` [PATCH v6 5/5] liveupdate: Remove unused ser field from struct luo_session Pasha Tatashin
@ 2026-05-28 15:08 ` Mike Rapoport
  5 siblings, 0 replies; 9+ messages in thread
From: Mike Rapoport @ 2026-05-28 15:08 UTC (permalink / raw)
  To: sourabhjain, jbouron, akpm, error27, bhe, linux-kernel,
	rafael.j.wysocki, piliu, kexec, pratyush, skhawaja, graf,
	mario.limonciello, Pasha Tatashin
  Cc: Mike Rapoport

From: Mike Rapoport (Microsoft) <rppt@kernel.org>

On Wed, 27 May 2026 20:27:32 +0000, Pasha Tatashin wrote:
> This series addresses several issues related to the synchronization
> between the reboot process and LUO session management.
> 
> 1. Skip LUO serialization for context-preserving kexec: A
> preserve_context kexec returns to the current kernel, which is unrelated
> to live update where state is passed to the next kernel. Skipping
> serialization avoids unnecessary work and prevents sessions from being
> left in a frozen state upon return.
> 
> [...]

Applied to next branch of liveupdate/linux.git tree, thanks!

[1/5] liveupdate: skip serialization for context-preserving kexec
      commit: ef4448795cf193b2828019978d872bc0d301abe4
[2/5] liveupdate: fix TOCTOU race in luo_session_retrieve()
      commit: aedeca39112a2bee13e54097fbb98896010f375f
[3/5] liveupdate: block session mutations during reboot
      commit: 6f070471ce4fc9084165b77bfd7457ef85dc8c8c
[4/5] liveupdate: fix u-a-f in luo_file_unpreserve_files() and luo_file_finish()
      commit: 051c2ed7b42077c511654261f5efb52ab368817f
[5/5] liveupdate: Remove unused ser field from struct luo_session
      commit: 5428435567cbe06c19914592fc22ca23c9ca1de5

tree: https://git.kernel.org/pub/scm/linux/kernel/git/liveupdate/linux
branch: next

--
Sincerely yours,
Mike.



^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2026-05-28 15:08 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-27 20:27 [PATCH v6 0/5] liveupdate: serialization safety and race fixes Pasha Tatashin
2026-05-27 20:27 ` [PATCH v6 1/5] liveupdate: skip serialization for context-preserving kexec Pasha Tatashin
2026-05-27 20:27 ` [PATCH v6 2/5] liveupdate: fix TOCTOU race in luo_session_retrieve() Pasha Tatashin
2026-05-27 20:27 ` [PATCH v6 3/5] liveupdate: block session mutations during reboot Pasha Tatashin
2026-05-28 14:20   ` Pratyush Yadav
2026-05-28 14:51     ` Mike Rapoport
2026-05-27 20:27 ` [PATCH v6 4/5] liveupdate: fix u-a-f in luo_file_unpreserve_files() and luo_file_finish() Pasha Tatashin
2026-05-27 20:27 ` [PATCH v6 5/5] liveupdate: Remove unused ser field from struct luo_session Pasha Tatashin
2026-05-28 15:08 ` [PATCH v6 0/5] liveupdate: serialization safety and race fixes Mike Rapoport

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.