All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Eugenio Pérez" <eperezma@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Laurent Vivier" <lvivier@redhat.com>,
	"Jason Wang" <jasowang@redhat.com>,
	"Dragos Tatulea DE" <dtatulea@nvidia.com>,
	"Jonah Palmer" <jonah.palmer@oracle.com>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	"Eugenio Pérez" <eperezma@redhat.com>,
	"Lei Yang" <leiyang@redhat.com>,
	"Koushik Dutta" <kdutta@redhat.com>,
	"Stefano Garzarella" <sgarzare@redhat.com>,
	qemu-stable@nongnu.org, "Cindy Lu" <lulu@redhat.com>,
	"Maxime Coquelin" <mcoqueli@redhat.com>
Subject: [PATCH 3/7] vhost: factor out the descriptor next fetching
Date: Wed,  4 Mar 2026 18:35:31 +0100	[thread overview]
Message-ID: <20260304173535.2702587-4-eperezma@redhat.com> (raw)
In-Reply-To: <20260304173535.2702587-1-eperezma@redhat.com>

The next field will not be used if IN_ORDER is enabled.

Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
---
 hw/virtio/vhost-shadow-virtqueue.c | 24 ++++++++++++++++++++----
 1 file changed, 20 insertions(+), 4 deletions(-)

diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-virtqueue.c
index 901253d06e50..7adacd4f542a 100644
--- a/hw/virtio/vhost-shadow-virtqueue.c
+++ b/hw/virtio/vhost-shadow-virtqueue.c
@@ -139,6 +139,20 @@ static bool vhost_svq_translate_addr(const VhostShadowVirtqueue *svq,
     return true;
 }
 
+/**
+ * Get the next descriptor in the chain in SVQ vring from a descriptor id
+ *
+ * @svq Shadow Virtqueue
+ * @id ID of the descriptor
+ *
+ * Return the id of the next descriptor.
+ */
+static uint16_t vhost_svq_next_desc(const VhostShadowVirtqueue *svq,
+                                    uint16_t id)
+{
+    return svq->desc_state[id].next;
+}
+
 /**
  * Write descriptors to SVQ vring
  *
@@ -173,9 +187,11 @@ static bool vhost_svq_vring_write_descs(VhostShadowVirtqueue *svq, hwaddr *sg,
     }
 
     for (n = 0; n < num; n++) {
+        uint16_t next = vhost_svq_next_desc(svq, i);
+
         if (more_descs || (n + 1 < num)) {
             descs[i].flags = flags | cpu_to_le16(VRING_DESC_F_NEXT);
-            descs[i].next = cpu_to_le16(svq->desc_state[i].next);
+            descs[i].next = cpu_to_le16(next);
         } else {
             descs[i].flags = flags;
         }
@@ -183,10 +199,10 @@ static bool vhost_svq_vring_write_descs(VhostShadowVirtqueue *svq, hwaddr *sg,
         descs[i].len = cpu_to_le32(iovec[n].iov_len);
 
         last = i;
-        i = svq->desc_state[i].next;
+        i = next;
     }
 
-    svq->free_head = svq->desc_state[last].next;
+    svq->free_head = vhost_svq_next_desc(svq, last);
     return true;
 }
 
@@ -432,7 +448,7 @@ static uint16_t vhost_svq_last_desc_of_chain(const VhostShadowVirtqueue *svq,
                                              uint16_t num, uint16_t i)
 {
     for (uint16_t j = 0; j < (num - 1); ++j) {
-        i = svq->desc_state[i].next;
+        i = vhost_svq_next_desc(svq, i);
     }
 
     return i;
-- 
2.53.0



  parent reply	other threads:[~2026-03-04 17:38 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-04 17:35 [PATCH 0/7] Add VIRTIO_F_IN_ORDER support to vhost shadow virtqueue Eugenio Pérez
2026-03-04 17:35 ` [PATCH 1/7] virtio: Allow to fill a whole virtqueue in order Eugenio Pérez
2026-03-06  3:26   ` Jason Wang
2026-03-06  6:22     ` Eugenio Perez Martin
2026-03-09  3:16       ` Jason Wang
2026-03-09  6:19         ` Eugenio Perez Martin
2026-03-10  3:09           ` Jason Wang
2026-03-10  6:21             ` Eugenio Perez Martin
2026-03-11 14:42               ` Jonah Palmer
2026-03-04 17:35 ` [PATCH 2/7] vhost: move svq next desc array to descs state struct Eugenio Pérez
2026-03-09  8:57   ` Jason Wang
2026-03-04 17:35 ` Eugenio Pérez [this message]
2026-03-09  8:57   ` [PATCH 3/7] vhost: factor out the descriptor next fetching Jason Wang
2026-03-04 17:35 ` [PATCH 4/7] vhost: factor out the get of last used desc in SVQ Eugenio Pérez
     [not found]   ` <CACGkMEukuUcCuTUpYEG5bdWD9dnJDWh2w50vsdhEbF2E=rNsvA@mail.gmail.com>
     [not found]     ` <CAJaqyWcTav8BWcRio+w4LYsTtAJSvJBJdeLoTdDBYAmh_2jjLg@mail.gmail.com>
2026-03-10  3:07       ` Jason Wang
2026-03-04 17:35 ` [PATCH 5/7] vhost: factor out the detach buf logic " Eugenio Pérez
2026-03-09  8:57   ` Jason Wang
2026-03-09  9:43     ` Eugenio Perez Martin
2026-03-10  3:04       ` Jason Wang
2026-03-10  6:36         ` Eugenio Perez Martin
2026-03-04 17:35 ` [PATCH 6/7] vhost: add in_order feature to shadow virtqueue Eugenio Pérez
2026-03-09  8:57   ` Jason Wang
2026-03-04 17:35 ` [PATCH 7/7] vhost: accept in order feature flag Eugenio Pérez
2026-03-09  8:57   ` Jason Wang
2026-03-11 11:50 ` [PATCH 0/7] Add VIRTIO_F_IN_ORDER support to vhost shadow virtqueue Michael Tokarev
2026-03-11 12:24   ` Eugenio Perez Martin
2026-03-11 13:49     ` Michael Tokarev
2026-05-13  6:45 ` Michael Tokarev

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=20260304173535.2702587-4-eperezma@redhat.com \
    --to=eperezma@redhat.com \
    --cc=dtatulea@nvidia.com \
    --cc=jasowang@redhat.com \
    --cc=jonah.palmer@oracle.com \
    --cc=kdutta@redhat.com \
    --cc=leiyang@redhat.com \
    --cc=lulu@redhat.com \
    --cc=lvivier@redhat.com \
    --cc=mcoqueli@redhat.com \
    --cc=mst@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-stable@nongnu.org \
    --cc=sgarzare@redhat.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.