[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 17/33] virtio-net: handle virtio_net_flush_tx() error
From: |
Michael S. Tsirkin |
Subject: |
[Qemu-devel] [PULL 17/33] virtio-net: handle virtio_net_flush_tx() errors |
Date: |
Mon, 10 Oct 2016 05:57:57 +0300 |
From: Greg Kurz <address@hidden>
All these errors are caused by a buggy guest: let's switch the device to
the broken state instead of terminating QEMU. Also we detach the element
from the virtqueue and free it.
If this happens, virtio_net_flush_tx() also returns -EINVAL, so that all
callers can stop processing the virtqueue immediatly.
Signed-off-by: Greg Kurz <address@hidden>
Reviewed-by: Stefan Hajnoczi <address@hidden>
Reviewed-by: Michael S. Tsirkin <address@hidden>
Signed-off-by: Michael S. Tsirkin <address@hidden>
---
hw/net/virtio-net.c | 26 ++++++++++++++++++--------
1 file changed, 18 insertions(+), 8 deletions(-)
diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
index 5c0b2e0..ca1b469 100644
--- a/hw/net/virtio-net.c
+++ b/hw/net/virtio-net.c
@@ -1249,15 +1249,19 @@ static int32_t virtio_net_flush_tx(VirtIONetQueue *q)
out_num = elem->out_num;
out_sg = elem->out_sg;
if (out_num < 1) {
- error_report("virtio-net header not in first element");
- exit(1);
+ virtio_error(vdev, "virtio-net header not in first element");
+ virtqueue_detach_element(q->tx_vq, elem, 0);
+ g_free(elem);
+ return -EINVAL;
}
if (n->has_vnet_hdr) {
if (iov_to_buf(out_sg, out_num, 0, &mhdr, n->guest_hdr_len) <
n->guest_hdr_len) {
- error_report("virtio-net header incorrect");
- exit(1);
+ virtio_error(vdev, "virtio-net header incorrect");
+ virtqueue_detach_element(q->tx_vq, elem, 0);
+ g_free(elem);
+ return -EINVAL;
}
if (n->needs_vnet_hdr_swap) {
virtio_net_hdr_swap(vdev, (void *) &mhdr);
@@ -1325,7 +1329,9 @@ static void virtio_net_handle_tx_timer(VirtIODevice
*vdev, VirtQueue *vq)
virtio_queue_set_notification(vq, 1);
timer_del(q->tx_timer);
q->tx_waiting = 0;
- virtio_net_flush_tx(q);
+ if (virtio_net_flush_tx(q) == -EINVAL) {
+ return;
+ }
} else {
timer_mod(q->tx_timer,
qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + n->tx_timeout);
@@ -1396,8 +1402,9 @@ static void virtio_net_tx_bh(void *opaque)
}
ret = virtio_net_flush_tx(q);
- if (ret == -EBUSY) {
- return; /* Notification re-enable handled by tx_complete */
+ if (ret == -EBUSY || ret == -EINVAL) {
+ return; /* Notification re-enable handled by tx_complete or device
+ * broken */
}
/* If we flush a full burst of packets, assume there are
@@ -1412,7 +1419,10 @@ static void virtio_net_tx_bh(void *opaque)
* anything that may have come in while we weren't looking. If
* we find something, assume the guest is still active and reschedule */
virtio_queue_set_notification(q->tx_vq, 1);
- if (virtio_net_flush_tx(q) > 0) {
+ ret = virtio_net_flush_tx(q);
+ if (ret == -EINVAL) {
+ return;
+ } else if (ret > 0) {
virtio_queue_set_notification(q->tx_vq, 0);
qemu_bh_schedule(q->tx_bh);
q->tx_waiting = 1;
--
MST
- [Qemu-devel] [PULL 00/33] virtio, pc: fixes and features, Michael S. Tsirkin, 2016/10/09
- [Qemu-devel] [PULL 02/33] virtio-serial: add plumbing for virtio console emergency write support, Michael S. Tsirkin, 2016/10/09
- [Qemu-devel] [PULL 01/33] virtio-balloon: Remove needless precompiled directive, Michael S. Tsirkin, 2016/10/09
- [Qemu-devel] [PULL 03/33] virtio-serial: enable virtio console emergency write feature, Michael S. Tsirkin, 2016/10/09
- [Qemu-devel] [PULL 06/33] tests: acpi: extend cphp testcase with numa check, Michael S. Tsirkin, 2016/10/09
- [Qemu-devel] [PULL 08/33] virtio: add virtio_detach_element(), Michael S. Tsirkin, 2016/10/09
- [Qemu-devel] [PULL 07/33] tests: acpi tables expected blobs update, Michael S. Tsirkin, 2016/10/09
- [Qemu-devel] [PULL 05/33] acpi: provide _PXM method for CPU devices if QEMU is started numa enabled, Michael S. Tsirkin, 2016/10/09
- [Qemu-devel] [PULL 09/33] virtio-blk: add missing virtio_detach_element() call, Michael S. Tsirkin, 2016/10/09
- [Qemu-devel] [PULL 04/33] numa: reduce code duplication by adding helper numa_get_node_for_cpu(), Michael S. Tsirkin, 2016/10/09
- [Qemu-devel] [PULL 17/33] virtio-net: handle virtio_net_flush_tx() errors,
Michael S. Tsirkin <=
- [Qemu-devel] [PULL 19/33] virtio-scsi: handle virtio_scsi_set_config() error, Michael S. Tsirkin, 2016/10/09
- [Qemu-devel] [PULL 13/33] virtio-9p: handle handle_9p_output() error, Michael S. Tsirkin, 2016/10/09
- [Qemu-devel] [PULL 18/33] virtio-scsi: convert virtio_scsi_bad_req() to use virtio_error(), Michael S. Tsirkin, 2016/10/09
- [Qemu-devel] [PULL 24/33] virtio-9p: convert VMSTATE_VIRTIO_DEVICE, Michael S. Tsirkin, 2016/10/09
- [Qemu-devel] [PULL 27/33] virtio-input: convert VMSTATE_VIRTIO_DEVICE, Michael S. Tsirkin, 2016/10/09
- [Qemu-devel] [PULL 16/33] virtio-net: handle virtio_net_receive() errors, Michael S. Tsirkin, 2016/10/09
- [Qemu-devel] [PULL 10/33] virtio-serial: add missing virtio_detach_element() call, Michael S. Tsirkin, 2016/10/09
- [Qemu-devel] [PULL 20/33] net: don't poke at chardev internal QemuOpts, Michael S. Tsirkin, 2016/10/09
- [Qemu-devel] [PULL 23/33] virtio-net: convert VMSTATE_VIRTIO_DEVICE, Michael S. Tsirkin, 2016/10/09
- [Qemu-devel] [PULL 15/33] virtio-net: handle virtio_net_handle_ctrl() error, Michael S. Tsirkin, 2016/10/09