virtio: fix for assertion failure: virtio_net_get_subqueue(nc)->async_tx.elem failed
v2 cover virtio: fix for assertion failure: virtio_net_get_subqueue(nc)->async_tx.elem failed
In the current design, we stop the device from operating on the vring during per-queue reset by resetting the structure VirtQueue.
But before the reset operation, when recycling some resources, we should stop referencing new vring resources.
This bug is caused by this reason.
https://gitlab.com/qemu-project/qemu/-/issues/1451
Before we reset the structure, we called the ->queue_reset callback to let the device reclaim resources. Here virtio-net tries to release the packets sent asynchronously, but during this process virtio_net_flush_tx() will be called, and new data will be sent again. This leads to asserted.
assert(!virtio_net_get_subqueue(nc)->async_tx.elem);
v2:
1. fix by stop flush inside virtio_net_tx_complete() when purge packets.
v1:
1. rename "reset" to disabled_by_reset
2. add api: virtio_queue_reset_state()
Xuan Zhuo (2):
virtio_net: virtio_net_tx_complete() stop flush new packets for purge
operation
virtio_net: just purge tx when dev/queue reset
hw/net/virtio-net.c | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-)
--
2.32.0.3.g01195cf9f
PATCH v2 1/2 virtio_net: virtio_net_tx_complete() stop flush new packets for purge operation
For async tx, virtio_net_tx_complete() is called when purge or flush operation is done. But for purge operation, we should not try to flush new packet from tx queue. The purge operation means we will stop the queue soon.
--- hw/net/virtio-net.c | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-)
hw/net/virtio-net.c +18 -14
@@ -2601,21 +2601,25 @@ static void virtio_net_tx_complete(NetClientState *nc, ssize_t len) q->async_tx.elem =NULL ;virtio_queue_set_notification (q->tx_vq,1 ); - ret =virtio_net_flush_tx (q); -if (ret >= n->tx_burst) { -/* -* the flush has been stopped by tx_burst -* we will not receive notification for the -* remainining part, so re-schedule -*/ -virtio_queue_set_notification (q->tx_vq,0 ); -if (q->tx_bh) { -qemu_bh_schedule (q->tx_bh); - }else { -timer_mod (q->tx_timer, -qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) + n->tx_timeout); + +/* len == 0 means purge, we should not flush new tx packets. */ +if (len) { + ret =virtio_net_flush_tx (q); +if (ret >= n->tx_burst) { +/* +* the flush has been stopped by tx_burst +* we will not receive notification for the +* remainining part, so re-schedule +*/ +virtio_queue_set_notification (q->tx_vq,0 ); +if (q->tx_bh) { +qemu_bh_schedule (q->tx_bh); + }else { +timer_mod (q->tx_timer, +qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) + n->tx_timeout); + } + q->tx_waiting =1 ; } - q->tx_waiting =1 ; } }
Signature · 1 line
2.32.0.3.g01195cf9f
PATCH v2 2/2 virtio_net: just purge tx when dev/queue reset
In reply to Xuan ZhuoWhen dev/queue reset, we should just purge all packet, not try to flush the async packets. When flush these async packets, the callback(virtio_net_tx_complete) will try to flush new packets from tx queue.
--- hw/net/virtio-net.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/net/virtio-net.c +1 -1
@@ -570,7 +570,7 @@ static void virtio_net_queue_reset(VirtIODevice *vdev, uint32_t queue_index)vhost_net_virtqueue_reset (vdev, nc, queue_index); } -flush_or_purge_queued_packets (nc); +qemu_purge_queued_packets (nc); }static void virtio_net_queue_enable (VirtIODevice *vdev,uint32_t queue_index)
Signature · 1 line
2.32.0.3.g01195cf9f