diff mbox series

[V5,2/6] virtio: device/driverr area size calculation refactor for split ring

Message ID 20190802040606.22573-3-jasowang@redhat.com
State New
Headers show
Series Packed virtqueue for virtrio | expand

Commit Message

Jason Wang Aug. 2, 2019, 4:06 a.m. UTC
From: Wei Xu <wexu@redhat.com>

There is slight size difference between split/packed rings.

This is the refactor of split ring as well as a helper to expanding
device and driver area size calculation for packed ring.

Signed-off-by: Wei Xu <wexu@redhat.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
---
 hw/virtio/virtio.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

Comments

Jens Freimann Aug. 2, 2019, 9:03 a.m. UTC | #1
In subject s/driverr/driver


On Fri, Aug 02, 2019 at 12:06:02AM -0400, Jason Wang wrote:
>From: Wei Xu <wexu@redhat.com>
>
>There is slight size difference between split/packed rings.
>
>This is the refactor of split ring as well as a helper to expanding
>device and driver area size calculation for packed ring.
>
>Signed-off-by: Wei Xu <wexu@redhat.com>
>Signed-off-by: Jason Wang <jasowang@redhat.com>
>---
> hw/virtio/virtio.c | 16 ++++++++++------
> 1 file changed, 10 insertions(+), 6 deletions(-)
>

Reviewed-by: Jens Freimann <jfreimann@redhat.com>
Jason Wang Aug. 2, 2019, 9:43 a.m. UTC | #2
On 2019/8/2 下午5:03, Jens Freimann wrote:
> In subject s/driverr/driver
>

Right, let me fix.

Thanks


>
> On Fri, Aug 02, 2019 at 12:06:02AM -0400, Jason Wang wrote:
>> From: Wei Xu <wexu@redhat.com>
>>
>> There is slight size difference between split/packed rings.
>>
>> This is the refactor of split ring as well as a helper to expanding
>> device and driver area size calculation for packed ring.
>>
>> Signed-off-by: Wei Xu <wexu@redhat.com>
>> Signed-off-by: Jason Wang <jasowang@redhat.com>
>> ---
>> hw/virtio/virtio.c | 16 ++++++++++------
>> 1 file changed, 10 insertions(+), 6 deletions(-)
>>
>
> Reviewed-by: Jens Freimann <jfreimann@redhat.com>
>
>
>
diff mbox series

Patch

diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
index 981738fa19..ac21ab43e2 100644
--- a/hw/virtio/virtio.c
+++ b/hw/virtio/virtio.c
@@ -155,10 +155,8 @@  static void virtio_init_region_cache(VirtIODevice *vdev, int n)
     VRingMemoryRegionCaches *old = vq->vring.caches;
     VRingMemoryRegionCaches *new = NULL;
     hwaddr addr, size;
-    int event_size;
     int64_t len;
 
-    event_size = virtio_vdev_has_feature(vq->vdev, VIRTIO_RING_F_EVENT_IDX) ? 2 : 0;
 
     addr = vq->vring.desc;
     if (!addr) {
@@ -173,7 +171,7 @@  static void virtio_init_region_cache(VirtIODevice *vdev, int n)
         goto err_desc;
     }
 
-    size = virtio_queue_get_used_size(vdev, n) + event_size;
+    size = virtio_queue_get_used_size(vdev, n);
     len = address_space_cache_init(&new->used, vdev->dma_as,
                                    vq->vring.used, size, true);
     if (len < size) {
@@ -181,7 +179,7 @@  static void virtio_init_region_cache(VirtIODevice *vdev, int n)
         goto err_used;
     }
 
-    size = virtio_queue_get_avail_size(vdev, n) + event_size;
+    size = virtio_queue_get_avail_size(vdev, n);
     len = address_space_cache_init(&new->avail, vdev->dma_as,
                                    vq->vring.avail, size, false);
     if (len < size) {
@@ -2410,14 +2408,20 @@  hwaddr virtio_queue_get_desc_size(VirtIODevice *vdev, int n)
 
 hwaddr virtio_queue_get_avail_size(VirtIODevice *vdev, int n)
 {
+    int s;
+
+    s = virtio_vdev_has_feature(vdev, VIRTIO_RING_F_EVENT_IDX) ? 2 : 0;
     return offsetof(VRingAvail, ring) +
-        sizeof(uint16_t) * vdev->vq[n].vring.num;
+        sizeof(uint16_t) * vdev->vq[n].vring.num + s;
 }
 
 hwaddr virtio_queue_get_used_size(VirtIODevice *vdev, int n)
 {
+    int s;
+
+    s = virtio_vdev_has_feature(vdev, VIRTIO_RING_F_EVENT_IDX) ? 2 : 0;
     return offsetof(VRingUsed, ring) +
-        sizeof(VRingUsedElem) * vdev->vq[n].vring.num;
+        sizeof(VRingUsedElem) * vdev->vq[n].vring.num + s;
 }
 
 uint16_t virtio_queue_get_last_avail_idx(VirtIODevice *vdev, int n)