From b6640c1609a7ef5d7eec2ce72ffe6c7050404711 Mon Sep 17 00:00:00 2001 From: Valentine Burley Date: Thu, 19 Mar 2026 11:16:20 +0100 Subject: [PATCH] tu/drm/virtio: Avoid freeing zombified tu_sparse_vma This is d3cedd2fa56 ("tu/drm: msm's has_set_iova codepath should avoid freeing zombified tu_sparse_vma") but for virtio. Fixes: 764b3d9161c ("tu: Implement transient attachments and lazily allocated memory") Signed-off-by: Valentine Burley (cherry picked from commit f1366ca14479254ed29b6aa6c1d218ca8af6456f) Part-of: --- .pick_status.json | 2 +- src/freedreno/vulkan/tu_knl_drm_virtio.cc | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index 4d964fd08a0..57502b4bf37 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -3854,7 +3854,7 @@ "description": "tu/drm/virtio: Avoid freeing zombified tu_sparse_vma", "nominated": true, "nomination_type": 2, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": "764b3d9161c27afb57d20536c6968fa5085f34f1", "notes": null diff --git a/src/freedreno/vulkan/tu_knl_drm_virtio.cc b/src/freedreno/vulkan/tu_knl_drm_virtio.cc index 6db0645e106..4dbc85d3adf 100644 --- a/src/freedreno/vulkan/tu_knl_drm_virtio.cc +++ b/src/freedreno/vulkan/tu_knl_drm_virtio.cc @@ -753,6 +753,8 @@ virtio_bo_init(struct tu_device *dev, } *out_bo = bo; + if (lazy_vma) + lazy_vma->msm.backs_lazy_bo = true; /* We don't use bo->name here because for the !TU_DEBUG=bo case bo->name is NULL. */ tu_bo_set_kernel_name(dev, bo, name); @@ -947,9 +949,14 @@ static void virtio_sparse_vma_finish(struct tu_device *dev, struct tu_sparse_vma *vma) { - mtx_lock(&dev->vma_mutex); - util_vma_heap_free(&dev->vma, vma->msm.iova, vma->msm.size); - mtx_unlock(&dev->vma_mutex); + /* For has_set_iova, if a lazy BO was mapped into this sparse VMA + * the allocation will be handed off to the zombie VMA mechanism. + */ + if (!vma->msm.backs_lazy_bo) { + mtx_lock(&dev->vma_mutex); + util_vma_heap_free(&dev->vma, vma->msm.iova, vma->msm.size); + mtx_unlock(&dev->vma_mutex); + } } static VkResult