From: Mike Rapoport <rppt@kernel.org>
To: Pratyush Yadav <pratyush@kernel.org>
Cc: Pasha Tatashin <pasha.tatashin@soleen.com>,
Shuah Khan <shuah@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org,
linux-mm@kvack.org
Subject: Re: [PATCH 3/6] selftests/liveupdate: add test for memfd content preservation
Date: Wed, 18 Mar 2026 09:31:00 +0200 [thread overview]
Message-ID: <abpUtCd1-MGL1O4p@kernel.org> (raw)
In-Reply-To: <20260309115441.266805-4-pratyush@kernel.org>
On Mon, Mar 09, 2026 at 11:54:36AM +0000, Pratyush Yadav wrote:
> From: "Pratyush Yadav (Google)" <pratyush@kernel.org>
>
> Add a selftest that makes sure the contents of a memfd are correctly
> preserved across a live update. In stage 1, create a memfd and fill it
> with random data, and preserve it. Save the random data to the file
> system. This will be used by stage 2 to verify the contents are correct.
There's a small caveat here, as some CI systems put selftests in tmpfs, so
creating a file there won't really help.
I think there should be a skip if the test runs of tmpfs.
> In stage 2, retrieve the memfd and compare its contents with the
> contents saved on the file system.
>
> Signed-off-by: Pratyush Yadav <ptyadav@amazon.de>
> Signed-off-by: Pratyush Yadav (Google) <pratyush@kernel.org>
> ---
> tools/testing/selftests/liveupdate/Makefile | 1 +
> .../testing/selftests/liveupdate/luo_memfd.c | 61 +++++++++++++++++++
> 2 files changed, 62 insertions(+)
>
> diff --git a/tools/testing/selftests/liveupdate/Makefile b/tools/testing/selftests/liveupdate/Makefile
> index 051daae55eec..8e2eb6500c07 100644
> --- a/tools/testing/selftests/liveupdate/Makefile
> +++ b/tools/testing/selftests/liveupdate/Makefile
> @@ -13,6 +13,7 @@ TEST_FILES += do_kexec.sh
> include ../lib.mk
>
> CFLAGS += $(KHDR_INCLUDES)
> +CFLAGS += -I$(top_srcdir)/tools/include
> CFLAGS += -Wall -O2 -Wno-unused-function
> CFLAGS += -MD
>
> diff --git a/tools/testing/selftests/liveupdate/luo_memfd.c b/tools/testing/selftests/liveupdate/luo_memfd.c
> index b779eee18387..52b5f6b16e19 100644
> --- a/tools/testing/selftests/liveupdate/luo_memfd.c
> +++ b/tools/testing/selftests/liveupdate/luo_memfd.c
> @@ -3,6 +3,9 @@
> /*
> * Copyright (c) 2026, Google LLC.
> * Pratyush Yadav (Google) <pratyush@kernel.org>
> + *
> + * Copyright (C) 2025 Amazon.com Inc. or its affiliates.
> + * Pratyush Yadav <ptyadav@amazon.de>
> */
>
> /*
> @@ -11,11 +14,14 @@
>
> #include <errno.h>
> #include <fcntl.h>
> +#include <stdlib.h>
> #include <string.h>
> #include <sys/ioctl.h>
> +#include <sys/mman.h>
> #include <unistd.h>
>
> #include <linux/liveupdate.h>
> +#include <linux/sizes.h>
>
> #include "../kselftest.h"
> #include "../kselftest_harness.h"
> @@ -25,9 +31,64 @@
> #define STATE_SESSION_NAME "luo-state"
> #define STATE_MEMFD_TOKEN 1
>
> +#define MEMFD_DATA_SESSION_NAME "memfd_data_session"
> +#define MEMFD_DATA_TOKEN 1
> +#define MEMFD_DATA_BUFFER_SIZE SZ_1M
> +#define RANDOM_DATA_FILE "luo_random_data.bin"
Reads to me like a random file containing data :)
Something like FILESYSTEM_DATA_COPY would better express the meaning.
> +
> #define LIVEUPDATE_DEV "/dev/liveupdate"
> static int luo_fd = -1, stage;
>
> +/*
> + * Test that a memfd with its data is preserved across live update.
> + */
> +TEST(memfd_data)
> +{
> + int fd, session;
> + char *buffer;
> + struct liveupdate_session_preserve_fd preserve_arg = { .size = sizeof(preserve_arg) };
> + struct liveupdate_session_retrieve_fd retrieve_arg = { .size = sizeof(retrieve_arg) };
> +
> + buffer = malloc(MEMFD_DATA_BUFFER_SIZE);
> + ASSERT_NE(buffer, NULL);
> +
> + switch (stage) {
> + case 1:
Can we please move each state to a helper function?
> + session = luo_create_session(luo_fd, MEMFD_DATA_SESSION_NAME);
> + ASSERT_GE(session, 0);
> +
> + fd = create_random_memfd("memfd_data", buffer, MEMFD_DATA_BUFFER_SIZE);
> + ASSERT_GE(fd, 0);
> +
> + ASSERT_EQ(save_test_data(RANDOM_DATA_FILE, buffer, MEMFD_DATA_BUFFER_SIZE), 0);
> +
> + preserve_arg.fd = fd;
> + preserve_arg.token = MEMFD_DATA_TOKEN;
> + ASSERT_GE(ioctl(session, LIVEUPDATE_SESSION_PRESERVE_FD, &preserve_arg), 0);
> +
> + daemonize_and_wait();
> + break;
> + case 2:
> + session = luo_retrieve_session(luo_fd, MEMFD_DATA_SESSION_NAME);
> + ASSERT_GE(session, 0);
> +
> + ASSERT_EQ(load_test_data(RANDOM_DATA_FILE, buffer, MEMFD_DATA_BUFFER_SIZE), 0);
> +
> + retrieve_arg.token = MEMFD_DATA_TOKEN;
> + ASSERT_GE(ioctl(session, LIVEUPDATE_SESSION_RETRIEVE_FD, &retrieve_arg), 0);
> + fd = retrieve_arg.fd;
> + ASSERT_GE(fd, 0);
> +
> + ASSERT_EQ(verify_fd_content(fd, buffer, MEMFD_DATA_BUFFER_SIZE), 0);
> +
> + ASSERT_EQ(luo_session_finish(session), 0);
> + break;
> + default:
> + TH_LOG("Unknown stage %d\n", stage);
> + ASSERT_FALSE(true);
> + }
> +}
> +
> int main(int argc, char *argv[])
> {
> int session, expected_stage = 0;
> --
> 2.53.0.473.g4a7958ca14-goog
>
--
Sincerely yours,
Mike.
next prev parent reply other threads:[~2026-03-18 7:31 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-09 11:54 [PATCH 0/6] selftests/liveupdate: add memfd tests Pratyush Yadav
2026-03-09 11:54 ` [PATCH 1/6] selftests/liveupdate: add framework for " Pratyush Yadav
2026-03-10 11:08 ` Usama Arif
2026-03-13 10:05 ` Pratyush Yadav
2026-03-18 7:15 ` Mike Rapoport
2026-03-09 11:54 ` [PATCH 2/6] selftests/liveupdate: add helper functions " Pratyush Yadav
2026-03-17 11:01 ` Mike Rapoport
2026-03-17 12:21 ` Pratyush Yadav
2026-03-18 7:20 ` Mike Rapoport
2026-03-09 11:54 ` [PATCH 3/6] selftests/liveupdate: add test for memfd content preservation Pratyush Yadav
2026-03-18 7:31 ` Mike Rapoport [this message]
2026-03-09 11:54 ` [PATCH 4/6] selftests/liveupdate: add test for zero-size memfd preservation Pratyush Yadav
2026-03-18 7:35 ` Mike Rapoport
2026-03-09 11:54 ` [PATCH 5/6] selftests/liveupdate: add test for operations on a preserved memfd Pratyush Yadav
2026-03-18 7:38 ` Mike Rapoport
2026-03-09 11:54 ` [PATCH 6/6] selftests/liveupdate: add fallocate test for memfd Pratyush Yadav
2026-03-18 7:43 ` Mike Rapoport
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=abpUtCd1-MGL1O4p@kernel.org \
--to=rppt@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=pasha.tatashin@soleen.com \
--cc=pratyush@kernel.org \
--cc=shuah@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox