From 0a3784ae33bbdcd50b2a6d8de5d52779276bb36c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Pi=C3=B1eiro?= Date: Tue, 9 Jan 2024 13:48:07 +0100 Subject: [PATCH] v3dv/bo: use mtx_lock/unlock on cache_init too To handle coverity warning: 4. thread2_modifies_field: Thread2 sets cache_size to a new value. Note that this write can be reordered at runtime to occur before instructions that do not access this field within this locked region. After Thread2 leaves the critical section, control is switched back to Thread1. CID 1559509 (#1 of 1): Check of thread-shared field evades lock acquisition (LOCK_EVASION)6. thread1_overwrites_value_in_field: Thread1 sets cache_size to a new value. Now the two threads have an inconsistent view of cache_size and updates to fields correlated with cache_size may be lost. 521 cache->cache_size += bo->size; Reviewed-by: Juan A. Suarez Part-of: --- src/broadcom/vulkan/v3dv_bo.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/broadcom/vulkan/v3dv_bo.c b/src/broadcom/vulkan/v3dv_bo.c index 2728a9233f9..594401edd82 100644 --- a/src/broadcom/vulkan/v3dv_bo.c +++ b/src/broadcom/vulkan/v3dv_bo.c @@ -419,9 +419,11 @@ v3dv_bo_cache_init(struct v3dv_device *device) fprintf(stderr, "MAX BO CACHE SIZE: %iMB\n", device->bo_cache.max_cache_size); } + mtx_lock(&device->bo_cache.lock); device->bo_cache.max_cache_size *= 1024 * 1024; device->bo_cache.cache_count = 0; device->bo_cache.cache_size = 0; + mtx_unlock(&device->bo_cache.lock); } void