ed5979
From 6282a83619f274ca45a52d61577c10a05a0714dc Mon Sep 17 00:00:00 2001
ed5979
From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= <eperezma@redhat.com>
ed5979
Date: Thu, 15 Dec 2022 12:31:43 +0100
ed5979
Subject: [PATCH 11/14] vdpa: add shadow_data to vhost_vdpa
ed5979
MIME-Version: 1.0
ed5979
Content-Type: text/plain; charset=UTF-8
ed5979
Content-Transfer-Encoding: 8bit
ed5979
ed5979
RH-Author: Eugenio Pérez <eperezma@redhat.com>
ed5979
RH-MergeRequest: 136: vDPA ASID support in Qemu
ed5979
RH-Bugzilla: 2104412
ed5979
RH-Acked-by: Laurent Vivier <lvivier@redhat.com>
ed5979
RH-Acked-by: Cindy Lu <lulu@redhat.com>
ed5979
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
ed5979
RH-Commit: [11/13] 9d317add1318b555ba06e19e4c67849069e047b9 (eperezmartin/qemu-kvm)
ed5979
ed5979
The memory listener that thells the device how to convert GPA to qemu's
ed5979
va is registered against CVQ vhost_vdpa. memory listener translations
ed5979
are always ASID 0, CVQ ones are ASID 1 if supported.
ed5979
ed5979
Let's tell the listener if it needs to register them on iova tree or
ed5979
not.
ed5979
ed5979
Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
ed5979
Acked-by: Jason Wang <jasowang@redhat.com>
ed5979
Message-Id: <20221215113144.322011-12-eperezma@redhat.com>
ed5979
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
ed5979
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
ed5979
(cherry picked from commit 6188d78a19894ac8f2bf9484d48a5235a529d3b7)
ed5979
---
ed5979
 hw/virtio/vhost-vdpa.c         | 6 +++---
ed5979
 include/hw/virtio/vhost-vdpa.h | 2 ++
ed5979
 net/vhost-vdpa.c               | 1 +
ed5979
 3 files changed, 6 insertions(+), 3 deletions(-)
ed5979
ed5979
diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c
ed5979
index 0ecf2bbaa0..dc3498e995 100644
ed5979
--- a/hw/virtio/vhost-vdpa.c
ed5979
+++ b/hw/virtio/vhost-vdpa.c
ed5979
@@ -224,7 +224,7 @@ static void vhost_vdpa_listener_region_add(MemoryListener *listener,
ed5979
                                          vaddr, section->readonly);
ed5979
 
ed5979
     llsize = int128_sub(llend, int128_make64(iova));
ed5979
-    if (v->shadow_vqs_enabled) {
ed5979
+    if (v->shadow_data) {
ed5979
         int r;
ed5979
 
ed5979
         mem_region.translated_addr = (hwaddr)(uintptr_t)vaddr,
ed5979
@@ -251,7 +251,7 @@ static void vhost_vdpa_listener_region_add(MemoryListener *listener,
ed5979
     return;
ed5979
 
ed5979
 fail_map:
ed5979
-    if (v->shadow_vqs_enabled) {
ed5979
+    if (v->shadow_data) {
ed5979
         vhost_iova_tree_remove(v->iova_tree, mem_region);
ed5979
     }
ed5979
 
ed5979
@@ -296,7 +296,7 @@ static void vhost_vdpa_listener_region_del(MemoryListener *listener,
ed5979
 
ed5979
     llsize = int128_sub(llend, int128_make64(iova));
ed5979
 
ed5979
-    if (v->shadow_vqs_enabled) {
ed5979
+    if (v->shadow_data) {
ed5979
         const DMAMap *result;
ed5979
         const void *vaddr = memory_region_get_ram_ptr(section->mr) +
ed5979
             section->offset_within_region +
ed5979
diff --git a/include/hw/virtio/vhost-vdpa.h b/include/hw/virtio/vhost-vdpa.h
ed5979
index e57dfa1fd1..45b969a311 100644
ed5979
--- a/include/hw/virtio/vhost-vdpa.h
ed5979
+++ b/include/hw/virtio/vhost-vdpa.h
ed5979
@@ -40,6 +40,8 @@ typedef struct vhost_vdpa {
ed5979
     struct vhost_vdpa_iova_range iova_range;
ed5979
     uint64_t acked_features;
ed5979
     bool shadow_vqs_enabled;
ed5979
+    /* Vdpa must send shadow addresses as IOTLB key for data queues, not GPA */
ed5979
+    bool shadow_data;
ed5979
     /* IOVA mapping used by the Shadow Virtqueue */
ed5979
     VhostIOVATree *iova_tree;
ed5979
     GPtrArray *shadow_vqs;
ed5979
diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c
ed5979
index 1757f1d028..eea7a0df12 100644
ed5979
--- a/net/vhost-vdpa.c
ed5979
+++ b/net/vhost-vdpa.c
ed5979
@@ -581,6 +581,7 @@ static NetClientState *net_vhost_vdpa_init(NetClientState *peer,
ed5979
     s->always_svq = svq;
ed5979
     s->vhost_vdpa.shadow_vqs_enabled = svq;
ed5979
     s->vhost_vdpa.iova_range = iova_range;
ed5979
+    s->vhost_vdpa.shadow_data = svq;
ed5979
     s->vhost_vdpa.iova_tree = iova_tree;
ed5979
     if (!is_datapath) {
ed5979
         s->cvq_cmd_out_buffer = qemu_memalign(qemu_real_host_page_size(),
ed5979
-- 
ed5979
2.31.1
ed5979