Skip to contentSkip to conversation

vhost-vdpa: Avoid unbalanced IOMMU region unref

PATCH In review Yuho Choi 1 participant 2 messages Sep 11 – Oct 20

lore
Share & tools
lore

Yuho Choi

author
#0 lore raw

PATCH 1/1 vhost-vdpa: Avoid unbalanced IOMMU region unref

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.")
---
 hw/virtio/vhost-vdpa.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
hw/virtio/vhost-vdpa.c +3 -1
index 9e1aa4860a8..2a067afd0a5 100644
@@ -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
Signature · 1 line
2.43.0
author
#1 lore raw

Hi,

Gentle ping on this patch.

Any feedback would be appreciated.

Thanks,
Yuho

Quoted 34 lines · Yuho Choi

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.")
---
 hw/virtio/vhost-vdpa.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
hw/virtio/vhost-vdpa.c +3 -2
index 9e1aa4860a8..2a067afd0a5 100644
@@ -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