All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] Make liveupdate selftests util as a library
@ 2026-05-11 20:11 Vipin Sharma
  2026-05-11 20:11 ` [PATCH 1/2] selftests/liveupdate: Move luo_test_utils.* into a reusable library Vipin Sharma
  2026-05-11 20:11 ` [PATCH 2/2] selftests/liveupdate: Add helpers to preserve/retrieve FDs Vipin Sharma
  0 siblings, 2 replies; 9+ messages in thread
From: Vipin Sharma @ 2026-05-11 20:11 UTC (permalink / raw)
  To: pasha.tatashin, rppt, pratyush
  Cc: shuah, dmatlack, skhawaja, tarunsahu, linux-kernel,
	linux-kselftest, Vipin Sharma

Hello,

This patch series refactors the liveupdate selftests util. It exposes
liveupdate util code as a library which can be used by other selftests
like VFIO and IOMMU.

In this series there are no users of this change but it is being used in
VFIO liveupdate series and iommu.
  https://lore.kernel.org/kvm/20260323235817.1960573-15-dmatlack@google.com/
  https://lore.kernel.org/linux-iommu/20260427175633.1978233-17-skhawaja@google.com/

I think it is better to move the patches out and propose as a
separate series for inclusion liveupdate repo. That way we can decouple
multiple downstream dependencies and then it can be used by VFIO, IOMMU,
and KVM (guest_memfd preservation) separately.

Vipin Sharma (2):
  selftests/liveupdate: Move luo_test_utils.* into a reusable library
  selftests/liveupdate: Add helpers to preserve/retrieve FDs

 tools/testing/selftests/liveupdate/.gitignore |  1 +
 tools/testing/selftests/liveupdate/Makefile   | 14 ++----
 .../include/libliveupdate.h}                  | 11 +++--
 .../selftests/liveupdate/lib/libliveupdate.mk | 20 +++++++++
 .../{luo_test_utils.c => lib/liveupdate.c}    | 43 ++++++++++++++-----
 .../selftests/liveupdate/luo_kexec_simple.c   |  2 +-
 .../selftests/liveupdate/luo_multi_session.c  |  2 +-
 7 files changed, 67 insertions(+), 26 deletions(-)
 rename tools/testing/selftests/liveupdate/{luo_test_utils.h => lib/include/libliveupdate.h} (80%)
 create mode 100644 tools/testing/selftests/liveupdate/lib/libliveupdate.mk
 rename tools/testing/selftests/liveupdate/{luo_test_utils.c => lib/liveupdate.c} (91%)


base-commit: 5d6919055dec134de3c40167a490f33c74c12581
-- 
2.54.0.563.g4f69b47b94-goog


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

* [PATCH 1/2] selftests/liveupdate: Move luo_test_utils.* into a reusable library
  2026-05-11 20:11 [PATCH 0/2] Make liveupdate selftests util as a library Vipin Sharma
