[PATCH v2 16/20] drm/vmwgfx: implement mmap access managament

David Herrmann dh.herrmann at gmail.com
Sun Jul 7 10:17:32 PDT 2013


Correctly allow and revoke buffer access on each open/close via the new
VMA offset manager.

Also remove unused vmw_user_dmabuf_reference() to prevent from using it
later without correctly adding mmap permissions.

Cc: Thomas Hellstrom <thellstrom at vmware.com>
Signed-off-by: David Herrmann <dh.herrmann at gmail.com>
---
 drivers/gpu/drm/vmwgfx/vmwgfx_resource.c | 29 +++++++++++++++++------------
 1 file changed, 17 insertions(+), 12 deletions(-)

diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c b/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c
index 0e67cf4..4d3f0ae 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c
@@ -499,6 +499,12 @@ int vmw_dmabuf_alloc_ioctl(struct drm_device *dev, void *data,
 	if (unlikely(ret != 0))
 		goto out_no_dmabuf;
 
+	ret = drm_vma_node_allow(&dma_buf->base.vma_node, file_priv->filp);
+	if (ret) {
+		vmw_dmabuf_unreference(&dma_buf);
+		goto out_no_dmabuf;
+	}
+
 	rep->handle = handle;
 	rep->map_handle = drm_vma_node_offset_addr(&dma_buf->base.vma_node);
 	rep->cur_gmr_id = handle;
@@ -517,7 +523,18 @@ int vmw_dmabuf_unref_ioctl(struct drm_device *dev, void *data,
 {
 	struct drm_vmw_unref_dmabuf_arg *arg =
 	    (struct drm_vmw_unref_dmabuf_arg *)data;
+	struct ttm_object_file *tfile = vmw_fpriv(file_priv)->tfile;
+	struct vmw_dma_buffer *dma_buf;
+	int ret;
+
+	ret = vmw_user_dmabuf_lookup(tfile, arg->handle, &dma_buf);
+	if (ret)
+		return -EINVAL;
 
+	drm_vma_node_revoke(&dma_buf->base.vma_node, file_priv->filp);
+	vmw_dmabuf_unreference(&dma_buf);
+
+	/* FIXME: is this equivalent to vmw_dmabuf_unreference(dma_buf)? */
 	return ttm_ref_object_base_unref(vmw_fpriv(file_priv)->tfile,
 					 arg->handle,
 					 TTM_REF_USAGE);
@@ -551,18 +568,6 @@ int vmw_user_dmabuf_lookup(struct ttm_object_file *tfile,
 	return 0;
 }
 
-int vmw_user_dmabuf_reference(struct ttm_object_file *tfile,
-			      struct vmw_dma_buffer *dma_buf)
-{
-	struct vmw_user_dma_buffer *user_bo;
-
-	if (dma_buf->base.destroy != vmw_user_dmabuf_destroy)
-		return -EINVAL;
-
-	user_bo = container_of(dma_buf, struct vmw_user_dma_buffer, dma);
-	return ttm_ref_object_add(tfile, &user_bo->base, TTM_REF_USAGE, NULL);
-}
-
 /*
  * Stream management
  */
-- 
1.8.3.2



More information about the dri-devel mailing list