diff --git a/src/amd/common/virtio/amdgpu_virtio_bo.c b/src/amd/common/virtio/amdgpu_virtio_bo.c index a7e4fa0ecae..cd57c94f72e 100644 --- a/src/amd/common/virtio/amdgpu_virtio_bo.c +++ b/src/amd/common/virtio/amdgpu_virtio_bo.c @@ -1,5 +1,5 @@ /* - * Copyright 2024 Advanced Micro Devices, Inc. + * Copyright 2026 Advanced Micro Devices, Inc. * * SPDX-License-Identifier: MIT */ @@ -125,27 +125,29 @@ int amdvgpu_bo_export(amdvgpu_device_handle dev, amdvgpu_bo_handle bo, } int amdvgpu_bo_free(amdvgpu_device_handle dev, struct amdvgpu_bo *bo) { + simple_mtx_lock(&dev->handle_to_vbo_mutex); int refcnt = p_atomic_dec_return(&bo->refcount); if (refcnt == 0) { - /* Flush pending ops. */ - vdrm_flush(dev->vdev); - /* Remove it from the bo table. */ if (bo->host_blob->handle > 0) { - simple_mtx_lock(&dev->handle_to_vbo_mutex); void *entry = _mesa_hash_table_u64_search(dev->handle_to_vbo, bo->host_blob->handle); if (entry) { /* entry can be NULL for the shmem buffer. */ _mesa_hash_table_u64_remove(dev->handle_to_vbo, bo->host_blob->handle); } - simple_mtx_unlock(&dev->handle_to_vbo_mutex); } + simple_mtx_unlock(&dev->handle_to_vbo_mutex); + + /* Flush pending ops. */ + vdrm_flush(dev->vdev); if (bo->host_blob) destroy_host_blob(dev, bo->host_blob); free(bo); + } else { + simple_mtx_unlock(&dev->handle_to_vbo_mutex); } return 0;