Blame SOURCES/kvm-vdpa-do-not-save-failed-dma-maps-in-SVQ-iova-tree.patch

586cba
From 6d16102aca24bab16c846fe6457071f4466b8e35 Mon Sep 17 00:00:00 2001
586cba
From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= <eperezma@redhat.com>
586cba
Date: Tue, 23 Aug 2022 20:20:03 +0200
586cba
Subject: [PATCH 04/23] vdpa: do not save failed dma maps in SVQ iova tree
586cba
MIME-Version: 1.0
586cba
Content-Type: text/plain; charset=UTF-8
586cba
Content-Transfer-Encoding: 8bit
586cba
586cba
RH-Author: Eugenio Pérez <eperezma@redhat.com>
586cba
RH-MergeRequest: 116: vdpa: Restore device state on destination
586cba
RH-Bugzilla: 2114060
586cba
RH-Acked-by: Cindy Lu <lulu@redhat.com>
586cba
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
586cba
RH-Commit: [3/21] f9bea39f7fa14c5ef0f85774cbad0ca3b52c4498 (eperezmartin/qemu-kvm)
586cba
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2114060
586cba
Upstream status: git@github.com:jasowang/qemu.git net-next
586cba
586cba
If a map fails for whatever reason, it must not be saved in the tree.
586cba
Otherwise, qemu will try to unmap it in cleanup, leaving to more errors.
586cba
586cba
Fixes: 34e3c94eda ("vdpa: Add custom IOTLB translations to SVQ")
586cba
Reported-by: Lei Yang <leiyang@redhat.com>
586cba
Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
586cba
Acked-by: Jason Wang <jasowang@redhat.com>
586cba
Signed-off-by: Jason Wang <jasowang@redhat.com>
586cba
(cherry picked from commit 6cc2ec65382fde205511ac00a324995ce6ee8f28)
586cba
---
586cba
 hw/virtio/vhost-vdpa.c | 20 +++++++++++++-------
586cba
 1 file changed, 13 insertions(+), 7 deletions(-)
586cba
586cba
diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c
586cba
index aa7765c6bc..cc15b7d8ee 100644
586cba
--- a/hw/virtio/vhost-vdpa.c
586cba
+++ b/hw/virtio/vhost-vdpa.c
586cba
@@ -174,6 +174,7 @@ static void vhost_vdpa_listener_commit(MemoryListener *listener)
586cba
 static void vhost_vdpa_listener_region_add(MemoryListener *listener,
586cba
                                            MemoryRegionSection *section)
586cba
 {
586cba
+    DMAMap mem_region = {};
586cba
     struct vhost_vdpa *v = container_of(listener, struct vhost_vdpa, listener);
586cba
     hwaddr iova;
586cba
     Int128 llend, llsize;
586cba
@@ -210,13 +211,13 @@ static void vhost_vdpa_listener_region_add(MemoryListener *listener,
586cba
 
586cba
     llsize = int128_sub(llend, int128_make64(iova));
586cba
     if (v->shadow_vqs_enabled) {
586cba
-        DMAMap mem_region = {
586cba
-            .translated_addr = (hwaddr)(uintptr_t)vaddr,
586cba
-            .size = int128_get64(llsize) - 1,
586cba
-            .perm = IOMMU_ACCESS_FLAG(true, section->readonly),
586cba
-        };
586cba
+        int r;
586cba
 
586cba
-        int r = vhost_iova_tree_map_alloc(v->iova_tree, &mem_region);
586cba
+        mem_region.translated_addr = (hwaddr)(uintptr_t)vaddr,
586cba
+        mem_region.size = int128_get64(llsize) - 1,
586cba
+        mem_region.perm = IOMMU_ACCESS_FLAG(true, section->readonly),
586cba
+
586cba
+        r = vhost_iova_tree_map_alloc(v->iova_tree, &mem_region);
586cba
         if (unlikely(r != IOVA_OK)) {
586cba
             error_report("Can't allocate a mapping (%d)", r);
586cba
             goto fail;
586cba
@@ -230,11 +231,16 @@ static void vhost_vdpa_listener_region_add(MemoryListener *listener,
586cba
                              vaddr, section->readonly);
586cba
     if (ret) {
586cba
         error_report("vhost vdpa map fail!");
586cba
-        goto fail;
586cba
+        goto fail_map;
586cba
     }
586cba
 
586cba
     return;
586cba
 
586cba
+fail_map:
586cba
+    if (v->shadow_vqs_enabled) {
586cba
+        vhost_iova_tree_remove(v->iova_tree, &mem_region);
586cba
+    }
586cba
+
586cba
 fail:
586cba
     /*
586cba
      * On the initfn path, store the first error in the container so we
586cba
-- 
586cba
2.31.1
586cba