History

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.

Davidlohr Bueso committed 11 years ago

Commit 83cde9e1 parent 8b28f6212 files · +40 −40Browse files

Unified · Split

12 files
  1. fs/hugetlbfs/inode.c +2 −2
  2. kernel/events/uprobes.c +2 −2
  3. kernel/fork.c +2 −2
  4. mm/filemap_xip.c +2 −2
  5. mm/fremap.c +2 −2
  6. mm/hugetlb.c +6 −6
  7. mm/memory-failure.c +2 −2
  8. mm/memory.c +4 −4
  9. mm/mmap.c +7 −7
  10. mm/mremap.c +2 −2
  11. mm/nommu.c +7 −7
  12. mm/rmap.c +2 −2
fs/hugetlbfs/inode.c+2−2
@@ -412,10 +412,10 @@ static int hugetlb_vmtruncate(struct inode *inode, loff_t offset) · 411 unmodified lines
412412 pgoff = offset >> PAGE_SHIFT;
413413
414414 i_size_write(inode, offset);
415− mutex_lock(&mapping->i_mmap_mutex);
415+ i_mmap_lock_write(mapping);
416416 if (!RB_EMPTY_ROOT(&mapping->i_mmap))
417417 hugetlb_vmtruncate_list(&mapping->i_mmap, pgoff);
418− mutex_unlock(&mapping->i_mmap_mutex);
418+ i_mmap_unlock_write(mapping);
419419 truncate_hugepages(inode, offset);
420420 return 0;
421421 }
kernel/events/uprobes.c+2−2
@@ -724,7 +724,7 @@ build_map_info(struct address_space *mapping, loff_t offset, bool is_register) · 723 unmodified lines
724724 int more = 0;
725725
726726 again:
727− mutex_lock(&mapping->i_mmap_mutex);
727+ i_mmap_lock_write(mapping);
728728 vma_interval_tree_foreach(vma, &mapping->i_mmap, pgoff, pgoff) {
729729 if (!valid_vma(vma, is_register))
730730 continue;
@@ -755,7 +755,7 @@ build_map_info(struct address_space *mapping, loff_t offset, bool is_register) · 24 unmodified lines
755755 info->mm = vma->vm_mm;
756756 info->vaddr = offset_to_vaddr(vma, offset);
757757 }
758− mutex_unlock(&mapping->i_mmap_mutex);
758+ i_mmap_unlock_write(mapping);
759759
760760 if (!more)
761761 goto out;
kernel/fork.c+2−2
@@ -433,7 +433,7 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm) · 432 unmodified lines
433433 get_file(file);
434434 if (tmp->vm_flags & VM_DENYWRITE)
435435 atomic_dec(&inode->i_writecount);
436− mutex_lock(&mapping->i_mmap_mutex);
436+ i_mmap_lock_write(mapping);
437437 if (tmp->vm_flags & VM_SHARED)
438438 atomic_inc(&mapping->i_mmap_writable);
439439 flush_dcache_mmap_lock(mapping);
@@ -445,7 +445,7 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm) · 5 unmodified lines
445445 vma_interval_tree_insert_after(tmp, mpnt,
446446 &mapping->i_mmap);
447447 flush_dcache_mmap_unlock(mapping);
448− mutex_unlock(&mapping->i_mmap_mutex);
448+ i_mmap_unlock_write(mapping);
449449 }
450450
451451 /*
mm/filemap_xip.c+2−2
@@ -182,7 +182,7 @@ __xip_unmap (struct address_space * mapping, · 181 unmodified lines
182182 return;
183183
184184 retry:
185− mutex_lock(&mapping->i_mmap_mutex);
185+ i_mmap_lock_write(mapping);
186186 vma_interval_tree_foreach(vma, &mapping->i_mmap, pgoff, pgoff) {
187187 mm = vma->vm_mm;
188188 address = vma->vm_start +
@@ -202,7 +202,7 @@ retry: · 13 unmodified lines
202202 page_cache_release(page);
203203 }
204204 }
205− mutex_unlock(&mapping->i_mmap_mutex);
205+ i_mmap_unlock_write(mapping);
206206
207207 if (locked) {
208208 mutex_unlock(&xip_sparse_mutex);
mm/fremap.c+2−2
@@ -238,13 +238,13 @@ get_write_lock: · 237 unmodified lines
238238 }
239239 goto out_freed;
240240 }
241− mutex_lock(&mapping->i_mmap_mutex);
241+ i_mmap_lock_write(mapping);
242242 flush_dcache_mmap_lock(mapping);
243243 vma->vm_flags |= VM_NONLINEAR;
244244 vma_interval_tree_remove(vma, &mapping->i_mmap);
245245 vma_nonlinear_insert(vma, &mapping->i_mmap_nonlinear);
246246 flush_dcache_mmap_unlock(mapping);
247− mutex_unlock(&mapping->i_mmap_mutex);
247+ i_mmap_unlock_write(mapping);
248248 }
249249
250250 if (vma->vm_flags & VM_LOCKED) {
mm/hugetlb.c+6−6
@@ -2774,7 +2774,7 @@ static void unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma, · 2773 unmodified lines
27742774 * this mapping should be shared between all the VMAs,
27752775 * __unmap_hugepage_range() is called as the lock is already held
27762776 */
2777− mutex_lock(&mapping->i_mmap_mutex);
2777+ i_mmap_lock_write(mapping);
27782778 vma_interval_tree_foreach(iter_vma, &mapping->i_mmap, pgoff, pgoff) {
27792779 /* Do not unmap the current VMA */
27802780 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
27912791 unmap_hugepage_range(iter_vma, address,
27922792 address + huge_page_size(h), page);
27932793 }
2794− mutex_unlock(&mapping->i_mmap_mutex);
2794+ i_mmap_unlock_write(mapping);
27952795 }
27962796
27972797 /*
@@ -3348,7 +3348,7 @@ unsigned long hugetlb_change_protection(struct vm_area_struct *vma, · 550 unmodified lines
33483348 flush_cache_range(vma, address, end);
33493349
33503350 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);
33523352 for (; address < end; address += huge_page_size(h)) {
33533353 spinlock_t *ptl;
33543354 ptep = huge_pte_offset(mm, address);
@@ -3376,7 +3376,7 @@ unsigned long hugetlb_change_protection(struct vm_area_struct *vma, · 21 unmodified lines
33763376 * and that page table be reused and filled with junk.
33773377 */
33783378 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);
33803380 mmu_notifier_invalidate_range_end(mm, start, end);
33813381
33823382 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
35443544 if (!vma_shareable(vma, addr))
35453545 return (pte_t *)pmd_alloc(mm, pud, addr);
35463546
3547− mutex_lock(&mapping->i_mmap_mutex);
3547+ i_mmap_lock_write(mapping);
35483548 vma_interval_tree_foreach(svma, &mapping->i_mmap, idx, idx) {
35493549 if (svma == vma)
35503550 continue;
@@ -3572,7 +3572,7 @@ pte_t *huge_pmd_share(struct mm_struct *mm, unsigned long addr, pud_t *pud) · 21 unmodified lines
35723572 spin_unlock(ptl);
35733573 out:
35743574 pte = (pte_t *)pmd_alloc(mm, pud, addr);
3575− mutex_unlock(&mapping->i_mmap_mutex);
3575+ i_mmap_unlock_write(mapping);
35763576 return pte;
35773577 }
35783578
mm/memory-failure.c+2−2
@@ -466,7 +466,7 @@ static void collect_procs_file(struct page *page, struct list_head *to_kill, · 465 unmodified lines
466466 struct task_struct *tsk;
467467 struct address_space *mapping = page->mapping;
468468
469− mutex_lock(&mapping->i_mmap_mutex);
469+ i_mmap_lock_write(mapping);
470470 read_lock(&tasklist_lock);
471471 for_each_process(tsk) {
472472 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
488488 }
489489 }
490490 read_unlock(&tasklist_lock);
491− mutex_unlock(&mapping->i_mmap_mutex);
491+ i_mmap_unlock_write(mapping);
492492 }
493493
494494 /*
mm/memory.c+4−4
@@ -1326,9 +1326,9 @@ static void unmap_single_vma(struct mmu_gather *tlb, · 1325 unmodified lines
13261326 * safe to do nothing in this case.
13271327 */
13281328 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);
13301330 __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);
13321332 }
13331333 } else
13341334 unmap_page_range(tlb, vma, start, end, details);
@@ -2377,12 +2377,12 @@ void unmap_mapping_range(struct address_space *mapping, · 1042 unmodified lines
23772377 details.last_index = ULONG_MAX;
23782378
23792379
2380− mutex_lock(&mapping->i_mmap_mutex);
2380+ i_mmap_lock_write(mapping);
23812381 if (unlikely(!RB_EMPTY_ROOT(&mapping->i_mmap)))
23822382 unmap_mapping_range_tree(&mapping->i_mmap, &details);
23832383 if (unlikely(!list_empty(&mapping->i_mmap_nonlinear)))
23842384 unmap_mapping_range_list(&mapping->i_mmap_nonlinear, &details);
2385− mutex_unlock(&mapping->i_mmap_mutex);
2385+ i_mmap_unlock_write(mapping);
23862386 }
23872387 EXPORT_SYMBOL(unmap_mapping_range);
23882388
mm/mmap.c+7−7
@@ -260,9 +260,9 @@ void unlink_file_vma(struct vm_area_struct *vma) · 259 unmodified lines
260260
261261 if (file) {
262262 struct address_space *mapping = file->f_mapping;
263− mutex_lock(&mapping->i_mmap_mutex);
263+ i_mmap_lock_write(mapping);
264264 __remove_shared_vm_struct(vma, file, mapping);
265− mutex_unlock(&mapping->i_mmap_mutex);
265+ i_mmap_unlock_write(mapping);
266266 }
267267 }
268268
@@ -674,14 +674,14 @@ static void vma_link(struct mm_struct *mm, struct vm_area_struct *vma, · 405 unmodified lines
674674
675675 if (vma->vm_file) {
676676 mapping = vma->vm_file->f_mapping;
677− mutex_lock(&mapping->i_mmap_mutex);
677+ i_mmap_lock_write(mapping);
678678 }
679679
680680 __vma_link(mm, vma, prev, rb_link, rb_parent);
681681 __vma_link_file(vma);
682682
683683 if (mapping)
684− mutex_unlock(&mapping->i_mmap_mutex);
684+ i_mmap_unlock_write(mapping);
685685
686686 mm->map_count++;
687687 validate_mm(mm);
@@ -796,7 +796,7 @@ again: remove_next = 1 + (end > next->vm_end); · 108 unmodified lines
796796 next->vm_end);
797797 }
798798
799− mutex_lock(&mapping->i_mmap_mutex);
799+ i_mmap_lock_write(mapping);
800800 if (insert) {
801801 /*
802802 * Put into interval tree now, so instantiated pages
@@ -883,7 +883,7 @@ again: remove_next = 1 + (end > next->vm_end); · 80 unmodified lines
883883 anon_vma_unlock_write(anon_vma);
884884 }
885885 if (mapping)
886− mutex_unlock(&mapping->i_mmap_mutex);
886+ i_mmap_unlock_write(mapping);
887887
888888 if (root) {
889889 uprobe_mmap(vma);
@@ -3182,7 +3182,7 @@ static void vm_unlock_mapping(struct address_space *mapping) · 2292 unmodified lines
31823182 * AS_MM_ALL_LOCKS can't change to 0 from under us
31833183 * because we hold the mm_all_locks_mutex.
31843184 */
3185− mutex_unlock(&mapping->i_mmap_mutex);
3185+ i_mmap_unlock_write(mapping);
31863186 if (!test_and_clear_bit(AS_MM_ALL_LOCKS,
31873187 &mapping->flags))
31883188 BUG();
mm/mremap.c+2−2
@@ -119,7 +119,7 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd, · 118 unmodified lines
119119 if (need_rmap_locks) {
120120 if (vma->vm_file) {
121121 mapping = vma->vm_file->f_mapping;
122− mutex_lock(&mapping->i_mmap_mutex);
122+ i_mmap_lock_write(mapping);
123123 }
124124 if (vma->anon_vma) {
125125 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
156156 if (anon_vma)
157157 anon_vma_unlock_write(anon_vma);
158158 if (mapping)
159− mutex_unlock(&mapping->i_mmap_mutex);
159+ i_mmap_unlock_write(mapping);
160160 }
161161
162162 #define LATENCY_LIMIT (64 * PAGE_SIZE)
mm/nommu.c+7−7
@@ -722,11 +722,11 @@ static void add_vma_to_mm(struct mm_struct *mm, struct vm_area_struct *vma) · 721 unmodified lines
722722 if (vma->vm_file) {
723723 mapping = vma->vm_file->f_mapping;
724724
725− mutex_lock(&mapping->i_mmap_mutex);
725+ i_mmap_lock_write(mapping);
726726 flush_dcache_mmap_lock(mapping);
727727 vma_interval_tree_insert(vma, &mapping->i_mmap);
728728 flush_dcache_mmap_unlock(mapping);
729− mutex_unlock(&mapping->i_mmap_mutex);
729+ i_mmap_unlock_write(mapping);
730730 }
731731
732732 /* add the VMA to the tree */
@@ -795,11 +795,11 @@ static void delete_vma_from_mm(struct vm_area_struct *vma) · 62 unmodified lines
795795 if (vma->vm_file) {
796796 mapping = vma->vm_file->f_mapping;
797797
798− mutex_lock(&mapping->i_mmap_mutex);
798+ i_mmap_lock_write(mapping);
799799 flush_dcache_mmap_lock(mapping);
800800 vma_interval_tree_remove(vma, &mapping->i_mmap);
801801 flush_dcache_mmap_unlock(mapping);
802− mutex_unlock(&mapping->i_mmap_mutex);
802+ i_mmap_unlock_write(mapping);
803803 }
804804
805805 /* 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
20942094 high = (size + PAGE_SIZE - 1) >> PAGE_SHIFT;
20952095
20962096 down_write(&nommu_region_sem);
2097− mutex_lock(&inode->i_mapping->i_mmap_mutex);
2097+ i_mmap_lock_write(inode->i_mapping);
20982098
20992099 /* search for VMAs that fall within the dead zone */
21002100 vma_interval_tree_foreach(vma, &inode->i_mapping->i_mmap, low, high) {
21012101 /* found one - only interested if it's shared out of the page
21022102 * cache */
21032103 if (vma->vm_flags & VM_SHARED) {
2104− mutex_unlock(&inode->i_mapping->i_mmap_mutex);
2104+ i_mmap_unlock_write(inode->i_mapping);
21052105 up_write(&nommu_region_sem);
21062106 return -ETXTBSY; /* not quite true, but near enough */
21072107 }
@@ -2129,7 +2129,7 @@ int nommu_shrink_inode_mappings(struct inode *inode, size_t size, · 21 unmodified lines
21292129 }
21302130 }
21312131
2132− mutex_unlock(&inode->i_mapping->i_mmap_mutex);
2132+ i_mmap_unlock_write(inode->i_mapping);
21332133 up_write(&nommu_region_sem);
21342134 return 0;
21352135 }
mm/rmap.c+2−2
@@ -1690,7 +1690,7 @@ static int rmap_walk_file(struct page *page, struct rmap_walk_control *rwc) · 1689 unmodified lines
16901690
16911691 if (!mapping)
16921692 return ret;
1693− mutex_lock(&mapping->i_mmap_mutex);
1693+ i_mmap_lock_write(mapping);
16941694 vma_interval_tree_foreach(vma, &mapping->i_mmap, pgoff, pgoff) {
16951695 unsigned long address = vma_address(page, vma);
16961696
@@ -1713,7 +1713,7 @@ static int rmap_walk_file(struct page *page, struct rmap_walk_control *rwc) · 16 unmodified lines
17131713 ret = rwc->file_nonlinear(page, mapping, rwc->arg);
17141714
17151715 done:
1716− mutex_unlock(&mapping->i_mmap_mutex);
1716+ i_mmap_unlock_write(mapping);
17171717 return ret;
17181718 }
17191719

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t