virtio-net: Flush incoming queues when DRIVER_OK is being set
commit38705bb57bf1cd9e3f837cf11bcdee3876786c07
authorFam Zheng <famz@redhat.com>
Wed, 15 Jul 2015 03:02:27 +0000 (15 11:02 +0800)
committerMichael S. Tsirkin <mst@redhat.com>
Mon, 20 Jul 2015 11:19:41 +0000 (20 14:19 +0300)
treebf504042a8c1fae2bccae82bf0e8bdbe2dfb06a4
parent9a2a66238e3bf2b681d6321c4667a2d589c8ebed
virtio-net: Flush incoming queues when DRIVER_OK is being set

This patch fixes network hang after "stop" then "cont", while network
packets keep arriving.

Tested both manually (tap, host pinging guest) and with Jason's qtest
series (plus his "[PATCH 2.4] socket: pass correct size in
net_socket_send()" fix).

As virtio_net_set_status is called when guest driver is setting status
byte and when vm state is changing, it is a good opportunity to flush
queued packets.

This is necessary because during vm stop the backend (e.g. tap) would
stop rx processing after .can_receive returns false, until the queue is
explicitly flushed or purged.

The other interesting condition in .can_receive, virtio_queue_ready(),
is handled by virtio_net_handle_rx() when guest kicks; the 3rd condition
is invalid queue index which doesn't need flushing.

Signed-off-by: Fam Zheng <famz@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
hw/net/virtio-net.c