]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
mm: kill vma flag VM_CAN_NONLINEAR
authorKonstantin Khlebnikov <khlebnikov@openvz.org>
Fri, 7 Sep 2012 00:22:30 +0000 (10:22 +1000)
committerStephen Rothwell <sfr@canb.auug.org.au>
Wed, 12 Sep 2012 07:08:22 +0000 (17:08 +1000)
Move actual pte filling for non-linear file mappings into the new special
vma operation: ->remap_pages().

Filesystems must implement this method to get non-linear mapping support,
if it uses filemap_fault() then generic_file_remap_pages() can be used.

Now device drivers can implement this method and obtain nonlinear vma support.

Signed-off-by: Konstantin Khlebnikov <khlebnikov@openvz.org>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: Carsten Otte <cotte@de.ibm.com>
Cc: Chris Metcalf <cmetcalf@tilera.com> #arch/tile
Cc: Cyrill Gorcunov <gorcunov@openvz.org>
Cc: Eric Paris <eparis@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Morris <james.l.morris@oracle.com>
Cc: Jason Baron <jbaron@redhat.com>
Cc: Kentaro Takeda <takedakn@nttdata.co.jp>
Cc: Matt Helsley <matthltc@us.ibm.com>
Cc: Nick Piggin <npiggin@kernel.dk>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Robert Richter <robert.richter@amd.com>
Cc: Suresh Siddha <suresh.b.siddha@intel.com>
Cc: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Cc: Venkatesh Pallipadi <venki@google.com>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
21 files changed:
drivers/staging/android/ashmem.c
fs/9p/vfs_file.c
fs/btrfs/file.c
fs/ceph/addr.c
fs/cifs/file.c
fs/ext4/file.c
fs/fuse/file.c
fs/gfs2/file.c
fs/nfs/file.c
fs/nilfs2/file.c
fs/ocfs2/mmap.c
fs/ubifs/file.c
fs/xfs/xfs_file.c
include/linux/fs.h
include/linux/mm.h
mm/filemap.c
mm/filemap_xip.c
mm/fremap.c
mm/mmap.c
mm/nommu.c
mm/shmem.c

index 94a740d2883dde4cce85a2e4859a0e94a949d436..634b9ae713e090d087b76c58bfe595637766d9f6 100644 (file)
@@ -332,7 +332,6 @@ static int ashmem_mmap(struct file *file, struct vm_area_struct *vma)
        if (vma->vm_file)
                fput(vma->vm_file);
        vma->vm_file = asma->file;
-       vma->vm_flags |= VM_CAN_NONLINEAR;
 
 out:
        mutex_unlock(&ashmem_mutex);
index dd6f7ee1e31258d94dfa1e038d2a272f17ecb541..c2483e97beee9f3e7f00cdf7b0a8f4ad1c86f27f 100644 (file)
@@ -738,6 +738,7 @@ v9fs_cached_file_write(struct file *filp, const char __user * data,
 static const struct vm_operations_struct v9fs_file_vm_ops = {
        .fault = filemap_fault,
        .page_mkwrite = v9fs_vm_page_mkwrite,
+       .remap_pages = generic_file_remap_pages,
 };
 
 
index 5caf285c6e4d0f1cb7adf82d8af911ab614a807a..f6b40e86121b007bf06954268254bcaae0fe7bf5 100644 (file)
@@ -1599,6 +1599,7 @@ out:
 static const struct vm_operations_struct btrfs_file_vm_ops = {
        .fault          = filemap_fault,
        .page_mkwrite   = btrfs_page_mkwrite,
+       .remap_pages    = generic_file_remap_pages,
 };
 
 static int btrfs_file_mmap(struct file *filp, struct vm_area_struct *vma)
@@ -1610,7 +1611,6 @@ static int btrfs_file_mmap(struct file    *filp, struct vm_area_struct *vma)
 
        file_accessed(filp);
        vma->vm_ops = &btrfs_file_vm_ops;
-       vma->vm_flags |= VM_CAN_NONLINEAR;
 
        return 0;
 }
