Let dataplane allocate different region for the desc/avail/used
ring regions.

Signed-off-by: Pierre Morel <pmo...@linux.vnet.ibm.com>
---
 hw/virtio/dataplane/vring.c         |   54 ++++++++++++++++++++++++++++------
 include/hw/virtio/dataplane/vring.h |    4 ++-
 2 files changed, 47 insertions(+), 11 deletions(-)

diff --git a/hw/virtio/dataplane/vring.c b/hw/virtio/dataplane/vring.c
index 07fd69c..49d783b 100644
--- a/hw/virtio/dataplane/vring.c
+++ b/hw/virtio/dataplane/vring.c
@@ -67,22 +67,46 @@ static void vring_unmap(void *buffer, bool is_write)
 /* Map the guest's vring to host memory */
 bool vring_setup(Vring *vring, VirtIODevice *vdev, int n)
 {
-    hwaddr vring_addr = virtio_queue_get_ring_addr(vdev, n);
-    hwaddr vring_size = virtio_queue_get_ring_size(vdev, n);
+    hwaddr vring_addr;
+    hwaddr vring_size;
     void *vring_ptr;
+    struct vring *vr = &vring->vr;
 
     vring->broken = false;
+    vr->num = virtio_queue_get_num(vdev, n);
 
-    vring_ptr = vring_map(&vring->mr, vring_addr, vring_size, true);
+    vring_addr = virtio_queue_get_desc_addr(vdev, n);
+    vring_size = virtio_queue_get_desc_size(vdev, n);
+    vring_ptr = vring_map(&vring->mr_desc, vring_addr, vring_size, true);
     if (!vring_ptr) {
-        error_report("Failed to map vring "
-                     "addr %#" HWADDR_PRIx " size %" HWADDR_PRIu,
-                     vring_addr, vring_size);
-        vring->broken = true;
-        return false;
+        error_report("Failed to map vring desc "
+                 "addr %#" HWADDR_PRIx " size %" HWADDR_PRIu,
+                 vring_addr, vring_size);
+        goto out_err_desc;
     }
+    vr->desc = vring_ptr;
 
-    vring_init(&vring->vr, virtio_queue_get_num(vdev, n), vring_ptr, 4096);
+    vring_addr = virtio_queue_get_avail_addr(vdev, n);
+    vring_size = virtio_queue_get_avail_size(vdev, n);
+    vring_ptr = vring_map(&vring->mr_avail, vring_addr, vring_size, true);
+    if (!vring_ptr) {
+        error_report("Failed to map vring avail "
+                 "addr %#" HWADDR_PRIx " size %" HWADDR_PRIu,
+                 vring_addr, vring_size);
+        goto out_err_avail;
+    }
+    vr->avail = vring_ptr;
+
+    vring_addr = virtio_queue_get_used_addr(vdev, n);
+    vring_size = virtio_queue_get_used_size(vdev, n);
+    vring_ptr = vring_map(&vring->mr_used, vring_addr, vring_size, true);
+    if (!vring_ptr) {
+        error_report("Failed to map vring used "
+                 "addr %#" HWADDR_PRIx " size %" HWADDR_PRIu,
+                 vring_addr, vring_size);
+        goto out_err_used;
+    }
+    vr->used = vring_ptr;
 
     vring->last_avail_idx = virtio_queue_get_last_avail_idx(vdev, n);
     vring->last_used_idx = vring_get_used_idx(vdev, vring);
@@ -92,6 +116,14 @@ bool vring_setup(Vring *vring, VirtIODevice *vdev, int n)
     trace_vring_setup(virtio_queue_get_ring_addr(vdev, n),
                       vring->vr.desc, vring->vr.avail, vring->vr.used);
     return true;
+
+out_err_used:
+    memory_region_unref(vring->mr_avail);
+out_err_avail:
+    memory_region_unref(vring->mr_desc);
+out_err_desc:
+    vring->broken = true;
+    return false;
 }
 
 void vring_teardown(Vring *vring, VirtIODevice *vdev, int n)
@@ -99,7 +131,9 @@ void vring_teardown(Vring *vring, VirtIODevice *vdev, int n)
     virtio_queue_set_last_avail_idx(vdev, n, vring->last_avail_idx);
     virtio_queue_invalidate_signalled_used(vdev, n);
 
-    memory_region_unref(vring->mr);
+    memory_region_unref(vring->mr_desc);
+    memory_region_unref(vring->mr_avail);
+    memory_region_unref(vring->mr_used);
 }
 
 /* Disable guest->host notifies */
diff --git a/include/hw/virtio/dataplane/vring.h 
b/include/hw/virtio/dataplane/vring.h
index 8d97db9..a596e4c 100644
--- a/include/hw/virtio/dataplane/vring.h
+++ b/include/hw/virtio/dataplane/vring.h
@@ -22,7 +22,9 @@
 #include "hw/virtio/virtio.h"
 
 typedef struct {
-    MemoryRegion *mr;               /* memory region containing the vring */
+    MemoryRegion *mr_desc;          /* memory region for the vring desc */
+    MemoryRegion *mr_avail;         /* memory region for the vring avail */
+    MemoryRegion *mr_used;          /* memory region for the vring used */
     struct vring vr;                /* virtqueue vring mapped to host memory */
     uint16_t last_avail_idx;        /* last processed avail ring index */
     uint16_t last_used_idx;         /* last processed used ring index */
-- 
1.7.1


Reply via email to