Skip to content

Commit

Permalink
mm/mmap.c: pass in mapping to __vma_link_file()
Browse files Browse the repository at this point in the history
__vma_link_file() resolves the mapping from the file, if there is one.
Pass through the mapping and check the vm_file externally since most
places already have the required information and check of vm_file.

Link: https://lkml.kernel.org/r/[email protected]
Signed-off-by: Liam R. Howlett <[email protected]>
Tested-by: Yu Zhao <[email protected]>
Cc: Catalin Marinas <[email protected]>
Cc: David Hildenbrand <[email protected]>
Cc: David Howells <[email protected]>
Cc: Davidlohr Bueso <[email protected]>
Cc: "Matthew Wilcox (Oracle)" <[email protected]>
Cc: SeongJae Park <[email protected]>
Cc: Sven Schnelle <[email protected]>
Cc: Vlastimil Babka <[email protected]>
Cc: Will Deacon <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
  • Loading branch information
howlett authored and akpm00 committed Sep 27, 2022
1 parent d0601a5 commit c154124
Showing 1 changed file with 12 additions and 17 deletions.
29 changes: 12 additions & 17 deletions mm/mmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -407,21 +407,15 @@ static unsigned long count_vma_pages_range(struct mm_struct *mm,
return nr_pages;
}

static void __vma_link_file(struct vm_area_struct *vma)
static void __vma_link_file(struct vm_area_struct *vma,
struct address_space *mapping)
{
struct file *file;

file = vma->vm_file;
if (file) {
struct address_space *mapping = file->f_mapping;

if (vma->vm_flags & VM_SHARED)
mapping_allow_writable(mapping);
if (vma->vm_flags & VM_SHARED)
mapping_allow_writable(mapping);

flush_dcache_mmap_lock(mapping);
vma_interval_tree_insert(vma, &mapping->i_mmap);
flush_dcache_mmap_unlock(mapping);
}
flush_dcache_mmap_lock(mapping);
vma_interval_tree_insert(vma, &mapping->i_mmap);
flush_dcache_mmap_unlock(mapping);
}

/*
Expand Down Expand Up @@ -488,10 +482,11 @@ static int vma_link(struct mm_struct *mm, struct vm_area_struct *vma)
}

vma_mas_store(vma, &mas);
__vma_link_file(vma);

if (mapping)
if (mapping) {
__vma_link_file(vma, mapping);
i_mmap_unlock_write(mapping);
}

mm->map_count++;
validate_mm(mm);
Expand Down Expand Up @@ -730,14 +725,14 @@ int __vma_adjust(struct vm_area_struct *vma, unsigned long start,
uprobe_munmap(next, next->vm_start, next->vm_end);

i_mmap_lock_write(mapping);
if (insert) {
if (insert && insert->vm_file) {
/*
* Put into interval tree now, so instantiated pages
* are visible to arm/parisc __flush_dcache_page
* throughout; but we cannot insert into address
* space until vma start or end is updated.
*/
__vma_link_file(insert);
__vma_link_file(insert, insert->vm_file->f_mapping);
}
}

Expand Down

0 comments on commit c154124

Please sign in to comment.