mm: introduce vma_set_file function v4
Add the new vma_set_file() function to allow changing
vma->vm_file with the necessary refcount dance.
v2: add more users of this.
v3: add missing EXPORT_SYMBOL, rebase on mmap cleanup,
add comments why we drop the reference on two occasions.
v4: make it clear that changing an anonymous vma is illegal.
Signed-off-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch> (v2)
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Link: https://patchwork.freedesktop.org/patch/394773/
This commit is contained in:
12
mm/mmap.c
12
mm/mmap.c
@@ -136,6 +136,18 @@ void vma_set_page_prot(struct vm_area_struct *vma)
|
||||
WRITE_ONCE(vma->vm_page_prot, vm_page_prot);
|
||||
}
|
||||
|
||||
/*
|
||||
* Change backing file, only valid to use during initial VMA setup.
|
||||
*/
|
||||
void vma_set_file(struct vm_area_struct *vma, struct file *file)
|
||||
{
|
||||
/* Changing an anonymous vma with this is illegal */
|
||||
get_file(file);
|
||||
swap(vma->vm_file, file);
|
||||
fput(file);
|
||||
}
|
||||
EXPORT_SYMBOL(vma_set_file);
|
||||
|
||||
/*
|
||||
* Requires inode->i_mapping->i_mmap_rwsem
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user