[PATCH 05/16] drm/nouveau: implement mmap access managament

David Herrmann dh.herrmann at gmail.com
Tue Aug 13 12:38:26 PDT 2013


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

Cc: Ben Skeggs <bskeggs at redhat.com>
Signed-off-by: David Herrmann <dh.herrmann at gmail.com>
---
 drivers/gpu/drm/nouveau/nouveau_gem.c | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
index 487242f..f2c4040 100644
--- a/drivers/gpu/drm/nouveau/nouveau_gem.c
+++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
@@ -67,32 +67,41 @@ nouveau_gem_object_open(struct drm_gem_object *gem, struct drm_file *file_priv)
 	struct nouveau_vma *vma;
 	int ret;
 
+	ret = drm_vma_node_allow(&nvbo->bo.vma_node, file_priv->filp);
+	if (ret)
+		return ret;
+
 	if (!cli->base.vm)
 		return 0;
 
 	ret = ttm_bo_reserve(&nvbo->bo, false, false, false, 0);
 	if (ret)
-		return ret;
+		goto err_node;
 
 	vma = nouveau_bo_vma_find(nvbo, cli->base.vm);
 	if (!vma) {
 		vma = kzalloc(sizeof(*vma), GFP_KERNEL);
 		if (!vma) {
 			ret = -ENOMEM;
-			goto out;
+			goto err_reserve;
 		}
 
 		ret = nouveau_bo_vma_add(nvbo, cli->base.vm, vma);
 		if (ret) {
 			kfree(vma);
-			goto out;
+			goto err_reserve;
 		}
 	} else {
 		vma->refcount++;
 	}
 
-out:
 	ttm_bo_unreserve(&nvbo->bo);
+	return 0;
+
+err_reserve:
+	ttm_bo_unreserve(&nvbo->bo);
+err_node:
+	drm_vma_node_revoke(&nvbo->bo.vma_node, file_priv->filp);
 	return ret;
 }
 
@@ -139,6 +148,8 @@ nouveau_gem_object_close(struct drm_gem_object *gem, struct drm_file *file_priv)
 	struct nouveau_vma *vma;
 	int ret;
 
+	drm_vma_node_revoke(&nvbo->bo.vma_node, file_priv->filp);
+
 	if (!cli->base.vm)
 		return;
 
-- 
1.8.3.4



More information about the dri-devel mailing list