diff mbox series

[RFC,for,8.0,02/13] vhost: iterate only available descriptors at SVQ stop

Message ID 20221205170436.2977336-3-eperezma@redhat.com (mailing list archive)
State New, archived
Headers show
Series vDPA-net inflight descriptors migration with SVQ | expand

Commit Message

Eugenio Perez Martin Dec. 5, 2022, 5:04 p.m. UTC
While we're at it, simplify the free path making just transverse the
list instead of all of them.

Signed-off-by: Eugenio PĂ©rez <eperezma@redhat.com>
---
 hw/virtio/vhost-shadow-virtqueue.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-virtqueue.c
index 0da72cb0ec..1bda8ca4bf 100644
--- a/hw/virtio/vhost-shadow-virtqueue.c
+++ b/hw/virtio/vhost-shadow-virtqueue.c
@@ -692,12 +692,13 @@  void vhost_svq_stop(VhostShadowVirtqueue *svq)
     /* Send all pending used descriptors to guest */
     vhost_svq_flush(svq, false);
 
-    for (unsigned i = 0; i < svq->vring.num; ++i) {
+    while (!QTAILQ_EMPTY(&svq->desc_state_avail)) {
+        SVQDescState *s = QTAILQ_FIRST(&svq->desc_state_avail);
         g_autofree VirtQueueElement *elem = NULL;
-        elem = g_steal_pointer(&svq->desc_state[i].elem);
-        if (elem) {
-            virtqueue_detach_element(svq->vq, elem, 0);
-        }
+
+        elem = g_steal_pointer(&s->elem);
+        virtqueue_detach_element(svq->vq, elem, 0);
+        QTAILQ_REMOVE(&svq->desc_state_avail, s, entry);
     }
 
     next_avail_elem = g_steal_pointer(&svq->next_guest_avail_elem);