Module: Mesa
Branch: master
Commit: 6deb158ec1e03027d855df6a2513c8595ed95924
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=6deb158ec1e03027d855df6a2513c8595ed95924

Author: Eric Anholt <e...@anholt.net>
Date:   Tue Feb 20 16:05:29 2018 +0000

broadcom/vc4: Add pipe_reference debugging for vc4_bos.

Trying to track down the YUV EGLImage use-after-free, it helps to see what
the mystery objects are that are being refcounted.

---

 src/gallium/drivers/vc4/vc4_bufmgr.c | 10 +++++++++-
 src/gallium/drivers/vc4/vc4_bufmgr.h | 19 +++++++++++++++----
 2 files changed, 24 insertions(+), 5 deletions(-)

diff --git a/src/gallium/drivers/vc4/vc4_bufmgr.c 
b/src/gallium/drivers/vc4/vc4_bufmgr.c
index 274c4c3120..54f9d9c264 100644
--- a/src/gallium/drivers/vc4/vc4_bufmgr.c
+++ b/src/gallium/drivers/vc4/vc4_bufmgr.c
@@ -30,6 +30,7 @@
 
 #include "util/u_hash_table.h"
 #include "util/u_memory.h"
+#include "util/u_string.h"
 #include "util/ralloc.h"
 
 #include "vc4_context.h"
@@ -49,6 +50,13 @@ static void
 vc4_bo_cache_free_all(struct vc4_bo_cache *cache);
 
 void
+vc4_bo_debug_describe(char* buf, const struct vc4_bo *ptr)
+{
+   util_sprintf(buf, "vc4_bo<%s,%u,%u>", ptr->name ? ptr->name : "?",
+                ptr->handle, ptr->size);
+}
+
+void
 vc4_bo_label(struct vc4_screen *screen, struct vc4_bo *bo, const char *fmt, 
...)
 {
         /* Perform BO labeling by default on debug builds (so that you get
@@ -389,7 +397,7 @@ vc4_bo_open_handle(struct vc4_screen *screen,
 
         bo = util_hash_table_get(screen->bo_handles, (void*)(uintptr_t)handle);
         if (bo) {
-                pipe_reference(NULL, &bo->reference);
+                vc4_bo_reference(bo);
                 goto done;
         }
 
diff --git a/src/gallium/drivers/vc4/vc4_bufmgr.h 
b/src/gallium/drivers/vc4/vc4_bufmgr.h
index ecd0daa7c7..9fa4774427 100644
--- a/src/gallium/drivers/vc4/vc4_bufmgr.h
+++ b/src/gallium/drivers/vc4/vc4_bufmgr.h
@@ -73,10 +73,13 @@ struct vc4_bo *vc4_bo_open_dmabuf(struct vc4_screen 
*screen, int fd,
 bool vc4_bo_flink(struct vc4_bo *bo, uint32_t *name);
 int vc4_bo_get_dmabuf(struct vc4_bo *bo);
 
+void vc4_bo_debug_describe(char* buf, const struct vc4_bo *ptr);
 static inline struct vc4_bo *
 vc4_bo_reference(struct vc4_bo *bo)
 {
-        pipe_reference(NULL, &bo->reference);
+        pipe_reference_described(NULL, &bo->reference,
+                                 (debug_reference_descriptor)
+                                 vc4_bo_debug_describe);
         return bo;
 }
 
@@ -89,13 +92,18 @@ vc4_bo_unreference(struct vc4_bo **bo)
 
         if ((*bo)->private) {
                 /* Avoid the mutex for private BOs */
-                if (pipe_reference(&(*bo)->reference, NULL))
+                if (pipe_reference_described(&(*bo)->reference, NULL,
+                                             (debug_reference_descriptor)
+                                             vc4_bo_debug_describe)) {
                         vc4_bo_last_unreference(*bo);
+                }
         } else {
                 screen = (*bo)->screen;
                 mtx_lock(&screen->bo_handles_mutex);
 
-                if (pipe_reference(&(*bo)->reference, NULL)) {
+                if (pipe_reference_described(&(*bo)->reference, NULL,
+                                             (debug_reference_descriptor)
+                                             vc4_bo_debug_describe)) {
                         util_hash_table_remove(screen->bo_handles,
                                                (void 
*)(uintptr_t)(*bo)->handle);
                         vc4_bo_last_unreference(*bo);
@@ -113,8 +121,11 @@ vc4_bo_unreference_locked_timed(struct vc4_bo **bo, time_t 
time)
         if (!*bo)
                 return;
 
-        if (pipe_reference(&(*bo)->reference, NULL))
+        if (pipe_reference_described(&(*bo)->reference, NULL,
+                                     (debug_reference_descriptor)
+                                     vc4_bo_debug_describe)) {
                 vc4_bo_last_unreference_locked_timed(*bo, time);
+        }
         *bo = NULL;
 }
 

_______________________________________________
mesa-commit mailing list
mesa-commit@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-commit

Reply via email to