Skip to contentSkip to conversation

liveupdate: check for duplicate session before growing block set

PATCH Applied Christian Aurich Zanettini Martins 5 participants 5 messages Nov 3

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 liveupdate: check for duplicate session before growing block set

luo_session_insert() grows the outgoing block set before checking for a duplicate session name. On -EEXIST the new block stays in the set.

If the session count is an exact multiple of the per-block capacity (51 with 4K pages), that block stays empty. It is serialized with count 0, which kho_block_set_restore() rejects in the next kernel:

luo: Block contains invalid entry count: 0

  Kernel panic - not syncing: The incoming tree failed to initialize properly [-EINVAL], disabling live update

Check for the duplicate before growing the block set, as luo_preserve_file() does with the token.

Fixes 2a441a14c2c0 ("liveupdate: Remove limit on the number of sessions")

---

Notes:
Tested in QEMU: create N sessions, retry "sess-0" to get -EEXIST, then kexec and retrieve them. Unpatched, the second kernel panics for N=51 and N=102; patched, N=1, 51, 52, 102 and 153 all come back.

Based on v7.4-rc1.

 kernel/liveupdate/luo_session.c | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)
kernel/liveupdate/luo_session.c +11 -10
index f48e9a4185f9..74bc66929f4b 100644
@@ -176,16 +176,6 @@ static int luo_session_insert(struct luo_session_header *sh,
 
 	guard(rwsem_write)(&sh->rwsem);
 
-	/*
-	 * For outgoing we should make sure there is room in serialization array
-	 * for new session.
-	 */
-	if (sh == &luo_session_global.outgoing) {
-		err = kho_block_set_grow(&sh->block_set, sh->count + 1);
-		if (err)
-			return err;
-	}
-
 	/*
 	 * For small number of sessions this loop won't hurt performance
 	 * but if we ever start using a lot of sessions, this might
@@ -196,6 +186,17 @@ static int luo_session_insert(struct luo_session_header *sh,
 		if (!strncmp(it->name, session->name, sizeof(it->name)))
 			return -EEXIST;
 	}
+
+	/*
+	 * For outgoing we should make sure there is room in serialization array
+	 * for new session.
+	 */
+	if (sh == &luo_session_global.outgoing) {
+		err = kho_block_set_grow(&sh->block_set, sh->count + 1);
+		if (err)
+			return err;
+	}
+
 	list_add_tail(&session->list, &sh->list);
 	sh->count++;
 

base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4

Signature · 1 line
2.43.0
#1 lore raw
Sashiko has reviewed this patch and found no issues.
Quoted 8 lines

luo_session_insert() grows the outgoing block set before checking for a duplicate session name. On -EEXIST the new block stays in the set.

If the session count is an exact multiple of the per-block capacity (51 with 4K pages), that block stays empty. It is serialized with count 0, which kho_block_set_restore() rejects in the next kernel:

luo: Block contains invalid entry count: 0

Quoted 8 lines
  Kernel panic - not syncing: The incoming tree failed to initialize properly [-EINVAL], disabling live update

Check for the duplicate before growing the block set, as luo_preserve_file() does with the token.

Fixes 2a441a14c2c0 ("liveupdate: Remove limit on the number of sessions")

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
maintainer Reviewed-by on v1 1/1
#2 lore raw
In reply to Christian Aurich Zanettini Martins
Quoted 8 lines · Christian Aurich Zanettini Martins

luo_session_insert() grows the outgoing block set before checking for a duplicate session name. On -EEXIST the new block stays in the set.

If the session count is an exact multiple of the per-block capacity (51 with 4K pages), that block stays empty. It is serialized with count 0, which kho_block_set_restore() rejects in the next kernel:

luo: Block contains invalid entry count: 0

Quoted 8 lines
  Kernel panic - not syncing: The incoming tree failed to initialize properly [-EINVAL], disabling live update

Check for the duplicate before growing the block set, as luo_preserve_file() does with the token.

Fixes 2a441a14c2c0 ("liveupdate: Remove limit on the number of sessions")

[...]

Signature · 2 lines
Regards,
Pratyush Yadav
maintainer Applied
#3 lore raw
In reply to Christian Aurich Zanettini Martins

From: Mike Rapoport (Microsoft) <[email protected]>

Quoted 8 lines · Christian Aurich Zanettini Martins

luo_session_insert() grows the outgoing block set before checking for a duplicate session name. On -EEXIST the new block stays in the set.

If the session count is an exact multiple of the per-block capacity (51 with 4K pages), that block stays empty. It is serialized with count 0, which kho_block_set_restore() rejects in the next kernel:

[...]

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

[1/1] liveupdate: check for duplicate session before growing block set

      commit: 7d4282ec2d3bfd5e7959bbd2663936a29c45f609

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

--
Sincerely yours,
Mike.

maintainer Reviewed-by on v1 1/1
#4 lore raw
In reply to Christian Aurich Zanettini Martins
Quoted 54 lines · Christian Aurich Zanettini Martins

luo_session_insert() grows the outgoing block set before checking for a duplicate session name. On -EEXIST the new block stays in the set.

If the session count is an exact multiple of the per-block capacity (51 with 4K pages), that block stays empty. It is serialized with count 0, which kho_block_set_restore() rejects in the next kernel:

luo: Block contains invalid entry count: 0

  Kernel panic - not syncing: The incoming tree failed to initialize properly [-EINVAL], disabling live update

Check for the duplicate before growing the block set, as luo_preserve_file() does with the token.

Fixes 2a441a14c2c0 ("liveupdate: Remove limit on the number of sessions")

---

Notes:
Tested in QEMU: create N sessions, retry "sess-0" to get -EEXIST, then kexec and retrieve them. Unpatched, the second kernel panics for N=51 and N=102; patched, N=1, 51, 52, 102 and 153 all come back.

Based on v7.4-rc1.

 kernel/liveupdate/luo_session.c | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)
kernel/liveupdate/luo_session.c +1 -10
index f48e9a4185f9..74bc66929f4b 100644
@@ -176,16 +176,6 @@ static int luo_session_insert(struct luo_session_header *sh,
 
 	guard(rwsem_write)(&sh->rwsem);
 
-	/*
-	 * For outgoing we should make sure there is room in serialization array
-	 * for new session.
-	 */
-	if (sh == &luo_session_global.outgoing) {
-		err = kho_block_set_grow(&sh->block_set, sh->count + 1);
-		if (err)
-			return err;
-	}
-
 	/*
 	 * For small number of sessions this loop won't hurt performance
 	 * but if we ever start using a lot of sessions, this might
@@ -196,6 +186,17 @@ static int luo_session_insert(struct luo_session_header *sh,
 		if (!strncmp(it->name, session->name, sizeof(it->name)))
 			return -EEXIST;
 	}
+

kernel/liveupdate/luo_session.c static int luo_session_insert(struct luo_session_header *sh, · line 199

Quoted 10 lines
kernel/liveupdate/luo_session.c +10 -0
+	/*
+	 * For outgoing we should make sure there is room in serialization array
+	 * for new session.
+	 */
+	if (sh == &luo_session_global.outgoing) {
+		err = kho_block_set_grow(&sh->block_set, sh->count + 1);
+		if (err)
+			return err;
+	}
+