public inbox for linux-mm@kvack.org
 help / color / mirror / Atom feed
* [PATCH v2 0/2] liveupdate: prevent double preservation
@ 2026-03-23 20:31 Pasha Tatashin
  2026-03-23 20:31 ` [PATCH v2 1/2] liveupdate: prevent double management of files Pasha Tatashin
  2026-03-23 20:31 ` [PATCH v2 2/2] selftests: liveupdate: add test for double preservation Pasha Tatashin
  0 siblings, 2 replies; 9+ messages in thread
From: Pasha Tatashin @ 2026-03-23 20:31 UTC (permalink / raw)
  To: linux-kselftest, rppt, shuah, akpm, linux-mm, linux-kernel,
	pasha.tatashin, dmatlack, pratyush, skhawaja

Currently, LUO does not prevent the same file from being preserved twice
across different active sessions.

Because LUO preserves files of absolutely different types: memfd, and
upcoming vfiofd [1], iommufd [2], guestmefd (and possible kvmfd/cpufd).
There is no common private data or guarantee on how to prevent that the
same file is not preserved twice beside using inode or some slower and
expensive method like hashtables.

[1] https://lore.kernel.org/all/20260129212510.967611-1-dmatlack@google.com
[2] https://lore.kernel.org/all/20260203220948.2176157-1-skhawaja@google.com

Changelog:
v2:
 - Because inodes of preserved files can be shared, we cannot rely on a
   flag in the inode. Therefore, use an xarray to prevent preserving
   duplicated files.

Pasha Tatashin (2):
  liveupdate: prevent double management of files
  selftests: liveupdate: add test for double preservation

 kernel/liveupdate/luo_file.c                  | 17 +++++++-
 .../testing/selftests/liveupdate/liveupdate.c | 41 +++++++++++++++++++
 2 files changed, 56 insertions(+), 2 deletions(-)

-- 
2.43.0


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

* [PATCH v2 1/2] liveupdate: prevent double management of files
  2026-03-23 20:31 [PATCH v2 0/2] liveupdate: prevent double preservation Pasha Tatashin
@ 2026-03-23 20:31 ` Pasha Tatashin
  2026-03-23 20:43   ` Samiullah Khawaja
  2026-03-25 15:31   ` Mike Rapoport
  2026-03-23 20:31 ` [PATCH v2 2/2] selftests: liveupdate: add test for double preservation Pasha Tatashin
  1 sibling, 2 replies; 9+ messages in thread
From: Pasha Tatashin @ 2026-03-23 20:31 UTC (permalink / raw)
  To: linux-kselftest, rppt, shuah, akpm, linux-mm, linux-kernel,
	pasha.tatashin, dmatlack, pratyush, skhawaja

Currently, LUO does not prevent the same file from being managed twice
across different active sessions.

Use a global xarray `luo_preserved_files_xa` to keep track of file
pointers being preserved by LUO. Update luo_preserve_file() to check and
insert the file pointer into this xarray when it is preserved, and
erase it in luo_file_unpreserve_files() when it is released.

This ensures that the same file (struct file) cannot be managed by
multiple sessions. If another session attempts to preserve an already
managed file, it will now fail with -EBUSY.

Signed-off-by: Pasha Tatashin <pasha.tatashin@soleen.com>
---
 kernel/liveupdate/luo_file.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/kernel/liveupdate/luo_file.c b/kernel/liveupdate/luo_file.c
index a38ea4975824..5f48c3c8c561 100644
--- a/kernel/liveupdate/luo_file.c
+++ b/kernel/liveupdate/luo_file.c
@@ -110,11 +110,15 @@
 #include <linux/sizes.h>
 #include <linux/slab.h>
 #include <linux/string.h>
+#include <linux/xarray.h>
 #include "luo_internal.h"
 
 static DECLARE_RWSEM(luo_file_handler_lock);
 static LIST_HEAD(luo_file_handler_list);
 
+/* Keep track of files being preserved by LUO */
+static DEFINE_XARRAY(luo_preserved_files_xa);
+
 /* 2 4K pages, give space for 128 files per file_set */
 #define LUO_FILE_PGCNT		2ul
 #define LUO_FILE_MAX							\
