Mesa (master): freedreno: Protect gmem_cache ralloc allocations

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Tue Nov 10 18:27:28 UTC 2020


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

Author: Rob Clark <robdclark at chromium.org>
Date:   Mon Nov  9 14:11:09 2020 -0800

freedreno: Protect gmem_cache ralloc allocations

Since the ralloc context for cache_key allocation is shared between all
the contexts hanging off a screen, we need to allocate the key under the
screen->lock.

Fixes: 91f9bb99c5e ("freedreno: add gmem state cache")
Signed-off-by: Rob Clark <robdclark at chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7342>

---

 src/gallium/drivers/freedreno/freedreno_gmem.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/src/gallium/drivers/freedreno/freedreno_gmem.c b/src/gallium/drivers/freedreno/freedreno_gmem.c
index 04447ffef03..b97b41ae470 100644
--- a/src/gallium/drivers/freedreno/freedreno_gmem.c
+++ b/src/gallium/drivers/freedreno/freedreno_gmem.c
@@ -528,11 +528,15 @@ lookup_gmem_state(struct fd_batch *batch, bool assume_zs, bool no_scis_opt)
 	struct fd_screen *screen = batch->ctx->screen;
 	struct fd_gmem_cache *cache = &screen->gmem_cache;
 	struct fd_gmem_stateobj *gmem = NULL;
-	struct gmem_key *key = gmem_key_init(batch, assume_zs, no_scis_opt);
-	uint32_t hash = gmem_key_hash(key);
 
+	/* Lock before allocating gmem_key, since that a screen-wide
+	 * ralloc pool and ralloc itself is not thread-safe.
+	 */
 	fd_screen_lock(screen);
 
+	struct gmem_key *key = gmem_key_init(batch, assume_zs, no_scis_opt);
+	uint32_t hash = gmem_key_hash(key);
+
 	struct hash_entry *entry =
 		_mesa_hash_table_search_pre_hashed(cache->ht, hash, key);
 	if (entry) {



More information about the mesa-commit mailing list