index 452e71a1b75388b2dc06d3ad1665f36a1ed1176f..36172f9723ffd158359959f72cf8c247acf8a3c4 100644 (file)
@@ -1225,6 +1225,7 @@ out:
 static struct vm_operations_struct ceph_vmops = {
        .fault          = filemap_fault,
        .page_mkwrite   = ceph_page_mkwrite,
+       .remap_pages    = generic_file_remap_pages,
 };
 
 int ceph_mmap(struct file *file, struct vm_area_struct *vma)
@@ -1235,6 +1236,5 @@ int ceph_mmap(struct file *file, struct vm_area_struct *vma)
                return -ENOEXEC;
        file_accessed(file);
        vma->vm_ops = &ceph_vmops;
-       vma->vm_flags |= VM_CAN_NONLINEAR;
        return 0;
 }
index 8a781226ae33eae5bff03ab5d977ebff25069f67..fcddc9f7304d8d6d863141fc0fef5f8dedc432d4 100644 (file)
@@ -2871,6 +2871,7 @@ cifs_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
 static struct vm_operations_struct cifs_file_vm_ops = {
        .fault = filemap_fault,
        .page_mkwrite = cifs_page_mkwrite,
+       .remap_pages = generic_file_remap_pages,
 };
 
 int cifs_file_strict_mmap(struct file *file, struct vm_area_struct *vma)
index 3b0e3bdaabfc08ab566f40fe1d91bad4b9edc469..04e89676394b9d79b5e2f6ad6f9bd12d4edb9bc4 100644 (file)
@@ -207,6 +207,7 @@ ext4_file_write(struct kiocb *iocb, const struct iovec *iov,
 static const struct vm_operations_struct ext4_file_vm_ops = {
        .fault          = filemap_fault,
        .page_mkwrite   = ext4_page_mkwrite,
+       .remap_pages    = generic_file_remap_pages,
 };
 
 static int ext4_file_mmap(struct file *file, struct vm_area_struct *vma)
@@ -217,7 +218,6 @@ static int ext4_file_mmap(struct file *file, struct vm_area_struct *vma)
                return -ENOEXEC;
        file_accessed(file);
        vma->vm_ops = &ext4_file_vm_ops;
-       vma->vm_flags |= VM_CAN_NONLINEAR;
        return 0;
 }
 
index aba15f1b7ad2974aa85e2c7272afc3d7836a40bc..78d2837bc940292aa757aba68f84fa18fb4057da 100644 (file)
@@ -1379,6 +1379,7 @@ static const struct vm_operations_struct fuse_file_vm_ops = {
        .close          = fuse_vma_close,
        .fault          = filemap_fault,
        .page_mkwrite   = fuse_page_mkwrite,
+       .remap_pages    = generic_file_remap_pages,
 };
 
 static int fuse_file_mmap(struct file *file, struct vm_area_struct *vma)
