From: "Michael S. Tsirkin" <mst@redhat.com>
To: qemu-devel@nongnu.org
Cc: Peter Maydell <peter.maydell@linaro.org>, Fam Zheng <famz@redhat.com>
Subject: [Qemu-devel] [PULL 5/6] virtio-net: Flush incoming queues when DRIVER_OK is being set
Date: Mon, 20 Jul 2015 15:12:23 +0300 [thread overview]
Message-ID: <1437394279-24416-6-git-send-email-mst@redhat.com> (raw)
In-Reply-To: <1437394279-24416-1-git-send-email-mst@redhat.com>
From: Fam Zheng <famz@redhat.com>
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 | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
index 9f7e91d..e1d9cbf 100644
--- a/hw/net/virtio-net.c
+++ b/hw/net/virtio-net.c
@@ -162,6 +162,8 @@ static void virtio_net_set_status(struct VirtIODevice *vdev, uint8_t status)
virtio_net_vhost_status(n, status);
for (i = 0; i < n->max_queues; i++) {
+ NetClientState *ncs = qemu_get_subqueue(n->nic, i);
+ bool queue_started;
q = &n->vqs[i];
if ((!n->multiqueue && i != 0) || i >= n->curr_queues) {
@@ -169,12 +171,18 @@ static void virtio_net_set_status(struct VirtIODevice *vdev, uint8_t status)
} else {
queue_status = status;
}
+ queue_started =
+ virtio_net_started(n, queue_status) && !n->vhost_started;
+
+ if (queue_started) {
+ qemu_flush_queued_packets(ncs);
+ }
if (!q->tx_waiting) {
continue;
}
- if (virtio_net_started(n, queue_status) && !n->vhost_started) {
+ if (queue_started) {
if (q->tx_timer) {
timer_mod(q->tx_timer,
qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + n->tx_timeout);
--
MST
next prev parent reply other threads:[~2015-07-20 12:22 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-07-20 12:12 [Qemu-devel] [PULL 0/6] virtio, vhost, pc fixes for 2.4 Michael S. Tsirkin
2015-07-20 12:12 ` [Qemu-devel] [PULL 1/6] ich9: fix skipped vmstate_memhp_state subsection Michael S. Tsirkin
2015-07-20 12:12 ` [Qemu-devel] [PULL 2/6] Revert "vhost-user: add multi queue support" Michael S. Tsirkin
2015-07-20 12:12 ` [Qemu-devel] [PULL 3/6] virtio-net: unbreak any layout Michael S. Tsirkin
2015-07-20 14:26 ` Eric Blake
2015-07-20 12:12 ` [Qemu-devel] [PULL 4/6] pci_add_capability: remove duplicate comments Michael S. Tsirkin
2015-07-20 12:12 ` Michael S. Tsirkin [this message]
2015-07-20 12:12 ` [Qemu-devel] [PULL 6/6] virtio-net: remove virtio queues if the guest doesn't support multiqueue Michael S. Tsirkin
2015-07-20 15:01 ` [Qemu-devel] [PULL 0/6] virtio, vhost, pc fixes for 2.4 Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1437394279-24416-6-git-send-email-mst@redhat.com \
--to=mst@redhat.com \
--cc=famz@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).