Skip to contentSkip to conversation

virtio-net: Flush incoming queues when DRIVER_OK is being set

PATCH In review Fam Zheng 2 participants 3 messages Jul 14, 2015

lore
Share & tools
lore

Fam Zheng

author
#0 lore raw

PATCH 1/1 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.

---
 hw/net/virtio-net.c | 5 +++++
 1 file changed, 5 insertions(+)
hw/net/virtio-net.c +5 -0
index d728233..7c178c6 100644
@@ -162,8 +162,13 @@ 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);
         q = &n->vqs[i];
 
+        if (status & VIRTIO_CONFIG_S_DRIVER_OK) {
+            qemu_flush_queued_packets(ncs);
+        }
+
         if ((!n->multiqueue && i != 0) || i >= n->curr_queues) {
             queue_status = 0;
         } else {
Signature · 1 line
2.4.3
#1 lore raw
Quoted 32 lines · Fam Zheng

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.

---
 hw/net/virtio-net.c | 5 +++++
 1 file changed, 5 insertions(+)
hw/net/virtio-net.c +0 -0
index d728233..7c178c6 100644
@@ -162,8 +162,13 @@ 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++) {

hw/net/virtio-net.c static void virtio_net_set_status(struct VirtIODevice *vdev, uint8_t status) · line 174

Quoted 10 lines
hw/net/virtio-net.c +5 -0
+        NetClientState *ncs = qemu_get_subqueue(n->nic, i);
         q = &n->vqs[i];
 
+        if (status & VIRTIO_CONFIG_S_DRIVER_OK) {
+            qemu_flush_queued_packets(ncs);
+        }
+
         if ((!n->multiqueue && i != 0) || i >= n->curr_queues) {
             queue_status = 0;
         } else {

I think this should be limited to

	virtio_net_started(n, queue_status) && !n->vhost_started
Quoted 2 lines
Signature · 1 line
2.4.3
author
#2 lore raw
Quoted 45 lines · Michael S. Tsirkin
Quoted 32 lines · Fam Zheng

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.

---
 hw/net/virtio-net.c | 5 +++++
 1 file changed, 5 insertions(+)
hw/net/virtio-net.c +0 -0
index d728233..7c178c6 100644
@@ -162,8 +162,13 @@ 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++) {

hw/net/virtio-net.c static void virtio_net_set_status(struct VirtIODevice *vdev, uint8_t status) · line 174

Quoted 10 lines
hw/net/virtio-net.c +5 -0
+        NetClientState *ncs = qemu_get_subqueue(n->nic, i);
         q = &n->vqs[i];
 
+        if (status & VIRTIO_CONFIG_S_DRIVER_OK) {
+            qemu_flush_queued_packets(ncs);
+        }
+
         if ((!n->multiqueue && i != 0) || i >= n->curr_queues) {
             queue_status = 0;
         } else {

I think this should be limited to

Quoted 1 line
	virtio_net_started(n, queue_status) && !n->vhost_started

Yes, that looks better.

Fam