Skip to contentSkip to conversation

drm/amd/display: wait for fence without holding reservation lock

PATCH In review Christian König 2 participants 3 messages Apr 2, 2019 2 messages not in the archive

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

PATCH 1/1 drm/amd/display: wait for fence without holding reservation lock

Don't block others while waiting for the fences to finish, concurrent submission is perfectly valid in this case and holding the lock can prevent killed applications from terminating.

---
 drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +8 -5
index 697af51d403a..9426e701a7b6 100644
@@ -5129,23 +5129,26 @@ static void amdgpu_dm_commit_planes(struct drm_atomic_state *state,
 			continue;
 		}
 
+		abo = gem_to_amdgpu_bo(fb->obj[0]);
+
+		/* Wait for all fences on this FB */
+		r = reservation_object_wait_timeout_rcu(abo->tbo.resv, true,
+							false,
+							MAX_SCHEDULE_TIMEOUT);
+		WARN_ON(r < 0);
+
 		/*
 		 * TODO This might fail and hence better not used, wait
 		 * explicitly on fences instead
 		 * and in general should be called for
 		 * blocking commit to as per framework helpers
 		 */
-		abo = gem_to_amdgpu_bo(fb->obj[0]);
 		r = amdgpu_bo_reserve(abo, true);
 		if (unlikely(r != 0)) {
 			DRM_ERROR("failed to reserve buffer before flip\n");
 			WARN_ON(1);
 		}
 
-		/* Wait for all fences on this FB */
-		WARN_ON(reservation_object_wait_timeout_rcu(abo->tbo.resv, true, false,
-									    MAX_SCHEDULE_TIMEOUT) < 0);
-
 		amdgpu_bo_get_tiling_flags(abo, &tiling_flags);
 
 		amdgpu_bo_unreserve(abo);
Signature · 6 lines
2.17.1

_______________________________________________
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): 20190402142813.8381-1-christian.koenig-5C7GfCeVMHo@public.gmane.org

Reviewed-by Nicholas Kazlauskas
#2 lore raw
Quoted 5 lines · Christian König

Don't block others while waiting for the fences to finish, concurrent submission is perfectly valid in this case and holding the lock can prevent killed applications from terminating.

I do recall having the discussion about this a while back with you and Andrey.

I highly doubt that the flags would ever really change here (if they're even capable) between the wait and the lock so I think this is fine.

I think there's a bigger problem with that and how they could potentially change between atomic check and atomic commit tail anyway (and doing something bad after we think it's passed validation).

But this is mostly a theoretical concern I think rather than a practical one.

Thanks.

Nicholas Kazlauskas

Quoted 31 lines
---
  drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 13 ++++++++-----
  1 file changed, 8 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +8 -1
index 697af51d403a..9426e701a7b6 100644
@@ -5129,23 +5129,26 @@ static void amdgpu_dm_commit_planes(struct drm_atomic_state *state,
  			continue;
  		}
 
+		abo = gem_to_amdgpu_bo(fb->obj[0]);
+
+		/* Wait for all fences on this FB */
+		r = reservation_object_wait_timeout_rcu(abo->tbo.resv, true,
+							false,
+							MAX_SCHEDULE_TIMEOUT);
+		WARN_ON(r < 0);
+
  		/*
  		 * TODO This might fail and hence better not used, wait
  		 * explicitly on fences instead
  		 * and in general should be called for
  		 * blocking commit to as per framework helpers
  		 */
-		abo = gem_to_amdgpu_bo(fb->obj[0]);
  		r = amdgpu_bo_reserve(abo, true);
  		if (unlikely(r != 0)) {
  			DRM_ERROR("failed to reserve buffer before flip\n");

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static void amdgpu_dm_commit_planes(struct drm_atomic_state *state, · line 5154

Quoted 10 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -4
  			WARN_ON(1);
  		}
 
-		/* Wait for all fences on this FB */
-		WARN_ON(reservation_object_wait_timeout_rcu(abo->tbo.resv, true, false,
-									    MAX_SCHEDULE_TIMEOUT) < 0);
-
  		amdgpu_bo_get_tiling_flags(abo, &tiling_flags);
 
  		amdgpu_bo_unreserve(abo);

_______________________________________________
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): 9f78fcd2-2753-7145-03f9-cee3f4da9938-5C7GfCeVMHo@public.gmane.org

#4 lore raw
Quoted 19 lines · Nicholas
Quoted 5 lines · Christian König

Don't block others while waiting for the fences to finish, concurrent submission is perfectly valid in this case and holding the lock can prevent killed applications from terminating.

I do recall having the discussion about this a while back with you and Andrey.

I highly doubt that the flags would ever really change here (if they're even capable) between the wait and the lock so I think this is fine.

I think there's a bigger problem with that and how they could potentially change between atomic check and atomic commit tail anyway (and doing something bad after we think it's passed validation).

Quoted 6 lines

But this is mostly a theoretical concern I think rather than a practical one.

Thanks.

Nicholas Kazlauskas

...and waiting for the fence isn't really analogous to ensuring that they can't change in the first place I suppose.

This looks fine.

Nicholas Kazlauskas

Quoted 41 lines
Quoted 41 lines

---
   drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 13 ++++++++-----
   1 file changed, 8 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +8 -5
index 697af51d403a..9426e701a7b6 100644
@@ -5129,23 +5129,26 @@ static void amdgpu_dm_commit_planes(struct drm_atomic_state *state,
   			continue;
   		}
 
+		abo = gem_to_amdgpu_bo(fb->obj[0]);
+
+		/* Wait for all fences on this FB */
+		r = reservation_object_wait_timeout_rcu(abo->tbo.resv, true,
+							false,
+							MAX_SCHEDULE_TIMEOUT);
+		WARN_ON(r < 0);
+
   		/*
   		 * TODO This might fail and hence better not used, wait
   		 * explicitly on fences instead
   		 * and in general should be called for
   		 * blocking commit to as per framework helpers
   		 */
-		abo = gem_to_amdgpu_bo(fb->obj[0]);
   		r = amdgpu_bo_reserve(abo, true);
   		if (unlikely(r != 0)) {
   			DRM_ERROR("failed to reserve buffer before flip\n");
   			WARN_ON(1);
   		}
 
-		/* Wait for all fences on this FB */
-		WARN_ON(reservation_object_wait_timeout_rcu(abo->tbo.resv, true, false,
-									    MAX_SCHEDULE_TIMEOUT) < 0);
-
   		amdgpu_bo_get_tiling_flags(abo, &tiling_flags);
 
Quoted 8 lines

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static void amdgpu_dm_commit_planes(struct drm_atomic_state *state, · line 5154

Quoted 2 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -0
   		amdgpu_bo_unreserve(abo);

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

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