]> Git Repo - linux.git/commitdiff
drm/ttm: Warn on pinning without holding a reference
authorDaniel Vetter <[email protected]>
Wed, 28 Oct 2020 11:31:20 +0000 (12:31 +0100)
committerDaniel Vetter <[email protected]>
Fri, 27 Nov 2020 15:43:54 +0000 (16:43 +0100)
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).

Reviewed-by: Huang Rui <[email protected]>
Reviewed-by: Christian König <[email protected]>
Signed-off-by: Daniel Vetter <[email protected]>
Cc: Christian Koenig <[email protected]>
Cc: Huang Rui <[email protected]>
Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
drivers/gpu/drm/ttm/ttm_bo.c
include/drm/ttm/ttm_bo_api.h

index 9a03c7834b1eded3c7f9b26e6d3d69f3a81c1367..fc6b619c0329109ce652fc033c93b6bd2a141886 100644 (file)
@@ -514,7 +514,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);
index 2564e66e67d747cfb07bb6b0b5e3cd4a6f4fe7f6..79b9367e0ffd9cab8a046631fec6daccaceb6c5b 100644 (file)
@@ -600,6 +600,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;
 }
 
@@ -613,6 +614,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;
 }
 
This page took 0.063588 seconds and 4 git commands to generate.