vhost: use last available index for ring reservation
authorYuanhan Liu <yuanhan.liu@linux.intel.com>
Fri, 14 Oct 2016 09:34:35 +0000 (17:34 +0800)
committerYuanhan Liu <yuanhan.liu@linux.intel.com>
Wed, 26 Oct 2016 11:39:09 +0000 (13:39 +0200)
shadow_used_ring will be introduced later. Since then last avail
idx will not be updated together with last used idx.

So, here we use last_avail_idx for avail ring reservation.

Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
Signed-off-by: Zhihong Wang <zhihong.wang@intel.com>
Reviewed-by: Jianbo Liu <jianbo.liu@linaro.org>
Tested-by: Maxime Coquelin <maxime.coquelin@redhat.com>
lib/librte_vhost/virtio_net.c

index e449388..b41312b 100644 (file)
@@ -344,7 +344,7 @@ reserve_avail_buf_mergeable(struct vhost_virtqueue *vq, uint32_t size,
        uint32_t vec_idx = 0;
        uint16_t tries = 0;
 
-       cur_idx  = vq->last_used_idx;
+       cur_idx = vq->last_avail_idx;
 
        while (1) {
                avail_idx = *((volatile uint16_t *)&vq->avail->idx);
@@ -370,7 +370,7 @@ reserve_avail_buf_mergeable(struct vhost_virtqueue *vq, uint32_t size,
                        return -1;
        }
 
-       *num_buffers = cur_idx - vq->last_used_idx;
+       *num_buffers = cur_idx - vq->last_avail_idx;
        return 0;
 }
 
@@ -536,6 +536,7 @@ virtio_dev_merge_rx(struct virtio_net *dev, uint16_t queue_id,
                vhost_log_used_vring(dev, vq, offsetof(struct vring_used, idx),
                        sizeof(vq->used->idx));
                vq->last_used_idx += num_buffers;
+               vq->last_avail_idx += num_buffers;
        }
 
        if (likely(pkt_idx)) {