@ 2026-05-11 20:11 ` Vipin Sharma
  2026-06-08 14:31   ` Pratyush Yadav
  2026-05-11 20:11 ` [PATCH 2/2] selftests/liveupdate: Add helpers to preserve/retrieve FDs Vipin Sharma
  1 sibling, 1 reply; 9+ messages in thread
From: Vipin Sharma @ 2026-05-11 20:11 UTC (permalink / raw)
  To: pasha.tatashin, rppt, pratyush
  Cc: shuah, dmatlack, skhawaja, tarunsahu, linux-kernel,
	linux-kselftest, Vipin Sharma

Move luo_test_utils.[ch] into a lib/ directory and pull the rules to
build them out into a separate make script. This will enable these
utilities to be also built by and used within other selftests (such as
VFIO).

No functional change intended.

Signed-off-by: Vipin Sharma <vipinsh@google.com>
Co-developed-by: David Matlack <dmatlack@google.com>
Signed-off-by: David Matlack <dmatlack@google.com>
Signed-off-by: Vipin Sharma <vipinsh@google.com>
---
 tools/testing/selftests/liveupdate/.gitignore |  1 +
 tools/testing/selftests/liveupdate/Makefile   | 14 ++++---------
 .../include/libliveupdate.h}                  |  8 ++++----
 .../selftests/liveupdate/lib/libliveupdate.mk | 20 +++++++++++++++++++
 .../{luo_test_utils.c => lib/liveupdate.c}    |  2 +-
 .../selftests/liveupdate/luo_kexec_simple.c   |  2 +-
 .../selftests/liveupdate/luo_multi_session.c  |  2 +-
 7 files changed, 32 insertions(+), 17 deletions(-)
 rename tools/testing/selftests/liveupdate/{luo_test_utils.h => lib/include/libliveupdate.h} (87%)
 create mode 100644 tools/testing/selftests/liveupdate/lib/libliveupdate.mk
 rename tools/testing/selftests/liveupdate/{luo_test_utils.c => lib/liveupdate.c} (99%)

diff --git a/tools/testing/selftests/liveupdate/.gitignore b/tools/testing/selftests/liveupdate/.gitignore
index 661827083ab6..18a0c7036cf3 100644
--- a/tools/testing/selftests/liveupdate/.gitignore
+++ b/tools/testing/selftests/liveupdate/.gitignore
@@ -3,6 +3,7 @@
 !/**/
 !*.c
 !*.h
+!*.mk
 !*.sh
 !.gitignore
 !config
diff --git a/tools/testing/selftests/liveupdate/Makefile b/tools/testing/selftests/liveupdate/Makefile
index 080754787ede..a060cc21f27f 100644
--- a/tools/testing/selftests/liveupdate/Makefile
+++ b/tools/testing/selftests/liveupdate/Makefile
@@ -1,7 +1,5 @@
 # SPDX-License-Identifier: GPL-2.0-only
 
-LIB_C += luo_test_utils.c
-
 TEST_GEN_PROGS += liveupdate
 
 TEST_GEN_PROGS_EXTENDED += luo_kexec_simple
@@ -10,25 +8,21 @@ TEST_GEN_PROGS_EXTENDED += luo_multi_session
 TEST_FILES += do_kexec.sh
 
 include ../lib.mk
+include lib/libliveupdate.mk
 
 CFLAGS += $(KHDR_INCLUDES)
 CFLAGS += -Wall -O2 -Wno-unused-function
 CFLAGS += -MD
 
-LIB_O := $(patsubst %.c, $(OUTPUT)/%.o, $(LIB_C))
 TEST_O := $(patsubst %, %.o, $(TEST_GEN_PROGS))
 TEST_O += $(patsubst %, %.o, $(TEST_GEN_PROGS_EXTENDED))
 
-TEST_DEP_FILES := $(patsubst %.o, %.d, $(LIB_O))
+TEST_DEP_FILES := $(patsubst %.o, %.d, $(LIBLIVEUPDATE_O))
 TEST_DEP_FILES += $(patsubst %.o, %.d, $(TEST_O))
 -include $(TEST_DEP_FILES)
 
-$(LIB_O): $(OUTPUT)/%.o: %.c
-	$(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c $< -o $@
-
-$(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED): $(OUTPUT)/%: %.o $(LIB_O)
-	$(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH) $< $(LIB_O) $(LDLIBS) -o $@
+$(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED): $(OUTPUT)/%: %.o $(LIBLIVEUPDATE_O)
+	$(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH) $< $(LIBLIVEUPDATE_O) $(LDLIBS) -o $@
 
-EXTRA_CLEAN += $(LIB_O)
 EXTRA_CLEAN += $(TEST_O)
 EXTRA_CLEAN += $(TEST_DEP_FILES)
diff --git a/tools/testing/selftests/liveupdate/luo_test_utils.h b/tools/testing/selftests/liveupdate/lib/include/libliveupdate.h
similarity index 87%
rename from tools/testing/selftests/liveupdate/luo_test_utils.h
rename to tools/testing/selftests/liveupdate/lib/include/libliveupdate.h
index 90099bf49577..4390a2737930 100644
--- a/tools/testing/selftests/liveupdate/luo_test_utils.h
+++ b/tools/testing/selftests/liveupdate/lib/include/libliveupdate.h
@@ -7,13 +7,13 @@
  * Utility functions for LUO kselftests.
  */
 
-#ifndef LUO_TEST_UTILS_H
-#define LUO_TEST_UTILS_H
+#ifndef SELFTESTS_LIVEUPDATE_LIB_LIVEUPDATE_H
+#define SELFTESTS_LIVEUPDATE_LIB_LIVEUPDATE_H
 
 #include <errno.h>
 #include <string.h>
 #include <linux/liveupdate.h>
-#include "../kselftest.h"
+#include "../../../kselftest.h"
 
 #define LUO_DEVICE "/dev/liveupdate"
 
@@ -41,4 +41,4 @@ typedef void (*luo_test_stage2_fn)(int luo_fd, int state_session_fd);
 int luo_test(int argc, char *argv[], const char *state_session_name,
 	     luo_test_stage1_fn stage1, luo_test_stage2_fn stage2);
 
-#endif /* LUO_TEST_UTILS_H */
+#endif /* SELFTESTS_LIVEUPDATE_LIB_LIVEUPDATE_H */
diff --git a/tools/testing/selftests/liveupdate/lib/libliveupdate.mk b/tools/testing/selftests/liveupdate/lib/libliveupdate.mk
new file mode 100644
index 000000000000..fffd95b085b6
--- /dev/null
+++ b/tools/testing/selftests/liveupdate/lib/libliveupdate.mk
@@ -0,0 +1,20 @@
+include $(top_srcdir)/scripts/subarch.include
+ARCH ?= $(SUBARCH)
+
+LIBLIVEUPDATE_SRCDIR := $(selfdir)/liveupdate/lib
+
+LIBLIVEUPDATE_C := liveupdate.c
+
+LIBLIVEUPDATE_OUTPUT := $(OUTPUT)/libliveupdate
+
+LIBLIVEUPDATE_O := $(patsubst %.c, $(LIBLIVEUPDATE_OUTPUT)/%.o, $(LIBLIVEUPDATE_C))
+
+LIBLIVEUPDATE_O_DIRS := $(shell dirname $(LIBLIVEUPDATE_O) | uniq)
+$(shell mkdir -p $(LIBLIVEUPDATE_O_DIRS))
+
+CFLAGS += -I$(LIBLIVEUPDATE_SRCDIR)/include
+
+$(LIBLIVEUPDATE_O): $(LIBLIVEUPDATE_OUTPUT)/%.o : $(LIBLIVEUPDATE_SRCDIR)/%.c
+	$(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c $< -o $@
+
+EXTRA_CLEAN += $(LIBLIVEUPDATE_OUTPUT)
diff --git a/tools/testing/selftests/liveupdate/luo_test_utils.c b/tools/testing/selftests/liveupdate/lib/liveupdate.c
similarity index 99%
rename from tools/testing/selftests/liveupdate/luo_test_utils.c
rename to tools/testing/selftests/liveupdate/lib/liveupdate.c
index 3c8721c505df..60121873f685 100644
--- a/tools/testing/selftests/liveupdate/luo_test_utils.c
+++ b/tools/testing/selftests/liveupdate/lib/liveupdate.c
@@ -21,7 +21,7 @@
 #include <errno.h>
 #include <stdarg.h>
 
-#include "luo_test_utils.h"
+#include <libliveupdate.h>
 
 int luo_open_device(void)
 {
diff --git a/tools/testing/selftests/liveupdate/luo_kexec_simple.c b/tools/testing/selftests/liveupdate/luo_kexec_simple.c
index d7ac1f3dc4cb..786ac93b9ae3 100644
--- a/tools/testing/selftests/liveupdate/luo_kexec_simple.c
+++ b/tools/testing/selftests/liveupdate/luo_kexec_simple.c
@@ -8,7 +8,7 @@
  * across a single kexec reboot.
  */
 
-#include "luo_test_utils.h"
+#include <libliveupdate.h>
 
 #define TEST_SESSION_NAME "test-session"
 #define TEST_MEMFD_TOKEN 0x1A
diff --git a/tools/testing/selftests/liveupdate/luo_multi_session.c b/tools/testing/selftests/liveupdate/luo_multi_session.c
index 0ee2d795beef..aac24a5f5ce3 100644
--- a/tools/testing/selftests/liveupdate/luo_multi_session.c
+++ b/tools/testing/selftests/liveupdate/luo_multi_session.c
@@ -9,7 +9,7 @@
  * files.
  */
 
-#include "luo_test_utils.h"
+#include <libliveupdate.h>
 
 #define SESSION_EMPTY_1 "multi-test-empty-1"
 #define SESSION_EMPTY_2 "multi-test-empty-2"
-- 
2.54.0.563.g4f69b47b94-goog


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

* [PATCH 2/2] selftests/liveupdate: Add helpers to preserve/retrieve FDs
  2026-05-11 20:11 [PATCH 0/2] Make liveupdate selftests util as a library Vipin Sharma
  2026-05-11 20:11 ` [PATCH 1/2] selftests/liveupdate: Move luo_test_utils.* into a reusable library Vipin Sharma
