From bd15e5e6af898f558267e93797083c4ba5a5b3d2 Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Thu, 12 Aug 2021 23:25:49 +0000 Subject: [PATCH] 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 Part-of: --- 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; }