index 30e21997a1a1323963e6de594482d3a4f9e74878..0def0504afc1816ae40b55de02c07aa68cc3a003 100644 (file)
@@ -492,6 +492,7 @@ out:
 static const struct vm_operations_struct gfs2_vm_ops = {
        .fault = filemap_fault,
        .page_mkwrite = gfs2_page_mkwrite,
+       .remap_pages = generic_file_remap_pages,
 };
 
 /**
@@ -526,7 +527,6 @@ static int gfs2_mmap(struct file *file, struct vm_area_struct *vma)
                        return error;
        }
        vma->vm_ops = &gfs2_vm_ops;
-       vma->vm_flags |= VM_CAN_NONLINEAR;
 
        return 0;
 }
index 6a7fcab7ecb3115c7630573c17f4d8285a418591..f692be97676d264d8e9100df4306e9e9fb021a7f 100644 (file)
@@ -578,6 +578,7 @@ out:
 static const struct vm_operations_struct nfs_file_vm_ops = {
        .fault = filemap_fault,
        .page_mkwrite = nfs_vm_page_mkwrite,
+       .remap_pages = generic_file_remap_pages,
 };
 
 static int nfs_need_sync_write(struct file *filp, struct inode *inode)
index a4d56ac02e6cf075b81dfaee284175d86776219d..185b8e62d639a36e7128aec438e482496d5ebd5b 100644 (file)
@@ -134,13 +134,13 @@ static int nilfs_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
 static const struct vm_operations_struct nilfs_file_vm_ops = {
        .fault          = filemap_fault,
        .page_mkwrite   = nilfs_page_mkwrite,
+       .remap_pages    = generic_file_remap_pages,
 };
 
 static int nilfs_file_mmap(struct file *file, struct vm_area_struct *vma)
 {
        file_accessed(file);
        vma->vm_ops = &nilfs_file_vm_ops;
-       vma->vm_flags |= VM_CAN_NONLINEAR;
        return 0;
 }
 
index d150372fd81da7967eb3a8f3d2a3b0d9c8c41c82..47a87dda54ce38a5a911099256775f01ff4eb5f5 100644 (file)
@@ -173,6 +173,7 @@ out:
 static const struct vm_operations_struct ocfs2_file_vm_ops = {
        .fault          = ocfs2_fault,
        .page_mkwrite   = ocfs2_page_mkwrite,
+       .remap_pages    = generic_file_remap_pages,
 };
 
 int ocfs2_mmap(struct file *file, struct vm_area_struct *vma)
@@ -188,7 +189,6 @@ int ocfs2_mmap(struct file *file, struct vm_area_struct *vma)
        ocfs2_inode_unlock(file->f_dentry->d_inode, lock_level);
 out:
        vma->vm_ops = &ocfs2_file_vm_ops;
-       vma->vm_flags |= VM_CAN_NONLINEAR;
        return 0;
 }
 
index ff48c5a853092e92cd6b4ef77362694ce9ba8cb5..5bc77817f382c8d527237f3a91976c4de9bf1873 100644 (file)
@@ -1536,6 +1536,7 @@ out_unlock:
 static const struct vm_operations_struct ubifs_file_vm_ops = {
        .fault        = filemap_fault,
        .page_mkwrite = ubifs_vm_page_mkwrite,
+       .remap_pages = generic_file_remap_pages,
 };
 
 static int ubifs_file_mmap(struct file *file, struct vm_area_struct *vma)
index 1eaeb8be3aaea5d4a034c36949bbca34fca6ceac..aa473fa640a2dd16f56ae76abfb72c1f204ba43b 100644 (file)
@@ -940,7 +940,6 @@ xfs_file_mmap(
        struct vm_area_struct *vma)
 {
        vma->vm_ops = &xfs_file_vm_ops;
-       vma->vm_flags |= VM_CAN_NONLINEAR;
 
        file_accessed(filp);
        return 0;
@@ -1443,4 +1442,5 @@ const struct file_operations xfs_dir_file_operations = {
 static const struct vm_operations_struct xfs_file_vm_ops = {
        .fault          = filemap_fault,
        .page_mkwrite   = xfs_vm_page_mkwrite,
+       .remap_pages    = generic_file_remap_pages,
 };
index aa110476a95be0b1d479555346c560d45ecc0b20..0b25c5d4da7462c96c33fb1ea9fe6734a88442e8 100644 (file)
@@ -2548,6 +2548,8 @@ 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 *);
+extern int generic_file_remap_pages(struct vm_area_struct *, unsigned long addr,
+               unsigned long size, pgoff_t pgoff);
 extern int file_read_actor(read_descriptor_t * desc, struct page *page, unsigned long offset, unsigned long size);
 int generic_write_checks(struct file *file, loff_t *pos, size_t *count, int isblk);
 extern ssize_t generic_file_aio_read(struct kiocb *, const struct iovec *, unsigned long, loff_t);
index e7876e0b3e23b4282a825ee7774b5672bc4d6d99..a8ceb51f489abf33da620649d0343f73fdcd1c1d 100644 (file)
@@ -105,7 +105,6 @@ extern unsigned int kobjsize(const void *objp);
 #define VM_ARCH_1      0x01000000      /* Architecture-specific flag */
 #define VM_NODUMP      0x04000000      /* Do not include in the core dump */
 
