venus: fix image reqs cache store locking

lock the entire scope when storing image reqs cache entry to prevent
entry being added between the split locks.

Fixes: b51ff22fbe ("venus: support caching image memory requirements")

Signed-off-by: Juston Li <justonli@google.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/27401>
(cherry picked from commit f3de6f17c1)
This commit is contained in:
Juston Li 2024-02-02 13:29:23 -08:00 committed by Eric Engestrom
parent 000135abe1
commit be7a46c3c5
2 changed files with 18 additions and 13 deletions

View file

@ -9394,7 +9394,7 @@
"description": "venus: fix image reqs cache store locking",
"nominated": true,
"nomination_type": 1,
"resolution": 0,
"resolution": 1,
"main_sha": null,
"because_sha": "b51ff22fbe8c9786f968e102ef8d223f415fcaba",
"notes": null

View file

@ -231,8 +231,15 @@ vn_image_store_reqs_in_cache(struct vn_device *dev,
assert(cache->ht);
simple_mtx_lock(&cache->mutex);
uint32_t cache_entry_count = _mesa_hash_table_num_entries(cache->ht);
if (cache_entry_count == IMAGE_REQS_CACHE_MAX_ENTRIES) {
/* Check if entry was added before lock */
if (_mesa_hash_table_search(cache->ht, key)) {
simple_mtx_unlock(&cache->mutex);
return;
}
if (_mesa_hash_table_num_entries(cache->ht) ==
IMAGE_REQS_CACHE_MAX_ENTRIES) {
/* Evict/use the last entry in the lru list for this new entry */
cache_entry =
list_last_entry(&cache->lru, struct vn_image_reqs_cache_entry, head);
@ -242,11 +249,11 @@ vn_image_store_reqs_in_cache(struct vn_device *dev,
} else {
cache_entry = vk_zalloc(alloc, sizeof(*cache_entry), VN_DEFAULT_ALIGN,
VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
if (!cache_entry) {
simple_mtx_unlock(&cache->mutex);
return;
}
}
simple_mtx_unlock(&cache->mutex);
if (!cache_entry)
return;
for (uint32_t i = 0; i < plane_count; i++)
cache_entry->requirements[i] = requirements[i];
@ -254,12 +261,10 @@ vn_image_store_reqs_in_cache(struct vn_device *dev,
memcpy(cache_entry->key, key, SHA1_DIGEST_LENGTH);
cache_entry->plane_count = plane_count;
simple_mtx_lock(&cache->mutex);
if (!_mesa_hash_table_search(cache->ht, cache_entry->key)) {
_mesa_hash_table_insert(dev->image_reqs_cache.ht, cache_entry->key,
cache_entry);
list_add(&cache_entry->head, &cache->lru);
}
_mesa_hash_table_insert(dev->image_reqs_cache.ht, cache_entry->key,
cache_entry);
list_add(&cache_entry->head, &cache->lru);
simple_mtx_unlock(&cache->mutex);
}