diff mbox series

[RFC,for,8.0,03/13] vhost: merge avail list and next avail descriptors detach

Message ID 20221205170436.2977336-4-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
We need to perform the same actions for the two.

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

Patch

diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-virtqueue.c
index 1bda8ca4bf..e50bfba6dc 100644
--- a/hw/virtio/vhost-shadow-virtqueue.c
+++ b/hw/virtio/vhost-shadow-virtqueue.c
@@ -692,18 +692,18 @@  void vhost_svq_stop(VhostShadowVirtqueue *svq)
     /* Send all pending used descriptors to guest */
     vhost_svq_flush(svq, false);
 
-    while (!QTAILQ_EMPTY(&svq->desc_state_avail)) {
+    while (!QTAILQ_EMPTY(&svq->desc_state_avail)
+           || svq->next_guest_avail_elem) {
         SVQDescState *s = QTAILQ_FIRST(&svq->desc_state_avail);
         g_autofree VirtQueueElement *elem = NULL;
 
-        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);
-    if (next_avail_elem) {
-        virtqueue_detach_element(svq->vq, next_avail_elem, 0);
+        elem = g_steal_pointer(s ? &s->elem : &svq->next_guest_avail_elem);
+        if (elem) {
+            virtqueue_detach_element(svq->vq, elem, 0);
+        }
+        if (s) {
+            QTAILQ_REMOVE(&svq->desc_state_avail, s, entry);
+        }
     }
     svq->vq = NULL;
     g_free(svq->desc_next);