diff mbox

[v3,5/9] virtio-net: handle virtio_net_handle_ctrl() error

Message ID 147487887245.6679.16815990471966664075.stgit@bahia (mailing list archive)
State New, archived
Headers show

Commit Message

Greg Kurz Sept. 26, 2016, 8:34 a.m. UTC
This error is 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.

Signed-off-by: Greg Kurz <groug@kaod.org>
---
v3: - detach and free element
    - updated changelog
---
 hw/net/virtio-net.c |    7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

Comments

Stefan Hajnoczi Sept. 26, 2016, 4:25 p.m. UTC | #1
On Mon, Sep 26, 2016 at 10:34:32AM +0200, Greg Kurz wrote:
> This error is 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.
> 
> Signed-off-by: Greg Kurz <groug@kaod.org>
> ---
> v3: - detach and free element
>     - updated changelog
> ---
>  hw/net/virtio-net.c |    7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)

Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
diff mbox

Patch

diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
index 01f1351554aa..2c02ba8a70a4 100644
--- a/hw/net/virtio-net.c
+++ b/hw/net/virtio-net.c
@@ -875,6 +875,7 @@  static int virtio_net_handle_mq(VirtIONet *n, uint8_t cmd,
 
     return VIRTIO_NET_OK;
 }
+
 static void virtio_net_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq)
 {
     VirtIONet *n = VIRTIO_NET(vdev);
@@ -892,8 +893,10 @@  static void virtio_net_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq)
         }
         if (iov_size(elem->in_sg, elem->in_num) < sizeof(status) ||
             iov_size(elem->out_sg, elem->out_num) < sizeof(ctrl)) {
-            error_report("virtio-net ctrl missing headers");
-            exit(1);
+            virtio_error(vdev, "virtio-net ctrl missing headers");
+            virtqueue_detach_element(vq, elem, 0);
+            g_free(elem);
+            break;
         }
 
         iov_cnt = elem->out_num;