Skip to contentSkip to conversation

drm/nouveau: wait for moving fence after pinning v2

PATCH In review Christian König 2 participants 4 messages Jun 22, 2021

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/3 drm/nouveau: wait for moving fence after pinning v2

We actually need to wait for the moving fence after pinning the BO to make sure that the pin is completed.

v2: grab the lock while waiting

References: https://lore.kernel.org/dri-devel/[email protected]/
CC: [email protected]

---
 drivers/gpu/drm/nouveau/nouveau_prime.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)
drivers/gpu/drm/nouveau/nouveau_prime.c +16 -1
index 347488685f74..60019d0532fc 100644
@@ -93,7 +93,22 @@ int nouveau_gem_prime_pin(struct drm_gem_object *obj)
 	if (ret)
 		return -EINVAL;
 
-	return 0;
+	ret = ttm_bo_reserve(&nvbo->bo, false, false, NULL);
+	if (ret)
+		goto error;
+
+	if (nvbo->bo.moving)
+		ret = dma_fence_wait(nvbo->bo.moving, true);
+
+	ttm_bo_unreserve(&nvbo->bo);
+	if (ret)
+		goto error;
+
+	return ret;
+
+error:
+	nouveau_bo_unpin(nvbo);
+	return ret;
 }
 
 void nouveau_gem_prime_unpin(struct drm_gem_object *obj)
Signature · 1 line
2.25.1
#1 lore raw

PATCH 2/3 drm/radeon: wait for moving fence after pinning

We actually need to wait for the moving fence after pinning the BO to make sure that the pin is completed.

References: https://lore.kernel.org/dri-devel/[email protected]/
CC: [email protected]

---
 drivers/gpu/drm/radeon/radeon_prime.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)
drivers/gpu/drm/radeon/radeon_prime.c +13 -3
index 42a87948e28c..4a90807351e7 100644
@@ -77,9 +77,19 @@ int radeon_gem_prime_pin(struct drm_gem_object *obj)
 
 	/* pin buffer into GTT */
 	ret = radeon_bo_pin(bo, RADEON_GEM_DOMAIN_GTT, NULL);
-	if (likely(ret == 0))
-		bo->prime_shared_count++;
-
+	if (unlikely(ret))
+		goto error;
+
+	if (bo->tbo.moving) {
+		ret = dma_fence_wait(bo->tbo.moving, false);
+		if (unlikely(ret)) {
+			radeon_bo_unpin(bo);
+			goto error;
+		}
+	}
+
+	bo->prime_shared_count++;
+error:
 	radeon_bo_unreserve(bo);
 	return ret;
 }
Signature · 1 line
2.25.1
#2 lore raw

PATCH 3/3 drm/amdgpu: wait for moving fence after pinning

In reply to Christian König

We actually need to wait for the moving fence after pinning the BO to make sure that the pin is completed.

References: https://lore.kernel.org/dri-devel/[email protected]/
CC: [email protected]

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c +13 -1
index baa980a477d9..37ec59365080 100644
@@ -214,9 +214,21 @@ static int amdgpu_dma_buf_pin(struct dma_buf_attachment *attach)
 {
 	struct drm_gem_object *obj = attach->dmabuf->priv;
 	struct amdgpu_bo *bo = gem_to_amdgpu_bo(obj);
+	int r;
 
 	/* pin buffer into GTT */
-	return amdgpu_bo_pin(bo, AMDGPU_GEM_DOMAIN_GTT);
+	r = amdgpu_bo_pin(bo, AMDGPU_GEM_DOMAIN_GTT);
+	if (r)
+		return r;
+
+	if (bo->tbo.moving) {
+		r = dma_fence_wait(bo->tbo.moving, true);
+		if (r) {
+			amdgpu_bo_unpin(bo);
+			return r;
+		}
+	}
+	return 0;
 }
 
 /**
Signature · 1 line
2.25.1
Reviewed-by on v1 1/3
#3 lore raw
In reply to Christian König
Quoted 9 lines · Christian König

We actually need to wait for the moving fence after pinning the BO to make sure that the pin is completed.

v2: grab the lock while waiting

References: https://lore.kernel.org/dri-devel/[email protected]/
CC: [email protected]

Quoted 35 lines
---
 drivers/gpu/drm/nouveau/nouveau_prime.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)
drivers/gpu/drm/nouveau/nouveau_prime.c +16 -2
index 347488685f74..60019d0532fc 100644
@@ -93,7 +93,22 @@ int nouveau_gem_prime_pin(struct drm_gem_object *obj)
        if (ret)
                return -EINVAL;
 
-       return 0;
+       ret = ttm_bo_reserve(&nvbo->bo, false, false, NULL);
+       if (ret)
+               goto error;
+
+       if (nvbo->bo.moving)
+               ret = dma_fence_wait(nvbo->bo.moving, true);
+
+       ttm_bo_unreserve(&nvbo->bo);
+       if (ret)
+               goto error;
+
+       return ret;
+
+error:
+       nouveau_bo_unpin(nvbo);
+       return ret;
 }
 
 void nouveau_gem_prime_unpin(struct drm_gem_object *obj)
--

2.25.1

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch