aufs4.9 mmap patch
authorJ. R. Okajima <hooanon05@yahoo.co.jp>
Fri, 27 Jan 2017 15:46:14 +0000 (00:46 +0900)
committerYves-Alexis Perez <corsac@debian.org>
Wed, 21 Feb 2018 15:29:03 +0000 (15:29 +0000)
Patch headers added by debian/patches/features/all/aufs4/gen-patch

aufs4.9 mmap patch

Gbp-Pq: Topic features/all/aufs4
Gbp-Pq: Name aufs4-mmap.patch

13 files changed:
fs/proc/base.c
fs/proc/nommu.c
fs/proc/task_mmu.c
fs/proc/task_nommu.c
include/linux/mm.h
include/linux/mm_types.h
kernel/fork.c
mm/Makefile
mm/filemap.c
mm/memory.c
mm/mmap.c
mm/nommu.c
mm/prfile.c [new file with mode: 0644]

index e67fec3c98566308d3679b59f6c0f1ebaca1accb..c83180c14f38bfc165662c71a6d60427fa0bb231 100644 (file)
@@ -1953,7 +1953,7 @@ static int map_files_get_link(struct dentry *dentry, struct path *path)
        down_read(&mm->mmap_sem);
        vma = find_exact_vma(mm, vm_start, vm_end);
        if (vma && vma->vm_file) {
-               *path = vma->vm_file->f_path;
+               *path = vma_pr_or_file(vma)->f_path;
                path_get(path);
                rc = 0;
        }
index f8595e8b5cd067e474d1ca2c9a20d60fd0ec903d..cb8eda060e95ab3b1b4bfb108f7ef14f0b3b641c 100644 (file)
@@ -45,7 +45,10 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
        file = region->vm_file;
 
        if (file) {
-               struct inode *inode = file_inode(region->vm_file);
+               struct inode *inode;
+
+               file = vmr_pr_or_file(region);
+               inode = file_inode(file);
                dev = inode->i_sb->s_dev;
                ino = inode->i_ino;
        }
index 5138e781737a075078728d654dd03542dc559653..77a4ec2a0ebdce1e0e21ee9d76c2b8241e6e2e75 100644 (file)
@@ -291,7 +291,10 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
        const char *name = NULL;
 
        if (file) {
-               struct inode *inode = file_inode(vma->vm_file);
+               struct inode *inode;
+
+               file = vma_pr_or_file(vma);
+               inode = file_inode(file);
                dev = inode->i_sb->s_dev;
                ino = inode->i_ino;
                pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
@@ -1630,7 +1633,7 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
        struct proc_maps_private *proc_priv = &numa_priv->proc_maps;
        struct vm_area_struct *vma = v;
        struct numa_maps *md = &numa_priv->md;
-       struct file *file = vma->vm_file;
+       struct file *file = vma_pr_or_file(vma);
        struct mm_struct *mm = vma->vm_mm;
        struct mm_walk walk = {
                .hugetlb_entry = gather_hugetlb_stats,
index 37175621e8906881adf4e034ce06224664120031..6a328f1a9dd280315cead28663f212748d531f73 100644 (file)
@@ -155,7 +155,10 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
        file = vma->vm_file;
 
        if (file) {
-               struct inode *inode = file_inode(vma->vm_file);
+               struct inode *inode;
+
+               file = vma_pr_or_file(vma);
+               inode = file_inode(file);
                dev = inode->i_sb->s_dev;
                ino = inode->i_ino;
                pgoff = (loff_t)vma->vm_pgoff << PAGE_SHIFT;
index 2217e2f18247a206bee9a579e8c9973b494dbe7d..140a8833e187cb2de31cf5dac65bc6662d50401a 100644 (file)
@@ -1267,6 +1267,28 @@ static inline int fixup_user_fault(struct task_struct *tsk,
 }
 #endif
 
+extern void vma_do_file_update_time(struct vm_area_struct *, const char[], int);
+extern struct file *vma_do_pr_or_file(struct vm_area_struct *, const char[],
+                                     int);
+extern void vma_do_get_file(struct vm_area_struct *, const char[], int);
+extern void vma_do_fput(struct vm_area_struct *, const char[], int);
+
+#define vma_file_update_time(vma)      vma_do_file_update_time(vma, __func__, \
+                                                               __LINE__)
+#define vma_pr_or_file(vma)            vma_do_pr_or_file(vma, __func__, \
+                                                         __LINE__)
+#define vma_get_file(vma)              vma_do_get_file(vma, __func__, __LINE__)
+#define vma_fput(vma)                  vma_do_fput(vma, __func__, __LINE__)
+
+#ifndef CONFIG_MMU
+extern struct file *vmr_do_pr_or_file(struct vm_region *, const char[], int);
+extern void vmr_do_fput(struct vm_region *, const char[], int);
+
+#define vmr_pr_or_file(region)         vmr_do_pr_or_file(region, __func__, \
+                                                         __LINE__)
+#define vmr_fput(region)               vmr_do_fput(region, __func__, __LINE__)
+#endif /* !CONFIG_MMU */
+
 extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len,
                unsigned int gup_flags);
 extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
