qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Jason Wang <jasowang@redhat.com>
To: qemu-devel@nongnu.org, peter.maydell@linaro.org
Cc: "Eugenio Pérez" <eperezma@redhat.com>,
	"Jason Wang" <jasowang@redhat.com>,
	"Michael S . Tsirkin" <mst@redhat.com>
Subject: [PULL 01/24] vhost: move descriptor translation to vhost_svq_vring_write_descs
Date: Tue, 19 Jul 2022 21:16:14 +0800	[thread overview]
Message-ID: <20220719131637.46131-2-jasowang@redhat.com> (raw)
In-Reply-To: <20220719131637.46131-1-jasowang@redhat.com>

From: Eugenio Pérez <eperezma@redhat.com>

It's done for both in and out descriptors so it's better placed here.

Acked-by: Jason Wang <jasowang@redhat.com>
Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
---
 hw/virtio/vhost-shadow-virtqueue.c | 38 +++++++++++++++++++++++++++-----------
 1 file changed, 27 insertions(+), 11 deletions(-)

diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-virtqueue.c
index 56c96eb..e2184a4 100644
--- a/hw/virtio/vhost-shadow-virtqueue.c
+++ b/hw/virtio/vhost-shadow-virtqueue.c
@@ -122,17 +122,35 @@ static bool vhost_svq_translate_addr(const VhostShadowVirtqueue *svq,
     return true;
 }
 
-static void vhost_vring_write_descs(VhostShadowVirtqueue *svq, hwaddr *sg,
-                                    const struct iovec *iovec, size_t num,
-                                    bool more_descs, bool write)
+/**
+ * Write descriptors to SVQ vring
+ *
+ * @svq: The shadow virtqueue
+ * @sg: Cache for hwaddr
+ * @iovec: The iovec from the guest
+ * @num: iovec length
+ * @more_descs: True if more descriptors come in the chain
+ * @write: True if they are writeable descriptors
+ *
+ * Return true if success, false otherwise and print error.
+ */
+static bool vhost_svq_vring_write_descs(VhostShadowVirtqueue *svq, hwaddr *sg,
+                                        const struct iovec *iovec, size_t num,
+                                        bool more_descs, bool write)
 {
     uint16_t i = svq->free_head, last = svq->free_head;
     unsigned n;
     uint16_t flags = write ? cpu_to_le16(VRING_DESC_F_WRITE) : 0;
     vring_desc_t *descs = svq->vring.desc;
+    bool ok;
 
     if (num == 0) {
-        return;
+        return true;
+    }
+
+    ok = vhost_svq_translate_addr(svq, sg, iovec, num);
+    if (unlikely(!ok)) {
+        return false;
     }
 
     for (n = 0; n < num; n++) {
@@ -150,6 +168,7 @@ static void vhost_vring_write_descs(VhostShadowVirtqueue *svq, hwaddr *sg,
     }
 
     svq->free_head = le16_to_cpu(svq->desc_next[last]);
+    return true;
 }
 
 static bool vhost_svq_add_split(VhostShadowVirtqueue *svq,
@@ -169,21 +188,18 @@ static bool vhost_svq_add_split(VhostShadowVirtqueue *svq,
         return false;
     }
 
-    ok = vhost_svq_translate_addr(svq, sgs, elem->out_sg, elem->out_num);
+    ok = vhost_svq_vring_write_descs(svq, sgs, elem->out_sg, elem->out_num,
+                                     elem->in_num > 0, false);
     if (unlikely(!ok)) {
         return false;
     }
-    vhost_vring_write_descs(svq, sgs, elem->out_sg, elem->out_num,
-                            elem->in_num > 0, false);
-
 
-    ok = vhost_svq_translate_addr(svq, sgs, elem->in_sg, elem->in_num);
+    ok = vhost_svq_vring_write_descs(svq, sgs, elem->in_sg, elem->in_num, false,
+                                     true);
     if (unlikely(!ok)) {
         return false;
     }
 
-    vhost_vring_write_descs(svq, sgs, elem->in_sg, elem->in_num, false, true);
-
     /*
      * Put the entry in the available array (but don't update avail->idx until
      * they do sync).
-- 
2.7.4



  reply	other threads:[~2022-07-19 13:19 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-19 13:16 [PULL 00/24] Net Patches Jason Wang
2022-07-19 13:16 ` Jason Wang [this message]
2022-07-19 13:16 ` [PULL 02/24] virtio-net: Expose MAC_TABLE_ENTRIES Jason Wang
2022-07-19 13:16 ` [PULL 03/24] virtio-net: Expose ctrl virtqueue logic Jason Wang
2022-07-19 13:16 ` [PULL 04/24] vdpa: Avoid compiler to squash reads to used idx Jason Wang
2022-07-19 13:16 ` [PULL 05/24] vhost: Reorder vhost_svq_kick Jason Wang
2022-07-19 13:16 ` [PULL 06/24] vhost: Move vhost_svq_kick call to vhost_svq_add Jason Wang
2022-07-19 13:16 ` [PULL 07/24] vhost: Check for queue full at vhost_svq_add Jason Wang
2022-07-19 13:16 ` [PULL 08/24] vhost: Decouple vhost_svq_add from VirtQueueElement Jason Wang
2022-07-19 13:16 ` [PULL 09/24] vhost: Add SVQDescState Jason Wang
2022-07-19 13:16 ` [PULL 10/24] vhost: Track number of descs in SVQDescState Jason Wang
2022-07-19 13:16 ` [PULL 11/24] vhost: add vhost_svq_push_elem Jason Wang
2022-07-19 13:16 ` [PULL 12/24] vhost: Expose vhost_svq_add Jason Wang
2022-07-19 13:16 ` [PULL 13/24] vhost: add vhost_svq_poll Jason Wang
2022-07-19 13:16 ` [PULL 14/24] vhost: Add svq avail_handler callback Jason Wang
2022-07-19 13:16 ` [PULL 15/24] vdpa: Export vhost_vdpa_dma_map and unmap calls Jason Wang
2022-07-19 13:16 ` [PULL 16/24] vdpa: manual forward CVQ buffers Jason Wang
2022-07-19 13:16 ` [PULL 17/24] vdpa: Buffer CVQ support on shadow virtqueue Jason Wang
2022-07-19 13:16 ` [PULL 18/24] vdpa: Extract get features part from vhost_vdpa_get_max_queue_pairs Jason Wang
2022-07-19 13:16 ` [PULL 19/24] vdpa: Add device migration blocker Jason Wang
2022-07-19 13:16 ` [PULL 20/24] vdpa: Add x-svq to NetdevVhostVDPAOptions Jason Wang
2022-07-19 13:16 ` [PULL 21/24] softmmu/runstate.c: add RunStateTransition support form COLO to PRELAUNCH Jason Wang
2022-07-19 13:16 ` [PULL 22/24] net/colo: Fix a "double free" crash to clear the conn_list Jason Wang
2022-07-19 13:16 ` [PULL 23/24] net/colo.c: No need to track conn_list for filter-rewriter Jason Wang
2022-07-19 13:16 ` [PULL 24/24] net/colo.c: fix segmentation fault when packet is not parsed correctly Jason Wang
2022-07-19 16:40 ` [PULL 00/24] Net Patches Peter Maydell
2022-07-20  3:40   ` Jason Wang
2022-07-20  6:02     ` Eugenio Perez Martin
2022-07-20  6:06       ` Jason Wang

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=20220719131637.46131-2-jasowang@redhat.com \
    --to=jasowang@redhat.com \
    --cc=eperezma@redhat.com \
    --cc=mst@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).