Commit 83cde9e8 authored by Davidlohr Bueso's avatar Davidlohr Bueso Committed by Linus Torvalds

mm: use new helper functions around the i_mmap_mutex

Convert all open coded mutex_lock/unlock calls to the
i_mmap_[lock/unlock]_write() helpers.
Signed-off-by: default avatarDavidlohr Bueso <dbueso@suse.de>
Acked-by: default avatarRik van Riel <riel@redhat.com>
Acked-by: default avatar"Kirill A. Shutemov" <kirill@shutemov.name>
Acked-by: default avatarHugh Dickins <hughd@google.com>
Cc: Oleg Nesterov <oleg@redhat.com>
Acked-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
Cc: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
Acked-by: default avatarMel Gorman <mgorman@suse.de>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 8b28f621
...@@ -412,10 +412,10 @@ static int hugetlb_vmtruncate(struct inode *inode, loff_t offset) ...@@ -412,10 +412,10 @@ static int hugetlb_vmtruncate(struct inode *inode, loff_t offset)
pgoff = offset >> PAGE_SHIFT; pgoff = offset >> PAGE_SHIFT;
i_size_write(inode, offset); i_size_write(inode, offset);
mutex_lock(&mapping->i_mmap_mutex); i_mmap_lock_write(mapping);
if (!RB_EMPTY_ROOT(&mapping->i_mmap)) if (!RB_EMPTY_ROOT(&mapping->i_mmap))
hugetlb_vmtruncate_list(&mapping->i_mmap, pgoff); hugetlb_vmtruncate_list(&mapping->i_mmap, pgoff);
mutex_unlock(&mapping->i_mmap_mutex); i_mmap_unlock_write(mapping);
truncate_hugepages(inode, offset); truncate_hugepages(inode, offset);
return 0; return 0;
} }
......
...@@ -724,7 +724,7 @@ build_map_info(struct address_space *mapping, loff_t offset, bool is_register) ...@@ -724,7 +724,7 @@ build_map_info(struct address_space *mapping, loff_t offset, bool is_register)
int more = 0; int more = 0;
again: again:
mutex_lock(&mapping->i_mmap_mutex); i_mmap_lock_write(mapping);
vma_interval_tree_foreach(vma, &mapping->i_mmap, pgoff, pgoff) { vma_interval_tree_foreach(vma, &mapping->i_mmap, pgoff, pgoff) {
if (!valid_vma(vma, is_register)) if (!valid_vma(vma, is_register))
continue; continue;
...@@ -755,7 +755,7 @@ build_map_info(struct address_space *mapping, loff_t offset, bool is_register) ...@@ -755,7 +755,7 @@ build_map_info(struct address_space *mapping, loff_t offset, bool is_register)
info->mm = vma->vm_mm; info->mm = vma->vm_mm;
info->vaddr = offset_to_vaddr(vma, offset); info->vaddr = offset_to_vaddr(vma, offset);
} }
mutex_unlock(&mapping->i_mmap_mutex); i_mmap_unlock_write(mapping);
if (!more) if (!more)
goto out; goto out;
......
...@@ -433,7 +433,7 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm) ...@@ -433,7 +433,7 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
get_file(file); get_file(file);
if (tmp->vm_flags & VM_DENYWRITE) if (tmp->vm_flags & VM_DENYWRITE)
atomic_dec(&inode->i_writecount); atomic_dec(&inode->i_writecount);
mutex_lock(&mapping->i_mmap_mutex); i_mmap_lock_write(mapping);
if (tmp->vm_flags & VM_SHARED) if (tmp->vm_flags & VM_SHARED)
atomic_inc(&mapping->i_mmap_writable); atomic_inc(&mapping->i_mmap_writable);
flush_dcache_mmap_lock(mapping); flush_dcache_mmap_lock(mapping);
...@@ -445,7 +445,7 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm) ...@@ -445,7 +445,7 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
vma_interval_tree_insert_after(tmp, mpnt, vma_interval_tree_insert_after(tmp, mpnt,
&mapping->i_mmap); &mapping->i_mmap);
flush_dcache_mmap_unlock(mapping); flush_dcache_mmap_unlock(mapping);
mutex_unlock(&mapping->i_mmap_mutex); i_mmap_unlock_write(mapping);
} }
/* /*
......
...@@ -182,7 +182,7 @@ __xip_unmap (struct address_space * mapping, ...@@ -182,7 +182,7 @@ __xip_unmap (struct address_space * mapping,
return; return;
retry: retry:
mutex_lock(&mapping->i_mmap_mutex); i_mmap_lock_write(mapping);
vma_interval_tree_foreach(vma, &mapping->i_mmap, pgoff, pgoff) { vma_interval_tree_foreach(vma, &mapping->i_mmap, pgoff, pgoff) {
mm = vma->vm_mm; mm = vma->vm_mm;
address = vma->vm_start + address = vma->vm_start +
...@@ -202,7 +202,7 @@ __xip_unmap (struct address_space * mapping, ...@@ -202,7 +202,7 @@ __xip_unmap (struct address_space * mapping,
page_cache_release(page); page_cache_release(page);
} }
} }
mutex_unlock(&mapping->i_mmap_mutex); i_mmap_unlock_write(mapping);
if (locked) { if (locked) {
mutex_unlock(&xip_sparse_mutex); mutex_unlock(&xip_sparse_mutex);
......
...@@ -238,13 +238,13 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size, ...@@ -238,13 +238,13 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
} }
goto out_freed; goto out_freed;
} }
mutex_lock(&mapping->i_mmap_mutex); i_mmap_lock_write(mapping);
flush_dcache_mmap_lock(mapping); flush_dcache_mmap_lock(mapping);
vma->vm_flags |= VM_NONLINEAR; vma->vm_flags |= VM_NONLINEAR;
vma_interval_tree_remove(vma, &mapping->i_mmap); vma_interval_tree_remove(vma, &mapping->i_mmap);
vma_nonlinear_insert(vma, &mapping->i_mmap_nonlinear); vma_nonlinear_insert(vma, &mapping->i_mmap_nonlinear);
flush_dcache_mmap_unlock(mapping); flush_dcache_mmap_unlock(mapping);
mutex_unlock(&mapping->i_mmap_mutex); i_mmap_unlock_write(mapping);
} }
if (vma->vm_flags & VM_LOCKED) { if (vma->vm_flags & VM_LOCKED) {
......
...@@ -2774,7 +2774,7 @@ static void unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma, ...@@ -2774,7 +2774,7 @@ static void unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
* this mapping should be shared between all the VMAs, * this mapping should be shared between all the VMAs,
* __unmap_hugepage_range() is called as the lock is already held * __unmap_hugepage_range() is called as the lock is already held
*/ */
mutex_lock(&mapping->i_mmap_mutex); i_mmap_lock_write(mapping);
vma_interval_tree_foreach(iter_vma, &mapping->i_mmap, pgoff, pgoff) { vma_interval_tree_foreach(iter_vma, &mapping->i_mmap, pgoff, pgoff) {
/* Do not unmap the current VMA */ /* Do not unmap the current VMA */
if (iter_vma == vma) if (iter_vma == vma)
...@@ -2791,7 +2791,7 @@ static void unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma, ...@@ -2791,7 +2791,7 @@ static void unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
unmap_hugepage_range(iter_vma, address, unmap_hugepage_range(iter_vma, address,
address + huge_page_size(h), page); address + huge_page_size(h), page);
} }
mutex_unlock(&mapping->i_mmap_mutex); i_mmap_unlock_write(mapping);
} }
/* /*
...@@ -3348,7 +3348,7 @@ unsigned long hugetlb_change_protection(struct vm_area_struct *vma, ...@@ -3348,7 +3348,7 @@ unsigned long hugetlb_change_protection(struct vm_area_struct *vma,
flush_cache_range(vma, address, end); flush_cache_range(vma, address, end);
mmu_notifier_invalidate_range_start(mm, start, end); mmu_notifier_invalidate_range_start(mm, start, end);
mutex_lock(&vma->vm_file->f_mapping->i_mmap_mutex); i_mmap_lock_write(vma->vm_file->f_mapping);
for (; address < end; address += huge_page_size(h)) { for (; address < end; address += huge_page_size(h)) {
spinlock_t *ptl; spinlock_t *ptl;
ptep = huge_pte_offset(mm, address); ptep = huge_pte_offset(mm, address);
...@@ -3376,7 +3376,7 @@ unsigned long hugetlb_change_protection(struct vm_area_struct *vma, ...@@ -3376,7 +3376,7 @@ unsigned long hugetlb_change_protection(struct vm_area_struct *vma,
* and that page table be reused and filled with junk. * and that page table be reused and filled with junk.
*/ */
flush_tlb_range(vma, start, end); flush_tlb_range(vma, start, end);
mutex_unlock(&vma->vm_file->f_mapping->i_mmap_mutex); i_mmap_unlock_write(vma->vm_file->f_mapping);
mmu_notifier_invalidate_range_end(mm, start, end); mmu_notifier_invalidate_range_end(mm, start, end);
return pages << h->order; return pages << h->order;
...@@ -3544,7 +3544,7 @@ pte_t *huge_pmd_share(struct mm_struct *mm, unsigned long addr, pud_t *pud) ...@@ -3544,7 +3544,7 @@ pte_t *huge_pmd_share(struct mm_struct *mm, unsigned long addr, pud_t *pud)
if (!vma_shareable(vma, addr)) if (!vma_shareable(vma, addr))
return (pte_t *)pmd_alloc(mm, pud, addr); return (pte_t *)pmd_alloc(mm, pud, addr);
mutex_lock(&mapping->i_mmap_mutex); i_mmap_lock_write(mapping);
vma_interval_tree_foreach(svma, &mapping->i_mmap, idx, idx) { vma_interval_tree_foreach(svma, &mapping->i_mmap, idx, idx) {
if (svma == vma) if (svma == vma)
continue; continue;
...@@ -3572,7 +3572,7 @@ pte_t *huge_pmd_share(struct mm_struct *mm, unsigned long addr, pud_t *pud) ...@@ -3572,7 +3572,7 @@ pte_t *huge_pmd_share(struct mm_struct *mm, unsigned long addr, pud_t *pud)
spin_unlock(ptl); spin_unlock(ptl);
out: out:
pte = (pte_t *)pmd_alloc(mm, pud, addr); pte = (pte_t *)pmd_alloc(mm, pud, addr);
mutex_unlock(&mapping->i_mmap_mutex); i_mmap_unlock_write(mapping);
return pte; return pte;
} }
......
...@@ -466,7 +466,7 @@ static void collect_procs_file(struct page *page, struct list_head *to_kill, ...@@ -466,7 +466,7 @@ static void collect_procs_file(struct page *page, struct list_head *to_kill,
struct task_struct *tsk; struct task_struct *tsk;
struct address_space *mapping = page->mapping; struct address_space *mapping = page->mapping;
mutex_lock(&mapping->i_mmap_mutex); i_mmap_lock_write(mapping);
read_lock(&tasklist_lock); read_lock(&tasklist_lock);
for_each_process(tsk) { for_each_process(tsk) {
pgoff_t pgoff = page_to_pgoff(page); pgoff_t pgoff = page_to_pgoff(page);
...@@ -488,7 +488,7 @@ static void collect_procs_file(struct page *page, struct list_head *to_kill, ...@@ -488,7 +488,7 @@ static void collect_procs_file(struct page *page, struct list_head *to_kill,
} }
} }
read_unlock(&tasklist_lock); read_unlock(&tasklist_lock);
mutex_unlock(&mapping->i_mmap_mutex); i_mmap_unlock_write(mapping);
} }
/* /*
......
...@@ -1326,9 +1326,9 @@ static void unmap_single_vma(struct mmu_gather *tlb, ...@@ -1326,9 +1326,9 @@ static void unmap_single_vma(struct mmu_gather *tlb,
* safe to do nothing in this case. * safe to do nothing in this case.
*/ */
if (vma->vm_file) { if (vma->vm_file) {
mutex_lock(&vma->vm_file->f_mapping->i_mmap_mutex); i_mmap_lock_write(vma->vm_file->f_mapping);
__unmap_hugepage_range_final(tlb, vma, start, end, NULL); __unmap_hugepage_range_final(tlb, vma, start, end, NULL);
mutex_unlock(&vma->vm_file->f_mapping->i_mmap_mutex); i_mmap_unlock_write(vma->vm_file->f_mapping);
} }
} else } else
unmap_page_range(tlb, vma, start, end, details); unmap_page_range(tlb, vma, start, end, details);
...@@ -2377,12 +2377,12 @@ void unmap_mapping_range(struct address_space *mapping, ...@@ -2377,12 +2377,12 @@ void unmap_mapping_range(struct address_space *mapping,
details.last_index = ULONG_MAX; details.last_index = ULONG_MAX;
mutex_lock(&mapping->i_mmap_mutex); i_mmap_lock_write(mapping);
if (unlikely(!RB_EMPTY_ROOT(&mapping->i_mmap))) if (unlikely(!RB_EMPTY_ROOT(&mapping->i_mmap)))
unmap_mapping_range_tree(&mapping->i_mmap, &details); unmap_mapping_range_tree(&mapping->i_mmap, &details);
if (unlikely(!list_empty(&mapping->i_mmap_nonlinear))) if (unlikely(!list_empty(&mapping->i_mmap_nonlinear)))
unmap_mapping_range_list(&mapping->i_mmap_nonlinear, &details); unmap_mapping_range_list(&mapping->i_mmap_nonlinear, &details);
mutex_unlock(&mapping->i_mmap_mutex); i_mmap_unlock_write(mapping);
} }
EXPORT_SYMBOL(unmap_mapping_range); EXPORT_SYMBOL(unmap_mapping_range);
......
...@@ -260,9 +260,9 @@ void unlink_file_vma(struct vm_area_struct *vma) ...@@ -260,9 +260,9 @@ void unlink_file_vma(struct vm_area_struct *vma)
if (file) { if (file) {
struct address_space *mapping = file->f_mapping; struct address_space *mapping = file->f_mapping;
mutex_lock(&mapping->i_mmap_mutex); i_mmap_lock_write(mapping);
__remove_shared_vm_struct(vma, file, mapping); __remove_shared_vm_struct(vma, file, mapping);
mutex_unlock(&mapping->i_mmap_mutex); i_mmap_unlock_write(mapping);
} }
} }
...@@ -674,14 +674,14 @@ static void vma_link(struct mm_struct *mm, struct vm_area_struct *vma, ...@@ -674,14 +674,14 @@ static void vma_link(struct mm_struct *mm, struct vm_area_struct *vma,
if (vma->vm_file) { if (vma->vm_file) {
mapping = vma->vm_file->f_mapping; mapping = vma->vm_file->f_mapping;
mutex_lock(&mapping->i_mmap_mutex); i_mmap_lock_write(mapping);
} }
__vma_link(mm, vma, prev, rb_link, rb_parent); __vma_link(mm, vma, prev, rb_link, rb_parent);
__vma_link_file(vma); __vma_link_file(vma);
if (mapping) if (mapping)
mutex_unlock(&mapping->i_mmap_mutex); i_mmap_unlock_write(mapping);
mm->map_count++; mm->map_count++;
validate_mm(mm); validate_mm(mm);
...@@ -796,7 +796,7 @@ again: remove_next = 1 + (end > next->vm_end); ...@@ -796,7 +796,7 @@ again: remove_next = 1 + (end > next->vm_end);
next->vm_end); next->vm_end);
} }
mutex_lock(&mapping->i_mmap_mutex); i_mmap_lock_write(mapping);
if (insert) { if (insert) {
/* /*
* Put into interval tree now, so instantiated pages * Put into interval tree now, so instantiated pages
...@@ -883,7 +883,7 @@ again: remove_next = 1 + (end > next->vm_end); ...@@ -883,7 +883,7 @@ again: remove_next = 1 + (end > next->vm_end);
anon_vma_unlock_write(anon_vma); anon_vma_unlock_write(anon_vma);
} }
if (mapping) if (mapping)
mutex_unlock(&mapping->i_mmap_mutex); i_mmap_unlock_write(mapping);
if (root) { if (root) {
uprobe_mmap(vma); uprobe_mmap(vma);
...@@ -3182,7 +3182,7 @@ static void vm_unlock_mapping(struct address_space *mapping) ...@@ -3182,7 +3182,7 @@ static void vm_unlock_mapping(struct address_space *mapping)
* AS_MM_ALL_LOCKS can't change to 0 from under us * AS_MM_ALL_LOCKS can't change to 0 from under us
* because we hold the mm_all_locks_mutex. * because we hold the mm_all_locks_mutex.
*/ */
mutex_unlock(&mapping->i_mmap_mutex); i_mmap_unlock_write(mapping);
if (!test_and_clear_bit(AS_MM_ALL_LOCKS, if (!test_and_clear_bit(AS_MM_ALL_LOCKS,
&mapping->flags)) &mapping->flags))
BUG(); BUG();
......
...@@ -119,7 +119,7 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd, ...@@ -119,7 +119,7 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
if (need_rmap_locks) { if (need_rmap_locks) {
if (vma->vm_file) { if (vma->vm_file) {
mapping = vma->vm_file->f_mapping; mapping = vma->vm_file->f_mapping;
mutex_lock(&mapping->i_mmap_mutex); i_mmap_lock_write(mapping);
} }
if (vma->anon_vma) { if (vma->anon_vma) {
anon_vma = vma->anon_vma; anon_vma = vma->anon_vma;
...@@ -156,7 +156,7 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd, ...@@ -156,7 +156,7 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
if (anon_vma) if (anon_vma)
anon_vma_unlock_write(anon_vma); anon_vma_unlock_write(anon_vma);
if (mapping) if (mapping)
mutex_unlock(&mapping->i_mmap_mutex); i_mmap_unlock_write(mapping);
} }
#define LATENCY_LIMIT (64 * PAGE_SIZE) #define LATENCY_LIMIT (64 * PAGE_SIZE)
......
...@@ -722,11 +722,11 @@ static void add_vma_to_mm(struct mm_struct *mm, struct vm_area_struct *vma) ...@@ -722,11 +722,11 @@ static void add_vma_to_mm(struct mm_struct *mm, struct vm_area_struct *vma)
if (vma->vm_file) { if (vma->vm_file) {
mapping = vma->vm_file->f_mapping; mapping = vma->vm_file->f_mapping;
mutex_lock(&mapping->i_mmap_mutex); i_mmap_lock_write(mapping);
flush_dcache_mmap_lock(mapping); flush_dcache_mmap_lock(mapping);
vma_interval_tree_insert(vma, &mapping->i_mmap); vma_interval_tree_insert(vma, &mapping->i_mmap);
flush_dcache_mmap_unlock(mapping); flush_dcache_mmap_unlock(mapping);
mutex_unlock(&mapping->i_mmap_mutex); i_mmap_unlock_write(mapping);
} }
/* add the VMA to the tree */ /* add the VMA to the tree */
...@@ -795,11 +795,11 @@ static void delete_vma_from_mm(struct vm_area_struct *vma) ...@@ -795,11 +795,11 @@ static void delete_vma_from_mm(struct vm_area_struct *vma)
if (vma->vm_file) { if (vma->vm_file) {
mapping = vma->vm_file->f_mapping; mapping = vma->vm_file->f_mapping;
mutex_lock(&mapping->i_mmap_mutex); i_mmap_lock_write(mapping);
flush_dcache_mmap_lock(mapping); flush_dcache_mmap_lock(mapping);
vma_interval_tree_remove(vma, &mapping->i_mmap); vma_interval_tree_remove(vma, &mapping->i_mmap);
flush_dcache_mmap_unlock(mapping); flush_dcache_mmap_unlock(mapping);
mutex_unlock(&mapping->i_mmap_mutex); i_mmap_unlock_write(mapping);
} }
/* remove from the MM's tree and list */ /* remove from the MM's tree and list */
...@@ -2094,14 +2094,14 @@ int nommu_shrink_inode_mappings(struct inode *inode, size_t size, ...@@ -2094,14 +2094,14 @@ int nommu_shrink_inode_mappings(struct inode *inode, size_t size,
high = (size + PAGE_SIZE - 1) >> PAGE_SHIFT; high = (size + PAGE_SIZE - 1) >> PAGE_SHIFT;
down_write(&nommu_region_sem); down_write(&nommu_region_sem);
mutex_lock(&inode->i_mapping->i_mmap_mutex); i_mmap_lock_write(inode->i_mapping);
/* search for VMAs that fall within the dead zone */ /* search for VMAs that fall within the dead zone */
vma_interval_tree_foreach(vma, &inode->i_mapping->i_mmap, low, high) { vma_interval_tree_foreach(vma, &inode->i_mapping->i_mmap, low, high) {
/* found one - only interested if it's shared out of the page /* found one - only interested if it's shared out of the page
* cache */ * cache */
if (vma->vm_flags & VM_SHARED) { if (vma->vm_flags & VM_SHARED) {
mutex_unlock(&inode->i_mapping->i_mmap_mutex); i_mmap_unlock_write(inode->i_mapping);
up_write(&nommu_region_sem); up_write(&nommu_region_sem);
return -ETXTBSY; /* not quite true, but near enough */ return -ETXTBSY; /* not quite true, but near enough */
} }
...@@ -2129,7 +2129,7 @@ int nommu_shrink_inode_mappings(struct inode *inode, size_t size, ...@@ -2129,7 +2129,7 @@ int nommu_shrink_inode_mappings(struct inode *inode, size_t size,
} }
} }
mutex_unlock(&inode->i_mapping->i_mmap_mutex); i_mmap_unlock_write(inode->i_mapping);
up_write(&nommu_region_sem); up_write(&nommu_region_sem);
return 0; return 0;
} }
......
...@@ -1690,7 +1690,7 @@ static int rmap_walk_file(struct page *page, struct rmap_walk_control *rwc) ...@@ -1690,7 +1690,7 @@ static int rmap_walk_file(struct page *page, struct rmap_walk_control *rwc)
if (!mapping) if (!mapping)
return ret; return ret;
mutex_lock(&mapping->i_mmap_mutex); i_mmap_lock_write(mapping);
vma_interval_tree_foreach(vma, &mapping->i_mmap, pgoff, pgoff) { vma_interval_tree_foreach(vma, &mapping->i_mmap, pgoff, pgoff) {
unsigned long address = vma_address(page, vma); unsigned long address = vma_address(page, vma);
...@@ -1713,7 +1713,7 @@ static int rmap_walk_file(struct page *page, struct rmap_walk_control *rwc) ...@@ -1713,7 +1713,7 @@ static int rmap_walk_file(struct page *page, struct rmap_walk_control *rwc)
ret = rwc->file_nonlinear(page, mapping, rwc->arg); ret = rwc->file_nonlinear(page, mapping, rwc->arg);
done: done:
mutex_unlock(&mapping->i_mmap_mutex); i_mmap_unlock_write(mapping);
return ret; return ret;
} }
......
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