From e217a7582aece7883c6372c50a3a7c8122d0477c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=C2=A0Miros=C5=82aw?= Date: Thu, 3 Aug 2023 16:53:59 +0200 Subject: [PATCH] memfd: make memfd_open() skip fd attributes not needed for vma mapping MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There is only one user of memfd_open() outside of memfd.c: open_filemap(). It is restoring a file-backed mapping and doesn't need to F_SETOWN nor update the fd's position. Signed-off-by: Michał Mirosław --- criu/memfd.c | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/criu/memfd.c b/criu/memfd.c index 2158b67206..657f265727 100644 --- a/criu/memfd.c +++ b/criu/memfd.c @@ -355,14 +355,6 @@ int memfd_open(struct file_desc *d, u32 *fdflags) close(fd); fd = _fd; - if (restore_fown(fd, mfe->fown) < 0) - goto err; - - if (lseek(fd, mfe->pos, SEEK_SET) < 0) { - pr_perror("Can't restore file position of memfd id=%d", mfe->id); - goto err; - } - return fd; err: @@ -371,14 +363,26 @@ int memfd_open(struct file_desc *d, u32 *fdflags) return -1; } -static int memfd_open_fe_fd(struct file_desc *fd, int *new_fd) +static int memfd_open_fe_fd(struct file_desc *d, int *new_fd) { - int tmp; + MemfdFileEntry *mfe; + int fd; - tmp = memfd_open(fd, NULL); - if (tmp < 0) + fd = memfd_open(d, NULL); + if (fd < 0) return -1; - *new_fd = tmp; + + mfe = container_of(d, struct memfd_info, d)->mfe; + + if (restore_fown(fd, mfe->fown) < 0) + goto err; + + if (lseek(fd, mfe->pos, SEEK_SET) < 0) { + pr_perror("Can't restore file position of %d for memfd id=%d", fd, mfe->id); + goto err; + } + + *new_fd = fd; return 0; }