memfd: export alloc_file()

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>

authored by

Pratyush Yadav (Google) and committed by
Andrew Morton
71e2b5ea dd9e2f5b

+8 -2
+6
include/linux/memfd.h
··· 17 * to by vm_flags_ptr. 18 */ 19 int memfd_check_seals_mmap(struct file *file, vm_flags_t *vm_flags_ptr); 20 #else 21 static inline long memfd_fcntl(struct file *f, unsigned int c, unsigned int a) 22 { ··· 31 vm_flags_t *vm_flags_ptr) 32 { 33 return 0; 34 } 35 #endif 36
··· 17 * to by vm_flags_ptr. 18 */ 19 int memfd_check_seals_mmap(struct file *file, vm_flags_t *vm_flags_ptr); 20 + struct file *memfd_alloc_file(const char *name, unsigned int flags); 21 #else 22 static inline long memfd_fcntl(struct file *f, unsigned int c, unsigned int a) 23 { ··· 30 vm_flags_t *vm_flags_ptr) 31 { 32 return 0; 33 + } 34 + 35 + static inline struct file *memfd_alloc_file(const char *name, unsigned int flags) 36 + { 37 + return ERR_PTR(-EINVAL); 38 } 39 #endif 40
+2 -2
mm/memfd.c
··· 456 return ERR_PTR(error); 457 } 458 459 - static struct file *alloc_file(const char *name, unsigned int flags) 460 { 461 unsigned int *file_seals; 462 struct file *file; ··· 520 return PTR_ERR(name); 521 522 fd_flags = (flags & MFD_CLOEXEC) ? O_CLOEXEC : 0; 523 - return FD_ADD(fd_flags, alloc_file(name, flags)); 524 }
··· 456 return ERR_PTR(error); 457 } 458 459 + struct file *memfd_alloc_file(const char *name, unsigned int flags) 460 { 461 unsigned int *file_seals; 462 struct file *file; ··· 520 return PTR_ERR(name); 521 522 fd_flags = (flags & MFD_CLOEXEC) ? O_CLOEXEC : 0; 523 + return FD_ADD(fd_flags, memfd_alloc_file(name, flags)); 524 }