[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v3 09/10] virtio: handle virtqueue_num_heads() error
From: |
Stefan Hajnoczi |
Subject: |
[Qemu-devel] [PATCH v3 09/10] virtio: handle virtqueue_num_heads() errors |
Date: |
Tue, 12 Apr 2016 14:25:33 +0100 |
If the avail ring index is bogus virtqueue_num_heads() must return
-EINVAL.
The only caller is virtqueue_get_avail_bytes(). Return saying no bytes
are available when virtqueue_num_heads() fails.
Signed-off-by: Stefan Hajnoczi <address@hidden>
---
hw/virtio/virtio.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
index 58599cf..4fe342a 100644
--- a/hw/virtio/virtio.c
+++ b/hw/virtio/virtio.c
@@ -323,9 +323,9 @@ static int virtqueue_num_heads(VirtQueue *vq, unsigned int
idx)
/* Check it isn't doing very strange things with descriptor numbers. */
if (num_heads > vq->vring.num) {
- error_report("Guest moved used index from %u to %u",
+ virtio_error(vq->vdev, "Guest moved used index from %u to %u",
idx, vq->shadow_avail_idx);
- exit(1);
+ return -EINVAL;
}
/* On success, callers read a descriptor at vq->last_avail_idx.
* Make sure descriptor read does not bypass avail index read. */
@@ -393,7 +393,7 @@ void virtqueue_get_avail_bytes(VirtQueue *vq, unsigned int
*in_bytes,
idx = vq->last_avail_idx;
total_bufs = in_total = out_total = 0;
- while (virtqueue_num_heads(vq, idx)) {
+ while ((rc = virtqueue_num_heads(vq, idx)) > 0) {
VirtIODevice *vdev = vq->vdev;
unsigned int max, num_bufs, indirect = 0;
VRingDesc desc;
@@ -454,6 +454,11 @@ void virtqueue_get_avail_bytes(VirtQueue *vq, unsigned int
*in_bytes,
else
total_bufs++;
}
+
+ if (rc < 0) {
+ goto err;
+ }
+
done:
if (in_bytes) {
*in_bytes = in_total;
--
2.5.5
- [Qemu-devel] [PATCH v3 00/10] virtio: avoid exit() when device enters invalid states, Stefan Hajnoczi, 2016/04/12
- [Qemu-devel] [PATCH v3 01/10] virtio: fix stray tab character, Stefan Hajnoczi, 2016/04/12
- [Qemu-devel] [PATCH v3 02/10] include: update virtio_config.h Linux header, Stefan Hajnoczi, 2016/04/12
- [Qemu-devel] [PATCH v3 03/10] virtio: stop virtqueue processing if device is broken, Stefan Hajnoczi, 2016/04/12
- [Qemu-devel] [PATCH v3 04/10] virtio: migrate vdev->broken flag, Stefan Hajnoczi, 2016/04/12
- [Qemu-devel] [PATCH v3 05/10] virtio: handle virtqueue_map_desc() errors, Stefan Hajnoczi, 2016/04/12
- [Qemu-devel] [PATCH v3 06/10] virtio: handle virtqueue_get_avail_bytes() errors, Stefan Hajnoczi, 2016/04/12
- [Qemu-devel] [PATCH v3 07/10] virtio: use unsigned int for virtqueue_get_avail_bytes() index, Stefan Hajnoczi, 2016/04/12
- [Qemu-devel] [PATCH v3 08/10] virtio: handle virtqueue_read_next_desc() errors, Stefan Hajnoczi, 2016/04/12
- [Qemu-devel] [PATCH v3 09/10] virtio: handle virtqueue_num_heads() errors,
Stefan Hajnoczi <=
- [Qemu-devel] [PATCH v3 10/10] virtio: handle virtqueue_get_head() errors, Stefan Hajnoczi, 2016/04/12