Mesa (staging/21.2): panfrost: Move bo->label assignment into the lock

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Thu Aug 26 17:46:43 UTC 2021


Module: Mesa
Branch: staging/21.2
Commit: a56b5e1fcd86549abfe2f3c50ae0176931190d01
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=a56b5e1fcd86549abfe2f3c50ae0176931190d01

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>
(cherry picked from commit bd15e5e6af898f558267e93797083c4ba5a5b3d2)

---

 .pick_status.json         | 2 +-
 src/panfrost/lib/pan_bo.c | 5 ++++-
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/.pick_status.json b/.pick_status.json
index f9187396445..e4b1d8a7144 100644
--- a/.pick_status.json
+++ b/.pick_status.json
@@ -1237,7 +1237,7 @@
         "description": "panfrost: Move bo->label assignment into the lock",
         "nominated": true,
         "nomination_type": 1,
-        "resolution": 0,
+        "resolution": 1,
         "main_sha": null,
         "because_sha": "3fa1f93dace64d9f71869e08f3665f3e48b07286"
     },
diff --git a/src/panfrost/lib/pan_bo.c b/src/panfrost/lib/pan_bo.c
index 7e07c41cc32..178e8b333cf 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)
                 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