Move from the deprecated mmap hook to the new mmap_prepare hook. The hook only validates the request and sets the VMA flags, operations and page protection.
Acked-by: Michael S. Tsirkin <[email protected]> Signed-off-by: Lorenzo Stoakes (ARM) <[email protected]> --- drivers/vhost/vdpa.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c index c912ac40ca37..c729efd108d0 100644 --- a/drivers/vhost/vdpa.c +++ b/drivers/vhost/vdpa.c @@ -1617,19 +1617,19 @@ static const struct vm_operations_struct vhost_vdpa_vm_ops = { .fault = vhost_vdpa_fault, }; -static int vhost_vdpa_mmap(struct file *file, struct vm_area_struct *vma) +static int vhost_vdpa_mmap_prepare(struct vm_area_desc *desc) { - struct vhost_vdpa *v = vma->vm_file->private_data; + struct vhost_vdpa *v = desc->file->private_data; struct vdpa_device *vdpa = v->vdpa; const struct vdpa_config_ops *ops = vdpa->config; struct vdpa_notification_area notify; - unsigned long index = vma->vm_pgoff; + unsigned long index = desc->pgoff; - if (vma->vm_end - vma->vm_start != PAGE_SIZE) + if (vma_desc_size(desc) != PAGE_SIZE) return -EINVAL; - if ((vma->vm_flags & VM_SHARED) == 0) + if (!vma_desc_test(desc, VMA_SHARED_BIT)) return -EINVAL; - if (vma->vm_flags & VM_READ) + if (vma_desc_test(desc, VMA_READ_BIT)) return -EINVAL; if (!ops->get_vq_notification) return -ENOTSUPP; @@ -1642,12 +1642,13 @@ static int vhost_vdpa_mmap(struct file *file, struct vm_area_struct *vma) return -EINVAL; if (notify.addr & (PAGE_SIZE - 1)) return -EINVAL; - if (vma->vm_end - vma->vm_start != notify.size) + if (vma_desc_size(desc) != notify.size) return -ENOTSUPP; - vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); - vm_flags_set(vma, VM_IO | VM_PFNMAP | VM_DONTEXPAND | VM_DONTDUMP); - vma->vm_ops = &vhost_vdpa_vm_ops; + desc->page_prot = pgprot_noncached(desc->page_prot); + vma_desc_set_flags(desc, VMA_IO_BIT, VMA_PFNMAP_BIT, VMA_DONTEXPAND_BIT, + VMA_DONTDUMP_BIT); + desc->vm_ops = &vhost_vdpa_vm_ops; return 0; } #endif /* CONFIG_MMU */ @@ -1659,7 +1660,7 @@ static const struct file_operations vhost_vdpa_fops = { .write_iter = vhost_vdpa_chr_write_iter, .unlocked_ioctl = vhost_vdpa_unlocked_ioctl, #ifdef CONFIG_MMU - .mmap = vhost_vdpa_mmap, + .mmap_prepare = vhost_vdpa_mmap_prepare, #endif /* CONFIG_MMU */ .compat_ioctl = compat_ptr_ioctl, }; -- 2.56.1
