From 53d03d91b8993c81bb7e82505a03b9b14c0371ca Mon Sep 17 00:00:00 2001 From: Rob Clark Date: Mon, 9 Nov 2020 14:11:09 -0800 Subject: [PATCH] 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 Part-of: (cherry picked from commit cb034ae44f4a1f3ed036ba71fc42746efb4cd775) --- .pick_status.json | 2 +- src/gallium/drivers/freedreno/freedreno_gmem.c | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index c461ebbbbd7..202ed9e12fb 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -3604,7 +3604,7 @@ "description": "freedreno: Protect gmem_cache ralloc allocations", "nominated": true, "nomination_type": 1, - "resolution": 0, + "resolution": 1, "master_sha": null, "because_sha": "91f9bb99c5e0db38a1ac26dd9e6a967312f5e8b0" }, diff --git a/src/gallium/drivers/freedreno/freedreno_gmem.c b/src/gallium/drivers/freedreno/freedreno_gmem.c index 6119f564400..b54725f1e41 100644 --- a/src/gallium/drivers/freedreno/freedreno_gmem.c +++ b/src/gallium/drivers/freedreno/freedreno_gmem.c @@ -521,11 +521,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; + + /* 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); - fd_screen_lock(screen); - struct hash_entry *entry = _mesa_hash_table_search_pre_hashed(cache->ht, hash, key); if (entry) {