vhost: fix stored last used index
authorBalazs Nemeth <bnemeth@redhat.com>
Fri, 14 May 2021 16:02:07 +0000 (18:02 +0200)
committerChenbo Xia <chenbo.xia@intel.com>
Tue, 18 May 2021 07:43:35 +0000 (09:43 +0200)
The optimization introduced by
commit d18db8049c7c ("vhost: read last used index once")
didn't account for the fact that vhost_flush_enqueue_shadow_packed
increments the last_used_idx.
For this reason, store last_used_idx after the potential call to
vhost_flush_enqueue_shadow_packed.

Bugzilla ID: 699
Fixes: d18db8049c7c ("vhost: read last used index once")

Signed-off-by: Balazs Nemeth <bnemeth@redhat.com>
Reviewed-by: David Marchand <david.marchand@redhat.com>
Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>
Tested-by: Wei Ling <weix.ling@intel.com>
lib/vhost/virtio_net.c

index abfd67d..8da8a86 100644 (file)
@@ -218,14 +218,17 @@ vhost_flush_enqueue_batch_packed(struct virtio_net *dev,
 {
        uint16_t i;
        uint16_t flags;
-       uint16_t last_used_idx = vq->last_used_idx;
-       struct vring_packed_desc *desc_base = &vq->desc_packed[last_used_idx];
+       uint16_t last_used_idx;
+       struct vring_packed_desc *desc_base;
 
        if (vq->shadow_used_idx) {
                do_data_copy_enqueue(dev, vq);
                vhost_flush_enqueue_shadow_packed(dev, vq);
        }
 
+       last_used_idx = vq->last_used_idx;
+       desc_base = &vq->desc_packed[last_used_idx];
+
        flags = PACKED_DESC_ENQUEUE_USED_FLAG(vq->used_wrap_counter);
 
        vhost_for_each_try_unroll(i, 0, PACKED_BATCH_SIZE) {