All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jason Wang <jasowang@redhat.com>
To: mst@redhat.com
Cc: yang.zhong@intel.com, tiwei.bie@intel.com,
	Jason Wang <jasowang@redhat.com>,
	qemu-devel@nongnu.org, maxime.coquelin@redhat.com,
	Wei Xu <wexu@redhat.com>,
	jfreimann@redhat.com, weiyshay@gmail.com
Subject: [Qemu-devel] [PATCH V5 2/6] virtio: device/driverr area size calculation refactor for split ring
Date: Fri,  2 Aug 2019 00:06:02 -0400	[thread overview]
Message-ID: <20190802040606.22573-3-jasowang@redhat.com> (raw)
In-Reply-To: <20190802040606.22573-1-jasowang@redhat.com>

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(-)

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)
-- 
2.18.1



  parent reply	other threads:[~2019-08-02  4:07 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-02  4:06 [Qemu-devel] [PATCH V5 0/6] Packed virtqueue for virtrio Jason Wang
2019-08-02  4:06 ` [Qemu-devel] [PATCH V5 1/6] virtio: basic structure for packed ring Jason Wang
2019-08-02  9:01   ` Jens Freimann
2019-08-02  4:06 ` Jason Wang [this message]
2019-08-02  9:03   ` [Qemu-devel] [PATCH V5 2/6] virtio: device/driverr area size calculation refactor for split ring Jens Freimann
2019-08-02  9:43     ` Jason Wang
2019-08-02  4:06 ` [Qemu-devel] [PATCH V5 3/6] virtio: basic packed virtqueue support Jason Wang
2019-08-02  4:06 ` [Qemu-devel] [PATCH V5 4/6] virtio: event suppression support for packed ring Jason Wang
2019-08-02  4:06 ` [Qemu-devel] [PATCH V5 5/6] vhost_net: enable packed ring support Jason Wang
2019-08-02  9:03   ` Jens Freimann
2019-08-02  4:06 ` [Qemu-devel] [PATCH V5 6/6] virtio: add property to enable packed virtqueue Jason Wang
2019-08-02  9:04   ` Jens Freimann
2019-08-02  4:43 ` [Qemu-devel] [PATCH V5 0/6] Packed virtqueue for virtrio no-reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190802040606.22573-3-jasowang@redhat.com \
    --to=jasowang@redhat.com \
    --cc=jfreimann@redhat.com \
    --cc=maxime.coquelin@redhat.com \
    --cc=mst@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=tiwei.bie@intel.com \
    --cc=weiyshay@gmail.com \
    --cc=wexu@redhat.com \
    --cc=yang.zhong@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.