]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
mm: rename call_mmap/mmap_prepare to vfs_mmap/mmap_prepare
authorLorenzo Stoakes <lorenzo.stoakes@oracle.com>
Mon, 16 Jun 2025 19:33:20 +0000 (20:33 +0100)
committerChristian Brauner <brauner@kernel.org>
Tue, 17 Jun 2025 11:35:23 +0000 (13:35 +0200)
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>
Link: https://lore.kernel.org/8d389f4994fa736aa8f9172bef8533c10a9e9011.1750099179.git.lorenzo.stoakes@oracle.com
Signed-off-by: Christian Brauner <brauner@kernel.org>
drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c
fs/backing-file.c
fs/coda/file.c
include/linux/fs.h
ipc/shm.c
mm/internal.h
mm/vma.c
tools/testing/vma/vma_internal.h

index 05e440643aa2f3df58ff2ad78e4d43a55478525e..f4f1c979d1b9ca2a47872af4baa1fb61efd185b8 100644 (file)
@@ -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;
 
index 763fbe9b72b22753a5b90ac673b10ebb2527403f..04018679bf69bc265a56152c2e4b2212eff62609 100644 (file)
@@ -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)
index 148856a582a960a95ed0190886307c0805faa3b3..2e6ea9319b353e5fdc4c5829983c98998ec6237c 100644 (file)
@@ -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);
index 4ec77da65f144f0a5c8fa775b2c7e982787380b9..c66f235f9e4de77857dce3d45be0dd1822bb0376 100644 (file)
@@ -2276,7 +2276,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);
@@ -2284,8 +2284,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);
 }
index 492fcc6999857a30b8c2e1c98f550ba9b9e81e5e..a9310b6dbbc369ee4089645fdb103666a8e8a859 100644 (file)
--- 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;
index 6b8ed20177432581deb86bb8664ef968f3665a3f..0f73ff13c2121af835813d911e1bb2e47990729c 100644 (file)
@@ -164,7 +164,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;
index fef67a66a09591d81bc99af773eb06b13cdeefba..535b138e26c1d734c424ba59c91d2b9ce2857218 100644 (file)
--- a/mm/vma.c
+++ b/mm/vma.c
@@ -2569,7 +2569,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;
 
index 14718ca23a05bb96575f88bfb9944915672281c5..7ab04700470ff51262f8a995082d4f3fcca14cea 100644 (file)
@@ -1442,6 +1442,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)
 {
@@ -1451,22 +1472,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);
 }