Convert all open coded mutex_lock/unlock calls to the i_mmap_[lock/unlock]_write() helpers.
Unified · Split
| @@ -412,10 +412,10 @@ static int hugetlb_vmtruncate(struct inode *inode, loff_t offset) · 411 unmodified lines | ||
| 412 | 412 | pgoff = offset >> PAGE_SHIFT; |
| 413 | 413 | |
| 414 | 414 | i_size_write(inode, offset); |
| 415 | − mutex_lock(&mapping->i_mmap_mutex); | |
| 415 | + i_mmap_lock_write(mapping); | |
| 416 | 416 | if (!RB_EMPTY_ROOT(&mapping->i_mmap)) |
| 417 | 417 | hugetlb_vmtruncate_list(&mapping->i_mmap, pgoff); |
| 418 | − mutex_unlock(&mapping->i_mmap_mutex); | |
| 418 | + i_mmap_unlock_write(mapping); | |
| 419 | 419 | truncate_hugepages(inode, offset); |
| 420 | 420 | return 0; |
| 421 | 421 | } |
| @@ -724,7 +724,7 @@ build_map_info(struct address_space *mapping, loff_t offset, bool is_register) · 723 unmodified lines | ||
| 724 | 724 | int more = 0; |
| 725 | 725 | |
| 726 | 726 | again: |
| 727 | − mutex_lock(&mapping->i_mmap_mutex); | |
| 727 | + i_mmap_lock_write(mapping); | |
| 728 | 728 | vma_interval_tree_foreach(vma, &mapping->i_mmap, pgoff, pgoff) { |
| 729 | 729 | if (!valid_vma(vma, is_register)) |
| 730 | 730 | continue; |
| @@ -755,7 +755,7 @@ build_map_info(struct address_space *mapping, loff_t offset, bool is_register) · 24 unmodified lines | ||
| 755 | 755 | info->mm = vma->vm_mm; |
| 756 | 756 | info->vaddr = offset_to_vaddr(vma, offset); |
| 757 | 757 | } |
| 758 | − mutex_unlock(&mapping->i_mmap_mutex); | |
| 758 | + i_mmap_unlock_write(mapping); | |
| 759 | 759 | |
| 760 | 760 | if (!more) |
| 761 | 761 | goto out; |
| @@ -433,7 +433,7 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm) · 432 unmodified lines | ||
| 433 | 433 | get_file(file); |
| 434 | 434 | if (tmp->vm_flags & VM_DENYWRITE) |
| 435 | 435 | atomic_dec(&inode->i_writecount); |
| 436 | − mutex_lock(&mapping->i_mmap_mutex); | |
| 436 | + i_mmap_lock_write(mapping); | |
| 437 | 437 | if (tmp->vm_flags & VM_SHARED) |
| 438 | 438 | atomic_inc(&mapping->i_mmap_writable); |
| 439 | 439 | flush_dcache_mmap_lock(mapping); |
| @@ -445,7 +445,7 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm) · 5 unmodified lines | ||
| 445 | 445 | vma_interval_tree_insert_after(tmp, mpnt, |
| 446 | 446 | &mapping->i_mmap); |
| 447 | 447 | flush_dcache_mmap_unlock(mapping); |
| 448 | − mutex_unlock(&mapping->i_mmap_mutex); | |
| 448 | + i_mmap_unlock_write(mapping); | |
| 449 | 449 | } |
| 450 | 450 | |
| 451 | 451 | /* |
| @@ -182,7 +182,7 @@ __xip_unmap (struct address_space * mapping, · 181 unmodified lines | ||
| 182 | 182 | return; |
| 183 | 183 | |
| 184 | 184 | retry: |
| 185 | − mutex_lock(&mapping->i_mmap_mutex); | |
| 185 | + i_mmap_lock_write(mapping); | |
| 186 | 186 | vma_interval_tree_foreach(vma, &mapping->i_mmap, pgoff, pgoff) { |
| 187 | 187 | mm = vma->vm_mm; |
| 188 | 188 | address = vma->vm_start + |
| @@ -202,7 +202,7 @@ retry: · 13 unmodified lines | ||
| 202 | 202 | page_cache_release(page); |
| 203 | 203 | } |
| 204 | 204 | } |
| 205 | − mutex_unlock(&mapping->i_mmap_mutex); | |
| 205 | + i_mmap_unlock_write(mapping); | |
| 206 | 206 | |
| 207 | 207 | if (locked) { |
| 208 | 208 | mutex_unlock(&xip_sparse_mutex); |
| @@ -238,13 +238,13 @@ get_write_lock: · 237 unmodified lines | ||
| 238 | 238 | } |
| 239 | 239 | goto out_freed; |
| 240 | 240 | } |
| 241 | − mutex_lock(&mapping->i_mmap_mutex); | |
| 241 | + i_mmap_lock_write(mapping); | |
| 242 | 242 | flush_dcache_mmap_lock(mapping); |
| 243 | 243 | vma->vm_flags |= VM_NONLINEAR; |
| 244 | 244 | vma_interval_tree_remove(vma, &mapping->i_mmap); |
| 245 | 245 | vma_nonlinear_insert(vma, &mapping->i_mmap_nonlinear); |
| 246 | 246 | flush_dcache_mmap_unlock(mapping); |
| 247 | − mutex_unlock(&mapping->i_mmap_mutex); | |
| 247 | + i_mmap_unlock_write(mapping); | |
| 248 | 248 | } |
| 249 | 249 | |
| 250 | 250 | if (vma->vm_flags & VM_LOCKED) { |
| @@ -2774,7 +2774,7 @@ static void unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma, · 2773 unmodified lines | ||
| 2774 | 2774 | * this mapping should be shared between all the VMAs, |
| 2775 | 2775 | * __unmap_hugepage_range() is called as the lock is already held |
| 2776 | 2776 | */ |
| 2777 | − mutex_lock(&mapping->i_mmap_mutex); | |
| 2777 | + i_mmap_lock_write(mapping); | |
| 2778 | 2778 | vma_interval_tree_foreach(iter_vma, &mapping->i_mmap, pgoff, pgoff) { |
| 2779 | 2779 | /* Do not unmap the current VMA */ |
| 2780 | 2780 | if (iter_vma == vma) |
| @@ -2791,7 +2791,7 @@ static void unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma, · 10 unmodified lines | ||
| 2791 | 2791 | unmap_hugepage_range(iter_vma, address, |
| 2792 | 2792 | address + huge_page_size(h), page); |
| 2793 | 2793 | } |
| 2794 | − mutex_unlock(&mapping->i_mmap_mutex); | |
| 2794 | + i_mmap_unlock_write(mapping); | |
| 2795 | 2795 | } |
| 2796 | 2796 | |
| 2797 | 2797 | /* |
| @@ -3348,7 +3348,7 @@ unsigned long hugetlb_change_protection(struct vm_area_struct *vma, · 550 unmodified lines | ||
| 3348 | 3348 | flush_cache_range(vma, address, end); |
| 3349 | 3349 | |
| 3350 | 3350 | mmu_notifier_invalidate_range_start(mm, start, end); |
| 3351 | − mutex_lock(&vma->vm_file->f_mapping->i_mmap_mutex); | |
| 3351 | + i_mmap_lock_write(vma->vm_file->f_mapping); | |
| 3352 | 3352 | for (; address < end; address += huge_page_size(h)) { |
| 3353 | 3353 | spinlock_t *ptl; |
| 3354 | 3354 | ptep = huge_pte_offset(mm, address); |
| @@ -3376,7 +3376,7 @@ unsigned long hugetlb_change_protection(struct vm_area_struct *vma, · 21 unmodified lines | ||
| 3376 | 3376 | * and that page table be reused and filled with junk. |
| 3377 | 3377 | */ |
| 3378 | 3378 | flush_tlb_range(vma, start, end); |
| 3379 | − mutex_unlock(&vma->vm_file->f_mapping->i_mmap_mutex); | |
| 3379 | + i_mmap_unlock_write(vma->vm_file->f_mapping); | |
| 3380 | 3380 | mmu_notifier_invalidate_range_end(mm, start, end); |
| 3381 | 3381 | |
| 3382 | 3382 | return pages << h->order; |
| @@ -3544,7 +3544,7 @@ pte_t *huge_pmd_share(struct mm_struct *mm, unsigned long addr, pud_t *pud) · 161 unmodified lines | ||
| 3544 | 3544 | if (!vma_shareable(vma, addr)) |
| 3545 | 3545 | return (pte_t *)pmd_alloc(mm, pud, addr); |
| 3546 | 3546 | |
| 3547 | − mutex_lock(&mapping->i_mmap_mutex); | |
| 3547 | + i_mmap_lock_write(mapping); | |
| 3548 | 3548 | vma_interval_tree_foreach(svma, &mapping->i_mmap, idx, idx) { |
| 3549 | 3549 | if (svma == vma) |
| 3550 | 3550 | continue; |
| @@ -3572,7 +3572,7 @@ pte_t *huge_pmd_share(struct mm_struct *mm, unsigned long addr, pud_t *pud) · 21 unmodified lines | ||
| 3572 | 3572 | spin_unlock(ptl); |
| 3573 | 3573 | out: |
| 3574 | 3574 | pte = (pte_t *)pmd_alloc(mm, pud, addr); |
| 3575 | − mutex_unlock(&mapping->i_mmap_mutex); | |
| 3575 | + i_mmap_unlock_write(mapping); | |
| 3576 | 3576 | return pte; |
| 3577 | 3577 | } |
| 3578 | 3578 | |
| @@ -466,7 +466,7 @@ static void collect_procs_file(struct page *page, struct list_head *to_kill, · 465 unmodified lines | ||
| 466 | 466 | struct task_struct *tsk; |
| 467 | 467 | struct address_space *mapping = page->mapping; |
| 468 | 468 | |
| 469 | − mutex_lock(&mapping->i_mmap_mutex); | |
| 469 | + i_mmap_lock_write(mapping); | |
| 470 | 470 | read_lock(&tasklist_lock); |
| 471 | 471 | for_each_process(tsk) { |
| 472 | 472 | pgoff_t pgoff = page_to_pgoff(page); |
| @@ -488,7 +488,7 @@ static void collect_procs_file(struct page *page, struct list_head *to_kill, · 15 unmodified lines | ||
| 488 | 488 | } |
| 489 | 489 | } |
| 490 | 490 | read_unlock(&tasklist_lock); |
| 491 | − mutex_unlock(&mapping->i_mmap_mutex); | |
| 491 | + i_mmap_unlock_write(mapping); | |
| 492 | 492 | } |
| 493 | 493 | |
| 494 | 494 | /* |
| @@ -1326,9 +1326,9 @@ static void unmap_single_vma(struct mmu_gather *tlb, · 1325 unmodified lines | ||
| 1326 | 1326 | * safe to do nothing in this case. |
| 1327 | 1327 | */ |
| 1328 | 1328 | if (vma->vm_file) { |
| 1329 | − mutex_lock(&vma->vm_file->f_mapping->i_mmap_mutex); | |
| 1329 | + i_mmap_lock_write(vma->vm_file->f_mapping); | |
| 1330 | 1330 | __unmap_hugepage_range_final(tlb, vma, start, end, NULL); |
| 1331 | − mutex_unlock(&vma->vm_file->f_mapping->i_mmap_mutex); | |
| 1331 | + i_mmap_unlock_write(vma->vm_file->f_mapping); | |
| 1332 | 1332 | } |
| 1333 | 1333 | } else |
| 1334 | 1334 | unmap_page_range(tlb, vma, start, end, details); |
| @@ -2377,12 +2377,12 @@ void unmap_mapping_range(struct address_space *mapping, · 1042 unmodified lines | ||
| 2377 | 2377 | details.last_index = ULONG_MAX; |
| 2378 | 2378 | |
| 2379 | 2379 | |
| 2380 | − mutex_lock(&mapping->i_mmap_mutex); | |
| 2380 | + i_mmap_lock_write(mapping); | |
| 2381 | 2381 | if (unlikely(!RB_EMPTY_ROOT(&mapping->i_mmap))) |
| 2382 | 2382 | unmap_mapping_range_tree(&mapping->i_mmap, &details); |
| 2383 | 2383 | if (unlikely(!list_empty(&mapping->i_mmap_nonlinear))) |
| 2384 | 2384 | unmap_mapping_range_list(&mapping->i_mmap_nonlinear, &details); |
| 2385 | − mutex_unlock(&mapping->i_mmap_mutex); | |
| 2385 | + i_mmap_unlock_write(mapping); | |
| 2386 | 2386 | } |
| 2387 | 2387 | EXPORT_SYMBOL(unmap_mapping_range); |
| 2388 | 2388 | |
| @@ -260,9 +260,9 @@ void unlink_file_vma(struct vm_area_struct *vma) · 259 unmodified lines | ||
| 260 | 260 | |
| 261 | 261 | if (file) { |
| 262 | 262 | struct address_space *mapping = file->f_mapping; |
| 263 | − mutex_lock(&mapping->i_mmap_mutex); | |
| 263 | + i_mmap_lock_write(mapping); | |
| 264 | 264 | __remove_shared_vm_struct(vma, file, mapping); |
| 265 | − mutex_unlock(&mapping->i_mmap_mutex); | |
| 265 | + i_mmap_unlock_write(mapping); | |
| 266 | 266 | } |
| 267 | 267 | } |
| 268 | 268 | |
| @@ -674,14 +674,14 @@ static void vma_link(struct mm_struct *mm, struct vm_area_struct *vma, · 405 unmodified lines | ||
| 674 | 674 | |
| 675 | 675 | if (vma->vm_file) { |
| 676 | 676 | mapping = vma->vm_file->f_mapping; |
| 677 | − mutex_lock(&mapping->i_mmap_mutex); | |
| 677 | + i_mmap_lock_write(mapping); | |
| 678 | 678 | } |
| 679 | 679 | |
| 680 | 680 | __vma_link(mm, vma, prev, rb_link, rb_parent); |
| 681 | 681 | __vma_link_file(vma); |
| 682 | 682 | |
| 683 | 683 | if (mapping) |
| 684 | − mutex_unlock(&mapping->i_mmap_mutex); | |
| 684 | + i_mmap_unlock_write(mapping); | |
| 685 | 685 | |
| 686 | 686 | mm->map_count++; |
| 687 | 687 | validate_mm(mm); |
| @@ -796,7 +796,7 @@ again: remove_next = 1 + (end > next->vm_end); · 108 unmodified lines | ||
| 796 | 796 | next->vm_end); |
| 797 | 797 | } |
| 798 | 798 | |
| 799 | − mutex_lock(&mapping->i_mmap_mutex); | |
| 799 | + i_mmap_lock_write(mapping); | |
| 800 | 800 | if (insert) { |
| 801 | 801 | /* |
| 802 | 802 | * Put into interval tree now, so instantiated pages |
| @@ -883,7 +883,7 @@ again: remove_next = 1 + (end > next->vm_end); · 80 unmodified lines | ||
| 883 | 883 | anon_vma_unlock_write(anon_vma); |
| 884 | 884 | } |
| 885 | 885 | if (mapping) |
| 886 | − mutex_unlock(&mapping->i_mmap_mutex); | |
| 886 | + i_mmap_unlock_write(mapping); | |
| 887 | 887 | |
| 888 | 888 | if (root) { |
| 889 | 889 | uprobe_mmap(vma); |
| @@ -3182,7 +3182,7 @@ static void vm_unlock_mapping(struct address_space *mapping) · 2292 unmodified lines | ||
| 3182 | 3182 | * AS_MM_ALL_LOCKS can't change to 0 from under us |
| 3183 | 3183 | * because we hold the mm_all_locks_mutex. |
| 3184 | 3184 | */ |
| 3185 | − mutex_unlock(&mapping->i_mmap_mutex); | |
| 3185 | + i_mmap_unlock_write(mapping); | |
| 3186 | 3186 | if (!test_and_clear_bit(AS_MM_ALL_LOCKS, |
| 3187 | 3187 | &mapping->flags)) |
| 3188 | 3188 | BUG(); |
| @@ -119,7 +119,7 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd, · 118 unmodified lines | ||
| 119 | 119 | if (need_rmap_locks) { |
| 120 | 120 | if (vma->vm_file) { |
| 121 | 121 | mapping = vma->vm_file->f_mapping; |
| 122 | − mutex_lock(&mapping->i_mmap_mutex); | |
| 122 | + i_mmap_lock_write(mapping); | |
| 123 | 123 | } |
| 124 | 124 | if (vma->anon_vma) { |
| 125 | 125 | anon_vma = vma->anon_vma; |
| @@ -156,7 +156,7 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd, · 30 unmodified lines | ||
| 156 | 156 | if (anon_vma) |
| 157 | 157 | anon_vma_unlock_write(anon_vma); |
| 158 | 158 | if (mapping) |
| 159 | − mutex_unlock(&mapping->i_mmap_mutex); | |
| 159 | + i_mmap_unlock_write(mapping); | |
| 160 | 160 | } |
| 161 | 161 | |
| 162 | 162 | #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) · 721 unmodified lines | ||
| 722 | 722 | if (vma->vm_file) { |
| 723 | 723 | mapping = vma->vm_file->f_mapping; |
| 724 | 724 | |
| 725 | − mutex_lock(&mapping->i_mmap_mutex); | |
| 725 | + i_mmap_lock_write(mapping); | |
| 726 | 726 | flush_dcache_mmap_lock(mapping); |
| 727 | 727 | vma_interval_tree_insert(vma, &mapping->i_mmap); |
| 728 | 728 | flush_dcache_mmap_unlock(mapping); |
| 729 | − mutex_unlock(&mapping->i_mmap_mutex); | |
| 729 | + i_mmap_unlock_write(mapping); | |
| 730 | 730 | } |
| 731 | 731 | |
| 732 | 732 | /* add the VMA to the tree */ |
| @@ -795,11 +795,11 @@ static void delete_vma_from_mm(struct vm_area_struct *vma) · 62 unmodified lines | ||
| 795 | 795 | if (vma->vm_file) { |
| 796 | 796 | mapping = vma->vm_file->f_mapping; |
| 797 | 797 | |
| 798 | − mutex_lock(&mapping->i_mmap_mutex); | |
| 798 | + i_mmap_lock_write(mapping); | |
| 799 | 799 | flush_dcache_mmap_lock(mapping); |
| 800 | 800 | vma_interval_tree_remove(vma, &mapping->i_mmap); |
| 801 | 801 | flush_dcache_mmap_unlock(mapping); |
| 802 | − mutex_unlock(&mapping->i_mmap_mutex); | |
| 802 | + i_mmap_unlock_write(mapping); | |
| 803 | 803 | } |
| 804 | 804 | |
| 805 | 805 | /* remove from the MM's tree and list */ |
| @@ -2094,14 +2094,14 @@ int nommu_shrink_inode_mappings(struct inode *inode, size_t size, · 1288 unmodified lines | ||
| 2094 | 2094 | high = (size + PAGE_SIZE - 1) >> PAGE_SHIFT; |
| 2095 | 2095 | |
| 2096 | 2096 | down_write(&nommu_region_sem); |
| 2097 | − mutex_lock(&inode->i_mapping->i_mmap_mutex); | |
| 2097 | + i_mmap_lock_write(inode->i_mapping); | |
| 2098 | 2098 | |
| 2099 | 2099 | /* search for VMAs that fall within the dead zone */ |
| 2100 | 2100 | vma_interval_tree_foreach(vma, &inode->i_mapping->i_mmap, low, high) { |
| 2101 | 2101 | /* found one - only interested if it's shared out of the page |
| 2102 | 2102 | * cache */ |
| 2103 | 2103 | if (vma->vm_flags & VM_SHARED) { |
| 2104 | − mutex_unlock(&inode->i_mapping->i_mmap_mutex); | |
| 2104 | + i_mmap_unlock_write(inode->i_mapping); | |
| 2105 | 2105 | up_write(&nommu_region_sem); |
| 2106 | 2106 | return -ETXTBSY; /* not quite true, but near enough */ |
| 2107 | 2107 | } |
| @@ -2129,7 +2129,7 @@ int nommu_shrink_inode_mappings(struct inode *inode, size_t size, · 21 unmodified lines | ||
| 2129 | 2129 | } |
| 2130 | 2130 | } |
| 2131 | 2131 | |
| 2132 | − mutex_unlock(&inode->i_mapping->i_mmap_mutex); | |
| 2132 | + i_mmap_unlock_write(inode->i_mapping); | |
| 2133 | 2133 | up_write(&nommu_region_sem); |
| 2134 | 2134 | return 0; |
| 2135 | 2135 | } |
| @@ -1690,7 +1690,7 @@ static int rmap_walk_file(struct page *page, struct rmap_walk_control *rwc) · 1689 unmodified lines | ||
| 1690 | 1690 | |
| 1691 | 1691 | if (!mapping) |
| 1692 | 1692 | return ret; |
| 1693 | − mutex_lock(&mapping->i_mmap_mutex); | |
| 1693 | + i_mmap_lock_write(mapping); | |
| 1694 | 1694 | vma_interval_tree_foreach(vma, &mapping->i_mmap, pgoff, pgoff) { |
| 1695 | 1695 | unsigned long address = vma_address(page, vma); |
| 1696 | 1696 | |
| @@ -1713,7 +1713,7 @@ static int rmap_walk_file(struct page *page, struct rmap_walk_control *rwc) · 16 unmodified lines | ||
| 1713 | 1713 | ret = rwc->file_nonlinear(page, mapping, rwc->arg); |
| 1714 | 1714 | |
| 1715 | 1715 | done: |
| 1716 | − mutex_unlock(&mapping->i_mmap_mutex); | |
| 1716 | + i_mmap_unlock_write(mapping); | |
| 1717 | 1717 | return ret; |
| 1718 | 1718 | } |
| 1719 | 1719 | |