[Devel] [PATCH RHEL7 COMMIT] ms/mm: mmap_region: kill correct_wcount/inode, use allow_write_access()

Konstantin Khorenko khorenko at virtuozzo.com
Thu Oct 15 04:04:16 PDT 2015


The commit is pushed to "branch-rh7-3.10.0-229.7.2.vz7.8.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-229.7.2.vz7.8.6
------>
commit 55c695be4110abbbc0c16bd2f6d55de27ac03b90
Author: Andrew Vagin <avagin at openvz.org>
Date:   Thu Oct 15 15:04:16 2015 +0400

    ms/mm: mmap_region: kill correct_wcount/inode, use allow_write_access()
    
    The patch is required for CRIU.
    
    https://jira.sw.ru/browse/PSBM-39834
    
    MM: e86867720e617774b560dfbc169b7f3d0d490950
    
    correct_wcount and inode in mmap_region() just complicate the code.  This
    boolean was needed previously, when deny_write_access() was called before
    vma_merge(), now we can simply check VM_DENYWRITE and do
    allow_write_access() if it is set.
    
    allow_write_access() checks file != NULL, so this is safe even if it was
    possible to use VM_DENYWRITE && !file.  Just we need to ensure we use the
    same file which was deny_write_access()'ed, so the patch also moves "file
    = vma->vm_file" down after allow_write_access().
    
    Signed-off-by: Oleg Nesterov <oleg at redhat.com>
    Cc: Hugh Dickins <hughd at google.com>
    Cc: Al Viro <viro at zeniv.linux.org.uk>
    Cc: Colin Cross <ccross at android.com>
    Cc: David Rientjes <rientjes at google.com>
    Cc: KOSAKI Motohiro <kosaki.motohiro at jp.fujitsu.com>
    Signed-off-by: Andrew Morton <akpm at linux-foundation.org>
    Signed-off-by: Linus Torvalds <torvalds at linux-foundation.org>
    Signed-off-by: Andrew Vagin <avagin at openvz.org>
---
 mm/mmap.c | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)

diff --git a/mm/mmap.c b/mm/mmap.c
index 826cf37..f87a78b 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -1494,11 +1494,9 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
 {
 	struct mm_struct *mm = current->mm;
 	struct vm_area_struct *vma, *prev;
-	int correct_wcount = 0;
 	int error;
 	struct rb_node **rb_link, *rb_parent;
 	unsigned long charged = 0;
-	struct inode *inode =  file ? file_inode(file) : NULL;
 	unsigned long ub_charged = 0;
 
 	/* Check against address space limit. */
@@ -1576,7 +1574,6 @@ munmap_back:
 			error = deny_write_access(file);
 			if (error)
 				goto free_vma;
-			correct_wcount = 1;
 		}
 		vma->vm_file = get_file(file);
 		error = file->f_op->mmap(file, vma);
@@ -1631,11 +1628,10 @@ munmap_back:
 	}
 
 	vma_link(mm, vma, prev, rb_link, rb_parent);
-	file = vma->vm_file;
-
 	/* Once vma denies write, undo our temporary denial count */
-	if (correct_wcount)
-		atomic_inc(&inode->i_writecount);
+	if (vm_flags & VM_DENYWRITE)
+		allow_write_access(file);
+	file = vma->vm_file;
 out:
 	perf_event_mmap(vma);
 
@@ -1663,8 +1659,8 @@ out:
 	return addr;
 
 unmap_and_free_vma:
-	if (correct_wcount)
-		atomic_inc(&inode->i_writecount);
+	if (vm_flags & VM_DENYWRITE)
+		allow_write_access(file);
 	vma->vm_file = NULL;
 	fput(file);
 



More information about the Devel mailing list