vhost_vdpa_listener_region_add() handles IOMMU regions separately and
returns without calling memory_region_ref(). Its delete counterpart
removes the IOMMU notifier, continues through the shared DMA unmap path,
and then unconditionally drops an owner reference that was never acquired.

Limit memory_region_unref() to non-IOMMU regions. This keeps the existing
full-range DMA unmap for IOMMU teardown while balancing the references
acquired for RAM sections.

Fixes: bc7b0cac7bf4 ("vhost-vdpa: Add support for vIOMMU.")
Signed-off-by: Yuho Choi <[email protected]>
---
 hw/virtio/vhost-vdpa.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c
index 9e1aa4860a8..2a067afd0a5 100644
--- a/hw/virtio/vhost-vdpa.c
+++ b/hw/virtio/vhost-vdpa.c
@@ -487,7 +487,9 @@ static void vhost_vdpa_listener_region_del(MemoryListener 
*listener,
                      s, iova, int128_get64(llsize), ret);
     }
 
-    memory_region_unref(section->mr);
+    if (!memory_region_is_iommu(section->mr)) {
+        memory_region_unref(section->mr);
+    }
 }
 /*
  * IOTLB API is used by vhost-vdpa which requires incremental updating
-- 
2.43.0


Reply via email to