]> git.ipfire.org Git - thirdparty/qemu.git/commitdiff
virtio-net: fix network stall under load
authorTom Lendacky <tahm@linux.vnet.ibm.com>
Mon, 8 Feb 2010 16:10:01 +0000 (10:10 -0600)
committerAnthony Liguori <aliguori@us.ibm.com>
Tue, 23 Feb 2010 20:07:58 +0000 (14:07 -0600)
Fix a race condition where qemu finds that there are not enough virtio
ring buffers available and the guest make more buffers available before
qemu can enable notifications.

Signed-off-by: Tom Lendacky <toml@us.ibm.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
(cherry picked from commit 06b1297017415ae6a07a0e97ad7d8e90b2d95823)

hw/virtio-net.c

index 2f201ffc76149737b7c0eb70860cc319baa18f5f..d8a1629dc33b909fc4836b66387236b63e3d4a7d 100644 (file)
@@ -384,7 +384,15 @@ static int virtio_net_has_buffers(VirtIONet *n, int bufsize)
         (n->mergeable_rx_bufs &&
          !virtqueue_avail_bytes(n->rx_vq, bufsize, 0))) {
         virtio_queue_set_notification(n->rx_vq, 1);
-        return 0;
+
+        /* To avoid a race condition where the guest has made some buffers
+         * available after the above check but before notification was
+         * enabled, check for available buffers again.
+         */
+        if (virtio_queue_empty(n->rx_vq) ||
+            (n->mergeable_rx_bufs &&
+             !virtqueue_avail_bytes(n->rx_vq, bufsize, 0)))
+            return 0;
     }
 
     virtio_queue_set_notification(n->rx_vq, 0);