Skip to content

Commit

Permalink
virtio-net: purge outstanding packets when starting vhost
Browse files Browse the repository at this point in the history
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: [email protected]
Cc: Jason Wang <[email protected]>
Signed-off-by: Michael S. Tsirkin <[email protected]>
Signed-off-by: Stefan Hajnoczi <[email protected]>
  • Loading branch information
mstsirkin authored and stefanhaRH committed Sep 4, 2014
1 parent ca77d85 commit 086abc1
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion hw/net/virtio-net.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 086abc1

Please sign in to comment.