@samitouri / QOSamiQemu / commits / 00373aa05e

vhost: factor out the descriptor next fetching

The next field will not be used if IN_ORDER is enabled. Signed-off-by: Eugenio Pérez <eperezma@redhat.com> Acked-by: Jason Wang <jasowang@redhat.com> Reviewed-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Message-Id: <20260304173535.2702587-4-eperezma@redhat.com>

Eugenio Pérez committed Mar 4, 2026 at 18:35 UTC 00373aa05e683e4d4f72f534a8b9179cd4065149
1 file changed +20 -4
hw/virtio/vhost-shadow-virtqueue.c
+20 -4
@@ -139,6 +139,20 @@ static bool vhost_svq_translate_addr(const VhostShadowVirtqueue *svq,
139 return true;
140 }
141
142 +/**
143 + * Get the next descriptor in the chain in SVQ vring from a descriptor id
144 + *
145 + * @svq Shadow Virtqueue
146 + * @id ID of the descriptor
147 + *
148 + * Return the id of the next descriptor.
149 + */
150 +static uint16_t vhost_svq_next_desc(const VhostShadowVirtqueue *svq,
151 + uint16_t id)
152 +{
153 + return svq->desc_state[id].next;
154 +}
155 +
156 /**
157 * Write descriptors to SVQ vring
158 *
@@ -173,9 +187,11 @@ static bool vhost_svq_vring_write_descs(VhostShadowVirtqueue *svq, hwaddr *sg,
187 }
188
189 for (n = 0; n < num; n++) {
190 + uint16_t next = vhost_svq_next_desc(svq, i);
191 +
192 if (more_descs || (n + 1 < num)) {
193 descs[i].flags = flags | cpu_to_le16(VRING_DESC_F_NEXT);
178 - descs[i].next = cpu_to_le16(svq->desc_state[i].next);
194 + descs[i].next = cpu_to_le16(next);
195 } else {
196 descs[i].flags = flags;
197 }
@@ -183,10 +199,10 @@ static bool vhost_svq_vring_write_descs(VhostShadowVirtqueue *svq, hwaddr *sg,
199 descs[i].len = cpu_to_le32(iovec[n].iov_len);
200
201 last = i;
186 - i = svq->desc_state[i].next;
202 + i = next;
203 }
204
189 - svq->free_head = svq->desc_state[last].next;
205 + svq->free_head = vhost_svq_next_desc(svq, last);
206 return true;
207 }
208
@@ -432,7 +448,7 @@ static uint16_t vhost_svq_last_desc_of_chain(const VhostShadowVirtqueue *svq,
448 uint16_t num, uint16_t i)
449 {
450 for (uint16_t j = 0; j < (num - 1); ++j) {
435 - i = svq->desc_state[i].next;
451 + i = vhost_svq_next_desc(svq, i);
452 }
453
454 return i;