From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.167.197 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795477175; b=nGXc7gfTn9HiBsQymDcXx2j4rXoTkTlYg7YFD61xpSfwehiTY2gZkq+R4yOU4hs4F0yN vZSbuxVfAGwiCgC2iOLN1v4cHjA4roJMEFhlxcxKoYAWRvi2Ngm5x7KeG/L+UILS+xVME iCcnLhcGOdFMqVv9191jQqFn8eroSf9l8mh78bbTv1utELuYjxO5CjAJKmdWj6/fNRgPP kW3rmeQK/UYNI7hJA65TGjUf3X/OQKIVEAgxz5v1O5esEdT3tlzMpv4LKStYcKTBFUTX6 l6mYFDfon1TVIKIZ2FDQZ0/oKkCeOC1q6k9am8Gv+i/pUQxdijf0iMS10b1XBJnIu1Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795477175; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:Date:In-Reply-To: Mime-Version:References:X-Mailer:Message-ID:Subject:From:To:Cc: Content-Type; bh=EeRPz4sZOybVhfqP/WD/7fCihnY2rWbCdbzpXQtgwmc=; b=nCKp3zWM0fE8OJP5hMYWMcZ6R0Kg5HuQx+RylaiGvfjN/zs/pWIv/Evqye2RxSiVkdD7 GkWXsCQlGgAgRcHDAchVTTLBFnkvaWBNTZjnmg8tz2SGUysFXBEggIKqS1Q6XdPhQJnuI d2cNU/OVQlRjt9KSohuEctCLqO2mAdsZDmi37wOk7S8ur4qkLzEm/3i7b7v1VirdhlPi0 Z8sQenIwg/D6bjah9y3WGhDqJjx6oAzMzU0WmrHR4VmzObt29iq0vIfqkd/cndGWcqyl8 o3m03dWwsF1DVwWU35wUotTN9LFiFQIKZv+5fPbyD+ueAaGA7K8lx3ZDHC0w0px90lg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=flex--dmatlack.bounces.google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=N5Sz8hl3; arc=none smtp.remote-ip=209.85.167.197 Received: from mail-oi1-f197.google.com (mail-oi1-f197.google.com [209.85.167.197]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 35EB3606A334 for ; Mon, 23 Nov 2026 23:39:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 35EB3606A334 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--dmatlack.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=N5Sz8hl3 Received: by mail-oi1-f197.google.com with SMTP id 5614622812f47-4c467e19391so5980597b6e.3 for ; Mon, 23 Nov 2026 15:39:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1795477173; x=1796081973; 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=EeRPz4sZOybVhfqP/WD/7fCihnY2rWbCdbzpXQtgwmc=; b=N5Sz8hl3BK6Wus+dA4iR4/YluDgy390oeWI4OR8S+cIERP4cMeZVOSB0EpNj2o+Q/P eqhc2F0GH38RWVJx4EeahnBVR+SuFz+fiyjY+HXX60PbiQwkB0yhWA51eGUxnC1Kqzrg 0lZim1oorPlfkv5nb0aPGW59a++H+Wpc4KpPenmMaBNsAshU1qxNw3/t5jA9T7uzNqoP YSkP8tQHQ8MHk06C1568WPRvnUfPXGEsb8u5c701tcMiBunDN6wowX0+mA7p+3iNky+K izrRXQuha5iB6BIhQZO7xjze78Yh3oiBMEa7AS6DhOYy1GkNddI4/eloBFl544GqtUqL khrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795477173; x=1796081973; 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=EeRPz4sZOybVhfqP/WD/7fCihnY2rWbCdbzpXQtgwmc=; b=Qbb0+mBNY5a6YJbgIS8C12gid6cLG1THaGBshj95eWhwAiNZmdG6FyAyG2cCkFFGcV EZpMRZdpkp/8Mdmr4NL6TwpXoMnNQtmnTaPDw5hkzxoP2PnDvuitGGueIPgyxsSxOXJ9 REeAYDx06dzNK5r3+YE7qSCJcm1bc0Svr+MC1cSbaDmh0zZW338uM+yX1zuHtZt9ojHX 89hcvIVZKrLIoMoCLU8s1FZmedp5Bz7ZkVsQuyk7YewUD7n1ur83wcB5jsbdYdzcLu4b TpoKwR1G5H7EgJfzF6yx3Uf37BM/06M4zRQGIUkSbjF9Wn3T5WT3l7VJzbhrn6+JSzru heHQ== X-Forwarded-Encrypted: i=1; AL+hErF2BqdHbxt4LTnYivZoVYmhdXtrAOSvo1actNNjwL2cYQQ+MhA6JjVPL00wX625NMlIy/FrV5V7zzZOkX8=@vger.kernel.org X-Gm-Message-State: APuU4Z/ZK+QvbrvqdCauGA7bZrWJDp4efnAjJbUxXCAA9uKhRRWitOCd la9FnY7y3vnCuTjOXhG1sM9Us109Tyqt65Pe8iLTInGw1j/Z+YINhRjVKKp1gyU2v+NdZyf5OeR OBvS0Z9Md5ZrXAw== X-Received: from oixz16-n2.prod.google.com ([2002:a05:6809:410:20b0:4f4:549a:d85d]) (user=dmatlack job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6808:4fe1:b0:575:39f9:df7c with SMTP id 5614622812f47-57a06504990mr14793633b6e.2.1795477172875; Mon, 23 Nov 2026 15:39:32 -0800 (PST) Date: Mon, 23 Nov 2026 23:39:08 +0000 In-Reply-To: <20261123233924.3970932-1-dmatlack@google.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 References: <20261123233924.3970932-1-dmatlack@google.com> X-Mailer: git-send-email 2.56.1.809.ga0b61035b5-goog Message-ID: <20261123233924.3970932-4-dmatlack@google.com> Subject: [PATCH v5 03/18] selftests/liveupdate: Add tests for preserve and retrieve user argument From: David Matlack To: kexec@lists.infradead.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org Cc: Alexander Graf , Andrew Morton , Baolin Wang , Christian Brauner , David Hildenbrand , Hugh Dickins , Jonathan Corbet , "Liam R. Howlett" , Lorenzo Stoakes , Michal Hocko , Mike Rapoport , Pasha Tatashin , Pratyush Yadav , Randy Dunlap , Samiullah Khawaja , Shuah Khan , Suren Baghdasaryan , Vlastimil Babka , David Matlack Content-Type: text/plain; charset="UTF-8" From: Pasha Tatashin Verify the user argument support in LIVEUPDATE_SESSION_PRESERVE_FD and LIVEUPDATE_SESSION_RETRIEVE_FD. Add luo_session_preserve_fd_arg() and luo_session_retrieve_fd_arg() helpers to libliveupdate so tests can pass a handler-specific argument. Add a preserve_memfd_with_arg test case to verify that memfd preservation rejects a non-zero argument with -EOPNOTSUPP, accepts an explicit zero argument, and remains compatible with callers passing the legacy struct size up to the token field. Signed-off-by: Pasha Tatashin Signed-off-by: David Matlack Reviewed-by: Pratyush Yadav (Google) --- .../liveupdate/lib/include/libliveupdate.h | 3 ++ .../selftests/liveupdate/lib/lu_utils.c | 17 ++++++- .../testing/selftests/liveupdate/liveupdate.c | 48 +++++++++++++++++++ 3 files changed, 66 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/liveupdate/lib/include/libliveupdate.h b/tools/testing/selftests/liveupdate/lib/include/libliveupdate.h index fa07fed08364..cd1d843a0d3d 100644 --- a/tools/testing/selftests/liveupdate/lib/include/libliveupdate.h +++ b/tools/testing/selftests/liveupdate/lib/include/libliveupdate.h @@ -29,7 +29,10 @@ 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_preserve_fd_arg(int session_fd, int fd, __u64 token, + __u64 user_arg); int luo_session_retrieve_fd(int session_fd, __u64 token); +int luo_session_retrieve_fd_arg(int session_fd, __u64 token, __u64 user_arg); 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/lu_utils.c b/tools/testing/selftests/liveupdate/lib/lu_utils.c index 74d41115c281..db7a90b002cb 100644 --- a/tools/testing/selftests/liveupdate/lib/lu_utils.c +++ b/tools/testing/selftests/liveupdate/lib/lu_utils.c @@ -79,12 +79,14 @@ 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) +int luo_session_preserve_fd_arg(int session_fd, int fd, __u64 token, + __u64 user_arg) { struct liveupdate_session_preserve_fd arg = { .size = sizeof(arg), .fd = fd, .token = token, + .arg = user_arg, }; if (ioctl(session_fd, LIVEUPDATE_SESSION_PRESERVE_FD, &arg)) @@ -93,11 +95,17 @@ int luo_session_preserve_fd(int session_fd, int fd, __u64 token) return 0; } -int luo_session_retrieve_fd(int session_fd, __u64 token) +int luo_session_preserve_fd(int session_fd, int fd, __u64 token) +{ + return luo_session_preserve_fd_arg(session_fd, fd, token, 0); +} + +int luo_session_retrieve_fd_arg(int session_fd, __u64 token, __u64 user_arg) { struct liveupdate_session_retrieve_fd arg = { .size = sizeof(arg), .token = token, + .arg = user_arg, }; if (ioctl(session_fd, LIVEUPDATE_SESSION_RETRIEVE_FD, &arg)) @@ -106,6 +114,11 @@ int luo_session_retrieve_fd(int session_fd, __u64 token) return arg.fd; } +int luo_session_retrieve_fd(int session_fd, __u64 token) +{ + return luo_session_retrieve_fd_arg(session_fd, token, 0); +} + /* Helper function to get a session name via ioctl. */ int luo_get_session_name(int session_fd, char *name, size_t name_len) { diff --git a/tools/testing/selftests/liveupdate/liveupdate.c b/tools/testing/selftests/liveupdate/liveupdate.c index 2dedd5fc2534..8b6e61695a35 100644 --- a/tools/testing/selftests/liveupdate/liveupdate.c +++ b/tools/testing/selftests/liveupdate/liveupdate.c @@ -20,6 +20,7 @@ #include #include +#include #include #include #include @@ -530,4 +531,51 @@ TEST_F(liveupdate_device, preserve_many_files) ASSERT_EQ(close(session_fd), 0); } +/* + * Test Case: Preserve MemFD with User Argument + * + * Verifies that passing a non-zero user argument to memfd preservation fails + * with -EOPNOTSUPP, while passing a zero argument or using the minimum struct + * size without the arg field succeeds. + */ +TEST_F(liveupdate_device, preserve_memfd_with_arg) +{ + struct liveupdate_session_preserve_fd min_arg = {}; + int session_fd, mem_fd1, mem_fd2; + + self->fd1 = open(LIVEUPDATE_DEV, O_RDWR); + if (self->fd1 < 0 && errno == ENOENT) + SKIP(return, "%s does not exist", LIVEUPDATE_DEV); + ASSERT_GE(self->fd1, 0); + + session_fd = luo_create_session(self->fd1, "preserve-arg-test"); + ASSERT_GE(session_fd, 0); + + mem_fd1 = memfd_create("arg-memfd-1", 0); + ASSERT_GE(mem_fd1, 0); + + /* Non-zero arg is not supported by memfd handler */ + EXPECT_EQ(luo_session_preserve_fd_arg(session_fd, mem_fd1, 0x1111, 1), + -EOPNOTSUPP); + + /* + * Legacy struct size (up to token) should succeed. The kernel must + * ignore arg, so set it to a value the memfd handler would reject. + */ + min_arg.size = offsetof(struct liveupdate_session_preserve_fd, arg); + min_arg.fd = mem_fd1; + min_arg.token = 0x1111; + min_arg.arg = 1; + ASSERT_EQ(ioctl(session_fd, LIVEUPDATE_SESSION_PRESERVE_FD, &min_arg), 0); + + /* Explicit zero arg with full struct size should also succeed */ + mem_fd2 = memfd_create("arg-memfd-2", 0); + ASSERT_GE(mem_fd2, 0); + ASSERT_EQ(luo_session_preserve_fd_arg(session_fd, mem_fd2, 0x2222, 0), 0); + + ASSERT_EQ(close(session_fd), 0); + ASSERT_EQ(close(mem_fd1), 0); + ASSERT_EQ(close(mem_fd2), 0); +} + TEST_HARNESS_MAIN -- 2.56.1.809.ga0b61035b5-goog