index e8471c2ca83a513ce878d523ab2a2a2af80ef4dd..6616107518adb0eac4086fe99125aa2157f0c326 100644 (file)
@@ -275,6 +275,7 @@ struct vm_region {
        unsigned long   vm_top;         /* region allocated to here */
        unsigned long   vm_pgoff;       /* the offset in vm_file corresponding to vm_start */
        struct file     *vm_file;       /* the backing file or NULL */
+       struct file     *vm_prfile;     /* the virtual backing file or NULL */
 
        int             vm_usage;       /* region usage count (access under nommu_region_sem) */
        bool            vm_icache_flushed : 1; /* true if the icache has been flushed for
@@ -349,6 +350,7 @@ struct vm_area_struct {
        unsigned long vm_pgoff;         /* Offset (within vm_file) in PAGE_SIZE
                                           units */
        struct file * vm_file;          /* File we map to (can be NULL). */
+       struct file *vm_prfile;         /* shadow of vm_file */
        void * vm_private_data;         /* was vm_pte (shared mem) */
 
 #ifndef CONFIG_MMU
index 70e10cb49be0ff861bd379ac6cfec3561764e156..299b6c3a47cb05854b4bff714255b5d22defb94a 100644 (file)
@@ -630,7 +630,7 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm,
                        struct inode *inode = file_inode(file);
                        struct address_space *mapping = file->f_mapping;
 
-                       get_file(file);
+                       vma_get_file(tmp);
                        if (tmp->vm_flags & VM_DENYWRITE)
                                atomic_dec(&inode->i_writecount);
                        i_mmap_lock_write(mapping);
index 295bd7a9f76bbb292d68f088546dc220231458d4..14fa1c83b5042f3b6702aa3253b17ee525456a24 100644 (file)
@@ -37,7 +37,7 @@ obj-y                 := filemap.o mempool.o oom_kill.o \
                           mm_init.o mmu_context.o percpu.o slab_common.o \
                           compaction.o vmacache.o \
                           interval_tree.o list_lru.o workingset.o \
-                          debug.o $(mmu-y)
+                          prfile.o debug.o $(mmu-y)
 
 obj-y += init-mm.o
 
index edfb90e3830cd72112a9a359a232208c5d2f2ee1..f24e83525ba687daafaa2697311c67a87d809cbf 100644 (file)
@@ -2312,7 +2312,7 @@ int filemap_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
        int ret = VM_FAULT_LOCKED;
 
        sb_start_pagefault(inode->i_sb);
-       file_update_time(vma->vm_file);
+       vma_file_update_time(vma);
        lock_page(page);
        if (page->mapping != inode->i_mapping) {
                unlock_page(page);
index 1aa63e7dd790808003b2c40785fb44089f834c97..94d4871ad3f8818d714d344610959d590a47117b 100644 (file)
@@ -2118,7 +2118,7 @@ static inline int wp_page_reuse(struct fault_env *fe, pte_t orig_pte,
                }
 
                if (!page_mkwrite)
-                       file_update_time(vma->vm_file);
+                       vma_file_update_time(vma);
        }
 
        return VM_FAULT_WRITE;
index 45ac5b973459fc7ad4aae10187f54f403f150914..82b17dacda1d65b59a7b62e0a317f0ce8d641395 100644 (file)
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -170,7 +170,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
        if (vma->vm_ops && vma->vm_ops->close)
                vma->vm_ops->close(vma);
        if (vma->vm_file)
-               fput(vma->vm_file);
+               vma_fput(vma);
        mpol_put(vma_policy(vma));
        kmem_cache_free(vm_area_cachep, vma);
        return next;
@@ -893,7 +893,7 @@ again:
        if (remove_next) {
                if (file) {
                        uprobe_munmap(next, next->vm_start, next->vm_end);
-                       fput(file);
+                       vma_fput(vma);
                }
                if (next->anon_vma)
                        anon_vma_merge(vma, next);
@@ -1741,8 +1741,8 @@ out:
        return addr;
 
 unmap_and_free_vma:
+       vma_fput(vma);
        vma->vm_file = NULL;
-       fput(file);
 
        /* Undo any partial mapping done by a device driver. */
        unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
@@ -2571,7 +2571,7 @@ static int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
                goto out_free_mpol;
 
        if (new->vm_file)
-               get_file(new->vm_file);
+               vma_get_file(new);
 
        if (new->vm_ops && new->vm_ops->open)
                new->vm_ops->open(new);
@@ -2590,7 +2590,7 @@ static int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
        if (new->vm_ops && new->vm_ops->close)
                new->vm_ops->close(new);
        if (new->vm_file)
-               fput(new->vm_file);
+               vma_fput(new);
        unlink_anon_vmas(new);
  out_free_mpol:
        mpol_put(vma_policy(new));
@@ -2741,7 +2741,7 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
        struct vm_area_struct *vma;
        unsigned long populate = 0;
        unsigned long ret = -EINVAL;
-       struct file *file;
+       struct file *file, *prfile;
 
        pr_warn_once("%s (%d) uses deprecated remap_file_pages() syscall. See Documentation/vm/remap_file_pages.txt.\n",
                     current->comm, current->pid);
@@ -2816,10 +2816,27 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
                }
        }
 
-       file = get_file(vma->vm_file);
+       vma_get_file(vma);
+       file = vma->vm_file;
+       prfile = vma->vm_prfile;
        ret = do_mmap_pgoff(vma->vm_file, start, size,
                        prot, flags, pgoff, &populate);
+       if (!IS_ERR_VALUE(ret) && file && prfile) {
+               struct vm_area_struct *new_vma;
+
+               new_vma = find_vma(mm, ret);
+               if (!new_vma->vm_prfile)
+                       new_vma->vm_prfile = prfile;
+               if (new_vma != vma)
+                       get_file(prfile);
+       }
+       /*
+        * two fput()s instead of vma_fput(vma),
+        * coz vma may not be available anymore.
+        */
        fput(file);
+       if (prfile)
+               fput(prfile);
 out:
        up_write(&mm->mmap_sem);
        if (populate)
@@ -3094,7 +3111,7 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
                if (anon_vma_clone(new_vma, vma))
                        goto out_free_mempol;
                if (new_vma->vm_file)
-                       get_file(new_vma->vm_file);
+                       vma_get_file(new_vma);
                if (new_vma->vm_ops && new_vma->vm_ops->open)
                        new_vma->vm_ops->open(new_vma);
                vma_link(mm, new_vma, prev, rb_link, rb_parent);
index 44265e00b701ebe5bc3327c8575f5181aa6a6f99..781c61e3bc740dab12da9c250c32139584669bda 100644 (file)
@@ -636,7 +636,7 @@ static void __put_nommu_region(struct vm_region *region)
                up_write(&nommu_region_sem);
 
                if (region->vm_file)
-                       fput(region->vm_file);
+                       vmr_fput(region);
 
                /* IO memory and memory shared directly out of the pagecache
                 * from ramfs/tmpfs mustn't be released here */
@@ -794,7 +794,7 @@ static void delete_vma(struct mm_struct *mm, struct vm_area_struct *vma)
        if (vma->vm_ops && vma->vm_ops->close)
                vma->vm_ops->close(vma);
        if (vma->vm_file)
-               fput(vma->vm_file);
+               vma_fput(vma);
        put_nommu_region(vma->vm_region);
        kmem_cache_free(vm_area_cachep, vma);
 }
@@ -1320,7 +1320,7 @@ unsigned long do_mmap(struct file *file,
                                        goto error_just_free;
                                }
                        }
-                       fput(region->vm_file);
+                       vmr_fput(region);
                        kmem_cache_free(vm_region_jar, region);
                        region = pregion;
                        result = start;
@@ -1395,10 +1395,10 @@ error_just_free:
        up_write(&nommu_region_sem);
 error:
        if (region->vm_file)
-               fput(region->vm_file);
+               vmr_fput(region);
        kmem_cache_free(vm_region_jar, region);
        if (vma->vm_file)
-               fput(vma->vm_file);
+               vma_fput(vma);
        kmem_cache_free(vm_area_cachep, vma);
        return ret;
 
diff --git a/mm/prfile.c b/mm/prfile.c
new file mode 100644 (file)
index 0000000..b323b8a
--- /dev/null
@@ -0,0 +1,86 @@
+/*
+ * Mainly for aufs which mmap(2) diffrent file and wants to print different path
+ * in /proc/PID/maps.
+ * Call these functions via macros defined in linux/mm.h.
+ *
+ * See Documentation/filesystems/aufs/design/06mmap.txt
+ *
+ * Copyright (c) 2014 Junjro R. Okajima
+ * Copyright (c) 2014 Ian Campbell
+ */
+
+#include <linux/mm.h>
+#include <linux/file.h>
+#include <linux/fs.h>
+
+/* #define PRFILE_TRACE */
+static inline void prfile_trace(struct file *f, struct file *pr,
+                             const char func[], int line, const char func2[])
+{
+#ifdef PRFILE_TRACE
+       if (pr)
+               pr_info("%s:%d: %s, %s\n", func, line, func2,
+                       f ? (char *)f->f_path.dentry->d_name.name : "(null)");
+#endif
+}
+
+void vma_do_file_update_time(struct vm_area_struct *vma, const char func[],
+                            int line)
+{
+       struct file *f = vma->vm_file, *pr = vma->vm_prfile;
+
+       prfile_trace(f, pr, func, line, __func__);
+       file_update_time(f);
+       if (f && pr)
+               file_update_time(pr);
+}
+
+struct file *vma_do_pr_or_file(struct vm_area_struct *vma, const char func[],
+                              int line)
+{
+       struct file *f = vma->vm_file, *pr = vma->vm_prfile;
+
+       prfile_trace(f, pr, func, line, __func__);
+       return (f && pr) ? pr : f;
+}
+
+void vma_do_get_file(struct vm_area_struct *vma, const char func[], int line)
+{
+       struct file *f = vma->vm_file, *pr = vma->vm_prfile;
+
+       prfile_trace(f, pr, func, line, __func__);
+       get_file(f);
+       if (f && pr)
+               get_file(pr);
+}
+
+void vma_do_fput(struct vm_area_struct *vma, const char func[], int line)
+{
+       struct file *f = vma->vm_file, *pr = vma->vm_prfile;
+
+       prfile_trace(f, pr, func, line, __func__);
+       fput(f);
+       if (f && pr)
+               fput(pr);
+}
+
+#ifndef CONFIG_MMU
+struct file *vmr_do_pr_or_file(struct vm_region *region, const char func[],
+                              int line)
+{
+       struct file *f = region->vm_file, *pr = region->vm_prfile;
+
+       prfile_trace(f, pr, func, line, __func__);
+       return (f && pr) ? pr : f;
+}
+
+void vmr_do_fput(struct vm_region *region, const char func[], int line)
+{
+       struct file *f = region->vm_file, *pr = region->vm_prfile;
+
+       prfile_trace(f, pr, func, line, __func__);
+       fput(f);
+       if (f && pr)
+               fput(pr);
+}
+#endif /* !CONFIG_MMU */