-#define VM_CAN_NONLINEAR 0x08000000    /* Has ->fault & does nonlinear pages */
 #define VM_MIXEDMAP    0x10000000      /* Can contain "struct page" and pure PFN pages */
 #define VM_HUGEPAGE    0x20000000      /* MADV_HUGEPAGE marked this vma */
 #define VM_NOHUGEPAGE  0x40000000      /* MADV_NOHUGEPAGE marked this vma */
@@ -172,8 +171,7 @@ extern pgprot_t protection_map[16];
  * of VM_FAULT_xxx flags that give details about how the fault was handled.
  *
  * pgoff should be used in favour of virtual_address, if possible. If pgoff
- * is used, one may set VM_CAN_NONLINEAR in the vma->vm_flags to get nonlinear
- * mapping support.
+ * is used, one may implement ->remap_pages to get nonlinear mapping support.
  */
 struct vm_fault {
        unsigned int flags;             /* FAULT_FLAG_xxx flags */
@@ -231,6 +229,9 @@ struct vm_operations_struct {
        int (*migrate)(struct vm_area_struct *vma, const nodemask_t *from,
                const nodemask_t *to, unsigned long flags);
 #endif
+       /* called by sys_remap_file_pages() to populate non-linear mapping */
+       int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
+                          unsigned long size, pgoff_t pgoff);
 };
 
 struct mmu_gather;
index 94a50bfa2f996183c0a4c3dade6f2c84adda14d9..83efee76a5c0b12c577903346eca32f7ca49be18 100644 (file)
@@ -1737,6 +1737,7 @@ EXPORT_SYMBOL(filemap_page_mkwrite);
 const struct vm_operations_struct generic_file_vm_ops = {
        .fault          = filemap_fault,
        .page_mkwrite   = filemap_page_mkwrite,
+       .remap_pages    = generic_file_remap_pages,
 };
 
 /* This is used for a general mmap of a disk file */
@@ -1749,7 +1750,6 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
                return -ENOEXEC;
        file_accessed(file);
        vma->vm_ops = &generic_file_vm_ops;
-       vma->vm_flags |= VM_CAN_NONLINEAR;
        return 0;
 }
 
index 13e013b1270c6c240ba19eadb6e091e8c6afb13d..91750227a191c2dc82cb6f7ca21840fd8fbb74da 100644 (file)
@@ -305,6 +305,7 @@ out:
 static const struct vm_operations_struct xip_file_vm_ops = {
        .fault  = xip_file_fault,
        .page_mkwrite   = filemap_page_mkwrite,
+       .remap_pages = generic_file_remap_pages,
 };
 
 int xip_file_mmap(struct file * file, struct vm_area_struct * vma)
@@ -313,7 +314,7 @@ int xip_file_mmap(struct file * file, struct vm_area_struct * vma)
 
        file_accessed(file);
        vma->vm_ops = &xip_file_vm_ops;
-       vma->vm_flags |= VM_CAN_NONLINEAR | VM_MIXEDMAP;
+       vma->vm_flags |= VM_MIXEDMAP;
        return 0;
 }
 EXPORT_SYMBOL_GPL(xip_file_mmap);
index 9ed4fd432467ee45a5310cd152fbba4399cbf722..c70190a8d525e17f2abffd50f367d77f72566a7a 100644 (file)
@@ -5,6 +5,7 @@
  *
  * started by Ingo Molnar, Copyright (C) 2002, 2003
  */
+#include <linux/export.h>
 #include <linux/backing-dev.h>
 #include <linux/mm.h>
 #include <linux/swap.h>
@@ -80,9 +81,10 @@ out:
        return err;
 }
 
