]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
Merge tag 'vfs-6.17-rc1.mmap_prepare' of git://git.kernel.org/pub/scm/linux/kernel...
authorLinus Torvalds <torvalds@linux-foundation.org>
Mon, 28 Jul 2025 20:43:25 +0000 (13:43 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Mon, 28 Jul 2025 20:43:25 +0000 (13:43 -0700)
Pull mmap_prepare updates from Christian Brauner:
 "Last cycle we introduce f_op->mmap_prepare() in c84bf6dd2b83 ("mm:
  introduce new .mmap_prepare() file callback").

  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"

* tag 'vfs-6.17-rc1.mmap_prepare' of git://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs:
  doc: update porting, vfs documentation to describe mmap_prepare()
  fs: replace mmap hook with .mmap_prepare for simple mappings
  fs: convert most other generic_file_*mmap() users to .mmap_prepare()
  fs: convert simple use of generic_file_*_mmap() to .mmap_prepare()
  mm/filemap: introduce generic_file_*_mmap_prepare() helpers
  fs/xfs: transition from deprecated .mmap hook to .mmap_prepare
  fs/ext4: transition from deprecated .mmap hook to .mmap_prepare
  fs/dax: make it possible to check dev dax support without a VMA
  fs: consistently use can_mmap_file() helper
  mm/nommu: use file_has_valid_mmap_hooks() helper
  mm: rename call_mmap/mmap_prepare to vfs_mmap/mmap_prepare

29 files changed:
1  2 
Documentation/filesystems/porting.rst
Documentation/filesystems/vfs.rst
block/fops.c
fs/affs/file.c
fs/backing-file.c
fs/bcachefs/fs.c
fs/bfs/file.c
fs/btrfs/file.c
fs/ceph/addr.c
fs/erofs/data.c
fs/exfat/file.c
fs/ext4/file.c
fs/f2fs/file.c
fs/hfs/inode.c
fs/hfsplus/inode.c
fs/hostfs/hostfs_kern.c
fs/hpfs/file.c
fs/jffs2/file.c
fs/nfs/file.c
fs/ntfs3/file.c
fs/omfs/file.c
fs/read_write.c
fs/smb/client/cifsfs.c
fs/smb/client/file.c
fs/ubifs/file.c
fs/vboxsf/file.c
fs/xfs/xfs_file.c
include/linux/fs.h
mm/filemap.c

index 4f34749126f50c1ce85efa633271adbeefca7835,48fff4c407f3217470c89be055ee6c97d47fc43c..85f590254f07504e9fc7152a3a1abec8d55ef96b
@@@ -1249,27 -1252,12 +1249,39 @@@ an extra reference to new mount - it sh
  
  ---
  
 +collect_mounts()/drop_collected_mounts()/iterate_mounts() are gone now.
 +Replacement is collect_paths()/drop_collected_path(), with no special
 +iterator needed.  Instead of a cloned mount tree, the new interface returns
 +an array of struct path, one for each mount collect_mounts() would've
 +created.  These struct path point to locations in the caller's namespace
 +that would be roots of the cloned mounts.
 +
 +---
 +
 +**mandatory**
 +
 +If your filesystem sets the default dentry_operations, use set_default_d_op()
 +rather than manually setting sb->s_d_op.
 +
 +---
 +
 +**mandatory**
 +
 +d_set_d_op() is no longer exported (or public, for that matter); _if_
 +your filesystem really needed that, make use of d_splice_alias_ops()
 +to have them set.  Better yet, think hard whether you need different
 +->d_op for different dentries - if not, just use set_default_d_op()
 +at mount time and be done with that.  Currently procfs is the only
 +thing that really needs ->d_op varying between dentries.
++
++---
++
+ **highly recommended**
+ The file operations mmap() callback is deprecated in favour of
+ mmap_prepare(). This passes a pointer to a vm_area_desc to the callback
+ rather than a VMA, as the VMA at this stage is not yet valid.
+ The vm_area_desc provides the minimum required information for a filesystem
+ to initialise state upon memory mapping of a file-backed region, and output
+ parameters for the file system to set this state.
Simple merge
diff --cc block/fops.c
Simple merge
diff --cc fs/affs/file.c
Simple merge
Simple merge
Simple merge
diff --cc fs/bfs/file.c
Simple merge
diff --cc fs/btrfs/file.c
Simple merge
diff --cc fs/ceph/addr.c
Simple merge
diff --cc fs/erofs/data.c
Simple merge
diff --cc fs/exfat/file.c
Simple merge
diff --cc fs/ext4/file.c
Simple merge
diff --cc fs/f2fs/file.c
Simple merge
diff --cc fs/hfs/inode.c
Simple merge
Simple merge
Simple merge
diff --cc fs/hpfs/file.c
Simple merge
diff --cc fs/jffs2/file.c
Simple merge
diff --cc fs/nfs/file.c
Simple merge
diff --cc fs/ntfs3/file.c
index c12ae1fb8b370c6eadf9c14d8027929bcd9535c3,7f2ec1c7106cdc3d83fe37df5dfe826f49b5cbc9..c1ece707b19511aad66fb3fd4695c29572c88736
@@@ -269,20 -261,17 +269,21 @@@ out
  }
  
  /*
-  * 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;
  
 +      /* Avoid any operation if inode is bad. */
 +      if (unlikely(is_bad_ni(ni)))
 +              return -EINVAL;
 +
        if (unlikely(ntfs3_forced_shutdown(inode->i_sb)))
                return -EIO;
  
diff --cc fs/omfs/file.c
Simple merge
diff --cc fs/read_write.c
Simple merge
Simple merge
Simple merge
diff --cc fs/ubifs/file.c
Simple merge
Simple merge
Simple merge
Simple merge
diff --cc mm/filemap.c
Simple merge