@ 2026-05-11 20:11 ` Vipin Sharma
  2026-05-18 11:29   ` tarunsahu
  2026-06-08 14:38   ` Pratyush Yadav
  1 sibling, 2 replies; 9+ messages in thread
From: Vipin Sharma @ 2026-05-11 20:11 UTC (permalink / raw)
  To: pasha.tatashin, rppt, pratyush
  Cc: shuah, dmatlack, skhawaja, tarunsahu, linux-kernel,
	linux-kselftest, Vipin Sharma

Add helper functions to preserve and retrieve file descriptors from an
LUO session. This allows library users to work with FD preservation.

No functional change intended.

Signed-off-by: Vipin Sharma <vipinsh@google.com>
Co-developed-by: David Matlack <dmatlack@google.com>
Signed-off-by: David Matlack <dmatlack@google.com>
Signed-off-by: Vipin Sharma <vipinsh@google.com>
---
 .../liveupdate/lib/include/libliveupdate.h    |  3 ++
 .../selftests/liveupdate/lib/liveupdate.c     | 41 +++++++++++++++----
 2 files changed, 35 insertions(+), 9 deletions(-)

diff --git a/tools/testing/selftests/liveupdate/lib/include/libliveupdate.h b/tools/testing/selftests/liveupdate/lib/include/libliveupdate.h
index 4390a2737930..2b04b3256382 100644
--- a/tools/testing/selftests/liveupdate/lib/include/libliveupdate.h
+++ b/tools/testing/selftests/liveupdate/lib/include/libliveupdate.h
@@ -26,6 +26,9 @@ int luo_create_session(int luo_fd, const char *name);
 int luo_retrieve_session(int luo_fd, const char *name);
 int luo_session_finish(int session_fd);
 
+int luo_session_preserve_fd(int session_fd, int fd, __u64 token);
+int luo_session_retrieve_fd(int session_fd, __u64 token);
+
 int create_and_preserve_memfd(int session_fd, int token, const char *data);
 int restore_and_verify_memfd(int session_fd, int token, const char *expected_data);
 
diff --git a/tools/testing/selftests/liveupdate/lib/liveupdate.c b/tools/testing/selftests/liveupdate/lib/liveupdate.c
index 60121873f685..7bc6707d8bb7 100644
--- a/tools/testing/selftests/liveupdate/lib/liveupdate.c
+++ b/tools/testing/selftests/liveupdate/lib/liveupdate.c
@@ -54,9 +54,35 @@ int luo_retrieve_session(int luo_fd, const char *name)
 	return arg.fd;
 }
 
+int luo_session_preserve_fd(int session_fd, int fd, __u64 token)
+{
+	struct liveupdate_session_preserve_fd arg = {
+		.size = sizeof(arg),
+		.fd = fd,
+		.token = token,
+	};
+
+	if (ioctl(session_fd, LIVEUPDATE_SESSION_PRESERVE_FD, &arg) < 0)
+		return -errno;
+
+	return 0;
+}
+
+int luo_session_retrieve_fd(int session_fd, __u64 token)
+{
+	struct liveupdate_session_retrieve_fd arg = {
+		.size = sizeof(arg),
+		.token = token,
+	};
+
+	if (ioctl(session_fd, LIVEUPDATE_SESSION_RETRIEVE_FD, &arg) < 0)
+		return -errno;
+
+	return arg.fd;
+}
+
 int create_and_preserve_memfd(int session_fd, int token, const char *data)
 {
-	struct liveupdate_session_preserve_fd arg = { .size = sizeof(arg) };
 	long page_size = sysconf(_SC_PAGE_SIZE);
 	void *map = MAP_FAILED;
 	int mfd = -1, ret = -1;
@@ -75,9 +101,8 @@ int create_and_preserve_memfd(int session_fd, int token, const char *data)
 	snprintf(map, page_size, "%s", data);
 	munmap(map, page_size);
 
-	arg.fd = mfd;
-	arg.token = token;
-	if (ioctl(session_fd, LIVEUPDATE_SESSION_PRESERVE_FD, &arg) < 0)
+	ret = luo_session_preserve_fd(session_fd, mfd, token);
+	if (ret)
 		goto out;
 
 	ret = 0;
@@ -92,15 +117,13 @@ int create_and_preserve_memfd(int session_fd, int token, const char *data)
 int restore_and_verify_memfd(int session_fd, int token,
 			     const char *expected_data)
 {
-	struct liveupdate_session_retrieve_fd arg = { .size = sizeof(arg) };
 	long page_size = sysconf(_SC_PAGE_SIZE);
 	void *map = MAP_FAILED;
 	int mfd = -1, ret = -1;
 
-	arg.token = token;
-	if (ioctl(session_fd, LIVEUPDATE_SESSION_RETRIEVE_FD, &arg) < 0)
-		return -errno;
-	mfd = arg.fd;
+	mfd = luo_session_retrieve_fd(session_fd, token);
+	if (mfd < 0)
+		return mfd;
 
 	map = mmap(NULL, page_size, PROT_READ, MAP_SHARED, mfd, 0);
 	if (map == MAP_FAILED)
-- 
2.54.0.563.g4f69b47b94-goog


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

* Re: [PATCH 2/2] selftests/liveupdate: Add helpers to preserve/retrieve FDs
  2026-05-11 20:11 ` [PATCH 2/2] selftests/liveupdate: Add helpers to preserve/retrieve FDs Vipin Sharma
