Commit a1ea9549 authored by Michel Lespinasse's avatar Michel Lespinasse Committed by Linus Torvalds

mm: use mm_populate() for blocking remap_file_pages()

Signed-off-by: default avatarMichel Lespinasse <walken@google.com>
Reviewed-by: default avatarRik van Riel <riel@redhat.com>
Tested-by: default avatarAndy Lutomirski <luto@amacapital.net>
Cc: Greg Ungerer <gregungerer@westnet.com.au>
Cc: David Howells <dhowells@redhat.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent bebeb3d6
...@@ -129,6 +129,7 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size, ...@@ -129,6 +129,7 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
struct vm_area_struct *vma; struct vm_area_struct *vma;
int err = -EINVAL; int err = -EINVAL;
int has_write_lock = 0; int has_write_lock = 0;
vm_flags_t vm_flags;
if (prot) if (prot)
return err; return err;
...@@ -228,30 +229,16 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size, ...@@ -228,30 +229,16 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
/* /*
* drop PG_Mlocked flag for over-mapped range * drop PG_Mlocked flag for over-mapped range
*/ */
vm_flags_t saved_flags = vma->vm_flags;
if (!has_write_lock) if (!has_write_lock)
goto get_write_lock; goto get_write_lock;
vm_flags = vma->vm_flags;
munlock_vma_pages_range(vma, start, start + size); munlock_vma_pages_range(vma, start, start + size);
vma->vm_flags = saved_flags; vma->vm_flags = vm_flags;
} }
mmu_notifier_invalidate_range_start(mm, start, start + size); mmu_notifier_invalidate_range_start(mm, start, start + size);
err = vma->vm_ops->remap_pages(vma, start, size, pgoff); err = vma->vm_ops->remap_pages(vma, start, size, pgoff);
mmu_notifier_invalidate_range_end(mm, start, start + size); mmu_notifier_invalidate_range_end(mm, start, start + size);
if (!err) {
if (vma->vm_flags & VM_LOCKED) {
/*
* might be mapping previously unmapped range of file
*/
mlock_vma_pages_range(vma, start, start + size);
} else if (!(flags & MAP_NONBLOCK)) {
if (unlikely(has_write_lock)) {
downgrade_write(&mm->mmap_sem);
has_write_lock = 0;
}
make_pages_present(start, start+size);
}
}
/* /*
* We can't clear VM_NONLINEAR because we'd have to do * We can't clear VM_NONLINEAR because we'd have to do
...@@ -260,10 +247,13 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size, ...@@ -260,10 +247,13 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
*/ */
out: out:
vm_flags = vma->vm_flags;
if (likely(!has_write_lock)) if (likely(!has_write_lock))
up_read(&mm->mmap_sem); up_read(&mm->mmap_sem);
else else
up_write(&mm->mmap_sem); up_write(&mm->mmap_sem);
if (!err && ((vm_flags & VM_LOCKED) || !(flags & MAP_NONBLOCK)))
mm_populate(start, size);
return err; return err;
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment