Mesa (main): panfrost: Move bo->label assignment into the lock

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Tue Aug 24 19:22:31 UTC 2021


Module: Mesa
Branch: main
Commit: bd15e5e6af898f558267e93797083c4ba5a5b3d2
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=bd15e5e6af898f558267e93797083c4ba5a5b3d2

Author: Alyssa Rosenzweig <alyssa at collabora.com>
Date:   Thu Aug 12 23:25:49 2021 +0000

panfrost: Move bo->label assignment into the lock

We already took the lock, we just unlocked too early. Since the label is
reset in the BO cache, this is racy. Minimal impact in practice but is
still /wrong/ and caught by helgrind.

Fixes: 3fa1f93dace ("panfrost: Label all BOs in userspace")
Signed-off-by: Alyssa Rosenzweig <alyssa at collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12525>

---

 src/panfrost/lib/pan_bo.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/panfrost/lib/pan_bo.c b/src/panfrost/lib/pan_bo.c
index 033f06cc8e1..1fb02514fca 100644
--- a/src/panfrost/lib/pan_bo.c
+++ b/src/panfrost/lib/pan_bo.c
@@ -270,7 +270,9 @@ panfrost_bo_cache_put(struct panfrost_bo *bo)
         if (bo->flags & PAN_BO_SHARED || dev->debug & PAN_DBG_NO_CACHE)
                 return false;
 
+        /* Must be first */
         pthread_mutex_lock(&dev->bo_cache.lock);
+
         struct list_head *bucket = pan_bucket(dev, MAX2(bo->size, 4096));
         struct drm_panfrost_madvise madv;
         struct timespec time;
@@ -293,11 +295,12 @@ panfrost_bo_cache_put(struct panfrost_bo *bo)
          * lock.
          */
         panfrost_bo_cache_evict_stale_bos(dev);
-        pthread_mutex_unlock(&dev->bo_cache.lock);
 
         /* Update the label to help debug BO cache memory usage issues */
         bo->label = "Unused (BO cache)";
 
+        /* Must be last */
+        pthread_mutex_unlock(&dev->bo_cache.lock);
         return true;
 }
 



More information about the mesa-commit mailing list