summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTom Lendacky <tahm@linux.vnet.ibm.com>2010-02-08 10:10:01 -0600
committerAnthony Liguori <aliguori@us.ibm.com>2010-02-10 12:48:48 -0600
commit06b1297017415ae6a07a0e97ad7d8e90b2d95823 (patch)
tree7850b2ee2927dc4574ffcf142153566f7b77d070
parent2c0d4b36e7fe28c569c5436f7724735e35d3c493 (diff)
downloadhqemu-06b1297017415ae6a07a0e97ad7d8e90b2d95823.zip
hqemu-06b1297017415ae6a07a0e97ad7d8e90b2d95823.tar.gz
virtio-net: fix network stall under load
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>
-rw-r--r--hw/virtio-net.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/hw/virtio-net.c b/hw/virtio-net.c
index 6e48997..5c0093e 100644
--- a/hw/virtio-net.c
+++ b/hw/virtio-net.c
@@ -379,7 +379,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);
OpenPOWER on IntegriCloud