kvm: Fix virtqueue ring index check

This patch fixes the virtqueu ring index check that was totally wrong. The
->last_avail_idx is the index we've last seen but it doesn't need to match with
avail->idx.

Signed-off-by: Pekka Enberg <penberg@kernel.org>
This commit is contained in:
Pekka Enberg
2015-06-01 16:39:41 +01:00
committed by Will Deacon
parent 6160ab9d82
commit 93d18b7223
+10 -8
View File
@@ -18,9 +18,9 @@
struct virt_queue {
struct vring vring;
uint32_t pfn;
/* The next_avail_ndx field is an index to ->ring of struct vring_avail.
/* The last_avail_idx field is an index to ->ring of struct vring_avail.
It's where we assume the next request index is at. */
uint16_t next_avail_ndx;
uint16_t last_avail_idx;
};
struct device {
@@ -152,13 +152,15 @@ static bool blk_virtio_out(struct kvm *self, uint16_t port, void *data, int size
queue = &device.virt_queues[queue_index];
desc_ndx = queue->vring.avail->ring[queue->next_avail_ndx++ % queue->vring.num];
if (queue->vring.avail->idx == queue->last_avail_idx) {
warning("vring is empty");
break;
}
if (queue->vring.avail->idx != queue->next_avail_ndx) {
/*
* The hypervisor and the guest disagree on next index.
*/
warning("I/O error");
desc_ndx = queue->vring.avail->ring[queue->last_avail_idx++ % queue->vring.num];
if (desc_ndx >= queue->vring.num) {
warning("fatal I/O error");
break;
}