Skip to contentSkip to conversation

drm/ttm: Warn on pinning without holding a reference

PATCH In review Daniel Vetter 4 participants 4 messages Oct 28, 2020 – Nov 27, 2020

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

PATCH 1/1 drm/ttm: Warn on pinning without holding a reference

Not technically a problem for ttm, but very likely a driver bug and pretty big time confusing for reviewing code.

So warn about it, both at cleanup time (so we catch these for sure) and at pin/unpin time (so we know who's the culprit).

Cc Christian Koenig <[email protected]>
Cc Huang Rui <[email protected]>
---
 drivers/gpu/drm/ttm/ttm_bo.c | 2 +-
 include/drm/ttm/ttm_bo_api.h | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/ttm/ttm_bo.c +1 -1
index f51b5e20fa17..a011072ab61d 100644
@@ -509,7 +509,7 @@ static void ttm_bo_release(struct kref *kref)
 		 * shrinkers, now that they are queued for
 		 * destruction.
 		 */
-		if (bo->pin_count) {
+		if (WARN_ON(bo->pin_count)) {
 			bo->pin_count = 0;
 			ttm_bo_del_from_lru(bo);
 			ttm_bo_add_mem_to_lru(bo, &bo->mem);
include/drm/ttm/ttm_bo_api.h +2 -0
index 37102e45e496..b45aee23d7d0 100644
@@ -571,6 +571,7 @@ static inline bool ttm_bo_uses_embedded_gem_object(struct ttm_buffer_object *bo)
 static inline void ttm_bo_pin(struct ttm_buffer_object *bo)
 {
 	dma_resv_assert_held(bo->base.resv);
+	WARN_ON_ONCE(!kref_read(&bo->kref));
 	++bo->pin_count;
 }
 
@@ -584,6 +585,7 @@ static inline void ttm_bo_unpin(struct ttm_buffer_object *bo)
 {
 	dma_resv_assert_held(bo->base.resv);
 	WARN_ON_ONCE(!bo->pin_count);
+	WARN_ON_ONCE(!kref_read(&bo->kref));
 	--bo->pin_count;
 }
 
Signature · 6 lines
2.28.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Daniel Vetter

Not technically a problem for ttm, but very likely a driver bug and pretty big time confusing for reviewing code.

So warn about it, both at cleanup time (so we catch these for sure) and at pin/unpin time (so we know who's the culprit).

Quoted 43 lines
Cc Christian Koenig <[email protected]>
Cc Huang Rui <[email protected]>
---
 drivers/gpu/drm/ttm/ttm_bo.c | 2 +-
 include/drm/ttm/ttm_bo_api.h | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/ttm/ttm_bo.c +1 -1
index f51b5e20fa17..a011072ab61d 100644
@@ -509,7 +509,7 @@ static void ttm_bo_release(struct kref *kref)
 		 * shrinkers, now that they are queued for
 		 * destruction.
 		 */
-		if (bo->pin_count) {
+		if (WARN_ON(bo->pin_count)) {
 			bo->pin_count = 0;
 			ttm_bo_del_from_lru(bo);
 			ttm_bo_add_mem_to_lru(bo, &bo->mem);
include/drm/ttm/ttm_bo_api.h +2 -0
index 37102e45e496..b45aee23d7d0 100644
@@ -571,6 +571,7 @@ static inline bool ttm_bo_uses_embedded_gem_object(struct ttm_buffer_object *bo)
 static inline void ttm_bo_pin(struct ttm_buffer_object *bo)
 {
 	dma_resv_assert_held(bo->base.resv);
+	WARN_ON_ONCE(!kref_read(&bo->kref));
 	++bo->pin_count;
 }
 
@@ -584,6 +585,7 @@ static inline void ttm_bo_unpin(struct ttm_buffer_object *bo)
 {
 	dma_resv_assert_held(bo->base.resv);
 	WARN_ON_ONCE(!bo->pin_count);
+	WARN_ON_ONCE(!kref_read(&bo->kref));
 	--bo->pin_count;
 }
 
Signature · 1 line
2.28.0

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

Reviewed-by on v1 1/1
#2 lore raw
In reply to Daniel Vetter

Am 28.10.20 um 12:31 schrieb Daniel Vetter:

Quoted 9 lines

Not technically a problem for ttm, but very likely a driver bug and pretty big time confusing for reviewing code.

So warn about it, both at cleanup time (so we catch these for sure) and at pin/unpin time (so we know who's the culprit).

Cc Christian Koenig <[email protected]>
Cc Huang Rui <[email protected]>
Quoted 31 lines
---
  drivers/gpu/drm/ttm/ttm_bo.c | 2 +-
  include/drm/ttm/ttm_bo_api.h | 2 ++
  2 files changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/ttm/ttm_bo.c +1 -1
index f51b5e20fa17..a011072ab61d 100644
@@ -509,7 +509,7 @@ static void ttm_bo_release(struct kref *kref)
  		 * shrinkers, now that they are queued for
  		 * destruction.
  		 */
-		if (bo->pin_count) {
+		if (WARN_ON(bo->pin_count)) {
  			bo->pin_count = 0;
  			ttm_bo_del_from_lru(bo);
  			ttm_bo_add_mem_to_lru(bo, &bo->mem);
include/drm/ttm/ttm_bo_api.h +1 -0
index 37102e45e496..b45aee23d7d0 100644
@@ -571,6 +571,7 @@ static inline bool ttm_bo_uses_embedded_gem_object(struct ttm_buffer_object *bo)
  static inline void ttm_bo_pin(struct ttm_buffer_object *bo)
  {
  	dma_resv_assert_held(bo->base.resv);
+	WARN_ON_ONCE(!kref_read(&bo->kref));
  	++bo->pin_count;
  }
 

include/drm/ttm/ttm_bo_api.h static inline void ttm_bo_unpin(struct ttm_buffer_object *bo) · line 591

Quoted 7 lines
include/drm/ttm/ttm_bo_api.h +1 -0
@@ -584,6 +585,7 @@ static inline void ttm_bo_unpin(struct ttm_buffer_object *bo)
  {
  	dma_resv_assert_held(bo->base.resv);
  	WARN_ON_ONCE(!bo->pin_count);
+	WARN_ON_ONCE(!kref_read(&bo->kref));
  	--bo->pin_count;
  }
 

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

#3 lore raw
Quoted 4 lines · Christian König

Am 28.10.20 um 12:31 schrieb Daniel Vetter:

Quoted 3 lines

Not technically a problem for ttm, but very likely a driver bug and pretty big time confusing for reviewing code.

Quoted 8 lines
Quoted 6 lines

So warn about it, both at cleanup time (so we catch these for sure) and at pin/unpin time (so we know who's the culprit).

Cc Christian Koenig <[email protected]>
Cc Huang Rui <[email protected]>

Remembered this patch, pushed it. Thanks to you both for the reviews. -Daniel

Quoted 38 lines
Quoted 37 lines
---
  drivers/gpu/drm/ttm/ttm_bo.c | 2 +-
  include/drm/ttm/ttm_bo_api.h | 2 ++
  2 files changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/ttm/ttm_bo.c +1 -1
index f51b5e20fa17..a011072ab61d 100644
@@ -509,7 +509,7 @@ static void ttm_bo_release(struct kref *kref)
  		 * shrinkers, now that they are queued for
  		 * destruction.
  		 */
-		if (bo->pin_count) {
+		if (WARN_ON(bo->pin_count)) {
  			bo->pin_count = 0;
  			ttm_bo_del_from_lru(bo);
  			ttm_bo_add_mem_to_lru(bo, &bo->mem);
include/drm/ttm/ttm_bo_api.h +2 -0
index 37102e45e496..b45aee23d7d0 100644
@@ -571,6 +571,7 @@ static inline bool ttm_bo_uses_embedded_gem_object(struct ttm_buffer_object *bo)
  static inline void ttm_bo_pin(struct ttm_buffer_object *bo)
  {
  	dma_resv_assert_held(bo->base.resv);
+	WARN_ON_ONCE(!kref_read(&bo->kref));
  	++bo->pin_count;
  }
@@ -584,6 +585,7 @@ static inline void ttm_bo_unpin(struct ttm_buffer_object *bo)
  {
  	dma_resv_assert_held(bo->base.resv);
  	WARN_ON_ONCE(!bo->pin_count);
+	WARN_ON_ONCE(!kref_read(&bo->kref));
  	--bo->pin_count;
  }
Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel