mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-09-29 22:02:02 +00:00
mm: mmap_region: kill correct_wcount/inode, use allow_write_access()
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@redhat.com> Cc: Hugh Dickins <hughd@google.com> Cc: Al Viro <viro@zeniv.linux.org.uk> Cc: Colin Cross <ccross@android.com> Cc: David Rientjes <rientjes@google.com> Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
parent
077bf22b5c
commit
e86867720e
1 changed files with 5 additions and 9 deletions
14
mm/mmap.c
14
mm/mmap.c
|
@ -1479,11 +1479,9 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
|
||||||
{
|
{
|
||||||
struct mm_struct *mm = current->mm;
|
struct mm_struct *mm = current->mm;
|
||||||
struct vm_area_struct *vma, *prev;
|
struct vm_area_struct *vma, *prev;
|
||||||
int correct_wcount = 0;
|
|
||||||
int error;
|
int error;
|
||||||
struct rb_node **rb_link, *rb_parent;
|
struct rb_node **rb_link, *rb_parent;
|
||||||
unsigned long charged = 0;
|
unsigned long charged = 0;
|
||||||
struct inode *inode = file ? file_inode(file) : NULL;
|
|
||||||
|
|
||||||
/* Check against address space limit. */
|
/* Check against address space limit. */
|
||||||
if (!may_expand_vm(mm, len >> PAGE_SHIFT)) {
|
if (!may_expand_vm(mm, len >> PAGE_SHIFT)) {
|
||||||
|
@ -1552,7 +1550,6 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
|
||||||
error = deny_write_access(file);
|
error = deny_write_access(file);
|
||||||
if (error)
|
if (error)
|
||||||
goto free_vma;
|
goto free_vma;
|
||||||
correct_wcount = 1;
|
|
||||||
}
|
}
|
||||||
vma->vm_file = get_file(file);
|
vma->vm_file = get_file(file);
|
||||||
error = file->f_op->mmap(file, vma);
|
error = file->f_op->mmap(file, vma);
|
||||||
|
@ -1593,11 +1590,10 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
|
||||||
}
|
}
|
||||||
|
|
||||||
vma_link(mm, vma, prev, rb_link, rb_parent);
|
vma_link(mm, vma, prev, rb_link, rb_parent);
|
||||||
file = vma->vm_file;
|
|
||||||
|
|
||||||
/* Once vma denies write, undo our temporary denial count */
|
/* Once vma denies write, undo our temporary denial count */
|
||||||
if (correct_wcount)
|
if (vm_flags & VM_DENYWRITE)
|
||||||
atomic_inc(&inode->i_writecount);
|
allow_write_access(file);
|
||||||
|
file = vma->vm_file;
|
||||||
out:
|
out:
|
||||||
perf_event_mmap(vma);
|
perf_event_mmap(vma);
|
||||||
|
|
||||||
|
@ -1616,8 +1612,8 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
|
||||||
return addr;
|
return addr;
|
||||||
|
|
||||||
unmap_and_free_vma:
|
unmap_and_free_vma:
|
||||||
if (correct_wcount)
|
if (vm_flags & VM_DENYWRITE)
|
||||||
atomic_inc(&inode->i_writecount);
|
allow_write_access(file);
|
||||||
vma->vm_file = NULL;
|
vma->vm_file = NULL;
|
||||||
fput(file);
|
fput(file);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue