Skip to content

Commit 0a3784a

Browse files
committed
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 <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26951>
1 parent ffd0e3a commit 0a3784a

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

src/broadcom/vulkan/v3dv_bo.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,9 +419,11 @@ v3dv_bo_cache_init(struct v3dv_device *device)
419419
fprintf(stderr, "MAX BO CACHE SIZE: %iMB\n", device->bo_cache.max_cache_size);
420420
}
421421

422+
mtx_lock(&device->bo_cache.lock);
422423
device->bo_cache.max_cache_size *= 1024 * 1024;
423424
device->bo_cache.cache_count = 0;
424425
device->bo_cache.cache_size = 0;
426+
mtx_unlock(&device->bo_cache.lock);
425427
}
426428

427429
void

0 commit comments

Comments
 (0)