git: c72dd0aabe25 - main - linuxkpi: Introduce `vma_set_file()`

From: Jean-Sébastien Pédron <dumbbell_at_FreeBSD.org>
Date: Fri, 11 Nov 2022 17:57:41 UTC
The branch main has been updated by dumbbell (ports committer):

URL: https://cgit.FreeBSD.org/src/commit/?id=c72dd0aabe25dd4ea82e5b83d36f706d8bd2e783

commit c72dd0aabe25dd4ea82e5b83d36f706d8bd2e783
Author:     Jean-Sébastien Pédron <dumbbell@FreeBSD.org>
AuthorDate: 2022-11-11 17:36:00 +0000
Commit:     Jean-Sébastien Pédron <dumbbell@FreeBSD.org>
CommitDate: 2022-11-11 17:36:00 +0000

    linuxkpi: Introduce `vma_set_file()`
    
    This code was moved from the i915 driver in Linux 5.11.
    
    Reviewed by:    manu
    Approved by:    manu
    Differential Revision:  https://reviews.freebsd.org/D36957
---
 sys/compat/linuxkpi/common/include/linux/mm.h |  2 ++
 sys/compat/linuxkpi/common/src/linux_compat.c | 12 ++++++++++++
 2 files changed, 14 insertions(+)

diff --git a/sys/compat/linuxkpi/common/include/linux/mm.h b/sys/compat/linuxkpi/common/include/linux/mm.h
index a0a96bcdb5a2..930d588902af 100644
--- a/sys/compat/linuxkpi/common/include/linux/mm.h
+++ b/sys/compat/linuxkpi/common/include/linux/mm.h
@@ -311,4 +311,6 @@ void lkpi_unmap_mapping_range(void *obj, loff_t const holebegin __unused,
 
 #define PAGE_ALIGNED(p)	__is_aligned(p, PAGE_SIZE)
 
+void vma_set_file(struct vm_area_struct *vma, struct linux_file *file);
+
 #endif					/* _LINUXKPI_LINUX_MM_H_ */
diff --git a/sys/compat/linuxkpi/common/src/linux_compat.c b/sys/compat/linuxkpi/common/src/linux_compat.c
index 1367556a6f43..26af40836c64 100644
--- a/sys/compat/linuxkpi/common/src/linux_compat.c
+++ b/sys/compat/linuxkpi/common/src/linux_compat.c
@@ -834,6 +834,18 @@ zap_vma_ptes(struct vm_area_struct *vma, unsigned long address,
 	return (0);
 }
 
+void
+vma_set_file(struct vm_area_struct *vma, struct linux_file *file)
+{
+	struct linux_file *tmp;
+
+	/* Changing an anonymous vma with this is illegal */
+	get_file(file);
+	tmp = vma->vm_file;
+	vma->vm_file = file;
+	fput(tmp);
+}
+
 static struct file_operations dummy_ldev_ops = {
 	/* XXXKIB */
 };