mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-07 02:48:06 +02:00
zink: Guard bo map/unmap on map_count.
Otherwise zink_bo_map can return cpu_ptr being destroyed by zink_bo_unmap.
Cc: mesa-stable
(cherry picked from commit ce45069c49)
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/41269>
This commit is contained in:
parent
ab39d20454
commit
7294206e88
2 changed files with 11 additions and 8 deletions
|
|
@ -1774,7 +1774,7 @@
|
|||
"description": "zink: Guard bo map/unmap on map_count.",
|
||||
"nominated": true,
|
||||
"nomination_type": 1,
|
||||
"resolution": 0,
|
||||
"resolution": 1,
|
||||
"main_sha": null,
|
||||
"because_sha": null,
|
||||
"notes": null
|
||||
|
|
|
|||
|
|
@ -707,8 +707,8 @@ zink_bo_map(struct zink_screen *screen, struct zink_bo *bo)
|
|||
offset = bo->offset - real->offset;
|
||||
}
|
||||
|
||||
p_atomic_inc(&real->u.real.map_count);
|
||||
cpu = p_atomic_read(&real->u.real.cpu_ptr);
|
||||
if (p_atomic_inc_return(&real->u.real.map_count) > 1)
|
||||
cpu = p_atomic_read(&real->u.real.cpu_ptr);
|
||||
if (!cpu) {
|
||||
simple_mtx_lock(&real->lock);
|
||||
/* Must re-check due to the possibility of a race. Re-check need not
|
||||
|
|
@ -743,12 +743,15 @@ zink_bo_unmap(struct zink_screen *screen, struct zink_bo *bo)
|
|||
|
||||
if (p_atomic_dec_zero(&real->u.real.map_count)) {
|
||||
simple_mtx_lock(&real->lock);
|
||||
p_atomic_set(&real->u.real.cpu_ptr, NULL);
|
||||
if (unlikely(zink_debug & ZINK_DEBUG_MAP)) {
|
||||
p_atomic_add(&screen->mapped_vram, -real->base.base.size);
|
||||
mesa_loge("UNMAP(%"PRIu64") TOTAL(%"PRIu64")", real->base.base.size, screen->mapped_vram);
|
||||
/* Re-check in case of race with zink_bo_map */
|
||||
if (!p_atomic_read(&real->u.real.map_count)) {
|
||||
p_atomic_set(&real->u.real.cpu_ptr, NULL);
|
||||
if (unlikely(zink_debug & ZINK_DEBUG_MAP)) {
|
||||
p_atomic_add(&screen->mapped_vram, -real->base.base.size);
|
||||
mesa_loge("UNMAP(%"PRIu64") TOTAL(%"PRIu64")", real->base.base.size, screen->mapped_vram);
|
||||
}
|
||||
VKSCR(UnmapMemory)(screen->dev, real->mem);
|
||||
}
|
||||
VKSCR(UnmapMemory)(screen->dev, real->mem);
|
||||
simple_mtx_unlock(&real->lock);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue