]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
memfd: export alloc_file()
authorPratyush Yadav (Google) <pratyush@kernel.org>
Thu, 22 Jan 2026 15:18:39 +0000 (16:18 +0100)
committerAndrew Morton <akpm@linux-foundation.org>
Tue, 27 Jan 2026 03:03:47 +0000 (19:03 -0800)
Patch series "mm: memfd_luo hotfixes".

This series contains a couple of fixes for memfd preservation using LUO.

This patch (of 3):

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.

Link: https://lkml.kernel.org/r/20260122151842.4069702-1-pratyush@kernel.org
Link: https://lkml.kernel.org/r/20260122151842.4069702-2-pratyush@kernel.org
Signed-off-by: Pratyush Yadav (Google) <pratyush@kernel.org>
Reviewed-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
Reviewed-by: Pasha Tatashin <pasha.tatashin@soleen.com>
Cc: Baolin Wang <baolin.wang@linux.alibaba.com>
Cc: Hugh Dickins <hughd@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
include/linux/memfd.h
mm/memfd.c

index cc74de3dbcfe93d327f45748439e9cf604bba5e7..c328a7b356d0e558842b8fbc718205f1ed80f922 100644 (file)
@@ -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 */
index ab5312aff14b97a5d06bcc900a1fba27fbaba625..f032c60529265cd16dcd0668ab8e6557a6c6972b 100644 (file)
@@ -456,7 +456,7 @@ err_name:
        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));
 }