-static int populate_range(struct mm_struct *mm, struct vm_area_struct *vma,
-                       unsigned long addr, unsigned long size, pgoff_t pgoff)
+int generic_file_remap_pages(struct vm_area_struct *vma, unsigned long addr,
+                            unsigned long size, pgoff_t pgoff)
 {
+       struct mm_struct *mm = vma->vm_mm;
        int err;
 
        do {
@@ -95,9 +97,9 @@ static int populate_range(struct mm_struct *mm, struct vm_area_struct *vma,
                pgoff++;
        } while (size);
 
-        return 0;
-
+       return 0;
 }
+EXPORT_SYMBOL(generic_file_remap_pages);
 
 /**
  * sys_remap_file_pages - remap arbitrary pages of an existing VM_SHARED vma
@@ -167,7 +169,7 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
        if (vma->vm_private_data && !(vma->vm_flags & VM_NONLINEAR))
                goto out;
 
-       if (!(vma->vm_flags & VM_CAN_NONLINEAR))
+       if (!vma->vm_ops->remap_pages)
                goto out;
 
        if (start < vma->vm_start || start + size > vma->vm_end)
@@ -229,7 +231,7 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
        }
 
        mmu_notifier_invalidate_range_start(mm, start, start + size);
-       err = populate_range(mm, vma, start, size, pgoff);
+       err = vma->vm_ops->remap_pages(vma, start, size, pgoff);
        mmu_notifier_invalidate_range_end(mm, start, start + size);
        if (!err && !(flags & MAP_NONBLOCK)) {
                if (vma->vm_flags & VM_LOCKED) {
index 6f21d6e4098e8ab75c1b23f8b13230c70494abad..a28b502868e62c6c09afb9ac3d5bd009e7c0d4a8 100644 (file)
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -669,8 +669,7 @@ again:                      remove_next = 1 + (end > next->vm_end);
 static inline int is_mergeable_vma(struct vm_area_struct *vma,
                        struct file *file, unsigned long vm_flags)
 {
-       /* VM_CAN_NONLINEAR may get set later by f_op->mmap() */
-       if ((vma->vm_flags ^ vm_flags) & ~VM_CAN_NONLINEAR)
+       if (vma->vm_flags ^ vm_flags)
                return 0;
        if (vma->vm_file != file)
                return 0;
index d4b0c10872de59d8959262b1daac92d5d60eb80a..686d2000b84fdb95f7557a6b15a12bfda8df03c1 100644 (file)
@@ -1963,6 +1963,14 @@ int filemap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
 }
 EXPORT_SYMBOL(filemap_fault);
 
+int generic_file_remap_pages(struct vm_area_struct *vma, unsigned long addr,
+                            unsigned long size, pgoff_t pgoff)
+{
+       BUG();
+       return 0;
+}
+EXPORT_SYMBOL(generic_file_remap_pages);
+
 static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
                unsigned long addr, void *buf, int len, int write)
 {
index d3752110c8c7ee29b7a0d98947366482984c18ca..cc12072f8787d5adacc6cd49a78849ca5c2005a6 100644 (file)
@@ -1339,7 +1339,6 @@ static int shmem_mmap(struct file *file, struct vm_area_struct *vma)
 {
        file_accessed(file);
        vma->vm_ops = &shmem_vm_ops;
-       vma->vm_flags |= VM_CAN_NONLINEAR;
        return 0;
 }
 
@@ -2643,6 +2642,7 @@ static const struct vm_operations_struct shmem_vm_ops = {
        .set_policy     = shmem_set_policy,
        .get_policy     = shmem_get_policy,
 #endif
+       .remap_pages    = generic_file_remap_pages,
 };
 
 static struct dentry *shmem_mount(struct file_system_type *fs_type,
@@ -2836,7 +2836,6 @@ int shmem_zero_setup(struct vm_area_struct *vma)
                fput(vma->vm_file);
        vma->vm_file = file;
        vma->vm_ops = &shmem_vm_ops;
-       vma->vm_flags |= VM_CAN_NONLINEAR;
        return 0;
 }