Skip to content

Commit 20ca475

Browse files
lorenzo-stoakesbrauner
authored andcommitted
mm: rename call_mmap/mmap_prepare to vfs_mmap/mmap_prepare
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>
1 parent e04c78d commit 20ca475

File tree

8 files changed

+35
-16
lines changed

8 files changed

+35
-16
lines changed

drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ static int i915_gem_dmabuf_mmap(struct dma_buf *dma_buf, struct vm_area_struct *
105105
if (!obj->base.filp)
106106
return -ENODEV;
107107

108-
ret = call_mmap(obj->base.filp, vma);
108+
ret = vfs_mmap(obj->base.filp, vma);
109109
if (ret)
110110
return ret;
111111

fs/backing-file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ int backing_file_mmap(struct file *file, struct vm_area_struct *vma,
339339
vma_set_file(vma, file);
340340

341341
old_cred = override_creds(ctx->cred);
342-
ret = call_mmap(vma->vm_file, vma);
342+
ret = vfs_mmap(vma->vm_file, vma);
343343
revert_creds(old_cred);
344344

345345
if (ctx->accessed)

fs/coda/file.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,10 @@ coda_file_mmap(struct file *coda_file, struct vm_area_struct *vma)
199199
spin_unlock(&cii->c_lock);
200200

201201
vma->vm_file = get_file(host_file);
202-
ret = call_mmap(vma->vm_file, vma);
202+
ret = vfs_mmap(vma->vm_file, vma);
203203

204204
if (ret) {
205-
/* if call_mmap fails, our caller will put host_file so we
205+
/* if vfs_mmap fails, our caller will put host_file so we
206206
* should drop the reference to the coda_file that we got.
207207
*/
208208
fput(coda_file);

include/linux/fs.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2276,16 +2276,15 @@ static inline bool file_has_valid_mmap_hooks(struct file *file)
22762276

22772277
int compat_vma_mmap_prepare(struct file *file, struct vm_area_struct *vma);
22782278

2279-
static inline int call_mmap(struct file *file, struct vm_area_struct *vma)
2279+
static inline int vfs_mmap(struct file *file, struct vm_area_struct *vma)
22802280
{
22812281
if (file->f_op->mmap_prepare)
22822282
return compat_vma_mmap_prepare(file, vma);
22832283

22842284
return file->f_op->mmap(file, vma);
22852285
}
22862286

2287-
static inline int __call_mmap_prepare(struct file *file,
2288-
struct vm_area_desc *desc)
2287+
static inline int vfs_mmap_prepare(struct file *file, struct vm_area_desc *desc)
22892288
{
22902289
return file->f_op->mmap_prepare(desc);
22912290
}

ipc/shm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ static int shm_mmap(struct file *file, struct vm_area_struct *vma)
602602
if (ret)
603603
return ret;
604604

605-
ret = call_mmap(sfd->file, vma);
605+
ret = vfs_mmap(sfd->file, vma);
606606
if (ret) {
607607
__shm_close(sfd);
608608
return ret;

mm/internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ static inline void *folio_raw_mapping(const struct folio *folio)
164164
*/
165165
static inline int mmap_file(struct file *file, struct vm_area_struct *vma)
166166
{
167-
int err = call_mmap(file, vma);
167+
int err = vfs_mmap(file, vma);
168168

169169
if (likely(!err))
170170
return 0;

mm/vma.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2569,7 +2569,7 @@ static int call_mmap_prepare(struct mmap_state *map)
25692569
};
25702570

25712571
/* Invoke the hook. */
2572-
err = __call_mmap_prepare(map->file, &desc);
2572+
err = vfs_mmap_prepare(map->file, &desc);
25732573
if (err)
25742574
return err;
25752575

tools/testing/vma/vma_internal.h

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1442,6 +1442,27 @@ static inline void free_anon_vma_name(struct vm_area_struct *vma)
14421442
(void)vma;
14431443
}
14441444

1445+
/* Declared in vma.h. */
1446+
static inline void set_vma_from_desc(struct vm_area_struct *vma,
1447+
struct vm_area_desc *desc);
1448+
1449+
static inline struct vm_area_desc *vma_to_desc(struct vm_area_struct *vma,
1450+
struct vm_area_desc *desc);
1451+
1452+
static int compat_vma_mmap_prepare(struct file *file,
1453+
struct vm_area_struct *vma)
1454+
{
1455+
struct vm_area_desc desc;
1456+
int err;
1457+
1458+
err = file->f_op->mmap_prepare(vma_to_desc(vma, &desc));
1459+
if (err)
1460+
return err;
1461+
set_vma_from_desc(vma, &desc);
1462+
1463+
return 0;
1464+
}
1465+
14451466
/* Did the driver provide valid mmap hook configuration? */
14461467
static inline bool file_has_valid_mmap_hooks(struct file *file)
14471468
{
@@ -1451,22 +1472,21 @@ static inline bool file_has_valid_mmap_hooks(struct file *file)
14511472
/* Hooks are mutually exclusive. */
14521473
if (WARN_ON_ONCE(has_mmap && has_mmap_prepare))
14531474
return false;
1454-
if (WARN_ON_ONCE(!has_mmap && !has_mmap_prepare))
1475+
if (!has_mmap && !has_mmap_prepare)
14551476
return false;
14561477

14571478
return true;
14581479
}
14591480

1460-
static inline int call_mmap(struct file *file, struct vm_area_struct *vma)
1481+
static inline int vfs_mmap(struct file *file, struct vm_area_struct *vma)
14611482
{
1462-
if (WARN_ON_ONCE(file->f_op->mmap_prepare))
1463-
return -EINVAL;
1483+
if (file->f_op->mmap_prepare)
1484+
return compat_vma_mmap_prepare(file, vma);
14641485

14651486
return file->f_op->mmap(file, vma);
14661487
}
14671488

1468-
static inline int __call_mmap_prepare(struct file *file,
1469-
struct vm_area_desc *desc)
1489+
static inline int vfs_mmap_prepare(struct file *file, struct vm_area_desc *desc)
14701490
{
14711491
return file->f_op->mmap_prepare(desc);
14721492
}

0 commit comments

Comments
 (0)