[PATCH 2/2] drm/etnaviv: properly implement mmaping of imported buffers

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.

Signed-off-by: Lucas Stach <l.stach@xxxxxxxxxxxxxx>
---
 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@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/dri-devel




[Index of Archives]     [Linux DRI Users]     [Linux Intel Graphics]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux