summaryrefslogtreecommitdiff
path: root/mm/mmap.c
diff options
context:
space:
mode:
authorChristian König <christian.koenig@amd.com>2020-09-14 15:09:33 +0200
committerChristian König <christian.koenig@amd.com>2020-11-05 13:03:52 +0100
commit2b5b95b1ff3d70a95013a45e3b5b90f1daf42348 (patch)
tree0d0d804862b63c20500e6e947931d18f440dbb45 /mm/mmap.c
parent0227da01f2559626396af5f6c7453360db86c1f6 (diff)
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/
Diffstat (limited to 'mm/mmap.c')
-rw-r--r--mm/mmap.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/mm/mmap.c b/mm/mmap.c
index 30a4e8412a58..b0093cc69240 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -137,6 +137,18 @@ void vma_set_page_prot(struct vm_area_struct *vma)
}
/*
+ * 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
*/
static void __remove_shared_vm_struct(struct vm_area_struct *vma,