From nobody Sat Jul 25 01:52:43 2026 Received: from mail-pj1-f71.google.com (mail-pj1-f71.google.com [209.85.216.71]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 199163CA48C for ; Mon, 20 Jul 2026 20:32:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.71 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784579530; cv=none; b=Ewzy9T97B0TSOMUaKZRVswkt1uhlkzQjADPNwMKzSoxlD8N/DqRqTUU+eoMn8OvuaAfOto/Q/dfKmwlA/ZrKt09L7r4gzNLUmNs8CIQYF1ihiRGcVBSmdE+cRNxV6Qi10qGL0Sbln1gX+s0/NVELtsj4zIutCl/JKPp4zg06Y1E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784579530; c=relaxed/simple; bh=5MvrFjRMYK2s0gs1A9vvtO4sbeJ5TNHDaWeV7xw6huY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=aDlMg6kRIN6r452KpndRvIZOYcnnxOAEESIBUOJQvoxWX9lHmD3KnM2ArIk/CAWhUqBlpLVAtCGtJbzJbdkypvzngseVDpaqRvaDbuaHz668A6V8WVTYFNuiMrh9dIr4SepqYD9g+nXLvzvPAUYpOeL9DxgdUvmJU7/3MEvoSkw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--vipinsh.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=pRa71yrD; arc=none smtp.client-ip=209.85.216.71 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--vipinsh.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="pRa71yrD" Received: by mail-pj1-f71.google.com with SMTP id 98e67ed59e1d1-38dd87656d3so10116990a91.2 for ; Mon, 20 Jul 2026 13:32:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1784579527; x=1785184327; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=fi8xeCp6XPPBE7dFzJmCqzaIXOtrA82+UGnJsprXgM8=; b=pRa71yrDpwf5BoIBC/VKA0UCEeR2AcZbVspLkoRgHVl8itD4g2Xr7rKskiOCRQzzpT Z6WlGiqZW3GzycBKIo7351a0qIITOFZrl3pdL9n2xEHJ19nb5UCPlUE5ylKgXqLjwoh0 RI4L43Zx1ujW0cb/PNSicbwoDYwBPyAB26lpic5joJj1TWwLGcttDmPSXaBFtBQ8W+u6 39zdNv04VHWYo9x+HEWTrsVqCh1gtyfwyJEz+2CtcXsCLmh6NcMBj1YjKptRbH/WRWbA 6UXxuES1S63PtinvR1+rVcQtcN+kBVtJckrcH/IPw/l2eMSlMJTqoAIW11kyH0jTx0W7 wd3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784579527; x=1785184327; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=fi8xeCp6XPPBE7dFzJmCqzaIXOtrA82+UGnJsprXgM8=; b=pnbmhHHldObkteQdeTL6EdvIncTpGHgHtFYRoKZrPo7X8SsURZQWCsH+B/TWjhrC+x EgL2z0ciVk9fLXIJolYtr2eS0TQ2x9FTKcmeSEI62ALaTllh0eo31mYwmS6G1Jscr1sR /zgp1NsStF61Z/BTFAEeEZjoMerwFOXY7u1qyhCQkaYmRrOscF1ML2xh9MehHoj+gz5l SM+7FQcrhH/fomglBHruBFQiO25mgu1HLFqn3xw/wWvx9KiyD/3siqPBi78QOjJpAOW7 077kFAQN4xJg0I0/Ua1lfm0iqObuPHZNgKi9+XRwo4NHwYzqMeOaX6C2N1Aew5poqpL5 z0DA== X-Forwarded-Encrypted: i=1; AHgh+RqdLhC9otsF17nkRPwx0rG7NCfpWDXWwlCcr5PsbsoO+X+zPbAPxjOGi3Z/HOJBVmeAMcQC6fvuaPHQrG4=@vger.kernel.org X-Gm-Message-State: AOJu0YxZczHi+oqz1/S0iYiM6oLTKHef/DmK9kqqsxPinbEV+xkBIEJr w8pzfOy6K/+5sZIPo8M1D7LAmEjyq9ZyJglrY5Fj3bxlY31XPCXAl0Hx9SLmJ8RvwPyUk4dVcFC z8seZvhHbPA== X-Received: from pjkk7.prod.google.com ([2002:a17:90b:57e7:b0:380:fc48:584e]) (user=vipinsh job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:1844:b0:37f:9ce1:cdb2 with SMTP id 98e67ed59e1d1-38e4b55aeebmr16648660a91.32.1784579526707; Mon, 20 Jul 2026 13:32:06 -0700 (PDT) Date: Mon, 20 Jul 2026 13:32:01 -0700 In-Reply-To: <20260720203202.1964557-1-vipinsh@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260720203202.1964557-1-vipinsh@google.com> X-Mailer: git-send-email 2.55.0.229.g6434b31f56-goog Message-ID: <20260720203202.1964557-2-vipinsh@google.com> Subject: [PATCH v4 1/2] selftests/liveupdate: Use luo_test_utils.c for liveupdate ioctl APIs From: Vipin Sharma To: pasha.tatashin@soleen.com, rppt@kernel.org, pratyush@kernel.org Cc: tarunsahu@google.com, skhawaja@google.com, shuah@kernel.org, dmatlack@google.com, linux-kernel@vger.kernel.org, kexec@lists.infradead.org, linux-kselftest@vger.kernel.org, Vipin Sharma Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 Signed-off-by: David Matlack Reviewed-by: Pasha Tatashin Reviewed-by: Pratyush Yadav (Google) Signed-off-by: Vipin Sharma --- .../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/testin= g/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); } =20 -/* 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 =3D {}; - - args.size =3D 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 =3D {}; - - args.size =3D 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] =3D '\0'; - - return 0; -} - /* * Test Case: Create Duplicate Session * @@ -135,10 +105,10 @@ TEST_F(liveupdate_device, create_duplicate_session) =20 ASSERT_GE(self->fd1, 0); =20 - session_fd1 =3D create_session(self->fd1, "duplicate-session-test"); + session_fd1 =3D luo_create_session(self->fd1, "duplicate-session-test"); ASSERT_GE(session_fd1, 0); =20 - session_fd2 =3D create_session(self->fd1, "duplicate-session-test"); + session_fd2 =3D luo_create_session(self->fd1, "duplicate-session-test"); EXPECT_LT(session_fd2, 0); EXPECT_EQ(-session_fd2, EEXIST); =20 @@ -160,30 +130,16 @@ TEST_F(liveupdate_device, create_distinct_sessions) =20 ASSERT_GE(self->fd1, 0); =20 - session_fd1 =3D create_session(self->fd1, "distinct-session-1"); + session_fd1 =3D luo_create_session(self->fd1, "distinct-session-1"); ASSERT_GE(session_fd1, 0); =20 - session_fd2 =3D create_session(self->fd1, "distinct-session-2"); + session_fd2 =3D luo_create_session(self->fd1, "distinct-session-2"); ASSERT_GE(session_fd2, 0); =20 ASSERT_EQ(close(session_fd1), 0); ASSERT_EQ(close(session_fd2), 0); } =20 -static int preserve_fd(int session_fd, int fd_to_preserve, __u64 token) -{ - struct liveupdate_session_preserve_fd args =3D {}; - - args.size =3D sizeof(args); - args.fd =3D fd_to_preserve; - args.token =3D 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); =20 - session_fd =3D create_session(self->fd1, "preserve-memfd-test"); + session_fd =3D luo_create_session(self->fd1, "preserve-memfd-test"); ASSERT_GE(session_fd, 0); =20 mem_fd =3D memfd_create("test-memfd", 0); ASSERT_GE(mem_fd, 0); =20 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); =20 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); =20 - session_fd =3D create_session(self->fd1, "preserve-multi-memfd-test"); + session_fd =3D luo_create_session(self->fd1, "preserve-multi-memfd-test"); ASSERT_GE(session_fd, 0); =20 mem_fd1 =3D 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)= ); =20 - 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); =20 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); =20 - session_fd1 =3D create_session(self->fd1, "complex-session-1"); + session_fd1 =3D luo_create_session(self->fd1, "complex-session-1"); ASSERT_GE(session_fd1, 0); - session_fd2 =3D create_session(self->fd1, "complex-session-2"); + session_fd2 =3D luo_create_session(self->fd1, "complex-session-2"); ASSERT_GE(session_fd2, 0); =20 mem_fd_data1 =3D memfd_create("data1", 0); @@ -303,10 +259,10 @@ TEST_F(liveupdate_device, preserve_complex_scenario) mem_fd_empty2 =3D memfd_create("empty2", 0); ASSERT_GE(mem_fd_empty2, 0); =20 - 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); =20 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); =20 - session_fd =3D create_session(self->fd1, "unsupported-fd-test"); + session_fd =3D luo_create_session(self->fd1, "unsupported-fd-test"); ASSERT_GE(session_fd, 0); =20 unsupported_fd =3D open("/dev/null", O_RDWR); ASSERT_GE(unsupported_fd, 0); =20 - ret =3D preserve_fd(session_fd, unsupported_fd, 0xDEAD); + ret =3D luo_session_preserve_fd(session_fd, unsupported_fd, 0xDEAD); EXPECT_EQ(ret, -ENOENT); =20 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); =20 - session_fd1 =3D create_session(self->fd1, "double-preserve-session-1"); + session_fd1 =3D luo_create_session(self->fd1, "double-preserve-session-1"= ); ASSERT_GE(session_fd1, 0); - session_fd2 =3D create_session(self->fd1, "double-preserve-session-2"); + session_fd2 =3D luo_create_session(self->fd1, "double-preserve-session-2"= ); ASSERT_GE(session_fd2, 0); =20 mem_fd =3D memfd_create("test-memfd", 0); ASSERT_GE(mem_fd, 0); =20 /* 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); =20 /* Second preservation in a different session should fail with EBUSY */ - ret =3D preserve_fd(session_fd2, mem_fd, 0x2222); + ret =3D luo_session_preserve_fd(session_fd2, mem_fd, 0x2222); EXPECT_EQ(ret, -EBUSY); =20 /* Second preservation in the same session (different token) should fail = with EBUSY */ - ret =3D preserve_fd(session_fd1, mem_fd, 0x3333); + ret =3D luo_session_preserve_fd(session_fd1, mem_fd, 0x3333); EXPECT_EQ(ret, -EBUSY); =20 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); =20 - session_fd =3D create_session(self->fd1, ""); + session_fd =3D luo_create_session(self->fd1, ""); EXPECT_EQ(session_fd, -EINVAL); } =20 @@ -462,10 +418,10 @@ TEST_F(liveupdate_device, get_session_name) SKIP(return, "%s does not exist", LIVEUPDATE_DEV); ASSERT_GE(self->fd1, 0); =20 - session_fd =3D create_session(self->fd1, session_name); + session_fd =3D luo_create_session(self->fd1, session_name); ASSERT_GE(session_fd, 0); =20 - 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); =20 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); =20 - session_fd =3D create_session(self->fd1, long_name); + session_fd =3D luo_create_session(self->fd1, long_name); ASSERT_GE(session_fd, 0); =20 - 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); =20 ASSERT_EQ(close(session_fd), 0); @@ -528,7 +484,7 @@ TEST_F(liveupdate_device, preserve_many_sessions) char name[64]; =20 snprintf(name, sizeof(name), "many-session-%d", i); - session_fds[i] =3D create_session(self->fd1, name); + session_fds[i] =3D luo_create_session(self->fd1, name); ASSERT_GE(session_fds[i], 0); } =20 @@ -554,7 +510,7 @@ TEST_F(liveupdate_device, preserve_many_files) SKIP(return, "%s does not exist", LIVEUPDATE_DEV); ASSERT_GE(self->fd1, 0); =20 - session_fd =3D create_session(self->fd1, "many-files-test"); + session_fd =3D luo_create_session(self->fd1, "many-files-test"); ASSERT_GE(session_fd, 0); =20 ret =3D luo_ensure_nofile_limit(MANY_FILES + 10); @@ -565,7 +521,7 @@ TEST_F(liveupdate_device, preserve_many_files) for (i =3D 0; i < MANY_FILES; i++) { mem_fds[i] =3D 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); } =20 for (i =3D 0; i < MANY_FILES; i++) diff --git a/tools/testing/selftests/liveupdate/luo_test_utils.c b/tools/te= sting/selftests/liveupdate/luo_test_utils.c index 1439b2b48ed0..885712a65075 100644 --- a/tools/testing/selftests/liveupdate/luo_test_utils.c +++ b/tools/testing/selftests/liveupdate/luo_test_utils.c @@ -60,7 +60,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); =20 - if (ioctl(luo_fd, LIVEUPDATE_IOCTL_CREATE_SESSION, &arg) < 0) + if (ioctl(luo_fd, LIVEUPDATE_IOCTL_CREATE_SESSION, &arg)) return -errno; =20 return arg.fd; @@ -73,15 +73,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); =20 - if (ioctl(luo_fd, LIVEUPDATE_IOCTL_RETRIEVE_SESSION, &arg) < 0) + if (ioctl(luo_fd, LIVEUPDATE_IOCTL_RETRIEVE_SESSION, &arg)) return -errno; =20 return arg.fd; } =20 +int luo_session_preserve_fd(int session_fd, int fd, __u64 token) +{ + struct liveupdate_session_preserve_fd arg =3D { + .size =3D sizeof(arg), + .fd =3D fd, + .token =3D 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 =3D { + .size =3D sizeof(arg), + .token =3D 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 =3D {}; + + args.size =3D 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] =3D '\0'; + + return 0; +} + int create_and_preserve_memfd(int session_fd, int token, const char *data) { - struct liveupdate_session_preserve_fd arg =3D { .size =3D sizeof(arg) }; long page_size =3D getpagesize(); void *map =3D MAP_FAILED; int mfd =3D -1, ret =3D -1; @@ -100,9 +142,8 @@ int create_and_preserve_memfd(int session_fd, int token= , const char *data) snprintf(map, page_size, "%s", data); munmap(map, page_size); =20 - arg.fd =3D mfd; - arg.token =3D token; - if (ioctl(session_fd, LIVEUPDATE_SESSION_PRESERVE_FD, &arg) < 0) + ret =3D luo_session_preserve_fd(session_fd, mfd, token); + if (ret) goto out; =20 ret =3D 0; @@ -117,15 +158,13 @@ int create_and_preserve_memfd(int session_fd, int tok= en, const char *data) int restore_and_verify_memfd(int session_fd, int token, const char *expected_data) { - struct liveupdate_session_retrieve_fd arg =3D { .size =3D sizeof(arg) }; long page_size =3D getpagesize(); void *map =3D MAP_FAILED; int mfd =3D -1, ret =3D -1; =20 - arg.token =3D token; - if (ioctl(session_fd, LIVEUPDATE_SESSION_RETRIEVE_FD, &arg) < 0) - return -errno; - mfd =3D arg.fd; + mfd =3D luo_session_retrieve_fd(session_fd, token); + if (mfd < 0) + return mfd; =20 map =3D mmap(NULL, page_size, PROT_READ, MAP_SHARED, mfd, 0); if (map =3D=3D MAP_FAILED) diff --git a/tools/testing/selftests/liveupdate/luo_test_utils.h b/tools/te= sting/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); =20 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); =20 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 *expect= ed_data); --=20 2.55.0.229.g6434b31f56-goog From nobody Sat Jul 25 01:52:43 2026 Received: from mail-pf1-f198.google.com (mail-pf1-f198.google.com [209.85.210.198]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D87E63C2B92 for ; Mon, 20 Jul 2026 20:32:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.198 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784579530; cv=none; b=ZXTmaJ3pNxGWMbZtXMUA94amNJj/GVJ2NGoVwLh8O+aQty3oFXZHE+laat3wmsjHdKuFU+mnnzDR9JR/j7r0LRuf41Jbi/8uCDPrwAtwPPx7mjr892JLk3IDGrdqSIXaio23lMdkWY4TEmXB2xA0vKRBwXjvPNfuErKVBwmdw8k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784579530; c=relaxed/simple; bh=jdIVzBFIoulpULK4pzaO1WKiE6HjqadJrPUbUmqnGMk=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=NBC7/vsIBYzv+ACMQ+D3Zd8fkSd6uVAVAZe9OPh/Fq8SgRk1WVZwFCCJyRmFv2tgFsMS73VFt2lnC6/aQpyvKezh4r796aWs0NCzIek7Yy0OIOCZvT6SpWK6SzLBnLUZ1degPDd2OMrIvyHsYunAIdV8Lf7XnlZGvG4VnaVzHAA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--vipinsh.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=fFDJoKN/; arc=none smtp.client-ip=209.85.210.198 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--vipinsh.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="fFDJoKN/" Received: by mail-pf1-f198.google.com with SMTP id d2e1a72fcca58-848860def2cso11221653b3a.2 for ; Mon, 20 Jul 2026 13:32:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1784579528; x=1785184328; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=D0u/ZsKaJ4sWO+EwXyup1tCC2bG9yJvlOEOLZr8wnIo=; b=fFDJoKN/LeZehdU8w2+ZkXQDSAEtsgE9mGROxxy6kz1F4A/6m8No11Jhb2slosVEJd xAKJxTGBb79PhLnaLlkyIVWEJUMO9CarNESnGmanlUFjtNHWjqPC01YUAxxz6dfeYhc1 rlCq93JS8CCjXDyMyzSnWpyThKTsmLUoDGOrZNxFiG1eBvH3pOhe7lseBPvmb17SFaFF uXE5Z3c7Ms8v4jK4SxsW28pmx9Lfk976hbcXg3eikdm17vTEoPJbrcIlq0AKfWHzLNyT GoFLQoVNKRC9JzjPx2D3QR4XyuNA/tdMP0K8cnkBd75sxIu6lPc2huRX9J93tiULrqHi cfDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784579528; x=1785184328; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=D0u/ZsKaJ4sWO+EwXyup1tCC2bG9yJvlOEOLZr8wnIo=; b=B1psrdt14iFoP2IyhyPp5RApo8/Av1NeUOaldCpFFuUMg652DhyVYlPQUMQ3AykohY MSC8UjcuQ3/JpeCWWkt25XzqfjdBag1Blp3rWWOq1Me+2uZsrc5lqBnidGCz21QPB0Jm WwKpc34Uryxi0YsXe1IA2XnZI/0LYzLWH9OG8TZvJUTMTMq3tN9IyTd5R2pE6mgidTph rlMb+RJDLeBeIKJX5bXttbAsyxElH5gnyN7w9FtGDjw5JXjn0NHoCUpnQ1nDSPqc8Fy+ 9rwr513UMLFrhUnXKoAg0ph5rdRcQ+y5jqXCFlBcqbbsYLOsuJv2aVMWnXpOuykvBRze VZhQ== X-Forwarded-Encrypted: i=1; AHgh+RrbV/Mt7oOdnjKz1u6eCAFy4h78SFSHS89U60z2sr2L7Mbp7Na5fbmof7ddigY9KhPk4saJymoS6Ph+B4I=@vger.kernel.org X-Gm-Message-State: AOJu0YzqoRaU25PGKCuozuMvQxcKTO3hPbVXcngbQexhe8E03sV84cMf Yts3JS+Uz9c0qkbWuAblJ7n+yOAjl6K5SXDmROLpgM3DqgRpv1B1qN5uEjcz6zahUVnhZlGJyuj nqlM23HR7wQ== X-Received: from pfbjo7.prod.google.com ([2002:a05:6a00:9087:b0:845:b941:bc97]) (user=vipinsh job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:8c2:b0:848:54e0:96c1 with SMTP id d2e1a72fcca58-84c29590547mr16031465b3a.77.1784579527756; Mon, 20 Jul 2026 13:32:07 -0700 (PDT) Date: Mon, 20 Jul 2026 13:32:02 -0700 In-Reply-To: <20260720203202.1964557-1-vipinsh@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260720203202.1964557-1-vipinsh@google.com> X-Mailer: git-send-email 2.55.0.229.g6434b31f56-goog Message-ID: <20260720203202.1964557-3-vipinsh@google.com> Subject: [PATCH v4 2/2] selftests/liveupdate: Move luo_test_utils.* into a reusable library From: Vipin Sharma To: pasha.tatashin@soleen.com, rppt@kernel.org, pratyush@kernel.org Cc: tarunsahu@google.com, skhawaja@google.com, shuah@kernel.org, dmatlack@google.com, linux-kernel@vger.kernel.org, kexec@lists.infradead.org, linux-kselftest@vger.kernel.org, Vipin Sharma Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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). Update path in vmtest.sh as that one uses hardcoded path for util. No functional change intended. Co-developed-by: David Matlack Signed-off-by: David Matlack Acked-by: Pratyush Yadav (Google) Reviewed-by: Pasha Tatashin Signed-off-by: Vipin Sharma --- 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 =3D> 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 ++- tools/testing/selftests/liveupdate/vmtest.sh | 4 ++-- 11 files changed, 39 insertions(+), 22 deletions(-) rename tools/testing/selftests/liveupdate/{luo_test_utils.h =3D> lib/inclu= de/libliveupdate.h} (89%) create mode 100644 tools/testing/selftests/liveupdate/lib/libliveupdate.mk rename tools/testing/selftests/liveupdate/{luo_test_utils.c =3D> lib/lu_ut= ils.c} (99%) diff --git a/tools/testing/selftests/liveupdate/.gitignore b/tools/testing/= selftests/liveupdate/.gitignore index cb08ddb0dfee..47c670bf532b 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/se= lftests/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 =20 -LIB_C +=3D luo_test_utils.c - TEST_GEN_PROGS +=3D liveupdate =20 TEST_GEN_PROGS_EXTENDED +=3D luo_kexec_simple @@ -12,25 +10,21 @@ TEST_GEN_PROGS_EXTENDED +=3D luo_stress_files TEST_FILES +=3D do_kexec.sh =20 include ../lib.mk +include lib/libliveupdate.mk =20 CFLAGS +=3D $(KHDR_INCLUDES) CFLAGS +=3D -Wall -O2 -Wno-unused-function CFLAGS +=3D -MD =20 -LIB_O :=3D $(patsubst %.c, $(OUTPUT)/%.o, $(LIB_C)) TEST_O :=3D $(patsubst %, %.o, $(TEST_GEN_PROGS)) TEST_O +=3D $(patsubst %, %.o, $(TEST_GEN_PROGS_EXTENDED)) =20 -TEST_DEP_FILES :=3D $(patsubst %.o, %.d, $(LIB_O)) +TEST_DEP_FILES :=3D $(patsubst %.o, %.d, $(LIBLIVEUPDATE_O)) TEST_DEP_FILES +=3D $(patsubst %.o, %.d, $(TEST_O)) -include $(TEST_DEP_FILES) =20 -$(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) $(LDLIB= S) -o $@ +$(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED): $(OUTPUT)/%: %.o $(LIBLIVEUP= DATE_O) + $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH) $< $(LIBLIVEUPDATE_= O) $(LDLIBS) -o $@ =20 -EXTRA_CLEAN +=3D $(LIB_O) EXTRA_CLEAN +=3D $(TEST_O) EXTRA_CLEAN +=3D $(TEST_DEP_FILES) diff --git a/tools/testing/selftests/liveupdate/luo_test_utils.h b/tools/te= sting/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. */ =20 -#ifndef LUO_TEST_UTILS_H -#define LUO_TEST_UTILS_H +#ifndef SELFTESTS_LIVEUPDATE_LIB_LIVEUPDATE_H +#define SELFTESTS_LIVEUPDATE_LIB_LIVEUPDATE_H =20 #include #include #include -#include "../kselftest.h" +#include "../../../kselftest.h" =20 #define LUO_DEVICE "/dev/liveupdate" =20 @@ -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); =20 -#endif /* LUO_TEST_UTILS_H */ +#endif /* SELFTESTS_LIVEUPDATE_LIB_LIVEUPDATE_H */ diff --git a/tools/testing/selftests/liveupdate/lib/libliveupdate.mk b/tool= s/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 ?=3D $(SUBARCH) + +LIBLIVEUPDATE_SRCDIR :=3D $(selfdir)/liveupdate/lib + +LIBLIVEUPDATE_C :=3D lu_utils.c + +LIBLIVEUPDATE_OUTPUT :=3D $(OUTPUT)/libliveupdate + +LIBLIVEUPDATE_O :=3D $(patsubst %.c, $(LIBLIVEUPDATE_OUTPUT)/%.o, $(LIBLIV= EUPDATE_C)) + +CFLAGS +=3D -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 +=3D $(LIBLIVEUPDATE_OUTPUT) diff --git a/tools/testing/selftests/liveupdate/luo_test_utils.c b/tools/te= sting/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 885712a65075..74d41115c281 100644 --- a/tools/testing/selftests/liveupdate/luo_test_utils.c +++ b/tools/testing/selftests/liveupdate/lib/lu_utils.c @@ -23,7 +23,7 @@ #include #include =20 -#include "luo_test_utils.h" +#include =20 int luo_open_device(void) { diff --git a/tools/testing/selftests/liveupdate/liveupdate.c b/tools/testin= g/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 #include =20 +#include #include =20 -#include "luo_test_utils.h" #include "../kselftest.h" #include "../kselftest_harness.h" =20 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. */ =20 -#include "luo_test_utils.h" +#include =20 #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. */ =20 -#include "luo_test_utils.h" +#include =20 #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 @@ =20 #include #include -#include "luo_test_utils.h" + +#include =20 #define NUM_FILES 500 #define STATE_SESSION_NAME "kexec_many_files_state" diff --git a/tools/testing/selftests/liveupdate/luo_stress_sessions.c b/too= ls/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 @@ =20 #include #include -#include "luo_test_utils.h" + +#include =20 #define NUM_SESSIONS 2000 #define STATE_SESSION_NAME "kexec_many_state" diff --git a/tools/testing/selftests/liveupdate/vmtest.sh b/tools/testing/s= elftests/liveupdate/vmtest.sh index b0000fae1461..64fd2ab55b76 100755 --- a/tools/testing/selftests/liveupdate/vmtest.sh +++ b/tools/testing/selftests/liveupdate/vmtest.sh @@ -131,9 +131,9 @@ function mkinitrd() { "$CROSS_COMPILE"gcc -static -O2 -nostdinc -nostdlib \ -I "$headers_dir/include" \ -I "$kernel_dir/tools/include/nolibc" \ - -I "$test_dir" \ + -I "$test_dir/lib/include" \ -o "$workspace_dir/test_binary" \ - "$test_dir/$test_name.c" "$test_dir/luo_test_utils.c" + "$test_dir/$test_name.c" "$test_dir/lib/lu_utils.c" =20 "$CROSS_COMPILE"gcc -s -static -Os -nostdinc -nostdlib \ -fno-asynchronous-unwind-tables -fno-ident \ --=20 2.55.0.229.g6434b31f56-goog