* [PATCH 00/10] convert the majority of file systems to mmap_prepare
@ 2025-06-16 19:33 Lorenzo Stoakes
2025-06-16 19:33 ` [PATCH 01/10] mm: rename call_mmap/mmap_prepare to vfs_mmap/mmap_prepare Lorenzo Stoakes
` (15 more replies)
0 siblings, 16 replies; 50+ messages in thread
From: Lorenzo Stoakes @ 2025-06-16 19:33 UTC (permalink / raw)
To: Andrew Morton
Cc: Liam R . Howlett, Jens Axboe, Jani Nikula, Joonas Lahtinen,
Rodrigo Vivi, Tvrtko Ursulin, David Airlie, Simona Vetter,
Eric Van Hensbergen, Latchesar Ionkov, Dominique Martinet,
Christian Schoenebeck, David Sterba, David Howells, Marc Dionne,
Alexander Viro, Christian Brauner, Jan Kara, Benjamin LaHaise,
Miklos Szeredi, Amir Goldstein, Kent Overstreet,
Tigran A . Aivazian, Kees Cook, Chris Mason, Josef Bacik,
Xiubo Li, Ilya Dryomov, Jan Harkes, coda, Tyler Hicks, Gao Xiang,
Chao Yu, Yue Hu, Jeffle Xu, Sandeep Dhavale, Hongbo Li,
Namjae Jeon, Sungjong Seo, Yuezhang Mo, Theodore Ts'o,
Andreas Dilger, Jaegeuk Kim, OGAWA Hirofumi, Viacheslav Dubeyko,
John Paul Adrian Glaubitz, Yangtao Li, Richard Weinberger,
Anton Ivanov, Johannes Berg, Mikulas Patocka, David Woodhouse,
Dave Kleikamp, Trond Myklebust, Anna Schumaker, Ryusuke Konishi,
Konstantin Komarov, Mark Fasheh, Joel Becker, Joseph Qi,
Bob Copeland, Mike Marshall, Martin Brandenburg, Steve French,
Paulo Alcantara, Ronnie Sahlberg, Shyam Prasad N, Tom Talpey,
Bharath SM, Zhihao Cheng, Hans de Goede, Carlos Maiolino,
Damien Le Moal, Naohiro Aota, Johannes Thumshirn, Dan Williams,
Matthew Wilcox, Vlastimil Babka, Jann Horn, Pedro Falcato,
linux-block, linux-kernel, intel-gfx, dri-devel, v9fs,
linux-fsdevel, linux-afs, linux-aio, linux-unionfs,
linux-bcachefs, linux-mm, linux-btrfs, ceph-devel, codalist,
ecryptfs, linux-erofs, linux-ext4, linux-f2fs-devel, linux-um,
linux-mtd, jfs-discussion, linux-nfs, linux-nilfs, ntfs3,
ocfs2-devel, linux-karma-devel, devel, linux-cifs,
samba-technical, linux-xfs, nvdimm
REVIEWER'S NOTES
================
I am basing this on the mm-new branch in Andrew's tree, so let me know if I
should rebase anything here. Given the mm bits touched I did think perhaps
we should take it through the mm tree, however it may be more sensible to
take it through an fs tree - let me know!
Apologies for the noise/churn, but there are some prerequisite steps here
that inform an ordering - "fs: consistently use file_has_valid_mmap_hooks()
helper" being especially critical, and so I put the bulk of the work in the
same series.
Let me know if there's anything I can do to make life easier here.
Thanks!
===============
In commit c84bf6dd2b83 ("mm: introduce new .mmap_prepare() file
callback"), a new hook for mmap was introduced - f_op->mmap_prepare().
This is preferred to the existing f_op->mmap() hook as it does require a
VMA to be established yet, thus allowing the mmap logic to invoke this hook
far, far earlier, prior to inserting a VMA into the virtual address space,
or performing any other heavy handed operations.
This allows for much simpler unwinding on error, and for there to be a
single attempt at merging a VMA rather than having to possibly reattempt a
merge based on potentially altered VMA state.
Far more importantly, it prevents inappropriate manipulation of
incompletely initialised VMA state, which is something that has been the
cause of bugs and complexity in the past.
The intent is to gradually deprecate f_op->mmap, and in that vein this
series coverts the majority of file systems to using f_op->mmap_prepare.
Prerequisite steps are taken - firstly ensuring all checks for mmap
capabilities use the file_has_valid_mmap_hooks() helper rather than
directly checking for f_op->mmap (which is now not a valid check) and
secondly updating daxdev_mapping_supported() to not require a VMA parameter
to allow ext4 and xfs to be converted.
Commit bb666b7c2707 ("mm: add mmap_prepare() compatibility layer for nested
file systems") handles the nasty edge-case of nested file systems like
overlayfs, which introduces a compatibility shim to allow
f_op->mmap_prepare() to be invoked from an f_op->mmap() callback.
This allows for nested filesystems to continue to function correctly with
all file systems regardless of which callback is used. Once we finally
convert all file systems, this shim can be removed.
As a result, ecryptfs, fuse, and overlayfs remain unaltered so they can
nest all other file systems.
We additionally do not update resctl - as this requires an update to
remap_pfn_range() (or an alternative to it) which we defer to a later
series, equally we do not update cramfs which needs a mixed mapping
insertion with the same issue, nor do we update procfs, hugetlbfs, syfs or
kernfs all of which require VMAs for internal state and hooks. We shall
return to all of these later.
Lorenzo Stoakes (10):
mm: rename call_mmap/mmap_prepare to vfs_mmap/mmap_prepare
mm/nommu: use file_has_valid_mmap_hooks() helper
fs: consistently use file_has_valid_mmap_hooks() helper
fs/dax: make it possible to check dev dax support without a VMA
fs/ext4: transition from deprecated .mmap hook to .mmap_prepare
fs/xfs: transition from deprecated .mmap hook to .mmap_prepare
mm/filemap: introduce generic_file_*_mmap_prepare() helpers
fs: convert simple use of generic_file_*_mmap() to .mmap_prepare()
fs: convert most other generic_file_*mmap() users to .mmap_prepare()
fs: replace mmap hook with .mmap_prepare for simple mappings
block/fops.c | 9 +++---
drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c | 2 +-
fs/9p/vfs_file.c | 13 +++++----
fs/adfs/file.c | 2 +-
fs/affs/file.c | 2 +-
fs/afs/file.c | 11 ++++----
fs/aio.c | 8 +++---
fs/backing-file.c | 4 +--
fs/bcachefs/fs.c | 8 +++---
fs/bfs/file.c | 2 +-
fs/binfmt_elf.c | 4 +--
fs/binfmt_elf_fdpic.c | 2 +-
fs/btrfs/file.c | 7 +++--
fs/ceph/addr.c | 5 ++--
fs/ceph/file.c | 2 +-
fs/ceph/super.h | 2 +-
fs/coda/file.c | 6 ++--
fs/ecryptfs/file.c | 2 +-
fs/erofs/data.c | 16 ++++++-----
fs/exfat/file.c | 7 +++--
fs/ext2/file.c | 12 ++++----
fs/ext4/file.c | 13 +++++----
fs/f2fs/file.c | 7 +++--
fs/fat/file.c | 2 +-
fs/hfs/inode.c | 2 +-
fs/hfsplus/inode.c | 2 +-
fs/hostfs/hostfs_kern.c | 2 +-
fs/hpfs/file.c | 2 +-
fs/jffs2/file.c | 2 +-
fs/jfs/file.c | 2 +-
fs/minix/file.c | 2 +-
fs/nfs/file.c | 13 +++++----
fs/nfs/internal.h | 2 +-
fs/nfs/nfs4file.c | 2 +-
fs/nilfs2/file.c | 8 +++---
fs/ntfs3/file.c | 15 +++++-----
fs/ocfs2/file.c | 4 +--
fs/ocfs2/mmap.c | 5 ++--
fs/ocfs2/mmap.h | 2 +-
fs/omfs/file.c | 2 +-
fs/orangefs/file.c | 10 ++++---
fs/ramfs/file-mmu.c | 2 +-
fs/ramfs/file-nommu.c | 12 ++++----
fs/read_write.c | 2 +-
fs/romfs/mmap-nommu.c | 6 ++--
fs/smb/client/cifsfs.c | 12 ++++----
fs/smb/client/cifsfs.h | 4 +--
fs/smb/client/file.c | 14 ++++++----
fs/ubifs/file.c | 8 +++---
fs/ufs/file.c | 2 +-
fs/vboxsf/file.c | 8 +++---
fs/xfs/xfs_file.c | 15 +++++-----
fs/zonefs/file.c | 10 ++++---
include/linux/dax.h | 16 ++++++-----
include/linux/fs.h | 11 ++++----
ipc/shm.c | 2 +-
mm/filemap.c | 29 ++++++++++++++++++++
mm/internal.h | 2 +-
mm/nommu.c | 2 +-
mm/vma.c | 2 +-
tools/testing/vma/vma_internal.h | 32 ++++++++++++++++++----
61 files changed, 245 insertions(+), 171 deletions(-)
--
2.49.0
^ permalink raw reply [flat|nested] 50+ messages in thread
* [PATCH 01/10] mm: rename call_mmap/mmap_prepare to vfs_mmap/mmap_prepare
2025-06-16 19:33 [PATCH 00/10] convert the majority of file systems to mmap_prepare Lorenzo Stoakes
@ 2025-06-16 19:33 ` Lorenzo Stoakes
2025-06-17 5:10 ` Christoph Hellwig
2025-06-17 18:57 ` Vlastimil Babka
2025-06-16 19:33 ` [PATCH 02/10] mm/nommu: use file_has_valid_mmap_hooks() helper Lorenzo Stoakes
` (14 subsequent siblings)
15 siblings, 2 replies; 50+ messages in thread
From: Lorenzo Stoakes @ 2025-06-16 19:33 UTC (permalink / raw)
To: Andrew Morton
Cc: Liam R . Howlett, Jens Axboe, Jani Nikula, Joonas Lahtinen,
Rodrigo Vivi, Tvrtko Ursulin, David Airlie, Simona Vetter,
Eric Van Hensbergen, Latchesar Ionkov, Dominique Martinet,
Christian Schoenebeck, David Sterba, David Howells, Marc Dionne,
Alexander Viro, Christian Brauner, Jan Kara, Benjamin LaHaise,
Miklos Szeredi, Amir Goldstein, Kent Overstreet,
Tigran A . Aivazian, Kees Cook, Chris Mason, Josef Bacik,
Xiubo Li, Ilya Dryomov, Jan Harkes, coda, Tyler Hicks, Gao Xiang,
Chao Yu, Yue Hu, Jeffle Xu, Sandeep Dhavale, Hongbo Li,
Namjae Jeon, Sungjong Seo, Yuezhang Mo, Theodore Ts'o,
Andreas Dilger, Jaegeuk Kim, OGAWA Hirofumi, Viacheslav Dubeyko,
John Paul Adrian Glaubitz, Yangtao Li, Richard Weinberger,
Anton Ivanov, Johannes Berg, Mikulas Patocka, David Woodhouse,
Dave Kleikamp, Trond Myklebust, Anna Schumaker, Ryusuke Konishi,
Konstantin Komarov, Mark Fasheh, Joel Becker, Joseph Qi,
Bob Copeland, Mike Marshall, Martin Brandenburg, Steve French,
Paulo Alcantara, Ronnie Sahlberg, Shyam Prasad N, Tom Talpey,
Bharath SM, Zhihao Cheng, Hans de Goede, Carlos Maiolino,
Damien Le Moal, Naohiro Aota, Johannes Thumshirn, Dan Williams,
Matthew Wilcox, Vlastimil Babka, Jann Horn, Pedro Falcato,
linux-block, linux-kernel, intel-gfx, dri-devel, v9fs,
linux-fsdevel, linux-afs, linux-aio, linux-unionfs,
linux-bcachefs, linux-mm, linux-btrfs, ceph-devel, codalist,
ecryptfs, linux-erofs, linux-ext4, linux-f2fs-devel, linux-um,
linux-mtd, jfs-discussion, linux-nfs, linux-nilfs, ntfs3,
ocfs2-devel, linux-karma-devel, devel, linux-cifs,
samba-technical, linux-xfs, nvdimm
The call_mmap() function violates the existing convention in
include/linux/fs.h whereby invocations of virtual file system hooks is
performed by functions prefixed with vfs_xxx().
Correct this by renaming call_mmap() to vfs_mmap(). This also avoids
confusion as to the fact that f_op->mmap_prepare may be invoked here.
Also rename __call_mmap_prepare() function to vfs_mmap_prepare() and adjust
to accept a file parameter, this is useful later for nested file systems.
Finally, fix up the VMA userland tests and ensure the mmap_prepare -> mmap
shim is implemented there.
Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
---
drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c | 2 +-
fs/backing-file.c | 2 +-
fs/coda/file.c | 4 +--
include/linux/fs.h | 5 ++--
ipc/shm.c | 2 +-
mm/internal.h | 2 +-
mm/vma.c | 2 +-
tools/testing/vma/vma_internal.h | 32 ++++++++++++++++++----
8 files changed, 35 insertions(+), 16 deletions(-)
diff --git a/drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c b/drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c
index 05e440643aa2..f4f1c979d1b9 100644
--- a/drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c
+++ b/drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c
@@ -105,7 +105,7 @@ static int i915_gem_dmabuf_mmap(struct dma_buf *dma_buf, struct vm_area_struct *
if (!obj->base.filp)
return -ENODEV;
- ret = call_mmap(obj->base.filp, vma);
+ ret = vfs_mmap(obj->base.filp, vma);
if (ret)
return ret;
diff --git a/fs/backing-file.c b/fs/backing-file.c
index 763fbe9b72b2..04018679bf69 100644
--- a/fs/backing-file.c
+++ b/fs/backing-file.c
@@ -339,7 +339,7 @@ int backing_file_mmap(struct file *file, struct vm_area_struct *vma,
vma_set_file(vma, file);
old_cred = override_creds(ctx->cred);
- ret = call_mmap(vma->vm_file, vma);
+ ret = vfs_mmap(vma->vm_file, vma);
revert_creds(old_cred);
if (ctx->accessed)
diff --git a/fs/coda/file.c b/fs/coda/file.c
index 148856a582a9..2e6ea9319b35 100644
--- a/fs/coda/file.c
+++ b/fs/coda/file.c
@@ -199,10 +199,10 @@ coda_file_mmap(struct file *coda_file, struct vm_area_struct *vma)
spin_unlock(&cii->c_lock);
vma->vm_file = get_file(host_file);
- ret = call_mmap(vma->vm_file, vma);
+ ret = vfs_mmap(vma->vm_file, vma);
if (ret) {
- /* if call_mmap fails, our caller will put host_file so we
+ /* if vfs_mmap fails, our caller will put host_file so we
* should drop the reference to the coda_file that we got.
*/
fput(coda_file);
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 93ee0d2d6f1a..7120f80255b3 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -2278,7 +2278,7 @@ static inline bool file_has_valid_mmap_hooks(struct file *file)
int compat_vma_mmap_prepare(struct file *file, struct vm_area_struct *vma);
-static inline int call_mmap(struct file *file, struct vm_area_struct *vma)
+static inline int vfs_mmap(struct file *file, struct vm_area_struct *vma)
{
if (file->f_op->mmap_prepare)
return compat_vma_mmap_prepare(file, vma);
@@ -2286,8 +2286,7 @@ static inline int call_mmap(struct file *file, struct vm_area_struct *vma)
return file->f_op->mmap(file, vma);
}
-static inline int __call_mmap_prepare(struct file *file,
- struct vm_area_desc *desc)
+static inline int vfs_mmap_prepare(struct file *file, struct vm_area_desc *desc)
{
return file->f_op->mmap_prepare(desc);
}
diff --git a/ipc/shm.c b/ipc/shm.c
index 492fcc699985..a9310b6dbbc3 100644
--- a/ipc/shm.c
+++ b/ipc/shm.c
@@ -602,7 +602,7 @@ static int shm_mmap(struct file *file, struct vm_area_struct *vma)
if (ret)
return ret;
- ret = call_mmap(sfd->file, vma);
+ ret = vfs_mmap(sfd->file, vma);
if (ret) {
__shm_close(sfd);
return ret;
diff --git a/mm/internal.h b/mm/internal.h
index 3823fb356d3b..a55c88afff6d 100644
--- a/mm/internal.h
+++ b/mm/internal.h
@@ -165,7 +165,7 @@ static inline void *folio_raw_mapping(const struct folio *folio)
*/
static inline int mmap_file(struct file *file, struct vm_area_struct *vma)
{
- int err = call_mmap(file, vma);
+ int err = vfs_mmap(file, vma);
if (likely(!err))
return 0;
diff --git a/mm/vma.c b/mm/vma.c
index 5d35adadf2b5..f548bede3bbe 100644
--- a/mm/vma.c
+++ b/mm/vma.c
@@ -2582,7 +2582,7 @@ static int call_mmap_prepare(struct mmap_state *map)
};
/* Invoke the hook. */
- err = __call_mmap_prepare(map->file, &desc);
+ err = vfs_mmap_prepare(map->file, &desc);
if (err)
return err;
diff --git a/tools/testing/vma/vma_internal.h b/tools/testing/vma/vma_internal.h
index d7fea56e3bb3..51dd122b8d50 100644
--- a/tools/testing/vma/vma_internal.h
+++ b/tools/testing/vma/vma_internal.h
@@ -1458,6 +1458,27 @@ static inline void free_anon_vma_name(struct vm_area_struct *vma)
(void)vma;
}
+/* Declared in vma.h. */
+static inline void set_vma_from_desc(struct vm_area_struct *vma,
+ struct vm_area_desc *desc);
+
+static inline struct vm_area_desc *vma_to_desc(struct vm_area_struct *vma,
+ struct vm_area_desc *desc);
+
+static int compat_vma_mmap_prepare(struct file *file,
+ struct vm_area_struct *vma)
+{
+ struct vm_area_desc desc;
+ int err;
+
+ err = file->f_op->mmap_prepare(vma_to_desc(vma, &desc));
+ if (err)
+ return err;
+ set_vma_from_desc(vma, &desc);
+
+ return 0;
+}
+
/* Did the driver provide valid mmap hook configuration? */
static inline bool file_has_valid_mmap_hooks(struct file *file)
{
@@ -1467,22 +1488,21 @@ static inline bool file_has_valid_mmap_hooks(struct file *file)
/* Hooks are mutually exclusive. */
if (WARN_ON_ONCE(has_mmap && has_mmap_prepare))
return false;
- if (WARN_ON_ONCE(!has_mmap && !has_mmap_prepare))
+ if (!has_mmap && !has_mmap_prepare)
return false;
return true;
}
-static inline int call_mmap(struct file *file, struct vm_area_struct *vma)
+static inline int vfs_mmap(struct file *file, struct vm_area_struct *vma)
{
- if (WARN_ON_ONCE(file->f_op->mmap_prepare))
- return -EINVAL;
+ if (file->f_op->mmap_prepare)
+ return compat_vma_mmap_prepare(file, vma);
return file->f_op->mmap(file, vma);
}
-static inline int __call_mmap_prepare(struct file *file,
- struct vm_area_desc *desc)
+static inline int vfs_mmap_prepare(struct file *file, struct vm_area_desc *desc)
{
return file->f_op->mmap_prepare(desc);
}
--
2.49.0
^ permalink raw reply related [flat|nested] 50+ messages in thread
* [PATCH 02/10] mm/nommu: use file_has_valid_mmap_hooks() helper
2025-06-16 19:33 [PATCH 00/10] convert the majority of file systems to mmap_prepare Lorenzo Stoakes
2025-06-16 19:33 ` [PATCH 01/10] mm: rename call_mmap/mmap_prepare to vfs_mmap/mmap_prepare Lorenzo Stoakes
@ 2025-06-16 19:33 ` Lorenzo Stoakes
2025-06-17 10:05 ` Jan Kara
2025-06-17 18:58 ` Vlastimil Babka
2025-06-16 19:33 ` [PATCH 03/10] fs: consistently " Lorenzo Stoakes
` (13 subsequent siblings)
15 siblings, 2 replies; 50+ messages in thread
From: Lorenzo Stoakes @ 2025-06-16 19:33 UTC (permalink / raw)
To: Andrew Morton
Cc: Liam R . Howlett, Jens Axboe, Jani Nikula, Joonas Lahtinen,
Rodrigo Vivi, Tvrtko Ursulin, David Airlie, Simona Vetter,
Eric Van Hensbergen, Latchesar Ionkov, Dominique Martinet,
Christian Schoenebeck, David Sterba, David Howells, Marc Dionne,
Alexander Viro, Christian Brauner, Jan Kara, Benjamin LaHaise,
Miklos Szeredi, Amir Goldstein, Kent Overstreet,
Tigran A . Aivazian, Kees Cook, Chris Mason, Josef Bacik,
Xiubo Li, Ilya Dryomov, Jan Harkes, coda, Tyler Hicks, Gao Xiang,
Chao Yu, Yue Hu, Jeffle Xu, Sandeep Dhavale, Hongbo Li,
Namjae Jeon, Sungjong Seo, Yuezhang Mo, Theodore Ts'o,
Andreas Dilger, Jaegeuk Kim, OGAWA Hirofumi, Viacheslav Dubeyko,
John Paul Adrian Glaubitz, Yangtao Li, Richard Weinberger,
Anton Ivanov, Johannes Berg, Mikulas Patocka, David Woodhouse,
Dave Kleikamp, Trond Myklebust, Anna Schumaker, Ryusuke Konishi,
Konstantin Komarov, Mark Fasheh, Joel Becker, Joseph Qi,
Bob Copeland, Mike Marshall, Martin Brandenburg, Steve French,
Paulo Alcantara, Ronnie Sahlberg, Shyam Prasad N, Tom Talpey,
Bharath SM, Zhihao Cheng, Hans de Goede, Carlos Maiolino,
Damien Le Moal, Naohiro Aota, Johannes Thumshirn, Dan Williams,
Matthew Wilcox, Vlastimil Babka, Jann Horn, Pedro Falcato,
linux-block, linux-kernel, intel-gfx, dri-devel, v9fs,
linux-fsdevel, linux-afs, linux-aio, linux-unionfs,
linux-bcachefs, linux-mm, linux-btrfs, ceph-devel, codalist,
ecryptfs, linux-erofs, linux-ext4, linux-f2fs-devel, linux-um,
linux-mtd, jfs-discussion, linux-nfs, linux-nilfs, ntfs3,
ocfs2-devel, linux-karma-devel, devel, linux-cifs,
samba-technical, linux-xfs, nvdimm
Since commit c84bf6dd2b83 ("mm: introduce new .mmap_prepare() file
callback"), the f_op->mmap() hook has been deprecated in favour of
f_op->mmap_prepare().
Therefore, update the check for file operations supporting mmap() by using
the file_has_valid_mmap_hooks() helper function, which checks for either
f_op->mmap or f_op->mmap_prepare rather than checking only for f_op->mmap
directly.
Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
---
mm/nommu.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/mm/nommu.c b/mm/nommu.c
index b624acec6d2e..38c22ea0a95c 100644
--- a/mm/nommu.c
+++ b/mm/nommu.c
@@ -719,7 +719,7 @@ static int validate_mmap_request(struct file *file,
if (file) {
/* files must support mmap */
- if (!file->f_op->mmap)
+ if (!file_has_valid_mmap_hooks(file))
return -ENODEV;
/* work out if what we've got could possibly be shared
--
2.49.0
^ permalink raw reply related [flat|nested] 50+ messages in thread
* [PATCH 03/10] fs: consistently use file_has_valid_mmap_hooks() helper
2025-06-16 19:33 [PATCH 00/10] convert the majority of file systems to mmap_prepare Lorenzo Stoakes
2025-06-16 19:33 ` [PATCH 01/10] mm: rename call_mmap/mmap_prepare to vfs_mmap/mmap_prepare Lorenzo Stoakes
2025-06-16 19:33 ` [PATCH 02/10] mm/nommu: use file_has_valid_mmap_hooks() helper Lorenzo Stoakes
@ 2025-06-16 19:33 ` Lorenzo Stoakes
2025-06-16 20:01 ` Kees Cook
2025-06-17 5:11 ` Christoph Hellwig
2025-06-16 19:33 ` [PATCH 04/10] fs/dax: make it possible to check dev dax support without a VMA Lorenzo Stoakes
` (12 subsequent siblings)
15 siblings, 2 replies; 50+ messages in thread
From: Lorenzo Stoakes @ 2025-06-16 19:33 UTC (permalink / raw)
To: Andrew Morton
Cc: Liam R . Howlett, Jens Axboe, Jani Nikula, Joonas Lahtinen,
Rodrigo Vivi, Tvrtko Ursulin, David Airlie, Simona Vetter,
Eric Van Hensbergen, Latchesar Ionkov, Dominique Martinet,
Christian Schoenebeck, David Sterba, David Howells, Marc Dionne,
Alexander Viro, Christian Brauner, Jan Kara, Benjamin LaHaise,
Miklos Szeredi, Amir Goldstein, Kent Overstreet,
Tigran A . Aivazian, Kees Cook, Chris Mason, Josef Bacik,
Xiubo Li, Ilya Dryomov, Jan Harkes, coda, Tyler Hicks, Gao Xiang,
Chao Yu, Yue Hu, Jeffle Xu, Sandeep Dhavale, Hongbo Li,
Namjae Jeon, Sungjong Seo, Yuezhang Mo, Theodore Ts'o,
Andreas Dilger, Jaegeuk Kim, OGAWA Hirofumi, Viacheslav Dubeyko,
John Paul Adrian Glaubitz, Yangtao Li, Richard Weinberger,
Anton Ivanov, Johannes Berg, Mikulas Patocka, David Woodhouse,
Dave Kleikamp, Trond Myklebust, Anna Schumaker, Ryusuke Konishi,
Konstantin Komarov, Mark Fasheh, Joel Becker, Joseph Qi,
Bob Copeland, Mike Marshall, Martin Brandenburg, Steve French,
Paulo Alcantara, Ronnie Sahlberg, Shyam Prasad N, Tom Talpey,
Bharath SM, Zhihao Cheng, Hans de Goede, Carlos Maiolino,
Damien Le Moal, Naohiro Aota, Johannes Thumshirn, Dan Williams,
Matthew Wilcox, Vlastimil Babka, Jann Horn, Pedro Falcato,
linux-block, linux-kernel, intel-gfx, dri-devel, v9fs,
linux-fsdevel, linux-afs, linux-aio, linux-unionfs,
linux-bcachefs, linux-mm, linux-btrfs, ceph-devel, codalist,
ecryptfs, linux-erofs, linux-ext4, linux-f2fs-devel, linux-um,
linux-mtd, jfs-discussion, linux-nfs, linux-nilfs, ntfs3,
ocfs2-devel, linux-karma-devel, devel, linux-cifs,
samba-technical, linux-xfs, nvdimm
Since commit c84bf6dd2b83 ("mm: introduce new .mmap_prepare() file
callback"), the f_op->mmap() hook has been deprecated in favour of
f_op->mmap_prepare().
Additionally, commit bb666b7c2707 ("mm: add mmap_prepare() compatibility
layer for nested file systems") permits the use of the .mmap_prepare() hook
even in nested filesystems like overlayfs.
There are a number of places where we check only for f_op->mmap - this is
incorrect now mmap_prepare exists, so update all of these to use the
general helper file_has_valid_mmap_hooks().
Most notably, this updates the elf logic to allow for the ability to
execute binaries on filesystems which have the .mmap_prepare hook, but
additionally we update nested filesystems.
Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
---
fs/backing-file.c | 2 +-
fs/binfmt_elf.c | 4 ++--
fs/binfmt_elf_fdpic.c | 2 +-
fs/coda/file.c | 2 +-
fs/ecryptfs/file.c | 2 +-
5 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/fs/backing-file.c b/fs/backing-file.c
index 04018679bf69..5761db9a52a9 100644
--- a/fs/backing-file.c
+++ b/fs/backing-file.c
@@ -333,7 +333,7 @@ int backing_file_mmap(struct file *file, struct vm_area_struct *vma,
if (WARN_ON_ONCE(!(file->f_mode & FMODE_BACKING)))
return -EIO;
- if (!file->f_op->mmap)
+ if (!file_has_valid_mmap_hooks(file))
return -ENODEV;
vma_set_file(vma, file);
diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
index a43363d593e5..a6750bd9392a 100644
--- a/fs/binfmt_elf.c
+++ b/fs/binfmt_elf.c
@@ -646,7 +646,7 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
if (!elf_check_arch(interp_elf_ex) ||
elf_check_fdpic(interp_elf_ex))
goto out;
- if (!interpreter->f_op->mmap)
+ if (!file_has_valid_mmap_hooks(interpreter))
goto out;
total_size = total_mapping_size(interp_elf_phdata,
@@ -848,7 +848,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
goto out;
if (elf_check_fdpic(elf_ex))
goto out;
- if (!bprm->file->f_op->mmap)
+ if (!file_has_valid_mmap_hooks(bprm->file))
goto out;
elf_phdata = load_elf_phdrs(elf_ex, bprm->file);
diff --git a/fs/binfmt_elf_fdpic.c b/fs/binfmt_elf_fdpic.c
index 9133f3827f90..699bb9a65c27 100644
--- a/fs/binfmt_elf_fdpic.c
+++ b/fs/binfmt_elf_fdpic.c
@@ -109,7 +109,7 @@ static int is_elf(struct elfhdr *hdr, struct file *file)
return 0;
if (!elf_check_arch(hdr))
return 0;
- if (!file->f_op->mmap)
+ if (!file_has_valid_mmap_hooks(file))
return 0;
return 1;
}
diff --git a/fs/coda/file.c b/fs/coda/file.c
index 2e6ea9319b35..eed45a80e9bc 100644
--- a/fs/coda/file.c
+++ b/fs/coda/file.c
@@ -160,7 +160,7 @@ coda_file_mmap(struct file *coda_file, struct vm_area_struct *vma)
size_t count;
int ret;
- if (!host_file->f_op->mmap)
+ if (!file_has_valid_mmap_hooks(host_file))
return -ENODEV;
if (WARN_ON(coda_file != vma->vm_file))
diff --git a/fs/ecryptfs/file.c b/fs/ecryptfs/file.c
index ce0a3c5ed0ca..2bd50d1de5ef 100644
--- a/fs/ecryptfs/file.c
+++ b/fs/ecryptfs/file.c
@@ -193,7 +193,7 @@ static int ecryptfs_mmap(struct file *file, struct vm_area_struct *vma)
* natively. If FILESYSTEM_MAX_STACK_DEPTH > 2 or ecryptfs
* allows recursive mounting, this will need to be extended.
*/
- if (!lower_file->f_op->mmap)
+ if (!file_has_valid_mmap_hooks(lower_file))
return -ENODEV;
return generic_file_mmap(file, vma);
}
--
2.49.0
^ permalink raw reply related [flat|nested] 50+ messages in thread
* [PATCH 04/10] fs/dax: make it possible to check dev dax support without a VMA
2025-06-16 19:33 [PATCH 00/10] convert the majority of file systems to mmap_prepare Lorenzo Stoakes
` (2 preceding siblings ...)
2025-06-16 19:33 ` [PATCH 03/10] fs: consistently " Lorenzo Stoakes
@ 2025-06-16 19:33 ` Lorenzo Stoakes
2025-06-16 20:26 ` Matthew Wilcox
2025-06-16 19:33 ` [PATCH 05/10] fs/ext4: transition from deprecated .mmap hook to .mmap_prepare Lorenzo Stoakes
` (11 subsequent siblings)
15 siblings, 1 reply; 50+ messages in thread
From: Lorenzo Stoakes @ 2025-06-16 19:33 UTC (permalink / raw)
To: Andrew Morton
Cc: Liam R . Howlett, Jens Axboe, Jani Nikula, Joonas Lahtinen,
Rodrigo Vivi, Tvrtko Ursulin, David Airlie, Simona Vetter,
Eric Van Hensbergen, Latchesar Ionkov, Dominique Martinet,
Christian Schoenebeck, David Sterba, David Howells, Marc Dionne,
Alexander Viro, Christian Brauner, Jan Kara, Benjamin LaHaise,
Miklos Szeredi, Amir Goldstein, Kent Overstreet,
Tigran A . Aivazian, Kees Cook, Chris Mason, Josef Bacik,
Xiubo Li, Ilya Dryomov, Jan Harkes, coda, Tyler Hicks, Gao Xiang,
Chao Yu, Yue Hu, Jeffle Xu, Sandeep Dhavale, Hongbo Li,
Namjae Jeon, Sungjong Seo, Yuezhang Mo, Theodore Ts'o,
Andreas Dilger, Jaegeuk Kim, OGAWA Hirofumi, Viacheslav Dubeyko,
John Paul Adrian Glaubitz, Yangtao Li, Richard Weinberger,
Anton Ivanov, Johannes Berg, Mikulas Patocka, David Woodhouse,
Dave Kleikamp, Trond Myklebust, Anna Schumaker, Ryusuke Konishi,
Konstantin Komarov, Mark Fasheh, Joel Becker, Joseph Qi,
Bob Copeland, Mike Marshall, Martin Brandenburg, Steve French,
Paulo Alcantara, Ronnie Sahlberg, Shyam Prasad N, Tom Talpey,
Bharath SM, Zhihao Cheng, Hans de Goede, Carlos Maiolino,
Damien Le Moal, Naohiro Aota, Johannes Thumshirn, Dan Williams,
Matthew Wilcox, Vlastimil Babka, Jann Horn, Pedro Falcato,
linux-block, linux-kernel, intel-gfx, dri-devel, v9fs,
linux-fsdevel, linux-afs, linux-aio, linux-unionfs,
linux-bcachefs, linux-mm, linux-btrfs, ceph-devel, codalist,
ecryptfs, linux-erofs, linux-ext4, linux-f2fs-devel, linux-um,
linux-mtd, jfs-discussion, linux-nfs, linux-nilfs, ntfs3,
ocfs2-devel, linux-karma-devel, devel, linux-cifs,
samba-technical, linux-xfs, nvdimm
This is a prerequisite for adapting those filesystems to use the
.mmap_prepare() hook for mmap()'ing which invoke this check as this hook
does not have access to a VMA pointer.
To effect this, change the signature of daxdev_mapping_supported() and
update its callers (ext4 and xfs mmap()'ing hook code).
Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
---
fs/ext4/file.c | 2 +-
fs/xfs/xfs_file.c | 3 ++-
include/linux/dax.h | 16 +++++++++-------
3 files changed, 12 insertions(+), 9 deletions(-)
diff --git a/fs/ext4/file.c b/fs/ext4/file.c
index 21df81347147..08a814fcd956 100644
--- a/fs/ext4/file.c
+++ b/fs/ext4/file.c
@@ -821,7 +821,7 @@ static int ext4_file_mmap(struct file *file, struct vm_area_struct *vma)
* We don't support synchronous mappings for non-DAX files and
* for DAX files if underneath dax_device is not synchronous.
*/
- if (!daxdev_mapping_supported(vma, dax_dev))
+ if (!daxdev_mapping_supported(vma->vm_flags, vma->vm_file, dax_dev))
return -EOPNOTSUPP;
file_accessed(file);
diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c
index 48254a72071b..ab97ce1f9087 100644
--- a/fs/xfs/xfs_file.c
+++ b/fs/xfs/xfs_file.c
@@ -1924,7 +1924,8 @@ xfs_file_mmap(
* We don't support synchronous mappings for non-DAX files and
* for DAX files if underneath dax_device is not synchronous.
*/
- if (!daxdev_mapping_supported(vma, target->bt_daxdev))
+ if (!daxdev_mapping_supported(vma->vm_flags, vma->vm_file,
+ target->bt_daxdev))
return -EOPNOTSUPP;
file_accessed(file);
diff --git a/include/linux/dax.h b/include/linux/dax.h
index dcc9fcdf14e4..d0092cefb963 100644
--- a/include/linux/dax.h
+++ b/include/linux/dax.h
@@ -65,12 +65,13 @@ size_t dax_recovery_write(struct dax_device *dax_dev, pgoff_t pgoff,
/*
* Check if given mapping is supported by the file / underlying device.
*/
-static inline bool daxdev_mapping_supported(struct vm_area_struct *vma,
- struct dax_device *dax_dev)
+static inline bool daxdev_mapping_supported(vm_flags_t vm_flags,
+ struct file *file,
+ struct dax_device *dax_dev)
{
- if (!(vma->vm_flags & VM_SYNC))
+ if (!(vm_flags & VM_SYNC))
return true;
- if (!IS_DAX(file_inode(vma->vm_file)))
+ if (!IS_DAX(file_inode(file)))
return false;
return dax_synchronous(dax_dev);
}
@@ -110,10 +111,11 @@ static inline void set_dax_nomc(struct dax_device *dax_dev)
static inline void set_dax_synchronous(struct dax_device *dax_dev)
{
}
-static inline bool daxdev_mapping_supported(struct vm_area_struct *vma,
- struct dax_device *dax_dev)
+static inline bool daxdev_mapping_supported(vm_flags_t vm_flags,
+ struct file *file,
+ struct dax_device *dax_dev)
{
- return !(vma->vm_flags & VM_SYNC);
+ return !(vm_flags & VM_SYNC);
}
static inline size_t dax_recovery_write(struct dax_device *dax_dev,
pgoff_t pgoff, void *addr, size_t bytes, struct iov_iter *i)
--
2.49.0
^ permalink raw reply related [flat|nested] 50+ messages in thread
* [PATCH 05/10] fs/ext4: transition from deprecated .mmap hook to .mmap_prepare
2025-06-16 19:33 [PATCH 00/10] convert the majority of file systems to mmap_prepare Lorenzo Stoakes
` (3 preceding siblings ...)
2025-06-16 19:33 ` [PATCH 04/10] fs/dax: make it possible to check dev dax support without a VMA Lorenzo Stoakes
@ 2025-06-16 19:33 ` Lorenzo Stoakes
2025-06-17 10:11 ` Jan Kara
2025-06-16 19:33 ` [PATCH 06/10] fs/xfs: " Lorenzo Stoakes
` (10 subsequent siblings)
15 siblings, 1 reply; 50+ messages in thread
From: Lorenzo Stoakes @ 2025-06-16 19:33 UTC (permalink / raw)
To: Andrew Morton
Cc: Liam R . Howlett, Jens Axboe, Jani Nikula, Joonas Lahtinen,
Rodrigo Vivi, Tvrtko Ursulin, David Airlie, Simona Vetter,
Eric Van Hensbergen, Latchesar Ionkov, Dominique Martinet,
Christian Schoenebeck, David Sterba, David Howells, Marc Dionne,
Alexander Viro, Christian Brauner, Jan Kara, Benjamin LaHaise,
Miklos Szeredi, Amir Goldstein, Kent Overstreet,
Tigran A . Aivazian, Kees Cook, Chris Mason, Josef Bacik,
Xiubo Li, Ilya Dryomov, Jan Harkes, coda, Tyler Hicks, Gao Xiang,
Chao Yu, Yue Hu, Jeffle Xu, Sandeep Dhavale, Hongbo Li,
Namjae Jeon, Sungjong Seo, Yuezhang Mo, Theodore Ts'o,
Andreas Dilger, Jaegeuk Kim, OGAWA Hirofumi, Viacheslav Dubeyko,
John Paul Adrian Glaubitz, Yangtao Li, Richard Weinberger,
Anton Ivanov, Johannes Berg, Mikulas Patocka, David Woodhouse,
Dave Kleikamp, Trond Myklebust, Anna Schumaker, Ryusuke Konishi,
Konstantin Komarov, Mark Fasheh, Joel Becker, Joseph Qi,
Bob Copeland, Mike Marshall, Martin Brandenburg, Steve French,
Paulo Alcantara, Ronnie Sahlberg, Shyam Prasad N, Tom Talpey,
Bharath SM, Zhihao Cheng, Hans de Goede, Carlos Maiolino,
Damien Le Moal, Naohiro Aota, Johannes Thumshirn, Dan Williams,
Matthew Wilcox, Vlastimil Babka, Jann Horn, Pedro Falcato,
linux-block, linux-kernel, intel-gfx, dri-devel, v9fs,
linux-fsdevel, linux-afs, linux-aio, linux-unionfs,
linux-bcachefs, linux-mm, linux-btrfs, ceph-devel, codalist,
ecryptfs, linux-erofs, linux-ext4, linux-f2fs-devel, linux-um,
linux-mtd, jfs-discussion, linux-nfs, linux-nilfs, ntfs3,
ocfs2-devel, linux-karma-devel, devel, linux-cifs,
samba-technical, linux-xfs, nvdimm
Since commit c84bf6dd2b83 ("mm: introduce new .mmap_prepare() file
callback"), the f_op->mmap() hook has been deprecated in favour of
f_op->mmap_prepare().
This callback is invoked in the mmap() logic far earlier, so error handling
can be performed more safely without complicated and bug-prone state
unwinding required should an error arise.
This hook also avoids passing a pointer to a not-yet-correctly-established
VMA avoiding any issues with referencing this data structure.
It rather provides a pointer to the new struct vm_area_desc descriptor type
which contains all required state and allows easy setting of required
parameters without any consideration needing to be paid to locking or
reference counts.
Note that nested filesystems like overlayfs are compatible with an
.mmap_prepare() callback since commit bb666b7c2707 ("mm: add mmap_prepare()
compatibility layer for nested file systems").
Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
---
fs/ext4/file.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/fs/ext4/file.c b/fs/ext4/file.c
index 08a814fcd956..38180e527dbe 100644
--- a/fs/ext4/file.c
+++ b/fs/ext4/file.c
@@ -804,9 +804,10 @@ static const struct vm_operations_struct ext4_file_vm_ops = {
.page_mkwrite = ext4_page_mkwrite,
};
-static int ext4_file_mmap(struct file *file, struct vm_area_struct *vma)
+static int ext4_file_mmap_prepare(struct vm_area_desc *desc)
{
int ret;
+ struct file *file = desc->file;
struct inode *inode = file->f_mapping->host;
struct dax_device *dax_dev = EXT4_SB(inode->i_sb)->s_daxdev;
@@ -821,15 +822,15 @@ static int ext4_file_mmap(struct file *file, struct vm_area_struct *vma)
* We don't support synchronous mappings for non-DAX files and
* for DAX files if underneath dax_device is not synchronous.
*/
- if (!daxdev_mapping_supported(vma->vm_flags, vma->vm_file, dax_dev))
+ if (!daxdev_mapping_supported(desc->vm_flags, file, dax_dev))
return -EOPNOTSUPP;
file_accessed(file);
if (IS_DAX(file_inode(file))) {
- vma->vm_ops = &ext4_dax_vm_ops;
- vm_flags_set(vma, VM_HUGEPAGE);
+ desc->vm_ops = &ext4_dax_vm_ops;
+ desc->vm_flags |= VM_HUGEPAGE;
} else {
- vma->vm_ops = &ext4_file_vm_ops;
+ desc->vm_ops = &ext4_file_vm_ops;
}
return 0;
}
@@ -968,7 +969,7 @@ const struct file_operations ext4_file_operations = {
#ifdef CONFIG_COMPAT
.compat_ioctl = ext4_compat_ioctl,
#endif
- .mmap = ext4_file_mmap,
+ .mmap_prepare = ext4_file_mmap_prepare,
.open = ext4_file_open,
.release = ext4_release_file,
.fsync = ext4_sync_file,
--
2.49.0
^ permalink raw reply related [flat|nested] 50+ messages in thread
* [PATCH 06/10] fs/xfs: transition from deprecated .mmap hook to .mmap_prepare
2025-06-16 19:33 [PATCH 00/10] convert the majority of file systems to mmap_prepare Lorenzo Stoakes
` (4 preceding siblings ...)
2025-06-16 19:33 ` [PATCH 05/10] fs/ext4: transition from deprecated .mmap hook to .mmap_prepare Lorenzo Stoakes
@ 2025-06-16 19:33 ` Lorenzo Stoakes
2025-06-17 5:08 ` Christoph Hellwig
2025-06-16 19:33 ` [PATCH 07/10] mm/filemap: introduce generic_file_*_mmap_prepare() helpers Lorenzo Stoakes
` (9 subsequent siblings)
15 siblings, 1 reply; 50+ messages in thread
From: Lorenzo Stoakes @ 2025-06-16 19:33 UTC (permalink / raw)
To: Andrew Morton
Cc: Liam R . Howlett, Jens Axboe, Jani Nikula, Joonas Lahtinen,
Rodrigo Vivi, Tvrtko Ursulin, David Airlie, Simona Vetter,
Eric Van Hensbergen, Latchesar Ionkov, Dominique Martinet,
Christian Schoenebeck, David Sterba, David Howells, Marc Dionne,
Alexander Viro, Christian Brauner, Jan Kara, Benjamin LaHaise,
Miklos Szeredi, Amir Goldstein, Kent Overstreet,
Tigran A . Aivazian, Kees Cook, Chris Mason, Josef Bacik,
Xiubo Li, Ilya Dryomov, Jan Harkes, coda, Tyler Hicks, Gao Xiang,
Chao Yu, Yue Hu, Jeffle Xu, Sandeep Dhavale, Hongbo Li,
Namjae Jeon, Sungjong Seo, Yuezhang Mo, Theodore Ts'o,
Andreas Dilger, Jaegeuk Kim, OGAWA Hirofumi, Viacheslav Dubeyko,
John Paul Adrian Glaubitz, Yangtao Li, Richard Weinberger,
Anton Ivanov, Johannes Berg, Mikulas Patocka, David Woodhouse,
Dave Kleikamp, Trond Myklebust, Anna Schumaker, Ryusuke Konishi,
Konstantin Komarov, Mark Fasheh, Joel Becker, Joseph Qi,
Bob Copeland, Mike Marshall, Martin Brandenburg, Steve French,
Paulo Alcantara, Ronnie Sahlberg, Shyam Prasad N, Tom Talpey,
Bharath SM, Zhihao Cheng, Hans de Goede, Carlos Maiolino,
Damien Le Moal, Naohiro Aota, Johannes Thumshirn, Dan Williams,
Matthew Wilcox, Vlastimil Babka, Jann Horn, Pedro Falcato,
linux-block, linux-kernel, intel-gfx, dri-devel, v9fs,
linux-fsdevel, linux-afs, linux-aio, linux-unionfs,
linux-bcachefs, linux-mm, linux-btrfs, ceph-devel, codalist,
ecryptfs, linux-erofs, linux-ext4, linux-f2fs-devel, linux-um,
linux-mtd, jfs-discussion, linux-nfs, linux-nilfs, ntfs3,
ocfs2-devel, linux-karma-devel, devel, linux-cifs,
samba-technical, linux-xfs, nvdimm
Since commit c84bf6dd2b83 ("mm: introduce new .mmap_prepare() file
callback"), the f_op->mmap() hook has been deprecated in favour of
f_op->mmap_prepare().
This callback is invoked in the mmap() logic far earlier, so error handling
can be performed more safely without complicated and bug-prone state
unwinding required should an error arise.
This hook also avoids passing a pointer to a not-yet-correctly-established
VMA avoiding any issues with referencing this data structure.
It rather provides a pointer to the new struct vm_area_desc descriptor type
which contains all required state and allows easy setting of required
parameters without any consideration needing to be paid to locking or
reference counts.
Note that nested filesystems like overlayfs are compatible with an
.mmap_prepare() callback since commit bb666b7c2707 ("mm: add mmap_prepare()
compatibility layer for nested file systems").
Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
---
fs/xfs/xfs_file.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c
index ab97ce1f9087..f7b76647d675 100644
--- a/fs/xfs/xfs_file.c
+++ b/fs/xfs/xfs_file.c
@@ -1913,10 +1913,10 @@ static const struct vm_operations_struct xfs_file_vm_ops = {
};
STATIC int
-xfs_file_mmap(
- struct file *file,
- struct vm_area_struct *vma)
+xfs_file_mmap_prepare(
+ struct vm_area_desc *desc)
{
+ struct file *file = desc->file;
struct inode *inode = file_inode(file);
struct xfs_buftarg *target = xfs_inode_buftarg(XFS_I(inode));
@@ -1924,14 +1924,14 @@ xfs_file_mmap(
* We don't support synchronous mappings for non-DAX files and
* for DAX files if underneath dax_device is not synchronous.
*/
- if (!daxdev_mapping_supported(vma->vm_flags, vma->vm_file,
+ if (!daxdev_mapping_supported(desc->vm_flags, file,
target->bt_daxdev))
return -EOPNOTSUPP;
file_accessed(file);
- vma->vm_ops = &xfs_file_vm_ops;
+ desc->vm_ops = &xfs_file_vm_ops;
if (IS_DAX(inode))
- vm_flags_set(vma, VM_HUGEPAGE);
+ desc->vm_flags |= VM_HUGEPAGE;
return 0;
}
@@ -1946,7 +1946,7 @@ const struct file_operations xfs_file_operations = {
#ifdef CONFIG_COMPAT
.compat_ioctl = xfs_file_compat_ioctl,
#endif
- .mmap = xfs_file_mmap,
+ .mmap_prepare = xfs_file_mmap_prepare,
.open = xfs_file_open,
.release = xfs_file_release,
.fsync = xfs_file_fsync,
--
2.49.0
^ permalink raw reply related [flat|nested] 50+ messages in thread
* [PATCH 07/10] mm/filemap: introduce generic_file_*_mmap_prepare() helpers
2025-06-16 19:33 [PATCH 00/10] convert the majority of file systems to mmap_prepare Lorenzo Stoakes
` (5 preceding siblings ...)
2025-06-16 19:33 ` [PATCH 06/10] fs/xfs: " Lorenzo Stoakes
@ 2025-06-16 19:33 ` Lorenzo Stoakes
2025-06-17 10:12 ` Jan Kara
2025-06-17 19:00 ` Vlastimil Babka
2025-06-16 19:33 ` [PATCH 08/10] fs: convert simple use of generic_file_*_mmap() to .mmap_prepare() Lorenzo Stoakes
` (8 subsequent siblings)
15 siblings, 2 replies; 50+ messages in thread
From: Lorenzo Stoakes @ 2025-06-16 19:33 UTC (permalink / raw)
To: Andrew Morton
Cc: Liam R . Howlett, Jens Axboe, Jani Nikula, Joonas Lahtinen,
Rodrigo Vivi, Tvrtko Ursulin, David Airlie, Simona Vetter,
Eric Van Hensbergen, Latchesar Ionkov, Dominique Martinet,
Christian Schoenebeck, David Sterba, David Howells, Marc Dionne,
Alexander Viro, Christian Brauner, Jan Kara, Benjamin LaHaise,
Miklos Szeredi, Amir Goldstein, Kent Overstreet,
Tigran A . Aivazian, Kees Cook, Chris Mason, Josef Bacik,
Xiubo Li, Ilya Dryomov, Jan Harkes, coda, Tyler Hicks, Gao Xiang,
Chao Yu, Yue Hu, Jeffle Xu, Sandeep Dhavale, Hongbo Li,
Namjae Jeon, Sungjong Seo, Yuezhang Mo, Theodore Ts'o,
Andreas Dilger, Jaegeuk Kim, OGAWA Hirofumi, Viacheslav Dubeyko,
John Paul Adrian Glaubitz, Yangtao Li, Richard Weinberger,
Anton Ivanov, Johannes Berg, Mikulas Patocka, David Woodhouse,
Dave Kleikamp, Trond Myklebust, Anna Schumaker, Ryusuke Konishi,
Konstantin Komarov, Mark Fasheh, Joel Becker, Joseph Qi,
Bob Copeland, Mike Marshall, Martin Brandenburg, Steve French,
Paulo Alcantara, Ronnie Sahlberg, Shyam Prasad N, Tom Talpey,
Bharath SM, Zhihao Cheng, Hans de Goede, Carlos Maiolino,
Damien Le Moal, Naohiro Aota, Johannes Thumshirn, Dan Williams,
Matthew Wilcox, Vlastimil Babka, Jann Horn, Pedro Falcato,
linux-block, linux-kernel, intel-gfx, dri-devel, v9fs,
linux-fsdevel, linux-afs, linux-aio, linux-unionfs,
linux-bcachefs, linux-mm, linux-btrfs, ceph-devel, codalist,
ecryptfs, linux-erofs, linux-ext4, linux-f2fs-devel, linux-um,
linux-mtd, jfs-discussion, linux-nfs, linux-nilfs, ntfs3,
ocfs2-devel, linux-karma-devel, devel, linux-cifs,
samba-technical, linux-xfs, nvdimm
Since commit c84bf6dd2b83 ("mm: introduce new .mmap_prepare() file
callback"), the f_op->mmap() hook has been deprecated in favour of
f_op->mmap_prepare().
The generic mmap handlers are very simple, so we can very easily convert
these in advance of converting file systems which use them.
This patch does so.
Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
---
include/linux/fs.h | 6 ++++--
mm/filemap.c | 29 +++++++++++++++++++++++++++++
2 files changed, 33 insertions(+), 2 deletions(-)
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 7120f80255b3..65cffc445fcc 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -3395,8 +3395,10 @@ extern void inode_add_lru(struct inode *inode);
extern int sb_set_blocksize(struct super_block *, int);
extern int sb_min_blocksize(struct super_block *, int);
-extern int generic_file_mmap(struct file *, struct vm_area_struct *);
-extern int generic_file_readonly_mmap(struct file *, struct vm_area_struct *);
+int generic_file_mmap(struct file *, struct vm_area_struct *);
+int generic_file_mmap_prepare(struct vm_area_desc *desc);
+int generic_file_readonly_mmap(struct file *, struct vm_area_struct *);
+int generic_file_readonly_mmap_prepare(struct vm_area_desc *desc);
extern ssize_t generic_write_checks(struct kiocb *, struct iov_iter *);
int generic_write_checks_count(struct kiocb *iocb, loff_t *count);
extern int generic_write_check_limits(struct file *file, loff_t pos,
diff --git a/mm/filemap.c b/mm/filemap.c
index 93fbc2ef232a..e75608cbf420 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -3847,6 +3847,18 @@ int generic_file_mmap(struct file *file, struct vm_area_struct *vma)
return 0;
}
+int generic_file_mmap_prepare(struct vm_area_desc *desc)
+{
+ struct file *file = desc->file;
+ struct address_space *mapping = file->f_mapping;
+
+ if (!mapping->a_ops->read_folio)
+ return -ENOEXEC;
+ file_accessed(file);
+ desc->vm_ops = &generic_file_vm_ops;
+ return 0;
+}
+
/*
* This is for filesystems which do not implement ->writepage.
*/
@@ -3856,6 +3868,13 @@ int generic_file_readonly_mmap(struct file *file, struct vm_area_struct *vma)
return -EINVAL;
return generic_file_mmap(file, vma);
}
+
+int generic_file_readonly_mmap_prepare(struct vm_area_desc *desc)
+{
+ if (is_shared_maywrite(desc->vm_flags))
+ return -EINVAL;
+ return generic_file_mmap_prepare(desc);
+}
#else
vm_fault_t filemap_page_mkwrite(struct vm_fault *vmf)
{
@@ -3865,15 +3884,25 @@ int generic_file_mmap(struct file *file, struct vm_area_struct *vma)
{
return -ENOSYS;
}
+int generic_file_mmap_prepare(struct vm_area_desc *desc)
+{
+ return -ENOSYS;
+}
int generic_file_readonly_mmap(struct file *file, struct vm_area_struct *vma)
{
return -ENOSYS;
}
+int generic_file_readonly_mmap_prepare(struct vm_area_desc *desc)
+{
+ return -ENOSYS;
+}
#endif /* CONFIG_MMU */
EXPORT_SYMBOL(filemap_page_mkwrite);
EXPORT_SYMBOL(generic_file_mmap);
+EXPORT_SYMBOL(generic_file_mmap_prepare);
EXPORT_SYMBOL(generic_file_readonly_mmap);
+EXPORT_SYMBOL(generic_file_readonly_mmap_prepare);
static struct folio *do_read_cache_folio(struct address_space *mapping,
pgoff_t index, filler_t filler, struct file *file, gfp_t gfp)
--
2.49.0
^ permalink raw reply related [flat|nested] 50+ messages in thread
* [PATCH 08/10] fs: convert simple use of generic_file_*_mmap() to .mmap_prepare()
2025-06-16 19:33 [PATCH 00/10] convert the majority of file systems to mmap_prepare Lorenzo Stoakes
` (6 preceding siblings ...)
2025-06-16 19:33 ` [PATCH 07/10] mm/filemap: introduce generic_file_*_mmap_prepare() helpers Lorenzo Stoakes
@ 2025-06-16 19:33 ` Lorenzo Stoakes
2025-06-16 23:26 ` Viacheslav Dubeyko
` (2 more replies)
2025-06-16 19:33 ` [PATCH 09/10] fs: convert most other generic_file_*mmap() users " Lorenzo Stoakes
` (7 subsequent siblings)
15 siblings, 3 replies; 50+ messages in thread
From: Lorenzo Stoakes @ 2025-06-16 19:33 UTC (permalink / raw)
To: Andrew Morton
Cc: Liam R . Howlett, Jens Axboe, Jani Nikula, Joonas Lahtinen,
Rodrigo Vivi, Tvrtko Ursulin, David Airlie, Simona Vetter,
Eric Van Hensbergen, Latchesar Ionkov, Dominique Martinet,
Christian Schoenebeck, David Sterba, David Howells, Marc Dionne,
Alexander Viro, Christian Brauner, Jan Kara, Benjamin LaHaise,
Miklos Szeredi, Amir Goldstein, Kent Overstreet,
Tigran A . Aivazian, Kees Cook, Chris Mason, Josef Bacik,
Xiubo Li, Ilya Dryomov, Jan Harkes, coda, Tyler Hicks, Gao Xiang,
Chao Yu, Yue Hu, Jeffle Xu, Sandeep Dhavale, Hongbo Li,
Namjae Jeon, Sungjong Seo, Yuezhang Mo, Theodore Ts'o,
Andreas Dilger, Jaegeuk Kim, OGAWA Hirofumi, Viacheslav Dubeyko,
John Paul Adrian Glaubitz, Yangtao Li, Richard Weinberger,
Anton Ivanov, Johannes Berg, Mikulas Patocka, David Woodhouse,
Dave Kleikamp, Trond Myklebust, Anna Schumaker, Ryusuke Konishi,
Konstantin Komarov, Mark Fasheh, Joel Becker, Joseph Qi,
Bob Copeland, Mike Marshall, Martin Brandenburg, Steve French,
Paulo Alcantara, Ronnie Sahlberg, Shyam Prasad N, Tom Talpey,
Bharath SM, Zhihao Cheng, Hans de Goede, Carlos Maiolino,
Damien Le Moal, Naohiro Aota, Johannes Thumshirn, Dan Williams,
Matthew Wilcox, Vlastimil Babka, Jann Horn, Pedro Falcato,
linux-block, linux-kernel, intel-gfx, dri-devel, v9fs,
linux-fsdevel, linux-afs, linux-aio, linux-unionfs,
linux-bcachefs, linux-mm, linux-btrfs, ceph-devel, codalist,
ecryptfs, linux-erofs, linux-ext4, linux-f2fs-devel, linux-um,
linux-mtd, jfs-discussion, linux-nfs, linux-nilfs, ntfs3,
ocfs2-devel, linux-karma-devel, devel, linux-cifs,
samba-technical, linux-xfs, nvdimm
Since commit c84bf6dd2b83 ("mm: introduce new .mmap_prepare() file
callback"), the f_op->mmap() hook has been deprecated in favour of
f_op->mmap_prepare().
We have provided generic .mmap_prepare() equivalents, so update all file
systems that specify these directly in their file_operations structures.
This updates 9p, adfs, affs, bfs, fat, hfs, hfsplus, hostfs, hpfs, jffs2,
jfs, minix, omfs, ramfs and ufs file systems directly.
It updates generic_ro_fops which impacts qnx4, cramfs, befs, squashfs,
frebxfs, qnx6, efs, romfs, erofs and isofs file systems.
There are remaining file systems which use generic hooks in a less direct
way which we address in a subsequent commit.
Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
---
fs/9p/vfs_file.c | 2 +-
fs/adfs/file.c | 2 +-
fs/affs/file.c | 2 +-
fs/bfs/file.c | 2 +-
fs/fat/file.c | 2 +-
fs/hfs/inode.c | 2 +-
fs/hfsplus/inode.c | 2 +-
fs/hostfs/hostfs_kern.c | 2 +-
fs/hpfs/file.c | 2 +-
fs/jffs2/file.c | 2 +-
fs/jfs/file.c | 2 +-
fs/minix/file.c | 2 +-
fs/omfs/file.c | 2 +-
fs/ramfs/file-mmu.c | 2 +-
fs/read_write.c | 2 +-
fs/ufs/file.c | 2 +-
16 files changed, 16 insertions(+), 16 deletions(-)
diff --git a/fs/9p/vfs_file.c b/fs/9p/vfs_file.c
index 348cc90bf9c5..2ff3e0ac7266 100644
--- a/fs/9p/vfs_file.c
+++ b/fs/9p/vfs_file.c
@@ -516,7 +516,7 @@ const struct file_operations v9fs_file_operations = {
.open = v9fs_file_open,
.release = v9fs_dir_release,
.lock = v9fs_file_lock,
- .mmap = generic_file_readonly_mmap,
+ .mmap_prepare = generic_file_readonly_mmap_prepare,
.splice_read = v9fs_file_splice_read,
.splice_write = iter_file_splice_write,
.fsync = v9fs_file_fsync,
diff --git a/fs/adfs/file.c b/fs/adfs/file.c
index ee80718aaeec..cd13165fd904 100644
--- a/fs/adfs/file.c
+++ b/fs/adfs/file.c
@@ -25,7 +25,7 @@
const struct file_operations adfs_file_operations = {
.llseek = generic_file_llseek,
.read_iter = generic_file_read_iter,
- .mmap = generic_file_mmap,
+ .mmap_prepare = generic_file_mmap_prepare,
.fsync = generic_file_fsync,
.write_iter = generic_file_write_iter,
.splice_read = filemap_splice_read,
diff --git a/fs/affs/file.c b/fs/affs/file.c
index 7a71018e3f67..fbac204b7055 100644
--- a/fs/affs/file.c
+++ b/fs/affs/file.c
@@ -999,7 +999,7 @@ const struct file_operations affs_file_operations = {
.llseek = generic_file_llseek,
.read_iter = generic_file_read_iter,
.write_iter = generic_file_write_iter,
- .mmap = generic_file_mmap,
+ .mmap_prepare = generic_file_mmap_prepare,
.open = affs_file_open,
.release = affs_file_release,
.fsync = affs_file_fsync,
diff --git a/fs/bfs/file.c b/fs/bfs/file.c
index fa66a09e496a..6685c3411fe7 100644
--- a/fs/bfs/file.c
+++ b/fs/bfs/file.c
@@ -27,7 +27,7 @@ const struct file_operations bfs_file_operations = {
.llseek = generic_file_llseek,
.read_iter = generic_file_read_iter,
.write_iter = generic_file_write_iter,
- .mmap = generic_file_mmap,
+ .mmap_prepare = generic_file_mmap_prepare,
.splice_read = filemap_splice_read,
};
diff --git a/fs/fat/file.c b/fs/fat/file.c
index e887e9ab7472..4fc49a614fb8 100644
--- a/fs/fat/file.c
+++ b/fs/fat/file.c
@@ -204,7 +204,7 @@ const struct file_operations fat_file_operations = {
.llseek = generic_file_llseek,
.read_iter = generic_file_read_iter,
.write_iter = generic_file_write_iter,
- .mmap = generic_file_mmap,
+ .mmap_prepare = generic_file_mmap_prepare,
.release = fat_file_release,
.unlocked_ioctl = fat_generic_ioctl,
.compat_ioctl = compat_ptr_ioctl,
diff --git a/fs/hfs/inode.c b/fs/hfs/inode.c
index a81ce7a740b9..d419586d668d 100644
--- a/fs/hfs/inode.c
+++ b/fs/hfs/inode.c
@@ -690,7 +690,7 @@ static const struct file_operations hfs_file_operations = {
.llseek = generic_file_llseek,
.read_iter = generic_file_read_iter,
.write_iter = generic_file_write_iter,
- .mmap = generic_file_mmap,
+ .mmap_prepare = generic_file_mmap_prepare,
.splice_read = filemap_splice_read,
.fsync = hfs_file_fsync,
.open = hfs_file_open,
diff --git a/fs/hfsplus/inode.c b/fs/hfsplus/inode.c
index f331e9574217..0af7e302730c 100644
--- a/fs/hfsplus/inode.c
+++ b/fs/hfsplus/inode.c
@@ -366,7 +366,7 @@ static const struct file_operations hfsplus_file_operations = {
.llseek = generic_file_llseek,
.read_iter = generic_file_read_iter,
.write_iter = generic_file_write_iter,
- .mmap = generic_file_mmap,
+ .mmap_prepare = generic_file_mmap_prepare,
.splice_read = filemap_splice_read,
.fsync = hfsplus_file_fsync,
.open = hfsplus_file_open,
diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c
index 702c41317589..bc22b6cc72af 100644
--- a/fs/hostfs/hostfs_kern.c
+++ b/fs/hostfs/hostfs_kern.c
@@ -382,7 +382,7 @@ static const struct file_operations hostfs_file_fops = {
.splice_write = iter_file_splice_write,
.read_iter = generic_file_read_iter,
.write_iter = generic_file_write_iter,
- .mmap = generic_file_mmap,
+ .mmap_prepare = generic_file_mmap_prepare,
.open = hostfs_open,
.release = hostfs_file_release,
.fsync = hostfs_fsync,
diff --git a/fs/hpfs/file.c b/fs/hpfs/file.c
index 449a3fc1b8d9..a1a44e3edb19 100644
--- a/fs/hpfs/file.c
+++ b/fs/hpfs/file.c
@@ -255,7 +255,7 @@ const struct file_operations hpfs_file_ops =
.llseek = generic_file_llseek,
.read_iter = generic_file_read_iter,
.write_iter = generic_file_write_iter,
- .mmap = generic_file_mmap,
+ .mmap_prepare = generic_file_mmap_prepare,
.release = hpfs_file_release,
.fsync = hpfs_file_fsync,
.splice_read = filemap_splice_read,
diff --git a/fs/jffs2/file.c b/fs/jffs2/file.c
index 13c18ccc13b0..1e05f7fe5dd4 100644
--- a/fs/jffs2/file.c
+++ b/fs/jffs2/file.c
@@ -54,7 +54,7 @@ const struct file_operations jffs2_file_operations =
.read_iter = generic_file_read_iter,
.write_iter = generic_file_write_iter,
.unlocked_ioctl=jffs2_ioctl,
- .mmap = generic_file_readonly_mmap,
+ .mmap_prepare = generic_file_readonly_mmap_prepare,
.fsync = jffs2_fsync,
.splice_read = filemap_splice_read,
.splice_write = iter_file_splice_write,
diff --git a/fs/jfs/file.c b/fs/jfs/file.c
index 01b6912e60f8..5e47951db630 100644
--- a/fs/jfs/file.c
+++ b/fs/jfs/file.c
@@ -143,7 +143,7 @@ const struct file_operations jfs_file_operations = {
.llseek = generic_file_llseek,
.read_iter = generic_file_read_iter,
.write_iter = generic_file_write_iter,
- .mmap = generic_file_mmap,
+ .mmap_prepare = generic_file_mmap_prepare,
.splice_read = filemap_splice_read,
.splice_write = iter_file_splice_write,
.fsync = jfs_fsync,
diff --git a/fs/minix/file.c b/fs/minix/file.c
index 906d192ab7f3..dca7ac71f049 100644
--- a/fs/minix/file.c
+++ b/fs/minix/file.c
@@ -17,7 +17,7 @@ const struct file_operations minix_file_operations = {
.llseek = generic_file_llseek,
.read_iter = generic_file_read_iter,
.write_iter = generic_file_write_iter,
- .mmap = generic_file_mmap,
+ .mmap_prepare = generic_file_mmap_prepare,
.fsync = generic_file_fsync,
.splice_read = filemap_splice_read,
};
diff --git a/fs/omfs/file.c b/fs/omfs/file.c
index 98358d405b6a..319c04e63964 100644
--- a/fs/omfs/file.c
+++ b/fs/omfs/file.c
@@ -332,7 +332,7 @@ const struct file_operations omfs_file_operations = {
.llseek = generic_file_llseek,
.read_iter = generic_file_read_iter,
.write_iter = generic_file_write_iter,
- .mmap = generic_file_mmap,
+ .mmap_prepare = generic_file_mmap_prepare,
.fsync = generic_file_fsync,
.splice_read = filemap_splice_read,
};
diff --git a/fs/ramfs/file-mmu.c b/fs/ramfs/file-mmu.c
index b45c7edc3225..b11f5b20b78b 100644
--- a/fs/ramfs/file-mmu.c
+++ b/fs/ramfs/file-mmu.c
@@ -41,7 +41,7 @@ static unsigned long ramfs_mmu_get_unmapped_area(struct file *file,
const struct file_operations ramfs_file_operations = {
.read_iter = generic_file_read_iter,
.write_iter = generic_file_write_iter,
- .mmap = generic_file_mmap,
+ .mmap_prepare = generic_file_mmap_prepare,
.fsync = noop_fsync,
.splice_read = filemap_splice_read,
.splice_write = iter_file_splice_write,
diff --git a/fs/read_write.c b/fs/read_write.c
index 0ef70e128c4a..80fdab99f9e4 100644
--- a/fs/read_write.c
+++ b/fs/read_write.c
@@ -28,7 +28,7 @@
const struct file_operations generic_ro_fops = {
.llseek = generic_file_llseek,
.read_iter = generic_file_read_iter,
- .mmap = generic_file_readonly_mmap,
+ .mmap_prepare = generic_file_readonly_mmap_prepare,
.splice_read = filemap_splice_read,
};
diff --git a/fs/ufs/file.c b/fs/ufs/file.c
index 487ad1fc2de6..c2a391c17df7 100644
--- a/fs/ufs/file.c
+++ b/fs/ufs/file.c
@@ -38,7 +38,7 @@ const struct file_operations ufs_file_operations = {
.llseek = generic_file_llseek,
.read_iter = generic_file_read_iter,
.write_iter = generic_file_write_iter,
- .mmap = generic_file_mmap,
+ .mmap_prepare = generic_file_mmap_prepare,
.open = generic_file_open,
.fsync = generic_file_fsync,
.splice_read = filemap_splice_read,
--
2.49.0
^ permalink raw reply related [flat|nested] 50+ messages in thread
* [PATCH 09/10] fs: convert most other generic_file_*mmap() users to .mmap_prepare()
2025-06-16 19:33 [PATCH 00/10] convert the majority of file systems to mmap_prepare Lorenzo Stoakes
` (7 preceding siblings ...)
2025-06-16 19:33 ` [PATCH 08/10] fs: convert simple use of generic_file_*_mmap() to .mmap_prepare() Lorenzo Stoakes
@ 2025-06-16 19:33 ` Lorenzo Stoakes
2025-06-17 10:23 ` Jan Kara
2025-06-16 19:33 ` [PATCH 10/10] fs: replace mmap hook with .mmap_prepare for simple mappings Lorenzo Stoakes
` (6 subsequent siblings)
15 siblings, 1 reply; 50+ messages in thread
From: Lorenzo Stoakes @ 2025-06-16 19:33 UTC (permalink / raw)
To: Andrew Morton
Cc: Liam R . Howlett, Jens Axboe, Jani Nikula, Joonas Lahtinen,
Rodrigo Vivi, Tvrtko Ursulin, David Airlie, Simona Vetter,
Eric Van Hensbergen, Latchesar Ionkov, Dominique Martinet,
Christian Schoenebeck, David Sterba, David Howells, Marc Dionne,
Alexander Viro, Christian Brauner, Jan Kara, Benjamin LaHaise,
Miklos Szeredi, Amir Goldstein, Kent Overstreet,
Tigran A . Aivazian, Kees Cook, Chris Mason, Josef Bacik,
Xiubo Li, Ilya Dryomov, Jan Harkes, coda, Tyler Hicks, Gao Xiang,
Chao Yu, Yue Hu, Jeffle Xu, Sandeep Dhavale, Hongbo Li,
Namjae Jeon, Sungjong Seo, Yuezhang Mo, Theodore Ts'o,
Andreas Dilger, Jaegeuk Kim, OGAWA Hirofumi, Viacheslav Dubeyko,
John Paul Adrian Glaubitz, Yangtao Li, Richard Weinberger,
Anton Ivanov, Johannes Berg, Mikulas Patocka, David Woodhouse,
Dave Kleikamp, Trond Myklebust, Anna Schumaker, Ryusuke Konishi,
Konstantin Komarov, Mark Fasheh, Joel Becker, Joseph Qi,
Bob Copeland, Mike Marshall, Martin Brandenburg, Steve French,
Paulo Alcantara, Ronnie Sahlberg, Shyam Prasad N, Tom Talpey,
Bharath SM, Zhihao Cheng, Hans de Goede, Carlos Maiolino,
Damien Le Moal, Naohiro Aota, Johannes Thumshirn, Dan Williams,
Matthew Wilcox, Vlastimil Babka, Jann Horn, Pedro Falcato,
linux-block, linux-kernel, intel-gfx, dri-devel, v9fs,
linux-fsdevel, linux-afs, linux-aio, linux-unionfs,
linux-bcachefs, linux-mm, linux-btrfs, ceph-devel, codalist,
ecryptfs, linux-erofs, linux-ext4, linux-f2fs-devel, linux-um,
linux-mtd, jfs-discussion, linux-nfs, linux-nilfs, ntfs3,
ocfs2-devel, linux-karma-devel, devel, linux-cifs,
samba-technical, linux-xfs, nvdimm
Update nearly all generic_file_mmap() and generic_file_readonly_mmap()
callers to use generic_file_mmap_prepare() and
generic_file_readonly_mmap_prepare() respectively.
We update blkdev, 9p, afs, erofs, ext2, nfs, ntfs3, smb, ubifs and vboxsf
file systems this way.
Remaining users we cannot yet update are ecryptfs, fuse and cramfs. The
former two are nested file systems that must support any underlying file
ssytem, and cramfs inserts a mixed mapping which currently requires a VMA.
Once all file systems have been converted to mmap_prepare(), we can then
update nested file systems.
Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
---
block/fops.c | 9 +++++----
fs/9p/vfs_file.c | 11 ++++++-----
fs/afs/file.c | 11 ++++++-----
fs/erofs/data.c | 16 +++++++++-------
fs/ext2/file.c | 12 +++++++-----
fs/nfs/file.c | 13 +++++++------
fs/nfs/internal.h | 2 +-
fs/nfs/nfs4file.c | 2 +-
fs/ntfs3/file.c | 15 ++++++++-------
fs/smb/client/cifsfs.c | 12 ++++++------
fs/smb/client/cifsfs.h | 4 ++--
fs/smb/client/file.c | 14 ++++++++------
fs/ubifs/file.c | 8 ++++----
fs/vboxsf/file.c | 8 ++++----
14 files changed, 74 insertions(+), 63 deletions(-)
diff --git a/block/fops.c b/block/fops.c
index 1309861d4c2c..5a0ebc81e489 100644
--- a/block/fops.c
+++ b/block/fops.c
@@ -911,14 +911,15 @@ static long blkdev_fallocate(struct file *file, int mode, loff_t start,
return error;
}
-static int blkdev_mmap(struct file *file, struct vm_area_struct *vma)
+static int blkdev_mmap_prepare(struct vm_area_desc *desc)
{
+ struct file *file = desc->file;
struct inode *bd_inode = bdev_file_inode(file);
if (bdev_read_only(I_BDEV(bd_inode)))
- return generic_file_readonly_mmap(file, vma);
+ return generic_file_readonly_mmap_prepare(desc);
- return generic_file_mmap(file, vma);
+ return generic_file_mmap_prepare(desc);
}
const struct file_operations def_blk_fops = {
@@ -928,7 +929,7 @@ const struct file_operations def_blk_fops = {
.read_iter = blkdev_read_iter,
.write_iter = blkdev_write_iter,
.iopoll = iocb_bio_iopoll,
- .mmap = blkdev_mmap,
+ .mmap_prepare = blkdev_mmap_prepare,
.fsync = blkdev_fsync,
.unlocked_ioctl = blkdev_ioctl,
#ifdef CONFIG_COMPAT
diff --git a/fs/9p/vfs_file.c b/fs/9p/vfs_file.c
index 2ff3e0ac7266..eb0b083da269 100644
--- a/fs/9p/vfs_file.c
+++ b/fs/9p/vfs_file.c
@@ -454,9 +454,10 @@ int v9fs_file_fsync_dotl(struct file *filp, loff_t start, loff_t end,
}
static int
-v9fs_file_mmap(struct file *filp, struct vm_area_struct *vma)
+v9fs_file_mmap_prepare(struct vm_area_desc *desc)
{
int retval;
+ struct file *filp = desc->file;
struct inode *inode = file_inode(filp);
struct v9fs_session_info *v9ses = v9fs_inode2v9ses(inode);
@@ -464,12 +465,12 @@ v9fs_file_mmap(struct file *filp, struct vm_area_struct *vma)
if (!(v9ses->cache & CACHE_WRITEBACK)) {
p9_debug(P9_DEBUG_CACHE, "(read-only mmap mode)");
- return generic_file_readonly_mmap(filp, vma);
+ return generic_file_readonly_mmap_prepare(desc);
}
- retval = generic_file_mmap(filp, vma);
+ retval = generic_file_mmap_prepare(desc);
if (!retval)
- vma->vm_ops = &v9fs_mmap_file_vm_ops;
+ desc->vm_ops = &v9fs_mmap_file_vm_ops;
return retval;
}
@@ -531,7 +532,7 @@ const struct file_operations v9fs_file_operations_dotl = {
.release = v9fs_dir_release,
.lock = v9fs_file_lock_dotl,
.flock = v9fs_file_flock_dotl,
- .mmap = v9fs_file_mmap,
+ .mmap_prepare = v9fs_file_mmap_prepare,
.splice_read = v9fs_file_splice_read,
.splice_write = iter_file_splice_write,
.fsync = v9fs_file_fsync_dotl,
diff --git a/fs/afs/file.c b/fs/afs/file.c
index fc15497608c6..aa899292979b 100644
--- a/fs/afs/file.c
+++ b/fs/afs/file.c
@@ -19,7 +19,7 @@
#include <trace/events/netfs.h>
#include "internal.h"
-static int afs_file_mmap(struct file *file, struct vm_area_struct *vma);
+static int afs_file_mmap_prepare(struct vm_area_desc *desc);
static ssize_t afs_file_read_iter(struct kiocb *iocb, struct iov_iter *iter);
static ssize_t afs_file_splice_read(struct file *in, loff_t *ppos,
@@ -35,7 +35,7 @@ const struct file_operations afs_file_operations = {
.llseek = generic_file_llseek,
.read_iter = afs_file_read_iter,
.write_iter = netfs_file_write_iter,
- .mmap = afs_file_mmap,
+ .mmap_prepare = afs_file_mmap_prepare,
.splice_read = afs_file_splice_read,
.splice_write = iter_file_splice_write,
.fsync = afs_fsync,
@@ -492,16 +492,17 @@ static void afs_drop_open_mmap(struct afs_vnode *vnode)
/*
* Handle setting up a memory mapping on an AFS file.
*/
-static int afs_file_mmap(struct file *file, struct vm_area_struct *vma)
+static int afs_file_mmap_prepare(struct vm_area_desc *desc)
{
+ struct file *file = desc->file;
struct afs_vnode *vnode = AFS_FS_I(file_inode(file));
int ret;
afs_add_open_mmap(vnode);
- ret = generic_file_mmap(file, vma);
+ ret = generic_file_mmap_prepare(desc);
if (ret == 0)
- vma->vm_ops = &afs_vm_ops;
+ desc->vm_ops = &afs_vm_ops;
else
afs_drop_open_mmap(vnode);
return ret;
diff --git a/fs/erofs/data.c b/fs/erofs/data.c
index 6a329c329f43..52dfd1a44c43 100644
--- a/fs/erofs/data.c
+++ b/fs/erofs/data.c
@@ -409,20 +409,22 @@ static const struct vm_operations_struct erofs_dax_vm_ops = {
.huge_fault = erofs_dax_huge_fault,
};
-static int erofs_file_mmap(struct file *file, struct vm_area_struct *vma)
+static int erofs_file_mmap_prepare(struct vm_area_desc *desc)
{
+ struct file *file = desc->file;
+
if (!IS_DAX(file_inode(file)))
- return generic_file_readonly_mmap(file, vma);
+ return generic_file_readonly_mmap_prepare(desc);
- if ((vma->vm_flags & VM_SHARED) && (vma->vm_flags & VM_MAYWRITE))
+ if ((desc->vm_flags & VM_SHARED) && (desc->vm_flags & VM_MAYWRITE))
return -EINVAL;
- vma->vm_ops = &erofs_dax_vm_ops;
- vm_flags_set(vma, VM_HUGEPAGE);
+ desc->vm_ops = &erofs_dax_vm_ops;
+ desc->vm_flags |= VM_HUGEPAGE;
return 0;
}
#else
-#define erofs_file_mmap generic_file_readonly_mmap
+#define erofs_file_mmap_prepare generic_file_readonly_mmap_prepare
#endif
static loff_t erofs_file_llseek(struct file *file, loff_t offset, int whence)
@@ -452,7 +454,7 @@ static loff_t erofs_file_llseek(struct file *file, loff_t offset, int whence)
const struct file_operations erofs_file_fops = {
.llseek = erofs_file_llseek,
.read_iter = erofs_file_read_iter,
- .mmap = erofs_file_mmap,
+ .mmap_prepare = erofs_file_mmap_prepare,
.get_unmapped_area = thp_get_unmapped_area,
.splice_read = filemap_splice_read,
};
diff --git a/fs/ext2/file.c b/fs/ext2/file.c
index 10b061ac5bc0..76bddce462fc 100644
--- a/fs/ext2/file.c
+++ b/fs/ext2/file.c
@@ -122,17 +122,19 @@ static const struct vm_operations_struct ext2_dax_vm_ops = {
.pfn_mkwrite = ext2_dax_fault,
};
-static int ext2_file_mmap(struct file *file, struct vm_area_struct *vma)
+static int ext2_file_mmap_prepare(struct vm_area_desc *desc)
{
+ struct file *file = desc->file;
+
if (!IS_DAX(file_inode(file)))
- return generic_file_mmap(file, vma);
+ return generic_file_mmap_prepare(desc);
file_accessed(file);
- vma->vm_ops = &ext2_dax_vm_ops;
+ desc->vm_ops = &ext2_dax_vm_ops;
return 0;
}
#else
-#define ext2_file_mmap generic_file_mmap
+#define ext2_file_mmap_prepare generic_file_mmap_prepare
#endif
/*
@@ -316,7 +318,7 @@ const struct file_operations ext2_file_operations = {
#ifdef CONFIG_COMPAT
.compat_ioctl = ext2_compat_ioctl,
#endif
- .mmap = ext2_file_mmap,
+ .mmap_prepare = ext2_file_mmap_prepare,
.open = ext2_file_open,
.release = ext2_release_file,
.fsync = ext2_fsync,
diff --git a/fs/nfs/file.c b/fs/nfs/file.c
index 033feeab8c34..b51b75cf981d 100644
--- a/fs/nfs/file.c
+++ b/fs/nfs/file.c
@@ -207,24 +207,25 @@ nfs_file_splice_read(struct file *in, loff_t *ppos, struct pipe_inode_info *pipe
EXPORT_SYMBOL_GPL(nfs_file_splice_read);
int
-nfs_file_mmap(struct file *file, struct vm_area_struct *vma)
+nfs_file_mmap_prepare(struct vm_area_desc *desc)
{
+ struct file *file = desc->file;
struct inode *inode = file_inode(file);
int status;
dprintk("NFS: mmap(%pD2)\n", file);
- /* Note: generic_file_mmap() returns ENOSYS on nommu systems
+ /* Note: generic_file_mmap_prepare() returns ENOSYS on nommu systems
* so we call that before revalidating the mapping
*/
- status = generic_file_mmap(file, vma);
+ status = generic_file_mmap_prepare(desc);
if (!status) {
- vma->vm_ops = &nfs_file_vm_ops;
+ desc->vm_ops = &nfs_file_vm_ops;
status = nfs_revalidate_mapping(inode, file->f_mapping);
}
return status;
}
-EXPORT_SYMBOL_GPL(nfs_file_mmap);
+EXPORT_SYMBOL_GPL(nfs_file_mmap_prepare);
/*
* Flush any dirty pages for this process, and check for write errors.
@@ -899,7 +900,7 @@ const struct file_operations nfs_file_operations = {
.llseek = nfs_file_llseek,
.read_iter = nfs_file_read,
.write_iter = nfs_file_write,
- .mmap = nfs_file_mmap,
+ .mmap_prepare = nfs_file_mmap_prepare,
.open = nfs_file_open,
.flush = nfs_file_flush,
.release = nfs_file_release,
diff --git a/fs/nfs/internal.h b/fs/nfs/internal.h
index 69c2c10ee658..26551ff09a52 100644
--- a/fs/nfs/internal.h
+++ b/fs/nfs/internal.h
@@ -432,7 +432,7 @@ loff_t nfs_file_llseek(struct file *, loff_t, int);
ssize_t nfs_file_read(struct kiocb *, struct iov_iter *);
ssize_t nfs_file_splice_read(struct file *in, loff_t *ppos, struct pipe_inode_info *pipe,
size_t len, unsigned int flags);
-int nfs_file_mmap(struct file *, struct vm_area_struct *);
+int nfs_file_mmap_prepare(struct vm_area_desc *);
ssize_t nfs_file_write(struct kiocb *, struct iov_iter *);
int nfs_file_release(struct inode *, struct file *);
int nfs_lock(struct file *, int, struct file_lock *);
diff --git a/fs/nfs/nfs4file.c b/fs/nfs/nfs4file.c
index 5e9d66f3466c..5c749b6117bb 100644
--- a/fs/nfs/nfs4file.c
+++ b/fs/nfs/nfs4file.c
@@ -456,7 +456,7 @@ static int nfs4_setlease(struct file *file, int arg, struct file_lease **lease,
const struct file_operations nfs4_file_operations = {
.read_iter = nfs_file_read,
.write_iter = nfs_file_write,
- .mmap = nfs_file_mmap,
+ .mmap_prepare = nfs_file_mmap_prepare,
.open = nfs4_file_open,
.flush = nfs4_file_flush,
.release = nfs_file_release,
diff --git a/fs/ntfs3/file.c b/fs/ntfs3/file.c
index 1e99a35691cd..7f2ec1c7106c 100644
--- a/fs/ntfs3/file.c
+++ b/fs/ntfs3/file.c
@@ -261,14 +261,15 @@ static int ntfs_zero_range(struct inode *inode, u64 vbo, u64 vbo_to)
}
/*
- * ntfs_file_mmap - file_operations::mmap
+ * ntfs_file_mmap_prepare - file_operations::mmap_prepare
*/
-static int ntfs_file_mmap(struct file *file, struct vm_area_struct *vma)
+static int ntfs_file_mmap_prepare(struct vm_area_desc *desc)
{
+ struct file *file = desc->file;
struct inode *inode = file_inode(file);
struct ntfs_inode *ni = ntfs_i(inode);
- u64 from = ((u64)vma->vm_pgoff << PAGE_SHIFT);
- bool rw = vma->vm_flags & VM_WRITE;
+ u64 from = ((u64)desc->pgoff << PAGE_SHIFT);
+ bool rw = desc->vm_flags & VM_WRITE;
int err;
if (unlikely(ntfs3_forced_shutdown(inode->i_sb)))
@@ -291,7 +292,7 @@ static int ntfs_file_mmap(struct file *file, struct vm_area_struct *vma)
if (rw) {
u64 to = min_t(loff_t, i_size_read(inode),
- from + vma->vm_end - vma->vm_start);
+ from + desc->end - desc->start);
if (is_sparsed(ni)) {
/* Allocate clusters for rw map. */
@@ -319,7 +320,7 @@ static int ntfs_file_mmap(struct file *file, struct vm_area_struct *vma)
}
}
- err = generic_file_mmap(file, vma);
+ err = generic_file_mmap_prepare(desc);
out:
return err;
}
@@ -1331,7 +1332,7 @@ const struct file_operations ntfs_file_operations = {
#endif
.splice_read = ntfs_file_splice_read,
.splice_write = ntfs_file_splice_write,
- .mmap = ntfs_file_mmap,
+ .mmap_prepare = ntfs_file_mmap_prepare,
.open = ntfs_file_open,
.fsync = generic_file_fsync,
.fallocate = ntfs_fallocate,
diff --git a/fs/smb/client/cifsfs.c b/fs/smb/client/cifsfs.c
index 0a5266ecfd15..d1e6b5cf7d99 100644
--- a/fs/smb/client/cifsfs.c
+++ b/fs/smb/client/cifsfs.c
@@ -1525,7 +1525,7 @@ const struct file_operations cifs_file_ops = {
.flock = cifs_flock,
.fsync = cifs_fsync,
.flush = cifs_flush,
- .mmap = cifs_file_mmap,
+ .mmap_prepare = cifs_file_mmap_prepare,
.splice_read = filemap_splice_read,
.splice_write = iter_file_splice_write,
.llseek = cifs_llseek,
@@ -1545,7 +1545,7 @@ const struct file_operations cifs_file_strict_ops = {
.flock = cifs_flock,
.fsync = cifs_strict_fsync,
.flush = cifs_flush,
- .mmap = cifs_file_strict_mmap,
+ .mmap_prepare = cifs_file_strict_mmap_prepare,
.splice_read = filemap_splice_read,
.splice_write = iter_file_splice_write,
.llseek = cifs_llseek,
@@ -1565,7 +1565,7 @@ const struct file_operations cifs_file_direct_ops = {
.flock = cifs_flock,
.fsync = cifs_fsync,
.flush = cifs_flush,
- .mmap = cifs_file_mmap,
+ .mmap_prepare = cifs_file_mmap_prepare,
.splice_read = copy_splice_read,
.splice_write = iter_file_splice_write,
.unlocked_ioctl = cifs_ioctl,
@@ -1583,7 +1583,7 @@ const struct file_operations cifs_file_nobrl_ops = {
.release = cifs_close,
.fsync = cifs_fsync,
.flush = cifs_flush,
- .mmap = cifs_file_mmap,
+ .mmap_prepare = cifs_file_mmap_prepare,
.splice_read = filemap_splice_read,
.splice_write = iter_file_splice_write,
.llseek = cifs_llseek,
@@ -1601,7 +1601,7 @@ const struct file_operations cifs_file_strict_nobrl_ops = {
.release = cifs_close,
.fsync = cifs_strict_fsync,
.flush = cifs_flush,
- .mmap = cifs_file_strict_mmap,
+ .mmap_prepare = cifs_file_strict_mmap_prepare,
.splice_read = filemap_splice_read,
.splice_write = iter_file_splice_write,
.llseek = cifs_llseek,
@@ -1619,7 +1619,7 @@ const struct file_operations cifs_file_direct_nobrl_ops = {
.release = cifs_close,
.fsync = cifs_fsync,
.flush = cifs_flush,
- .mmap = cifs_file_mmap,
+ .mmap_prepare = cifs_file_mmap_prepare,
.splice_read = copy_splice_read,
.splice_write = iter_file_splice_write,
.unlocked_ioctl = cifs_ioctl,
diff --git a/fs/smb/client/cifsfs.h b/fs/smb/client/cifsfs.h
index b9ec9fe16a98..487f39cff77e 100644
--- a/fs/smb/client/cifsfs.h
+++ b/fs/smb/client/cifsfs.h
@@ -103,8 +103,8 @@ extern int cifs_lock(struct file *, int, struct file_lock *);
extern int cifs_fsync(struct file *, loff_t, loff_t, int);
extern int cifs_strict_fsync(struct file *, loff_t, loff_t, int);
extern int cifs_flush(struct file *, fl_owner_t id);
-extern int cifs_file_mmap(struct file *file, struct vm_area_struct *vma);
-extern int cifs_file_strict_mmap(struct file *file, struct vm_area_struct *vma);
+int cifs_file_mmap_prepare(struct vm_area_desc *desc);
+int cifs_file_strict_mmap_prepare(struct vm_area_desc *desc);
extern const struct file_operations cifs_dir_ops;
extern int cifs_readdir(struct file *file, struct dir_context *ctx);
diff --git a/fs/smb/client/file.c b/fs/smb/client/file.c
index 9835672267d2..2ed5173cfa73 100644
--- a/fs/smb/client/file.c
+++ b/fs/smb/client/file.c
@@ -2995,8 +2995,9 @@ static const struct vm_operations_struct cifs_file_vm_ops = {
.page_mkwrite = cifs_page_mkwrite,
};
-int cifs_file_strict_mmap(struct file *file, struct vm_area_struct *vma)
+int cifs_file_strict_mmap_prepare(struct vm_area_desc *desc)
{
+ struct file *file = desc->file;
int xid, rc = 0;
struct inode *inode = file_inode(file);
@@ -3005,16 +3006,17 @@ int cifs_file_strict_mmap(struct file *file, struct vm_area_struct *vma)
if (!CIFS_CACHE_READ(CIFS_I(inode)))
rc = cifs_zap_mapping(inode);
if (!rc)
- rc = generic_file_mmap(file, vma);
+ rc = generic_file_mmap_prepare(desc);
if (!rc)
- vma->vm_ops = &cifs_file_vm_ops;
+ desc->vm_ops = &cifs_file_vm_ops;
free_xid(xid);
return rc;
}
-int cifs_file_mmap(struct file *file, struct vm_area_struct *vma)
+int cifs_file_mmap_prepare(struct vm_area_desc *desc)
{
+ struct file *file = desc->file;
int rc, xid;
xid = get_xid();
@@ -3024,9 +3026,9 @@ int cifs_file_mmap(struct file *file, struct vm_area_struct *vma)
cifs_dbg(FYI, "Validation prior to mmap failed, error=%d\n",
rc);
if (!rc)
- rc = generic_file_mmap(file, vma);
+ rc = generic_file_mmap_prepare(desc);
if (!rc)
- vma->vm_ops = &cifs_file_vm_ops;
+ desc->vm_ops = &cifs_file_vm_ops;
free_xid(xid);
return rc;
diff --git a/fs/ubifs/file.c b/fs/ubifs/file.c
index bf311c38d9a8..9dcb69fbf5c2 100644
--- a/fs/ubifs/file.c
+++ b/fs/ubifs/file.c
@@ -1579,17 +1579,17 @@ static const struct vm_operations_struct ubifs_file_vm_ops = {
.page_mkwrite = ubifs_vm_page_mkwrite,
};
-static int ubifs_file_mmap(struct file *file, struct vm_area_struct *vma)
+static int ubifs_file_mmap_prepare(struct vm_area_desc *desc)
{
int err;
- err = generic_file_mmap(file, vma);
+ err = generic_file_mmap_prepare(desc);
if (err)
return err;
vma->vm_ops = &ubifs_file_vm_ops;
if (IS_ENABLED(CONFIG_UBIFS_ATIME_SUPPORT))
- file_accessed(file);
+ file_accessed(desc->file);
return 0;
}
@@ -1652,7 +1652,7 @@ const struct file_operations ubifs_file_operations = {
.llseek = generic_file_llseek,
.read_iter = generic_file_read_iter,
.write_iter = ubifs_write_iter,
- .mmap = ubifs_file_mmap,
+ .mmap_prepare = ubifs_file_mmap_prepare,
.fsync = ubifs_fsync,
.unlocked_ioctl = ubifs_ioctl,
.splice_read = filemap_splice_read,
diff --git a/fs/vboxsf/file.c b/fs/vboxsf/file.c
index b492794f8e9a..82afb9430033 100644
--- a/fs/vboxsf/file.c
+++ b/fs/vboxsf/file.c
@@ -165,13 +165,13 @@ static const struct vm_operations_struct vboxsf_file_vm_ops = {
.map_pages = filemap_map_pages,
};
-static int vboxsf_file_mmap(struct file *file, struct vm_area_struct *vma)
+static int vboxsf_file_mmap_prepare(struct vm_area_desc *desc)
{
int err;
- err = generic_file_mmap(file, vma);
+ err = generic_file_mmap_prepare(desc);
if (!err)
- vma->vm_ops = &vboxsf_file_vm_ops;
+ desc->vm_ops = &vboxsf_file_vm_ops;
return err;
}
@@ -213,7 +213,7 @@ const struct file_operations vboxsf_reg_fops = {
.llseek = generic_file_llseek,
.read_iter = generic_file_read_iter,
.write_iter = generic_file_write_iter,
- .mmap = vboxsf_file_mmap,
+ .mmap_prepare = vboxsf_file_mmap_prepare,
.open = vboxsf_file_open,
.release = vboxsf_file_release,
.fsync = noop_fsync,
--
2.49.0
^ permalink raw reply related [flat|nested] 50+ messages in thread
* [PATCH 10/10] fs: replace mmap hook with .mmap_prepare for simple mappings
2025-06-16 19:33 [PATCH 00/10] convert the majority of file systems to mmap_prepare Lorenzo Stoakes
` (8 preceding siblings ...)
2025-06-16 19:33 ` [PATCH 09/10] fs: convert most other generic_file_*mmap() users " Lorenzo Stoakes
@ 2025-06-16 19:33 ` Lorenzo Stoakes
2025-06-16 22:51 ` Damien Le Moal
` (4 more replies)
2025-06-16 19:56 ` [PATCH 00/10] convert the majority of file systems to mmap_prepare Kent Overstreet
` (5 subsequent siblings)
15 siblings, 5 replies; 50+ messages in thread
From: Lorenzo Stoakes @ 2025-06-16 19:33 UTC (permalink / raw)
To: Andrew Morton
Cc: Liam R . Howlett, Jens Axboe, Jani Nikula, Joonas Lahtinen,
Rodrigo Vivi, Tvrtko Ursulin, David Airlie, Simona Vetter,
Eric Van Hensbergen, Latchesar Ionkov, Dominique Martinet,
Christian Schoenebeck, David Sterba, David Howells, Marc Dionne,
Alexander Viro, Christian Brauner, Jan Kara, Benjamin LaHaise,
Miklos Szeredi, Amir Goldstein, Kent Overstreet,
Tigran A . Aivazian, Kees Cook, Chris Mason, Josef Bacik,
Xiubo Li, Ilya Dryomov, Jan Harkes, coda, Tyler Hicks, Gao Xiang,
Chao Yu, Yue Hu, Jeffle Xu, Sandeep Dhavale, Hongbo Li,
Namjae Jeon, Sungjong Seo, Yuezhang Mo, Theodore Ts'o,
Andreas Dilger, Jaegeuk Kim, OGAWA Hirofumi, Viacheslav Dubeyko,
John Paul Adrian Glaubitz, Yangtao Li, Richard Weinberger,
Anton Ivanov, Johannes Berg, Mikulas Patocka, David Woodhouse,
Dave Kleikamp, Trond Myklebust, Anna Schumaker, Ryusuke Konishi,
Konstantin Komarov, Mark Fasheh, Joel Becker, Joseph Qi,
Bob Copeland, Mike Marshall, Martin Brandenburg, Steve French,
Paulo Alcantara, Ronnie Sahlberg, Shyam Prasad N, Tom Talpey,
Bharath SM, Zhihao Cheng, Hans de Goede, Carlos Maiolino,
Damien Le Moal, Naohiro Aota, Johannes Thumshirn, Dan Williams,
Matthew Wilcox, Vlastimil Babka, Jann Horn, Pedro Falcato,
linux-block, linux-kernel, intel-gfx, dri-devel, v9fs,
linux-fsdevel, linux-afs, linux-aio, linux-unionfs,
linux-bcachefs, linux-mm, linux-btrfs, ceph-devel, codalist,
ecryptfs, linux-erofs, linux-ext4, linux-f2fs-devel, linux-um,
linux-mtd, jfs-discussion, linux-nfs, linux-nilfs, ntfs3,
ocfs2-devel, linux-karma-devel, devel, linux-cifs,
samba-technical, linux-xfs, nvdimm
Since commit c84bf6dd2b83 ("mm: introduce new .mmap_prepare() file
callback"), the f_op->mmap() hook has been deprecated in favour of
f_op->mmap_prepare().
This callback is invoked in the mmap() logic far earlier, so error handling
can be performed more safely without complicated and bug-prone state
unwinding required should an error arise.
This hook also avoids passing a pointer to a not-yet-correctly-established
VMA avoiding any issues with referencing this data structure.
It rather provides a pointer to the new struct vm_area_desc descriptor type
which contains all required state and allows easy setting of required
parameters without any consideration needing to be paid to locking or
reference counts.
Note that nested filesystems like overlayfs are compatible with an
.mmap_prepare() callback since commit bb666b7c2707 ("mm: add mmap_prepare()
compatibility layer for nested file systems").
In this patch we apply this change to file systems with relatively simple
mmap() hook logic - exfat, ceph, f2fs, bcachefs, zonefs, btrfs, ocfs2,
orangefs, nilfs2, romfs, ramfs and aio.
Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
---
fs/aio.c | 8 ++++----
fs/bcachefs/fs.c | 8 ++++----
fs/btrfs/file.c | 7 ++++---
fs/ceph/addr.c | 5 +++--
fs/ceph/file.c | 2 +-
fs/ceph/super.h | 2 +-
fs/exfat/file.c | 7 ++++---
fs/f2fs/file.c | 7 ++++---
fs/nilfs2/file.c | 8 ++++----
fs/ocfs2/file.c | 4 ++--
fs/ocfs2/mmap.c | 5 +++--
fs/ocfs2/mmap.h | 2 +-
fs/orangefs/file.c | 10 ++++++----
fs/ramfs/file-nommu.c | 12 ++++++------
fs/romfs/mmap-nommu.c | 6 +++---
fs/zonefs/file.c | 10 ++++++----
16 files changed, 56 insertions(+), 47 deletions(-)
diff --git a/fs/aio.c b/fs/aio.c
index 793b7b15ec4b..7fc7b6221312 100644
--- a/fs/aio.c
+++ b/fs/aio.c
@@ -392,15 +392,15 @@ static const struct vm_operations_struct aio_ring_vm_ops = {
#endif
};
-static int aio_ring_mmap(struct file *file, struct vm_area_struct *vma)
+static int aio_ring_mmap_prepare(struct vm_area_desc *desc)
{
- vm_flags_set(vma, VM_DONTEXPAND);
- vma->vm_ops = &aio_ring_vm_ops;
+ desc->vm_flags |= VM_DONTEXPAND;
+ desc->vm_ops = &aio_ring_vm_ops;
return 0;
}
static const struct file_operations aio_ring_fops = {
- .mmap = aio_ring_mmap,
+ .mmap_prepare = aio_ring_mmap_prepare,
};
#if IS_ENABLED(CONFIG_MIGRATION)
diff --git a/fs/bcachefs/fs.c b/fs/bcachefs/fs.c
index 3063a8ddc2df..9c2238edc0e3 100644
--- a/fs/bcachefs/fs.c
+++ b/fs/bcachefs/fs.c
@@ -1553,11 +1553,11 @@ static const struct vm_operations_struct bch_vm_ops = {
.page_mkwrite = bch2_page_mkwrite,
};
-static int bch2_mmap(struct file *file, struct vm_area_struct *vma)
+static int bch2_mmap_prepare(struct vm_area_desc *desc)
{
- file_accessed(file);
+ file_accessed(desc->file);
- vma->vm_ops = &bch_vm_ops;
+ desc->vm_ops = &bch_vm_ops;
return 0;
}
@@ -1740,7 +1740,7 @@ static const struct file_operations bch_file_operations = {
.llseek = bch2_llseek,
.read_iter = bch2_read_iter,
.write_iter = bch2_write_iter,
- .mmap = bch2_mmap,
+ .mmap_prepare = bch2_mmap_prepare,
.get_unmapped_area = thp_get_unmapped_area,
.fsync = bch2_fsync,
.splice_read = filemap_splice_read,
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
index 8ce6f45f45e0..06bd30b35b95 100644
--- a/fs/btrfs/file.c
+++ b/fs/btrfs/file.c
@@ -1978,15 +1978,16 @@ static const struct vm_operations_struct btrfs_file_vm_ops = {
.page_mkwrite = btrfs_page_mkwrite,
};
-static int btrfs_file_mmap(struct file *filp, struct vm_area_struct *vma)
+static int btrfs_file_mmap_prepare(struct vm_area_desc *desc)
{
+ struct file *filp = desc->file;
struct address_space *mapping = filp->f_mapping;
if (!mapping->a_ops->read_folio)
return -ENOEXEC;
file_accessed(filp);
- vma->vm_ops = &btrfs_file_vm_ops;
+ desc->vm_ops = &btrfs_file_vm_ops;
return 0;
}
@@ -3765,7 +3766,7 @@ const struct file_operations btrfs_file_operations = {
.splice_read = filemap_splice_read,
.write_iter = btrfs_file_write_iter,
.splice_write = iter_file_splice_write,
- .mmap = btrfs_file_mmap,
+ .mmap_prepare = btrfs_file_mmap_prepare,
.open = btrfs_file_open,
.release = btrfs_release_file,
.get_unmapped_area = thp_get_unmapped_area,
diff --git a/fs/ceph/addr.c b/fs/ceph/addr.c
index 60a621b00c65..37522137c380 100644
--- a/fs/ceph/addr.c
+++ b/fs/ceph/addr.c
@@ -2330,13 +2330,14 @@ static const struct vm_operations_struct ceph_vmops = {
.page_mkwrite = ceph_page_mkwrite,
};
-int ceph_mmap(struct file *file, struct vm_area_struct *vma)
+int ceph_mmap_prepare(struct vm_area_desc *desc)
{
+ struct file *file = desc->file;
struct address_space *mapping = file->f_mapping;
if (!mapping->a_ops->read_folio)
return -ENOEXEC;
- vma->vm_ops = &ceph_vmops;
+ desc->vm_ops = &ceph_vmops;
return 0;
}
diff --git a/fs/ceph/file.c b/fs/ceph/file.c
index d5c674d2ba8a..41b8ec33e864 100644
--- a/fs/ceph/file.c
+++ b/fs/ceph/file.c
@@ -3170,7 +3170,7 @@ const struct file_operations ceph_file_fops = {
.llseek = ceph_llseek,
.read_iter = ceph_read_iter,
.write_iter = ceph_write_iter,
- .mmap = ceph_mmap,
+ .mmap_prepare = ceph_mmap_prepare,
.fsync = ceph_fsync,
.lock = ceph_lock,
.setlease = simple_nosetlease,
diff --git a/fs/ceph/super.h b/fs/ceph/super.h
index bb0db0cc8003..cf176aab0f82 100644
--- a/fs/ceph/super.h
+++ b/fs/ceph/super.h
@@ -1286,7 +1286,7 @@ extern void __ceph_touch_fmode(struct ceph_inode_info *ci,
/* addr.c */
extern const struct address_space_operations ceph_aops;
extern const struct netfs_request_ops ceph_netfs_ops;
-extern int ceph_mmap(struct file *file, struct vm_area_struct *vma);
+int ceph_mmap_prepare(struct vm_area_desc *desc);
extern int ceph_uninline_data(struct file *file);
extern int ceph_pool_perm_check(struct inode *inode, int need);
extern void ceph_pool_perm_destroy(struct ceph_mds_client* mdsc);
diff --git a/fs/exfat/file.c b/fs/exfat/file.c
index 841a5b18e3df..d63213c8a823 100644
--- a/fs/exfat/file.c
+++ b/fs/exfat/file.c
@@ -683,13 +683,14 @@ static const struct vm_operations_struct exfat_file_vm_ops = {
.page_mkwrite = exfat_page_mkwrite,
};
-static int exfat_file_mmap(struct file *file, struct vm_area_struct *vma)
+static int exfat_file_mmap_prepare(struct vm_area_desc *desc)
{
+ struct file *file = desc->file;
if (unlikely(exfat_forced_shutdown(file_inode(file)->i_sb)))
return -EIO;
file_accessed(file);
- vma->vm_ops = &exfat_file_vm_ops;
+ desc->vm_ops = &exfat_file_vm_ops;
return 0;
}
@@ -710,7 +711,7 @@ const struct file_operations exfat_file_operations = {
#ifdef CONFIG_COMPAT
.compat_ioctl = exfat_compat_ioctl,
#endif
- .mmap = exfat_file_mmap,
+ .mmap_prepare = exfat_file_mmap_prepare,
.fsync = exfat_file_fsync,
.splice_read = exfat_splice_read,
.splice_write = iter_file_splice_write,
diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index 6bd3de64f2a8..7af2b49b7e8a 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -532,8 +532,9 @@ static loff_t f2fs_llseek(struct file *file, loff_t offset, int whence)
return -EINVAL;
}
-static int f2fs_file_mmap(struct file *file, struct vm_area_struct *vma)
+static int f2fs_file_mmap_prepare(struct vm_area_desc *desc)
{
+ struct file *file = desc->file;
struct inode *inode = file_inode(file);
if (unlikely(f2fs_cp_error(F2FS_I_SB(inode))))
@@ -543,7 +544,7 @@ static int f2fs_file_mmap(struct file *file, struct vm_area_struct *vma)
return -EOPNOTSUPP;
file_accessed(file);
- vma->vm_ops = &f2fs_file_vm_ops;
+ desc->vm_ops = &f2fs_file_vm_ops;
f2fs_down_read(&F2FS_I(inode)->i_sem);
set_inode_flag(inode, FI_MMAP_FILE);
@@ -5376,7 +5377,7 @@ const struct file_operations f2fs_file_operations = {
.iopoll = iocb_bio_iopoll,
.open = f2fs_file_open,
.release = f2fs_release_file,
- .mmap = f2fs_file_mmap,
+ .mmap_prepare = f2fs_file_mmap_prepare,
.flush = f2fs_file_flush,
.fsync = f2fs_sync_file,
.fallocate = f2fs_fallocate,
diff --git a/fs/nilfs2/file.c b/fs/nilfs2/file.c
index 0e3fc5ba33c7..1b8d754db44d 100644
--- a/fs/nilfs2/file.c
+++ b/fs/nilfs2/file.c
@@ -125,10 +125,10 @@ static const struct vm_operations_struct nilfs_file_vm_ops = {
.page_mkwrite = nilfs_page_mkwrite,
};
-static int nilfs_file_mmap(struct file *file, struct vm_area_struct *vma)
+static int nilfs_file_mmap_prepare(struct vm_area_desc *desc)
{
- file_accessed(file);
- vma->vm_ops = &nilfs_file_vm_ops;
+ file_accessed(desc->file);
+ desc->vm_ops = &nilfs_file_vm_ops;
return 0;
}
@@ -144,7 +144,7 @@ const struct file_operations nilfs_file_operations = {
#ifdef CONFIG_COMPAT
.compat_ioctl = nilfs_compat_ioctl,
#endif /* CONFIG_COMPAT */
- .mmap = nilfs_file_mmap,
+ .mmap_prepare = nilfs_file_mmap_prepare,
.open = generic_file_open,
/* .release = nilfs_release_file, */
.fsync = nilfs_sync_file,
diff --git a/fs/ocfs2/file.c b/fs/ocfs2/file.c
index 2056cf08ac1e..21d797ccccd0 100644
--- a/fs/ocfs2/file.c
+++ b/fs/ocfs2/file.c
@@ -2800,7 +2800,7 @@ const struct inode_operations ocfs2_special_file_iops = {
*/
const struct file_operations ocfs2_fops = {
.llseek = ocfs2_file_llseek,
- .mmap = ocfs2_mmap,
+ .mmap_prepare = ocfs2_mmap_prepare,
.fsync = ocfs2_sync_file,
.release = ocfs2_file_release,
.open = ocfs2_file_open,
@@ -2850,7 +2850,7 @@ const struct file_operations ocfs2_dops = {
*/
const struct file_operations ocfs2_fops_no_plocks = {
.llseek = ocfs2_file_llseek,
- .mmap = ocfs2_mmap,
+ .mmap_prepare = ocfs2_mmap_prepare,
.fsync = ocfs2_sync_file,
.release = ocfs2_file_release,
.open = ocfs2_file_open,
diff --git a/fs/ocfs2/mmap.c b/fs/ocfs2/mmap.c
index 6a314e9f2b49..50e2faf64c19 100644
--- a/fs/ocfs2/mmap.c
+++ b/fs/ocfs2/mmap.c
@@ -159,8 +159,9 @@ static const struct vm_operations_struct ocfs2_file_vm_ops = {
.page_mkwrite = ocfs2_page_mkwrite,
};
-int ocfs2_mmap(struct file *file, struct vm_area_struct *vma)
+int ocfs2_mmap_prepare(struct vm_area_desc *desc)
{
+ struct file *file = desc->file;
int ret = 0, lock_level = 0;
ret = ocfs2_inode_lock_atime(file_inode(file),
@@ -171,7 +172,7 @@ int ocfs2_mmap(struct file *file, struct vm_area_struct *vma)
}
ocfs2_inode_unlock(file_inode(file), lock_level);
out:
- vma->vm_ops = &ocfs2_file_vm_ops;
+ desc->vm_ops = &ocfs2_file_vm_ops;
return 0;
}
diff --git a/fs/ocfs2/mmap.h b/fs/ocfs2/mmap.h
index 1051507cc684..d21c30de6b8c 100644
--- a/fs/ocfs2/mmap.h
+++ b/fs/ocfs2/mmap.h
@@ -2,6 +2,6 @@
#ifndef OCFS2_MMAP_H
#define OCFS2_MMAP_H
-int ocfs2_mmap(struct file *file, struct vm_area_struct *vma);
+int ocfs2_mmap_prepare(struct vm_area_desc *desc);
#endif /* OCFS2_MMAP_H */
diff --git a/fs/orangefs/file.c b/fs/orangefs/file.c
index 90c49c0de243..919f99b16834 100644
--- a/fs/orangefs/file.c
+++ b/fs/orangefs/file.c
@@ -398,8 +398,9 @@ static const struct vm_operations_struct orangefs_file_vm_ops = {
/*
* Memory map a region of a file.
*/
-static int orangefs_file_mmap(struct file *file, struct vm_area_struct *vma)
+static int orangefs_file_mmap_prepare(struct vm_area_desc *desc)
{
+ struct file *file = desc->file;
int ret;
ret = orangefs_revalidate_mapping(file_inode(file));
@@ -410,10 +411,11 @@ static int orangefs_file_mmap(struct file *file, struct vm_area_struct *vma)
"orangefs_file_mmap: called on %pD\n", file);
/* set the sequential readahead hint */
- vm_flags_mod(vma, VM_SEQ_READ, VM_RAND_READ);
+ desc->vm_flags |= VM_SEQ_READ;
+ desc->vm_flags &= ~VM_RAND_READ;
file_accessed(file);
- vma->vm_ops = &orangefs_file_vm_ops;
+ desc->vm_ops = &orangefs_file_vm_ops;
return 0;
}
@@ -574,7 +576,7 @@ const struct file_operations orangefs_file_operations = {
.read_iter = orangefs_file_read_iter,
.write_iter = orangefs_file_write_iter,
.lock = orangefs_lock,
- .mmap = orangefs_file_mmap,
+ .mmap_prepare = orangefs_file_mmap_prepare,
.open = generic_file_open,
.splice_read = orangefs_file_splice_read,
.splice_write = iter_file_splice_write,
diff --git a/fs/ramfs/file-nommu.c b/fs/ramfs/file-nommu.c
index 7a6d980e614d..77b8ca2757e0 100644
--- a/fs/ramfs/file-nommu.c
+++ b/fs/ramfs/file-nommu.c
@@ -28,7 +28,7 @@ static unsigned long ramfs_nommu_get_unmapped_area(struct file *file,
unsigned long len,
unsigned long pgoff,
unsigned long flags);
-static int ramfs_nommu_mmap(struct file *file, struct vm_area_struct *vma);
+static int ramfs_nommu_mmap_prepare(struct vm_area_desc *desc);
static unsigned ramfs_mmap_capabilities(struct file *file)
{
@@ -38,7 +38,7 @@ static unsigned ramfs_mmap_capabilities(struct file *file)
const struct file_operations ramfs_file_operations = {
.mmap_capabilities = ramfs_mmap_capabilities,
- .mmap = ramfs_nommu_mmap,
+ .mmap_prepare = ramfs_nommu_mmap_prepare,
.get_unmapped_area = ramfs_nommu_get_unmapped_area,
.read_iter = generic_file_read_iter,
.write_iter = generic_file_write_iter,
@@ -262,12 +262,12 @@ static unsigned long ramfs_nommu_get_unmapped_area(struct file *file,
/*
* set up a mapping for shared memory segments
*/
-static int ramfs_nommu_mmap(struct file *file, struct vm_area_struct *vma)
+static int ramfs_nommu_mmap_prepare(struct vm_area_desc *desc)
{
- if (!is_nommu_shared_mapping(vma->vm_flags))
+ if (!is_nommu_shared_mapping(desc->vm_flags))
return -ENOSYS;
- file_accessed(file);
- vma->vm_ops = &generic_file_vm_ops;
+ file_accessed(desc->file);
+ desc->vm_ops = &generic_file_vm_ops;
return 0;
}
diff --git a/fs/romfs/mmap-nommu.c b/fs/romfs/mmap-nommu.c
index 4520ca413867..4b77c6dc4418 100644
--- a/fs/romfs/mmap-nommu.c
+++ b/fs/romfs/mmap-nommu.c
@@ -61,9 +61,9 @@ static unsigned long romfs_get_unmapped_area(struct file *file,
* permit a R/O mapping to be made directly through onto an MTD device if
* possible
*/
-static int romfs_mmap(struct file *file, struct vm_area_struct *vma)
+static int romfs_mmap_prepare(struct vm_area_desc *desc)
{
- return is_nommu_shared_mapping(vma->vm_flags) ? 0 : -ENOSYS;
+ return is_nommu_shared_mapping(desc->vm_flags) ? 0 : -ENOSYS;
}
static unsigned romfs_mmap_capabilities(struct file *file)
@@ -79,7 +79,7 @@ const struct file_operations romfs_ro_fops = {
.llseek = generic_file_llseek,
.read_iter = generic_file_read_iter,
.splice_read = filemap_splice_read,
- .mmap = romfs_mmap,
+ .mmap_prepare = romfs_mmap_prepare,
.get_unmapped_area = romfs_get_unmapped_area,
.mmap_capabilities = romfs_mmap_capabilities,
};
diff --git a/fs/zonefs/file.c b/fs/zonefs/file.c
index 42e2c0065bb3..c1848163b378 100644
--- a/fs/zonefs/file.c
+++ b/fs/zonefs/file.c
@@ -312,8 +312,10 @@ static const struct vm_operations_struct zonefs_file_vm_ops = {
.page_mkwrite = zonefs_filemap_page_mkwrite,
};
-static int zonefs_file_mmap(struct file *file, struct vm_area_struct *vma)
+static int zonefs_file_mmap_prepare(struct vm_area_desc *desc)
{
+ struct file *file = desc->file;
+
/*
* Conventional zones accept random writes, so their files can support
* shared writable mappings. For sequential zone files, only read
@@ -321,11 +323,11 @@ static int zonefs_file_mmap(struct file *file, struct vm_area_struct *vma)
* ordering between msync() and page cache writeback.
*/
if (zonefs_inode_is_seq(file_inode(file)) &&
- (vma->vm_flags & VM_SHARED) && (vma->vm_flags & VM_MAYWRITE))
+ (desc->vm_flags & VM_SHARED) && (desc->vm_flags & VM_MAYWRITE))
return -EINVAL;
file_accessed(file);
- vma->vm_ops = &zonefs_file_vm_ops;
+ desc->vm_ops = &zonefs_file_vm_ops;
return 0;
}
@@ -850,7 +852,7 @@ const struct file_operations zonefs_file_operations = {
.open = zonefs_file_open,
.release = zonefs_file_release,
.fsync = zonefs_file_fsync,
- .mmap = zonefs_file_mmap,
+ .mmap_prepare = zonefs_file_mmap_prepare,
.llseek = zonefs_file_llseek,
.read_iter = zonefs_file_read_iter,
.write_iter = zonefs_file_write_iter,
--
2.49.0
^ permalink raw reply related [flat|nested] 50+ messages in thread
* Re: [PATCH 00/10] convert the majority of file systems to mmap_prepare
2025-06-16 19:33 [PATCH 00/10] convert the majority of file systems to mmap_prepare Lorenzo Stoakes
` (9 preceding siblings ...)
2025-06-16 19:33 ` [PATCH 10/10] fs: replace mmap hook with .mmap_prepare for simple mappings Lorenzo Stoakes
@ 2025-06-16 19:56 ` Kent Overstreet
2025-06-16 20:41 ` Al Viro
` (4 subsequent siblings)
15 siblings, 0 replies; 50+ messages in thread
From: Kent Overstreet @ 2025-06-16 19:56 UTC (permalink / raw)
To: Lorenzo Stoakes
Cc: Andrew Morton, linux-block, linux-kernel, intel-gfx, dri-devel,
v9fs, linux-fsdevel, linux-afs, linux-aio, linux-unionfs,
linux-bcachefs, linux-mm, linux-btrfs, ceph-devel, codalist,
ecryptfs, linux-erofs, linux-ext4, linux-f2fs-devel, linux-um,
linux-mtd, jfs-discussion, linux-nfs, linux-nilfs, ntfs3,
ocfs2-devel, linux-karma-devel, devel, linux-cifs,
samba-technical, linux-xfs, nvdimm
Mailserver is rejecting with "too many recipients" - aieeee
On Mon, Jun 16, 2025 at 08:33:19PM +0100, Lorenzo Stoakes wrote:
> REVIEWER'S NOTES
> ================
>
> I am basing this on the mm-new branch in Andrew's tree, so let me know if I
> should rebase anything here. Given the mm bits touched I did think perhaps
> we should take it through the mm tree, however it may be more sensible to
> take it through an fs tree - let me know!
>
> Apologies for the noise/churn, but there are some prerequisite steps here
> that inform an ordering - "fs: consistently use file_has_valid_mmap_hooks()
> helper" being especially critical, and so I put the bulk of the work in the
> same series.
>
> Let me know if there's anything I can do to make life easier here.
This seems to be more of an mm thing than a filesystem thing? I don't
see any code changes on the filesystem side from a quick scan, just
renaming?
Are there any behavioural changes for the filesystem to be aware of?
How's it been tested, any considerations there?
If this is as simple as it looks, ack from me (and if it is that simply,
why so many recipients?).
If there are _any_ behavioural changes on the mm side that might
interact with the filesystem in funny ways, please make sure the whole
fstests suite has been run.
^ permalink raw reply [flat|nested] 50+ messages in thread
* Re: [PATCH 03/10] fs: consistently use file_has_valid_mmap_hooks() helper
2025-06-16 19:33 ` [PATCH 03/10] fs: consistently " Lorenzo Stoakes
@ 2025-06-16 20:01 ` Kees Cook
2025-06-17 5:11 ` Christoph Hellwig
1 sibling, 0 replies; 50+ messages in thread
From: Kees Cook @ 2025-06-16 20:01 UTC (permalink / raw)
To: Lorenzo Stoakes, Andrew Morton
Cc: Liam R . Howlett, Jens Axboe, Jani Nikula, Joonas Lahtinen,
Rodrigo Vivi, Tvrtko Ursulin, David Airlie, Simona Vetter,
Eric Van Hensbergen, Latchesar Ionkov, Dominique Martinet,
Christian Schoenebeck, David Sterba, David Howells, Marc Dionne,
Alexander Viro, Christian Brauner, Jan Kara, Benjamin LaHaise,
Miklos Szeredi, Amir Goldstein, Kent Overstreet,
Tigran A . Aivazian, Chris Mason, Josef Bacik, Xiubo Li,
Ilya Dryomov, Jan Harkes, coda, Tyler Hicks, Gao Xiang, Chao Yu,
Yue Hu, Jeffle Xu, Sandeep Dhavale, Hongbo Li, Namjae Jeon,
Sungjong Seo, Yuezhang Mo, Theodore Ts'o, Andreas Dilger,
Jaegeuk Kim, OGAWA Hirofumi, Viacheslav Dubeyko,
John Paul Adrian Glaubitz, Yangtao Li, Richard Weinberger,
Anton Ivanov, Johannes Berg, Mikulas Patocka, David Woodhouse,
Dave Kleikamp, Trond Myklebust, Anna Schumaker, Ryusuke Konishi,
Konstantin Komarov, Mark Fasheh, Joel Becker, Joseph Qi,
Bob Copeland, Mike Marshall, Martin Brandenburg, Steve French,
Paulo Alcantara, Ronnie Sahlberg, Shyam Prasad N, Tom Talpey,
Bharath SM, Zhihao Cheng, Hans de Goede, Carlos Maiolino,
Damien Le Moal, Naohiro Aota, Johannes Thumshirn, Dan Williams,
Matthew Wilcox, Vlastimil Babka, Jann Horn, Pedro Falcato,
linux-block, linux-kernel, intel-gfx, dri-devel, v9fs,
linux-fsdevel, linux-afs, linux-aio, linux-unionfs,
linux-bcachefs, linux-mm, linux-btrfs, ceph-devel, codalist,
ecryptfs, linux-erofs, linux-ext4, linux-f2fs-devel, linux-um,
linux-mtd, jfs-discussion, linux-nfs, linux-nilfs, ntfs3,
ocfs2-devel, linux-karma-devel, devel, linux-cifs,
samba-technical, linux-xfs, nvdimm
On June 16, 2025 12:33:22 PM PDT, Lorenzo Stoakes <lorenzo.stoakes@oracle.com> wrote:
>Since commit c84bf6dd2b83 ("mm: introduce new .mmap_prepare() file
>callback"), the f_op->mmap() hook has been deprecated in favour of
>f_op->mmap_prepare().
>
>Additionally, commit bb666b7c2707 ("mm: add mmap_prepare() compatibility
>layer for nested file systems") permits the use of the .mmap_prepare() hook
>even in nested filesystems like overlayfs.
>
>There are a number of places where we check only for f_op->mmap - this is
>incorrect now mmap_prepare exists, so update all of these to use the
>general helper file_has_valid_mmap_hooks().
>
>Most notably, this updates the elf logic to allow for the ability to
>execute binaries on filesystems which have the .mmap_prepare hook, but
>additionally we update nested filesystems.
>
>Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
>---
> fs/backing-file.c | 2 +-
> fs/binfmt_elf.c | 4 ++--
> fs/binfmt_elf_fdpic.c | 2 +-
Thanks for the refactoring!
Acked-by: Kees Cook<kees@kernel.org>
--
Kees Cook
^ permalink raw reply [flat|nested] 50+ messages in thread
* Re: [PATCH 04/10] fs/dax: make it possible to check dev dax support without a VMA
2025-06-16 19:33 ` [PATCH 04/10] fs/dax: make it possible to check dev dax support without a VMA Lorenzo Stoakes
@ 2025-06-16 20:26 ` Matthew Wilcox
2025-06-17 11:43 ` Christian Brauner
0 siblings, 1 reply; 50+ messages in thread
From: Matthew Wilcox @ 2025-06-16 20:26 UTC (permalink / raw)
To: Lorenzo Stoakes
Cc: Andrew Morton, Liam R . Howlett, Jens Axboe, Jani Nikula,
Joonas Lahtinen, Rodrigo Vivi, Tvrtko Ursulin, David Airlie,
Simona Vetter, Eric Van Hensbergen, Latchesar Ionkov,
Dominique Martinet, Christian Schoenebeck, David Sterba,
David Howells, Marc Dionne, Alexander Viro, Christian Brauner,
Jan Kara, Benjamin LaHaise, Miklos Szeredi, Amir Goldstein,
Kent Overstreet, Tigran A . Aivazian, Kees Cook, Chris Mason,
Josef Bacik, Xiubo Li, Ilya Dryomov, Jan Harkes, coda,
Tyler Hicks, Gao Xiang, Chao Yu, Yue Hu, Jeffle Xu,
Sandeep Dhavale, Hongbo Li, Namjae Jeon, Sungjong Seo,
Yuezhang Mo, Theodore Ts'o, Andreas Dilger, Jaegeuk Kim,
OGAWA Hirofumi, Viacheslav Dubeyko, John Paul Adrian Glaubitz,
Yangtao Li, Richard Weinberger, Anton Ivanov, Johannes Berg,
Mikulas Patocka, David Woodhouse, Dave Kleikamp, Trond Myklebust,
Anna Schumaker, Ryusuke Konishi, Konstantin Komarov, Mark Fasheh,
Joel Becker, Joseph Qi, Bob Copeland, Mike Marshall,
Martin Brandenburg, Steve French, Paulo Alcantara,
Ronnie Sahlberg, Shyam Prasad N, Tom Talpey, Bharath SM,
Zhihao Cheng, Hans de Goede, Carlos Maiolino, Damien Le Moal,
Naohiro Aota, Johannes Thumshirn, Dan Williams, Vlastimil Babka,
Jann Horn, Pedro Falcato, linux-block, linux-kernel, intel-gfx,
dri-devel, v9fs, linux-fsdevel, linux-afs, linux-aio,
linux-unionfs, linux-bcachefs, linux-mm, linux-btrfs, ceph-devel,
codalist, ecryptfs, linux-erofs, linux-ext4, linux-f2fs-devel,
linux-um, linux-mtd, jfs-discussion, linux-nfs, linux-nilfs,
ntfs3, ocfs2-devel, linux-karma-devel, devel, linux-cifs,
samba-technical, linux-xfs, nvdimm
On Mon, Jun 16, 2025 at 08:33:23PM +0100, Lorenzo Stoakes wrote:
> fs/ext4/file.c | 2 +-
> fs/xfs/xfs_file.c | 3 ++-
Both of these already have the inode from the file ...
> +static inline bool daxdev_mapping_supported(vm_flags_t vm_flags,
> + struct file *file,
> + struct dax_device *dax_dev)
> {
> - if (!(vma->vm_flags & VM_SYNC))
> + if (!(vm_flags & VM_SYNC))
> return true;
> - if (!IS_DAX(file_inode(vma->vm_file)))
> + if (!IS_DAX(file_inode(file)))
> return false;
> return dax_synchronous(dax_dev);
... and the only thing this function uses from the file is the inode.
So maybe pass in the inode rather than the file?
^ permalink raw reply [flat|nested] 50+ messages in thread
* Re: [PATCH 00/10] convert the majority of file systems to mmap_prepare
2025-06-16 19:33 [PATCH 00/10] convert the majority of file systems to mmap_prepare Lorenzo Stoakes
` (10 preceding siblings ...)
2025-06-16 19:56 ` [PATCH 00/10] convert the majority of file systems to mmap_prepare Kent Overstreet
@ 2025-06-16 20:41 ` Al Viro
2025-06-17 13:45 ` Jeff Layton
2025-06-16 23:11 ` Andrew Morton
` (3 subsequent siblings)
15 siblings, 1 reply; 50+ messages in thread
From: Al Viro @ 2025-06-16 20:41 UTC (permalink / raw)
To: Lorenzo Stoakes
Cc: Andrew Morton, Liam R . Howlett, Jens Axboe, Jani Nikula,
Joonas Lahtinen, Rodrigo Vivi, Tvrtko Ursulin, David Airlie,
Simona Vetter, Eric Van Hensbergen, Latchesar Ionkov,
Dominique Martinet, Christian Schoenebeck, David Sterba,
David Howells, Marc Dionne, Christian Brauner, Jan Kara,
Benjamin LaHaise, Miklos Szeredi, Amir Goldstein, Kent Overstreet,
Tigran A . Aivazian, Kees Cook, Chris Mason, Josef Bacik,
Xiubo Li, Ilya Dryomov, Jan Harkes, coda, Tyler Hicks, Gao Xiang,
Chao Yu, Yue Hu, Jeffle Xu, Sandeep Dhavale, Hongbo Li,
Namjae Jeon, Sungjong Seo, Yuezhang Mo, Theodore Ts'o,
Andreas Dilger, Jaegeuk Kim, OGAWA Hirofumi, Viacheslav Dubeyko,
John Paul Adrian Glaubitz, Yangtao Li, Richard Weinberger,
Anton Ivanov, Johannes Berg, Mikulas Patocka, David Woodhouse,
Dave Kleikamp, Trond Myklebust, Anna Schumaker, Ryusuke Konishi,
Konstantin Komarov, Mark Fasheh, Joel Becker, Joseph Qi,
Bob Copeland, Mike Marshall, Martin Brandenburg, Steve French,
Paulo Alcantara, Ronnie Sahlberg, Shyam Prasad N, Tom Talpey,
Bharath SM, Zhihao Cheng, Hans de Goede, Carlos Maiolino,
Damien Le Moal, Naohiro Aota, Johannes Thumshirn, Dan Williams,
Matthew Wilcox, Vlastimil Babka, Jann Horn, Pedro Falcato,
linux-block, linux-kernel, intel-gfx, dri-devel, v9fs,
linux-fsdevel, linux-afs, linux-aio, linux-unionfs,
linux-bcachefs, linux-mm, linux-btrfs, ceph-devel, codalist,
ecryptfs, linux-erofs, linux-ext4, linux-f2fs-devel, linux-um,
linux-mtd, jfs-discussion, linux-nfs, linux-nilfs, ntfs3,
ocfs2-devel, linux-karma-devel, devel, linux-cifs,
samba-technical, linux-xfs, nvdimm
On Mon, Jun 16, 2025 at 08:33:19PM +0100, Lorenzo Stoakes wrote:
> REVIEWER'S NOTES
> ================
>
> I am basing this on the mm-new branch in Andrew's tree, so let me know if I
> should rebase anything here. Given the mm bits touched I did think perhaps
> we should take it through the mm tree, however it may be more sensible to
> take it through an fs tree - let me know!
>
> Apologies for the noise/churn, but there are some prerequisite steps here
> that inform an ordering - "fs: consistently use file_has_valid_mmap_hooks()
> helper" being especially critical, and so I put the bulk of the work in the
> same series.
>
> Let me know if there's anything I can do to make life easier here.
Documentation/filesystems/porting.rst?
^ permalink raw reply [flat|nested] 50+ messages in thread
* Re: [PATCH 10/10] fs: replace mmap hook with .mmap_prepare for simple mappings
2025-06-16 19:33 ` [PATCH 10/10] fs: replace mmap hook with .mmap_prepare for simple mappings Lorenzo Stoakes
@ 2025-06-16 22:51 ` Damien Le Moal
2025-06-16 23:24 ` Viacheslav Dubeyko
` (3 subsequent siblings)
4 siblings, 0 replies; 50+ messages in thread
From: Damien Le Moal @ 2025-06-16 22:51 UTC (permalink / raw)
To: Lorenzo Stoakes, Andrew Morton
Cc: Liam R . Howlett, Jens Axboe, Jani Nikula, Joonas Lahtinen,
Rodrigo Vivi, Tvrtko Ursulin, David Airlie, Simona Vetter,
Eric Van Hensbergen, Latchesar Ionkov, Dominique Martinet,
Christian Schoenebeck, David Sterba, David Howells, Marc Dionne,
Alexander Viro, Christian Brauner, Jan Kara, Benjamin LaHaise,
Miklos Szeredi, Amir Goldstein, Kent Overstreet,
Tigran A . Aivazian, Kees Cook, Chris Mason, Josef Bacik,
Xiubo Li, Ilya Dryomov, Jan Harkes, coda, Tyler Hicks, Gao Xiang,
Chao Yu, Yue Hu, Jeffle Xu, Sandeep Dhavale, Hongbo Li,
Namjae Jeon, Sungjong Seo, Yuezhang Mo, Theodore Ts'o,
Andreas Dilger, Jaegeuk Kim, OGAWA Hirofumi, Viacheslav Dubeyko,
John Paul Adrian Glaubitz, Yangtao Li, Richard Weinberger,
Anton Ivanov, Johannes Berg, Mikulas Patocka, David Woodhouse,
Dave Kleikamp, Trond Myklebust, Anna Schumaker, Ryusuke Konishi,
Konstantin Komarov, Mark Fasheh, Joel Becker, Joseph Qi,
Bob Copeland, Mike Marshall, Martin Brandenburg, Steve French,
Paulo Alcantara, Ronnie Sahlberg, Shyam Prasad N, Tom Talpey,
Bharath SM, Zhihao Cheng, Hans de Goede, Carlos Maiolino,
Naohiro Aota, Johannes Thumshirn, Dan Williams, Matthew Wilcox,
Vlastimil Babka, Jann Horn, Pedro Falcato, linux-block,
linux-kernel, intel-gfx, dri-devel, v9fs, linux-fsdevel,
linux-afs, linux-aio, linux-unionfs, linux-bcachefs, linux-mm,
linux-btrfs, ceph-devel, codalist, ecryptfs, linux-erofs,
linux-ext4, linux-f2fs-devel, linux-um, linux-mtd, jfs-discussion,
linux-nfs, linux-nilfs, ntfs3, ocfs2-devel, linux-karma-devel,
devel, linux-cifs, samba-technical, linux-xfs, nvdimm
On 6/17/25 4:33 AM, Lorenzo Stoakes wrote:
> Since commit c84bf6dd2b83 ("mm: introduce new .mmap_prepare() file
> callback"), the f_op->mmap() hook has been deprecated in favour of
> f_op->mmap_prepare().
>
> This callback is invoked in the mmap() logic far earlier, so error handling
> can be performed more safely without complicated and bug-prone state
> unwinding required should an error arise.
>
> This hook also avoids passing a pointer to a not-yet-correctly-established
> VMA avoiding any issues with referencing this data structure.
>
> It rather provides a pointer to the new struct vm_area_desc descriptor type
> which contains all required state and allows easy setting of required
> parameters without any consideration needing to be paid to locking or
> reference counts.
>
> Note that nested filesystems like overlayfs are compatible with an
> .mmap_prepare() callback since commit bb666b7c2707 ("mm: add mmap_prepare()
> compatibility layer for nested file systems").
>
> In this patch we apply this change to file systems with relatively simple
> mmap() hook logic - exfat, ceph, f2fs, bcachefs, zonefs, btrfs, ocfs2,
> orangefs, nilfs2, romfs, ramfs and aio.
>
> Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
For zonefs,
Acked-by: Damien Le Moal <dlemoal@kernel.org>
--
Damien Le Moal
Western Digital Research
^ permalink raw reply [flat|nested] 50+ messages in thread
* Re: [PATCH 00/10] convert the majority of file systems to mmap_prepare
2025-06-16 19:33 [PATCH 00/10] convert the majority of file systems to mmap_prepare Lorenzo Stoakes
` (11 preceding siblings ...)
2025-06-16 20:41 ` Al Viro
@ 2025-06-16 23:11 ` Andrew Morton
2025-06-17 11:31 ` Christian Brauner
2025-06-17 11:58 ` Christian Brauner
` (2 subsequent siblings)
15 siblings, 1 reply; 50+ messages in thread
From: Andrew Morton @ 2025-06-16 23:11 UTC (permalink / raw)
To: Lorenzo Stoakes
Cc: Liam R . Howlett, Jens Axboe, Jani Nikula, Joonas Lahtinen,
Rodrigo Vivi, Tvrtko Ursulin, David Airlie, Simona Vetter,
Eric Van Hensbergen, Latchesar Ionkov, Dominique Martinet,
Christian Schoenebeck, David Sterba, David Howells, Marc Dionne,
Alexander Viro, Christian Brauner, Jan Kara, Benjamin LaHaise,
Miklos Szeredi, Amir Goldstein, Kent Overstreet,
Tigran A . Aivazian, Kees Cook, Chris Mason, Josef Bacik,
Xiubo Li, Ilya Dryomov, Jan Harkes, coda, Tyler Hicks, Gao Xiang,
Chao Yu, Yue Hu, Jeffle Xu, Sandeep Dhavale, Hongbo Li,
Namjae Jeon, Sungjong Seo, Yuezhang Mo, Theodore Ts'o,
Andreas Dilger, Jaegeuk Kim, OGAWA Hirofumi, Viacheslav Dubeyko,
John Paul Adrian Glaubitz, Yangtao Li, Richard Weinberger,
Anton Ivanov, Johannes Berg, Mikulas Patocka, David Woodhouse,
Dave Kleikamp, Trond Myklebust, Anna Schumaker, Ryusuke Konishi,
Konstantin Komarov, Mark Fasheh, Joel Becker, Joseph Qi,
Bob Copeland, Mike Marshall, Martin Brandenburg, Steve French,
Paulo Alcantara, Ronnie Sahlberg, Shyam Prasad N, Tom Talpey,
Bharath SM, Zhihao Cheng, Hans de Goede, Carlos Maiolino,
Damien Le Moal, Naohiro Aota, Johannes Thumshirn, Dan Williams,
Matthew Wilcox, Vlastimil Babka, Jann Horn, Pedro Falcato,
linux-block, linux-kernel, intel-gfx, dri-devel, v9fs,
linux-fsdevel, linux-afs, linux-aio, linux-unionfs,
linux-bcachefs, linux-mm, linux-btrfs, ceph-devel, codalist,
ecryptfs, linux-erofs, linux-ext4, linux-f2fs-devel, linux-um,
linux-mtd, jfs-discussion, linux-nfs, linux-nilfs, ntfs3,
ocfs2-devel, linux-karma-devel, devel, linux-cifs,
samba-technical, linux-xfs, nvdimm
On Mon, 16 Jun 2025 20:33:19 +0100 Lorenzo Stoakes <lorenzo.stoakes@oracle.com> wrote:
> I am basing this on the mm-new branch in Andrew's tree, so let me know if I
> should rebase anything here. Given the mm bits touched I did think perhaps
> we should take it through the mm tree, however it may be more sensible to
> take it through an fs tree - let me know!
It's more fs/ than mm/ purely from a footprint point of view. But is
there any expectation that there will be additional patches which build
on this?
I'll scoop it into mm-new for now, see what happens.
Minus all the cc's. Sorry ;)
^ permalink raw reply [flat|nested] 50+ messages in thread
* Re: [PATCH 10/10] fs: replace mmap hook with .mmap_prepare for simple mappings
2025-06-16 19:33 ` [PATCH 10/10] fs: replace mmap hook with .mmap_prepare for simple mappings Lorenzo Stoakes
2025-06-16 22:51 ` Damien Le Moal
@ 2025-06-16 23:24 ` Viacheslav Dubeyko
2025-06-17 10:28 ` Jan Kara
` (2 subsequent siblings)
4 siblings, 0 replies; 50+ messages in thread
From: Viacheslav Dubeyko @ 2025-06-16 23:24 UTC (permalink / raw)
To: lorenzo.stoakes@oracle.com, akpm@linux-foundation.org
Cc: xiang@kernel.org, codalist@coda.cs.cmu.edu,
dri-devel@lists.freedesktop.org, anna@kernel.org, vbabka@suse.cz,
pfalcato@suse.de, jack@suse.cz, linux-xfs@vger.kernel.org,
v9fs@lists.linux.dev, glaubitz@physik.fu-berlin.de,
miklos@szeredi.hu, linux-unionfs@vger.kernel.org,
amir73il@gmail.com, slava@dubeyko.com, Hans De Goede,
asmadeus@codewreck.org, simona@ffwll.ch, jth@kernel.org,
shaggy@kernel.org, willy@infradead.org,
linux-erofs@lists.ozlabs.org, jaharkes@cs.cmu.edu,
tursulin@ursulin.net, trondmy@kernel.org,
ecryptfs@vger.kernel.org, ericvh@kernel.org,
joonas.lahtinen@linux.intel.com, hirofumi@mail.parknet.co.jp,
linux-nilfs@vger.kernel.org, Xiubo Li, aivazian.tigran@gmail.com,
hubcap@omnibond.com, linux-kernel@vger.kernel.org,
intel-gfx@lists.freedesktop.org, sfrench@samba.org,
jfs-discussion@lists.sourceforge.net, clm@fb.com,
jlbec@evilplan.org, lihongbo22@huawei.com,
ronniesahlberg@gmail.com, lucho@ionkov.net,
anton.ivanov@cambridgegreys.com, dan.j.williams@intel.com,
Liam.Howlett@oracle.com, sj1557.seo@samsung.com,
josef@toxicpanda.com, linux-block@vger.kernel.org, cem@kernel.org,
linkinjeon@kernel.org, tom@talpey.com,
mikulas@artax.karlin.mff.cuni.cz, bcrl@kvack.org,
linux-afs@lists.infradead.org, mark@fasheh.com,
linux-mtd@lists.infradead.org, linux-nfs@vger.kernel.org,
bharathsm@microsoft.com, linux-ext4@vger.kernel.org,
linux-f2fs-devel@lists.sourceforge.net, tytso@mit.edu,
martin@omnibond.com, jefflexu@linux.alibaba.com,
naohiro.aota@wdc.com, frank.li@vivo.com, nvdimm@lists.linux.dev,
dsterba@suse.com, pc@manguebit.org, dwmw2@infradead.org,
code@tyhicks.com, ocfs2-devel@lists.linux.dev,
linux-aio@kvack.org, idryomov@gmail.com, dlemoal@kernel.org,
linux-btrfs@vger.kernel.org, viro@zeniv.linux.org.uk,
zbestahu@gmail.com, linux-cifs@vger.kernel.org,
johannes@sipsolutions.net, David Howells,
linux-fsdevel@vger.kernel.org, ntfs3@lists.linux.dev,
richard@nod.at, yuezhang.mo@sony.com, joseph.qi@linux.alibaba.com,
axboe@kernel.dk, linux-karma-devel@lists.sourceforge.net,
kent.overstreet@linux.dev, ceph-devel@vger.kernel.org,
samba-technical@lists.samba.org, dhavale@google.com,
devel@lists.orangefs.org, konishi.ryusuke@gmail.com,
linux_oss@crudebyte.com, jaegeuk@kernel.org,
sprasad@microsoft.com, linux-um@lists.infradead.org,
jani.nikula@linux.intel.com, brauner@kernel.org,
rodrigo.vivi@intel.com, adilger.kernel@dilger.ca,
airlied@gmail.com, chao@kernel.org, coda@cs.cmu.edu,
jannh@google.com, kees@kernel.org, me@bobcopeland.com,
chengzhihao1@huawei.com, linux-bcachefs@vger.kernel.org,
marc.dionne@auristor.com,
almaz.alexandrovich@paragon-software.com, linux-mm@kvack.org
On Mon, 2025-06-16 at 20:33 +0100, Lorenzo Stoakes wrote:
> Since commit c84bf6dd2b83 ("mm: introduce new .mmap_prepare() file
> callback"), the f_op->mmap() hook has been deprecated in favour of
> f_op->mmap_prepare().
>
> This callback is invoked in the mmap() logic far earlier, so error handling
> can be performed more safely without complicated and bug-prone state
> unwinding required should an error arise.
>
> This hook also avoids passing a pointer to a not-yet-correctly-established
> VMA avoiding any issues with referencing this data structure.
>
> It rather provides a pointer to the new struct vm_area_desc descriptor type
> which contains all required state and allows easy setting of required
> parameters without any consideration needing to be paid to locking or
> reference counts.
>
> Note that nested filesystems like overlayfs are compatible with an
> .mmap_prepare() callback since commit bb666b7c2707 ("mm: add mmap_prepare()
> compatibility layer for nested file systems").
>
> In this patch we apply this change to file systems with relatively simple
> mmap() hook logic - exfat, ceph, f2fs, bcachefs, zonefs, btrfs, ocfs2,
> orangefs, nilfs2, romfs, ramfs and aio.
>
> Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
> ---
> fs/aio.c | 8 ++++----
> fs/bcachefs/fs.c | 8 ++++----
> fs/btrfs/file.c | 7 ++++---
> fs/ceph/addr.c | 5 +++--
> fs/ceph/file.c | 2 +-
> fs/ceph/super.h | 2 +-
> fs/exfat/file.c | 7 ++++---
> fs/f2fs/file.c | 7 ++++---
> fs/nilfs2/file.c | 8 ++++----
> fs/ocfs2/file.c | 4 ++--
> fs/ocfs2/mmap.c | 5 +++--
> fs/ocfs2/mmap.h | 2 +-
> fs/orangefs/file.c | 10 ++++++----
> fs/ramfs/file-nommu.c | 12 ++++++------
> fs/romfs/mmap-nommu.c | 6 +++---
> fs/zonefs/file.c | 10 ++++++----
> 16 files changed, 56 insertions(+), 47 deletions(-)
>
> diff --git a/fs/aio.c b/fs/aio.c
> index 793b7b15ec4b..7fc7b6221312 100644
> --- a/fs/aio.c
> +++ b/fs/aio.c
> @@ -392,15 +392,15 @@ static const struct vm_operations_struct aio_ring_vm_ops = {
> #endif
> };
>
> -static int aio_ring_mmap(struct file *file, struct vm_area_struct *vma)
> +static int aio_ring_mmap_prepare(struct vm_area_desc *desc)
> {
> - vm_flags_set(vma, VM_DONTEXPAND);
> - vma->vm_ops = &aio_ring_vm_ops;
> + desc->vm_flags |= VM_DONTEXPAND;
> + desc->vm_ops = &aio_ring_vm_ops;
> return 0;
> }
>
> static const struct file_operations aio_ring_fops = {
> - .mmap = aio_ring_mmap,
> + .mmap_prepare = aio_ring_mmap_prepare,
> };
>
> #if IS_ENABLED(CONFIG_MIGRATION)
> diff --git a/fs/bcachefs/fs.c b/fs/bcachefs/fs.c
> index 3063a8ddc2df..9c2238edc0e3 100644
> --- a/fs/bcachefs/fs.c
> +++ b/fs/bcachefs/fs.c
> @@ -1553,11 +1553,11 @@ static const struct vm_operations_struct bch_vm_ops = {
> .page_mkwrite = bch2_page_mkwrite,
> };
>
> -static int bch2_mmap(struct file *file, struct vm_area_struct *vma)
> +static int bch2_mmap_prepare(struct vm_area_desc *desc)
> {
> - file_accessed(file);
> + file_accessed(desc->file);
>
> - vma->vm_ops = &bch_vm_ops;
> + desc->vm_ops = &bch_vm_ops;
> return 0;
> }
>
> @@ -1740,7 +1740,7 @@ static const struct file_operations bch_file_operations = {
> .llseek = bch2_llseek,
> .read_iter = bch2_read_iter,
> .write_iter = bch2_write_iter,
> - .mmap = bch2_mmap,
> + .mmap_prepare = bch2_mmap_prepare,
> .get_unmapped_area = thp_get_unmapped_area,
> .fsync = bch2_fsync,
> .splice_read = filemap_splice_read,
> diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
> index 8ce6f45f45e0..06bd30b35b95 100644
> --- a/fs/btrfs/file.c
> +++ b/fs/btrfs/file.c
> @@ -1978,15 +1978,16 @@ static const struct vm_operations_struct btrfs_file_vm_ops = {
> .page_mkwrite = btrfs_page_mkwrite,
> };
>
> -static int btrfs_file_mmap(struct file *filp, struct vm_area_struct *vma)
> +static int btrfs_file_mmap_prepare(struct vm_area_desc *desc)
> {
> + struct file *filp = desc->file;
> struct address_space *mapping = filp->f_mapping;
>
> if (!mapping->a_ops->read_folio)
> return -ENOEXEC;
>
> file_accessed(filp);
> - vma->vm_ops = &btrfs_file_vm_ops;
> + desc->vm_ops = &btrfs_file_vm_ops;
>
> return 0;
> }
> @@ -3765,7 +3766,7 @@ const struct file_operations btrfs_file_operations = {
> .splice_read = filemap_splice_read,
> .write_iter = btrfs_file_write_iter,
> .splice_write = iter_file_splice_write,
> - .mmap = btrfs_file_mmap,
> + .mmap_prepare = btrfs_file_mmap_prepare,
> .open = btrfs_file_open,
> .release = btrfs_release_file,
> .get_unmapped_area = thp_get_unmapped_area,
> diff --git a/fs/ceph/addr.c b/fs/ceph/addr.c
> index 60a621b00c65..37522137c380 100644
> --- a/fs/ceph/addr.c
> +++ b/fs/ceph/addr.c
> @@ -2330,13 +2330,14 @@ static const struct vm_operations_struct ceph_vmops = {
> .page_mkwrite = ceph_page_mkwrite,
> };
>
> -int ceph_mmap(struct file *file, struct vm_area_struct *vma)
> +int ceph_mmap_prepare(struct vm_area_desc *desc)
> {
> + struct file *file = desc->file;
> struct address_space *mapping = file->f_mapping;
>
> if (!mapping->a_ops->read_folio)
> return -ENOEXEC;
> - vma->vm_ops = &ceph_vmops;
> + desc->vm_ops = &ceph_vmops;
> return 0;
> }
>
> diff --git a/fs/ceph/file.c b/fs/ceph/file.c
> index d5c674d2ba8a..41b8ec33e864 100644
> --- a/fs/ceph/file.c
> +++ b/fs/ceph/file.c
> @@ -3170,7 +3170,7 @@ const struct file_operations ceph_file_fops = {
> .llseek = ceph_llseek,
> .read_iter = ceph_read_iter,
> .write_iter = ceph_write_iter,
> - .mmap = ceph_mmap,
> + .mmap_prepare = ceph_mmap_prepare,
> .fsync = ceph_fsync,
> .lock = ceph_lock,
> .setlease = simple_nosetlease,
> diff --git a/fs/ceph/super.h b/fs/ceph/super.h
> index bb0db0cc8003..cf176aab0f82 100644
> --- a/fs/ceph/super.h
> +++ b/fs/ceph/super.h
> @@ -1286,7 +1286,7 @@ extern void __ceph_touch_fmode(struct ceph_inode_info *ci,
> /* addr.c */
> extern const struct address_space_operations ceph_aops;
> extern const struct netfs_request_ops ceph_netfs_ops;
> -extern int ceph_mmap(struct file *file, struct vm_area_struct *vma);
> +int ceph_mmap_prepare(struct vm_area_desc *desc);
> extern int ceph_uninline_data(struct file *file);
> extern int ceph_pool_perm_check(struct inode *inode, int need);
> extern void ceph_pool_perm_destroy(struct ceph_mds_client* mdsc);
Looks good for CephFS.
Reviewed-by: Viacheslav Dubeyko <Slava.Dubeyko@ibm.com>
Thanks,
Slava.
> diff --git a/fs/exfat/file.c b/fs/exfat/file.c
> index 841a5b18e3df..d63213c8a823 100644
> --- a/fs/exfat/file.c
> +++ b/fs/exfat/file.c
> @@ -683,13 +683,14 @@ static const struct vm_operations_struct exfat_file_vm_ops = {
> .page_mkwrite = exfat_page_mkwrite,
> };
>
> -static int exfat_file_mmap(struct file *file, struct vm_area_struct *vma)
> +static int exfat_file_mmap_prepare(struct vm_area_desc *desc)
> {
> + struct file *file = desc->file;
> if (unlikely(exfat_forced_shutdown(file_inode(file)->i_sb)))
> return -EIO;
>
> file_accessed(file);
> - vma->vm_ops = &exfat_file_vm_ops;
> + desc->vm_ops = &exfat_file_vm_ops;
> return 0;
> }
>
> @@ -710,7 +711,7 @@ const struct file_operations exfat_file_operations = {
> #ifdef CONFIG_COMPAT
> .compat_ioctl = exfat_compat_ioctl,
> #endif
> - .mmap = exfat_file_mmap,
> + .mmap_prepare = exfat_file_mmap_prepare,
> .fsync = exfat_file_fsync,
> .splice_read = exfat_splice_read,
> .splice_write = iter_file_splice_write,
> diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
> index 6bd3de64f2a8..7af2b49b7e8a 100644
> --- a/fs/f2fs/file.c
> +++ b/fs/f2fs/file.c
> @@ -532,8 +532,9 @@ static loff_t f2fs_llseek(struct file *file, loff_t offset, int whence)
> return -EINVAL;
> }
>
> -static int f2fs_file_mmap(struct file *file, struct vm_area_struct *vma)
> +static int f2fs_file_mmap_prepare(struct vm_area_desc *desc)
> {
> + struct file *file = desc->file;
> struct inode *inode = file_inode(file);
>
> if (unlikely(f2fs_cp_error(F2FS_I_SB(inode))))
> @@ -543,7 +544,7 @@ static int f2fs_file_mmap(struct file *file, struct vm_area_struct *vma)
> return -EOPNOTSUPP;
>
> file_accessed(file);
> - vma->vm_ops = &f2fs_file_vm_ops;
> + desc->vm_ops = &f2fs_file_vm_ops;
>
> f2fs_down_read(&F2FS_I(inode)->i_sem);
> set_inode_flag(inode, FI_MMAP_FILE);
> @@ -5376,7 +5377,7 @@ const struct file_operations f2fs_file_operations = {
> .iopoll = iocb_bio_iopoll,
> .open = f2fs_file_open,
> .release = f2fs_release_file,
> - .mmap = f2fs_file_mmap,
> + .mmap_prepare = f2fs_file_mmap_prepare,
> .flush = f2fs_file_flush,
> .fsync = f2fs_sync_file,
> .fallocate = f2fs_fallocate,
> diff --git a/fs/nilfs2/file.c b/fs/nilfs2/file.c
> index 0e3fc5ba33c7..1b8d754db44d 100644
> --- a/fs/nilfs2/file.c
> +++ b/fs/nilfs2/file.c
> @@ -125,10 +125,10 @@ static const struct vm_operations_struct nilfs_file_vm_ops = {
> .page_mkwrite = nilfs_page_mkwrite,
> };
>
> -static int nilfs_file_mmap(struct file *file, struct vm_area_struct *vma)
> +static int nilfs_file_mmap_prepare(struct vm_area_desc *desc)
> {
> - file_accessed(file);
> - vma->vm_ops = &nilfs_file_vm_ops;
> + file_accessed(desc->file);
> + desc->vm_ops = &nilfs_file_vm_ops;
> return 0;
> }
>
> @@ -144,7 +144,7 @@ const struct file_operations nilfs_file_operations = {
> #ifdef CONFIG_COMPAT
> .compat_ioctl = nilfs_compat_ioctl,
> #endif /* CONFIG_COMPAT */
> - .mmap = nilfs_file_mmap,
> + .mmap_prepare = nilfs_file_mmap_prepare,
> .open = generic_file_open,
> /* .release = nilfs_release_file, */
> .fsync = nilfs_sync_file,
> diff --git a/fs/ocfs2/file.c b/fs/ocfs2/file.c
> index 2056cf08ac1e..21d797ccccd0 100644
> --- a/fs/ocfs2/file.c
> +++ b/fs/ocfs2/file.c
> @@ -2800,7 +2800,7 @@ const struct inode_operations ocfs2_special_file_iops = {
> */
> const struct file_operations ocfs2_fops = {
> .llseek = ocfs2_file_llseek,
> - .mmap = ocfs2_mmap,
> + .mmap_prepare = ocfs2_mmap_prepare,
> .fsync = ocfs2_sync_file,
> .release = ocfs2_file_release,
> .open = ocfs2_file_open,
> @@ -2850,7 +2850,7 @@ const struct file_operations ocfs2_dops = {
> */
> const struct file_operations ocfs2_fops_no_plocks = {
> .llseek = ocfs2_file_llseek,
> - .mmap = ocfs2_mmap,
> + .mmap_prepare = ocfs2_mmap_prepare,
> .fsync = ocfs2_sync_file,
> .release = ocfs2_file_release,
> .open = ocfs2_file_open,
> diff --git a/fs/ocfs2/mmap.c b/fs/ocfs2/mmap.c
> index 6a314e9f2b49..50e2faf64c19 100644
> --- a/fs/ocfs2/mmap.c
> +++ b/fs/ocfs2/mmap.c
> @@ -159,8 +159,9 @@ static const struct vm_operations_struct ocfs2_file_vm_ops = {
> .page_mkwrite = ocfs2_page_mkwrite,
> };
>
> -int ocfs2_mmap(struct file *file, struct vm_area_struct *vma)
> +int ocfs2_mmap_prepare(struct vm_area_desc *desc)
> {
> + struct file *file = desc->file;
> int ret = 0, lock_level = 0;
>
> ret = ocfs2_inode_lock_atime(file_inode(file),
> @@ -171,7 +172,7 @@ int ocfs2_mmap(struct file *file, struct vm_area_struct *vma)
> }
> ocfs2_inode_unlock(file_inode(file), lock_level);
> out:
> - vma->vm_ops = &ocfs2_file_vm_ops;
> + desc->vm_ops = &ocfs2_file_vm_ops;
> return 0;
> }
>
> diff --git a/fs/ocfs2/mmap.h b/fs/ocfs2/mmap.h
> index 1051507cc684..d21c30de6b8c 100644
> --- a/fs/ocfs2/mmap.h
> +++ b/fs/ocfs2/mmap.h
> @@ -2,6 +2,6 @@
> #ifndef OCFS2_MMAP_H
> #define OCFS2_MMAP_H
>
> -int ocfs2_mmap(struct file *file, struct vm_area_struct *vma);
> +int ocfs2_mmap_prepare(struct vm_area_desc *desc);
>
> #endif /* OCFS2_MMAP_H */
> diff --git a/fs/orangefs/file.c b/fs/orangefs/file.c
> index 90c49c0de243..919f99b16834 100644
> --- a/fs/orangefs/file.c
> +++ b/fs/orangefs/file.c
> @@ -398,8 +398,9 @@ static const struct vm_operations_struct orangefs_file_vm_ops = {
> /*
> * Memory map a region of a file.
> */
> -static int orangefs_file_mmap(struct file *file, struct vm_area_struct *vma)
> +static int orangefs_file_mmap_prepare(struct vm_area_desc *desc)
> {
> + struct file *file = desc->file;
> int ret;
>
> ret = orangefs_revalidate_mapping(file_inode(file));
> @@ -410,10 +411,11 @@ static int orangefs_file_mmap(struct file *file, struct vm_area_struct *vma)
> "orangefs_file_mmap: called on %pD\n", file);
>
> /* set the sequential readahead hint */
> - vm_flags_mod(vma, VM_SEQ_READ, VM_RAND_READ);
> + desc->vm_flags |= VM_SEQ_READ;
> + desc->vm_flags &= ~VM_RAND_READ;
>
> file_accessed(file);
> - vma->vm_ops = &orangefs_file_vm_ops;
> + desc->vm_ops = &orangefs_file_vm_ops;
> return 0;
> }
>
> @@ -574,7 +576,7 @@ const struct file_operations orangefs_file_operations = {
> .read_iter = orangefs_file_read_iter,
> .write_iter = orangefs_file_write_iter,
> .lock = orangefs_lock,
> - .mmap = orangefs_file_mmap,
> + .mmap_prepare = orangefs_file_mmap_prepare,
> .open = generic_file_open,
> .splice_read = orangefs_file_splice_read,
> .splice_write = iter_file_splice_write,
> diff --git a/fs/ramfs/file-nommu.c b/fs/ramfs/file-nommu.c
> index 7a6d980e614d..77b8ca2757e0 100644
> --- a/fs/ramfs/file-nommu.c
> +++ b/fs/ramfs/file-nommu.c
> @@ -28,7 +28,7 @@ static unsigned long ramfs_nommu_get_unmapped_area(struct file *file,
> unsigned long len,
> unsigned long pgoff,
> unsigned long flags);
> -static int ramfs_nommu_mmap(struct file *file, struct vm_area_struct *vma);
> +static int ramfs_nommu_mmap_prepare(struct vm_area_desc *desc);
>
> static unsigned ramfs_mmap_capabilities(struct file *file)
> {
> @@ -38,7 +38,7 @@ static unsigned ramfs_mmap_capabilities(struct file *file)
>
> const struct file_operations ramfs_file_operations = {
> .mmap_capabilities = ramfs_mmap_capabilities,
> - .mmap = ramfs_nommu_mmap,
> + .mmap_prepare = ramfs_nommu_mmap_prepare,
> .get_unmapped_area = ramfs_nommu_get_unmapped_area,
> .read_iter = generic_file_read_iter,
> .write_iter = generic_file_write_iter,
> @@ -262,12 +262,12 @@ static unsigned long ramfs_nommu_get_unmapped_area(struct file *file,
> /*
> * set up a mapping for shared memory segments
> */
> -static int ramfs_nommu_mmap(struct file *file, struct vm_area_struct *vma)
> +static int ramfs_nommu_mmap_prepare(struct vm_area_desc *desc)
> {
> - if (!is_nommu_shared_mapping(vma->vm_flags))
> + if (!is_nommu_shared_mapping(desc->vm_flags))
> return -ENOSYS;
>
> - file_accessed(file);
> - vma->vm_ops = &generic_file_vm_ops;
> + file_accessed(desc->file);
> + desc->vm_ops = &generic_file_vm_ops;
> return 0;
> }
> diff --git a/fs/romfs/mmap-nommu.c b/fs/romfs/mmap-nommu.c
> index 4520ca413867..4b77c6dc4418 100644
> --- a/fs/romfs/mmap-nommu.c
> +++ b/fs/romfs/mmap-nommu.c
> @@ -61,9 +61,9 @@ static unsigned long romfs_get_unmapped_area(struct file *file,
> * permit a R/O mapping to be made directly through onto an MTD device if
> * possible
> */
> -static int romfs_mmap(struct file *file, struct vm_area_struct *vma)
> +static int romfs_mmap_prepare(struct vm_area_desc *desc)
> {
> - return is_nommu_shared_mapping(vma->vm_flags) ? 0 : -ENOSYS;
> + return is_nommu_shared_mapping(desc->vm_flags) ? 0 : -ENOSYS;
> }
>
> static unsigned romfs_mmap_capabilities(struct file *file)
> @@ -79,7 +79,7 @@ const struct file_operations romfs_ro_fops = {
> .llseek = generic_file_llseek,
> .read_iter = generic_file_read_iter,
> .splice_read = filemap_splice_read,
> - .mmap = romfs_mmap,
> + .mmap_prepare = romfs_mmap_prepare,
> .get_unmapped_area = romfs_get_unmapped_area,
> .mmap_capabilities = romfs_mmap_capabilities,
> };
> diff --git a/fs/zonefs/file.c b/fs/zonefs/file.c
> index 42e2c0065bb3..c1848163b378 100644
> --- a/fs/zonefs/file.c
> +++ b/fs/zonefs/file.c
> @@ -312,8 +312,10 @@ static const struct vm_operations_struct zonefs_file_vm_ops = {
> .page_mkwrite = zonefs_filemap_page_mkwrite,
> };
>
> -static int zonefs_file_mmap(struct file *file, struct vm_area_struct *vma)
> +static int zonefs_file_mmap_prepare(struct vm_area_desc *desc)
> {
> + struct file *file = desc->file;
> +
> /*
> * Conventional zones accept random writes, so their files can support
> * shared writable mappings. For sequential zone files, only read
> @@ -321,11 +323,11 @@ static int zonefs_file_mmap(struct file *file, struct vm_area_struct *vma)
> * ordering between msync() and page cache writeback.
> */
> if (zonefs_inode_is_seq(file_inode(file)) &&
> - (vma->vm_flags & VM_SHARED) && (vma->vm_flags & VM_MAYWRITE))
> + (desc->vm_flags & VM_SHARED) && (desc->vm_flags & VM_MAYWRITE))
> return -EINVAL;
>
> file_accessed(file);
> - vma->vm_ops = &zonefs_file_vm_ops;
> + desc->vm_ops = &zonefs_file_vm_ops;
>
> return 0;
> }
> @@ -850,7 +852,7 @@ const struct file_operations zonefs_file_operations = {
> .open = zonefs_file_open,
> .release = zonefs_file_release,
> .fsync = zonefs_file_fsync,
> - .mmap = zonefs_file_mmap,
> + .mmap_prepare = zonefs_file_mmap_prepare,
> .llseek = zonefs_file_llseek,
> .read_iter = zonefs_file_read_iter,
> .write_iter = zonefs_file_write_iter,
^ permalink raw reply [flat|nested] 50+ messages in thread
* Re: [PATCH 08/10] fs: convert simple use of generic_file_*_mmap() to .mmap_prepare()
2025-06-16 19:33 ` [PATCH 08/10] fs: convert simple use of generic_file_*_mmap() to .mmap_prepare() Lorenzo Stoakes
@ 2025-06-16 23:26 ` Viacheslav Dubeyko
2025-06-17 10:14 ` Jan Kara
2025-06-17 14:07 ` Dave Kleikamp
2 siblings, 0 replies; 50+ messages in thread
From: Viacheslav Dubeyko @ 2025-06-16 23:26 UTC (permalink / raw)
To: lorenzo.stoakes@oracle.com, akpm@linux-foundation.org
Cc: xiang@kernel.org, codalist@coda.cs.cmu.edu,
dri-devel@lists.freedesktop.org, anna@kernel.org, vbabka@suse.cz,
pfalcato@suse.de, jack@suse.cz, linux-xfs@vger.kernel.org,
v9fs@lists.linux.dev, glaubitz@physik.fu-berlin.de,
miklos@szeredi.hu, linux-unionfs@vger.kernel.org,
amir73il@gmail.com, slava@dubeyko.com, Hans De Goede,
asmadeus@codewreck.org, simona@ffwll.ch, jth@kernel.org,
shaggy@kernel.org, willy@infradead.org,
linux-erofs@lists.ozlabs.org, jaharkes@cs.cmu.edu,
tursulin@ursulin.net, trondmy@kernel.org,
ecryptfs@vger.kernel.org, ericvh@kernel.org,
joonas.lahtinen@linux.intel.com, hirofumi@mail.parknet.co.jp,
linux-nilfs@vger.kernel.org, Xiubo Li, aivazian.tigran@gmail.com,
hubcap@omnibond.com, linux-kernel@vger.kernel.org,
intel-gfx@lists.freedesktop.org, sfrench@samba.org,
jfs-discussion@lists.sourceforge.net, clm@fb.com,
jlbec@evilplan.org, lihongbo22@huawei.com,
ronniesahlberg@gmail.com, lucho@ionkov.net,
anton.ivanov@cambridgegreys.com, dan.j.williams@intel.com,
Liam.Howlett@oracle.com, sj1557.seo@samsung.com,
josef@toxicpanda.com, linux-block@vger.kernel.org, cem@kernel.org,
linkinjeon@kernel.org, tom@talpey.com,
mikulas@artax.karlin.mff.cuni.cz, bcrl@kvack.org,
linux-afs@lists.infradead.org, mark@fasheh.com,
linux-mtd@lists.infradead.org, linux-nfs@vger.kernel.org,
bharathsm@microsoft.com, linux-ext4@vger.kernel.org,
linux-f2fs-devel@lists.sourceforge.net, tytso@mit.edu,
martin@omnibond.com, jefflexu@linux.alibaba.com,
naohiro.aota@wdc.com, frank.li@vivo.com, nvdimm@lists.linux.dev,
dsterba@suse.com, pc@manguebit.org, dwmw2@infradead.org,
code@tyhicks.com, ocfs2-devel@lists.linux.dev,
linux-aio@kvack.org, idryomov@gmail.com, dlemoal@kernel.org,
linux-btrfs@vger.kernel.org, viro@zeniv.linux.org.uk,
zbestahu@gmail.com, linux-cifs@vger.kernel.org,
johannes@sipsolutions.net, David Howells,
linux-fsdevel@vger.kernel.org, ntfs3@lists.linux.dev,
richard@nod.at, yuezhang.mo@sony.com, joseph.qi@linux.alibaba.com,
axboe@kernel.dk, linux-karma-devel@lists.sourceforge.net,
kent.overstreet@linux.dev, ceph-devel@vger.kernel.org,
samba-technical@lists.samba.org, dhavale@google.com,
devel@lists.orangefs.org, konishi.ryusuke@gmail.com,
linux_oss@crudebyte.com, jaegeuk@kernel.org,
sprasad@microsoft.com, linux-um@lists.infradead.org,
jani.nikula@linux.intel.com, brauner@kernel.org,
rodrigo.vivi@intel.com, adilger.kernel@dilger.ca,
airlied@gmail.com, chao@kernel.org, coda@cs.cmu.edu,
jannh@google.com, kees@kernel.org, me@bobcopeland.com,
chengzhihao1@huawei.com, linux-bcachefs@vger.kernel.org,
marc.dionne@auristor.com,
almaz.alexandrovich@paragon-software.com, linux-mm@kvack.org
On Mon, 2025-06-16 at 20:33 +0100, Lorenzo Stoakes wrote:
> Since commit c84bf6dd2b83 ("mm: introduce new .mmap_prepare() file
> callback"), the f_op->mmap() hook has been deprecated in favour of
> f_op->mmap_prepare().
>
> We have provided generic .mmap_prepare() equivalents, so update all file
> systems that specify these directly in their file_operations structures.
>
> This updates 9p, adfs, affs, bfs, fat, hfs, hfsplus, hostfs, hpfs, jffs2,
> jfs, minix, omfs, ramfs and ufs file systems directly.
>
> It updates generic_ro_fops which impacts qnx4, cramfs, befs, squashfs,
> frebxfs, qnx6, efs, romfs, erofs and isofs file systems.
>
> There are remaining file systems which use generic hooks in a less direct
> way which we address in a subsequent commit.
>
> Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
> ---
> fs/9p/vfs_file.c | 2 +-
> fs/adfs/file.c | 2 +-
> fs/affs/file.c | 2 +-
> fs/bfs/file.c | 2 +-
> fs/fat/file.c | 2 +-
> fs/hfs/inode.c | 2 +-
> fs/hfsplus/inode.c | 2 +-
> fs/hostfs/hostfs_kern.c | 2 +-
> fs/hpfs/file.c | 2 +-
> fs/jffs2/file.c | 2 +-
> fs/jfs/file.c | 2 +-
> fs/minix/file.c | 2 +-
> fs/omfs/file.c | 2 +-
> fs/ramfs/file-mmu.c | 2 +-
> fs/read_write.c | 2 +-
> fs/ufs/file.c | 2 +-
> 16 files changed, 16 insertions(+), 16 deletions(-)
>
> diff --git a/fs/9p/vfs_file.c b/fs/9p/vfs_file.c
> index 348cc90bf9c5..2ff3e0ac7266 100644
> --- a/fs/9p/vfs_file.c
> +++ b/fs/9p/vfs_file.c
> @@ -516,7 +516,7 @@ const struct file_operations v9fs_file_operations = {
> .open = v9fs_file_open,
> .release = v9fs_dir_release,
> .lock = v9fs_file_lock,
> - .mmap = generic_file_readonly_mmap,
> + .mmap_prepare = generic_file_readonly_mmap_prepare,
> .splice_read = v9fs_file_splice_read,
> .splice_write = iter_file_splice_write,
> .fsync = v9fs_file_fsync,
> diff --git a/fs/adfs/file.c b/fs/adfs/file.c
> index ee80718aaeec..cd13165fd904 100644
> --- a/fs/adfs/file.c
> +++ b/fs/adfs/file.c
> @@ -25,7 +25,7 @@
> const struct file_operations adfs_file_operations = {
> .llseek = generic_file_llseek,
> .read_iter = generic_file_read_iter,
> - .mmap = generic_file_mmap,
> + .mmap_prepare = generic_file_mmap_prepare,
> .fsync = generic_file_fsync,
> .write_iter = generic_file_write_iter,
> .splice_read = filemap_splice_read,
> diff --git a/fs/affs/file.c b/fs/affs/file.c
> index 7a71018e3f67..fbac204b7055 100644
> --- a/fs/affs/file.c
> +++ b/fs/affs/file.c
> @@ -999,7 +999,7 @@ const struct file_operations affs_file_operations = {
> .llseek = generic_file_llseek,
> .read_iter = generic_file_read_iter,
> .write_iter = generic_file_write_iter,
> - .mmap = generic_file_mmap,
> + .mmap_prepare = generic_file_mmap_prepare,
> .open = affs_file_open,
> .release = affs_file_release,
> .fsync = affs_file_fsync,
> diff --git a/fs/bfs/file.c b/fs/bfs/file.c
> index fa66a09e496a..6685c3411fe7 100644
> --- a/fs/bfs/file.c
> +++ b/fs/bfs/file.c
> @@ -27,7 +27,7 @@ const struct file_operations bfs_file_operations = {
> .llseek = generic_file_llseek,
> .read_iter = generic_file_read_iter,
> .write_iter = generic_file_write_iter,
> - .mmap = generic_file_mmap,
> + .mmap_prepare = generic_file_mmap_prepare,
> .splice_read = filemap_splice_read,
> };
>
> diff --git a/fs/fat/file.c b/fs/fat/file.c
> index e887e9ab7472..4fc49a614fb8 100644
> --- a/fs/fat/file.c
> +++ b/fs/fat/file.c
> @@ -204,7 +204,7 @@ const struct file_operations fat_file_operations = {
> .llseek = generic_file_llseek,
> .read_iter = generic_file_read_iter,
> .write_iter = generic_file_write_iter,
> - .mmap = generic_file_mmap,
> + .mmap_prepare = generic_file_mmap_prepare,
> .release = fat_file_release,
> .unlocked_ioctl = fat_generic_ioctl,
> .compat_ioctl = compat_ptr_ioctl,
> diff --git a/fs/hfs/inode.c b/fs/hfs/inode.c
> index a81ce7a740b9..d419586d668d 100644
> --- a/fs/hfs/inode.c
> +++ b/fs/hfs/inode.c
> @@ -690,7 +690,7 @@ static const struct file_operations hfs_file_operations = {
> .llseek = generic_file_llseek,
> .read_iter = generic_file_read_iter,
> .write_iter = generic_file_write_iter,
> - .mmap = generic_file_mmap,
> + .mmap_prepare = generic_file_mmap_prepare,
> .splice_read = filemap_splice_read,
> .fsync = hfs_file_fsync,
> .open = hfs_file_open,
> diff --git a/fs/hfsplus/inode.c b/fs/hfsplus/inode.c
> index f331e9574217..0af7e302730c 100644
> --- a/fs/hfsplus/inode.c
> +++ b/fs/hfsplus/inode.c
> @@ -366,7 +366,7 @@ static const struct file_operations hfsplus_file_operations = {
> .llseek = generic_file_llseek,
> .read_iter = generic_file_read_iter,
> .write_iter = generic_file_write_iter,
> - .mmap = generic_file_mmap,
> + .mmap_prepare = generic_file_mmap_prepare,
> .splice_read = filemap_splice_read,
> .fsync = hfsplus_file_fsync,
> .open = hfsplus_file_open,
Looks good for HFS/HFS+.
Reviewed-by: Viacheslav Dubeyko <Slava.Dubeyko@ibm.com>
Thanks,
Slava.
> diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c
> index 702c41317589..bc22b6cc72af 100644
> --- a/fs/hostfs/hostfs_kern.c
> +++ b/fs/hostfs/hostfs_kern.c
> @@ -382,7 +382,7 @@ static const struct file_operations hostfs_file_fops = {
> .splice_write = iter_file_splice_write,
> .read_iter = generic_file_read_iter,
> .write_iter = generic_file_write_iter,
> - .mmap = generic_file_mmap,
> + .mmap_prepare = generic_file_mmap_prepare,
> .open = hostfs_open,
> .release = hostfs_file_release,
> .fsync = hostfs_fsync,
> diff --git a/fs/hpfs/file.c b/fs/hpfs/file.c
> index 449a3fc1b8d9..a1a44e3edb19 100644
> --- a/fs/hpfs/file.c
> +++ b/fs/hpfs/file.c
> @@ -255,7 +255,7 @@ const struct file_operations hpfs_file_ops =
> .llseek = generic_file_llseek,
> .read_iter = generic_file_read_iter,
> .write_iter = generic_file_write_iter,
> - .mmap = generic_file_mmap,
> + .mmap_prepare = generic_file_mmap_prepare,
> .release = hpfs_file_release,
> .fsync = hpfs_file_fsync,
> .splice_read = filemap_splice_read,
> diff --git a/fs/jffs2/file.c b/fs/jffs2/file.c
> index 13c18ccc13b0..1e05f7fe5dd4 100644
> --- a/fs/jffs2/file.c
> +++ b/fs/jffs2/file.c
> @@ -54,7 +54,7 @@ const struct file_operations jffs2_file_operations =
> .read_iter = generic_file_read_iter,
> .write_iter = generic_file_write_iter,
> .unlocked_ioctl=jffs2_ioctl,
> - .mmap = generic_file_readonly_mmap,
> + .mmap_prepare = generic_file_readonly_mmap_prepare,
> .fsync = jffs2_fsync,
> .splice_read = filemap_splice_read,
> .splice_write = iter_file_splice_write,
> diff --git a/fs/jfs/file.c b/fs/jfs/file.c
> index 01b6912e60f8..5e47951db630 100644
> --- a/fs/jfs/file.c
> +++ b/fs/jfs/file.c
> @@ -143,7 +143,7 @@ const struct file_operations jfs_file_operations = {
> .llseek = generic_file_llseek,
> .read_iter = generic_file_read_iter,
> .write_iter = generic_file_write_iter,
> - .mmap = generic_file_mmap,
> + .mmap_prepare = generic_file_mmap_prepare,
> .splice_read = filemap_splice_read,
> .splice_write = iter_file_splice_write,
> .fsync = jfs_fsync,
> diff --git a/fs/minix/file.c b/fs/minix/file.c
> index 906d192ab7f3..dca7ac71f049 100644
> --- a/fs/minix/file.c
> +++ b/fs/minix/file.c
> @@ -17,7 +17,7 @@ const struct file_operations minix_file_operations = {
> .llseek = generic_file_llseek,
> .read_iter = generic_file_read_iter,
> .write_iter = generic_file_write_iter,
> - .mmap = generic_file_mmap,
> + .mmap_prepare = generic_file_mmap_prepare,
> .fsync = generic_file_fsync,
> .splice_read = filemap_splice_read,
> };
> diff --git a/fs/omfs/file.c b/fs/omfs/file.c
> index 98358d405b6a..319c04e63964 100644
> --- a/fs/omfs/file.c
> +++ b/fs/omfs/file.c
> @@ -332,7 +332,7 @@ const struct file_operations omfs_file_operations = {
> .llseek = generic_file_llseek,
> .read_iter = generic_file_read_iter,
> .write_iter = generic_file_write_iter,
> - .mmap = generic_file_mmap,
> + .mmap_prepare = generic_file_mmap_prepare,
> .fsync = generic_file_fsync,
> .splice_read = filemap_splice_read,
> };
> diff --git a/fs/ramfs/file-mmu.c b/fs/ramfs/file-mmu.c
> index b45c7edc3225..b11f5b20b78b 100644
> --- a/fs/ramfs/file-mmu.c
> +++ b/fs/ramfs/file-mmu.c
> @@ -41,7 +41,7 @@ static unsigned long ramfs_mmu_get_unmapped_area(struct file *file,
> const struct file_operations ramfs_file_operations = {
> .read_iter = generic_file_read_iter,
> .write_iter = generic_file_write_iter,
> - .mmap = generic_file_mmap,
> + .mmap_prepare = generic_file_mmap_prepare,
> .fsync = noop_fsync,
> .splice_read = filemap_splice_read,
> .splice_write = iter_file_splice_write,
> diff --git a/fs/read_write.c b/fs/read_write.c
> index 0ef70e128c4a..80fdab99f9e4 100644
> --- a/fs/read_write.c
> +++ b/fs/read_write.c
> @@ -28,7 +28,7 @@
> const struct file_operations generic_ro_fops = {
> .llseek = generic_file_llseek,
> .read_iter = generic_file_read_iter,
> - .mmap = generic_file_readonly_mmap,
> + .mmap_prepare = generic_file_readonly_mmap_prepare,
> .splice_read = filemap_splice_read,
> };
>
> diff --git a/fs/ufs/file.c b/fs/ufs/file.c
> index 487ad1fc2de6..c2a391c17df7 100644
> --- a/fs/ufs/file.c
> +++ b/fs/ufs/file.c
> @@ -38,7 +38,7 @@ const struct file_operations ufs_file_operations = {
> .llseek = generic_file_llseek,
> .read_iter = generic_file_read_iter,
> .write_iter = generic_file_write_iter,
> - .mmap = generic_file_mmap,
> + .mmap_prepare = generic_file_mmap_prepare,
> .open = generic_file_open,
> .fsync = generic_file_fsync,
> .splice_read = filemap_splice_read,
--
Viacheslav Dubeyko <Slava.Dubeyko@ibm.com>
^ permalink raw reply [flat|nested] 50+ messages in thread
* Re: [PATCH 06/10] fs/xfs: transition from deprecated .mmap hook to .mmap_prepare
2025-06-16 19:33 ` [PATCH 06/10] fs/xfs: " Lorenzo Stoakes
@ 2025-06-17 5:08 ` Christoph Hellwig
2025-06-17 11:45 ` Christian Brauner
0 siblings, 1 reply; 50+ messages in thread
From: Christoph Hellwig @ 2025-06-17 5:08 UTC (permalink / raw)
To: Lorenzo Stoakes
Cc: Andrew Morton, Liam R . Howlett, Jens Axboe, Jani Nikula,
Joonas Lahtinen, Rodrigo Vivi, Tvrtko Ursulin, David Airlie,
Simona Vetter, Eric Van Hensbergen, Latchesar Ionkov,
Dominique Martinet, Christian Schoenebeck, David Sterba,
David Howells, Marc Dionne, Alexander Viro, Christian Brauner,
Jan Kara, Benjamin LaHaise, Miklos Szeredi, Amir Goldstein,
Kent Overstreet, Tigran A . Aivazian, Kees Cook, Chris Mason,
Josef Bacik, Xiubo Li, Ilya Dryomov, Jan Harkes, coda,
Tyler Hicks, Gao Xiang, Chao Yu, Yue Hu, Jeffle Xu,
Sandeep Dhavale, Hongbo Li, Namjae Jeon, Sungjong Seo,
Yuezhang Mo, Theodore Ts'o, Andreas Dilger, Jaegeuk Kim,
OGAWA Hirofumi, Viacheslav Dubeyko, John Paul Adrian Glaubitz,
Yangtao Li, Richard Weinberger, Anton Ivanov, Johannes Berg,
Mikulas Patocka, David Woodhouse, Dave Kleikamp, Trond Myklebust,
Anna Schumaker, Ryusuke Konishi, Konstantin Komarov, Mark Fasheh,
Joel Becker, Joseph Qi, Bob Copeland, Mike Marshall,
Martin Brandenburg, Steve French, Paulo Alcantara,
Ronnie Sahlberg, Shyam Prasad N, Tom Talpey, Bharath SM,
Zhihao Cheng, Hans de Goede, Carlos Maiolino, Damien Le Moal,
Naohiro Aota, Johannes Thumshirn, Dan Williams, Matthew Wilcox,
Vlastimil Babka, Jann Horn, Pedro Falcato, linux-block,
linux-kernel, intel-gfx, dri-devel, v9fs, linux-fsdevel,
linux-afs, linux-aio, linux-unionfs, linux-bcachefs, linux-mm,
linux-btrfs, ceph-devel, codalist, ecryptfs, linux-erofs,
linux-ext4, linux-f2fs-devel, linux-um, linux-mtd, jfs-discussion,
linux-nfs, linux-nilfs, ntfs3, ocfs2-devel, linux-karma-devel,
devel, linux-cifs, samba-technical, linux-xfs, nvdimm
On Mon, Jun 16, 2025 at 08:33:25PM +0100, Lorenzo Stoakes wrote:
> STATIC int
> -xfs_file_mmap(
> - struct file *file,
> - struct vm_area_struct *vma)
> +xfs_file_mmap_prepare(
> + struct vm_area_desc *desc)
Please stick to the existing alignment for the declarations.
Otherwise this looks good.
^ permalink raw reply [flat|nested] 50+ messages in thread
* Re: [PATCH 01/10] mm: rename call_mmap/mmap_prepare to vfs_mmap/mmap_prepare
2025-06-16 19:33 ` [PATCH 01/10] mm: rename call_mmap/mmap_prepare to vfs_mmap/mmap_prepare Lorenzo Stoakes
@ 2025-06-17 5:10 ` Christoph Hellwig
2025-06-17 5:29 ` Lorenzo Stoakes
2025-06-17 18:57 ` Vlastimil Babka
1 sibling, 1 reply; 50+ messages in thread
From: Christoph Hellwig @ 2025-06-17 5:10 UTC (permalink / raw)
To: Lorenzo Stoakes
Cc: Andrew Morton, Liam R . Howlett, Jens Axboe, Jani Nikula,
Joonas Lahtinen, Rodrigo Vivi, Tvrtko Ursulin, David Airlie,
Simona Vetter, Eric Van Hensbergen, Latchesar Ionkov,
Dominique Martinet, Christian Schoenebeck, David Sterba,
David Howells, Marc Dionne, Alexander Viro, Christian Brauner,
Jan Kara, Benjamin LaHaise, Miklos Szeredi, Amir Goldstein,
Kent Overstreet, Tigran A . Aivazian, Kees Cook, Chris Mason,
Josef Bacik, Xiubo Li, Ilya Dryomov, Jan Harkes, coda,
Tyler Hicks, Gao Xiang, Chao Yu, Yue Hu, Jeffle Xu,
Sandeep Dhavale, Hongbo Li, Namjae Jeon, Sungjong Seo,
Yuezhang Mo, Theodore Ts'o, Andreas Dilger, Jaegeuk Kim,
OGAWA Hirofumi, Viacheslav Dubeyko, John Paul Adrian Glaubitz,
Yangtao Li, Richard Weinberger, Anton Ivanov, Johannes Berg,
Mikulas Patocka, David Woodhouse, Dave Kleikamp, Trond Myklebust,
Anna Schumaker, Ryusuke Konishi, Konstantin Komarov, Mark Fasheh,
Joel Becker, Joseph Qi, Bob Copeland, Mike Marshall,
Martin Brandenburg, Steve French, Paulo Alcantara,
Ronnie Sahlberg, Shyam Prasad N, Tom Talpey, Bharath SM,
Zhihao Cheng, Hans de Goede, Carlos Maiolino, Damien Le Moal,
Naohiro Aota, Johannes Thumshirn, Dan Williams, Matthew Wilcox,
Vlastimil Babka, Jann Horn, Pedro Falcato, linux-block,
linux-kernel, intel-gfx, dri-devel, v9fs, linux-fsdevel,
linux-afs, linux-aio, linux-unionfs, linux-bcachefs, linux-mm,
linux-btrfs, ceph-devel, codalist, ecryptfs, linux-erofs,
linux-ext4, linux-f2fs-devel, linux-um, linux-mtd, jfs-discussion,
linux-nfs, linux-nilfs, ntfs3, ocfs2-devel, linux-karma-devel,
devel, linux-cifs, samba-technical, linux-xfs, nvdimm
On Mon, Jun 16, 2025 at 08:33:20PM +0100, Lorenzo Stoakes wrote:
> The call_mmap() function violates the existing convention in
> include/linux/fs.h whereby invocations of virtual file system hooks is
> performed by functions prefixed with vfs_xxx().
>
> Correct this by renaming call_mmap() to vfs_mmap(). This also avoids
> confusion as to the fact that f_op->mmap_prepare may be invoked here.
>
> Also rename __call_mmap_prepare() function to vfs_mmap_prepare() and adjust
> to accept a file parameter, this is useful later for nested file systems.
>
> Finally, fix up the VMA userland tests and ensure the mmap_prepare -> mmap
> shim is implemented there.
Can we please just kill these silly call_* helpers instead?
^ permalink raw reply [flat|nested] 50+ messages in thread
* Re: [PATCH 03/10] fs: consistently use file_has_valid_mmap_hooks() helper
2025-06-16 19:33 ` [PATCH 03/10] fs: consistently " Lorenzo Stoakes
2025-06-16 20:01 ` Kees Cook
@ 2025-06-17 5:11 ` Christoph Hellwig
2025-06-17 5:25 ` Lorenzo Stoakes
1 sibling, 1 reply; 50+ messages in thread
From: Christoph Hellwig @ 2025-06-17 5:11 UTC (permalink / raw)
To: Lorenzo Stoakes
Cc: Andrew Morton, Liam R . Howlett, Jens Axboe, Jani Nikula,
Joonas Lahtinen, Rodrigo Vivi, Tvrtko Ursulin, David Airlie,
Simona Vetter, Eric Van Hensbergen, Latchesar Ionkov,
Dominique Martinet, Christian Schoenebeck, David Sterba,
David Howells, Marc Dionne, Alexander Viro, Christian Brauner,
Jan Kara, Benjamin LaHaise, Miklos Szeredi, Amir Goldstein,
Kent Overstreet, Tigran A . Aivazian, Kees Cook, Chris Mason,
Josef Bacik, Xiubo Li, Ilya Dryomov, Jan Harkes, coda,
Tyler Hicks, Gao Xiang, Chao Yu, Yue Hu, Jeffle Xu,
Sandeep Dhavale, Hongbo Li, Namjae Jeon, Sungjong Seo,
Yuezhang Mo, Theodore Ts'o, Andreas Dilger, Jaegeuk Kim,
OGAWA Hirofumi, Viacheslav Dubeyko, John Paul Adrian Glaubitz,
Yangtao Li, Richard Weinberger, Anton Ivanov, Johannes Berg,
Mikulas Patocka, David Woodhouse, Dave Kleikamp, Trond Myklebust,
Anna Schumaker, Ryusuke Konishi, Konstantin Komarov, Mark Fasheh,
Joel Becker, Joseph Qi, Bob Copeland, Mike Marshall,
Martin Brandenburg, Steve French, Paulo Alcantara,
Ronnie Sahlberg, Shyam Prasad N, Tom Talpey, Bharath SM,
Zhihao Cheng, Hans de Goede, Carlos Maiolino, Damien Le Moal,
Naohiro Aota, Johannes Thumshirn, Dan Williams, Matthew Wilcox,
Vlastimil Babka, Jann Horn, Pedro Falcato, linux-block,
linux-kernel, intel-gfx, dri-devel, v9fs, linux-fsdevel,
linux-afs, linux-aio, linux-unionfs, linux-bcachefs, linux-mm,
linux-btrfs, ceph-devel, codalist, ecryptfs, linux-erofs,
linux-ext4, linux-f2fs-devel, linux-um, linux-mtd, jfs-discussion,
linux-nfs, linux-nilfs, ntfs3, ocfs2-devel, linux-karma-devel,
devel, linux-cifs, samba-technical, linux-xfs, nvdimm
On Mon, Jun 16, 2025 at 08:33:22PM +0100, Lorenzo Stoakes wrote:
> Since commit c84bf6dd2b83 ("mm: introduce new .mmap_prepare() file
> callback"), the f_op->mmap() hook has been deprecated in favour of
> f_op->mmap_prepare().
>
> Additionally, commit bb666b7c2707 ("mm: add mmap_prepare() compatibility
> layer for nested file systems") permits the use of the .mmap_prepare() hook
> even in nested filesystems like overlayfs.
>
> There are a number of places where we check only for f_op->mmap - this is
> incorrect now mmap_prepare exists, so update all of these to use the
> general helper file_has_valid_mmap_hooks().
>
> Most notably, this updates the elf logic to allow for the ability to
> execute binaries on filesystems which have the .mmap_prepare hook, but
> additionally we update nested filesystems.
Can you please give the function a better name before spreading it?
file operations aren't hooks by any classic definition.
^ permalink raw reply [flat|nested] 50+ messages in thread
* Re: [PATCH 03/10] fs: consistently use file_has_valid_mmap_hooks() helper
2025-06-17 5:11 ` Christoph Hellwig
@ 2025-06-17 5:25 ` Lorenzo Stoakes
2025-06-17 5:29 ` Christoph Hellwig
2025-06-17 10:08 ` Jan Kara
0 siblings, 2 replies; 50+ messages in thread
From: Lorenzo Stoakes @ 2025-06-17 5:25 UTC (permalink / raw)
To: Christoph Hellwig
Cc: Andrew Morton, Liam R . Howlett, Jens Axboe, Jani Nikula,
Joonas Lahtinen, Rodrigo Vivi, Tvrtko Ursulin, David Airlie,
Simona Vetter, Eric Van Hensbergen, Latchesar Ionkov,
Dominique Martinet, Christian Schoenebeck, David Sterba,
David Howells, Marc Dionne, Alexander Viro, Christian Brauner,
Jan Kara, Benjamin LaHaise, Miklos Szeredi, Amir Goldstein,
Kent Overstreet, Tigran A . Aivazian, Kees Cook, Chris Mason,
Josef Bacik, Xiubo Li, Ilya Dryomov, Jan Harkes, coda,
Tyler Hicks, Gao Xiang, Chao Yu, Yue Hu, Jeffle Xu,
Sandeep Dhavale, Hongbo Li, Namjae Jeon, Sungjong Seo,
Yuezhang Mo, Theodore Ts'o, Andreas Dilger, Jaegeuk Kim,
OGAWA Hirofumi, Viacheslav Dubeyko, John Paul Adrian Glaubitz,
Yangtao Li, Richard Weinberger, Anton Ivanov, Johannes Berg,
Mikulas Patocka, David Woodhouse, Dave Kleikamp, Trond Myklebust,
Anna Schumaker, Ryusuke Konishi, Konstantin Komarov, Mark Fasheh,
Joel Becker, Joseph Qi, Bob Copeland, Mike Marshall,
Martin Brandenburg, Steve French, Paulo Alcantara,
Ronnie Sahlberg, Shyam Prasad N, Tom Talpey, Bharath SM,
Zhihao Cheng, Hans de Goede, Carlos Maiolino, Damien Le Moal,
Naohiro Aota, Johannes Thumshirn, Dan Williams, Matthew Wilcox,
Vlastimil Babka, Jann Horn, Pedro Falcato, linux-block,
linux-kernel, intel-gfx, dri-devel, v9fs, linux-fsdevel,
linux-afs, linux-aio, linux-unionfs, linux-bcachefs, linux-mm,
linux-btrfs, ceph-devel, codalist, ecryptfs, linux-erofs,
linux-ext4, linux-f2fs-devel, linux-um, linux-mtd, jfs-discussion,
linux-nfs, linux-nilfs, ntfs3, ocfs2-devel, linux-karma-devel,
devel, linux-cifs, samba-technical, linux-xfs, nvdimm
On Mon, Jun 16, 2025 at 10:11:28PM -0700, Christoph Hellwig wrote:
> On Mon, Jun 16, 2025 at 08:33:22PM +0100, Lorenzo Stoakes wrote:
> > Since commit c84bf6dd2b83 ("mm: introduce new .mmap_prepare() file
> > callback"), the f_op->mmap() hook has been deprecated in favour of
> > f_op->mmap_prepare().
> >
> > Additionally, commit bb666b7c2707 ("mm: add mmap_prepare() compatibility
> > layer for nested file systems") permits the use of the .mmap_prepare() hook
> > even in nested filesystems like overlayfs.
> >
> > There are a number of places where we check only for f_op->mmap - this is
> > incorrect now mmap_prepare exists, so update all of these to use the
> > general helper file_has_valid_mmap_hooks().
> >
> > Most notably, this updates the elf logic to allow for the ability to
> > execute binaries on filesystems which have the .mmap_prepare hook, but
> > additionally we update nested filesystems.
>
> Can you please give the function a better name before spreading it?
> file operations aren't hooks by any classic definition.
>
can_mmap_file()?
^ permalink raw reply [flat|nested] 50+ messages in thread
* Re: [PATCH 03/10] fs: consistently use file_has_valid_mmap_hooks() helper
2025-06-17 5:25 ` Lorenzo Stoakes
@ 2025-06-17 5:29 ` Christoph Hellwig
2025-06-17 10:08 ` Jan Kara
1 sibling, 0 replies; 50+ messages in thread
From: Christoph Hellwig @ 2025-06-17 5:29 UTC (permalink / raw)
To: Lorenzo Stoakes
Cc: Christoph Hellwig, Andrew Morton, Liam R . Howlett, Jens Axboe,
Jani Nikula, Joonas Lahtinen, Rodrigo Vivi, Tvrtko Ursulin,
David Airlie, Simona Vetter, Eric Van Hensbergen,
Latchesar Ionkov, Dominique Martinet, Christian Schoenebeck,
David Sterba, David Howells, Marc Dionne, Alexander Viro,
Christian Brauner, Jan Kara, Benjamin LaHaise, Miklos Szeredi,
Amir Goldstein, Kent Overstreet, Tigran A . Aivazian, Kees Cook,
Chris Mason, Josef Bacik, Xiubo Li, Ilya Dryomov, Jan Harkes,
coda, Tyler Hicks, Gao Xiang, Chao Yu, Yue Hu, Jeffle Xu,
Sandeep Dhavale, Hongbo Li, Namjae Jeon, Sungjong Seo,
Yuezhang Mo, Theodore Ts'o, Andreas Dilger, Jaegeuk Kim,
OGAWA Hirofumi, Viacheslav Dubeyko, John Paul Adrian Glaubitz,
Yangtao Li, Richard Weinberger, Anton Ivanov, Johannes Berg,
Mikulas Patocka, David Woodhouse, Dave Kleikamp, Trond Myklebust,
Anna Schumaker, Ryusuke Konishi, Konstantin Komarov, Mark Fasheh,
Joel Becker, Joseph Qi, Bob Copeland, Mike Marshall,
Martin Brandenburg, Steve French, Paulo Alcantara,
Ronnie Sahlberg, Shyam Prasad N, Tom Talpey, Bharath SM,
Zhihao Cheng, Hans de Goede, Carlos Maiolino, Damien Le Moal,
Naohiro Aota, Johannes Thumshirn, Dan Williams, Matthew Wilcox,
Vlastimil Babka, Jann Horn, Pedro Falcato, linux-block,
linux-kernel, intel-gfx, dri-devel, v9fs, linux-fsdevel,
linux-afs, linux-aio, linux-unionfs, linux-bcachefs, linux-mm,
linux-btrfs, ceph-devel, codalist, ecryptfs, linux-erofs,
linux-ext4, linux-f2fs-devel, linux-um, linux-mtd, jfs-discussion,
linux-nfs, linux-nilfs, ntfs3, ocfs2-devel, linux-karma-devel,
devel, linux-cifs, samba-technical, linux-xfs, nvdimm
On Tue, Jun 17, 2025 at 06:25:34AM +0100, Lorenzo Stoakes wrote:
> > > Most notably, this updates the elf logic to allow for the ability to
> > > execute binaries on filesystems which have the .mmap_prepare hook, but
> > > additionally we update nested filesystems.
> >
> > Can you please give the function a better name before spreading it?
> > file operations aren't hooks by any classic definition.
> >
>
> can_mmap_file()?
Sounds reasonable.
^ permalink raw reply [flat|nested] 50+ messages in thread
* Re: [PATCH 01/10] mm: rename call_mmap/mmap_prepare to vfs_mmap/mmap_prepare
2025-06-17 5:10 ` Christoph Hellwig
@ 2025-06-17 5:29 ` Lorenzo Stoakes
0 siblings, 0 replies; 50+ messages in thread
From: Lorenzo Stoakes @ 2025-06-17 5:29 UTC (permalink / raw)
To: Christoph Hellwig
Cc: Andrew Morton, Liam R . Howlett, Jens Axboe, Jani Nikula,
Joonas Lahtinen, Rodrigo Vivi, Tvrtko Ursulin, David Airlie,
Simona Vetter, Eric Van Hensbergen, Latchesar Ionkov,
Dominique Martinet, Christian Schoenebeck, David Sterba,
David Howells, Marc Dionne, Alexander Viro, Christian Brauner,
Jan Kara, Benjamin LaHaise, Miklos Szeredi, Amir Goldstein,
Kent Overstreet, Tigran A . Aivazian, Kees Cook, Chris Mason,
Josef Bacik, Xiubo Li, Ilya Dryomov, Jan Harkes, coda,
Tyler Hicks, Gao Xiang, Chao Yu, Yue Hu, Jeffle Xu,
Sandeep Dhavale, Hongbo Li, Namjae Jeon, Sungjong Seo,
Yuezhang Mo, Theodore Ts'o, Andreas Dilger, Jaegeuk Kim,
OGAWA Hirofumi, Viacheslav Dubeyko, John Paul Adrian Glaubitz,
Yangtao Li, Richard Weinberger, Anton Ivanov, Johannes Berg,
Mikulas Patocka, David Woodhouse, Dave Kleikamp, Trond Myklebust,
Anna Schumaker, Ryusuke Konishi, Konstantin Komarov, Mark Fasheh,
Joel Becker, Joseph Qi, Bob Copeland, Mike Marshall,
Martin Brandenburg, Steve French, Paulo Alcantara,
Ronnie Sahlberg, Shyam Prasad N, Tom Talpey, Bharath SM,
Zhihao Cheng, Hans de Goede, Carlos Maiolino, Damien Le Moal,
Naohiro Aota, Johannes Thumshirn, Dan Williams, Matthew Wilcox,
Vlastimil Babka, Jann Horn, Pedro Falcato, linux-block,
linux-kernel, intel-gfx, dri-devel, v9fs, linux-fsdevel,
linux-afs, linux-aio, linux-unionfs, linux-bcachefs, linux-mm,
linux-btrfs, ceph-devel, codalist, ecryptfs, linux-erofs,
linux-ext4, linux-f2fs-devel, linux-um, linux-mtd, jfs-discussion,
linux-nfs, linux-nilfs, ntfs3, ocfs2-devel, linux-karma-devel,
devel, linux-cifs, samba-technical, linux-xfs, nvdimm
On Mon, Jun 16, 2025 at 10:10:30PM -0700, Christoph Hellwig wrote:
> On Mon, Jun 16, 2025 at 08:33:20PM +0100, Lorenzo Stoakes wrote:
> > The call_mmap() function violates the existing convention in
> > include/linux/fs.h whereby invocations of virtual file system hooks is
> > performed by functions prefixed with vfs_xxx().
> >
> > Correct this by renaming call_mmap() to vfs_mmap(). This also avoids
> > confusion as to the fact that f_op->mmap_prepare may be invoked here.
> >
> > Also rename __call_mmap_prepare() function to vfs_mmap_prepare() and adjust
> > to accept a file parameter, this is useful later for nested file systems.
> >
> > Finally, fix up the VMA userland tests and ensure the mmap_prepare -> mmap
> > shim is implemented there.
>
> Can we please just kill these silly call_* helpers instead?
The vfs_mmap() function now has some actual meaningful logic added in
commit bb666b7c2707 ("mm: add mmap_prepare() compatibility layer for nested
file systems").
>
>
> ______________________________________________________
> Linux MTD discussion mailing list
> http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply [flat|nested] 50+ messages in thread
* Re: [PATCH 02/10] mm/nommu: use file_has_valid_mmap_hooks() helper
2025-06-16 19:33 ` [PATCH 02/10] mm/nommu: use file_has_valid_mmap_hooks() helper Lorenzo Stoakes
@ 2025-06-17 10:05 ` Jan Kara
2025-06-17 18:58 ` Vlastimil Babka
1 sibling, 0 replies; 50+ messages in thread
From: Jan Kara @ 2025-06-17 10:05 UTC (permalink / raw)
To: Lorenzo Stoakes
Cc: Andrew Morton, Liam R . Howlett, Jens Axboe, Jani Nikula,
Joonas Lahtinen, Rodrigo Vivi, Tvrtko Ursulin, David Airlie,
Simona Vetter, Eric Van Hensbergen, Latchesar Ionkov,
Dominique Martinet, Christian Schoenebeck, David Sterba,
David Howells, Marc Dionne, Alexander Viro, Christian Brauner,
Jan Kara, Benjamin LaHaise, Miklos Szeredi, Amir Goldstein,
Kent Overstreet, Tigran A . Aivazian, Kees Cook, Chris Mason,
Josef Bacik, Xiubo Li, Ilya Dryomov, Jan Harkes, coda,
Tyler Hicks, Gao Xiang, Chao Yu, Yue Hu, Jeffle Xu,
Sandeep Dhavale, Hongbo Li, Namjae Jeon, Sungjong Seo,
Yuezhang Mo, Theodore Ts'o, Andreas Dilger, Jaegeuk Kim,
OGAWA Hirofumi, Viacheslav Dubeyko, John Paul Adrian Glaubitz,
Yangtao Li, Richard Weinberger, Anton Ivanov, Johannes Berg,
Mikulas Patocka, David Woodhouse, Dave Kleikamp, Trond Myklebust,
Anna Schumaker, Ryusuke Konishi, Konstantin Komarov, Mark Fasheh,
Joel Becker, Joseph Qi, Bob Copeland, Mike Marshall,
Martin Brandenburg, Steve French, Paulo Alcantara,
Ronnie Sahlberg, Shyam Prasad N, Tom Talpey, Bharath SM,
Zhihao Cheng, Hans de Goede, Carlos Maiolino, Damien Le Moal,
Naohiro Aota, Johannes Thumshirn, Dan Williams, Matthew Wilcox,
Vlastimil Babka, Jann Horn, Pedro Falcato, linux-block,
linux-kernel, intel-gfx, dri-devel, v9fs, linux-fsdevel,
linux-afs, linux-aio, linux-unionfs, linux-bcachefs, linux-mm,
linux-btrfs, ceph-devel, codalist, ecryptfs, linux-erofs,
linux-ext4, linux-f2fs-devel, linux-um, linux-mtd, jfs-discussion,
linux-nfs, linux-nilfs, ntfs3, ocfs2-devel, linux-karma-devel,
devel, linux-cifs, samba-technical, linux-xfs, nvdimm
On Mon 16-06-25 20:33:21, Lorenzo Stoakes wrote:
> Since commit c84bf6dd2b83 ("mm: introduce new .mmap_prepare() file
> callback"), the f_op->mmap() hook has been deprecated in favour of
> f_op->mmap_prepare().
>
> Therefore, update the check for file operations supporting mmap() by using
> the file_has_valid_mmap_hooks() helper function, which checks for either
> f_op->mmap or f_op->mmap_prepare rather than checking only for f_op->mmap
> directly.
>
> Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Looks good. Feel free to add:
Reviewed-by: Jan Kara <jack@suse.cz>
Maybe Fixes tag would be appropriate here?
Honza
> ---
> mm/nommu.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/mm/nommu.c b/mm/nommu.c
> index b624acec6d2e..38c22ea0a95c 100644
> --- a/mm/nommu.c
> +++ b/mm/nommu.c
> @@ -719,7 +719,7 @@ static int validate_mmap_request(struct file *file,
>
> if (file) {
> /* files must support mmap */
> - if (!file->f_op->mmap)
> + if (!file_has_valid_mmap_hooks(file))
> return -ENODEV;
>
> /* work out if what we've got could possibly be shared
> --
> 2.49.0
>
--
Jan Kara <jack@suse.com>
SUSE Labs, CR
^ permalink raw reply [flat|nested] 50+ messages in thread
* Re: [PATCH 03/10] fs: consistently use file_has_valid_mmap_hooks() helper
2025-06-17 5:25 ` Lorenzo Stoakes
2025-06-17 5:29 ` Christoph Hellwig
@ 2025-06-17 10:08 ` Jan Kara
2025-06-17 11:48 ` Christian Brauner
1 sibling, 1 reply; 50+ messages in thread
From: Jan Kara @ 2025-06-17 10:08 UTC (permalink / raw)
To: Lorenzo Stoakes
Cc: Christoph Hellwig, Andrew Morton, Liam R . Howlett, Jens Axboe,
Jani Nikula, Joonas Lahtinen, Rodrigo Vivi, Tvrtko Ursulin,
David Airlie, Simona Vetter, Eric Van Hensbergen,
Latchesar Ionkov, Dominique Martinet, Christian Schoenebeck,
David Sterba, David Howells, Marc Dionne, Alexander Viro,
Christian Brauner, Jan Kara, Benjamin LaHaise, Miklos Szeredi,
Amir Goldstein, Kent Overstreet, Tigran A . Aivazian, Kees Cook,
Chris Mason, Josef Bacik, Xiubo Li, Ilya Dryomov, Jan Harkes,
coda, Tyler Hicks, Gao Xiang, Chao Yu, Yue Hu, Jeffle Xu,
Sandeep Dhavale, Hongbo Li, Namjae Jeon, Sungjong Seo,
Yuezhang Mo, Theodore Ts'o, Andreas Dilger, Jaegeuk Kim,
OGAWA Hirofumi, Viacheslav Dubeyko, John Paul Adrian Glaubitz,
Yangtao Li, Richard Weinberger, Anton Ivanov, Johannes Berg,
Mikulas Patocka, David Woodhouse, Dave Kleikamp, Trond Myklebust,
Anna Schumaker, Ryusuke Konishi, Konstantin Komarov, Mark Fasheh,
Joel Becker, Joseph Qi, Bob Copeland, Mike Marshall,
Martin Brandenburg, Steve French, Paulo Alcantara,
Ronnie Sahlberg, Shyam Prasad N, Tom Talpey, Bharath SM,
Zhihao Cheng, Hans de Goede, Carlos Maiolino, Damien Le Moal,
Naohiro Aota, Johannes Thumshirn, Dan Williams, Matthew Wilcox,
Vlastimil Babka, Jann Horn, Pedro Falcato, linux-block,
linux-kernel, intel-gfx, dri-devel, v9fs, linux-fsdevel,
linux-afs, linux-aio, linux-unionfs, linux-bcachefs, linux-mm,
linux-btrfs, ceph-devel, codalist, ecryptfs, linux-erofs,
linux-ext4, linux-f2fs-devel, linux-um, linux-mtd, jfs-discussion,
linux-nfs, linux-nilfs, ntfs3, ocfs2-devel, linux-karma-devel,
devel, linux-cifs, samba-technical, linux-xfs, nvdimm
On Tue 17-06-25 06:25:34, Lorenzo Stoakes wrote:
> On Mon, Jun 16, 2025 at 10:11:28PM -0700, Christoph Hellwig wrote:
> > On Mon, Jun 16, 2025 at 08:33:22PM +0100, Lorenzo Stoakes wrote:
> > > Since commit c84bf6dd2b83 ("mm: introduce new .mmap_prepare() file
> > > callback"), the f_op->mmap() hook has been deprecated in favour of
> > > f_op->mmap_prepare().
> > >
> > > Additionally, commit bb666b7c2707 ("mm: add mmap_prepare() compatibility
> > > layer for nested file systems") permits the use of the .mmap_prepare() hook
> > > even in nested filesystems like overlayfs.
> > >
> > > There are a number of places where we check only for f_op->mmap - this is
> > > incorrect now mmap_prepare exists, so update all of these to use the
> > > general helper file_has_valid_mmap_hooks().
> > >
> > > Most notably, this updates the elf logic to allow for the ability to
> > > execute binaries on filesystems which have the .mmap_prepare hook, but
> > > additionally we update nested filesystems.
> >
> > Can you please give the function a better name before spreading it?
> > file operations aren't hooks by any classic definition.
> >
>
> can_mmap_file()?
I like this name more as well :). With this patch looks good to me. Again a
note that Fixes tag would be probably appropriate for this patch...
Honza
--
Jan Kara <jack@suse.com>
SUSE Labs, CR
^ permalink raw reply [flat|nested] 50+ messages in thread
* Re: [PATCH 05/10] fs/ext4: transition from deprecated .mmap hook to .mmap_prepare
2025-06-16 19:33 ` [PATCH 05/10] fs/ext4: transition from deprecated .mmap hook to .mmap_prepare Lorenzo Stoakes
@ 2025-06-17 10:11 ` Jan Kara
0 siblings, 0 replies; 50+ messages in thread
From: Jan Kara @ 2025-06-17 10:11 UTC (permalink / raw)
To: Lorenzo Stoakes
Cc: Andrew Morton, Liam R . Howlett, Jens Axboe, Jani Nikula,
Joonas Lahtinen, Rodrigo Vivi, Tvrtko Ursulin, David Airlie,
Simona Vetter, Eric Van Hensbergen, Latchesar Ionkov,
Dominique Martinet, Christian Schoenebeck, David Sterba,
David Howells, Marc Dionne, Alexander Viro, Christian Brauner,
Jan Kara, Benjamin LaHaise, Miklos Szeredi, Amir Goldstein,
Kent Overstreet, Tigran A . Aivazian, Kees Cook, Chris Mason,
Josef Bacik, Xiubo Li, Ilya Dryomov, Jan Harkes, coda,
Tyler Hicks, Gao Xiang, Chao Yu, Yue Hu, Jeffle Xu,
Sandeep Dhavale, Hongbo Li, Namjae Jeon, Sungjong Seo,
Yuezhang Mo, Theodore Ts'o, Andreas Dilger, Jaegeuk Kim,
OGAWA Hirofumi, Viacheslav Dubeyko, John Paul Adrian Glaubitz,
Yangtao Li, Richard Weinberger, Anton Ivanov, Johannes Berg,
Mikulas Patocka, David Woodhouse, Dave Kleikamp, Trond Myklebust,
Anna Schumaker, Ryusuke Konishi, Konstantin Komarov, Mark Fasheh,
Joel Becker, Joseph Qi, Bob Copeland, Mike Marshall,
Martin Brandenburg, Steve French, Paulo Alcantara,
Ronnie Sahlberg, Shyam Prasad N, Tom Talpey, Bharath SM,
Zhihao Cheng, Hans de Goede, Carlos Maiolino, Damien Le Moal,
Naohiro Aota, Johannes Thumshirn, Dan Williams, Matthew Wilcox,
Vlastimil Babka, Jann Horn, Pedro Falcato, linux-block,
linux-kernel, intel-gfx, dri-devel, v9fs, linux-fsdevel,
linux-afs, linux-aio, linux-unionfs, linux-bcachefs, linux-mm,
linux-btrfs, ceph-devel, codalist, ecryptfs, linux-erofs,
linux-ext4, linux-f2fs-devel, linux-um, linux-mtd, jfs-discussion,
linux-nfs, linux-nilfs, ntfs3, ocfs2-devel, linux-karma-devel,
devel, linux-cifs, samba-technical, linux-xfs, nvdimm
On Mon 16-06-25 20:33:24, Lorenzo Stoakes wrote:
> Since commit c84bf6dd2b83 ("mm: introduce new .mmap_prepare() file
> callback"), the f_op->mmap() hook has been deprecated in favour of
> f_op->mmap_prepare().
>
> This callback is invoked in the mmap() logic far earlier, so error handling
> can be performed more safely without complicated and bug-prone state
> unwinding required should an error arise.
>
> This hook also avoids passing a pointer to a not-yet-correctly-established
> VMA avoiding any issues with referencing this data structure.
>
> It rather provides a pointer to the new struct vm_area_desc descriptor type
> which contains all required state and allows easy setting of required
> parameters without any consideration needing to be paid to locking or
> reference counts.
>
> Note that nested filesystems like overlayfs are compatible with an
> .mmap_prepare() callback since commit bb666b7c2707 ("mm: add mmap_prepare()
> compatibility layer for nested file systems").
>
> Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Looks good. Feel free to add:
Reviewed-by: Jan Kara <jack@suse.cz>
Honza
> ---
> fs/ext4/file.c | 13 +++++++------
> 1 file changed, 7 insertions(+), 6 deletions(-)
>
> diff --git a/fs/ext4/file.c b/fs/ext4/file.c
> index 08a814fcd956..38180e527dbe 100644
> --- a/fs/ext4/file.c
> +++ b/fs/ext4/file.c
> @@ -804,9 +804,10 @@ static const struct vm_operations_struct ext4_file_vm_ops = {
> .page_mkwrite = ext4_page_mkwrite,
> };
>
> -static int ext4_file_mmap(struct file *file, struct vm_area_struct *vma)
> +static int ext4_file_mmap_prepare(struct vm_area_desc *desc)
> {
> int ret;
> + struct file *file = desc->file;
> struct inode *inode = file->f_mapping->host;
> struct dax_device *dax_dev = EXT4_SB(inode->i_sb)->s_daxdev;
>
> @@ -821,15 +822,15 @@ static int ext4_file_mmap(struct file *file, struct vm_area_struct *vma)
> * We don't support synchronous mappings for non-DAX files and
> * for DAX files if underneath dax_device is not synchronous.
> */
> - if (!daxdev_mapping_supported(vma->vm_flags, vma->vm_file, dax_dev))
> + if (!daxdev_mapping_supported(desc->vm_flags, file, dax_dev))
> return -EOPNOTSUPP;
>
> file_accessed(file);
> if (IS_DAX(file_inode(file))) {
> - vma->vm_ops = &ext4_dax_vm_ops;
> - vm_flags_set(vma, VM_HUGEPAGE);
> + desc->vm_ops = &ext4_dax_vm_ops;
> + desc->vm_flags |= VM_HUGEPAGE;
> } else {
> - vma->vm_ops = &ext4_file_vm_ops;
> + desc->vm_ops = &ext4_file_vm_ops;
> }
> return 0;
> }
> @@ -968,7 +969,7 @@ const struct file_operations ext4_file_operations = {
> #ifdef CONFIG_COMPAT
> .compat_ioctl = ext4_compat_ioctl,
> #endif
> - .mmap = ext4_file_mmap,
> + .mmap_prepare = ext4_file_mmap_prepare,
> .open = ext4_file_open,
> .release = ext4_release_file,
> .fsync = ext4_sync_file,
> --
> 2.49.0
>
--
Jan Kara <jack@suse.com>
SUSE Labs, CR
^ permalink raw reply [flat|nested] 50+ messages in thread
* Re: [PATCH 07/10] mm/filemap: introduce generic_file_*_mmap_prepare() helpers
2025-06-16 19:33 ` [PATCH 07/10] mm/filemap: introduce generic_file_*_mmap_prepare() helpers Lorenzo Stoakes
@ 2025-06-17 10:12 ` Jan Kara
2025-06-17 19:00 ` Vlastimil Babka
1 sibling, 0 replies; 50+ messages in thread
From: Jan Kara @ 2025-06-17 10:12 UTC (permalink / raw)
To: Lorenzo Stoakes
Cc: Andrew Morton, Liam R . Howlett, Jens Axboe, Jani Nikula,
Joonas Lahtinen, Rodrigo Vivi, Tvrtko Ursulin, David Airlie,
Simona Vetter, Eric Van Hensbergen, Latchesar Ionkov,
Dominique Martinet, Christian Schoenebeck, David Sterba,
David Howells, Marc Dionne, Alexander Viro, Christian Brauner,
Jan Kara, Benjamin LaHaise, Miklos Szeredi, Amir Goldstein,
Kent Overstreet, Tigran A . Aivazian, Kees Cook, Chris Mason,
Josef Bacik, Xiubo Li, Ilya Dryomov, Jan Harkes, coda,
Tyler Hicks, Gao Xiang, Chao Yu, Yue Hu, Jeffle Xu,
Sandeep Dhavale, Hongbo Li, Namjae Jeon, Sungjong Seo,
Yuezhang Mo, Theodore Ts'o, Andreas Dilger, Jaegeuk Kim,
OGAWA Hirofumi, Viacheslav Dubeyko, John Paul Adrian Glaubitz,
Yangtao Li, Richard Weinberger, Anton Ivanov, Johannes Berg,
Mikulas Patocka, David Woodhouse, Dave Kleikamp, Trond Myklebust,
Anna Schumaker, Ryusuke Konishi, Konstantin Komarov, Mark Fasheh,
Joel Becker, Joseph Qi, Bob Copeland, Mike Marshall,
Martin Brandenburg, Steve French, Paulo Alcantara,
Ronnie Sahlberg, Shyam Prasad N, Tom Talpey, Bharath SM,
Zhihao Cheng, Hans de Goede, Carlos Maiolino, Damien Le Moal,
Naohiro Aota, Johannes Thumshirn, Dan Williams, Matthew Wilcox,
Vlastimil Babka, Jann Horn, Pedro Falcato, linux-block,
linux-kernel, intel-gfx, dri-devel, v9fs, linux-fsdevel,
linux-afs, linux-aio, linux-unionfs, linux-bcachefs, linux-mm,
linux-btrfs, ceph-devel, codalist, ecryptfs, linux-erofs,
linux-ext4, linux-f2fs-devel, linux-um, linux-mtd, jfs-discussion,
linux-nfs, linux-nilfs, ntfs3, ocfs2-devel, linux-karma-devel,
devel, linux-cifs, samba-technical, linux-xfs, nvdimm
On Mon 16-06-25 20:33:26, Lorenzo Stoakes wrote:
> Since commit c84bf6dd2b83 ("mm: introduce new .mmap_prepare() file
> callback"), the f_op->mmap() hook has been deprecated in favour of
> f_op->mmap_prepare().
>
> The generic mmap handlers are very simple, so we can very easily convert
> these in advance of converting file systems which use them.
>
> This patch does so.
>
> Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Looks good. Feel free to add:
Reviewed-by: Jan Kara <jack@suse.cz>
Honza
> ---
> include/linux/fs.h | 6 ++++--
> mm/filemap.c | 29 +++++++++++++++++++++++++++++
> 2 files changed, 33 insertions(+), 2 deletions(-)
>
> diff --git a/include/linux/fs.h b/include/linux/fs.h
> index 7120f80255b3..65cffc445fcc 100644
> --- a/include/linux/fs.h
> +++ b/include/linux/fs.h
> @@ -3395,8 +3395,10 @@ extern void inode_add_lru(struct inode *inode);
> extern int sb_set_blocksize(struct super_block *, int);
> extern int sb_min_blocksize(struct super_block *, int);
>
> -extern int generic_file_mmap(struct file *, struct vm_area_struct *);
> -extern int generic_file_readonly_mmap(struct file *, struct vm_area_struct *);
> +int generic_file_mmap(struct file *, struct vm_area_struct *);
> +int generic_file_mmap_prepare(struct vm_area_desc *desc);
> +int generic_file_readonly_mmap(struct file *, struct vm_area_struct *);
> +int generic_file_readonly_mmap_prepare(struct vm_area_desc *desc);
> extern ssize_t generic_write_checks(struct kiocb *, struct iov_iter *);
> int generic_write_checks_count(struct kiocb *iocb, loff_t *count);
> extern int generic_write_check_limits(struct file *file, loff_t pos,
> diff --git a/mm/filemap.c b/mm/filemap.c
> index 93fbc2ef232a..e75608cbf420 100644
> --- a/mm/filemap.c
> +++ b/mm/filemap.c
> @@ -3847,6 +3847,18 @@ int generic_file_mmap(struct file *file, struct vm_area_struct *vma)
> return 0;
> }
>
> +int generic_file_mmap_prepare(struct vm_area_desc *desc)
> +{
> + struct file *file = desc->file;
> + struct address_space *mapping = file->f_mapping;
> +
> + if (!mapping->a_ops->read_folio)
> + return -ENOEXEC;
> + file_accessed(file);
> + desc->vm_ops = &generic_file_vm_ops;
> + return 0;
> +}
> +
> /*
> * This is for filesystems which do not implement ->writepage.
> */
> @@ -3856,6 +3868,13 @@ int generic_file_readonly_mmap(struct file *file, struct vm_area_struct *vma)
> return -EINVAL;
> return generic_file_mmap(file, vma);
> }
> +
> +int generic_file_readonly_mmap_prepare(struct vm_area_desc *desc)
> +{
> + if (is_shared_maywrite(desc->vm_flags))
> + return -EINVAL;
> + return generic_file_mmap_prepare(desc);
> +}
> #else
> vm_fault_t filemap_page_mkwrite(struct vm_fault *vmf)
> {
> @@ -3865,15 +3884,25 @@ int generic_file_mmap(struct file *file, struct vm_area_struct *vma)
> {
> return -ENOSYS;
> }
> +int generic_file_mmap_prepare(struct vm_area_desc *desc)
> +{
> + return -ENOSYS;
> +}
> int generic_file_readonly_mmap(struct file *file, struct vm_area_struct *vma)
> {
> return -ENOSYS;
> }
> +int generic_file_readonly_mmap_prepare(struct vm_area_desc *desc)
> +{
> + return -ENOSYS;
> +}
> #endif /* CONFIG_MMU */
>
> EXPORT_SYMBOL(filemap_page_mkwrite);
> EXPORT_SYMBOL(generic_file_mmap);
> +EXPORT_SYMBOL(generic_file_mmap_prepare);
> EXPORT_SYMBOL(generic_file_readonly_mmap);
> +EXPORT_SYMBOL(generic_file_readonly_mmap_prepare);
>
> static struct folio *do_read_cache_folio(struct address_space *mapping,
> pgoff_t index, filler_t filler, struct file *file, gfp_t gfp)
> --
> 2.49.0
>
--
Jan Kara <jack@suse.com>
SUSE Labs, CR
^ permalink raw reply [flat|nested] 50+ messages in thread
* Re: [PATCH 08/10] fs: convert simple use of generic_file_*_mmap() to .mmap_prepare()
2025-06-16 19:33 ` [PATCH 08/10] fs: convert simple use of generic_file_*_mmap() to .mmap_prepare() Lorenzo Stoakes
2025-06-16 23:26 ` Viacheslav Dubeyko
@ 2025-06-17 10:14 ` Jan Kara
2025-06-17 14:07 ` Dave Kleikamp
2 siblings, 0 replies; 50+ messages in thread
From: Jan Kara @ 2025-06-17 10:14 UTC (permalink / raw)
To: Lorenzo Stoakes
Cc: Andrew Morton, Liam R . Howlett, Jens Axboe, Jani Nikula,
Joonas Lahtinen, Rodrigo Vivi, Tvrtko Ursulin, David Airlie,
Simona Vetter, Eric Van Hensbergen, Latchesar Ionkov,
Dominique Martinet, Christian Schoenebeck, David Sterba,
David Howells, Marc Dionne, Alexander Viro, Christian Brauner,
Jan Kara, Benjamin LaHaise, Miklos Szeredi, Amir Goldstein,
Kent Overstreet, Tigran A . Aivazian, Kees Cook, Chris Mason,
Josef Bacik, Xiubo Li, Ilya Dryomov, Jan Harkes, coda,
Tyler Hicks, Gao Xiang, Chao Yu, Yue Hu, Jeffle Xu,
Sandeep Dhavale, Hongbo Li, Namjae Jeon, Sungjong Seo,
Yuezhang Mo, Theodore Ts'o, Andreas Dilger, Jaegeuk Kim,
OGAWA Hirofumi, Viacheslav Dubeyko, John Paul Adrian Glaubitz,
Yangtao Li, Richard Weinberger, Anton Ivanov, Johannes Berg,
Mikulas Patocka, David Woodhouse, Dave Kleikamp, Trond Myklebust,
Anna Schumaker, Ryusuke Konishi, Konstantin Komarov, Mark Fasheh,
Joel Becker, Joseph Qi, Bob Copeland, Mike Marshall,
Martin Brandenburg, Steve French, Paulo Alcantara,
Ronnie Sahlberg, Shyam Prasad N, Tom Talpey, Bharath SM,
Zhihao Cheng, Hans de Goede, Carlos Maiolino, Damien Le Moal,
Naohiro Aota, Johannes Thumshirn, Dan Williams, Matthew Wilcox,
Vlastimil Babka, Jann Horn, Pedro Falcato, linux-block,
linux-kernel, intel-gfx, dri-devel, v9fs, linux-fsdevel,
linux-afs, linux-aio, linux-unionfs, linux-bcachefs, linux-mm,
linux-btrfs, ceph-devel, codalist, ecryptfs, linux-erofs,
linux-ext4, linux-f2fs-devel, linux-um, linux-mtd, jfs-discussion,
linux-nfs, linux-nilfs, ntfs3, ocfs2-devel, linux-karma-devel,
devel, linux-cifs, samba-technical, linux-xfs, nvdimm
On Mon 16-06-25 20:33:27, Lorenzo Stoakes wrote:
> Since commit c84bf6dd2b83 ("mm: introduce new .mmap_prepare() file
> callback"), the f_op->mmap() hook has been deprecated in favour of
> f_op->mmap_prepare().
>
> We have provided generic .mmap_prepare() equivalents, so update all file
> systems that specify these directly in their file_operations structures.
>
> This updates 9p, adfs, affs, bfs, fat, hfs, hfsplus, hostfs, hpfs, jffs2,
> jfs, minix, omfs, ramfs and ufs file systems directly.
>
> It updates generic_ro_fops which impacts qnx4, cramfs, befs, squashfs,
> frebxfs, qnx6, efs, romfs, erofs and isofs file systems.
>
> There are remaining file systems which use generic hooks in a less direct
> way which we address in a subsequent commit.
>
> Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Looks good. Feel free to add:
Reviewed-by: Jan Kara <jack@suse.cz>
Honza
> ---
> fs/9p/vfs_file.c | 2 +-
> fs/adfs/file.c | 2 +-
> fs/affs/file.c | 2 +-
> fs/bfs/file.c | 2 +-
> fs/fat/file.c | 2 +-
> fs/hfs/inode.c | 2 +-
> fs/hfsplus/inode.c | 2 +-
> fs/hostfs/hostfs_kern.c | 2 +-
> fs/hpfs/file.c | 2 +-
> fs/jffs2/file.c | 2 +-
> fs/jfs/file.c | 2 +-
> fs/minix/file.c | 2 +-
> fs/omfs/file.c | 2 +-
> fs/ramfs/file-mmu.c | 2 +-
> fs/read_write.c | 2 +-
> fs/ufs/file.c | 2 +-
> 16 files changed, 16 insertions(+), 16 deletions(-)
>
> diff --git a/fs/9p/vfs_file.c b/fs/9p/vfs_file.c
> index 348cc90bf9c5..2ff3e0ac7266 100644
> --- a/fs/9p/vfs_file.c
> +++ b/fs/9p/vfs_file.c
> @@ -516,7 +516,7 @@ const struct file_operations v9fs_file_operations = {
> .open = v9fs_file_open,
> .release = v9fs_dir_release,
> .lock = v9fs_file_lock,
> - .mmap = generic_file_readonly_mmap,
> + .mmap_prepare = generic_file_readonly_mmap_prepare,
> .splice_read = v9fs_file_splice_read,
> .splice_write = iter_file_splice_write,
> .fsync = v9fs_file_fsync,
> diff --git a/fs/adfs/file.c b/fs/adfs/file.c
> index ee80718aaeec..cd13165fd904 100644
> --- a/fs/adfs/file.c
> +++ b/fs/adfs/file.c
> @@ -25,7 +25,7 @@
> const struct file_operations adfs_file_operations = {
> .llseek = generic_file_llseek,
> .read_iter = generic_file_read_iter,
> - .mmap = generic_file_mmap,
> + .mmap_prepare = generic_file_mmap_prepare,
> .fsync = generic_file_fsync,
> .write_iter = generic_file_write_iter,
> .splice_read = filemap_splice_read,
> diff --git a/fs/affs/file.c b/fs/affs/file.c
> index 7a71018e3f67..fbac204b7055 100644
> --- a/fs/affs/file.c
> +++ b/fs/affs/file.c
> @@ -999,7 +999,7 @@ const struct file_operations affs_file_operations = {
> .llseek = generic_file_llseek,
> .read_iter = generic_file_read_iter,
> .write_iter = generic_file_write_iter,
> - .mmap = generic_file_mmap,
> + .mmap_prepare = generic_file_mmap_prepare,
> .open = affs_file_open,
> .release = affs_file_release,
> .fsync = affs_file_fsync,
> diff --git a/fs/bfs/file.c b/fs/bfs/file.c
> index fa66a09e496a..6685c3411fe7 100644
> --- a/fs/bfs/file.c
> +++ b/fs/bfs/file.c
> @@ -27,7 +27,7 @@ const struct file_operations bfs_file_operations = {
> .llseek = generic_file_llseek,
> .read_iter = generic_file_read_iter,
> .write_iter = generic_file_write_iter,
> - .mmap = generic_file_mmap,
> + .mmap_prepare = generic_file_mmap_prepare,
> .splice_read = filemap_splice_read,
> };
>
> diff --git a/fs/fat/file.c b/fs/fat/file.c
> index e887e9ab7472..4fc49a614fb8 100644
> --- a/fs/fat/file.c
> +++ b/fs/fat/file.c
> @@ -204,7 +204,7 @@ const struct file_operations fat_file_operations = {
> .llseek = generic_file_llseek,
> .read_iter = generic_file_read_iter,
> .write_iter = generic_file_write_iter,
> - .mmap = generic_file_mmap,
> + .mmap_prepare = generic_file_mmap_prepare,
> .release = fat_file_release,
> .unlocked_ioctl = fat_generic_ioctl,
> .compat_ioctl = compat_ptr_ioctl,
> diff --git a/fs/hfs/inode.c b/fs/hfs/inode.c
> index a81ce7a740b9..d419586d668d 100644
> --- a/fs/hfs/inode.c
> +++ b/fs/hfs/inode.c
> @@ -690,7 +690,7 @@ static const struct file_operations hfs_file_operations = {
> .llseek = generic_file_llseek,
> .read_iter = generic_file_read_iter,
> .write_iter = generic_file_write_iter,
> - .mmap = generic_file_mmap,
> + .mmap_prepare = generic_file_mmap_prepare,
> .splice_read = filemap_splice_read,
> .fsync = hfs_file_fsync,
> .open = hfs_file_open,
> diff --git a/fs/hfsplus/inode.c b/fs/hfsplus/inode.c
> index f331e9574217..0af7e302730c 100644
> --- a/fs/hfsplus/inode.c
> +++ b/fs/hfsplus/inode.c
> @@ -366,7 +366,7 @@ static const struct file_operations hfsplus_file_operations = {
> .llseek = generic_file_llseek,
> .read_iter = generic_file_read_iter,
> .write_iter = generic_file_write_iter,
> - .mmap = generic_file_mmap,
> + .mmap_prepare = generic_file_mmap_prepare,
> .splice_read = filemap_splice_read,
> .fsync = hfsplus_file_fsync,
> .open = hfsplus_file_open,
> diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c
> index 702c41317589..bc22b6cc72af 100644
> --- a/fs/hostfs/hostfs_kern.c
> +++ b/fs/hostfs/hostfs_kern.c
> @@ -382,7 +382,7 @@ static const struct file_operations hostfs_file_fops = {
> .splice_write = iter_file_splice_write,
> .read_iter = generic_file_read_iter,
> .write_iter = generic_file_write_iter,
> - .mmap = generic_file_mmap,
> + .mmap_prepare = generic_file_mmap_prepare,
> .open = hostfs_open,
> .release = hostfs_file_release,
> .fsync = hostfs_fsync,
> diff --git a/fs/hpfs/file.c b/fs/hpfs/file.c
> index 449a3fc1b8d9..a1a44e3edb19 100644
> --- a/fs/hpfs/file.c
> +++ b/fs/hpfs/file.c
> @@ -255,7 +255,7 @@ const struct file_operations hpfs_file_ops =
> .llseek = generic_file_llseek,
> .read_iter = generic_file_read_iter,
> .write_iter = generic_file_write_iter,
> - .mmap = generic_file_mmap,
> + .mmap_prepare = generic_file_mmap_prepare,
> .release = hpfs_file_release,
> .fsync = hpfs_file_fsync,
> .splice_read = filemap_splice_read,
> diff --git a/fs/jffs2/file.c b/fs/jffs2/file.c
> index 13c18ccc13b0..1e05f7fe5dd4 100644
> --- a/fs/jffs2/file.c
> +++ b/fs/jffs2/file.c
> @@ -54,7 +54,7 @@ const struct file_operations jffs2_file_operations =
> .read_iter = generic_file_read_iter,
> .write_iter = generic_file_write_iter,
> .unlocked_ioctl=jffs2_ioctl,
> - .mmap = generic_file_readonly_mmap,
> + .mmap_prepare = generic_file_readonly_mmap_prepare,
> .fsync = jffs2_fsync,
> .splice_read = filemap_splice_read,
> .splice_write = iter_file_splice_write,
> diff --git a/fs/jfs/file.c b/fs/jfs/file.c
> index 01b6912e60f8..5e47951db630 100644
> --- a/fs/jfs/file.c
> +++ b/fs/jfs/file.c
> @@ -143,7 +143,7 @@ const struct file_operations jfs_file_operations = {
> .llseek = generic_file_llseek,
> .read_iter = generic_file_read_iter,
> .write_iter = generic_file_write_iter,
> - .mmap = generic_file_mmap,
> + .mmap_prepare = generic_file_mmap_prepare,
> .splice_read = filemap_splice_read,
> .splice_write = iter_file_splice_write,
> .fsync = jfs_fsync,
> diff --git a/fs/minix/file.c b/fs/minix/file.c
> index 906d192ab7f3..dca7ac71f049 100644
> --- a/fs/minix/file.c
> +++ b/fs/minix/file.c
> @@ -17,7 +17,7 @@ const struct file_operations minix_file_operations = {
> .llseek = generic_file_llseek,
> .read_iter = generic_file_read_iter,
> .write_iter = generic_file_write_iter,
> - .mmap = generic_file_mmap,
> + .mmap_prepare = generic_file_mmap_prepare,
> .fsync = generic_file_fsync,
> .splice_read = filemap_splice_read,
> };
> diff --git a/fs/omfs/file.c b/fs/omfs/file.c
> index 98358d405b6a..319c04e63964 100644
> --- a/fs/omfs/file.c
> +++ b/fs/omfs/file.c
> @@ -332,7 +332,7 @@ const struct file_operations omfs_file_operations = {
> .llseek = generic_file_llseek,
> .read_iter = generic_file_read_iter,
> .write_iter = generic_file_write_iter,
> - .mmap = generic_file_mmap,
> + .mmap_prepare = generic_file_mmap_prepare,
> .fsync = generic_file_fsync,
> .splice_read = filemap_splice_read,
> };
> diff --git a/fs/ramfs/file-mmu.c b/fs/ramfs/file-mmu.c
> index b45c7edc3225..b11f5b20b78b 100644
> --- a/fs/ramfs/file-mmu.c
> +++ b/fs/ramfs/file-mmu.c
> @@ -41,7 +41,7 @@ static unsigned long ramfs_mmu_get_unmapped_area(struct file *file,
> const struct file_operations ramfs_file_operations = {
> .read_iter = generic_file_read_iter,
> .write_iter = generic_file_write_iter,
> - .mmap = generic_file_mmap,
> + .mmap_prepare = generic_file_mmap_prepare,
> .fsync = noop_fsync,
> .splice_read = filemap_splice_read,
> .splice_write = iter_file_splice_write,
> diff --git a/fs/read_write.c b/fs/read_write.c
> index 0ef70e128c4a..80fdab99f9e4 100644
> --- a/fs/read_write.c
> +++ b/fs/read_write.c
> @@ -28,7 +28,7 @@
> const struct file_operations generic_ro_fops = {
> .llseek = generic_file_llseek,
> .read_iter = generic_file_read_iter,
> - .mmap = generic_file_readonly_mmap,
> + .mmap_prepare = generic_file_readonly_mmap_prepare,
> .splice_read = filemap_splice_read,
> };
>
> diff --git a/fs/ufs/file.c b/fs/ufs/file.c
> index 487ad1fc2de6..c2a391c17df7 100644
> --- a/fs/ufs/file.c
> +++ b/fs/ufs/file.c
> @@ -38,7 +38,7 @@ const struct file_operations ufs_file_operations = {
> .llseek = generic_file_llseek,
> .read_iter = generic_file_read_iter,
> .write_iter = generic_file_write_iter,
> - .mmap = generic_file_mmap,
> + .mmap_prepare = generic_file_mmap_prepare,
> .open = generic_file_open,
> .fsync = generic_file_fsync,
> .splice_read = filemap_splice_read,
> --
> 2.49.0
>
--
Jan Kara <jack@suse.com>
SUSE Labs, CR
^ permalink raw reply [flat|nested] 50+ messages in thread
* Re: [PATCH 09/10] fs: convert most other generic_file_*mmap() users to .mmap_prepare()
2025-06-16 19:33 ` [PATCH 09/10] fs: convert most other generic_file_*mmap() users " Lorenzo Stoakes
@ 2025-06-17 10:23 ` Jan Kara
2025-06-17 11:54 ` Christian Brauner
0 siblings, 1 reply; 50+ messages in thread
From: Jan Kara @ 2025-06-17 10:23 UTC (permalink / raw)
To: Lorenzo Stoakes
Cc: Andrew Morton, Liam R . Howlett, Jens Axboe, Jani Nikula,
Joonas Lahtinen, Rodrigo Vivi, Tvrtko Ursulin, David Airlie,
Simona Vetter, Eric Van Hensbergen, Latchesar Ionkov,
Dominique Martinet, Christian Schoenebeck, David Sterba,
David Howells, Marc Dionne, Alexander Viro, Christian Brauner,
Jan Kara, Benjamin LaHaise, Miklos Szeredi, Amir Goldstein,
Kent Overstreet, Tigran A . Aivazian, Kees Cook, Chris Mason,
Josef Bacik, Xiubo Li, Ilya Dryomov, Jan Harkes, coda,
Tyler Hicks, Gao Xiang, Chao Yu, Yue Hu, Jeffle Xu,
Sandeep Dhavale, Hongbo Li, Namjae Jeon, Sungjong Seo,
Yuezhang Mo, Theodore Ts'o, Andreas Dilger, Jaegeuk Kim,
OGAWA Hirofumi, Viacheslav Dubeyko, John Paul Adrian Glaubitz,
Yangtao Li, Richard Weinberger, Anton Ivanov, Johannes Berg,
Mikulas Patocka, David Woodhouse, Dave Kleikamp, Trond Myklebust,
Anna Schumaker, Ryusuke Konishi, Konstantin Komarov, Mark Fasheh,
Joel Becker, Joseph Qi, Bob Copeland, Mike Marshall,
Martin Brandenburg, Steve French, Paulo Alcantara,
Ronnie Sahlberg, Shyam Prasad N, Tom Talpey, Bharath SM,
Zhihao Cheng, Hans de Goede, Carlos Maiolino, Damien Le Moal,
Naohiro Aota, Johannes Thumshirn, Dan Williams, Matthew Wilcox,
Vlastimil Babka, Jann Horn, Pedro Falcato, linux-block,
linux-kernel, intel-gfx, dri-devel, v9fs, linux-fsdevel,
linux-afs, linux-aio, linux-unionfs, linux-bcachefs, linux-mm,
linux-btrfs, ceph-devel, codalist, ecryptfs, linux-erofs,
linux-ext4, linux-f2fs-devel, linux-um, linux-mtd, jfs-discussion,
linux-nfs, linux-nilfs, ntfs3, ocfs2-devel, linux-karma-devel,
devel, linux-cifs, samba-technical, linux-xfs, nvdimm
On Mon 16-06-25 20:33:28, Lorenzo Stoakes wrote:
> Update nearly all generic_file_mmap() and generic_file_readonly_mmap()
> callers to use generic_file_mmap_prepare() and
> generic_file_readonly_mmap_prepare() respectively.
>
> We update blkdev, 9p, afs, erofs, ext2, nfs, ntfs3, smb, ubifs and vboxsf
> file systems this way.
>
> Remaining users we cannot yet update are ecryptfs, fuse and cramfs. The
> former two are nested file systems that must support any underlying file
> ssytem, and cramfs inserts a mixed mapping which currently requires a VMA.
>
> Once all file systems have been converted to mmap_prepare(), we can then
> update nested file systems.
>
> Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Overall the patch looks good. Just a couple of notes regarding pointless
local variable being created...
> ---
> block/fops.c | 9 +++++----
> fs/9p/vfs_file.c | 11 ++++++-----
> fs/afs/file.c | 11 ++++++-----
> fs/erofs/data.c | 16 +++++++++-------
> fs/ext2/file.c | 12 +++++++-----
> fs/nfs/file.c | 13 +++++++------
> fs/nfs/internal.h | 2 +-
> fs/nfs/nfs4file.c | 2 +-
> fs/ntfs3/file.c | 15 ++++++++-------
> fs/smb/client/cifsfs.c | 12 ++++++------
> fs/smb/client/cifsfs.h | 4 ++--
> fs/smb/client/file.c | 14 ++++++++------
> fs/ubifs/file.c | 8 ++++----
> fs/vboxsf/file.c | 8 ++++----
> 14 files changed, 74 insertions(+), 63 deletions(-)
>
> diff --git a/block/fops.c b/block/fops.c
> index 1309861d4c2c..5a0ebc81e489 100644
> --- a/block/fops.c
> +++ b/block/fops.c
> @@ -911,14 +911,15 @@ static long blkdev_fallocate(struct file *file, int mode, loff_t start,
> return error;
> }
>
> -static int blkdev_mmap(struct file *file, struct vm_area_struct *vma)
> +static int blkdev_mmap_prepare(struct vm_area_desc *desc)
> {
> + struct file *file = desc->file;
> struct inode *bd_inode = bdev_file_inode(file);
I guess no need to create 'file' variable here since it has only one use in
the line above...
>
> if (bdev_read_only(I_BDEV(bd_inode)))
> - return generic_file_readonly_mmap(file, vma);
> + return generic_file_readonly_mmap_prepare(desc);
>
> - return generic_file_mmap(file, vma);
> + return generic_file_mmap_prepare(desc);
> }
>
> const struct file_operations def_blk_fops = {
...
> @@ -492,16 +492,17 @@ static void afs_drop_open_mmap(struct afs_vnode *vnode)
> /*
> * Handle setting up a memory mapping on an AFS file.
> */
> -static int afs_file_mmap(struct file *file, struct vm_area_struct *vma)
> +static int afs_file_mmap_prepare(struct vm_area_desc *desc)
> {
> + struct file *file = desc->file;
> struct afs_vnode *vnode = AFS_FS_I(file_inode(file));
Same comment about pointless local variable here as well.
> int ret;
>
> afs_add_open_mmap(vnode);
>
> - ret = generic_file_mmap(file, vma);
> + ret = generic_file_mmap_prepare(desc);
> if (ret == 0)
> - vma->vm_ops = &afs_vm_ops;
> + desc->vm_ops = &afs_vm_ops;
> else
> afs_drop_open_mmap(vnode);
> return ret;
> diff --git a/fs/erofs/data.c b/fs/erofs/data.c
> index 6a329c329f43..52dfd1a44c43 100644
> --- a/fs/erofs/data.c
> +++ b/fs/erofs/data.c
> @@ -409,20 +409,22 @@ static const struct vm_operations_struct erofs_dax_vm_ops = {
> .huge_fault = erofs_dax_huge_fault,
> };
>
> -static int erofs_file_mmap(struct file *file, struct vm_area_struct *vma)
> +static int erofs_file_mmap_prepare(struct vm_area_desc *desc)
> {
> + struct file *file = desc->file;
> +
> if (!IS_DAX(file_inode(file)))
And here...
> - return generic_file_readonly_mmap(file, vma);
> + return generic_file_readonly_mmap_prepare(desc);
>
> - if ((vma->vm_flags & VM_SHARED) && (vma->vm_flags & VM_MAYWRITE))
> + if ((desc->vm_flags & VM_SHARED) && (desc->vm_flags & VM_MAYWRITE))
> return -EINVAL;
>
> - vma->vm_ops = &erofs_dax_vm_ops;
> - vm_flags_set(vma, VM_HUGEPAGE);
> + desc->vm_ops = &erofs_dax_vm_ops;
> + desc->vm_flags |= VM_HUGEPAGE;
> return 0;
> }
...
> diff --git a/fs/smb/client/file.c b/fs/smb/client/file.c
> index 9835672267d2..2ed5173cfa73 100644
> --- a/fs/smb/client/file.c
> +++ b/fs/smb/client/file.c
> @@ -2995,8 +2995,9 @@ static const struct vm_operations_struct cifs_file_vm_ops = {
> .page_mkwrite = cifs_page_mkwrite,
> };
>
> -int cifs_file_strict_mmap(struct file *file, struct vm_area_struct *vma)
> +int cifs_file_strict_mmap_prepare(struct vm_area_desc *desc)
> {
> + struct file *file = desc->file;
> int xid, rc = 0;
> struct inode *inode = file_inode(file);
Again pointless local variable 'file' here.
>
> @@ -3005,16 +3006,17 @@ int cifs_file_strict_mmap(struct file *file, struct vm_area_struct *vma)
> if (!CIFS_CACHE_READ(CIFS_I(inode)))
> rc = cifs_zap_mapping(inode);
> if (!rc)
> - rc = generic_file_mmap(file, vma);
> + rc = generic_file_mmap_prepare(desc);
> if (!rc)
> - vma->vm_ops = &cifs_file_vm_ops;
> + desc->vm_ops = &cifs_file_vm_ops;
>
> free_xid(xid);
> return rc;
> }
>
> -int cifs_file_mmap(struct file *file, struct vm_area_struct *vma)
> +int cifs_file_mmap_prepare(struct vm_area_desc *desc)
> {
> + struct file *file = desc->file;
> int rc, xid;
And here (the only use is in cifs_revalidate_file(file)).
Honza
--
Jan Kara <jack@suse.com>
SUSE Labs, CR
^ permalink raw reply [flat|nested] 50+ messages in thread
* Re: [PATCH 10/10] fs: replace mmap hook with .mmap_prepare for simple mappings
2025-06-16 19:33 ` [PATCH 10/10] fs: replace mmap hook with .mmap_prepare for simple mappings Lorenzo Stoakes
2025-06-16 22:51 ` Damien Le Moal
2025-06-16 23:24 ` Viacheslav Dubeyko
@ 2025-06-17 10:28 ` Jan Kara
2025-06-17 11:57 ` Christian Brauner
2025-06-18 17:06 ` David Sterba
2025-06-19 17:47 ` Ryusuke Konishi
4 siblings, 1 reply; 50+ messages in thread
From: Jan Kara @ 2025-06-17 10:28 UTC (permalink / raw)
To: Lorenzo Stoakes
Cc: Andrew Morton, Liam R . Howlett, Jens Axboe, Jani Nikula,
Joonas Lahtinen, Rodrigo Vivi, Tvrtko Ursulin, David Airlie,
Simona Vetter, Eric Van Hensbergen, Latchesar Ionkov,
Dominique Martinet, Christian Schoenebeck, David Sterba,
David Howells, Marc Dionne, Alexander Viro, Christian Brauner,
Jan Kara, Benjamin LaHaise, Miklos Szeredi, Amir Goldstein,
Kent Overstreet, Tigran A . Aivazian, Kees Cook, Chris Mason,
Josef Bacik, Xiubo Li, Ilya Dryomov, Jan Harkes, coda,
Tyler Hicks, Gao Xiang, Chao Yu, Yue Hu, Jeffle Xu,
Sandeep Dhavale, Hongbo Li, Namjae Jeon, Sungjong Seo,
Yuezhang Mo, Theodore Ts'o, Andreas Dilger, Jaegeuk Kim,
OGAWA Hirofumi, Viacheslav Dubeyko, John Paul Adrian Glaubitz,
Yangtao Li, Richard Weinberger, Anton Ivanov, Johannes Berg,
Mikulas Patocka, David Woodhouse, Dave Kleikamp, Trond Myklebust,
Anna Schumaker, Ryusuke Konishi, Konstantin Komarov, Mark Fasheh,
Joel Becker, Joseph Qi, Bob Copeland, Mike Marshall,
Martin Brandenburg, Steve French, Paulo Alcantara,
Ronnie Sahlberg, Shyam Prasad N, Tom Talpey, Bharath SM,
Zhihao Cheng, Hans de Goede, Carlos Maiolino, Damien Le Moal,
Naohiro Aota, Johannes Thumshirn, Dan Williams, Matthew Wilcox,
Vlastimil Babka, Jann Horn, Pedro Falcato, linux-block,
linux-kernel, intel-gfx, dri-devel, v9fs, linux-fsdevel,
linux-afs, linux-aio, linux-unionfs, linux-bcachefs, linux-mm,
linux-btrfs, ceph-devel, codalist, ecryptfs, linux-erofs,
linux-ext4, linux-f2fs-devel, linux-um, linux-mtd, jfs-discussion,
linux-nfs, linux-nilfs, ntfs3, ocfs2-devel, linux-karma-devel,
devel, linux-cifs, samba-technical, linux-xfs, nvdimm
On Mon 16-06-25 20:33:29, Lorenzo Stoakes wrote:
> Since commit c84bf6dd2b83 ("mm: introduce new .mmap_prepare() file
> callback"), the f_op->mmap() hook has been deprecated in favour of
> f_op->mmap_prepare().
>
> This callback is invoked in the mmap() logic far earlier, so error handling
> can be performed more safely without complicated and bug-prone state
> unwinding required should an error arise.
>
> This hook also avoids passing a pointer to a not-yet-correctly-established
> VMA avoiding any issues with referencing this data structure.
>
> It rather provides a pointer to the new struct vm_area_desc descriptor type
> which contains all required state and allows easy setting of required
> parameters without any consideration needing to be paid to locking or
> reference counts.
>
> Note that nested filesystems like overlayfs are compatible with an
> .mmap_prepare() callback since commit bb666b7c2707 ("mm: add mmap_prepare()
> compatibility layer for nested file systems").
>
> In this patch we apply this change to file systems with relatively simple
> mmap() hook logic - exfat, ceph, f2fs, bcachefs, zonefs, btrfs, ocfs2,
> orangefs, nilfs2, romfs, ramfs and aio.
>
> Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Two small nits below. Otherwise feel free to add:
Reviewed-by: Jan Kara <jack@suse.cz>
> diff --git a/fs/ceph/addr.c b/fs/ceph/addr.c
> index 60a621b00c65..37522137c380 100644
> --- a/fs/ceph/addr.c
> +++ b/fs/ceph/addr.c
> @@ -2330,13 +2330,14 @@ static const struct vm_operations_struct ceph_vmops = {
> .page_mkwrite = ceph_page_mkwrite,
> };
>
> -int ceph_mmap(struct file *file, struct vm_area_struct *vma)
> +int ceph_mmap_prepare(struct vm_area_desc *desc)
> {
> + struct file *file = desc->file;
> struct address_space *mapping = file->f_mapping;
Pointless local variable here...
>
> if (!mapping->a_ops->read_folio)
> return -ENOEXEC;
> - vma->vm_ops = &ceph_vmops;
> + desc->vm_ops = &ceph_vmops;
> return 0;
> }
>
...
> diff --git a/fs/exfat/file.c b/fs/exfat/file.c
> index 841a5b18e3df..d63213c8a823 100644
> --- a/fs/exfat/file.c
> +++ b/fs/exfat/file.c
> @@ -683,13 +683,14 @@ static const struct vm_operations_struct exfat_file_vm_ops = {
> .page_mkwrite = exfat_page_mkwrite,
> };
>
> -static int exfat_file_mmap(struct file *file, struct vm_area_struct *vma)
> +static int exfat_file_mmap_prepare(struct vm_area_desc *desc)
> {
> + struct file *file = desc->file;
Missing empty line here.
> if (unlikely(exfat_forced_shutdown(file_inode(file)->i_sb)))
> return -EIO;
>
> file_accessed(file);
> - vma->vm_ops = &exfat_file_vm_ops;
> + desc->vm_ops = &exfat_file_vm_ops;
> return 0;
> }
>
Honza
--
Jan Kara <jack@suse.com>
SUSE Labs, CR
^ permalink raw reply [flat|nested] 50+ messages in thread
* Re: [PATCH 00/10] convert the majority of file systems to mmap_prepare
2025-06-16 23:11 ` Andrew Morton
@ 2025-06-17 11:31 ` Christian Brauner
0 siblings, 0 replies; 50+ messages in thread
From: Christian Brauner @ 2025-06-17 11:31 UTC (permalink / raw)
To: Andrew Morton
Cc: Lorenzo Stoakes, Liam R . Howlett, Jens Axboe, Jani Nikula,
Joonas Lahtinen, Rodrigo Vivi, Tvrtko Ursulin, David Airlie,
Simona Vetter, Eric Van Hensbergen, Latchesar Ionkov,
Dominique Martinet, Christian Schoenebeck, David Sterba,
David Howells, Marc Dionne, Alexander Viro, Jan Kara,
Benjamin LaHaise, Miklos Szeredi, Amir Goldstein, Kent Overstreet,
Tigran A . Aivazian, Kees Cook, Chris Mason, Josef Bacik,
Xiubo Li, Ilya Dryomov, Jan Harkes, coda, Tyler Hicks, Gao Xiang,
Chao Yu, Yue Hu, Jeffle Xu, Sandeep Dhavale, Hongbo Li,
Namjae Jeon, Sungjong Seo, Yuezhang Mo, Theodore Ts'o,
Andreas Dilger, Jaegeuk Kim, OGAWA Hirofumi, Viacheslav Dubeyko,
John Paul Adrian Glaubitz, Yangtao Li, Richard Weinberger,
Anton Ivanov, Johannes Berg, Mikulas Patocka, David Woodhouse,
Dave Kleikamp, Trond Myklebust, Anna Schumaker, Ryusuke Konishi,
Konstantin Komarov, Mark Fasheh, Joel Becker, Joseph Qi,
Bob Copeland, Mike Marshall, Martin Brandenburg, Steve French,
Paulo Alcantara, Ronnie Sahlberg, Shyam Prasad N, Tom Talpey,
Bharath SM, Zhihao Cheng, Hans de Goede, Carlos Maiolino,
Damien Le Moal, Naohiro Aota, Johannes Thumshirn, Dan Williams,
Matthew Wilcox, Vlastimil Babka, Jann Horn, Pedro Falcato,
linux-block, linux-kernel, intel-gfx, dri-devel, v9fs,
linux-fsdevel, linux-afs, linux-aio, linux-unionfs,
linux-bcachefs, linux-mm, linux-btrfs, ceph-devel, codalist,
ecryptfs, linux-erofs, linux-ext4, linux-f2fs-devel, linux-um,
linux-mtd, jfs-discussion, linux-nfs, linux-nilfs, ntfs3,
ocfs2-devel, linux-karma-devel, devel, linux-cifs,
samba-technical, linux-xfs, nvdimm
On Mon, Jun 16, 2025 at 04:11:11PM -0700, Andrew Morton wrote:
> On Mon, 16 Jun 2025 20:33:19 +0100 Lorenzo Stoakes <lorenzo.stoakes@oracle.com> wrote:
>
> > I am basing this on the mm-new branch in Andrew's tree, so let me know if I
> > should rebase anything here. Given the mm bits touched I did think perhaps
> > we should take it through the mm tree, however it may be more sensible to
> > take it through an fs tree - let me know!
>
> It's more fs/ than mm/ purely from a footprint point of view. But
> there any expectation that there will be additional patches which build
> on this?
>
> I'll scoop it into mm-new for now, see what happens.
I'm going to carry this in the vfs-6.17.mmap_prepare branch after fixing
up the various minor issues spotted in the series.
^ permalink raw reply [flat|nested] 50+ messages in thread
* Re: [PATCH 04/10] fs/dax: make it possible to check dev dax support without a VMA
2025-06-16 20:26 ` Matthew Wilcox
@ 2025-06-17 11:43 ` Christian Brauner
0 siblings, 0 replies; 50+ messages in thread
From: Christian Brauner @ 2025-06-17 11:43 UTC (permalink / raw)
To: Matthew Wilcox
Cc: Lorenzo Stoakes, Andrew Morton, Liam R . Howlett, Jens Axboe,
Jani Nikula, Joonas Lahtinen, Rodrigo Vivi, Tvrtko Ursulin,
David Airlie, Simona Vetter, Eric Van Hensbergen,
Latchesar Ionkov, Dominique Martinet, Christian Schoenebeck,
David Sterba, David Howells, Marc Dionne, Alexander Viro,
Jan Kara, Benjamin LaHaise, Miklos Szeredi, Amir Goldstein,
Kent Overstreet, Tigran A . Aivazian, Kees Cook, Chris Mason,
Josef Bacik, Xiubo Li, Ilya Dryomov, Jan Harkes, coda,
Tyler Hicks, Gao Xiang, Chao Yu, Yue Hu, Jeffle Xu,
Sandeep Dhavale, Hongbo Li, Namjae Jeon, Sungjong Seo,
Yuezhang Mo, Theodore Ts'o, Andreas Dilger, Jaegeuk Kim,
OGAWA Hirofumi, Viacheslav Dubeyko, John Paul Adrian Glaubitz,
Yangtao Li, Richard Weinberger, Anton Ivanov, Johannes Berg,
Mikulas Patocka, David Woodhouse, Dave Kleikamp, Trond Myklebust,
Anna Schumaker, Ryusuke Konishi, Konstantin Komarov, Mark Fasheh,
Joel Becker, Joseph Qi, Bob Copeland, Mike Marshall,
Martin Brandenburg, Steve French, Paulo Alcantara,
Ronnie Sahlberg, Shyam Prasad N, Tom Talpey, Bharath SM,
Zhihao Cheng, Hans de Goede, Carlos Maiolino, Damien Le Moal,
Naohiro Aota, Johannes Thumshirn, Dan Williams, Vlastimil Babka,
Jann Horn, Pedro Falcato, linux-block, linux-kernel, intel-gfx,
dri-devel, v9fs, linux-fsdevel, linux-afs, linux-aio,
linux-unionfs, linux-bcachefs, linux-mm, linux-btrfs, ceph-devel,
codalist, ecryptfs, linux-erofs, linux-ext4, linux-f2fs-devel,
linux-um, linux-mtd, jfs-discussion, linux-nfs, linux-nilfs,
ntfs3, ocfs2-devel, linux-karma-devel, devel, linux-cifs,
samba-technical, linux-xfs, nvdimm
On Mon, Jun 16, 2025 at 09:26:54PM +0100, Matthew Wilcox wrote:
> On Mon, Jun 16, 2025 at 08:33:23PM +0100, Lorenzo Stoakes wrote:
> > fs/ext4/file.c | 2 +-
> > fs/xfs/xfs_file.c | 3 ++-
>
> Both of these already have the inode from the file ...
>
> > +static inline bool daxdev_mapping_supported(vm_flags_t vm_flags,
> > + struct file *file,
> > + struct dax_device *dax_dev)
> > {
> > - if (!(vma->vm_flags & VM_SYNC))
> > + if (!(vm_flags & VM_SYNC))
> > return true;
> > - if (!IS_DAX(file_inode(vma->vm_file)))
> > + if (!IS_DAX(file_inode(file)))
> > return false;
> > return dax_synchronous(dax_dev);
>
> ... and the only thing this function uses from the file is the inode.
> So maybe pass in the inode rather than the file?
Agreed. I've converted this to take const struct inode *.
^ permalink raw reply [flat|nested] 50+ messages in thread
* Re: [PATCH 06/10] fs/xfs: transition from deprecated .mmap hook to .mmap_prepare
2025-06-17 5:08 ` Christoph Hellwig
@ 2025-06-17 11:45 ` Christian Brauner
0 siblings, 0 replies; 50+ messages in thread
From: Christian Brauner @ 2025-06-17 11:45 UTC (permalink / raw)
To: Christoph Hellwig
Cc: Lorenzo Stoakes, Andrew Morton, Liam R . Howlett, Jens Axboe,
Jani Nikula, Joonas Lahtinen, Rodrigo Vivi, Tvrtko Ursulin,
David Airlie, Simona Vetter, Eric Van Hensbergen,
Latchesar Ionkov, Dominique Martinet, Christian Schoenebeck,
David Sterba, David Howells, Marc Dionne, Alexander Viro,
Jan Kara, Benjamin LaHaise, Miklos Szeredi, Amir Goldstein,
Kent Overstreet, Tigran A . Aivazian, Kees Cook, Chris Mason,
Josef Bacik, Xiubo Li, Ilya Dryomov, Jan Harkes, coda,
Tyler Hicks, Gao Xiang, Chao Yu, Yue Hu, Jeffle Xu,
Sandeep Dhavale, Hongbo Li, Namjae Jeon, Sungjong Seo,
Yuezhang Mo, Theodore Ts'o, Andreas Dilger, Jaegeuk Kim,
OGAWA Hirofumi, Viacheslav Dubeyko, John Paul Adrian Glaubitz,
Yangtao Li, Richard Weinberger, Anton Ivanov, Johannes Berg,
Mikulas Patocka, David Woodhouse, Dave Kleikamp, Trond Myklebust,
Anna Schumaker, Ryusuke Konishi, Konstantin Komarov, Mark Fasheh,
Joel Becker, Joseph Qi, Bob Copeland, Mike Marshall,
Martin Brandenburg, Steve French, Paulo Alcantara,
Ronnie Sahlberg, Shyam Prasad N, Tom Talpey, Bharath SM,
Zhihao Cheng, Hans de Goede, Carlos Maiolino, Damien Le Moal,
Naohiro Aota, Johannes Thumshirn, Dan Williams, Matthew Wilcox,
Vlastimil Babka, Jann Horn, Pedro Falcato, linux-block,
linux-kernel, intel-gfx, dri-devel, v9fs, linux-fsdevel,
linux-afs, linux-aio, linux-unionfs, linux-bcachefs, linux-mm,
linux-btrfs, ceph-devel, codalist, ecryptfs, linux-erofs,
linux-ext4, linux-f2fs-devel, linux-um, linux-mtd, jfs-discussion,
linux-nfs, linux-nilfs, ntfs3, ocfs2-devel, linux-karma-devel,
devel, linux-cifs, samba-technical, linux-xfs, nvdimm
On Mon, Jun 16, 2025 at 10:08:03PM -0700, Christoph Hellwig wrote:
> On Mon, Jun 16, 2025 at 08:33:25PM +0100, Lorenzo Stoakes wrote:
> > STATIC int
> > -xfs_file_mmap(
> > - struct file *file,
> > - struct vm_area_struct *vma)
> > +xfs_file_mmap_prepare(
> > + struct vm_area_desc *desc)
>
> Please stick to the existing alignment for the declarations.
>
> Otherwise this looks good.
Fixed in-tree.
^ permalink raw reply [flat|nested] 50+ messages in thread
* Re: [PATCH 03/10] fs: consistently use file_has_valid_mmap_hooks() helper
2025-06-17 10:08 ` Jan Kara
@ 2025-06-17 11:48 ` Christian Brauner
0 siblings, 0 replies; 50+ messages in thread
From: Christian Brauner @ 2025-06-17 11:48 UTC (permalink / raw)
To: Jan Kara
Cc: Lorenzo Stoakes, Christoph Hellwig, Andrew Morton,
Liam R . Howlett, Jens Axboe, Jani Nikula, Joonas Lahtinen,
Rodrigo Vivi, Tvrtko Ursulin, David Airlie, Simona Vetter,
Eric Van Hensbergen, Latchesar Ionkov, Dominique Martinet,
Christian Schoenebeck, David Sterba, David Howells, Marc Dionne,
Alexander Viro, Benjamin LaHaise, Miklos Szeredi, Amir Goldstein,
Kent Overstreet, Tigran A . Aivazian, Kees Cook, Chris Mason,
Josef Bacik, Xiubo Li, Ilya Dryomov, Jan Harkes, coda,
Tyler Hicks, Gao Xiang, Chao Yu, Yue Hu, Jeffle Xu,
Sandeep Dhavale, Hongbo Li, Namjae Jeon, Sungjong Seo,
Yuezhang Mo, Theodore Ts'o, Andreas Dilger, Jaegeuk Kim,
OGAWA Hirofumi, Viacheslav Dubeyko, John Paul Adrian Glaubitz,
Yangtao Li, Richard Weinberger, Anton Ivanov, Johannes Berg,
Mikulas Patocka, David Woodhouse, Dave Kleikamp, Trond Myklebust,
Anna Schumaker, Ryusuke Konishi, Konstantin Komarov, Mark Fasheh,
Joel Becker, Joseph Qi, Bob Copeland, Mike Marshall,
Martin Brandenburg, Steve French, Paulo Alcantara,
Ronnie Sahlberg, Shyam Prasad N, Tom Talpey, Bharath SM,
Zhihao Cheng, Hans de Goede, Carlos Maiolino, Damien Le Moal,
Naohiro Aota, Johannes Thumshirn, Dan Williams, Matthew Wilcox,
Vlastimil Babka, Jann Horn, Pedro Falcato, linux-block,
linux-kernel, intel-gfx, dri-devel, v9fs, linux-fsdevel,
linux-afs, linux-aio, linux-unionfs, linux-bcachefs, linux-mm,
linux-btrfs, ceph-devel, codalist, ecryptfs, linux-erofs,
linux-ext4, linux-f2fs-devel, linux-um, linux-mtd, jfs-discussion,
linux-nfs, linux-nilfs, ntfs3, ocfs2-devel, linux-karma-devel,
devel, linux-cifs, samba-technical, linux-xfs, nvdimm
On Tue, Jun 17, 2025 at 12:08:13PM +0200, Jan Kara wrote:
> On Tue 17-06-25 06:25:34, Lorenzo Stoakes wrote:
> > On Mon, Jun 16, 2025 at 10:11:28PM -0700, Christoph Hellwig wrote:
> > > On Mon, Jun 16, 2025 at 08:33:22PM +0100, Lorenzo Stoakes wrote:
> > > > Since commit c84bf6dd2b83 ("mm: introduce new .mmap_prepare() file
> > > > callback"), the f_op->mmap() hook has been deprecated in favour of
> > > > f_op->mmap_prepare().
> > > >
> > > > Additionally, commit bb666b7c2707 ("mm: add mmap_prepare() compatibility
> > > > layer for nested file systems") permits the use of the .mmap_prepare() hook
> > > > even in nested filesystems like overlayfs.
> > > >
> > > > There are a number of places where we check only for f_op->mmap - this is
> > > > incorrect now mmap_prepare exists, so update all of these to use the
> > > > general helper file_has_valid_mmap_hooks().
> > > >
> > > > Most notably, this updates the elf logic to allow for the ability to
> > > > execute binaries on filesystems which have the .mmap_prepare hook, but
> > > > additionally we update nested filesystems.
> > >
> > > Can you please give the function a better name before spreading it?
> > > file operations aren't hooks by any classic definition.
> > >
> >
> > can_mmap_file()?
>
> I like this name more as well :). With this patch looks good to me. Again a
Fixed in-tree.
^ permalink raw reply [flat|nested] 50+ messages in thread
* Re: [PATCH 09/10] fs: convert most other generic_file_*mmap() users to .mmap_prepare()
2025-06-17 10:23 ` Jan Kara
@ 2025-06-17 11:54 ` Christian Brauner
0 siblings, 0 replies; 50+ messages in thread
From: Christian Brauner @ 2025-06-17 11:54 UTC (permalink / raw)
To: Jan Kara
Cc: Lorenzo Stoakes, Andrew Morton, Liam R . Howlett, Jens Axboe,
Jani Nikula, Joonas Lahtinen, Rodrigo Vivi, Tvrtko Ursulin,
David Airlie, Simona Vetter, Eric Van Hensbergen,
Latchesar Ionkov, Dominique Martinet, Christian Schoenebeck,
David Sterba, David Howells, Marc Dionne, Alexander Viro,
Benjamin LaHaise, Miklos Szeredi, Amir Goldstein, Kent Overstreet,
Tigran A . Aivazian, Kees Cook, Chris Mason, Josef Bacik,
Xiubo Li, Ilya Dryomov, Jan Harkes, coda, Tyler Hicks, Gao Xiang,
Chao Yu, Yue Hu, Jeffle Xu, Sandeep Dhavale, Hongbo Li,
Namjae Jeon, Sungjong Seo, Yuezhang Mo, Theodore Ts'o,
Andreas Dilger, Jaegeuk Kim, OGAWA Hirofumi, Viacheslav Dubeyko,
John Paul Adrian Glaubitz, Yangtao Li, Richard Weinberger,
Anton Ivanov, Johannes Berg, Mikulas Patocka, David Woodhouse,
Dave Kleikamp, Trond Myklebust, Anna Schumaker, Ryusuke Konishi,
Konstantin Komarov, Mark Fasheh, Joel Becker, Joseph Qi,
Bob Copeland, Mike Marshall, Martin Brandenburg, Steve French,
Paulo Alcantara, Ronnie Sahlberg, Shyam Prasad N, Tom Talpey,
Bharath SM, Zhihao Cheng, Hans de Goede, Carlos Maiolino,
Damien Le Moal, Naohiro Aota, Johannes Thumshirn, Dan Williams,
Matthew Wilcox, Vlastimil Babka, Jann Horn, Pedro Falcato,
linux-block, linux-kernel, intel-gfx, dri-devel, v9fs,
linux-fsdevel, linux-afs, linux-aio, linux-unionfs,
linux-bcachefs, linux-mm, linux-btrfs, ceph-devel, codalist,
ecryptfs, linux-erofs, linux-ext4, linux-f2fs-devel, linux-um,
linux-mtd, jfs-discussion, linux-nfs, linux-nilfs, ntfs3,
ocfs2-devel, linux-karma-devel, devel, linux-cifs,
samba-technical, linux-xfs, nvdimm
On Tue, Jun 17, 2025 at 12:23:41PM +0200, Jan Kara wrote:
> On Mon 16-06-25 20:33:28, Lorenzo Stoakes wrote:
> > Update nearly all generic_file_mmap() and generic_file_readonly_mmap()
> > callers to use generic_file_mmap_prepare() and
> > generic_file_readonly_mmap_prepare() respectively.
> >
> > We update blkdev, 9p, afs, erofs, ext2, nfs, ntfs3, smb, ubifs and vboxsf
> > file systems this way.
> >
> > Remaining users we cannot yet update are ecryptfs, fuse and cramfs. The
> > former two are nested file systems that must support any underlying file
> > ssytem, and cramfs inserts a mixed mapping which currently requires a VMA.
> >
> > Once all file systems have been converted to mmap_prepare(), we can then
> > update nested file systems.
> >
> > Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
>
> Overall the patch looks good. Just a couple of notes regarding pointless
> local variable being created...
>
> > ---
> > block/fops.c | 9 +++++----
> > fs/9p/vfs_file.c | 11 ++++++-----
> > fs/afs/file.c | 11 ++++++-----
> > fs/erofs/data.c | 16 +++++++++-------
> > fs/ext2/file.c | 12 +++++++-----
> > fs/nfs/file.c | 13 +++++++------
> > fs/nfs/internal.h | 2 +-
> > fs/nfs/nfs4file.c | 2 +-
> > fs/ntfs3/file.c | 15 ++++++++-------
> > fs/smb/client/cifsfs.c | 12 ++++++------
> > fs/smb/client/cifsfs.h | 4 ++--
> > fs/smb/client/file.c | 14 ++++++++------
> > fs/ubifs/file.c | 8 ++++----
> > fs/vboxsf/file.c | 8 ++++----
> > 14 files changed, 74 insertions(+), 63 deletions(-)
> >
> > diff --git a/block/fops.c b/block/fops.c
> > index 1309861d4c2c..5a0ebc81e489 100644
> > --- a/block/fops.c
> > +++ b/block/fops.c
> > @@ -911,14 +911,15 @@ static long blkdev_fallocate(struct file *file, int mode, loff_t start,
> > return error;
> > }
> >
> > -static int blkdev_mmap(struct file *file, struct vm_area_struct *vma)
> > +static int blkdev_mmap_prepare(struct vm_area_desc *desc)
> > {
> > + struct file *file = desc->file;
> > struct inode *bd_inode = bdev_file_inode(file);
>
> I guess no need to create 'file' variable here since it has only one use in
> the line above...
Agreed, fixed in-tree.
> > -static int afs_file_mmap(struct file *file, struct vm_area_struct *vma)
> > +static int afs_file_mmap_prepare(struct vm_area_desc *desc)
> > {
> > + struct file *file = desc->file;
> > struct afs_vnode *vnode = AFS_FS_I(file_inode(file));
>
> Same comment about pointless local variable here as well.
Same.
> > -static int erofs_file_mmap(struct file *file, struct vm_area_struct *vma)
> > +static int erofs_file_mmap_prepare(struct vm_area_desc *desc)
> > {
> > + struct file *file = desc->file;
> > +
> > if (!IS_DAX(file_inode(file)))
>
> And here...
Same.
> > -int cifs_file_strict_mmap(struct file *file, struct vm_area_struct *vma)
> > +int cifs_file_strict_mmap_prepare(struct vm_area_desc *desc)
> > {
> > + struct file *file = desc->file;
> > int xid, rc = 0;
> > struct inode *inode = file_inode(file);
>
> Again pointless local variable 'file' here.
Same.
> > -int cifs_file_mmap(struct file *file, struct vm_area_struct *vma)
> > +int cifs_file_mmap_prepare(struct vm_area_desc *desc)
> > {
> > + struct file *file = desc->file;
> > int rc, xid;
>
> And here (the only use is in cifs_revalidate_file(file)).
Same.
^ permalink raw reply [flat|nested] 50+ messages in thread
* Re: [PATCH 10/10] fs: replace mmap hook with .mmap_prepare for simple mappings
2025-06-17 10:28 ` Jan Kara
@ 2025-06-17 11:57 ` Christian Brauner
0 siblings, 0 replies; 50+ messages in thread
From: Christian Brauner @ 2025-06-17 11:57 UTC (permalink / raw)
To: Jan Kara
Cc: Lorenzo Stoakes, Andrew Morton, Liam R . Howlett, Jens Axboe,
Jani Nikula, Joonas Lahtinen, Rodrigo Vivi, Tvrtko Ursulin,
David Airlie, Simona Vetter, Eric Van Hensbergen,
Latchesar Ionkov, Dominique Martinet, Christian Schoenebeck,
David Sterba, David Howells, Marc Dionne, Alexander Viro,
Benjamin LaHaise, Miklos Szeredi, Amir Goldstein, Kent Overstreet,
Tigran A . Aivazian, Kees Cook, Chris Mason, Josef Bacik,
Xiubo Li, Ilya Dryomov, Jan Harkes, coda, Tyler Hicks, Gao Xiang,
Chao Yu, Yue Hu, Jeffle Xu, Sandeep Dhavale, Hongbo Li,
Namjae Jeon, Sungjong Seo, Yuezhang Mo, Theodore Ts'o,
Andreas Dilger, Jaegeuk Kim, OGAWA Hirofumi, Viacheslav Dubeyko,
John Paul Adrian Glaubitz, Yangtao Li, Richard Weinberger,
Anton Ivanov, Johannes Berg, Mikulas Patocka, David Woodhouse,
Dave Kleikamp, Trond Myklebust, Anna Schumaker, Ryusuke Konishi,
Konstantin Komarov, Mark Fasheh, Joel Becker, Joseph Qi,
Bob Copeland, Mike Marshall, Martin Brandenburg, Steve French,
Paulo Alcantara, Ronnie Sahlberg, Shyam Prasad N, Tom Talpey,
Bharath SM, Zhihao Cheng, Hans de Goede, Carlos Maiolino,
Damien Le Moal, Naohiro Aota, Johannes Thumshirn, Dan Williams,
Matthew Wilcox, Vlastimil Babka, Jann Horn, Pedro Falcato,
linux-block, linux-kernel, intel-gfx, dri-devel, v9fs,
linux-fsdevel, linux-afs, linux-aio, linux-unionfs,
linux-bcachefs, linux-mm, linux-btrfs, ceph-devel, codalist,
ecryptfs, linux-erofs, linux-ext4, linux-f2fs-devel, linux-um,
linux-mtd, jfs-discussion, linux-nfs, linux-nilfs, ntfs3,
ocfs2-devel, linux-karma-devel, devel, linux-cifs,
samba-technical, linux-xfs, nvdimm
On Tue, Jun 17, 2025 at 12:28:17PM +0200, Jan Kara wrote:
> On Mon 16-06-25 20:33:29, Lorenzo Stoakes wrote:
> > Since commit c84bf6dd2b83 ("mm: introduce new .mmap_prepare() file
> > callback"), the f_op->mmap() hook has been deprecated in favour of
> > f_op->mmap_prepare().
> >
> > This callback is invoked in the mmap() logic far earlier, so error handling
> > can be performed more safely without complicated and bug-prone state
> > unwinding required should an error arise.
> >
> > This hook also avoids passing a pointer to a not-yet-correctly-established
> > VMA avoiding any issues with referencing this data structure.
> >
> > It rather provides a pointer to the new struct vm_area_desc descriptor type
> > which contains all required state and allows easy setting of required
> > parameters without any consideration needing to be paid to locking or
> > reference counts.
> >
> > Note that nested filesystems like overlayfs are compatible with an
> > .mmap_prepare() callback since commit bb666b7c2707 ("mm: add mmap_prepare()
> > compatibility layer for nested file systems").
> >
> > In this patch we apply this change to file systems with relatively simple
> > mmap() hook logic - exfat, ceph, f2fs, bcachefs, zonefs, btrfs, ocfs2,
> > orangefs, nilfs2, romfs, ramfs and aio.
> >
> > Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
>
> Two small nits below. Otherwise feel free to add:
>
> Reviewed-by: Jan Kara <jack@suse.cz>
>
> > diff --git a/fs/ceph/addr.c b/fs/ceph/addr.c
> > index 60a621b00c65..37522137c380 100644
> > --- a/fs/ceph/addr.c
> > +++ b/fs/ceph/addr.c
> > @@ -2330,13 +2330,14 @@ static const struct vm_operations_struct ceph_vmops = {
> > .page_mkwrite = ceph_page_mkwrite,
> > };
> >
> > -int ceph_mmap(struct file *file, struct vm_area_struct *vma)
> > +int ceph_mmap_prepare(struct vm_area_desc *desc)
> > {
> > + struct file *file = desc->file;
> > struct address_space *mapping = file->f_mapping;
>
> Pointless local variable here...
Agreed, fixed in-tree.
> > -static int exfat_file_mmap(struct file *file, struct vm_area_struct *vma)
> > +static int exfat_file_mmap_prepare(struct vm_area_desc *desc)
> > {
> > + struct file *file = desc->file;
>
> Missing empty line here.
Fixed in-tree.
^ permalink raw reply [flat|nested] 50+ messages in thread
* Re: [PATCH 00/10] convert the majority of file systems to mmap_prepare
2025-06-16 19:33 [PATCH 00/10] convert the majority of file systems to mmap_prepare Lorenzo Stoakes
` (12 preceding siblings ...)
2025-06-16 23:11 ` Andrew Morton
@ 2025-06-17 11:58 ` Christian Brauner
2025-06-17 14:05 ` David Howells
2025-08-01 14:00 ` Jason Gunthorpe
15 siblings, 0 replies; 50+ messages in thread
From: Christian Brauner @ 2025-06-17 11:58 UTC (permalink / raw)
To: Lorenzo Stoakes
Cc: Christian Brauner, Liam R . Howlett, Jens Axboe, Jani Nikula,
Joonas Lahtinen, Rodrigo Vivi, Tvrtko Ursulin, David Airlie,
Simona Vetter, Eric Van Hensbergen, Latchesar Ionkov,
Dominique Martinet, Christian Schoenebeck, David Sterba,
David Howells, Marc Dionne, Alexander Viro, Jan Kara,
Benjamin LaHaise, Miklos Szeredi, Amir Goldstein, Kent Overstreet,
Tigran A . Aivazian, Kees Cook, Chris Mason, Josef Bacik,
Xiubo Li, Ilya Dryomov, Jan Harkes, coda, Tyler Hicks, Gao Xiang,
Chao Yu, Yue Hu, Jeffle Xu, Sandeep Dhavale, Hongbo Li,
Namjae Jeon, Sungjong Seo, Yuezhang Mo, Theodore Ts'o,
Andreas Dilger, Jaegeuk Kim, OGAWA Hirofumi, Viacheslav Dubeyko,
John Paul Adrian Glaubitz, Yangtao Li, Richard Weinberger,
Anton Ivanov, Johannes Berg, Mikulas Patocka, David Woodhouse,
Dave Kleikamp, Trond Myklebust, Anna Schumaker, Ryusuke Konishi,
Konstantin Komarov, Mark Fasheh, Joel Becker, Joseph Qi,
Bob Copeland, Mike Marshall, Martin Brandenburg, Steve French,
Paulo Alcantara, Ronnie Sahlberg, Shyam Prasad N, Tom Talpey,
Bharath SM, Zhihao Cheng, Hans de Goede, Carlos Maiolino,
Damien Le Moal, Naohiro Aota, Johannes Thumshirn, Dan Williams,
Matthew Wilcox, Vlastimil Babka, Jann Horn, Pedro Falcato,
linux-block, linux-kernel, intel-gfx, dri-devel, v9fs,
linux-fsdevel, linux-afs, linux-aio, linux-unionfs,
linux-bcachefs, linux-mm, linux-btrfs, ceph-devel, codalist,
ecryptfs, linux-erofs, linux-ext4, linux-f2fs-devel, linux-um,
linux-mtd, jfs-discussion, linux-nfs, linux-nilfs, ntfs3,
ocfs2-devel, linux-karma-devel, devel, linux-cifs,
samba-technical, linux-xfs, nvdimm, Andrew Morton
On Mon, 16 Jun 2025 20:33:19 +0100, Lorenzo Stoakes wrote:
> REVIEWER'S NOTES
> ================
>
> I am basing this on the mm-new branch in Andrew's tree, so let me know if I
> should rebase anything here. Given the mm bits touched I did think perhaps
> we should take it through the mm tree, however it may be more sensible to
> take it through an fs tree - let me know!
>
> [...]
This looks good. I fixed up the minor review comments.
Looking forward to further cleanups in this area.
---
Applied to the vfs-6.17.mmap_prepare branch of the vfs/vfs.git tree.
Patches in the vfs-6.17.mmap_prepare branch should appear in linux-next soon.
Please report any outstanding bugs that were missed during review in a
new review to the original patch series allowing us to drop it.
It's encouraged to provide Acked-bys and Reviewed-bys even though the
patch has now been applied. If possible patch trailers will be updated.
Note that commit hashes shown below are subject to change due to rebase,
trailer updates or similar. If in doubt, please check the listed branch.
tree: https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
branch: vfs-6.17.mmap_prepare
[01/10] mm: rename call_mmap/mmap_prepare to vfs_mmap/mmap_prepare
https://git.kernel.org/vfs/vfs/c/20ca475d9860
[02/10] mm/nommu: use file_has_valid_mmap_hooks() helper
https://git.kernel.org/vfs/vfs/c/c6900f227f89
[03/10] fs: consistently use file_has_valid_mmap_hooks() helper
https://git.kernel.org/vfs/vfs/c/b013ed403197
[04/10] fs/dax: make it possible to check dev dax support without a VMA
https://git.kernel.org/vfs/vfs/c/0335f6afd348
[05/10] fs/ext4: transition from deprecated .mmap hook to .mmap_prepare
https://git.kernel.org/vfs/vfs/c/8c90ae8fe5e3
[06/10] fs/xfs: transition from deprecated .mmap hook to .mmap_prepare
https://git.kernel.org/vfs/vfs/c/6528d29b46d8
[07/10] mm/filemap: introduce generic_file_*_mmap_prepare() helpers
https://git.kernel.org/vfs/vfs/c/5b44297bcfa4
[08/10] fs: convert simple use of generic_file_*_mmap() to .mmap_prepare()
https://git.kernel.org/vfs/vfs/c/951ea2f4844c
[09/10] fs: convert most other generic_file_*mmap() users to .mmap_prepare()
https://git.kernel.org/vfs/vfs/c/a5ee9a82981d
[10/10] fs: replace mmap hook with .mmap_prepare for simple mappings
https://git.kernel.org/vfs/vfs/c/a1e5b36c4034
^ permalink raw reply [flat|nested] 50+ messages in thread
* Re: [PATCH 00/10] convert the majority of file systems to mmap_prepare
2025-06-16 20:41 ` Al Viro
@ 2025-06-17 13:45 ` Jeff Layton
2025-06-17 13:46 ` Lorenzo Stoakes
0 siblings, 1 reply; 50+ messages in thread
From: Jeff Layton @ 2025-06-17 13:45 UTC (permalink / raw)
To: Al Viro, Lorenzo Stoakes
Cc: Andrew Morton, Liam R . Howlett, Jens Axboe, Jani Nikula,
Joonas Lahtinen, Rodrigo Vivi, Tvrtko Ursulin, David Airlie,
Simona Vetter, Eric Van Hensbergen, Latchesar Ionkov,
Dominique Martinet, Christian Schoenebeck, David Sterba,
David Howells, Marc Dionne, Christian Brauner, Jan Kara,
Benjamin LaHaise, Miklos Szeredi, Amir Goldstein, Kent Overstreet,
Tigran A . Aivazian, Kees Cook, Chris Mason, Josef Bacik,
Xiubo Li, Ilya Dryomov, Jan Harkes, coda, Tyler Hicks, Gao Xiang,
Chao Yu, Yue Hu, Jeffle Xu, Sandeep Dhavale, Hongbo Li,
Namjae Jeon, Sungjong Seo, Yuezhang Mo, Theodore Ts'o,
Andreas Dilger, Jaegeuk Kim, OGAWA Hirofumi, Viacheslav Dubeyko,
John Paul Adrian Glaubitz, Yangtao Li, Richard Weinberger,
Anton Ivanov, Johannes Berg, Mikulas Patocka, David Woodhouse,
Dave Kleikamp, Trond Myklebust, Anna Schumaker, Ryusuke Konishi,
Konstantin Komarov, Mark Fasheh, Joel Becker, Joseph Qi,
Bob Copeland, Mike Marshall, Martin Brandenburg, Steve French,
Paulo Alcantara, Ronnie Sahlberg, Shyam Prasad N, Tom Talpey,
Bharath SM, Zhihao Cheng, Hans de Goede, Carlos Maiolino,
Damien Le Moal, Naohiro Aota, Johannes Thumshirn, Dan Williams,
Matthew Wilcox, Vlastimil Babka, Jann Horn, Pedro Falcato,
linux-block, linux-kernel, intel-gfx, dri-devel, v9fs,
linux-fsdevel, linux-afs, linux-aio, linux-unionfs,
linux-bcachefs, linux-mm, linux-btrfs, ceph-devel, codalist,
ecryptfs, linux-erofs, linux-ext4, linux-f2fs-devel, linux-um,
linux-mtd, jfs-discussion, linux-nfs, linux-nilfs, ntfs3,
ocfs2-devel, linux-karma-devel, devel, linux-cifs,
samba-technical, linux-xfs, nvdimm
On Mon, 2025-06-16 at 21:41 +0100, Al Viro wrote:
> On Mon, Jun 16, 2025 at 08:33:19PM +0100, Lorenzo Stoakes wrote:
> > REVIEWER'S NOTES
> > ================
> >
> > I am basing this on the mm-new branch in Andrew's tree, so let me know if I
> > should rebase anything here. Given the mm bits touched I did think perhaps
> > we should take it through the mm tree, however it may be more sensible to
> > take it through an fs tree - let me know!
> >
> > Apologies for the noise/churn, but there are some prerequisite steps here
> > that inform an ordering - "fs: consistently use file_has_valid_mmap_hooks()
> > helper" being especially critical, and so I put the bulk of the work in the
> > same series.
> >
> > Let me know if there's anything I can do to make life easier here.
>
> Documentation/filesystems/porting.rst?
Also, an entry for ->mmap_prepare in Documentation/filesystems/vfs.rst
would be good.
I went there first to understand what the requirements of mmap_prepare
are, but there is nothing.
--
Jeff Layton <jlayton@kernel.org>
^ permalink raw reply [flat|nested] 50+ messages in thread
* Re: [PATCH 00/10] convert the majority of file systems to mmap_prepare
2025-06-17 13:45 ` Jeff Layton
@ 2025-06-17 13:46 ` Lorenzo Stoakes
0 siblings, 0 replies; 50+ messages in thread
From: Lorenzo Stoakes @ 2025-06-17 13:46 UTC (permalink / raw)
To: Jeff Layton
Cc: Al Viro, Andrew Morton, Liam R . Howlett, Jens Axboe, Jani Nikula,
Joonas Lahtinen, Rodrigo Vivi, Tvrtko Ursulin, David Airlie,
Simona Vetter, Eric Van Hensbergen, Latchesar Ionkov,
Dominique Martinet, Christian Schoenebeck, David Sterba,
David Howells, Marc Dionne, Christian Brauner, Jan Kara,
Benjamin LaHaise, Miklos Szeredi, Amir Goldstein, Kent Overstreet,
Tigran A . Aivazian, Kees Cook, Chris Mason, Josef Bacik,
Xiubo Li, Ilya Dryomov, Jan Harkes, coda, Tyler Hicks, Gao Xiang,
Chao Yu, Yue Hu, Jeffle Xu, Sandeep Dhavale, Hongbo Li,
Namjae Jeon, Sungjong Seo, Yuezhang Mo, Theodore Ts'o,
Andreas Dilger, Jaegeuk Kim, OGAWA Hirofumi, Viacheslav Dubeyko,
John Paul Adrian Glaubitz, Yangtao Li, Richard Weinberger,
Anton Ivanov, Johannes Berg, Mikulas Patocka, David Woodhouse,
Dave Kleikamp, Trond Myklebust, Anna Schumaker, Ryusuke Konishi,
Konstantin Komarov, Mark Fasheh, Joel Becker, Joseph Qi,
Bob Copeland, Mike Marshall, Martin Brandenburg, Steve French,
Paulo Alcantara, Ronnie Sahlberg, Shyam Prasad N, Tom Talpey,
Bharath SM, Zhihao Cheng, Hans de Goede, Carlos Maiolino,
Damien Le Moal, Naohiro Aota, Johannes Thumshirn, Dan Williams,
Matthew Wilcox, Vlastimil Babka, Jann Horn, Pedro Falcato,
linux-block, linux-kernel, intel-gfx, dri-devel, v9fs,
linux-fsdevel, linux-afs, linux-aio, linux-unionfs,
linux-bcachefs, linux-mm, linux-btrfs, ceph-devel, codalist,
ecryptfs, linux-erofs, linux-ext4, linux-f2fs-devel, linux-um,
linux-mtd, jfs-discussion, linux-nfs, linux-nilfs, ntfs3,
ocfs2-devel, linux-karma-devel, devel, linux-cifs,
samba-technical, linux-xfs, nvdimm
On Tue, Jun 17, 2025 at 09:45:32AM -0400, Jeff Layton wrote:
> On Mon, 2025-06-16 at 21:41 +0100, Al Viro wrote:
> > On Mon, Jun 16, 2025 at 08:33:19PM +0100, Lorenzo Stoakes wrote:
> > > REVIEWER'S NOTES
> > > ================
> > >
> > > I am basing this on the mm-new branch in Andrew's tree, so let me know if I
> > > should rebase anything here. Given the mm bits touched I did think perhaps
> > > we should take it through the mm tree, however it may be more sensible to
> > > take it through an fs tree - let me know!
> > >
> > > Apologies for the noise/churn, but there are some prerequisite steps here
> > > that inform an ordering - "fs: consistently use file_has_valid_mmap_hooks()
> > > helper" being especially critical, and so I put the bulk of the work in the
> > > same series.
> > >
> > > Let me know if there's anything I can do to make life easier here.
> >
> > Documentation/filesystems/porting.rst?
>
> Also, an entry for ->mmap_prepare in Documentation/filesystems/vfs.rst
> would be good.
>
> I went there first to understand what the requirements of mmap_prepare
> are, but there is nothing.
Ack, on it.
> --
> Jeff Layton <jlayton@kernel.org>
>
^ permalink raw reply [flat|nested] 50+ messages in thread
* Re: [PATCH 00/10] convert the majority of file systems to mmap_prepare
2025-06-16 19:33 [PATCH 00/10] convert the majority of file systems to mmap_prepare Lorenzo Stoakes
` (13 preceding siblings ...)
2025-06-17 11:58 ` Christian Brauner
@ 2025-06-17 14:05 ` David Howells
2025-06-17 14:17 ` Lorenzo Stoakes
2025-08-01 14:00 ` Jason Gunthorpe
15 siblings, 1 reply; 50+ messages in thread
From: David Howells @ 2025-06-17 14:05 UTC (permalink / raw)
To: Lorenzo Stoakes
Cc: Andrew Morton, Liam R . Howlett, Jens Axboe, Jani Nikula,
Joonas Lahtinen, Rodrigo Vivi, Tvrtko Ursulin, David Airlie,
Simona Vetter, Eric Van Hensbergen, Latchesar Ionkov,
Dominique Martinet, Christian Schoenebeck, David Sterba,
David Howells, Marc Dionne, Alexander Viro, Christian Brauner,
Jan Kara, Benjamin LaHaise, Miklos Szeredi, Amir Goldstein,
Kent Overstreet, Tigran A . Aivazian, Kees Cook, Chris Mason,
Josef Bacik, Xiubo Li, Ilya Dryomov, Jan Harkes, coda,
Tyler Hicks, Gao Xiang, Chao Yu, Yue Hu, Jeffle Xu,
Sandeep Dhavale, Hongbo Li, Namjae Jeon, Sungjong Seo,
Yuezhang Mo, Theodore Ts'o, Andreas Dilger, Jaegeuk Kim,
OGAWA Hirofumi, Viacheslav Dubeyko, John Paul Adrian Glaubitz,
Yangtao Li, Richard Weinberger, Anton Ivanov, Johannes Berg,
Mikulas Patocka, David Woodhouse, Dave Kleikamp, Trond Myklebust,
Anna Schumaker, Ryusuke Konishi, Konstantin Komarov, Mark Fasheh,
Joel Becker, Joseph Qi, Bob Copeland, Mike Marshall,
Martin Brandenburg, Steve French, Paulo Alcantara,
Ronnie Sahlberg, Shyam Prasad N, Tom Talpey, Bharath SM,
Zhihao Cheng, Hans de Goede, Carlos Maiolino, Damien Le Moal,
Naohiro Aota, Johannes Thumshirn, Dan Williams, Matthew Wilcox,
Vlastimil Babka, Jann Horn, Pedro Falcato, linux-block,
linux-kernel, intel-gfx, dri-devel, v9fs, linux-fsdevel,
linux-afs, linux-aio, linux-unionfs, linux-bcachefs, linux-mm,
linux-btrfs, ceph-devel, codalist, ecryptfs, linux-erofs,
linux-ext4, linux-f2fs-devel, linux-um, linux-mtd, jfs-discussion,
linux-nfs, linux-nilfs, ntfs3, ocfs2-devel, linux-karma-devel,
devel, linux-cifs, samba-technical, linux-xfs, nvdimm
Lorenzo Stoakes <lorenzo.stoakes@oracle.com> wrote:
> This is preferred to the existing f_op->mmap() hook as it does require a
> VMA to be established yet,
Did you mean ".. doesn't require a VMA to be established yet, ..."
David
^ permalink raw reply [flat|nested] 50+ messages in thread
* Re: [PATCH 08/10] fs: convert simple use of generic_file_*_mmap() to .mmap_prepare()
2025-06-16 19:33 ` [PATCH 08/10] fs: convert simple use of generic_file_*_mmap() to .mmap_prepare() Lorenzo Stoakes
2025-06-16 23:26 ` Viacheslav Dubeyko
2025-06-17 10:14 ` Jan Kara
@ 2025-06-17 14:07 ` Dave Kleikamp
2 siblings, 0 replies; 50+ messages in thread
From: Dave Kleikamp @ 2025-06-17 14:07 UTC (permalink / raw)
To: Lorenzo Stoakes, Andrew Morton
Cc: Liam R . Howlett, Jens Axboe, Jani Nikula, Joonas Lahtinen,
Rodrigo Vivi, Tvrtko Ursulin, David Airlie, Simona Vetter,
Eric Van Hensbergen, Latchesar Ionkov, Dominique Martinet,
Christian Schoenebeck, David Sterba, David Howells, Marc Dionne,
Alexander Viro, Christian Brauner, Jan Kara, Benjamin LaHaise,
Miklos Szeredi, Amir Goldstein, Kent Overstreet,
Tigran A . Aivazian, Kees Cook, Chris Mason, Josef Bacik,
Xiubo Li, Ilya Dryomov, Jan Harkes, coda, Tyler Hicks, Gao Xiang,
Chao Yu, Yue Hu, Jeffle Xu, Sandeep Dhavale, Hongbo Li,
Namjae Jeon, Sungjong Seo, Yuezhang Mo, Theodore Ts'o,
Andreas Dilger, Jaegeuk Kim, OGAWA Hirofumi, Viacheslav Dubeyko,
John Paul Adrian Glaubitz, Yangtao Li, Richard Weinberger,
Anton Ivanov, Johannes Berg, Mikulas Patocka, David Woodhouse,
Dave Kleikamp, Trond Myklebust, Anna Schumaker, Ryusuke Konishi,
Konstantin Komarov, Mark Fasheh, Joel Becker, Joseph Qi,
Bob Copeland, Mike Marshall, Martin Brandenburg, Steve French,
Paulo Alcantara, Ronnie Sahlberg, Shyam Prasad N, Tom Talpey,
Bharath SM, Zhihao Cheng, Hans de Goede, Carlos Maiolino,
Damien Le Moal, Naohiro Aota, Johannes Thumshirn, Dan Williams,
Matthew Wilcox, Vlastimil Babka, Jann Horn, Pedro Falcato,
linux-block, linux-kernel, intel-gfx, dri-devel, v9fs,
linux-fsdevel, linux-afs, linux-aio, linux-unionfs,
linux-bcachefs, linux-mm, linux-btrfs, ceph-devel, codalist,
ecryptfs, linux-erofs, linux-ext4, linux-f2fs-devel, linux-um,
linux-mtd, jfs-discussion, linux-nfs, linux-nilfs, ntfs3,
ocfs2-devel, linux-karma-devel, devel, linux-cifs,
samba-technical, linux-xfs, nvdimm
On 6/16/25 2:33PM, Lorenzo Stoakes wrote:
> Since commit c84bf6dd2b83 ("mm: introduce new .mmap_prepare() file
> callback"), the f_op->mmap() hook has been deprecated in favour of
> f_op->mmap_prepare().
>
> We have provided generic .mmap_prepare() equivalents, so update all file
> systems that specify these directly in their file_operations structures.
>
> This updates 9p, adfs, affs, bfs, fat, hfs, hfsplus, hostfs, hpfs, jffs2,
> jfs, minix, omfs, ramfs and ufs file systems directly.
>
> It updates generic_ro_fops which impacts qnx4, cramfs, befs, squashfs,
> frebxfs, qnx6, efs, romfs, erofs and isofs file systems.
>
> There are remaining file systems which use generic hooks in a less direct
> way which we address in a subsequent commit.
>
> Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
For JFS,
Acked-by: Dave Kleikamp <dave.kleikamp@oracle.com>
> ---
> fs/9p/vfs_file.c | 2 +-
> fs/adfs/file.c | 2 +-
> fs/affs/file.c | 2 +-
> fs/bfs/file.c | 2 +-
> fs/fat/file.c | 2 +-
> fs/hfs/inode.c | 2 +-
> fs/hfsplus/inode.c | 2 +-
> fs/hostfs/hostfs_kern.c | 2 +-
> fs/hpfs/file.c | 2 +-
> fs/jffs2/file.c | 2 +-
> fs/jfs/file.c | 2 +-
> fs/minix/file.c | 2 +-
> fs/omfs/file.c | 2 +-
> fs/ramfs/file-mmu.c | 2 +-
> fs/read_write.c | 2 +-
> fs/ufs/file.c | 2 +-
> 16 files changed, 16 insertions(+), 16 deletions(-)
>
> diff --git a/fs/9p/vfs_file.c b/fs/9p/vfs_file.c
> index 348cc90bf9c5..2ff3e0ac7266 100644
> --- a/fs/9p/vfs_file.c
> +++ b/fs/9p/vfs_file.c
> @@ -516,7 +516,7 @@ const struct file_operations v9fs_file_operations = {
> .open = v9fs_file_open,
> .release = v9fs_dir_release,
> .lock = v9fs_file_lock,
> - .mmap = generic_file_readonly_mmap,
> + .mmap_prepare = generic_file_readonly_mmap_prepare,
> .splice_read = v9fs_file_splice_read,
> .splice_write = iter_file_splice_write,
> .fsync = v9fs_file_fsync,
> diff --git a/fs/adfs/file.c b/fs/adfs/file.c
> index ee80718aaeec..cd13165fd904 100644
> --- a/fs/adfs/file.c
> +++ b/fs/adfs/file.c
> @@ -25,7 +25,7 @@
> const struct file_operations adfs_file_operations = {
> .llseek = generic_file_llseek,
> .read_iter = generic_file_read_iter,
> - .mmap = generic_file_mmap,
> + .mmap_prepare = generic_file_mmap_prepare,
> .fsync = generic_file_fsync,
> .write_iter = generic_file_write_iter,
> .splice_read = filemap_splice_read,
> diff --git a/fs/affs/file.c b/fs/affs/file.c
> index 7a71018e3f67..fbac204b7055 100644
> --- a/fs/affs/file.c
> +++ b/fs/affs/file.c
> @@ -999,7 +999,7 @@ const struct file_operations affs_file_operations = {
> .llseek = generic_file_llseek,
> .read_iter = generic_file_read_iter,
> .write_iter = generic_file_write_iter,
> - .mmap = generic_file_mmap,
> + .mmap_prepare = generic_file_mmap_prepare,
> .open = affs_file_open,
> .release = affs_file_release,
> .fsync = affs_file_fsync,
> diff --git a/fs/bfs/file.c b/fs/bfs/file.c
> index fa66a09e496a..6685c3411fe7 100644
> --- a/fs/bfs/file.c
> +++ b/fs/bfs/file.c
> @@ -27,7 +27,7 @@ const struct file_operations bfs_file_operations = {
> .llseek = generic_file_llseek,
> .read_iter = generic_file_read_iter,
> .write_iter = generic_file_write_iter,
> - .mmap = generic_file_mmap,
> + .mmap_prepare = generic_file_mmap_prepare,
> .splice_read = filemap_splice_read,
> };
>
> diff --git a/fs/fat/file.c b/fs/fat/file.c
> index e887e9ab7472..4fc49a614fb8 100644
> --- a/fs/fat/file.c
> +++ b/fs/fat/file.c
> @@ -204,7 +204,7 @@ const struct file_operations fat_file_operations = {
> .llseek = generic_file_llseek,
> .read_iter = generic_file_read_iter,
> .write_iter = generic_file_write_iter,
> - .mmap = generic_file_mmap,
> + .mmap_prepare = generic_file_mmap_prepare,
> .release = fat_file_release,
> .unlocked_ioctl = fat_generic_ioctl,
> .compat_ioctl = compat_ptr_ioctl,
> diff --git a/fs/hfs/inode.c b/fs/hfs/inode.c
> index a81ce7a740b9..d419586d668d 100644
> --- a/fs/hfs/inode.c
> +++ b/fs/hfs/inode.c
> @@ -690,7 +690,7 @@ static const struct file_operations hfs_file_operations = {
> .llseek = generic_file_llseek,
> .read_iter = generic_file_read_iter,
> .write_iter = generic_file_write_iter,
> - .mmap = generic_file_mmap,
> + .mmap_prepare = generic_file_mmap_prepare,
> .splice_read = filemap_splice_read,
> .fsync = hfs_file_fsync,
> .open = hfs_file_open,
> diff --git a/fs/hfsplus/inode.c b/fs/hfsplus/inode.c
> index f331e9574217..0af7e302730c 100644
> --- a/fs/hfsplus/inode.c
> +++ b/fs/hfsplus/inode.c
> @@ -366,7 +366,7 @@ static const struct file_operations hfsplus_file_operations = {
> .llseek = generic_file_llseek,
> .read_iter = generic_file_read_iter,
> .write_iter = generic_file_write_iter,
> - .mmap = generic_file_mmap,
> + .mmap_prepare = generic_file_mmap_prepare,
> .splice_read = filemap_splice_read,
> .fsync = hfsplus_file_fsync,
> .open = hfsplus_file_open,
> diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c
> index 702c41317589..bc22b6cc72af 100644
> --- a/fs/hostfs/hostfs_kern.c
> +++ b/fs/hostfs/hostfs_kern.c
> @@ -382,7 +382,7 @@ static const struct file_operations hostfs_file_fops = {
> .splice_write = iter_file_splice_write,
> .read_iter = generic_file_read_iter,
> .write_iter = generic_file_write_iter,
> - .mmap = generic_file_mmap,
> + .mmap_prepare = generic_file_mmap_prepare,
> .open = hostfs_open,
> .release = hostfs_file_release,
> .fsync = hostfs_fsync,
> diff --git a/fs/hpfs/file.c b/fs/hpfs/file.c
> index 449a3fc1b8d9..a1a44e3edb19 100644
> --- a/fs/hpfs/file.c
> +++ b/fs/hpfs/file.c
> @@ -255,7 +255,7 @@ const struct file_operations hpfs_file_ops =
> .llseek = generic_file_llseek,
> .read_iter = generic_file_read_iter,
> .write_iter = generic_file_write_iter,
> - .mmap = generic_file_mmap,
> + .mmap_prepare = generic_file_mmap_prepare,
> .release = hpfs_file_release,
> .fsync = hpfs_file_fsync,
> .splice_read = filemap_splice_read,
> diff --git a/fs/jffs2/file.c b/fs/jffs2/file.c
> index 13c18ccc13b0..1e05f7fe5dd4 100644
> --- a/fs/jffs2/file.c
> +++ b/fs/jffs2/file.c
> @@ -54,7 +54,7 @@ const struct file_operations jffs2_file_operations =
> .read_iter = generic_file_read_iter,
> .write_iter = generic_file_write_iter,
> .unlocked_ioctl=jffs2_ioctl,
> - .mmap = generic_file_readonly_mmap,
> + .mmap_prepare = generic_file_readonly_mmap_prepare,
> .fsync = jffs2_fsync,
> .splice_read = filemap_splice_read,
> .splice_write = iter_file_splice_write,
> diff --git a/fs/jfs/file.c b/fs/jfs/file.c
> index 01b6912e60f8..5e47951db630 100644
> --- a/fs/jfs/file.c
> +++ b/fs/jfs/file.c
> @@ -143,7 +143,7 @@ const struct file_operations jfs_file_operations = {
> .llseek = generic_file_llseek,
> .read_iter = generic_file_read_iter,
> .write_iter = generic_file_write_iter,
> - .mmap = generic_file_mmap,
> + .mmap_prepare = generic_file_mmap_prepare,
> .splice_read = filemap_splice_read,
> .splice_write = iter_file_splice_write,
> .fsync = jfs_fsync,
> diff --git a/fs/minix/file.c b/fs/minix/file.c
> index 906d192ab7f3..dca7ac71f049 100644
> --- a/fs/minix/file.c
> +++ b/fs/minix/file.c
> @@ -17,7 +17,7 @@ const struct file_operations minix_file_operations = {
> .llseek = generic_file_llseek,
> .read_iter = generic_file_read_iter,
> .write_iter = generic_file_write_iter,
> - .mmap = generic_file_mmap,
> + .mmap_prepare = generic_file_mmap_prepare,
> .fsync = generic_file_fsync,
> .splice_read = filemap_splice_read,
> };
> diff --git a/fs/omfs/file.c b/fs/omfs/file.c
> index 98358d405b6a..319c04e63964 100644
> --- a/fs/omfs/file.c
> +++ b/fs/omfs/file.c
> @@ -332,7 +332,7 @@ const struct file_operations omfs_file_operations = {
> .llseek = generic_file_llseek,
> .read_iter = generic_file_read_iter,
> .write_iter = generic_file_write_iter,
> - .mmap = generic_file_mmap,
> + .mmap_prepare = generic_file_mmap_prepare,
> .fsync = generic_file_fsync,
> .splice_read = filemap_splice_read,
> };
> diff --git a/fs/ramfs/file-mmu.c b/fs/ramfs/file-mmu.c
> index b45c7edc3225..b11f5b20b78b 100644
> --- a/fs/ramfs/file-mmu.c
> +++ b/fs/ramfs/file-mmu.c
> @@ -41,7 +41,7 @@ static unsigned long ramfs_mmu_get_unmapped_area(struct file *file,
> const struct file_operations ramfs_file_operations = {
> .read_iter = generic_file_read_iter,
> .write_iter = generic_file_write_iter,
> - .mmap = generic_file_mmap,
> + .mmap_prepare = generic_file_mmap_prepare,
> .fsync = noop_fsync,
> .splice_read = filemap_splice_read,
> .splice_write = iter_file_splice_write,
> diff --git a/fs/read_write.c b/fs/read_write.c
> index 0ef70e128c4a..80fdab99f9e4 100644
> --- a/fs/read_write.c
> +++ b/fs/read_write.c
> @@ -28,7 +28,7 @@
> const struct file_operations generic_ro_fops = {
> .llseek = generic_file_llseek,
> .read_iter = generic_file_read_iter,
> - .mmap = generic_file_readonly_mmap,
> + .mmap_prepare = generic_file_readonly_mmap_prepare,
> .splice_read = filemap_splice_read,
> };
>
> diff --git a/fs/ufs/file.c b/fs/ufs/file.c
> index 487ad1fc2de6..c2a391c17df7 100644
> --- a/fs/ufs/file.c
> +++ b/fs/ufs/file.c
> @@ -38,7 +38,7 @@ const struct file_operations ufs_file_operations = {
> .llseek = generic_file_llseek,
> .read_iter = generic_file_read_iter,
> .write_iter = generic_file_write_iter,
> - .mmap = generic_file_mmap,
> + .mmap_prepare = generic_file_mmap_prepare,
> .open = generic_file_open,
> .fsync = generic_file_fsync,
> .splice_read = filemap_splice_read,
^ permalink raw reply [flat|nested] 50+ messages in thread
* Re: [PATCH 00/10] convert the majority of file systems to mmap_prepare
2025-06-17 14:05 ` David Howells
@ 2025-06-17 14:17 ` Lorenzo Stoakes
0 siblings, 0 replies; 50+ messages in thread
From: Lorenzo Stoakes @ 2025-06-17 14:17 UTC (permalink / raw)
To: David Howells
Cc: Andrew Morton, Liam R . Howlett, Jens Axboe, Jani Nikula,
Joonas Lahtinen, Rodrigo Vivi, Tvrtko Ursulin, David Airlie,
Simona Vetter, Eric Van Hensbergen, Latchesar Ionkov,
Dominique Martinet, Christian Schoenebeck, David Sterba,
Marc Dionne, Alexander Viro, Christian Brauner, Jan Kara,
Benjamin LaHaise, Miklos Szeredi, Amir Goldstein, Kent Overstreet,
Tigran A . Aivazian, Kees Cook, Chris Mason, Josef Bacik,
Xiubo Li, Ilya Dryomov, Jan Harkes, coda, Tyler Hicks, Gao Xiang,
Chao Yu, Yue Hu, Jeffle Xu, Sandeep Dhavale, Hongbo Li,
Namjae Jeon, Sungjong Seo, Yuezhang Mo, Theodore Ts'o,
Andreas Dilger, Jaegeuk Kim, OGAWA Hirofumi, Viacheslav Dubeyko,
John Paul Adrian Glaubitz, Yangtao Li, Richard Weinberger,
Anton Ivanov, Johannes Berg, Mikulas Patocka, David Woodhouse,
Dave Kleikamp, Trond Myklebust, Anna Schumaker, Ryusuke Konishi,
Konstantin Komarov, Mark Fasheh, Joel Becker, Joseph Qi,
Bob Copeland, Mike Marshall, Martin Brandenburg, Steve French,
Paulo Alcantara, Ronnie Sahlberg, Shyam Prasad N, Tom Talpey,
Bharath SM, Zhihao Cheng, Hans de Goede, Carlos Maiolino,
Damien Le Moal, Naohiro Aota, Johannes Thumshirn, Dan Williams,
Matthew Wilcox, Vlastimil Babka, Jann Horn, Pedro Falcato,
linux-block, linux-kernel, intel-gfx, dri-devel, v9fs,
linux-fsdevel, linux-afs, linux-aio, linux-unionfs,
linux-bcachefs, linux-mm, linux-btrfs, ceph-devel, codalist,
ecryptfs, linux-erofs, linux-ext4, linux-f2fs-devel, linux-um,
linux-mtd, jfs-discussion, linux-nfs, linux-nilfs, ntfs3,
ocfs2-devel, linux-karma-devel, devel, linux-cifs,
samba-technical, linux-xfs, nvdimm
On Tue, Jun 17, 2025 at 03:05:59PM +0100, David Howells wrote:
> Lorenzo Stoakes <lorenzo.stoakes@oracle.com> wrote:
>
> > This is preferred to the existing f_op->mmap() hook as it does require a
> > VMA to be established yet,
>
> Did you mean ".. doesn't require a VMA to be established yet, ..."
>
> David
>
Yeah apologies, indeed I did :)
^ permalink raw reply [flat|nested] 50+ messages in thread
* Re: [PATCH 01/10] mm: rename call_mmap/mmap_prepare to vfs_mmap/mmap_prepare
2025-06-16 19:33 ` [PATCH 01/10] mm: rename call_mmap/mmap_prepare to vfs_mmap/mmap_prepare Lorenzo Stoakes
2025-06-17 5:10 ` Christoph Hellwig
@ 2025-06-17 18:57 ` Vlastimil Babka
1 sibling, 0 replies; 50+ messages in thread
From: Vlastimil Babka @ 2025-06-17 18:57 UTC (permalink / raw)
To: Lorenzo Stoakes, Andrew Morton
Cc: Liam R . Howlett, Jens Axboe, Jani Nikula, Joonas Lahtinen,
Rodrigo Vivi, Tvrtko Ursulin, David Airlie, Simona Vetter,
Eric Van Hensbergen, Latchesar Ionkov, Dominique Martinet,
Christian Schoenebeck, David Sterba, David Howells, Marc Dionne,
Alexander Viro, Christian Brauner, Jan Kara, Benjamin LaHaise,
Miklos Szeredi, Amir Goldstein, Kent Overstreet,
Tigran A . Aivazian, Kees Cook, Chris Mason, Josef Bacik,
Xiubo Li, Ilya Dryomov, Jan Harkes, coda, Tyler Hicks, Gao Xiang,
Chao Yu, Yue Hu, Jeffle Xu, Sandeep Dhavale, Hongbo Li,
Namjae Jeon, Sungjong Seo, Yuezhang Mo, Theodore Ts'o,
Andreas Dilger, Jaegeuk Kim, OGAWA Hirofumi, Viacheslav Dubeyko,
John Paul Adrian Glaubitz, Yangtao Li, Richard Weinberger,
Anton Ivanov, Johannes Berg, Mikulas Patocka, David Woodhouse,
Dave Kleikamp, Trond Myklebust, Anna Schumaker, Ryusuke Konishi,
Konstantin Komarov, Mark Fasheh, Joel Becker, Joseph Qi,
Bob Copeland, Mike Marshall, Martin Brandenburg, Steve French,
Paulo Alcantara, Ronnie Sahlberg, Shyam Prasad N, Tom Talpey,
Bharath SM, Zhihao Cheng, Hans de Goede, Carlos Maiolino,
Damien Le Moal, Naohiro Aota, Johannes Thumshirn, Dan Williams,
Matthew Wilcox, Jann Horn, Pedro Falcato, linux-block,
linux-kernel, intel-gfx, dri-devel, v9fs, linux-fsdevel,
linux-afs, linux-aio, linux-unionfs, linux-bcachefs, linux-mm,
linux-btrfs, ceph-devel, codalist, ecryptfs, linux-erofs,
linux-ext4, linux-f2fs-devel, linux-um, linux-mtd, jfs-discussion,
linux-nfs, linux-nilfs, ntfs3, ocfs2-devel, linux-karma-devel,
devel, linux-cifs, samba-technical, linux-xfs, nvdimm
On 6/16/25 21:33, Lorenzo Stoakes wrote:
> The call_mmap() function violates the existing convention in
> include/linux/fs.h whereby invocations of virtual file system hooks is
> performed by functions prefixed with vfs_xxx().
>
> Correct this by renaming call_mmap() to vfs_mmap(). This also avoids
> confusion as to the fact that f_op->mmap_prepare may be invoked here.
>
> Also rename __call_mmap_prepare() function to vfs_mmap_prepare() and adjust
> to accept a file parameter, this is useful later for nested file systems.
>
> Finally, fix up the VMA userland tests and ensure the mmap_prepare -> mmap
> shim is implemented there.
>
> Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Acked-by: Vlastimil Babka <vbabka@suse.cz>
> ---
> drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c | 2 +-
> fs/backing-file.c | 2 +-
> fs/coda/file.c | 4 +--
> include/linux/fs.h | 5 ++--
> ipc/shm.c | 2 +-
> mm/internal.h | 2 +-
> mm/vma.c | 2 +-
> tools/testing/vma/vma_internal.h | 32 ++++++++++++++++++----
> 8 files changed, 35 insertions(+), 16 deletions(-)
>
> diff --git a/drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c b/drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c
> index 05e440643aa2..f4f1c979d1b9 100644
> --- a/drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c
> +++ b/drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c
> @@ -105,7 +105,7 @@ static int i915_gem_dmabuf_mmap(struct dma_buf *dma_buf, struct vm_area_struct *
> if (!obj->base.filp)
> return -ENODEV;
>
> - ret = call_mmap(obj->base.filp, vma);
> + ret = vfs_mmap(obj->base.filp, vma);
> if (ret)
> return ret;
>
> diff --git a/fs/backing-file.c b/fs/backing-file.c
> index 763fbe9b72b2..04018679bf69 100644
> --- a/fs/backing-file.c
> +++ b/fs/backing-file.c
> @@ -339,7 +339,7 @@ int backing_file_mmap(struct file *file, struct vm_area_struct *vma,
> vma_set_file(vma, file);
>
> old_cred = override_creds(ctx->cred);
> - ret = call_mmap(vma->vm_file, vma);
> + ret = vfs_mmap(vma->vm_file, vma);
> revert_creds(old_cred);
>
> if (ctx->accessed)
> diff --git a/fs/coda/file.c b/fs/coda/file.c
> index 148856a582a9..2e6ea9319b35 100644
> --- a/fs/coda/file.c
> +++ b/fs/coda/file.c
> @@ -199,10 +199,10 @@ coda_file_mmap(struct file *coda_file, struct vm_area_struct *vma)
> spin_unlock(&cii->c_lock);
>
> vma->vm_file = get_file(host_file);
> - ret = call_mmap(vma->vm_file, vma);
> + ret = vfs_mmap(vma->vm_file, vma);
>
> if (ret) {
> - /* if call_mmap fails, our caller will put host_file so we
> + /* if vfs_mmap fails, our caller will put host_file so we
> * should drop the reference to the coda_file that we got.
> */
> fput(coda_file);
> diff --git a/include/linux/fs.h b/include/linux/fs.h
> index 93ee0d2d6f1a..7120f80255b3 100644
> --- a/include/linux/fs.h
> +++ b/include/linux/fs.h
> @@ -2278,7 +2278,7 @@ static inline bool file_has_valid_mmap_hooks(struct file *file)
>
> int compat_vma_mmap_prepare(struct file *file, struct vm_area_struct *vma);
>
> -static inline int call_mmap(struct file *file, struct vm_area_struct *vma)
> +static inline int vfs_mmap(struct file *file, struct vm_area_struct *vma)
> {
> if (file->f_op->mmap_prepare)
> return compat_vma_mmap_prepare(file, vma);
> @@ -2286,8 +2286,7 @@ static inline int call_mmap(struct file *file, struct vm_area_struct *vma)
> return file->f_op->mmap(file, vma);
> }
>
> -static inline int __call_mmap_prepare(struct file *file,
> - struct vm_area_desc *desc)
> +static inline int vfs_mmap_prepare(struct file *file, struct vm_area_desc *desc)
> {
> return file->f_op->mmap_prepare(desc);
> }
> diff --git a/ipc/shm.c b/ipc/shm.c
> index 492fcc699985..a9310b6dbbc3 100644
> --- a/ipc/shm.c
> +++ b/ipc/shm.c
> @@ -602,7 +602,7 @@ static int shm_mmap(struct file *file, struct vm_area_struct *vma)
> if (ret)
> return ret;
>
> - ret = call_mmap(sfd->file, vma);
> + ret = vfs_mmap(sfd->file, vma);
> if (ret) {
> __shm_close(sfd);
> return ret;
> diff --git a/mm/internal.h b/mm/internal.h
> index 3823fb356d3b..a55c88afff6d 100644
> --- a/mm/internal.h
> +++ b/mm/internal.h
> @@ -165,7 +165,7 @@ static inline void *folio_raw_mapping(const struct folio *folio)
> */
> static inline int mmap_file(struct file *file, struct vm_area_struct *vma)
> {
> - int err = call_mmap(file, vma);
> + int err = vfs_mmap(file, vma);
>
> if (likely(!err))
> return 0;
> diff --git a/mm/vma.c b/mm/vma.c
> index 5d35adadf2b5..f548bede3bbe 100644
> --- a/mm/vma.c
> +++ b/mm/vma.c
> @@ -2582,7 +2582,7 @@ static int call_mmap_prepare(struct mmap_state *map)
> };
>
> /* Invoke the hook. */
> - err = __call_mmap_prepare(map->file, &desc);
> + err = vfs_mmap_prepare(map->file, &desc);
> if (err)
> return err;
>
> diff --git a/tools/testing/vma/vma_internal.h b/tools/testing/vma/vma_internal.h
> index d7fea56e3bb3..51dd122b8d50 100644
> --- a/tools/testing/vma/vma_internal.h
> +++ b/tools/testing/vma/vma_internal.h
> @@ -1458,6 +1458,27 @@ static inline void free_anon_vma_name(struct vm_area_struct *vma)
> (void)vma;
> }
>
> +/* Declared in vma.h. */
> +static inline void set_vma_from_desc(struct vm_area_struct *vma,
> + struct vm_area_desc *desc);
> +
> +static inline struct vm_area_desc *vma_to_desc(struct vm_area_struct *vma,
> + struct vm_area_desc *desc);
> +
> +static int compat_vma_mmap_prepare(struct file *file,
> + struct vm_area_struct *vma)
> +{
> + struct vm_area_desc desc;
> + int err;
> +
> + err = file->f_op->mmap_prepare(vma_to_desc(vma, &desc));
> + if (err)
> + return err;
> + set_vma_from_desc(vma, &desc);
> +
> + return 0;
> +}
> +
> /* Did the driver provide valid mmap hook configuration? */
> static inline bool file_has_valid_mmap_hooks(struct file *file)
> {
> @@ -1467,22 +1488,21 @@ static inline bool file_has_valid_mmap_hooks(struct file *file)
> /* Hooks are mutually exclusive. */
> if (WARN_ON_ONCE(has_mmap && has_mmap_prepare))
> return false;
> - if (WARN_ON_ONCE(!has_mmap && !has_mmap_prepare))
> + if (!has_mmap && !has_mmap_prepare)
> return false;
>
> return true;
> }
>
> -static inline int call_mmap(struct file *file, struct vm_area_struct *vma)
> +static inline int vfs_mmap(struct file *file, struct vm_area_struct *vma)
> {
> - if (WARN_ON_ONCE(file->f_op->mmap_prepare))
> - return -EINVAL;
> + if (file->f_op->mmap_prepare)
> + return compat_vma_mmap_prepare(file, vma);
>
> return file->f_op->mmap(file, vma);
> }
>
> -static inline int __call_mmap_prepare(struct file *file,
> - struct vm_area_desc *desc)
> +static inline int vfs_mmap_prepare(struct file *file, struct vm_area_desc *desc)
> {
> return file->f_op->mmap_prepare(desc);
> }
^ permalink raw reply [flat|nested] 50+ messages in thread
* Re: [PATCH 02/10] mm/nommu: use file_has_valid_mmap_hooks() helper
2025-06-16 19:33 ` [PATCH 02/10] mm/nommu: use file_has_valid_mmap_hooks() helper Lorenzo Stoakes
2025-06-17 10:05 ` Jan Kara
@ 2025-06-17 18:58 ` Vlastimil Babka
1 sibling, 0 replies; 50+ messages in thread
From: Vlastimil Babka @ 2025-06-17 18:58 UTC (permalink / raw)
To: Lorenzo Stoakes, Andrew Morton
Cc: Liam R . Howlett, Jens Axboe, Jani Nikula, Joonas Lahtinen,
Rodrigo Vivi, Tvrtko Ursulin, David Airlie, Simona Vetter,
Eric Van Hensbergen, Latchesar Ionkov, Dominique Martinet,
Christian Schoenebeck, David Sterba, David Howells, Marc Dionne,
Alexander Viro, Christian Brauner, Jan Kara, Benjamin LaHaise,
Miklos Szeredi, Amir Goldstein, Kent Overstreet,
Tigran A . Aivazian, Kees Cook, Chris Mason, Josef Bacik,
Xiubo Li, Ilya Dryomov, Jan Harkes, coda, Tyler Hicks, Gao Xiang,
Chao Yu, Yue Hu, Jeffle Xu, Sandeep Dhavale, Hongbo Li,
Namjae Jeon, Sungjong Seo, Yuezhang Mo, Theodore Ts'o,
Andreas Dilger, Jaegeuk Kim, OGAWA Hirofumi, Viacheslav Dubeyko,
John Paul Adrian Glaubitz, Yangtao Li, Richard Weinberger,
Anton Ivanov, Johannes Berg, Mikulas Patocka, David Woodhouse,
Dave Kleikamp, Trond Myklebust, Anna Schumaker, Ryusuke Konishi,
Konstantin Komarov, Mark Fasheh, Joel Becker, Joseph Qi,
Bob Copeland, Mike Marshall, Martin Brandenburg, Steve French,
Paulo Alcantara, Ronnie Sahlberg, Shyam Prasad N, Tom Talpey,
Bharath SM, Zhihao Cheng, Hans de Goede, Carlos Maiolino,
Damien Le Moal, Naohiro Aota, Johannes Thumshirn, Dan Williams,
Matthew Wilcox, Jann Horn, Pedro Falcato, linux-block,
linux-kernel, intel-gfx, dri-devel, v9fs, linux-fsdevel,
linux-afs, linux-aio, linux-unionfs, linux-bcachefs, linux-mm,
linux-btrfs, ceph-devel, codalist, ecryptfs, linux-erofs,
linux-ext4, linux-f2fs-devel, linux-um, linux-mtd, jfs-discussion,
linux-nfs, linux-nilfs, ntfs3, ocfs2-devel, linux-karma-devel,
devel, linux-cifs, samba-technical, linux-xfs, nvdimm
On 6/16/25 21:33, Lorenzo Stoakes wrote:
> Since commit c84bf6dd2b83 ("mm: introduce new .mmap_prepare() file
> callback"), the f_op->mmap() hook has been deprecated in favour of
> f_op->mmap_prepare().
>
> Therefore, update the check for file operations supporting mmap() by using
> the file_has_valid_mmap_hooks() helper function, which checks for either
> f_op->mmap or f_op->mmap_prepare rather than checking only for f_op->mmap
> directly.
>
> Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Acked-by: Vlastimil Babka <vbabka@suse.cz>
> ---
> mm/nommu.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/mm/nommu.c b/mm/nommu.c
> index b624acec6d2e..38c22ea0a95c 100644
> --- a/mm/nommu.c
> +++ b/mm/nommu.c
> @@ -719,7 +719,7 @@ static int validate_mmap_request(struct file *file,
>
> if (file) {
> /* files must support mmap */
> - if (!file->f_op->mmap)
> + if (!file_has_valid_mmap_hooks(file))
> return -ENODEV;
>
> /* work out if what we've got could possibly be shared
^ permalink raw reply [flat|nested] 50+ messages in thread
* Re: [PATCH 07/10] mm/filemap: introduce generic_file_*_mmap_prepare() helpers
2025-06-16 19:33 ` [PATCH 07/10] mm/filemap: introduce generic_file_*_mmap_prepare() helpers Lorenzo Stoakes
2025-06-17 10:12 ` Jan Kara
@ 2025-06-17 19:00 ` Vlastimil Babka
1 sibling, 0 replies; 50+ messages in thread
From: Vlastimil Babka @ 2025-06-17 19:00 UTC (permalink / raw)
To: Lorenzo Stoakes, Andrew Morton
Cc: Liam R . Howlett, Jens Axboe, Jani Nikula, Joonas Lahtinen,
Rodrigo Vivi, Tvrtko Ursulin, David Airlie, Simona Vetter,
Eric Van Hensbergen, Latchesar Ionkov, Dominique Martinet,
Christian Schoenebeck, David Sterba, David Howells, Marc Dionne,
Alexander Viro, Christian Brauner, Jan Kara, Benjamin LaHaise,
Miklos Szeredi, Amir Goldstein, Kent Overstreet,
Tigran A . Aivazian, Kees Cook, Chris Mason, Josef Bacik,
Xiubo Li, Ilya Dryomov, Jan Harkes, coda, Tyler Hicks, Gao Xiang,
Chao Yu, Yue Hu, Jeffle Xu, Sandeep Dhavale, Hongbo Li,
Namjae Jeon, Sungjong Seo, Yuezhang Mo, Theodore Ts'o,
Andreas Dilger, Jaegeuk Kim, OGAWA Hirofumi, Viacheslav Dubeyko,
John Paul Adrian Glaubitz, Yangtao Li, Richard Weinberger,
Anton Ivanov, Johannes Berg, Mikulas Patocka, David Woodhouse,
Dave Kleikamp, Trond Myklebust, Anna Schumaker, Ryusuke Konishi,
Konstantin Komarov, Mark Fasheh, Joel Becker, Joseph Qi,
Bob Copeland, Mike Marshall, Martin Brandenburg, Steve French,
Paulo Alcantara, Ronnie Sahlberg, Shyam Prasad N, Tom Talpey,
Bharath SM, Zhihao Cheng, Hans de Goede, Carlos Maiolino,
Damien Le Moal, Naohiro Aota, Johannes Thumshirn, Dan Williams,
Matthew Wilcox, Jann Horn, Pedro Falcato, linux-block,
linux-kernel, intel-gfx, dri-devel, v9fs, linux-fsdevel,
linux-afs, linux-aio, linux-unionfs, linux-bcachefs, linux-mm,
linux-btrfs, ceph-devel, codalist, ecryptfs, linux-erofs,
linux-ext4, linux-f2fs-devel, linux-um, linux-mtd, jfs-discussion,
linux-nfs, linux-nilfs, ntfs3, ocfs2-devel, linux-karma-devel,
devel, linux-cifs, samba-technical, linux-xfs, nvdimm
On 6/16/25 21:33, Lorenzo Stoakes wrote:
> Since commit c84bf6dd2b83 ("mm: introduce new .mmap_prepare() file
> callback"), the f_op->mmap() hook has been deprecated in favour of
> f_op->mmap_prepare().
>
> The generic mmap handlers are very simple, so we can very easily convert
> these in advance of converting file systems which use them.
>
> This patch does so.
>
> Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Acked-by: Vlastimil Babka <vbabka@suse.cz>
> ---
> include/linux/fs.h | 6 ++++--
> mm/filemap.c | 29 +++++++++++++++++++++++++++++
> 2 files changed, 33 insertions(+), 2 deletions(-)
>
> diff --git a/include/linux/fs.h b/include/linux/fs.h
> index 7120f80255b3..65cffc445fcc 100644
> --- a/include/linux/fs.h
> +++ b/include/linux/fs.h
> @@ -3395,8 +3395,10 @@ extern void inode_add_lru(struct inode *inode);
> extern int sb_set_blocksize(struct super_block *, int);
> extern int sb_min_blocksize(struct super_block *, int);
>
> -extern int generic_file_mmap(struct file *, struct vm_area_struct *);
> -extern int generic_file_readonly_mmap(struct file *, struct vm_area_struct *);
> +int generic_file_mmap(struct file *, struct vm_area_struct *);
> +int generic_file_mmap_prepare(struct vm_area_desc *desc);
> +int generic_file_readonly_mmap(struct file *, struct vm_area_struct *);
> +int generic_file_readonly_mmap_prepare(struct vm_area_desc *desc);
> extern ssize_t generic_write_checks(struct kiocb *, struct iov_iter *);
> int generic_write_checks_count(struct kiocb *iocb, loff_t *count);
> extern int generic_write_check_limits(struct file *file, loff_t pos,
> diff --git a/mm/filemap.c b/mm/filemap.c
> index 93fbc2ef232a..e75608cbf420 100644
> --- a/mm/filemap.c
> +++ b/mm/filemap.c
> @@ -3847,6 +3847,18 @@ int generic_file_mmap(struct file *file, struct vm_area_struct *vma)
> return 0;
> }
>
> +int generic_file_mmap_prepare(struct vm_area_desc *desc)
> +{
> + struct file *file = desc->file;
> + struct address_space *mapping = file->f_mapping;
> +
> + if (!mapping->a_ops->read_folio)
> + return -ENOEXEC;
> + file_accessed(file);
> + desc->vm_ops = &generic_file_vm_ops;
> + return 0;
> +}
> +
> /*
> * This is for filesystems which do not implement ->writepage.
> */
> @@ -3856,6 +3868,13 @@ int generic_file_readonly_mmap(struct file *file, struct vm_area_struct *vma)
> return -EINVAL;
> return generic_file_mmap(file, vma);
> }
> +
> +int generic_file_readonly_mmap_prepare(struct vm_area_desc *desc)
> +{
> + if (is_shared_maywrite(desc->vm_flags))
> + return -EINVAL;
> + return generic_file_mmap_prepare(desc);
> +}
> #else
> vm_fault_t filemap_page_mkwrite(struct vm_fault *vmf)
> {
> @@ -3865,15 +3884,25 @@ int generic_file_mmap(struct file *file, struct vm_area_struct *vma)
> {
> return -ENOSYS;
> }
> +int generic_file_mmap_prepare(struct vm_area_desc *desc)
> +{
> + return -ENOSYS;
> +}
> int generic_file_readonly_mmap(struct file *file, struct vm_area_struct *vma)
> {
> return -ENOSYS;
> }
> +int generic_file_readonly_mmap_prepare(struct vm_area_desc *desc)
> +{
> + return -ENOSYS;
> +}
> #endif /* CONFIG_MMU */
>
> EXPORT_SYMBOL(filemap_page_mkwrite);
> EXPORT_SYMBOL(generic_file_mmap);
> +EXPORT_SYMBOL(generic_file_mmap_prepare);
> EXPORT_SYMBOL(generic_file_readonly_mmap);
> +EXPORT_SYMBOL(generic_file_readonly_mmap_prepare);
>
> static struct folio *do_read_cache_folio(struct address_space *mapping,
> pgoff_t index, filler_t filler, struct file *file, gfp_t gfp)
^ permalink raw reply [flat|nested] 50+ messages in thread
* Re: [PATCH 10/10] fs: replace mmap hook with .mmap_prepare for simple mappings
2025-06-16 19:33 ` [PATCH 10/10] fs: replace mmap hook with .mmap_prepare for simple mappings Lorenzo Stoakes
` (2 preceding siblings ...)
2025-06-17 10:28 ` Jan Kara
@ 2025-06-18 17:06 ` David Sterba
2025-06-19 17:47 ` Ryusuke Konishi
4 siblings, 0 replies; 50+ messages in thread
From: David Sterba @ 2025-06-18 17:06 UTC (permalink / raw)
To: Lorenzo Stoakes
Cc: Andrew Morton, Liam R . Howlett, Jens Axboe, Jani Nikula,
Joonas Lahtinen, Rodrigo Vivi, Tvrtko Ursulin, David Airlie,
Simona Vetter, Eric Van Hensbergen, Latchesar Ionkov,
Dominique Martinet, Christian Schoenebeck, David Sterba,
David Howells, Marc Dionne, Alexander Viro, Christian Brauner,
Jan Kara, Benjamin LaHaise, Miklos Szeredi, Amir Goldstein,
Kent Overstreet, Tigran A . Aivazian, Kees Cook, Chris Mason,
Josef Bacik, Xiubo Li, Ilya Dryomov, Jan Harkes, coda,
Tyler Hicks, Gao Xiang, Chao Yu, Yue Hu, Jeffle Xu,
Sandeep Dhavale, Hongbo Li, Namjae Jeon, Sungjong Seo,
Yuezhang Mo, Theodore Ts'o, Andreas Dilger, Jaegeuk Kim,
OGAWA Hirofumi, Viacheslav Dubeyko, John Paul Adrian Glaubitz,
Yangtao Li, Richard Weinberger, Anton Ivanov, Johannes Berg,
Mikulas Patocka, David Woodhouse, Dave Kleikamp, Trond Myklebust,
Anna Schumaker, Ryusuke Konishi, Konstantin Komarov, Mark Fasheh,
Joel Becker, Joseph Qi, Bob Copeland, Mike Marshall,
Martin Brandenburg, Steve French, Paulo Alcantara,
Ronnie Sahlberg, Shyam Prasad N, Tom Talpey, Bharath SM,
Zhihao Cheng, Hans de Goede, Carlos Maiolino, Damien Le Moal,
Naohiro Aota, Johannes Thumshirn, Dan Williams, Matthew Wilcox,
Vlastimil Babka, Jann Horn, Pedro Falcato, linux-block,
linux-kernel, intel-gfx, dri-devel, v9fs, linux-fsdevel,
linux-afs, linux-aio, linux-unionfs, linux-bcachefs, linux-mm,
linux-btrfs, ceph-devel, codalist, ecryptfs, linux-erofs,
linux-ext4, linux-f2fs-devel, linux-um, linux-mtd, jfs-discussion,
linux-nfs, linux-nilfs, ntfs3, ocfs2-devel, linux-karma-devel,
devel, linux-cifs, samba-technical, linux-xfs, nvdimm
On Mon, Jun 16, 2025 at 08:33:29PM +0100, Lorenzo Stoakes wrote:
> Since commit c84bf6dd2b83 ("mm: introduce new .mmap_prepare() file
> callback"), the f_op->mmap() hook has been deprecated in favour of
> f_op->mmap_prepare().
>
> This callback is invoked in the mmap() logic far earlier, so error handling
> can be performed more safely without complicated and bug-prone state
> unwinding required should an error arise.
>
> This hook also avoids passing a pointer to a not-yet-correctly-established
> VMA avoiding any issues with referencing this data structure.
>
> It rather provides a pointer to the new struct vm_area_desc descriptor type
> which contains all required state and allows easy setting of required
> parameters without any consideration needing to be paid to locking or
> reference counts.
>
> Note that nested filesystems like overlayfs are compatible with an
> .mmap_prepare() callback since commit bb666b7c2707 ("mm: add mmap_prepare()
> compatibility layer for nested file systems").
>
> In this patch we apply this change to file systems with relatively simple
> mmap() hook logic - exfat, ceph, f2fs, bcachefs, zonefs, btrfs, ocfs2,
> orangefs, nilfs2, romfs, ramfs and aio.
>
> Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
> ---
For
> fs/btrfs/file.c | 7 ++++---
Acked-by: David Sterba <dsterba@suse.com>
^ permalink raw reply [flat|nested] 50+ messages in thread
* Re: [PATCH 10/10] fs: replace mmap hook with .mmap_prepare for simple mappings
2025-06-16 19:33 ` [PATCH 10/10] fs: replace mmap hook with .mmap_prepare for simple mappings Lorenzo Stoakes
` (3 preceding siblings ...)
2025-06-18 17:06 ` David Sterba
@ 2025-06-19 17:47 ` Ryusuke Konishi
4 siblings, 0 replies; 50+ messages in thread
From: Ryusuke Konishi @ 2025-06-19 17:47 UTC (permalink / raw)
To: Lorenzo Stoakes
Cc: Andrew Morton, Liam R . Howlett, Jens Axboe, Jani Nikula,
Joonas Lahtinen, Rodrigo Vivi, Tvrtko Ursulin, David Airlie,
Simona Vetter, Eric Van Hensbergen, Latchesar Ionkov,
Dominique Martinet, Christian Schoenebeck, David Sterba,
David Howells, Marc Dionne, Alexander Viro, Christian Brauner,
Jan Kara, Benjamin LaHaise, Miklos Szeredi, Amir Goldstein,
Kent Overstreet, Tigran A . Aivazian, Kees Cook, Chris Mason,
Josef Bacik, Xiubo Li, Ilya Dryomov, Jan Harkes, coda,
Tyler Hicks, Gao Xiang, Chao Yu, Yue Hu, Jeffle Xu,
Sandeep Dhavale, Hongbo Li, Namjae Jeon, Sungjong Seo,
Yuezhang Mo, Theodore Ts'o, Andreas Dilger, Jaegeuk Kim,
OGAWA Hirofumi, Viacheslav Dubeyko, John Paul Adrian Glaubitz,
Yangtao Li, Richard Weinberger, Anton Ivanov, Johannes Berg,
Mikulas Patocka, David Woodhouse, Dave Kleikamp, Trond Myklebust,
Anna Schumaker, Konstantin Komarov, Mark Fasheh, Joel Becker,
Joseph Qi, Bob Copeland, Mike Marshall, Martin Brandenburg,
Steve French, Paulo Alcantara, Ronnie Sahlberg, Shyam Prasad N,
Tom Talpey, Bharath SM, Zhihao Cheng, Hans de Goede,
Carlos Maiolino, Damien Le Moal, Naohiro Aota, Johannes Thumshirn,
Dan Williams, Matthew Wilcox, Vlastimil Babka, Jann Horn,
Pedro Falcato, linux-block, linux-kernel, intel-gfx, dri-devel,
v9fs, linux-fsdevel, linux-afs, linux-aio, linux-unionfs,
linux-bcachefs, linux-mm, linux-btrfs, ceph-devel, codalist,
ecryptfs, linux-erofs, linux-ext4, linux-f2fs-devel, linux-um,
linux-mtd, jfs-discussion, linux-nfs, linux-nilfs, ntfs3,
ocfs2-devel, linux-karma-devel, devel, linux-cifs,
samba-technical, linux-xfs, nvdimm
On Tue, Jun 17, 2025 at 4:48 AM Lorenzo Stoakes wrote:
>
> Since commit c84bf6dd2b83 ("mm: introduce new .mmap_prepare() file
> callback"), the f_op->mmap() hook has been deprecated in favour of
> f_op->mmap_prepare().
>
> This callback is invoked in the mmap() logic far earlier, so error handling
> can be performed more safely without complicated and bug-prone state
> unwinding required should an error arise.
>
> This hook also avoids passing a pointer to a not-yet-correctly-established
> VMA avoiding any issues with referencing this data structure.
>
> It rather provides a pointer to the new struct vm_area_desc descriptor type
> which contains all required state and allows easy setting of required
> parameters without any consideration needing to be paid to locking or
> reference counts.
>
> Note that nested filesystems like overlayfs are compatible with an
> .mmap_prepare() callback since commit bb666b7c2707 ("mm: add mmap_prepare()
> compatibility layer for nested file systems").
>
> In this patch we apply this change to file systems with relatively simple
> mmap() hook logic - exfat, ceph, f2fs, bcachefs, zonefs, btrfs, ocfs2,
> orangefs, nilfs2, romfs, ramfs and aio.
>
> Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
For nilfs2,
Acked-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
Thanks,
Ryusuke Konishi
^ permalink raw reply [flat|nested] 50+ messages in thread
* Re: [PATCH 00/10] convert the majority of file systems to mmap_prepare
2025-06-16 19:33 [PATCH 00/10] convert the majority of file systems to mmap_prepare Lorenzo Stoakes
` (14 preceding siblings ...)
2025-06-17 14:05 ` David Howells
@ 2025-08-01 14:00 ` Jason Gunthorpe
15 siblings, 0 replies; 50+ messages in thread
From: Jason Gunthorpe @ 2025-08-01 14:00 UTC (permalink / raw)
To: Lorenzo Stoakes
Cc: Andrew Morton, Liam R . Howlett, Jens Axboe, Jani Nikula,
Joonas Lahtinen, Rodrigo Vivi, Tvrtko Ursulin, David Airlie,
Simona Vetter, Eric Van Hensbergen, Latchesar Ionkov,
Dominique Martinet, Christian Schoenebeck, David Sterba,
David Howells, Marc Dionne, Alexander Viro, Christian Brauner,
Jan Kara, Benjamin LaHaise, Miklos Szeredi, Amir Goldstein,
Kent Overstreet, Tigran A . Aivazian, Kees Cook, Chris Mason,
Josef Bacik, Xiubo Li, Ilya Dryomov, Jan Harkes, coda,
Tyler Hicks, Gao Xiang, Chao Yu, Yue Hu, Jeffle Xu,
Sandeep Dhavale, Hongbo Li, Namjae Jeon, Sungjong Seo,
Yuezhang Mo, Theodore Ts'o, Andreas Dilger, Jaegeuk Kim,
OGAWA Hirofumi, Viacheslav Dubeyko, John Paul Adrian Glaubitz,
Yangtao Li, Richard Weinberger, Anton Ivanov, Johannes Berg,
Mikulas Patocka, David Woodhouse, Dave Kleikamp, Trond Myklebust,
Anna Schumaker, Ryusuke Konishi, Konstantin Komarov, Mark Fasheh,
Joel Becker, Joseph Qi, Bob Copeland, Mike Marshall,
Martin Brandenburg, Steve French, Paulo Alcantara,
Ronnie Sahlberg, Shyam Prasad N, Tom Talpey, Bharath SM,
Zhihao Cheng, Hans de Goede, Carlos Maiolino, Damien Le Moal,
Naohiro Aota, Johannes Thumshirn, Dan Williams, Matthew Wilcox,
Vlastimil Babka, Jann Horn, Pedro Falcato, linux-block,
linux-kernel, intel-gfx, dri-devel, v9fs, linux-fsdevel,
linux-afs, linux-aio, linux-unionfs, linux-bcachefs, linux-mm,
linux-btrfs, ceph-devel, codalist, ecryptfs, linux-erofs,
linux-ext4, linux-f2fs-devel, linux-um, linux-mtd, jfs-discussion,
linux-nfs, linux-nilfs, ntfs3, ocfs2-devel, linux-karma-devel,
devel, linux-cifs, samba-technical, linux-xfs, nvdimm
On Mon, Jun 16, 2025 at 08:33:19PM +0100, Lorenzo Stoakes wrote:
> The intent is to gradually deprecate f_op->mmap, and in that vein this
> series coverts the majority of file systems to using f_op->mmap_prepare.
I saw this on lwn and just wanted to give a little bit of thought on
this topic..
It looks to me like we need some more infrastructure to convert
anything that uses remap_pfn/etc in the mmap() callback
I would like to suggest we add a vma->prepopulate() callback which is
where the remap_pfn should go. Once the VMA is finalized and fully
operational the vma_ops have the opportunity to prepopulate any PTEs.
This could then actually be locked properly so it is safe with
concurrent unmap_mapping_range() (current mmap callback is not safe)
Jason
^ permalink raw reply [flat|nested] 50+ messages in thread
end of thread, other threads:[~2025-08-01 14:01 UTC | newest]
Thread overview: 50+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-16 19:33 [PATCH 00/10] convert the majority of file systems to mmap_prepare Lorenzo Stoakes
2025-06-16 19:33 ` [PATCH 01/10] mm: rename call_mmap/mmap_prepare to vfs_mmap/mmap_prepare Lorenzo Stoakes
2025-06-17 5:10 ` Christoph Hellwig
2025-06-17 5:29 ` Lorenzo Stoakes
2025-06-17 18:57 ` Vlastimil Babka
2025-06-16 19:33 ` [PATCH 02/10] mm/nommu: use file_has_valid_mmap_hooks() helper Lorenzo Stoakes
2025-06-17 10:05 ` Jan Kara
2025-06-17 18:58 ` Vlastimil Babka
2025-06-16 19:33 ` [PATCH 03/10] fs: consistently " Lorenzo Stoakes
2025-06-16 20:01 ` Kees Cook
2025-06-17 5:11 ` Christoph Hellwig
2025-06-17 5:25 ` Lorenzo Stoakes
2025-06-17 5:29 ` Christoph Hellwig
2025-06-17 10:08 ` Jan Kara
2025-06-17 11:48 ` Christian Brauner
2025-06-16 19:33 ` [PATCH 04/10] fs/dax: make it possible to check dev dax support without a VMA Lorenzo Stoakes
2025-06-16 20:26 ` Matthew Wilcox
2025-06-17 11:43 ` Christian Brauner
2025-06-16 19:33 ` [PATCH 05/10] fs/ext4: transition from deprecated .mmap hook to .mmap_prepare Lorenzo Stoakes
2025-06-17 10:11 ` Jan Kara
2025-06-16 19:33 ` [PATCH 06/10] fs/xfs: " Lorenzo Stoakes
2025-06-17 5:08 ` Christoph Hellwig
2025-06-17 11:45 ` Christian Brauner
2025-06-16 19:33 ` [PATCH 07/10] mm/filemap: introduce generic_file_*_mmap_prepare() helpers Lorenzo Stoakes
2025-06-17 10:12 ` Jan Kara
2025-06-17 19:00 ` Vlastimil Babka
2025-06-16 19:33 ` [PATCH 08/10] fs: convert simple use of generic_file_*_mmap() to .mmap_prepare() Lorenzo Stoakes
2025-06-16 23:26 ` Viacheslav Dubeyko
2025-06-17 10:14 ` Jan Kara
2025-06-17 14:07 ` Dave Kleikamp
2025-06-16 19:33 ` [PATCH 09/10] fs: convert most other generic_file_*mmap() users " Lorenzo Stoakes
2025-06-17 10:23 ` Jan Kara
2025-06-17 11:54 ` Christian Brauner
2025-06-16 19:33 ` [PATCH 10/10] fs: replace mmap hook with .mmap_prepare for simple mappings Lorenzo Stoakes
2025-06-16 22:51 ` Damien Le Moal
2025-06-16 23:24 ` Viacheslav Dubeyko
2025-06-17 10:28 ` Jan Kara
2025-06-17 11:57 ` Christian Brauner
2025-06-18 17:06 ` David Sterba
2025-06-19 17:47 ` Ryusuke Konishi
2025-06-16 19:56 ` [PATCH 00/10] convert the majority of file systems to mmap_prepare Kent Overstreet
2025-06-16 20:41 ` Al Viro
2025-06-17 13:45 ` Jeff Layton
2025-06-17 13:46 ` Lorenzo Stoakes
2025-06-16 23:11 ` Andrew Morton
2025-06-17 11:31 ` Christian Brauner
2025-06-17 11:58 ` Christian Brauner
2025-06-17 14:05 ` David Howells
2025-06-17 14:17 ` Lorenzo Stoakes
2025-08-01 14:00 ` Jason Gunthorpe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).