diff mbox

[v2,6/9] virtio-net: handle virtio_net_receive() errors

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

Commit Message

Greg Kurz Sept. 21, 2016, 4:57 p.m. UTC
All these errors are caused by a buggy guest: let's switch the device to
the broken state instead of terminating QEMU.

Signed-off-by: Greg Kurz <groug@kaod.org>
Reviewed-by: Cornelia Huck <cornelia.huck@de.ibm.com>
---
v2: - added Cornelia's R-b tag
---
 hw/net/virtio-net.c |   25 +++++++++++++------------
 1 file changed, 13 insertions(+), 12 deletions(-)

Comments

Stefan Hajnoczi Sept. 23, 2016, 1:11 p.m. UTC | #1
On Wed, Sep 21, 2016 at 06:57:37PM +0200, Greg Kurz wrote:
>          if (elem->in_num < 1) {
> -            error_report("virtio-net receive queue contains no in buffers");
> -            exit(1);
> +            virtio_error(vdev,
> +                         "virtio-net receive queue contains no in buffers");
> +            return -1;

Missing detach and free to avoid leaking elem.
diff mbox

Patch

diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
index 8a6f1d952467..b3e290c32cd0 100644
--- a/hw/net/virtio-net.c
+++ b/hw/net/virtio-net.c
@@ -1122,21 +1122,22 @@  static ssize_t virtio_net_receive(NetClientState *nc, const uint8_t *buf, size_t
 
         elem = virtqueue_pop(q->rx_vq, sizeof(VirtQueueElement));
         if (!elem) {
-            if (i == 0)
-                return -1;
-            error_report("virtio-net unexpected empty queue: "
-                         "i %zd mergeable %d offset %zd, size %zd, "
-                         "guest hdr len %zd, host hdr len %zd "
-                         "guest features 0x%" PRIx64,
-                         i, n->mergeable_rx_bufs, offset, size,
-                         n->guest_hdr_len, n->host_hdr_len,
-                         vdev->guest_features);
-            exit(1);
+            if (i) {
+                virtio_error(vdev, "virtio-net unexpected empty queue: "
+                             "i %zd mergeable %d offset %zd, size %zd, "
+                             "guest hdr len %zd, host hdr len %zd "
+                             "guest features 0x%" PRIx64,
+                             i, n->mergeable_rx_bufs, offset, size,
+                             n->guest_hdr_len, n->host_hdr_len,
+                             vdev->guest_features);
+            }
+            return -1;
         }
 
         if (elem->in_num < 1) {
-            error_report("virtio-net receive queue contains no in buffers");
-            exit(1);
+            virtio_error(vdev,
+                         "virtio-net receive queue contains no in buffers");
+            return -1;
         }
 
         sg = elem->in_sg;