@ 2026-05-18 11:29   ` tarunsahu
  2026-05-18 17:14     ` Vipin Sharma
  2026-06-08 14:38   ` Pratyush Yadav
  1 sibling, 1 reply; 9+ messages in thread
From: tarunsahu @ 2026-05-18 11:29 UTC (permalink / raw)
  To: Vipin Sharma, pasha.tatashin, rppt, pratyush
  Cc: shuah, dmatlack, skhawaja, linux-kernel, linux-kselftest,
	Vipin Sharma

Vipin Sharma <vipinsh@google.com> writes:

> Add helper functions to preserve and retrieve file descriptors from an
> LUO session. This allows library users to work with FD preservation.
>
> No functional change intended.
>
> Signed-off-by: Vipin Sharma <vipinsh@google.com>
> Co-developed-by: David Matlack <dmatlack@google.com>
> Signed-off-by: David Matlack <dmatlack@google.com>
> Signed-off-by: Vipin Sharma <vipinsh@google.com>
> ---
>  .../liveupdate/lib/include/libliveupdate.h    |  3 ++
>  .../selftests/liveupdate/lib/liveupdate.c     | 41 +++++++++++++++----
>  2 files changed, 35 insertions(+), 9 deletions(-)
>
> diff --git a/tools/testing/selftests/liveupdate/lib/include/libliveupdate.h b/tools/testing/selftests/liveupdate/lib/include/libliveupdate.h
> index 4390a2737930..2b04b3256382 100644
> --- a/tools/testing/selftests/liveupdate/lib/include/libliveupdate.h
> +++ b/tools/testing/selftests/liveupdate/lib/include/libliveupdate.h
> @@ -26,6 +26,9 @@ int luo_create_session(int luo_fd, const char *name);
>  int luo_retrieve_session(int luo_fd, const char *name);
>  int luo_session_finish(int session_fd);
>  
> +int luo_session_preserve_fd(int session_fd, int fd, __u64 token);
> +int luo_session_retrieve_fd(int session_fd, __u64 token);
> +
>  int create_and_preserve_memfd(int session_fd, int token, const char *data);
>  int restore_and_verify_memfd(int session_fd, int token, const char *expected_data);
>  
> diff --git a/tools/testing/selftests/liveupdate/lib/liveupdate.c b/tools/testing/selftests/liveupdate/lib/liveupdate.c
> index 60121873f685..7bc6707d8bb7 100644
> --- a/tools/testing/selftests/liveupdate/lib/liveupdate.c
> +++ b/tools/testing/selftests/liveupdate/lib/liveupdate.c
> @@ -54,9 +54,35 @@ int luo_retrieve_session(int luo_fd, const char *name)
>  	return arg.fd;
>  }
>  
> +int luo_session_preserve_fd(int session_fd, int fd, __u64 token)
> +{
> +	struct liveupdate_session_preserve_fd arg = {
> +		.size = sizeof(arg),
> +		.fd = fd,
> +		.token = token,
> +	};
> +
> +	if (ioctl(session_fd, LIVEUPDATE_SESSION_PRESERVE_FD, &arg) < 0)
> +		return -errno;
> +
> +	return 0;
> +}
> +
> +int luo_session_retrieve_fd(int session_fd, __u64 token)
nit: Can add a comment that, once it is failed, retrieved status is saved,
So it is permanent failure.
> +{
> +	struct liveupdate_session_retrieve_fd arg = {
> +		.size = sizeof(arg),
> +		.token = token,
> +	};
> +
> +	if (ioctl(session_fd, LIVEUPDATE_SESSION_RETRIEVE_FD, &arg) < 0)
> +		return -errno;
> +
> +	return arg.fd;
> +}
> +
>  int create_and_preserve_memfd(int session_fd, int token, const char *data)
>  {
> -	struct liveupdate_session_preserve_fd arg = { .size = sizeof(arg) };
>  	long page_size = sysconf(_SC_PAGE_SIZE);
>  	void *map = MAP_FAILED;
>  	int mfd = -1, ret = -1;
> @@ -75,9 +101,8 @@ int create_and_preserve_memfd(int session_fd, int token, const char *data)
>  	snprintf(map, page_size, "%s", data);
>  	munmap(map, page_size);
>  
> -	arg.fd = mfd;
> -	arg.token = token;
> -	if (ioctl(session_fd, LIVEUPDATE_SESSION_PRESERVE_FD, &arg) < 0)
> +	ret = luo_session_preserve_fd(session_fd, mfd, token);
> +	if (ret)
>  		goto out;
>  
>  	ret = 0;
> @@ -92,15 +117,13 @@ int create_and_preserve_memfd(int session_fd, int token, const char *data)
>  int restore_and_verify_memfd(int session_fd, int token,
>  			     const char *expected_data)
>  {
> -	struct liveupdate_session_retrieve_fd arg = { .size = sizeof(arg) };
>  	long page_size = sysconf(_SC_PAGE_SIZE);
>  	void *map = MAP_FAILED;
>  	int mfd = -1, ret = -1;
>  
> -	arg.token = token;
> -	if (ioctl(session_fd, LIVEUPDATE_SESSION_RETRIEVE_FD, &arg) < 0)
> -		return -errno;
> -	mfd = arg.fd;
> +	mfd = luo_session_retrieve_fd(session_fd, token);
> +	if (mfd < 0)
> +		return mfd;
>  
>  	map = mmap(NULL, page_size, PROT_READ, MAP_SHARED, mfd, 0);
>  	if (map == MAP_FAILED)
> -- 
> 2.54.0.563.g4f69b47b94-goog

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

* Re: [PATCH 2/2] selftests/liveupdate: Add helpers to preserve/retrieve FDs
  2026-05-18 11:29   ` tarunsahu
@ 2026-05-18 17:14     ` Vipin Sharma
  2026-06-08 14:32       ` Pratyush Yadav
  0 siblings, 1 reply; 9+ messages in thread
From: Vipin Sharma @ 2026-05-18 17:14 UTC (permalink / raw)
  To: tarunsahu
  Cc: pasha.tatashin, rppt, pratyush, shuah, dmatlack, skhawaja,
	linux-kernel, linux-kselftest

On Mon, May 18, 2026 at 11:29:49AM +0000, tarunsahu@google.com wrote:
> Vipin Sharma <vipinsh@google.com> writes:
> 
> > Add helper functions to preserve and retrieve file descriptors from an
> > LUO session. This allows library users to work with FD preservation.
> >
> > No functional change intended.
> >
> > Signed-off-by: Vipin Sharma <vipinsh@google.com>
> > Co-developed-by: David Matlack <dmatlack@google.com>
> > Signed-off-by: David Matlack <dmatlack@google.com>
> > Signed-off-by: Vipin Sharma <vipinsh@google.com>
> > ---
> >  .../liveupdate/lib/include/libliveupdate.h    |  3 ++
> >  .../selftests/liveupdate/lib/liveupdate.c     | 41 +++++++++++++++----
> >  2 files changed, 35 insertions(+), 9 deletions(-)
> >
> > diff --git a/tools/testing/selftests/liveupdate/lib/include/libliveupdate.h b/tools/testing/selftests/liveupdate/lib/include/libliveupdate.h
> > index 4390a2737930..2b04b3256382 100644
> > --- a/tools/testing/selftests/liveupdate/lib/include/libliveupdate.h
> > +++ b/tools/testing/selftests/liveupdate/lib/include/libliveupdate.h
> > @@ -26,6 +26,9 @@ int luo_create_session(int luo_fd, const char *name);
> >  int luo_retrieve_session(int luo_fd, const char *name);
> >  int luo_session_finish(int session_fd);
> >  
> > +int luo_session_preserve_fd(int session_fd, int fd, __u64 token);
> > +int luo_session_retrieve_fd(int session_fd, __u64 token);
> > +
> >  int create_and_preserve_memfd(int session_fd, int token, const char *data);
> >  int restore_and_verify_memfd(int session_fd, int token, const char *expected_data);
> >  
> > diff --git a/tools/testing/selftests/liveupdate/lib/liveupdate.c b/tools/testing/selftests/liveupdate/lib/liveupdate.c
> > index 60121873f685..7bc6707d8bb7 100644
> > --- a/tools/testing/selftests/liveupdate/lib/liveupdate.c
> > +++ b/tools/testing/selftests/liveupdate/lib/liveupdate.c
> > @@ -54,9 +54,35 @@ int luo_retrieve_session(int luo_fd, const char *name)
> >  	return arg.fd;
> >  }
> >  
> > +int luo_session_preserve_fd(int session_fd, int fd, __u64 token)
> > +{
> > +	struct liveupdate_session_preserve_fd arg = {
> > +		.size = sizeof(arg),
> > +		.fd = fd,
> > +		.token = token,
> > +	};
> > +
> > +	if (ioctl(session_fd, LIVEUPDATE_SESSION_PRESERVE_FD, &arg) < 0)
> > +		return -errno;
> > +
> > +	return 0;
> > +}
> > +
> > +int luo_session_retrieve_fd(int session_fd, __u64 token)
> nit: Can add a comment that, once it is failed, retrieved status is saved,
> So it is permanent failure.

I think appropriate place will be the official documentation which is
here include/uapi/linux/liveupdate.h

I don't see it is mentioned in the documentation (yes, code does what
you have said), I will refrain from adding that comment here.

> > +{
> > +	struct liveupdate_session_retrieve_fd arg = {
> > +		.size = sizeof(arg),
> > +		.token = token,
> > +	};
> > +
> > +	if (ioctl(session_fd, LIVEUPDATE_SESSION_RETRIEVE_FD, &arg) < 0)
> > +		return -errno;
> > +
> > +	return arg.fd;
> > +}
> > +
> >  int create_and_preserve_memfd(int session_fd, int token, const char *data)
> >  {
> > -	struct liveupdate_session_preserve_fd arg = { .size = sizeof(arg) };
> >  	long page_size = sysconf(_SC_PAGE_SIZE);
> >  	void *map = MAP_FAILED;
> >  	int mfd = -1, ret = -1;
> > @@ -75,9 +101,8 @@ int create_and_preserve_memfd(int session_fd, int token, const char *data)
> >  	snprintf(map, page_size, "%s", data);
> >  	munmap(map, page_size);
> >  
> > -	arg.fd = mfd;
> > -	arg.token = token;
> > -	if (ioctl(session_fd, LIVEUPDATE_SESSION_PRESERVE_FD, &arg) < 0)
> > +	ret = luo_session_preserve_fd(session_fd, mfd, token);
> > +	if (ret)
> >  		goto out;
> >  
> >  	ret = 0;
> > @@ -92,15 +117,13 @@ int create_and_preserve_memfd(int session_fd, int token, const char *data)
> >  int restore_and_verify_memfd(int session_fd, int token,
> >  			     const char *expected_data)
> >  {
> > -	struct liveupdate_session_retrieve_fd arg = { .size = sizeof(arg) };
> >  	long page_size = sysconf(_SC_PAGE_SIZE);
> >  	void *map = MAP_FAILED;
> >  	int mfd = -1, ret = -1;
> >  
> > -	arg.token = token;
> > -	if (ioctl(session_fd, LIVEUPDATE_SESSION_RETRIEVE_FD, &arg) < 0)
> > -		return -errno;
> > -	mfd = arg.fd;
> > +	mfd = luo_session_retrieve_fd(session_fd, token);
> > +	if (mfd < 0)
> > +		return mfd;
> >  
> >  	map = mmap(NULL, page_size, PROT_READ, MAP_SHARED, mfd, 0);
> >  	if (map == MAP_FAILED)
> > -- 
> > 2.54.0.563.g4f69b47b94-goog

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

* Re: [PATCH 1/2] selftests/liveupdate: Move luo_test_utils.* into a reusable library
  2026-05-11 20:11 ` [PATCH 1/2] selftests/liveupdate: Move luo_test_utils.* into a reusable library Vipin Sharma
@ 2026-06-08 14:31   ` Pratyush Yadav
  0 siblings, 0 replies; 9+ messages in thread
From: Pratyush Yadav @ 2026-06-08 14:31 UTC (permalink / raw)
  To: Vipin Sharma
  Cc: pasha.tatashin, rppt, pratyush, shuah, dmatlack, skhawaja,
	tarunsahu, linux-kernel, linux-kselftest

On Mon, May 11 2026, Vipin Sharma wrote:

> Move luo_test_utils.[ch] into a lib/ directory and pull the rules to
> build them out into a separate make script. This will enable these
> utilities to be also built by and used within other selftests (such as
> VFIO).
>
> No functional change intended.
>
> Signed-off-by: Vipin Sharma <vipinsh@google.com>
> Co-developed-by: David Matlack <dmatlack@google.com>
> Signed-off-by: David Matlack <dmatlack@google.com>
> Signed-off-by: Vipin Sharma <vipinsh@google.com>
> ---
>  tools/testing/selftests/liveupdate/.gitignore |  1 +
>  tools/testing/selftests/liveupdate/Makefile   | 14 ++++---------
>  .../include/libliveupdate.h}                  |  8 ++++----

Nit: perhaps libluo is a bit less wordy?

No strong opinions on it though, so I am fine with anything.

[...]
> diff --git a/tools/testing/selftests/liveupdate/lib/libliveupdate.mk b/tools/testing/selftests/liveupdate/lib/libliveupdate.mk
> new file mode 100644
> index 000000000000..fffd95b085b6
> --- /dev/null
> +++ b/tools/testing/selftests/liveupdate/lib/libliveupdate.mk
> @@ -0,0 +1,20 @@
> +include $(top_srcdir)/scripts/subarch.include
> +ARCH ?= $(SUBARCH)
> +
> +LIBLIVEUPDATE_SRCDIR := $(selfdir)/liveupdate/lib
> +
> +LIBLIVEUPDATE_C := liveupdate.c
> +
> +LIBLIVEUPDATE_OUTPUT := $(OUTPUT)/libliveupdate
> +
> +LIBLIVEUPDATE_O := $(patsubst %.c, $(LIBLIVEUPDATE_OUTPUT)/%.o, $(LIBLIVEUPDATE_C))
> +
> +LIBLIVEUPDATE_O_DIRS := $(shell dirname $(LIBLIVEUPDATE_O) | uniq)
> +$(shell mkdir -p $(LIBLIVEUPDATE_O_DIRS))

Sashiko complains about this:
https://sashiko.dev/#/patchset/20260511201155.1488670-1-vipinsh%40google.com

    Does this execute the directory creation unconditionally during Make parsing?
    Because it uses the shell function at the top level, this directory creation
    will run on every Make invocation, including utility targets like make clean
    or make help.
    
    Could the shell dirname command also be fragile if LIBLIVEUPDATE_O ever
    expands to multiple files? Strictly POSIX-compliant systems only accept a
    single argument for dirname.
    
    Would it be better to use GNU Make's built-in $(dir ...) function and move
    the directory creation into the compilation recipe below (e.g.,
    @mkdir -p $(dir $@)), or use an order-only prerequisite?

The first one seems to make sense. The second one not so much. The third
I have no idea. I don't know Makefiles well enough.

Perhaps worth a look?

With these comments addressed, feel free to add

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

> +
> +CFLAGS += -I$(LIBLIVEUPDATE_SRCDIR)/include
> +
> +$(LIBLIVEUPDATE_O): $(LIBLIVEUPDATE_OUTPUT)/%.o : $(LIBLIVEUPDATE_SRCDIR)/%.c
> +	$(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c $< -o $@
> +
> +EXTRA_CLEAN += $(LIBLIVEUPDATE_OUTPUT)
[...]

-- 
Regards,
Pratyush Yadav

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

* Re: [PATCH 2/2] selftests/liveupdate: Add helpers to preserve/retrieve FDs
  2026-05-18 17:14     ` Vipin Sharma
@ 2026-06-08 14:32       ` Pratyush Yadav
  2026-06-08 18:44         ` tarunsahu
  0 siblings, 1 reply; 9+ messages in thread
From: Pratyush Yadav @ 2026-06-08 14:32 UTC (permalink / raw)
  To: Vipin Sharma
  Cc: tarunsahu, pasha.tatashin, rppt, pratyush, shuah, dmatlack,
	skhawaja, linux-kernel, linux-kselftest

On Mon, May 18 2026, Vipin Sharma wrote:

> On Mon, May 18, 2026 at 11:29:49AM +0000, tarunsahu@google.com wrote:
>> Vipin Sharma <vipinsh@google.com> writes:
>> 
>> > Add helper functions to preserve and retrieve file descriptors from an
>> > LUO session. This allows library users to work with FD preservation.
>> >
>> > No functional change intended.
>> >
>> > Signed-off-by: Vipin Sharma <vipinsh@google.com>
>> > Co-developed-by: David Matlack <dmatlack@google.com>
>> > Signed-off-by: David Matlack <dmatlack@google.com>
>> > Signed-off-by: Vipin Sharma <vipinsh@google.com>
>> > ---
>> >  .../liveupdate/lib/include/libliveupdate.h    |  3 ++
>> >  .../selftests/liveupdate/lib/liveupdate.c     | 41 +++++++++++++++----
>> >  2 files changed, 35 insertions(+), 9 deletions(-)
>> >
>> > diff --git a/tools/testing/selftests/liveupdate/lib/include/libliveupdate.h b/tools/testing/selftests/liveupdate/lib/include/libliveupdate.h
>> > index 4390a2737930..2b04b3256382 100644
>> > --- a/tools/testing/selftests/liveupdate/lib/include/libliveupdate.h
>> > +++ b/tools/testing/selftests/liveupdate/lib/include/libliveupdate.h
>> > @@ -26,6 +26,9 @@ int luo_create_session(int luo_fd, const char *name);
>> >  int luo_retrieve_session(int luo_fd, const char *name);
>> >  int luo_session_finish(int session_fd);
>> >  
>> > +int luo_session_preserve_fd(int session_fd, int fd, __u64 token);
>> > +int luo_session_retrieve_fd(int session_fd, __u64 token);
>> > +
>> >  int create_and_preserve_memfd(int session_fd, int token, const char *data);
>> >  int restore_and_verify_memfd(int session_fd, int token, const char *expected_data);
>> >  
>> > diff --git a/tools/testing/selftests/liveupdate/lib/liveupdate.c b/tools/testing/selftests/liveupdate/lib/liveupdate.c
>> > index 60121873f685..7bc6707d8bb7 100644
>> > --- a/tools/testing/selftests/liveupdate/lib/liveupdate.c
>> > +++ b/tools/testing/selftests/liveupdate/lib/liveupdate.c
>> > @@ -54,9 +54,35 @@ int luo_retrieve_session(int luo_fd, const char *name)
>> >  	return arg.fd;
>> >  }
>> >  
>> > +int luo_session_preserve_fd(int session_fd, int fd, __u64 token)
>> > +{
>> > +	struct liveupdate_session_preserve_fd arg = {
>> > +		.size = sizeof(arg),
>> > +		.fd = fd,
>> > +		.token = token,
>> > +	};
>> > +
>> > +	if (ioctl(session_fd, LIVEUPDATE_SESSION_PRESERVE_FD, &arg) < 0)
>> > +		return -errno;
>> > +
>> > +	return 0;
>> > +}
>> > +
>> > +int luo_session_retrieve_fd(int session_fd, __u64 token)
>> nit: Can add a comment that, once it is failed, retrieved status is saved,
>> So it is permanent failure.
>
> I think appropriate place will be the official documentation which is
> here include/uapi/linux/liveupdate.h
>
> I don't see it is mentioned in the documentation (yes, code does what
> you have said), I will refrain from adding that comment here.

Would be a good addition to the LUO docs I think. Patches welcome :-)

[...]

-- 
Regards,
Pratyush Yadav

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

* Re: [PATCH 2/2] selftests/liveupdate: Add helpers to preserve/retrieve FDs
  2026-05-11 20:11 ` [PATCH 2/2] selftests/liveupdate: Add helpers to preserve/retrieve FDs Vipin Sharma
  2026-05-18 11:29   ` tarunsahu
@ 2026-06-08 14:38   ` Pratyush Yadav
  1 sibling, 0 replies; 9+ messages in thread
From: Pratyush Yadav @ 2026-06-08 14:38 UTC (permalink / raw)
  To: Vipin Sharma
  Cc: pasha.tatashin, rppt, pratyush, shuah, dmatlack, skhawaja,
	tarunsahu, linux-kernel, linux-kselftest

On Mon, May 11 2026, Vipin Sharma wrote:

> Add helper functions to preserve and retrieve file descriptors from an
> LUO session. This allows library users to work with FD preservation.
>
> No functional change intended.
>
> Signed-off-by: Vipin Sharma <vipinsh@google.com>
> Co-developed-by: David Matlack <dmatlack@google.com>
> Signed-off-by: David Matlack <dmatlack@google.com>
> Signed-off-by: Vipin Sharma <vipinsh@google.com>
> ---
>  .../liveupdate/lib/include/libliveupdate.h    |  3 ++
>  .../selftests/liveupdate/lib/liveupdate.c     | 41 +++++++++++++++----
>  2 files changed, 35 insertions(+), 9 deletions(-)
>
> diff --git a/tools/testing/selftests/liveupdate/lib/include/libliveupdate.h b/tools/testing/selftests/liveupdate/lib/include/libliveupdate.h
> index 4390a2737930..2b04b3256382 100644
> --- a/tools/testing/selftests/liveupdate/lib/include/libliveupdate.h
> +++ b/tools/testing/selftests/liveupdate/lib/include/libliveupdate.h
> @@ -26,6 +26,9 @@ int luo_create_session(int luo_fd, const char *name);
>  int luo_retrieve_session(int luo_fd, const char *name);
>  int luo_session_finish(int session_fd);
>  
> +int luo_session_preserve_fd(int session_fd, int fd, __u64 token);
> +int luo_session_retrieve_fd(int session_fd, __u64 token);
> +
>  int create_and_preserve_memfd(int session_fd, int token, const char *data);
>  int restore_and_verify_memfd(int session_fd, int token, const char *expected_data);
>  
> diff --git a/tools/testing/selftests/liveupdate/lib/liveupdate.c b/tools/testing/selftests/liveupdate/lib/liveupdate.c
> index 60121873f685..7bc6707d8bb7 100644
> --- a/tools/testing/selftests/liveupdate/lib/liveupdate.c
> +++ b/tools/testing/selftests/liveupdate/lib/liveupdate.c
> @@ -54,9 +54,35 @@ int luo_retrieve_session(int luo_fd, const char *name)
>  	return arg.fd;
>  }
>  
> +int luo_session_preserve_fd(int session_fd, int fd, __u64 token)
> +{
> +	struct liveupdate_session_preserve_fd arg = {
> +		.size = sizeof(arg),
> +		.fd = fd,
> +		.token = token,
> +	};
> +
> +	if (ioctl(session_fd, LIVEUPDATE_SESSION_PRESERVE_FD, &arg) < 0)
> +		return -errno;
> +
> +	return 0;
> +}
> +
> +int luo_session_retrieve_fd(int session_fd, __u64 token)
> +{
> +	struct liveupdate_session_retrieve_fd arg = {
> +		.size = sizeof(arg),
> +		.token = token,
> +	};
> +
> +	if (ioctl(session_fd, LIVEUPDATE_SESSION_RETRIEVE_FD, &arg) < 0)
> +		return -errno;
> +
> +	return arg.fd;
> +}
> +
>  int create_and_preserve_memfd(int session_fd, int token, const char *data)
>  {
> -	struct liveupdate_session_preserve_fd arg = { .size = sizeof(arg) };
>  	long page_size = sysconf(_SC_PAGE_SIZE);
>  	void *map = MAP_FAILED;
>  	int mfd = -1, ret = -1;
> @@ -75,9 +101,8 @@ int create_and_preserve_memfd(int session_fd, int token, const char *data)
>  	snprintf(map, page_size, "%s", data);
>  	munmap(map, page_size);
>  
> -	arg.fd = mfd;
> -	arg.token = token;
> -	if (ioctl(session_fd, LIVEUPDATE_SESSION_PRESERVE_FD, &arg) < 0)
> +	ret = luo_session_preserve_fd(session_fd, mfd, token);
> +	if (ret)
>  		goto out;
>  
>  	ret = 0;
> @@ -92,15 +117,13 @@ int create_and_preserve_memfd(int session_fd, int token, const char *data)
>  int restore_and_verify_memfd(int session_fd, int token,
>  			     const char *expected_data)
>  {
> -	struct liveupdate_session_retrieve_fd arg = { .size = sizeof(arg) };
>  	long page_size = sysconf(_SC_PAGE_SIZE);
>  	void *map = MAP_FAILED;
>  	int mfd = -1, ret = -1;
>  
> -	arg.token = token;
> -	if (ioctl(session_fd, LIVEUPDATE_SESSION_RETRIEVE_FD, &arg) < 0)
> -		return -errno;
> -	mfd = arg.fd;
> +	mfd = luo_session_retrieve_fd(session_fd, token);
> +	if (mfd < 0)
> +		return mfd;

There is also preserve_fd() in selftests/liveupdate/liveupdate.c which
pretty much does what your luo_session_preserve_fd() does. I think you
should remove it and make its callers use the new library.

LGTM otherwise.

>  
>  	map = mmap(NULL, page_size, PROT_READ, MAP_SHARED, mfd, 0);
>  	if (map == MAP_FAILED)

-- 
Regards,
Pratyush Yadav

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

* Re: [PATCH 2/2] selftests/liveupdate: Add helpers to preserve/retrieve FDs
  2026-06-08 14:32       ` Pratyush Yadav
@ 2026-06-08 18:44         ` tarunsahu
  0 siblings, 0 replies; 9+ messages in thread
From: tarunsahu @ 2026-06-08 18:44 UTC (permalink / raw)
  To: Pratyush Yadav, Vipin Sharma
  Cc: pasha.tatashin, rppt, pratyush, shuah, dmatlack, skhawaja,
	linux-kernel, linux-kselftest

Pratyush Yadav <pratyush@kernel.org> writes:

>>> > +	return 0;
>>> > +}
>>> > +
>>> > +int luo_session_retrieve_fd(int session_fd, __u64 token)
>>> nit: Can add a comment that, once it is failed, retrieved status is saved,
>>> So it is permanent failure.
>>
>> I think appropriate place will be the official documentation which is
>> here include/uapi/linux/liveupdate.h
>>
>> I don't see it is mentioned in the documentation (yes, code does what
>> you have said), I will refrain from adding that comment here.
>
> Would be a good addition to the LUO docs I think. Patches welcome :-)

Added here:
https://lore.kernel.org/all/074445fc4964961f12171ea129f2a7690322a78a.1780944056.git.tarunsahu@google.com/

>
> [...]
>
> -- 
> Regards,
> Pratyush Yadav

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

end of thread, other threads:[~2026-06-08 18:44 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-11 20:11 [PATCH 0/2] Make liveupdate selftests util as a library Vipin Sharma
2026-05-11 20:11 ` [PATCH 1/2] selftests/liveupdate: Move luo_test_utils.* into a reusable library Vipin Sharma
2026-06-08 14:31   ` Pratyush Yadav
2026-05-11 20:11 ` [PATCH 2/2] selftests/liveupdate: Add helpers to preserve/retrieve FDs Vipin Sharma
2026-05-18 11:29   ` tarunsahu
2026-05-18 17:14     ` Vipin Sharma
2026-06-08 14:32       ` Pratyush Yadav
2026-06-08 18:44         ` tarunsahu
2026-06-08 14:38   ` Pratyush Yadav

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.