From: "Pratyush Yadav (Google)" <pratyush@kernel.org>
The Live Update Orchestrator's (LUO) memfd preservation works by
preserving all the folios of a memfd, re-creating an empty memfd on the
next boot, and then inserting back the preserved folios.
Currently it creates the file by directly calling shmem_file_setup().
This leaves out other work done by alloc_file() like setting up the file
mode, flags, or calling the security hooks.
Export alloc_file() to let memfd_luo use it. Rename it to
memfd_alloc_file() since it is no longer private and thus needs a
subsystem prefix.
Signed-off-by: Pratyush Yadav (Google) <pratyush@kernel.org>
---
include/linux/memfd.h | 6 ++++++
mm/memfd.c | 4 ++--
2 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/include/linux/memfd.h b/include/linux/memfd.h
index cc74de3dbcfe..c328a7b356d0 100644
--- a/include/linux/memfd.h
+++ b/include/linux/memfd.h
@@ -17,6 +17,7 @@ struct folio *memfd_alloc_folio(struct file *memfd, pgoff_t idx);
* to by vm_flags_ptr.
*/
int memfd_check_seals_mmap(struct file *file, vm_flags_t *vm_flags_ptr);
+struct file *memfd_alloc_file(const char *name, unsigned int flags);
#else
static inline long memfd_fcntl(struct file *f, unsigned int c, unsigned int a)
{
@@ -31,6 +32,11 @@ static inline int memfd_check_seals_mmap(struct file *file,
{
return 0;
}
+
+static inline struct file *memfd_alloc_file(const char *name, unsigned int flags)
+{
+ return ERR_PTR(-EINVAL);
+}
#endif
#endif /* __LINUX_MEMFD_H */
diff --git a/mm/memfd.c b/mm/memfd.c
index ab5312aff14b..f032c6052926 100644
--- a/mm/memfd.c
+++ b/mm/memfd.c
@@ -456,7 +456,7 @@ static char *alloc_name(const char __user *uname)
return ERR_PTR(error);
}
-static struct file *alloc_file(const char *name, unsigned int flags)
+struct file *memfd_alloc_file(const char *name, unsigned int flags)
{
unsigned int *file_seals;
struct file *file;
@@ -520,5 +520,5 @@ SYSCALL_DEFINE2(memfd_create,
return PTR_ERR(name);
fd_flags = (flags & MFD_CLOEXEC) ? O_CLOEXEC : 0;
- return FD_ADD(fd_flags, alloc_file(name, flags));
+ return FD_ADD(fd_flags, memfd_alloc_file(name, flags));
}
--
2.52.0.457.g6b5491de43-goog
> ---
> include/linux/memfd.h | 6 ++++++
> mm/memfd.c | 4 ++--
> 2 files changed, 8 insertions(+), 2 deletions(-)
>
> diff --git a/include/linux/memfd.h b/include/linux/memfd.h
> index cc74de3dbcfe..c328a7b356d0 100644
> --- a/include/linux/memfd.h
> +++ b/include/linux/memfd.h
> @@ -17,6 +17,7 @@ struct folio *memfd_alloc_folio(struct file *memfd, pgoff_t idx);
> * to by vm_flags_ptr.
> */
> int memfd_check_seals_mmap(struct file *file, vm_flags_t *vm_flags_ptr);
> +struct file *memfd_alloc_file(const char *name, unsigned int flags);
> #else
> static inline long memfd_fcntl(struct file *f, unsigned int c, unsigned int a)
> {
> @@ -31,6 +32,11 @@ static inline int memfd_check_seals_mmap(struct file *file,
> {
> return 0;
> }
> +
> +static inline struct file *memfd_alloc_file(const char *name, unsigned int flags)
> +{
> + return ERR_PTR(-EINVAL);
> +}
> #endif
>
> #endif /* __LINUX_MEMFD_H */
> diff --git a/mm/memfd.c b/mm/memfd.c
> index ab5312aff14b..f032c6052926 100644
> --- a/mm/memfd.c
> +++ b/mm/memfd.c
> @@ -456,7 +456,7 @@ static char *alloc_name(const char __user *uname)
> return ERR_PTR(error);
> }
>
> -static struct file *alloc_file(const char *name, unsigned int flags)
> +struct file *memfd_alloc_file(const char *name, unsigned int flags)
> {
> unsigned int *file_seals;
> struct file *file;
> @@ -520,5 +520,5 @@ SYSCALL_DEFINE2(memfd_create,
> return PTR_ERR(name);
>
> fd_flags = (flags & MFD_CLOEXEC) ? O_CLOEXEC : 0;
> - return FD_ADD(fd_flags, alloc_file(name, flags));
> + return FD_ADD(fd_flags, memfd_alloc_file(name, flags));
> }
Reviewed-by: Pasha Tatashin <pasha.tatashin@soleen.com>
On Thu, Jan 22, 2026 at 04:18:39PM +0100, Pratyush Yadav wrote: > From: "Pratyush Yadav (Google)" <pratyush@kernel.org> > > The Live Update Orchestrator's (LUO) memfd preservation works by > preserving all the folios of a memfd, re-creating an empty memfd on the > next boot, and then inserting back the preserved folios. > > Currently it creates the file by directly calling shmem_file_setup(). > This leaves out other work done by alloc_file() like setting up the file > mode, flags, or calling the security hooks. > > Export alloc_file() to let memfd_luo use it. Rename it to > memfd_alloc_file() since it is no longer private and thus needs a > subsystem prefix. > > Signed-off-by: Pratyush Yadav (Google) <pratyush@kernel.org> Reviewed-by: Mike Rapoport (Microsoft) <rppt@kernel.org> -- Sincerely yours, Mike.
© 2016 - 2026 Red Hat, Inc.