@@ -249,6 +253,7 @@ static bool luo_token_is_used(struct luo_file_set *file_set, u64 token)
  * Context: Can be called from an ioctl handler during normal system operation.
  * Return: 0 on success. Returns a negative errno on failure:
  *         -EEXIST if the token is already used.
+ *         -EBUSY if the file descriptor is already preserved by another session.
  *         -EBADF if the file descriptor is invalid.
  *         -ENOSPC if the file_set is full.
  *         -ENOENT if no compatible handler is found.
@@ -277,6 +282,11 @@ int luo_preserve_file(struct luo_file_set *file_set, u64 token, int fd)
 	if (err)
 		goto  err_fput;
 
+	err = xa_insert(&luo_preserved_files_xa, (unsigned long)file,
+			file, GFP_KERNEL);
+	if (err)
+		goto err_free_files_mem;
+
 	err = -ENOENT;
 	scoped_guard(rwsem_read, &luo_file_handler_lock) {
 		list_private_for_each_entry(fh, &luo_file_handler_list, list) {
@@ -289,11 +299,11 @@ int luo_preserve_file(struct luo_file_set *file_set, u64 token, int fd)
 
 	/* err is still -ENOENT if no handler was found */
 	if (err)
-		goto err_free_files_mem;
+		goto err_erase_xa;
 
 	err = luo_flb_file_preserve(fh);
 	if (err)
-		goto err_free_files_mem;
+		goto err_erase_xa;
 
 	luo_file = kzalloc_obj(*luo_file);
 	if (!luo_file) {
@@ -323,6 +333,8 @@ int luo_preserve_file(struct luo_file_set *file_set, u64 token, int fd)
 	kfree(luo_file);
 err_flb_unpreserve:
 	luo_flb_file_unpreserve(fh);
+err_erase_xa:
+	xa_erase(&luo_preserved_files_xa, (unsigned long)file);
 err_free_files_mem:
 	luo_free_files_mem(file_set);
 err_fput:
@@ -366,6 +378,7 @@ void luo_file_unpreserve_files(struct luo_file_set *file_set)
 		luo_file->fh->ops->unpreserve(&args);
 		luo_flb_file_unpreserve(luo_file->fh);
 
+		xa_erase(&luo_preserved_files_xa, (unsigned long)luo_file->file);
 		list_del(&luo_file->list);
 		file_set->count--;
 
-- 
2.43.0



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

* [PATCH v2 2/2] selftests: liveupdate: add test for double preservation
  2026-03-23 20:31 [PATCH v2 0/2] liveupdate: prevent double preservation Pasha Tatashin
  2026-03-23 20:31 ` [PATCH v2 1/2] liveupdate: prevent double management of files Pasha Tatashin
@ 2026-03-23 20:31 ` Pasha Tatashin
  2026-03-23 20:44   ` Samiullah Khawaja
  2026-03-25 15:32   ` Mike Rapoport
  1 sibling, 2 replies; 9+ messages in thread
From: Pasha Tatashin @ 2026-03-23 20:31 UTC (permalink / raw)
  To: linux-kselftest, rppt, shuah, akpm, linux-mm, linux-kernel,
	pasha.tatashin, dmatlack, pratyush, skhawaja

Verify that a file can only be preserved once across all active
sessions. Attempting to preserve it a second time, whether in the same
or a different session, should fail with EBUSY.

Signed-off-by: Pasha Tatashin <pasha.tatashin@soleen.com>
---
 .../testing/selftests/liveupdate/liveupdate.c | 41 +++++++++++++++++++
 1 file changed, 41 insertions(+)

diff --git a/tools/testing/selftests/liveupdate/liveupdate.c b/tools/testing/selftests/liveupdate/liveupdate.c
index c2878e3d5ef9..37c808fbe1e9 100644
--- a/tools/testing/selftests/liveupdate/liveupdate.c
+++ b/tools/testing/selftests/liveupdate/liveupdate.c
@@ -345,4 +345,45 @@ TEST_F(liveupdate_device, preserve_unsupported_fd)
 	ASSERT_EQ(close(session_fd), 0);
 }
 
+/*
+ * Test Case: Prevent Double Preservation
+ *
+ * Verifies that a file (memfd) can only be preserved once across all active
+ * sessions. Attempting to preserve it a second time, whether in the same or
+ * a different session, should fail with EBUSY.
+ */
+TEST_F(liveupdate_device, prevent_double_preservation)
+{
+	int session_fd1, session_fd2, mem_fd;
+	int ret;
+
+	self->fd1 = open(LIVEUPDATE_DEV, O_RDWR);
+	if (self->fd1 < 0 && errno == ENOENT)
+		SKIP(return, "%s does not exist", LIVEUPDATE_DEV);
+	ASSERT_GE(self->fd1, 0);
+
+	session_fd1 = create_session(self->fd1, "double-preserve-session-1");
+	ASSERT_GE(session_fd1, 0);
+	session_fd2 = create_session(self->fd1, "double-preserve-session-2");
+	ASSERT_GE(session_fd2, 0);
+
+	mem_fd = memfd_create("test-memfd", 0);
+	ASSERT_GE(mem_fd, 0);
+
+	/* First preservation should succeed */
+	ASSERT_EQ(preserve_fd(session_fd1, mem_fd, 0x1111), 0);
+
+	/* Second preservation in a different session should fail with EBUSY */
+	ret = preserve_fd(session_fd2, mem_fd, 0x2222);
+	EXPECT_EQ(ret, -EBUSY);
+
+	/* Second preservation in the same session (different token) should fail with EBUSY */
+	ret = preserve_fd(session_fd1, mem_fd, 0x3333);
+	EXPECT_EQ(ret, -EBUSY);
+
+	ASSERT_EQ(close(mem_fd), 0);
+	ASSERT_EQ(close(session_fd1), 0);
+	ASSERT_EQ(close(session_fd2), 0);
+}
+
 TEST_HARNESS_MAIN
-- 
2.43.0



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

* Re: [PATCH v2 1/2] liveupdate: prevent double management of files
  2026-03-23 20:31 ` [PATCH v2 1/2] liveupdate: prevent double management of files Pasha Tatashin
@ 2026-03-23 20:43   ` Samiullah Khawaja
  2026-03-25 15:31   ` Mike Rapoport
  1 sibling, 0 replies; 9+ messages in thread
From: Samiullah Khawaja @ 2026-03-23 20:43 UTC (permalink / raw)
  To: Pasha Tatashin
  Cc: linux-kselftest, rppt, shuah, akpm, linux-mm, linux-kernel,
	dmatlack, pratyush

On Mon, Mar 23, 2026 at 08:31:44PM +0000, Pasha Tatashin wrote:
>Currently, LUO does not prevent the same file from being managed twice
>across different active sessions.
>
>Use a global xarray `luo_preserved_files_xa` to keep track of file
>pointers being preserved by LUO. Update luo_preserve_file() to check and
>insert the file pointer into this xarray when it is preserved, and
>erase it in luo_file_unpreserve_files() when it is released.
>
>This ensures that the same file (struct file) cannot be managed by
>multiple sessions. If another session attempts to preserve an already
>managed file, it will now fail with -EBUSY.
>
>Signed-off-by: Pasha Tatashin <pasha.tatashin@soleen.com>
>---
> kernel/liveupdate/luo_file.c | 17 +++++++++++++++--
> 1 file changed, 15 insertions(+), 2 deletions(-)
>
>diff --git a/kernel/liveupdate/luo_file.c b/kernel/liveupdate/luo_file.c
>index a38ea4975824..5f48c3c8c561 100644
>--- a/kernel/liveupdate/luo_file.c
>+++ b/kernel/liveupdate/luo_file.c
>@@ -110,11 +110,15 @@
> #include <linux/sizes.h>
> #include <linux/slab.h>
> #include <linux/string.h>
>+#include <linux/xarray.h>
> #include "luo_internal.h"
>
> static DECLARE_RWSEM(luo_file_handler_lock);
> static LIST_HEAD(luo_file_handler_list);
>
>+/* Keep track of files being preserved by LUO */
>+static DEFINE_XARRAY(luo_preserved_files_xa);
>+
> /* 2 4K pages, give space for 128 files per file_set */
> #define LUO_FILE_PGCNT		2ul
> #define LUO_FILE_MAX							\
>@@ -249,6 +253,7 @@ static bool luo_token_is_used(struct luo_file_set *file_set, u64 token)
>  * Context: Can be called from an ioctl handler during normal system operation.
>  * Return: 0 on success. Returns a negative errno on failure:
>  *         -EEXIST if the token is already used.
>+ *         -EBUSY if the file descriptor is already preserved by another session.
>  *         -EBADF if the file descriptor is invalid.
>  *         -ENOSPC if the file_set is full.
>  *         -ENOENT if no compatible handler is found.
>@@ -277,6 +282,11 @@ int luo_preserve_file(struct luo_file_set *file_set, u64 token, int fd)
> 	if (err)
> 		goto  err_fput;
>
>+	err = xa_insert(&luo_preserved_files_xa, (unsigned long)file,
>+			file, GFP_KERNEL);
>+	if (err)
>+		goto err_free_files_mem;
>+
> 	err = -ENOENT;
> 	scoped_guard(rwsem_read, &luo_file_handler_lock) {
> 		list_private_for_each_entry(fh, &luo_file_handler_list, list) {
>@@ -289,11 +299,11 @@ int luo_preserve_file(struct luo_file_set *file_set, u64 token, int fd)
>
> 	/* err is still -ENOENT if no handler was found */
> 	if (err)
>-		goto err_free_files_mem;
>+		goto err_erase_xa;
>
> 	err = luo_flb_file_preserve(fh);
> 	if (err)
>-		goto err_free_files_mem;
>+		goto err_erase_xa;
>
> 	luo_file = kzalloc_obj(*luo_file);
> 	if (!luo_file) {
>@@ -323,6 +333,8 @@ int luo_preserve_file(struct luo_file_set *file_set, u64 token, int fd)
> 	kfree(luo_file);
> err_flb_unpreserve:
> 	luo_flb_file_unpreserve(fh);
>+err_erase_xa:
>+	xa_erase(&luo_preserved_files_xa, (unsigned long)file);
> err_free_files_mem:
> 	luo_free_files_mem(file_set);
> err_fput:
>@@ -366,6 +378,7 @@ void luo_file_unpreserve_files(struct luo_file_set *file_set)
> 		luo_file->fh->ops->unpreserve(&args);
> 		luo_flb_file_unpreserve(luo_file->fh);
>
>+		xa_erase(&luo_preserved_files_xa, (unsigned long)luo_file->file);
> 		list_del(&luo_file->list);
> 		file_set->count--;
>
>-- 
>2.43.0
>

Reviewed-by: Samiullah Khawaja <skhawaja@google.com>


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

* Re: [PATCH v2 2/2] selftests: liveupdate: add test for double preservation
  2026-03-23 20:31 ` [PATCH v2 2/2] selftests: liveupdate: add test for double preservation Pasha Tatashin
@ 2026-03-23 20:44   ` Samiullah Khawaja
  2026-03-25 15:32   ` Mike Rapoport
  1 sibling, 0 replies; 9+ messages in thread
From: Samiullah Khawaja @ 2026-03-23 20:44 UTC (permalink / raw)
  To: Pasha Tatashin
  Cc: linux-kselftest, rppt, shuah, akpm, linux-mm, linux-kernel,
	dmatlack, pratyush

On Mon, Mar 23, 2026 at 08:31:45PM +0000, Pasha Tatashin wrote:
>Verify that a file can only be preserved once across all active
>sessions. Attempting to preserve it a second time, whether in the same
>or a different session, should fail with EBUSY.
>
>Signed-off-by: Pasha Tatashin <pasha.tatashin@soleen.com>
>---
> .../testing/selftests/liveupdate/liveupdate.c | 41 +++++++++++++++++++
> 1 file changed, 41 insertions(+)
>
>diff --git a/tools/testing/selftests/liveupdate/liveupdate.c b/tools/testing/selftests/liveupdate/liveupdate.c
>index c2878e3d5ef9..37c808fbe1e9 100644
>--- a/tools/testing/selftests/liveupdate/liveupdate.c
>+++ b/tools/testing/selftests/liveupdate/liveupdate.c
>@@ -345,4 +345,45 @@ TEST_F(liveupdate_device, preserve_unsupported_fd)
> 	ASSERT_EQ(close(session_fd), 0);
> }
>
>+/*
>+ * Test Case: Prevent Double Preservation
>+ *
>+ * Verifies that a file (memfd) can only be preserved once across all active
>+ * sessions. Attempting to preserve it a second time, whether in the same or
>+ * a different session, should fail with EBUSY.
>+ */
>+TEST_F(liveupdate_device, prevent_double_preservation)
>+{
>+	int session_fd1, session_fd2, mem_fd;
>+	int ret;
>+
>+	self->fd1 = open(LIVEUPDATE_DEV, O_RDWR);
>+	if (self->fd1 < 0 && errno == ENOENT)
>+		SKIP(return, "%s does not exist", LIVEUPDATE_DEV);
>+	ASSERT_GE(self->fd1, 0);
>+
>+	session_fd1 = create_session(self->fd1, "double-preserve-session-1");
>+	ASSERT_GE(session_fd1, 0);
>+	session_fd2 = create_session(self->fd1, "double-preserve-session-2");
>+	ASSERT_GE(session_fd2, 0);
>+
>+	mem_fd = memfd_create("test-memfd", 0);
>+	ASSERT_GE(mem_fd, 0);
>+
>+	/* First preservation should succeed */
>+	ASSERT_EQ(preserve_fd(session_fd1, mem_fd, 0x1111), 0);
>+
>+	/* Second preservation in a different session should fail with EBUSY */
>+	ret = preserve_fd(session_fd2, mem_fd, 0x2222);
>+	EXPECT_EQ(ret, -EBUSY);
>+
>+	/* Second preservation in the same session (different token) should fail with EBUSY */
>+	ret = preserve_fd(session_fd1, mem_fd, 0x3333);
>+	EXPECT_EQ(ret, -EBUSY);
>+
>+	ASSERT_EQ(close(mem_fd), 0);
>+	ASSERT_EQ(close(session_fd1), 0);
>+	ASSERT_EQ(close(session_fd2), 0);
>+}
>+
> TEST_HARNESS_MAIN
>-- 
>2.43.0
>

Reviewed-by: Samiullah Khawaja <skhawaja@google.com>


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

* Re: [PATCH v2 1/2] liveupdate: prevent double management of files
  2026-03-23 20:31 ` [PATCH v2 1/2] liveupdate: prevent double management of files Pasha Tatashin
  2026-03-23 20:43   ` Samiullah Khawaja
@ 2026-03-25 15:31   ` Mike Rapoport
  2026-03-25 16:15     ` Pasha Tatashin
  1 sibling, 1 reply; 9+ messages in thread
From: Mike Rapoport @ 2026-03-25 15:31 UTC (permalink / raw)
  To: Pasha Tatashin
  Cc: linux-kselftest, shuah, akpm, linux-mm, linux-kernel, dmatlack,
	pratyush, skhawaja

On Mon, Mar 23, 2026 at 08:31:44PM +0000, Pasha Tatashin wrote:
> Currently, LUO does not prevent the same file from being managed twice
> across different active sessions.
> 
> Use a global xarray `luo_preserved_files_xa` to keep track of file

Do we really need _xa suffix?

> pointers being preserved by LUO. Update luo_preserve_file() to check and
> insert the file pointer into this xarray when it is preserved, and
> erase it in luo_file_unpreserve_files() when it is released.
> 
> This ensures that the same file (struct file) cannot be managed by
> multiple sessions. If another session attempts to preserve an already
> managed file, it will now fail with -EBUSY.
> 
> Signed-off-by: Pasha Tatashin <pasha.tatashin@soleen.com>
> ---
>  kernel/liveupdate/luo_file.c | 17 +++++++++++++++--
>  1 file changed, 15 insertions(+), 2 deletions(-)
> 
> diff --git a/kernel/liveupdate/luo_file.c b/kernel/liveupdate/luo_file.c
> index a38ea4975824..5f48c3c8c561 100644
> --- a/kernel/liveupdate/luo_file.c
> +++ b/kernel/liveupdate/luo_file.c
> @@ -110,11 +110,15 @@
>  #include <linux/sizes.h>
>  #include <linux/slab.h>
>  #include <linux/string.h>
> +#include <linux/xarray.h>
>  #include "luo_internal.h"
>  
>  static DECLARE_RWSEM(luo_file_handler_lock);
>  static LIST_HEAD(luo_file_handler_list);
>  
> +/* Keep track of files being preserved by LUO */
> +static DEFINE_XARRAY(luo_preserved_files_xa);
> +
>  /* 2 4K pages, give space for 128 files per file_set */
>  #define LUO_FILE_PGCNT		2ul
>  #define LUO_FILE_MAX							\
> @@ -249,6 +253,7 @@ static bool luo_token_is_used(struct luo_file_set *file_set, u64 token)
>   * Context: Can be called from an ioctl handler during normal system operation.
>   * Return: 0 on success. Returns a negative errno on failure:
>   *         -EEXIST if the token is already used.
> + *         -EBUSY if the file descriptor is already preserved by another session.
>   *         -EBADF if the file descriptor is invalid.
>   *         -ENOSPC if the file_set is full.
>   *         -ENOENT if no compatible handler is found.
> @@ -277,6 +282,11 @@ int luo_preserve_file(struct luo_file_set *file_set, u64 token, int fd)
>  	if (err)
>  		goto  err_fput;
>  
> +	err = xa_insert(&luo_preserved_files_xa, (unsigned long)file,
> +			file, GFP_KERNEL);
> +	if (err)
> +		goto err_free_files_mem;
> +
>  	err = -ENOENT;
>  	scoped_guard(rwsem_read, &luo_file_handler_lock) {
>  		list_private_for_each_entry(fh, &luo_file_handler_list, list) {
> @@ -289,11 +299,11 @@ int luo_preserve_file(struct luo_file_set *file_set, u64 token, int fd)
>  
>  	/* err is still -ENOENT if no handler was found */
>  	if (err)
> -		goto err_free_files_mem;
> +		goto err_erase_xa;
>  
>  	err = luo_flb_file_preserve(fh);
>  	if (err)
> -		goto err_free_files_mem;
> +		goto err_erase_xa;
>  
>  	luo_file = kzalloc_obj(*luo_file);
>  	if (!luo_file) {
> @@ -323,6 +333,8 @@ int luo_preserve_file(struct luo_file_set *file_set, u64 token, int fd)
>  	kfree(luo_file);
>  err_flb_unpreserve:
>  	luo_flb_file_unpreserve(fh);
> +err_erase_xa:
> +	xa_erase(&luo_preserved_files_xa, (unsigned long)file);
>  err_free_files_mem:
>  	luo_free_files_mem(file_set);
>  err_fput:
> @@ -366,6 +378,7 @@ void luo_file_unpreserve_files(struct luo_file_set *file_set)
>  		luo_file->fh->ops->unpreserve(&args);
>  		luo_flb_file_unpreserve(luo_file->fh);
>  
> +		xa_erase(&luo_preserved_files_xa, (unsigned long)luo_file->file);
>  		list_del(&luo_file->list);
>  		file_set->count--;
>  
> -- 
> 2.43.0
> 

-- 
Sincerely yours,
Mike.


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

* Re: [PATCH v2 2/2] selftests: liveupdate: add test for double preservation
  2026-03-23 20:31 ` [PATCH v2 2/2] selftests: liveupdate: add test for double preservation Pasha Tatashin
  2026-03-23 20:44   ` Samiullah Khawaja
@ 2026-03-25 15:32   ` Mike Rapoport
  1 sibling, 0 replies; 9+ messages in thread
From: Mike Rapoport @ 2026-03-25 15:32 UTC (permalink / raw)
  To: Pasha Tatashin
  Cc: linux-kselftest, shuah, akpm, linux-mm, linux-kernel, dmatlack,
	pratyush, skhawaja

On Mon, Mar 23, 2026 at 08:31:45PM +0000, Pasha Tatashin wrote:
> Verify that a file can only be preserved once across all active
> sessions. Attempting to preserve it a second time, whether in the same
> or a different session, should fail with EBUSY.
> 
> Signed-off-by: Pasha Tatashin <pasha.tatashin@soleen.com>

Reviewed-by: Mike Rapoport (Microsoft) <rppt@kernel.org>

> ---
>  .../testing/selftests/liveupdate/liveupdate.c | 41 +++++++++++++++++++
>  1 file changed, 41 insertions(+)

-- 
Sincerely yours,
Mike.


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

* Re: [PATCH v2 1/2] liveupdate: prevent double management of files
  2026-03-25 15:31   ` Mike Rapoport
@ 2026-03-25 16:15     ` Pasha Tatashin
  2026-03-25 18:51       ` Mike Rapoport
  0 siblings, 1 reply; 9+ messages in thread
From: Pasha Tatashin @ 2026-03-25 16:15 UTC (permalink / raw)
  To: Mike Rapoport
  Cc: linux-kselftest, shuah, akpm, linux-mm, linux-kernel, dmatlack,
	pratyush, skhawaja

On Wed, Mar 25, 2026 at 11:32 AM Mike Rapoport <rppt@kernel.org> wrote:
>
> On Mon, Mar 23, 2026 at 08:31:44PM +0000, Pasha Tatashin wrote:
> > Currently, LUO does not prevent the same file from being managed twice
> > across different active sessions.
> >
> > Use a global xarray `luo_preserved_files_xa` to keep track of file
>
> Do we really need _xa suffix?

I liked it, because `luo_preserved_files` is a little too plain, and
not self-descriptive. Anyways, I can change it.

Pasha

>
> > pointers being preserved by LUO. Update luo_preserve_file() to check and
> > insert the file pointer into this xarray when it is preserved, and
> > erase it in luo_file_unpreserve_files() when it is released.
> >
> > This ensures that the same file (struct file) cannot be managed by
> > multiple sessions. If another session attempts to preserve an already
> > managed file, it will now fail with -EBUSY.
> >
> > Signed-off-by: Pasha Tatashin <pasha.tatashin@soleen.com>
> > ---
> >  kernel/liveupdate/luo_file.c | 17 +++++++++++++++--
> >  1 file changed, 15 insertions(+), 2 deletions(-)
> >
> > diff --git a/kernel/liveupdate/luo_file.c b/kernel/liveupdate/luo_file.c
> > index a38ea4975824..5f48c3c8c561 100644
> > --- a/kernel/liveupdate/luo_file.c
> > +++ b/kernel/liveupdate/luo_file.c
> > @@ -110,11 +110,15 @@
> >  #include <linux/sizes.h>
> >  #include <linux/slab.h>
> >  #include <linux/string.h>
> > +#include <linux/xarray.h>
> >  #include "luo_internal.h"
> >
> >  static DECLARE_RWSEM(luo_file_handler_lock);
> >  static LIST_HEAD(luo_file_handler_list);
> >
> > +/* Keep track of files being preserved by LUO */
> > +static DEFINE_XARRAY(luo_preserved_files_xa);
> > +
> >  /* 2 4K pages, give space for 128 files per file_set */
> >  #define LUO_FILE_PGCNT               2ul
> >  #define LUO_FILE_MAX                                                 \
> > @@ -249,6 +253,7 @@ static bool luo_token_is_used(struct luo_file_set *file_set, u64 token)
> >   * Context: Can be called from an ioctl handler during normal system operation.
> >   * Return: 0 on success. Returns a negative errno on failure:
> >   *         -EEXIST if the token is already used.
> > + *         -EBUSY if the file descriptor is already preserved by another session.
> >   *         -EBADF if the file descriptor is invalid.
> >   *         -ENOSPC if the file_set is full.
> >   *         -ENOENT if no compatible handler is found.
> > @@ -277,6 +282,11 @@ int luo_preserve_file(struct luo_file_set *file_set, u64 token, int fd)
> >       if (err)
> >               goto  err_fput;
> >
> > +     err = xa_insert(&luo_preserved_files_xa, (unsigned long)file,
> > +                     file, GFP_KERNEL);
> > +     if (err)
> > +             goto err_free_files_mem;
> > +
> >       err = -ENOENT;
> >       scoped_guard(rwsem_read, &luo_file_handler_lock) {
> >               list_private_for_each_entry(fh, &luo_file_handler_list, list) {
> > @@ -289,11 +299,11 @@ int luo_preserve_file(struct luo_file_set *file_set, u64 token, int fd)
> >
> >       /* err is still -ENOENT if no handler was found */
> >       if (err)
> > -             goto err_free_files_mem;
> > +             goto err_erase_xa;
> >
> >       err = luo_flb_file_preserve(fh);
> >       if (err)
> > -             goto err_free_files_mem;
> > +             goto err_erase_xa;
> >
> >       luo_file = kzalloc_obj(*luo_file);
> >       if (!luo_file) {
> > @@ -323,6 +333,8 @@ int luo_preserve_file(struct luo_file_set *file_set, u64 token, int fd)
> >       kfree(luo_file);
> >  err_flb_unpreserve:
> >       luo_flb_file_unpreserve(fh);
> > +err_erase_xa:
> > +     xa_erase(&luo_preserved_files_xa, (unsigned long)file);
> >  err_free_files_mem:
> >       luo_free_files_mem(file_set);
> >  err_fput:
> > @@ -366,6 +378,7 @@ void luo_file_unpreserve_files(struct luo_file_set *file_set)
> >               luo_file->fh->ops->unpreserve(&args);
> >               luo_flb_file_unpreserve(luo_file->fh);
> >
> > +             xa_erase(&luo_preserved_files_xa, (unsigned long)luo_file->file);
> >               list_del(&luo_file->list);
> >               file_set->count--;
> >
> > --
> > 2.43.0
> >
>
> --
> Sincerely yours,
> Mike.


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

* Re: [PATCH v2 1/2] liveupdate: prevent double management of files
  2026-03-25 16:15     ` Pasha Tatashin
@ 2026-03-25 18:51       ` Mike Rapoport
  0 siblings, 0 replies; 9+ messages in thread
From: Mike Rapoport @ 2026-03-25 18:51 UTC (permalink / raw)
  To: Pasha Tatashin
  Cc: linux-kselftest, shuah, akpm, linux-mm, linux-kernel, dmatlack,
	pratyush, skhawaja

On Wed, Mar 25, 2026 at 12:15:53PM -0400, Pasha Tatashin wrote:
> On Wed, Mar 25, 2026 at 11:32 AM Mike Rapoport <rppt@kernel.org> wrote:
> >
> > On Mon, Mar 23, 2026 at 08:31:44PM +0000, Pasha Tatashin wrote:
> > > Currently, LUO does not prevent the same file from being managed twice
> > > across different active sessions.
> > >
> > > Use a global xarray `luo_preserved_files_xa` to keep track of file
> >
> > Do we really need _xa suffix?
> 
> I liked it, because `luo_preserved_files` is a little too plain, and
> not self-descriptive. Anyways, I can change it.

Just reminded a bit of Hungarian notation, but I don't feel strongly :)
 
> Pasha

-- 
Sincerely yours,
Mike.


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

end of thread, other threads:[~2026-03-25 18:52 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-23 20:31 [PATCH v2 0/2] liveupdate: prevent double preservation Pasha Tatashin
2026-03-23 20:31 ` [PATCH v2 1/2] liveupdate: prevent double management of files Pasha Tatashin
2026-03-23 20:43   ` Samiullah Khawaja
2026-03-25 15:31   ` Mike Rapoport
2026-03-25 16:15     ` Pasha Tatashin
2026-03-25 18:51       ` Mike Rapoport
2026-03-23 20:31 ` [PATCH v2 2/2] selftests: liveupdate: add test for double preservation Pasha Tatashin
2026-03-23 20:44   ` Samiullah Khawaja
2026-03-25 15:32   ` Mike Rapoport

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox