[dpdk-dev] net/virtio: fix qemu exit on device stop/start
Commit Message
Starting with DPDK 16.04, performing a start, then stop followed by a
start on a virtio NIC sending traffic can cause qemu to exit.
Qemu exits with a message like:
2016-09-01T15:45:32.119059Z qemu-kvm: Guest moved used index from 5
to 1
This appears to occur because virtio_dev_start will always reinitialize
the virtio queues if virtio_dev_stop has been called. Prior to the
patch that introduced the regression, virtio_dev_stop did not mark the
device as stopped, so start would not actually reinitialize the queues.
This fix reintroduces that behaviour by tracking whether or not the
queues require initialization separately from whether or not the device
has been stopped. It does this by introducing an "opened" flag to the
device.
A simple test with testpmd can reproduce the problem.
1. Set up two virtio ports, ideally connecting two devices which can
ping one-another.
2. Start pinging between the devices
3. Start testpmd in interactive mode on the two virtio ports
e.g. testpmd -w 0000:00:05.0 -w 0000:00:06.0 -- -i
4. Run the following commands a few times:
start
stop
port stop 0
port stop 1
port start 0
port start 1
start
5. Qemu should exit with a "Guest moved ..." message.
After applying this patch, I can no longer reproduce this problem.
The ping resumes every time I start the ports back up.
Test environment:
- CPU: Intel(R) Xeon(R) CPU E5-2650 v2 @ 2.60GHz
- Host OS: CentOS Linux release 7.1.1503 (Core)
- Guest OS: CentOS Linux release 7.2.1511 (Core)
- Qemu-kvm version: 1.5.3-86.el7_1.6
Fixes: 9a0615af7746 ("virtio: fix restart")
Signed-off-by: Kyle Larose <klarose@sandvine.com>
---
drivers/net/virtio/virtio_ethdev.c | 10 ++++++++--
drivers/net/virtio/virtio_pci.h | 1 +
2 files changed, 9 insertions(+), 2 deletions(-)
@@ -558,6 +558,9 @@ virtio_dev_close(struct rte_eth_dev *dev)
vtpci_reset(hw);
virtio_dev_free_mbufs(dev);
virtio_free_queues(dev);
+
+ hw->opened = 0;
+
}
static void
@@ -1393,9 +1396,10 @@ virtio_dev_start(struct rte_eth_dev *dev)
virtio_dev_link_update(dev, 0);
/* On restart after stop do not touch queues */
- if (hw->started)
+ if (hw->opened) {
+ hw->started = 1;
return 0;
-
+ }
/* Do final configuration before rx/tx engine starts */
virtio_dev_rxtx_start(dev);
vtpci_reinit_complete(hw);
@@ -1431,6 +1435,8 @@ virtio_dev_start(struct rte_eth_dev *dev)
VIRTQUEUE_DUMP(txvq->vq);
}
+ hw->opened = 1;
+
return 0;
}
@@ -252,6 +252,7 @@ struct virtio_hw {
uint8_t vlan_strip;
uint8_t use_msix;
uint8_t started;
+ uint8_t opened;
uint8_t modern;
uint8_t mac_addr[ETHER_ADDR_LEN];
uint32_t notify_off_multiplier;