zink: fix data race in descriptor_util_pool_key_get

Two threads could end up creating a pool_key for the same hash and end up
overwriting the earlier one.

Fixes flaky image kernel_read_write CL CTS tests.

Cc: mesa-stable
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/36652>
(cherry picked from commit 9d8c95f8d3)
This commit is contained in:
Karol Herbst 2025-08-07 20:29:50 +02:00 committed by Eric Engestrom
parent 043d2f43f0
commit c33cf960ce
2 changed files with 4 additions and 4 deletions

View file

@ -5644,7 +5644,7 @@
"description": "zink: fix data race in descriptor_util_pool_key_get",
"nominated": true,
"nomination_type": 1,
"resolution": 0,
"resolution": 1,
"main_sha": null,
"because_sha": null,
"notes": null

View file

@ -202,9 +202,10 @@ descriptor_util_pool_key_get(struct zink_screen *screen, enum zink_descriptor_ty
hash = hash_descriptor_pool_key(&key);
simple_mtx_lock(&screen->desc_pool_keys_lock);
struct set_entry *he = _mesa_set_search_pre_hashed(&screen->desc_pool_keys[type], hash, &key);
simple_mtx_unlock(&screen->desc_pool_keys_lock);
if (he)
if (he) {
simple_mtx_unlock(&screen->desc_pool_keys_lock);
return (void*)he->key;
}
}
struct zink_descriptor_pool_key *pool_key = rzalloc(screen, struct zink_descriptor_pool_key);
@ -213,7 +214,6 @@ descriptor_util_pool_key_get(struct zink_screen *screen, enum zink_descriptor_ty
assert(pool_key->num_type_sizes);
memcpy(pool_key->sizes, sizes, num_type_sizes * sizeof(VkDescriptorPoolSize));
if (type != ZINK_DESCRIPTOR_TYPE_UNIFORMS) {
simple_mtx_lock(&screen->desc_pool_keys_lock);
_mesa_set_add_pre_hashed(&screen->desc_pool_keys[type], hash, pool_key);
pool_key->id = screen->desc_pool_keys[type].entries - 1;
simple_mtx_unlock(&screen->desc_pool_keys_lock);