[PATCH 16/35] dmemfs: introduce ->split() to dmemfs_vm_ops

From: yulei . kernel
Date: Thu Oct 08 2020 - 03:55:08 EST


From: Yulei Zhang <yuleixzhang@xxxxxxxxxxx>

It is required by __split_vma() to adjust vma. munmap() which create
hole unaligned to pagesize in dmemfs-mapping should be forbidden.

Signed-off-by: Chen Zhuo <sagazchen@xxxxxxxxxxx>
Signed-off-by: Yulei Zhang <yuleixzhang@xxxxxxxxxxx>
---
fs/dmemfs/inode.c | 8 ++++++++
1 file changed, 8 insertions(+)

diff --git a/fs/dmemfs/inode.c b/fs/dmemfs/inode.c
index 6932d73edab6..e37498c00497 100644
--- a/fs/dmemfs/inode.c
+++ b/fs/dmemfs/inode.c
@@ -453,6 +453,13 @@ dmemfs_access_dmem(struct vm_area_struct *vma, unsigned long addr,
return len;
}

+static int dmemfs_split(struct vm_area_struct *vma, unsigned long addr)
+{
+ if (addr & (dmem_page_size(file_inode(vma->vm_file)) - 1))
+ return -EINVAL;
+ return 0;
+}
+
static vm_fault_t dmemfs_fault(struct vm_fault *vmf)
{
struct vm_area_struct *vma = vmf->vma;
@@ -487,6 +494,7 @@ static unsigned long dmemfs_pagesize(struct vm_area_struct *vma)
}

static const struct vm_operations_struct dmemfs_vm_ops = {
+ .split = dmemfs_split,
.fault = dmemfs_fault,
.pagesize = dmemfs_pagesize,
.access = dmemfs_access_dmem,
--
2.28.0