Skip to content

Commit

Permalink
hw/virtio/vring/event_idx: fix the vring_avail_event error
Browse files Browse the repository at this point in the history
The event idx in virtio is an effective way to reduce the number of
interrupts and exits of the guest. When the guest puts an request
into the virtio ring, it doesn't exit immediately to inform the
backend. Instead, the guest checks the "avail" event idx to determine
the notification.

In virtqueue_pop, when a request is poped, the current avail event
idx should be set to the number of vq->last_avail_idx.

Signed-off-by: Bin Wu <wu.wubin@huawei.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
  • Loading branch information
Bin Wu authored and mstsirkin committed Nov 2, 2014
1 parent db80c7b commit a3614c6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions hw/virtio/dataplane/vring.c
Expand Up @@ -352,10 +352,6 @@ int vring_pop(VirtIODevice *vdev, Vring *vring,
goto out;
}

if (vdev->guest_features & (1 << VIRTIO_RING_F_EVENT_IDX)) {
vring_avail_event(&vring->vr) = vring->vr.avail->idx;
}

i = head;
do {
if (unlikely(i >= num)) {
Expand Down Expand Up @@ -392,6 +388,10 @@ int vring_pop(VirtIODevice *vdev, Vring *vring,

/* On success, increment avail index. */
vring->last_avail_idx++;
if (vdev->guest_features & (1 << VIRTIO_RING_F_EVENT_IDX)) {
vring_avail_event(&vring->vr) = vring->last_avail_idx;
}

return head;

out:
Expand Down
2 changes: 1 addition & 1 deletion hw/virtio/virtio.c
Expand Up @@ -469,7 +469,7 @@ int virtqueue_pop(VirtQueue *vq, VirtQueueElement *elem)

i = head = virtqueue_get_head(vq, vq->last_avail_idx++);
if (vdev->guest_features & (1 << VIRTIO_RING_F_EVENT_IDX)) {
vring_avail_event(vq, vring_avail_idx(vq));
vring_avail_event(vq, vq->last_avail_idx);
}

if (vring_desc_flags(vdev, desc_pa, i) & VRING_DESC_F_INDIRECT) {
Expand Down

0 comments on commit a3614c6

Please sign in to comment.