Skip to contentSkip to conversation

drm/amd/amdgpu: lock reservation object while creating shadow bo

PATCH In review Nicolai Hähnle 2 participants 3 messages Jan 11, 2017 – Jan 12, 2017 1 message not in the archive

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

PATCH v2 1/2 drm/amd/amdgpu: lock reservation object while creating shadow bo

From: Nicolai Hähnle <[email protected]>

ttm_bo_init checks that the reservation object is locked. This is the caller's responsibility when resv != NULL. Otherwise, the inline reservation object of the newly allocated buffer is used and must explicitly be locked.

Uninterruptible w/w locks without an acquire context are always successful.

v2: use ww_mutex_lock

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +9 -0
index 11c12c4d..4b2a5a9 100644
@@ -465,21 +465,30 @@ int amdgpu_bo_create(struct amdgpu_device *adev,
 	amdgpu_ttm_placement_init(adev, &placement,
 				  placements, domain, flags);
 
 	r = amdgpu_bo_create_restricted(adev, size, byte_align, kernel,
 					domain, flags, sg, &placement,
 					resv, bo_ptr);
 	if (r)
 		return r;
 
 	if (amdgpu_need_backup(adev) && (flags & AMDGPU_GEM_CREATE_SHADOW)) {
+		if (!resv) {
+			r = ww_mutex_lock(&(*bo_ptr)->tbo.resv->lock, NULL);
+			WARN_ON(r != 0);
+		}
+
 		r = amdgpu_bo_create_shadow(adev, size, byte_align, (*bo_ptr));
+
+		if (!resv)
+			ww_mutex_unlock(&(*bo_ptr)->tbo.resv->lock);
+
 		if (r)
 			amdgpu_bo_unref(bo_ptr);
 	}
 
 	return r;
 }
 
 int amdgpu_bo_backup_to_shadow(struct amdgpu_device *adev,
 			       struct amdgpu_ring *ring,
 			       struct amdgpu_bo *bo,
Signature · 6 lines
2.7.4

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 1484151256-20743-1-git-send-email-nhaehnle-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

#2 lore raw

PATCH v2 2/2 drm/amd/amdgpu: fix locking in bo creation error path

From: Nicolai Hähnle <[email protected]>

Unlock the resv lock only if we were the ones to lock it in the first place.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +2 -1
index 4b2a5a9..5076bc2 100644
@@ -401,21 +401,22 @@ int amdgpu_bo_create_restricted(struct amdgpu_device *adev,
 	}
 	if (!resv)
 		ww_mutex_unlock(&bo->tbo.resv->lock);
 	*bo_ptr = bo;
 
 	trace_amdgpu_bo_create(bo);
 
 	return 0;
 
 fail_unreserve:
-	ww_mutex_unlock(&bo->tbo.resv->lock);
+	if (!resv)
+		ww_mutex_unlock(&bo->tbo.resv->lock);
 	amdgpu_bo_unref(&bo);
 	return r;
 }
 
 static int amdgpu_bo_create_shadow(struct amdgpu_device *adev,
 				   unsigned long size, int byte_align,
 				   struct amdgpu_bo *bo)
 {
 	struct ttm_placement placement = {0};
 	struct ttm_place placements[AMDGPU_GEM_DOMAIN_MAX + 1];
Signature · 6 lines
2.7.4

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Reviewed-by
#3 lore raw
In reply to a message not in the archive

Am 11.01.2017 um 17:14 schrieb Nicolai Hähnle:

Quoted 7 lines

From: Nicolai Hähnle <[email protected]>

ttm_bo_init checks that the reservation object is locked. This is the caller's responsibility when resv != NULL. Otherwise, the inline reservation object of the newly allocated buffer is used and must explicitly be locked.

Quoted 7 lines

Uninterruptible w/w locks without an acquire context are always successful.

v2: use ww_mutex_lock

Quoted 29 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 9 +++++++++
  1 file changed, 9 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +9 -0
index 11c12c4d..4b2a5a9 100644
@@ -465,21 +465,30 @@ int amdgpu_bo_create(struct amdgpu_device *adev,
  	amdgpu_ttm_placement_init(adev, &placement,
  				  placements, domain, flags);
 
  	r = amdgpu_bo_create_restricted(adev, size, byte_align, kernel,
  					domain, flags, sg, &placement,
  					resv, bo_ptr);
  	if (r)
  		return r;
 
  	if (amdgpu_need_backup(adev) && (flags & AMDGPU_GEM_CREATE_SHADOW)) {
+		if (!resv) {
+			r = ww_mutex_lock(&(*bo_ptr)->tbo.resv->lock, NULL);
+			WARN_ON(r != 0);
+		}
+
  		r = amdgpu_bo_create_shadow(adev, size, byte_align, (*bo_ptr));
+
+		if (!resv)
+			ww_mutex_unlock(&(*bo_ptr)->tbo.resv->lock);
+

drivers/gpu/drm/amd/amdgpu/amdgpu_object.c int amdgpu_bo_create(struct amdgpu_device *adev, · line 494

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +0 -0
  		if (r)
  			amdgpu_bo_unref(bo_ptr);
  	}
 
  	return r;
  }
 
  int amdgpu_bo_backup_to_shadow(struct amdgpu_device *adev,
  			       struct amdgpu_ring *ring,
  			       struct amdgpu_bo *bo,

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx