* [PATCH v3 0/2] Make liveupdate selftests library
@ 2026-06-12 21:45 Vipin Sharma
2026-06-12 21:45 ` [PATCH v3 1/2] selftests/liveupdate: Use luo_test_utils.c for liveupdate ioctl APIs Vipin Sharma
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Vipin Sharma @ 2026-06-12 21:45 UTC (permalink / raw)
To: pasha.tatashin, rppt, pratyush
Cc: tarunsahu, skhawaja, shuah, dmatlack, linux-kernel, kexec,
linux-kselftest, Vipin Sharma
Hello,
This is v3 series of refactoring liveupdate selftests as a library. It
exposes common liveupdate ioctls as a library which can be used by other
selftests like VFIO and IOMMU.
Currently, there are no users of this change but it is being used in
VFIO and iommu liveupdate series.
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 from the above series and
propose them as a separate series for inclusion in 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.
v3:
- Renamed liveupdate.c in the library to lu_utils.c
- Reordered patches, first abstract out ioctls to utils file then
create libary.
- Using stricter check for ioctls.
- Reordered header include, also, keeping c lib headers as a separate
block.
v2: https://lore.kernel.org/kexec/20260610230909.876546-1-vipinsh@google.com/
- Addressed Sashiko feedback regarding folder creation.
https://sashiko.dev/#/patchset/20260511201155.1488670-1-vipinsh%40google.com
- Update liveupdate.c test to use ioctl wrappers in library
v1: https://lore.kernel.org/all/20260511201155.1488670-1-vipinsh@google.com/
Vipin Sharma (2):
selftests/liveupdate: Use luo_test_utils.c for liveupdate ioctl APIs
selftests/liveupdate: Move luo_test_utils.* into a reusable library
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/lu_utils.c} | 63 +++++++++--
.../testing/selftests/liveupdate/liveupdate.c | 106 +++++-------------
.../selftests/liveupdate/luo_kexec_simple.c | 2 +-
.../selftests/liveupdate/luo_multi_session.c | 2 +-
.../selftests/liveupdate/luo_stress_files.c | 3 +-
.../liveupdate/luo_stress_sessions.c | 3 +-
10 files changed, 120 insertions(+), 105 deletions(-)
rename tools/testing/selftests/liveupdate/{luo_test_utils.h => lib/include/libliveupdate.h} (77%)
create mode 100644 tools/testing/selftests/liveupdate/lib/libliveupdate.mk
rename tools/testing/selftests/liveupdate/{luo_test_utils.c => lib/lu_utils.c} (83%)
base-commit: 3a358c78093f98a70d84c934b7054f636bc846f2
--
2.54.0.1136.gdb2ca164c4-goog
^ permalink raw reply [flat|nested] 6+ messages in thread* [PATCH v3 1/2] selftests/liveupdate: Use luo_test_utils.c for liveupdate ioctl APIs 2026-06-12 21:45 [PATCH v3 0/2] Make liveupdate selftests library Vipin Sharma @ 2026-06-12 21:45 ` Vipin Sharma 2026-06-12 21:45 ` [PATCH v3 2/2] selftests/liveupdate: Move luo_test_utils.* into a reusable library Vipin Sharma 2026-06-17 18:54 ` [PATCH v3 0/2] Make liveupdate selftests library Mike Rapoport 2 siblings, 0 replies; 6+ messages in thread From: Vipin Sharma @ 2026-06-12 21:45 UTC (permalink / raw) To: pasha.tatashin, rppt, pratyush Cc: tarunsahu, skhawaja, shuah, dmatlack, linux-kernel, kexec, linux-kselftest, Vipin Sharma Use luo_test_utils.c for all live update ioctl calls. Remove direct ioctl calls in liveupdate.c. This avoids code duplication and use common interface. While at it, make ioctl error check stricter as liveupdate APIs don't return postive numbers as a valid result. Co-developed-by: David Matlack <dmatlack@google.com> Signed-off-by: David Matlack <dmatlack@google.com> Reviewed-by: Pasha Tatashin <pasha.tatashin@soleen.com> Reviewed-by: Pratyush Yadav (Google) <pratyush@kernel.org> Signed-off-by: Vipin Sharma <vipinsh@google.com> --- .../testing/selftests/liveupdate/liveupdate.c | 104 +++++------------- .../selftests/liveupdate/luo_test_utils.c | 61 ++++++++-- .../selftests/liveupdate/luo_test_utils.h | 3 + 3 files changed, 83 insertions(+), 85 deletions(-) diff --git a/tools/testing/selftests/liveupdate/liveupdate.c b/tools/testing/selftests/liveupdate/liveupdate.c index 502fb3567e38..5c7ed2512710 100644 --- a/tools/testing/selftests/liveupdate/liveupdate.c +++ b/tools/testing/selftests/liveupdate/liveupdate.c @@ -89,36 +89,6 @@ TEST_F(liveupdate_device, exclusive_open) EXPECT_EQ(errno, EBUSY); } -/* Helper function to create a LUO session via ioctl. */ -static int create_session(int lu_fd, const char *name) -{ - struct liveupdate_ioctl_create_session args = {}; - - args.size = sizeof(args); - strncpy((char *)args.name, name, sizeof(args.name) - 1); - - if (ioctl(lu_fd, LIVEUPDATE_IOCTL_CREATE_SESSION, &args)) - return -errno; - - return args.fd; -} - -/* Helper function to get a session name via ioctl. */ -static int get_session_name(int session_fd, char *name, size_t name_len) -{ - struct liveupdate_session_get_name args = {}; - - args.size = sizeof(args); - - if (ioctl(session_fd, LIVEUPDATE_SESSION_GET_NAME, &args)) - return -errno; - - strncpy(name, (char *)args.name, name_len - 1); - name[name_len - 1] = '\0'; - - return 0; -} - /* * Test Case: Create Duplicate Session * @@ -135,10 +105,10 @@ TEST_F(liveupdate_device, create_duplicate_session) ASSERT_GE(self->fd1, 0); - session_fd1 = create_session(self->fd1, "duplicate-session-test"); + session_fd1 = luo_create_session(self->fd1, "duplicate-session-test"); ASSERT_GE(session_fd1, 0); - session_fd2 = create_session(self->fd1, "duplicate-session-test"); + session_fd2 = luo_create_session(self->fd1, "duplicate-session-test"); EXPECT_LT(session_fd2, 0); EXPECT_EQ(-session_fd2, EEXIST); @@ -160,30 +130,16 @@ TEST_F(liveupdate_device, create_distinct_sessions) ASSERT_GE(self->fd1, 0); - session_fd1 = create_session(self->fd1, "distinct-session-1"); + session_fd1 = luo_create_session(self->fd1, "distinct-session-1"); ASSERT_GE(session_fd1, 0); - session_fd2 = create_session(self->fd1, "distinct-session-2"); + session_fd2 = luo_create_session(self->fd1, "distinct-session-2"); ASSERT_GE(session_fd2, 0); ASSERT_EQ(close(session_fd1), 0); ASSERT_EQ(close(session_fd2), 0); } -static int preserve_fd(int session_fd, int fd_to_preserve, __u64 token) -{ - struct liveupdate_session_preserve_fd args = {}; - - args.size = sizeof(args); - args.fd = fd_to_preserve; - args.token = token; - - if (ioctl(session_fd, LIVEUPDATE_SESSION_PRESERVE_FD, &args)) - return -errno; - - return 0; -} - /* * Test Case: Preserve MemFD * @@ -201,14 +157,14 @@ TEST_F(liveupdate_device, preserve_memfd) SKIP(return, "%s does not exist", LIVEUPDATE_DEV); ASSERT_GE(self->fd1, 0); - session_fd = create_session(self->fd1, "preserve-memfd-test"); + session_fd = luo_create_session(self->fd1, "preserve-memfd-test"); ASSERT_GE(session_fd, 0); mem_fd = memfd_create("test-memfd", 0); ASSERT_GE(mem_fd, 0); ASSERT_EQ(write(mem_fd, test_str, strlen(test_str)), strlen(test_str)); - ASSERT_EQ(preserve_fd(session_fd, mem_fd, 0x1234), 0); + ASSERT_EQ(luo_session_preserve_fd(session_fd, mem_fd, 0x1234), 0); ASSERT_EQ(close(session_fd), 0); ASSERT_EQ(lseek(mem_fd, 0, SEEK_SET), 0); @@ -236,7 +192,7 @@ TEST_F(liveupdate_device, preserve_multiple_memfds) SKIP(return, "%s does not exist", LIVEUPDATE_DEV); ASSERT_GE(self->fd1, 0); - session_fd = create_session(self->fd1, "preserve-multi-memfd-test"); + session_fd = luo_create_session(self->fd1, "preserve-multi-memfd-test"); ASSERT_GE(session_fd, 0); mem_fd1 = memfd_create("test-memfd-1", 0); @@ -247,8 +203,8 @@ TEST_F(liveupdate_device, preserve_multiple_memfds) ASSERT_EQ(write(mem_fd1, test_str1, strlen(test_str1)), strlen(test_str1)); ASSERT_EQ(write(mem_fd2, test_str2, strlen(test_str2)), strlen(test_str2)); - ASSERT_EQ(preserve_fd(session_fd, mem_fd1, 0xAAAA), 0); - ASSERT_EQ(preserve_fd(session_fd, mem_fd2, 0xBBBB), 0); + ASSERT_EQ(luo_session_preserve_fd(session_fd, mem_fd1, 0xAAAA), 0); + ASSERT_EQ(luo_session_preserve_fd(session_fd, mem_fd2, 0xBBBB), 0); memset(read_buf, 0, sizeof(read_buf)); ASSERT_EQ(lseek(mem_fd1, 0, SEEK_SET), 0); @@ -284,9 +240,9 @@ TEST_F(liveupdate_device, preserve_complex_scenario) SKIP(return, "%s does not exist", LIVEUPDATE_DEV); ASSERT_GE(self->fd1, 0); - session_fd1 = create_session(self->fd1, "complex-session-1"); + session_fd1 = luo_create_session(self->fd1, "complex-session-1"); ASSERT_GE(session_fd1, 0); - session_fd2 = create_session(self->fd1, "complex-session-2"); + session_fd2 = luo_create_session(self->fd1, "complex-session-2"); ASSERT_GE(session_fd2, 0); mem_fd_data1 = memfd_create("data1", 0); @@ -303,10 +259,10 @@ TEST_F(liveupdate_device, preserve_complex_scenario) mem_fd_empty2 = memfd_create("empty2", 0); ASSERT_GE(mem_fd_empty2, 0); - ASSERT_EQ(preserve_fd(session_fd1, mem_fd_data1, 0x1111), 0); - ASSERT_EQ(preserve_fd(session_fd1, mem_fd_empty1, 0x2222), 0); - ASSERT_EQ(preserve_fd(session_fd2, mem_fd_data2, 0x3333), 0); - ASSERT_EQ(preserve_fd(session_fd2, mem_fd_empty2, 0x4444), 0); + ASSERT_EQ(luo_session_preserve_fd(session_fd1, mem_fd_data1, 0x1111), 0); + ASSERT_EQ(luo_session_preserve_fd(session_fd1, mem_fd_empty1, 0x2222), 0); + ASSERT_EQ(luo_session_preserve_fd(session_fd2, mem_fd_data2, 0x3333), 0); + ASSERT_EQ(luo_session_preserve_fd(session_fd2, mem_fd_empty2, 0x4444), 0); ASSERT_EQ(lseek(mem_fd_data1, 0, SEEK_SET), 0); ASSERT_EQ(read(mem_fd_data1, read_buf, sizeof(read_buf)), strlen(data1)); @@ -349,13 +305,13 @@ TEST_F(liveupdate_device, preserve_unsupported_fd) SKIP(return, "%s does not exist", LIVEUPDATE_DEV); ASSERT_GE(self->fd1, 0); - session_fd = create_session(self->fd1, "unsupported-fd-test"); + session_fd = luo_create_session(self->fd1, "unsupported-fd-test"); ASSERT_GE(session_fd, 0); unsupported_fd = open("/dev/null", O_RDWR); ASSERT_GE(unsupported_fd, 0); - ret = preserve_fd(session_fd, unsupported_fd, 0xDEAD); + ret = luo_session_preserve_fd(session_fd, unsupported_fd, 0xDEAD); EXPECT_EQ(ret, -ENOENT); ASSERT_EQ(close(unsupported_fd), 0); @@ -379,23 +335,23 @@ TEST_F(liveupdate_device, prevent_double_preservation) SKIP(return, "%s does not exist", LIVEUPDATE_DEV); ASSERT_GE(self->fd1, 0); - session_fd1 = create_session(self->fd1, "double-preserve-session-1"); + session_fd1 = luo_create_session(self->fd1, "double-preserve-session-1"); ASSERT_GE(session_fd1, 0); - session_fd2 = create_session(self->fd1, "double-preserve-session-2"); + session_fd2 = luo_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); + ASSERT_EQ(luo_session_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); + ret = luo_session_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); + ret = luo_session_preserve_fd(session_fd1, mem_fd, 0x3333); EXPECT_EQ(ret, -EBUSY); ASSERT_EQ(close(mem_fd), 0); @@ -441,7 +397,7 @@ TEST_F(liveupdate_device, create_session_empty_name) SKIP(return, "%s does not exist", LIVEUPDATE_DEV); ASSERT_GE(self->fd1, 0); - session_fd = create_session(self->fd1, ""); + session_fd = luo_create_session(self->fd1, ""); EXPECT_EQ(session_fd, -EINVAL); } @@ -462,10 +418,10 @@ TEST_F(liveupdate_device, get_session_name) SKIP(return, "%s does not exist", LIVEUPDATE_DEV); ASSERT_GE(self->fd1, 0); - session_fd = create_session(self->fd1, session_name); + session_fd = luo_create_session(self->fd1, session_name); ASSERT_GE(session_fd, 0); - ASSERT_EQ(get_session_name(session_fd, name_buf, sizeof(name_buf)), 0); + ASSERT_EQ(luo_get_session_name(session_fd, name_buf, sizeof(name_buf)), 0); ASSERT_STREQ(name_buf, session_name); ASSERT_EQ(close(session_fd), 0); @@ -491,10 +447,10 @@ TEST_F(liveupdate_device, get_session_name_max_length) SKIP(return, "%s does not exist", LIVEUPDATE_DEV); ASSERT_GE(self->fd1, 0); - session_fd = create_session(self->fd1, long_name); + session_fd = luo_create_session(self->fd1, long_name); ASSERT_GE(session_fd, 0); - ASSERT_EQ(get_session_name(session_fd, name_buf, sizeof(name_buf)), 0); + ASSERT_EQ(luo_get_session_name(session_fd, name_buf, sizeof(name_buf)), 0); ASSERT_STREQ(name_buf, long_name); ASSERT_EQ(close(session_fd), 0); @@ -528,7 +484,7 @@ TEST_F(liveupdate_device, preserve_many_sessions) char name[64]; snprintf(name, sizeof(name), "many-session-%d", i); - session_fds[i] = create_session(self->fd1, name); + session_fds[i] = luo_create_session(self->fd1, name); ASSERT_GE(session_fds[i], 0); } @@ -554,7 +510,7 @@ TEST_F(liveupdate_device, preserve_many_files) SKIP(return, "%s does not exist", LIVEUPDATE_DEV); ASSERT_GE(self->fd1, 0); - session_fd = create_session(self->fd1, "many-files-test"); + session_fd = luo_create_session(self->fd1, "many-files-test"); ASSERT_GE(session_fd, 0); ret = luo_ensure_nofile_limit(MANY_FILES + 10); @@ -565,7 +521,7 @@ TEST_F(liveupdate_device, preserve_many_files) for (i = 0; i < MANY_FILES; i++) { mem_fds[i] = memfd_create("test-memfd", 0); ASSERT_GE(mem_fds[i], 0); - ASSERT_EQ(preserve_fd(session_fd, mem_fds[i], i), 0); + ASSERT_EQ(luo_session_preserve_fd(session_fd, mem_fds[i], i), 0); } for (i = 0; i < MANY_FILES; i++) diff --git a/tools/testing/selftests/liveupdate/luo_test_utils.c b/tools/testing/selftests/liveupdate/luo_test_utils.c index 333a3530051b..ddb4123f5107 100644 --- a/tools/testing/selftests/liveupdate/luo_test_utils.c +++ b/tools/testing/selftests/liveupdate/luo_test_utils.c @@ -59,7 +59,7 @@ int luo_create_session(int luo_fd, const char *name) snprintf((char *)arg.name, LIVEUPDATE_SESSION_NAME_LENGTH, "%.*s", LIVEUPDATE_SESSION_NAME_LENGTH - 1, name); - if (ioctl(luo_fd, LIVEUPDATE_IOCTL_CREATE_SESSION, &arg) < 0) + if (ioctl(luo_fd, LIVEUPDATE_IOCTL_CREATE_SESSION, &arg)) return -errno; return arg.fd; @@ -72,15 +72,57 @@ int luo_retrieve_session(int luo_fd, const char *name) snprintf((char *)arg.name, LIVEUPDATE_SESSION_NAME_LENGTH, "%.*s", LIVEUPDATE_SESSION_NAME_LENGTH - 1, name); - if (ioctl(luo_fd, LIVEUPDATE_IOCTL_RETRIEVE_SESSION, &arg) < 0) + if (ioctl(luo_fd, LIVEUPDATE_IOCTL_RETRIEVE_SESSION, &arg)) return -errno; 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)) + 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)) + return -errno; + + return arg.fd; +} + +/* Helper function to get a session name via ioctl. */ +int luo_get_session_name(int session_fd, char *name, size_t name_len) +{ + struct liveupdate_session_get_name args = {}; + + args.size = sizeof(args); + + if (ioctl(session_fd, LIVEUPDATE_SESSION_GET_NAME, &args)) + return -errno; + + strncpy(name, (char *)args.name, name_len - 1); + name[name_len - 1] = '\0'; + + return 0; +} + 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; @@ -99,9 +141,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; @@ -116,15 +157,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) diff --git a/tools/testing/selftests/liveupdate/luo_test_utils.h b/tools/testing/selftests/liveupdate/luo_test_utils.h index 6a0d85386613..49931ab90593 100644 --- a/tools/testing/selftests/liveupdate/luo_test_utils.h +++ b/tools/testing/selftests/liveupdate/luo_test_utils.h @@ -25,8 +25,11 @@ int luo_open_device(void); 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_get_session_name(int session_fd, char *name, size_t name_len); int luo_ensure_nofile_limit(long min_limit); +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); -- 2.54.0.1136.gdb2ca164c4-goog ^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v3 2/2] selftests/liveupdate: Move luo_test_utils.* into a reusable library 2026-06-12 21:45 [PATCH v3 0/2] Make liveupdate selftests library Vipin Sharma 2026-06-12 21:45 ` [PATCH v3 1/2] selftests/liveupdate: Use luo_test_utils.c for liveupdate ioctl APIs Vipin Sharma @ 2026-06-12 21:45 ` Vipin Sharma 2026-06-14 12:45 ` Pasha Tatashin 2026-06-17 18:54 ` [PATCH v3 0/2] Make liveupdate selftests library Mike Rapoport 2 siblings, 1 reply; 6+ messages in thread From: Vipin Sharma @ 2026-06-12 21:45 UTC (permalink / raw) To: pasha.tatashin, rppt, pratyush Cc: tarunsahu, skhawaja, shuah, dmatlack, linux-kernel, kexec, linux-kselftest, Vipin Sharma Move luo_test_utils.[ch] into a lib/ directory and make libliveupdate library. Pull the rules to build them out into a separate libliveupdate.mk script. This will enable these utilities to be also built by and used within other selftests (such as VFIO). No functional change intended. Co-developed-by: David Matlack <dmatlack@google.com> Signed-off-by: David Matlack <dmatlack@google.com> Acked-by: Pratyush Yadav (Google) <pratyush@kernel.org> 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/lu_utils.c} | 2 +- .../testing/selftests/liveupdate/liveupdate.c | 2 +- .../selftests/liveupdate/luo_kexec_simple.c | 2 +- .../selftests/liveupdate/luo_multi_session.c | 2 +- .../selftests/liveupdate/luo_stress_files.c | 3 ++- .../liveupdate/luo_stress_sessions.c | 3 ++- 10 files changed, 37 insertions(+), 20 deletions(-) rename tools/testing/selftests/liveupdate/{luo_test_utils.h => lib/include/libliveupdate.h} (89%) create mode 100644 tools/testing/selftests/liveupdate/lib/libliveupdate.mk rename tools/testing/selftests/liveupdate/{luo_test_utils.c => lib/lu_utils.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 30689d22cb02..634211c66652 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 @@ -12,25 +10,21 @@ TEST_GEN_PROGS_EXTENDED += luo_stress_files 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 89% rename from tools/testing/selftests/liveupdate/luo_test_utils.h rename to tools/testing/selftests/liveupdate/lib/include/libliveupdate.h index 49931ab90593..fa07fed08364 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" @@ -46,4 +46,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..634cd4c16c47 --- /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 := lu_utils.c + +LIBLIVEUPDATE_OUTPUT := $(OUTPUT)/libliveupdate + +LIBLIVEUPDATE_O := $(patsubst %.c, $(LIBLIVEUPDATE_OUTPUT)/%.o, $(LIBLIVEUPDATE_C)) + +CFLAGS += -I$(LIBLIVEUPDATE_SRCDIR)/include + +$(LIBLIVEUPDATE_OUTPUT): + $(Q)mkdir -p $@ + +$(LIBLIVEUPDATE_O): $(LIBLIVEUPDATE_OUTPUT)/%.o : $(LIBLIVEUPDATE_SRCDIR)/%.c | $(LIBLIVEUPDATE_OUTPUT) + $(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/lu_utils.c similarity index 99% rename from tools/testing/selftests/liveupdate/luo_test_utils.c rename to tools/testing/selftests/liveupdate/lib/lu_utils.c index ddb4123f5107..1f92daf3b372 100644 --- a/tools/testing/selftests/liveupdate/luo_test_utils.c +++ b/tools/testing/selftests/liveupdate/lib/lu_utils.c @@ -22,7 +22,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/liveupdate.c b/tools/testing/selftests/liveupdate/liveupdate.c index 5c7ed2512710..2dedd5fc2534 100644 --- a/tools/testing/selftests/liveupdate/liveupdate.c +++ b/tools/testing/selftests/liveupdate/liveupdate.c @@ -24,9 +24,9 @@ #include <sys/ioctl.h> #include <unistd.h> +#include <libliveupdate.h> #include <linux/liveupdate.h> -#include "luo_test_utils.h" #include "../kselftest.h" #include "../kselftest_harness.h" 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" diff --git a/tools/testing/selftests/liveupdate/luo_stress_files.c b/tools/testing/selftests/liveupdate/luo_stress_files.c index 0cdf9cd4bac7..a0d48490f4ed 100644 --- a/tools/testing/selftests/liveupdate/luo_stress_files.c +++ b/tools/testing/selftests/liveupdate/luo_stress_files.c @@ -10,7 +10,8 @@ #include <stdio.h> #include <unistd.h> -#include "luo_test_utils.h" + +#include <libliveupdate.h> #define NUM_FILES 500 #define STATE_SESSION_NAME "kexec_many_files_state" diff --git a/tools/testing/selftests/liveupdate/luo_stress_sessions.c b/tools/testing/selftests/liveupdate/luo_stress_sessions.c index f201b1839d1d..278aebabe0e9 100644 --- a/tools/testing/selftests/liveupdate/luo_stress_sessions.c +++ b/tools/testing/selftests/liveupdate/luo_stress_sessions.c @@ -10,7 +10,8 @@ #include <stdio.h> #include <unistd.h> -#include "luo_test_utils.h" + +#include <libliveupdate.h> #define NUM_SESSIONS 2000 #define STATE_SESSION_NAME "kexec_many_state" -- 2.54.0.1136.gdb2ca164c4-goog ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v3 2/2] selftests/liveupdate: Move luo_test_utils.* into a reusable library 2026-06-12 21:45 ` [PATCH v3 2/2] selftests/liveupdate: Move luo_test_utils.* into a reusable library Vipin Sharma @ 2026-06-14 12:45 ` Pasha Tatashin 0 siblings, 0 replies; 6+ messages in thread From: Pasha Tatashin @ 2026-06-14 12:45 UTC (permalink / raw) To: Vipin Sharma Cc: pasha.tatashin, rppt, pratyush, tarunsahu, skhawaja, shuah, dmatlack, linux-kernel, kexec, linux-kselftest On Fri, 12 Jun 2026 14:45:12 -0700, Vipin Sharma <vipinsh@google.com> wrote: > Move luo_test_utils.[ch] into a lib/ directory and make libliveupdate > library. Pull the rules to build them out into a separate > libliveupdate.mk script. This will enable these utilities to be > also built by and used within other selftests (such as VFIO). > > No functional change intended. > > [...] Reviewed-by: Pasha Tatashin <pasha.tatashin@soleen.com> -- Pasha Tatashin <pasha.tatashin@soleen.com> ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v3 0/2] Make liveupdate selftests library 2026-06-12 21:45 [PATCH v3 0/2] Make liveupdate selftests library Vipin Sharma 2026-06-12 21:45 ` [PATCH v3 1/2] selftests/liveupdate: Use luo_test_utils.c for liveupdate ioctl APIs Vipin Sharma 2026-06-12 21:45 ` [PATCH v3 2/2] selftests/liveupdate: Move luo_test_utils.* into a reusable library Vipin Sharma @ 2026-06-17 18:54 ` Mike Rapoport 2026-06-17 19:08 ` Vipin Sharma 2 siblings, 1 reply; 6+ messages in thread From: Mike Rapoport @ 2026-06-17 18:54 UTC (permalink / raw) To: Vipin Sharma Cc: pasha.tatashin, pratyush, tarunsahu, skhawaja, shuah, dmatlack, linux-kernel, kexec, linux-kselftest Hi Vipin, On Fri, Jun 12, 2026 at 02:45:10PM -0700, Vipin Sharma wrote: > Hello, > > This is v3 series of refactoring liveupdate selftests as a library. It > exposes common liveupdate ioctls as a library which can be used by other > selftests like VFIO and IOMMU. Let's revisit this after -rc1 is out. I don't think there would a need to change anything, it's just the matter of applying the patches to the right base :) > Currently, there are no users of this change but it is being used in > VFIO and iommu liveupdate series. -- Sincerely yours, Mike. ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v3 0/2] Make liveupdate selftests library 2026-06-17 18:54 ` [PATCH v3 0/2] Make liveupdate selftests library Mike Rapoport @ 2026-06-17 19:08 ` Vipin Sharma 0 siblings, 0 replies; 6+ messages in thread From: Vipin Sharma @ 2026-06-17 19:08 UTC (permalink / raw) To: Mike Rapoport Cc: pasha.tatashin, pratyush, tarunsahu, skhawaja, shuah, dmatlack, linux-kernel, kexec, linux-kselftest On Wed, Jun 17, 2026 at 09:54:54PM +0300, Mike Rapoport wrote: > Hi Vipin, > > On Fri, Jun 12, 2026 at 02:45:10PM -0700, Vipin Sharma wrote: > > Hello, > > > > This is v3 series of refactoring liveupdate selftests as a library. It > > exposes common liveupdate ioctls as a library which can be used by other > > selftests like VFIO and IOMMU. > > Let's revisit this after -rc1 is out. > I don't think there would a need to change anything, it's just the matter > of applying the patches to the right base :) Sounds good, thank you! > > > Currently, there are no users of this change but it is being used in > > VFIO and iommu liveupdate series. > > -- > Sincerely yours, > Mike. ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-06-17 19:08 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-06-12 21:45 [PATCH v3 0/2] Make liveupdate selftests library Vipin Sharma 2026-06-12 21:45 ` [PATCH v3 1/2] selftests/liveupdate: Use luo_test_utils.c for liveupdate ioctl APIs Vipin Sharma 2026-06-12 21:45 ` [PATCH v3 2/2] selftests/liveupdate: Move luo_test_utils.* into a reusable library Vipin Sharma 2026-06-14 12:45 ` Pasha Tatashin 2026-06-17 18:54 ` [PATCH v3 0/2] Make liveupdate selftests library Mike Rapoport 2026-06-17 19:08 ` Vipin Sharma
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.