Re: [PATCH 6/6] selftests/liveupdate: add fallocate test for memfd

From: Mike Rapoport

Date: Wed Mar 18 2026 - 03:47:21 EST


On Mon, Mar 09, 2026 at 11:54:39AM +0000, Pratyush Yadav wrote:
> From: "Pratyush Yadav (Google)" <pratyush@xxxxxxxxxx>
>
> When memory is added to a memfd via fallocate(), it does not get zeroed
> immediately. This is tracked by the absence of the uptodate folio flag.
> Initially, memfd preservation simply saved the folio flags at preserve
> time. This led to a bug, where all writes to un-initialized fallocated
> memory after preserve were lost after live update. This is fixed by
> patch [0] (not in mainline as of writing this).
>
> Add a test that fallocates some memory in a memfd, preserves it, writes
> to it. Then in stage 2 it verifies the written content is still present.
>
> [0] https://lore.kernel.org/linux-mm/20260223173931.2221759-2-pratyush@xxxxxxxxxx/

Looks like it's already in mm-stable, so it's sha should be stable already.

> Signed-off-by: Pratyush Yadav (Google) <pratyush@xxxxxxxxxx>
> ---
> .../testing/selftests/liveupdate/luo_memfd.c | 64 +++++++++++++++++++
> 1 file changed, 64 insertions(+)
>
> diff --git a/tools/testing/selftests/liveupdate/luo_memfd.c b/tools/testing/selftests/liveupdate/luo_memfd.c
> index 75f88101e7b5..dde3c78db50e 100644
> --- a/tools/testing/selftests/liveupdate/luo_memfd.c
> +++ b/tools/testing/selftests/liveupdate/luo_memfd.c
> @@ -43,6 +43,11 @@
> #define PRESERVED_MEMFD_TOKEN 1
> #define PRESERVED_BUFFER_SIZE SZ_1M
>
> +#define FALLOCATE_SESSION_NAME "fallocate_session"
> +#define FALLOCATE_MEMFD_TOKEN 1
> +#define FALLOCATE_BUFFER_SIZE SZ_1M
> +#define RANDOM_DATA_FILE_FALLOCATE "luo_random_data_fallocate.bin"

FILESYSTEM_COPY_ or something like that?

> +
> #define LIVEUPDATE_DEV "/dev/liveupdate"
> static int luo_fd = -1, stage;
>
> @@ -193,6 +198,65 @@ TEST(preserved_ops)
> ASSERT_EQ(lseek(fd, 0, SEEK_END), PRESERVED_BUFFER_SIZE);
> }
>
> +/*
> + * Test that an fallocated memfd is preserved across live update and can be
> + * written to after being preserved.
> + */
> +TEST(fallocate_memfd)
> +{
> + 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(FALLOCATE_BUFFER_SIZE);
> + ASSERT_NE(buffer, NULL);
> +
> + switch (stage) {
> + case 1:

Functions again :)

Reviewed-by: Mike Rapoport (Microsoft) <rppt@xxxxxxxxxx>

--
Sincerely yours,
Mike.