[PATCH v5 09/18] mm/shmem_luo: Don't make early retrieve failures permanent
From: David Matlack
Date: Mon Nov 23 2026 - 18:40:20 EST
Mark failures in shmem_luo_retrieve() before it starts restoring the
folios as retryable. If no retrieve succeeds, finish() frees the
preserved state, like it does for a file that was never retrieved.
Until the folios are restored, nothing has consumed the preserved state.
Leave it for another retrieve, which may succeed, e.g. if
memfd_alloc_file() failed with -ENOMEM.
The exception is a preserved file that this kernel can't restore, e.g.
because it has seals that this kernel doesn't support. Retrying can't
help, so keep that failure permanent: every later retrieve returns the
same error.
Signed-off-by: David Matlack <dmatlack@xxxxxxxxxx>
Acked-by: Pasha Tatashin <pasha.tatashin@xxxxxxxxxx>
Reviewed-by: Pratyush Yadav (Google) <pratyush@xxxxxxxxxx>
---
mm/shmem_luo.c | 17 ++++++++++++++---
1 file changed, 14 insertions(+), 3 deletions(-)
diff --git a/mm/shmem_luo.c b/mm/shmem_luo.c
index e747a0442295..46b33a00c2a2 100644
--- a/mm/shmem_luo.c
+++ b/mm/shmem_luo.c
@@ -532,6 +532,14 @@ static int shmem_luo_retrieve(struct liveupdate_file_op_args *args)
goto free_ser;
}
+ /*
+ * Nothing consumes the preserved state until the folios are restored
+ * below. If the retrieve fails before that, leave the state for another
+ * retrieve, or for finish() to free. The checks above can't succeed on
+ * a retry, so they fail permanently.
+ */
+ args->retryable = true;
+
/*
* The seals are preserved. Allow sealing here so they can be added
* later.
@@ -539,19 +547,22 @@ static int shmem_luo_retrieve(struct liveupdate_file_op_args *args)
file = memfd_alloc_file("", MFD_ALLOW_SEALING);
if (IS_ERR(file)) {
pr_err("failed to setup file: %pe\n", file);
- err = PTR_ERR(file);
- goto free_ser;
+ return PTR_ERR(file);
}
err = memfd_add_seals(file, ser->seals);
if (err) {
pr_err("failed to add seals: %pe\n", ERR_PTR(err));
- goto put_file;
+ fput(file);
+ return err;
}
vfs_setpos(file, ser->pos, MAX_LFS_FILESIZE);
i_size_write(file_inode(file), ser->size);
+ /* The preserved state is consumed from here on. */
+ args->retryable = false;
+
if (ser->nr_folios) {
folios_ser = kho_restore_vmalloc(&ser->folios);
if (!folios_ser) {
--
2.56.1.809.ga0b61035b5-goog