summaryrefslogtreecommitdiffstats
path: root/hw/net/virtio-net.c
diff options
context:
space:
mode:
authorMichael S. Tsirkin2014-09-04 10:39:17 +0200
committerStefan Hajnoczi2014-09-04 18:19:09 +0200
commit086abc1ccd0fa5103345adda819e6c6436949579 (patch)
tree3c64bcbc490597390f0b9213c564f24ed7ecf09d /hw/net/virtio-net.c
parentnet: complete all queued packets on VM stop (diff)
downloadqemu-086abc1ccd0fa5103345adda819e6c6436949579.tar.gz
qemu-086abc1ccd0fa5103345adda819e6c6436949579.tar.xz
qemu-086abc1ccd0fa5103345adda819e6c6436949579.zip
virtio-net: purge outstanding packets when starting vhost
whenever we start vhost, virtio could have outstanding packets queued, when they complete later we'll modify the ring while vhost is processing it. To prevent this, purge outstanding packets on vhost start. Cc: qemu-stable@nongnu.org Cc: Jason Wang <jasowang@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Diffstat (limited to 'hw/net/virtio-net.c')
-rw-r--r--hw/net/virtio-net.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
index 365e266b74..826a2a5fca 100644
--- a/hw/net/virtio-net.c
+++ b/hw/net/virtio-net.c
@@ -125,10 +125,23 @@ static void virtio_net_vhost_status(VirtIONet *n, uint8_t status)
return;
}
if (!n->vhost_started) {
- int r;
+ int r, i;
+
if (!vhost_net_query(get_vhost_net(nc->peer), vdev)) {
return;
}
+
+ /* Any packets outstanding? Purge them to avoid touching rings
+ * when vhost is running.
+ */
+ for (i = 0; i < queues; i++) {
+ NetClientState *qnc = qemu_get_subqueue(n->nic, i);
+
+ /* Purge both directions: TX and RX. */
+ qemu_net_queue_purge(qnc->peer->incoming_queue, qnc);
+ qemu_net_queue_purge(qnc->incoming_queue, qnc->peer);
+ }
+
n->vhost_started = 1;
r = vhost_net_start(vdev, n->nic->ncs, queues);
if (r < 0) {