[PATCH 2/2] drm/etnaviv: properly implement mmaping of imported buffers
Daniel Vetter
daniel at ffwll.ch
Tue May 29 08:20:15 UTC 2018
On Fri, May 25, 2018 at 03:42:54PM +0200, Lucas Stach wrote:
> The intention of the existing code was to deflect the actual work
> of mmaping a dma-buf to the exporter, as that one probably knows best
> how to handle the buffer. Unfortunately the call to drm_gem_mmap did
> more than what etnaviv needs in this case by actually setting up the
> mapping.
>
> Move mapping setup to the shm buffer type mmap implementation so we
> only need to look up the BO and call the buffer type mmap function
> from the handler.
>
> Fixes mmap behavior with dma-buf imported and userptr buffers.
You allow mmap on userptr buffers? That sounds really nasty ...
Also not really thrilled about dma-buf mmap forwarding either, since you
don't seem to forward the begin/end_cpu_access stuff either.
-Daniel
> Signed-off-by: Lucas Stach <l.stach at pengutronix.de>
> ---
> drivers/gpu/drm/etnaviv/etnaviv_gem.c | 30 ++++++++++++++++++++-------
> 1 file changed, 23 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gem.c b/drivers/gpu/drm/etnaviv/etnaviv_gem.c
> index fcc969fa0e69..f38989960d7f 100644
> --- a/drivers/gpu/drm/etnaviv/etnaviv_gem.c
> +++ b/drivers/gpu/drm/etnaviv/etnaviv_gem.c
> @@ -138,6 +138,13 @@ static int etnaviv_gem_mmap_obj(struct etnaviv_gem_object *etnaviv_obj,
> struct vm_area_struct *vma)
> {
> pgprot_t vm_page_prot;
> + int ret;
> +
> + ret = drm_gem_mmap_obj(&etnaviv_obj->base,
> + drm_vma_node_size(&etnaviv_obj->base.vma_node) << PAGE_SHIFT,
> + vma);
> + if (ret)
> + return ret;
>
> vma->vm_flags &= ~VM_PFNMAP;
> vma->vm_flags |= VM_MIXEDMAP;
> @@ -167,17 +174,26 @@ static int etnaviv_gem_mmap_obj(struct etnaviv_gem_object *etnaviv_obj,
>
> int etnaviv_gem_mmap(struct file *filp, struct vm_area_struct *vma)
> {
> - struct etnaviv_gem_object *obj;
> + struct drm_file *priv = filp->private_data;
> + struct etnaviv_gem_object *etnaviv_obj;
> + struct drm_gem_object *obj;
> int ret;
>
> - ret = drm_gem_mmap(filp, vma);
> - if (ret) {
> - DBG("mmap failed: %d", ret);
> - return ret;
> + obj = drm_gem_bo_vm_lookup(filp, vma);
> + if (!obj)
> + return -EINVAL;
> +
> + if (!drm_vma_node_is_allowed(&obj->vma_node, priv)) {
> + drm_gem_object_put_unlocked(obj);
> + return -EACCES;
> }
>
> - obj = to_etnaviv_bo(vma->vm_private_data);
> - return obj->ops->mmap(obj, vma);
> + etnaviv_obj = to_etnaviv_bo(obj);
> +
> + ret = etnaviv_obj->ops->mmap(etnaviv_obj, vma);
> + drm_gem_object_put_unlocked(obj);
> +
> + return ret;
> }
>
> int etnaviv_gem_fault(struct vm_fault *vmf)
> --
> 2.17.0
>
> _______________________________________________
> dri-devel mailing list
> dri-devel at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel
--
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
More information about the dri-devel
mailing list