virtio: fix for assertion failure: virtio_net_get_subqueue(nc)->async_tx.elem failed
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);
This patch set introduce new item "reset" into struct VirtQueue, then device can know this virtqueue is per-queue reset state.
v1:
1. rename "reset" to disabled_by_reset
2. add api: virtio_queue_reset_state()
Xuan Zhuo (2):
virtio: struct VirtQueue introduce reset
virtio-net: virtio_net_flush_tx() check for per-queue reset
hw/net/virtio-net.c | 3 ++- hw/virtio/virtio.c | 15 +++++++++++++++ include/hw/virtio/virtio.h | 1 + 3 files changed, 18 insertions(+), 1 deletion(-)
--
2.32.0.3.g01195cf9f
PATCH 1/2 virtio: struct VirtQueue introduce reset
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. For example, when recycling virtio-net's asynchronous sending resources, virtio-net should be able to perceive that the current queue is in the per-queue reset state, and stop sending new packets from the tx queue.
--- hw/virtio/virtio.c | 15 +++++++++++++++ include/hw/virtio/virtio.h | 1 + 2 files changed, 16 insertions(+)
hw/virtio/virtio.c +15 -0
@@ -142,6 +142,8 @@ struct VirtQueue/* Notification enabled? */ bool notification; +bool disabled_by_reset; +uint16_t queue_index;unsigned int inuse;
@@ -2079,6 +2081,12 @@ void virtio_queue_reset(VirtIODevice *vdev, uint32_t queue_index) {VirtioDeviceClass *k =VIRTIO_DEVICE_GET_CLASS (vdev); +/* +* Mark this queue is per-queue reset status. The device should release the +* references of the vring, and not refer more new vring item. +*/ + vdev->vq[queue_index].disabled_by_reset = true; +if (k->queue_reset) { k->queue_reset (vdev, queue_index); }
@@ -2102,11 +2110,18 @@ void virtio_queue_enable(VirtIODevice *vdev, uint32_t queue_index)} */ + vdev->vq[queue_index].disabled_by_reset = false; +if (k->queue_enable) { k->queue_enable (vdev, queue_index); } } +bool virtio_queue_reset_state (VirtQueue *vq) +{ +return vq->disabled_by_reset; +} +void virtio_reset (void *opaque) {VirtIODevice *vdev = opaque;
include/hw/virtio/virtio.h +1 -0
@@ -319,6 +319,7 @@ int virtio_set_status(VirtIODevice *vdev, uint8_t val);void virtio_reset (void *opaque);void virtio_queue_reset (VirtIODevice *vdev,uint32_t queue_index);void virtio_queue_enable (VirtIODevice *vdev,uint32_t queue_index); +bool virtio_queue_reset_state (VirtQueue *vq);void virtio_update_irq (VirtIODevice *vdev);int virtio_set_features (VirtIODevice *vdev,uint64_t val);
Signature · 1 line
2.32.0.3.g01195cf9f
Re: [PATCH v1 1/2] virtio: struct VirtQueue introduce reset
subject seems wrong.
Quoted 29 lines · Xuan Zhuo
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. For example, when recycling virtio-net's asynchronous sending resources, virtio-net should be able to perceive that the current queue is in the per-queue reset state, and stop sending new packets from the tx queue.
Signed-off-by Xuan Zhuo <[email protected]>--- hw/virtio/virtio.c | 15 +++++++++++++++ include/hw/virtio/virtio.h | 1 + 2 files changed, 16 insertions(+)hw/virtio/virtio.c +2
-0@@ -142,6 +142,8 @@ struct VirtQueue/* Notification enabled? */ bool notification; +bool disabled_by_reset; +uint16_t queue_index;unsigned int inuse;
hw/virtio/virtio.c void virtio_queue_reset(VirtIODevice *vdev, uint32_t queue_index) · line 2086
Quoted 6 lines
hw/virtio/virtio.c +3
-0@@ -2079,6 +2081,12 @@ void virtio_queue_reset(VirtIODevice *vdev, uint32_t queue_index) {VirtioDeviceClass *k =VIRTIO_DEVICE_GET_CLASS (vdev); +/* +* Mark this queue is per-queue reset status. The device should release the +* references of the vring, and not refer more new vring item.
items
hw/virtio/virtio.c void virtio_queue_reset(VirtIODevice *vdev, uint32_t queue_index) · line 2092
Quoted 6 lines
hw/virtio/virtio.c +3
-0+*/ + vdev->vq[queue_index].disabled_by_reset = true; +if (k->queue_reset) { k->queue_reset (vdev, queue_index); }
can we set this after calling queue_reset? For symmetry with enable.
Quoted 24 lines
hw/virtio/virtio.c +7
-0@@ -2102,11 +2110,18 @@ void virtio_queue_enable(VirtIODevice *vdev, uint32_t queue_index)} */ + vdev->vq[queue_index].disabled_by_reset = false; +if (k->queue_enable) { k->queue_enable (vdev, queue_index); } } +bool virtio_queue_reset_state (VirtQueue *vq) +{ +return vq->disabled_by_reset; +} +void virtio_reset (void *opaque) {VirtIODevice *vdev = opaque;include/hw/virtio/virtio.h +0
-0
include/hw/virtio/virtio.h int virtio_set_status(VirtIODevice *vdev, uint8_t val); · line 324
Quoted 6 lines
include/hw/virtio/virtio.h +1
-0@@ -319,6 +319,7 @@ int virtio_set_status(VirtIODevice *vdev, uint8_t val);void virtio_reset (void *opaque);void virtio_queue_reset (VirtIODevice *vdev,uint32_t queue_index);void virtio_queue_enable (VirtIODevice *vdev,uint32_t queue_index); +bool virtio_queue_reset_state (VirtQueue *vq);void virtio_update_irq (VirtIODevice *vdev);int virtio_set_features (VirtIODevice *vdev,uint64_t val);
OK I guess ... what about migration. This state won't be set correctly will it?
Quoted 3 lines
Signature · 2 lines
-- 2.32.0.3.g01195cf9f
Re: [PATCH v1 1/2] virtio: struct VirtQueue introduce reset
Quoted 2 lines · Michael S. Tsirkin
subject seems wrong.
Will fix.
Quoted 34 lines · Xuan Zhuo
Quoted 32 lines
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. For example, when recycling virtio-net's asynchronous sending resources, virtio-net should be able to perceive that the current queue is in the per-queue reset state, and stop sending new packets from the tx queue.
Signed-off-by Xuan Zhuo <[email protected]>--- hw/virtio/virtio.c | 15 +++++++++++++++ include/hw/virtio/virtio.h | 1 + 2 files changed, 16 insertions(+)hw/virtio/virtio.c +2
-0@@ -142,6 +142,8 @@ struct VirtQueue/* Notification enabled? */ bool notification; +bool disabled_by_reset; +uint16_t queue_index;unsigned int inuse;@@ -2079,6 +2081,12 @@ void virtio_queue_reset(VirtIODevice *vdev, uint32_t queue_index) {VirtioDeviceClass *k =VIRTIO_DEVICE_GET_CLASS (vdev);
Quoted 5 lines
hw/virtio/virtio.c void virtio_queue_reset(VirtIODevice *vdev, uint32_t queue_index) · line 2086
Quoted 3 lines
hw/virtio/virtio.c +3
-0+/* +* Mark this queue is per-queue reset status. The device should release the +* references of the vring, and not refer more new vring item. items
Will fix.
Quoted 9 lines
hw/virtio/virtio.c void virtio_queue_reset(VirtIODevice *vdev, uint32_t queue_index) · line 2092
Quoted 7 lines
hw/virtio/virtio.c +3
-0+*/ + vdev->vq[queue_index].disabled_by_reset = true; +if (k->queue_reset) { k->queue_reset (vdev, queue_index); }can we set this after calling
queue_reset? For symmetry with enable.
In fact, queue_reset() will check it.
Quoted 26 lines
Quoted 26 lines
hw/virtio/virtio.c +7
-0@@ -2102,11 +2110,18 @@ void virtio_queue_enable(VirtIODevice *vdev, uint32_t queue_index)} */ + vdev->vq[queue_index].disabled_by_reset = false; +if (k->queue_enable) { k->queue_enable (vdev, queue_index); } } +bool virtio_queue_reset_state (VirtQueue *vq) +{ +return vq->disabled_by_reset; +} +void virtio_reset (void *opaque) {VirtIODevice *vdev = opaque;include/hw/virtio/virtio.h +0
-0@@ -319,6 +319,7 @@ int virtio_set_status(VirtIODevice *vdev, uint8_t val);void virtio_reset (void *opaque);
Quoted 8 lines
include/hw/virtio/virtio.h int virtio_set_status(VirtIODevice *vdev, uint8_t val); · line 324
Quoted 5 lines
include/hw/virtio/virtio.h +1
-0void virtio_queue_reset (VirtIODevice *vdev,uint32_t queue_index);void virtio_queue_enable (VirtIODevice *vdev,uint32_t queue_index); +bool virtio_queue_reset_state (VirtQueue *vq);void virtio_update_irq (VirtIODevice *vdev);int virtio_set_features (VirtIODevice *vdev,uint64_t val);OK I guess ... what about migration. This state won't be set correctly will it?
I think it has no effect. After the reset, there is actually no state. We can migrate.
The current variable is only used by ->queue_reset().
Thanks.
Quoted 6 lines
Quoted 5 lines
include/hw/virtio/virtio.h +0
-1--2.32.0.3.g01195cf9f
Re: [PATCH v1 1/2] virtio: struct VirtQueue introduce reset
Quoted 59 lines · Xuan Zhuo
Quoted 2 lines · Michael S. Tsirkin
subject seems wrong.
Will fix.
Quoted 34 lines · Xuan Zhuo
Quoted 32 lines
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. For example, when recycling virtio-net's asynchronous sending resources, virtio-net should be able to perceive that the current queue is in the per-queue reset state, and stop sending new packets from the tx queue.
Signed-off-by Xuan Zhuo <[email protected]>--- hw/virtio/virtio.c | 15 +++++++++++++++ include/hw/virtio/virtio.h | 1 + 2 files changed, 16 insertions(+)hw/virtio/virtio.c +2
-0@@ -142,6 +142,8 @@ struct VirtQueue/* Notification enabled? */ bool notification; +bool disabled_by_reset; +uint16_t queue_index;unsigned int inuse;@@ -2079,6 +2081,12 @@ void virtio_queue_reset(VirtIODevice *vdev, uint32_t queue_index) {VirtioDeviceClass *k =VIRTIO_DEVICE_GET_CLASS (vdev);Quoted 5 lines
hw/virtio/virtio.c void virtio_queue_reset(VirtIODevice *vdev, uint32_t queue_index) · line 2086
Quoted 3 lines
hw/virtio/virtio.c +3
-0+/* +* Mark this queue is per-queue reset status. The device should release the +* references of the vring, and not refer more new vring item. items
Will fix.
Quoted 8 lines
Quoted 7 lines
hw/virtio/virtio.c +3
-0+*/ + vdev->vq[queue_index].disabled_by_reset = true; +if (k->queue_reset) { k->queue_reset (vdev, queue_index); }
Quoted 5 lines
Quoted 1 line
can we set this after calling
queue_reset? For symmetry with enable.In fact,
queue_reset()will check it.
when you disable you first set it then disable.
so when we are not 100% ready it's already set.
when you enable you first clear it then enable.
so we are not 100% ready but it's no longer set.
inconsistent.
Quoted 35 lines
Quoted 26 lines
Quoted 26 lines
hw/virtio/virtio.c +7
-0@@ -2102,11 +2110,18 @@ void virtio_queue_enable(VirtIODevice *vdev, uint32_t queue_index)} */ + vdev->vq[queue_index].disabled_by_reset = false; +if (k->queue_enable) { k->queue_enable (vdev, queue_index); } } +bool virtio_queue_reset_state (VirtQueue *vq) +{ +return vq->disabled_by_reset; +} +void virtio_reset (void *opaque) {VirtIODevice *vdev = opaque;include/hw/virtio/virtio.h +0
-0@@ -319,6 +319,7 @@ int virtio_set_status(VirtIODevice *vdev, uint8_t val);void virtio_reset (void *opaque);Quoted 8 lines
include/hw/virtio/virtio.h int virtio_set_status(VirtIODevice *vdev, uint8_t val); · line 324
Quoted 5 lines
include/hw/virtio/virtio.h +1
-0void virtio_queue_reset (VirtIODevice *vdev,uint32_t queue_index);void virtio_queue_enable (VirtIODevice *vdev,uint32_t queue_index); +bool virtio_queue_reset_state (VirtQueue *vq);void virtio_update_irq (VirtIODevice *vdev);int virtio_set_features (VirtIODevice *vdev,uint64_t val);OK I guess ... what about migration. This state won't be set correctly will it?
Quoted 7 lines
I think it has no effect. After the reset, there is actually no state. We can migrate.
The current variable is only used by ->queue_reset().
Thanks.
Yea maybe it works for this bug but ... yack. This means the state has no logic consistency. It's just there because you found a bug and wanted to fix it.
An ultra specific
bool this_weird_state_fuzzer_gets_in_issue_1451;
is hard to maintain, not happy :(
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
include/hw/virtio/virtio.h +0
-1--2.32.0.3.g01195cf9f
Re: [PATCH v1 1/2] virtio: struct VirtQueue introduce reset
Quoted 116 lines · Michael S. Tsirkin
Quoted 59 lines · Xuan Zhuo
Quoted 2 lines · Michael S. Tsirkin
subject seems wrong.
Will fix.
Quoted 34 lines · Xuan Zhuo
Quoted 32 lines
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. For example, when recycling virtio-net's asynchronous sending resources, virtio-net should be able to perceive that the current queue is in the per-queue reset state, and stop sending new packets from the tx queue.
Signed-off-by Xuan Zhuo <[email protected]>--- hw/virtio/virtio.c | 15 +++++++++++++++ include/hw/virtio/virtio.h | 1 + 2 files changed, 16 insertions(+)hw/virtio/virtio.c +2
-0@@ -142,6 +142,8 @@ struct VirtQueue/* Notification enabled? */ bool notification; +bool disabled_by_reset; +uint16_t queue_index;unsigned int inuse;@@ -2079,6 +2081,12 @@ void virtio_queue_reset(VirtIODevice *vdev, uint32_t queue_index) {VirtioDeviceClass *k =VIRTIO_DEVICE_GET_CLASS (vdev);Quoted 5 lines
hw/virtio/virtio.c void virtio_queue_reset(VirtIODevice *vdev, uint32_t queue_index) · line 2086
Quoted 3 lines
hw/virtio/virtio.c +3
-0+/* +* Mark this queue is per-queue reset status. The device should release the +* references of the vring, and not refer more new vring item. items
Will fix.
Quoted 8 lines
Quoted 7 lines
hw/virtio/virtio.c +3
-0+*/ + vdev->vq[queue_index].disabled_by_reset = true; +if (k->queue_reset) { k->queue_reset (vdev, queue_index); }Quoted 5 lines
Quoted 1 line
can we set this after calling
queue_reset? For symmetry with enable.In fact,
queue_reset()will check it.when you disable you first set it then disable.
so when we are not 100% ready it's already set.
when you enable you first clear it then enable.
so we are not 100% ready but it's no longer set.
inconsistent.Quoted 35 lines
Quoted 26 lines
Quoted 26 lines
hw/virtio/virtio.c +7
-0@@ -2102,11 +2110,18 @@ void virtio_queue_enable(VirtIODevice *vdev, uint32_t queue_index)} */ + vdev->vq[queue_index].disabled_by_reset = false; +if (k->queue_enable) { k->queue_enable (vdev, queue_index); } } +bool virtio_queue_reset_state (VirtQueue *vq) +{ +return vq->disabled_by_reset; +} +void virtio_reset (void *opaque) {VirtIODevice *vdev = opaque;include/hw/virtio/virtio.h +0
-0@@ -319,6 +319,7 @@ int virtio_set_status(VirtIODevice *vdev, uint8_t val);void virtio_reset (void *opaque);Quoted 8 lines
include/hw/virtio/virtio.h int virtio_set_status(VirtIODevice *vdev, uint8_t val); · line 324
Quoted 5 lines
include/hw/virtio/virtio.h +1
-0void virtio_queue_reset (VirtIODevice *vdev,uint32_t queue_index);void virtio_queue_enable (VirtIODevice *vdev,uint32_t queue_index); +bool virtio_queue_reset_state (VirtQueue *vq);void virtio_update_irq (VirtIODevice *vdev);int virtio_set_features (VirtIODevice *vdev,uint64_t val);OK I guess ... what about migration. This state won't be set correctly will it?
Quoted 7 lines
I think it has no effect. After the reset, there is actually no state. We can migrate.
The current variable is only used by ->queue_reset().
Thanks.
Quoted 6 lines
Yea maybe it works for this bug but ... yack. This means the state has no logic consistency. It's just there because you found a bug and wanted to fix it.
An ultra specificbool this_weird_state_fuzzer_gets_in_issue_1451;is hard to maintain, not happy :(
I agree.
Thanks.
Quoted 9 lines
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
include/hw/virtio/virtio.h +0
-1--2.32.0.3.g01195cf9f
PATCH 2/2 virtio-net: virtio_net_flush_tx() check for per-queue reset
In reply to Xuan ZhuoCheck whether it is per-queue reset state in virtio_net_flush_tx().
Before per-queue reset, we need to recover async tx resources. At this time, virtio_net_flush_tx() is called, but we should not try to send new packets, so virtio_net_flush_tx() should check the current per-queue reset state.
--- hw/net/virtio-net.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
hw/net/virtio-net.c +2 -1
@@ -2627,7 +2627,8 @@ static int32_t virtio_net_flush_tx(VirtIONetQueue *q)VirtQueueElement *elem;int32_t num_packets =0 ;int queue_index =vq2q (virtio_get_queue_index (q->tx_vq)); -if (!(vdev->status &VIRTIO_CONFIG_S_DRIVER_OK )) { +if (!(vdev->status &VIRTIO_CONFIG_S_DRIVER_OK ) || +virtio_queue_reset_state (q->tx_vq)) {return num_packets; }
Signature · 1 line
2.32.0.3.g01195cf9f
Re: [PATCH v1 2/2] virtio-net: virtio_net_flush_tx() check for per-queue reset
Quoted 21 lines · Xuan Zhuo
Check whether it is per-queue reset state in
virtio_net_flush_tx().Before per-queue reset, we need to recover async tx resources. At this time,
virtio_net_flush_tx()is called, but we should not try to send new packets, sovirtio_net_flush_tx()should check the current per-queue reset state.Fixes 7dc6be52 ("virtio-net: support queue reset")Reported-by Alexander Bulekov <[email protected]>Signed-off-by Xuan Zhuo <[email protected]>--- hw/net/virtio-net.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)hw/net/virtio-net.c +0
-0
hw/net/virtio-net.c static int32_t virtio_net_flush_tx(VirtIONetQueue *q) · line 2631
Quoted 6 lines
hw/net/virtio-net.c +2
-1@@ -2627,7 +2627,8 @@ static int32_t virtio_net_flush_tx(VirtIONetQueue *q)VirtQueueElement *elem;int32_t num_packets =0 ;int queue_index =vq2q (virtio_get_queue_index (q->tx_vq)); -if (!(vdev->status &VIRTIO_CONFIG_S_DRIVER_OK )) { +if (!(vdev->status &VIRTIO_CONFIG_S_DRIVER_OK ) || +virtio_queue_reset_state (q->tx_vq)) {
We have other places that check DRIVER_OK do we need to check queue reset as well?
E.g:virtio_net_can_receive()
virtio_net_tx_{timer|bh}()
Thanks
Quoted 6 lines
hw/net/virtio-net.c +0
-1return num_packets; } --2.32.0.3.g01195cf9f
Re: [PATCH v1 2/2] virtio-net: virtio_net_flush_tx() check for per-queue reset
Quoted 17 lines · Jason Wang
Quoted 16 lines · Xuan Zhuo
Check whether it is per-queue reset state in
virtio_net_flush_tx().Before per-queue reset, we need to recover async tx resources. At this time,
virtio_net_flush_tx()is called, but we should not try to send new packets, sovirtio_net_flush_tx()should check the current per-queue reset state.Fixes 7dc6be52 ("virtio-net: support queue reset")Reported-by Alexander Bulekov <[email protected]>Signed-off-by Xuan Zhuo <[email protected]>--- hw/net/virtio-net.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
Quoted 14 lines
hw/net/virtio-net.c static int32_t virtio_net_flush_tx(VirtIONetQueue *q) · line 2631
Quoted 11 lines
hw/net/virtio-net.c +2
-1@@ -2627,7 +2627,8 @@ static int32_t virtio_net_flush_tx(VirtIONetQueue *q)VirtQueueElement *elem;int32_t num_packets =0 ;int queue_index =vq2q (virtio_get_queue_index (q->tx_vq)); -if (!(vdev->status &VIRTIO_CONFIG_S_DRIVER_OK )) { +if (!(vdev->status &VIRTIO_CONFIG_S_DRIVER_OK ) || +virtio_queue_reset_state (q->tx_vq)) {We have other places that check
DRIVER_OKdo we need to check queue reset as well?
I checked it again. I still think that the location of other checking DRIVER_OK does not need to check the queue reset.
Thanks.
Quoted 14 lines
E.g:
virtio_net_can_receive()
virtio_net_tx_{timer|bh}()Thanks
Quoted 6 lines
hw/net/virtio-net.c +0
-1return num_packets; } --2.32.0.3.g01195cf9f
Re: [PATCH v1 2/2] virtio-net: virtio_net_flush_tx() check for per-queue reset
Quoted 34 lines · Xuan Zhuo
Quoted 17 lines · Jason Wang
Quoted 16 lines · Xuan Zhuo
Check whether it is per-queue reset state in
virtio_net_flush_tx().Before per-queue reset, we need to recover async tx resources. At this time,
virtio_net_flush_tx()is called, but we should not try to send new packets, sovirtio_net_flush_tx()should check the current per-queue reset state.Fixes 7dc6be52 ("virtio-net: support queue reset")Reported-by Alexander Bulekov <[email protected]>Signed-off-by Xuan Zhuo <[email protected]>--- hw/net/virtio-net.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)Quoted 14 lines
hw/net/virtio-net.c static int32_t virtio_net_flush_tx(VirtIONetQueue *q) · line 2631
Quoted 11 lines
hw/net/virtio-net.c +2
-1@@ -2627,7 +2627,8 @@ static int32_t virtio_net_flush_tx(VirtIONetQueue *q)VirtQueueElement *elem;int32_t num_packets =0 ;int queue_index =vq2q (virtio_get_queue_index (q->tx_vq)); -if (!(vdev->status &VIRTIO_CONFIG_S_DRIVER_OK )) { +if (!(vdev->status &VIRTIO_CONFIG_S_DRIVER_OK ) || +virtio_queue_reset_state (q->tx_vq)) {We have other places that check
DRIVER_OKdo we need to check queue reset as well?
Quoted 2 lines
I checked it again. I still think that the location of other checking
DRIVER_OKdoes not need to check the queue reset.
For example, if we don't disable can_receive() when the queue is reset, it means rx may go for virtio_net_receive_rcu(). It means the Qemu is still trying to process the traffic from the network backend like tap which may waste cpu cycles.
I think the correct way is to return false when the queue is reset in can_receive(), then the backend poll will be disabled (e.g TAP). When the queue is enabled again, qemu_flush_queued_packets() will wake up the backend polling.
Having had time to check other places but it would be better to mention why it doesn't need a check in the changelog.
Thanks
Quoted 19 lines
Thanks.
Quoted 14 lines
E.g:
virtio_net_can_receive()
virtio_net_tx_{timer|bh}()Thanks
Quoted 6 lines
hw/net/virtio-net.c +0
-1return num_packets; } --2.32.0.3.g01195cf9f
Re: [PATCH v1 2/2] virtio-net: virtio_net_flush_tx() check for per-queue reset
Quoted 43 lines · Jason Wang
Quoted 34 lines · Xuan Zhuo
Quoted 17 lines · Jason Wang
Quoted 16 lines · Xuan Zhuo
Check whether it is per-queue reset state in
virtio_net_flush_tx().Before per-queue reset, we need to recover async tx resources. At this time,
virtio_net_flush_tx()is called, but we should not try to send new packets, sovirtio_net_flush_tx()should check the current per-queue reset state.Fixes 7dc6be52 ("virtio-net: support queue reset")Reported-by Alexander Bulekov <[email protected]>Signed-off-by Xuan Zhuo <[email protected]>--- hw/net/virtio-net.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)Quoted 14 lines
hw/net/virtio-net.c static int32_t virtio_net_flush_tx(VirtIONetQueue *q) · line 2631
Quoted 11 lines
hw/net/virtio-net.c +2
-1@@ -2627,7 +2627,8 @@ static int32_t virtio_net_flush_tx(VirtIONetQueue *q)VirtQueueElement *elem;int32_t num_packets =0 ;int queue_index =vq2q (virtio_get_queue_index (q->tx_vq)); -if (!(vdev->status &VIRTIO_CONFIG_S_DRIVER_OK )) { +if (!(vdev->status &VIRTIO_CONFIG_S_DRIVER_OK ) || +virtio_queue_reset_state (q->tx_vq)) {We have other places that check
DRIVER_OKdo we need to check queue reset as well?Quoted 2 lines
I checked it again. I still think that the location of other checking
DRIVER_OKdoes not need to check the queue reset.For example, if we don't disable
can_receive()when the queue is reset, it means rx may go forvirtio_net_receive_rcu(). It means the Qemu is still trying to process the traffic from the network backend like tap which may waste cpu cycles.
Quoted 7 lines
I think the correct way is to return false when the queue is reset in
can_receive(), then the backend poll will be disabled (e.g TAP). When the queue is enabled again,qemu_flush_queued_packets()will wake up the backend polling.Having had time to check other places but it would be better to mention why it doesn't need a check in the changelog.
static bool virtio_net_can_receive(NetClientState *nc)
{
VirtIONet *n = qemu_get_nic_opaque(nc);
VirtIODevice *vdev = VIRTIO_DEVICE(n);
VirtIONetQueue *q = virtio_net_get_subqueue(nc);
if (!vdev->vm_running) {
return false;
}
if (nc->queue_index >= n->curr_queue_pairs) {
return false;
}
if (!virtio_queue_ready(q->rx_vq) ||
!(vdev->status & VIRTIO_CONFIG_S_DRIVER_OK)) {
return false;
}
return true;
}int virtio_queue_ready(VirtQueue *vq)
{
return vq->vring.avail != 0;
}static void __virtio_queue_reset(VirtIODevice *vdev, uint32_t i)
{
vdev->vq[i].vring.desc = 0;
vdev->vq[i].vring.avail = 0;
vdev->vq[i].vring.used = 0;
vdev->vq[i].last_avail_idx = 0;
vdev->vq[i].shadow_avail_idx = 0;
vdev->vq[i].used_idx = 0;
vdev->vq[i].last_avail_wrap_counter = true;
vdev->vq[i].shadow_avail_wrap_counter = true;
vdev->vq[i].used_wrap_counter = true;
virtio_queue_set_vector(vdev, i, VIRTIO_NO_VECTOR);
vdev->vq[i].signalled_used = 0;
vdev->vq[i].signalled_used_valid = false;
vdev->vq[i].notification = true;
vdev->vq[i].vring.num = vdev->vq[i].vring.num_default;
vdev->vq[i].inuse = 0;
virtio_virtqueue_reset_region_cache(&vdev->vq[i]);
}In the implementation of Per-Queue Reset, for RX, we stop RX by setting vdev->vq[i].vring.avail to 0. Then callback can_receive will return False.
Thanks.
Quoted 23 lines
Thanks
Quoted 19 lines
Thanks.
Quoted 14 lines
E.g:
virtio_net_can_receive()
virtio_net_tx_{timer|bh}()Thanks
Quoted 6 lines
hw/net/virtio-net.c +0
-1return num_packets; } --2.32.0.3.g01195cf9f
Re: [PATCH v1 2/2] virtio-net: virtio_net_flush_tx() check for per-queue reset
Quoted 102 lines · Xuan Zhuo
Quoted 43 lines · Jason Wang
Quoted 34 lines · Xuan Zhuo
Quoted 17 lines · Jason Wang
Quoted 16 lines · Xuan Zhuo
Check whether it is per-queue reset state in
virtio_net_flush_tx().Before per-queue reset, we need to recover async tx resources. At this time,
virtio_net_flush_tx()is called, but we should not try to send new packets, sovirtio_net_flush_tx()should check the current per-queue reset state.Fixes 7dc6be52 ("virtio-net: support queue reset")Reported-by Alexander Bulekov <[email protected]>Signed-off-by Xuan Zhuo <[email protected]>--- hw/net/virtio-net.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)Quoted 14 lines
hw/net/virtio-net.c static int32_t virtio_net_flush_tx(VirtIONetQueue *q) · line 2631
Quoted 11 lines
hw/net/virtio-net.c +2
-1@@ -2627,7 +2627,8 @@ static int32_t virtio_net_flush_tx(VirtIONetQueue *q)VirtQueueElement *elem;int32_t num_packets =0 ;int queue_index =vq2q (virtio_get_queue_index (q->tx_vq)); -if (!(vdev->status &VIRTIO_CONFIG_S_DRIVER_OK )) { +if (!(vdev->status &VIRTIO_CONFIG_S_DRIVER_OK ) || +virtio_queue_reset_state (q->tx_vq)) {We have other places that check
DRIVER_OKdo we need to check queue reset as well?Quoted 2 lines
I checked it again. I still think that the location of other checking
DRIVER_OKdoes not need to check the queue reset.For example, if we don't disable
can_receive()when the queue is reset, it means rx may go forvirtio_net_receive_rcu(). It means the Qemu is still trying to process the traffic from the network backend like tap which may waste cpu cycles.Quoted 7 lines
I think the correct way is to return false when the queue is reset in
can_receive(), then the backend poll will be disabled (e.g TAP). When the queue is enabled again,qemu_flush_queued_packets()will wake up the backend polling.Having had time to check other places but it would be better to mention why it doesn't need a check in the changelog.
static bool
virtio_net_can_receive(NetClientState *nc){ VirtIONet *n = qemu_get_nic_opaque(nc); VirtIODevice *vdev = VIRTIO_DEVICE(n); VirtIONetQueue *q = virtio_net_get_subqueue(nc); if (!vdev->vm_running) { return false; } if (nc->queue_index >= n->curr_queue_pairs) { return false; } if (!virtio_queue_ready(q->rx_vq) || !(vdev->status & VIRTIO_CONFIG_S_DRIVER_OK)) { return false; } return true; }int
virtio_queue_ready(VirtQueue *vq){ return vq->vring.avail != 0; }static void
__virtio_queue_reset(VirtIODevice *vdev, uint32_t i){ vdev->vq[i].vring.desc = 0; vdev->vq[i].vring.avail = 0; vdev->vq[i].vring.used = 0; vdev->vq[i].last_avail_idx = 0; vdev->vq[i].shadow_avail_idx = 0; vdev->vq[i].used_idx = 0; vdev->vq[i].last_avail_wrap_counter = true; vdev->vq[i].shadow_avail_wrap_counter = true; vdev->vq[i].used_wrap_counter = true; virtio_queue_set_vector(vdev, i, VIRTIO_NO_VECTOR); vdev->vq[i].signalled_used = 0; vdev->vq[i].signalled_used_valid = false; vdev->vq[i].notification = true; vdev->vq[i].vring.num = vdev->vq[i].vring.num_default; vdev->vq[i].inuse = 0; virtio_virtqueue_reset_region_cache(&vdev->vq[i]); }
Quoted 1 line
In the implementation of Per-Queue Reset, for RX, we stop RX by setting vdev->vq[i].vring.avail to 0.
Ok, but this is kind of fragile (especially when vIOMMU is enabled). I'd add an explicit check for reset there.
(probably on top).
Thanks
Quoted 30 lines
Then callback
can_receivewill return False.Thanks.
Quoted 23 lines
Thanks
Quoted 19 lines
Thanks.
Quoted 14 lines
E.g:
virtio_net_can_receive()
virtio_net_tx_{timer|bh}()Thanks
Quoted 6 lines
hw/net/virtio-net.c +0
-1return num_packets; } --2.32.0.3.g01195cf9f
Re: [PATCH v1 2/2] virtio-net: virtio_net_flush_tx() check for per-queue reset
Quoted 103 lines · Jason Wang
Quoted 102 lines · Xuan Zhuo
Quoted 43 lines · Jason Wang
Quoted 34 lines · Xuan Zhuo
Quoted 17 lines · Jason Wang
Quoted 16 lines · Xuan Zhuo
Check whether it is per-queue reset state in
virtio_net_flush_tx().Before per-queue reset, we need to recover async tx resources. At this time,
virtio_net_flush_tx()is called, but we should not try to send new packets, sovirtio_net_flush_tx()should check the current per-queue reset state.Fixes 7dc6be52 ("virtio-net: support queue reset")Reported-by Alexander Bulekov <[email protected]>Signed-off-by Xuan Zhuo <[email protected]>--- hw/net/virtio-net.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)Quoted 14 lines
hw/net/virtio-net.c static int32_t virtio_net_flush_tx(VirtIONetQueue *q) · line 2631
Quoted 11 lines
hw/net/virtio-net.c +2
-1@@ -2627,7 +2627,8 @@ static int32_t virtio_net_flush_tx(VirtIONetQueue *q)VirtQueueElement *elem;int32_t num_packets =0 ;int queue_index =vq2q (virtio_get_queue_index (q->tx_vq)); -if (!(vdev->status &VIRTIO_CONFIG_S_DRIVER_OK )) { +if (!(vdev->status &VIRTIO_CONFIG_S_DRIVER_OK ) || +virtio_queue_reset_state (q->tx_vq)) {We have other places that check
DRIVER_OKdo we need to check queue reset as well?Quoted 2 lines
I checked it again. I still think that the location of other checking
DRIVER_OKdoes not need to check the queue reset.For example, if we don't disable
can_receive()when the queue is reset, it means rx may go forvirtio_net_receive_rcu(). It means the Qemu is still trying to process the traffic from the network backend like tap which may waste cpu cycles.Quoted 7 lines
I think the correct way is to return false when the queue is reset in
can_receive(), then the backend poll will be disabled (e.g TAP). When the queue is enabled again,qemu_flush_queued_packets()will wake up the backend polling.Having had time to check other places but it would be better to mention why it doesn't need a check in the changelog.
static bool
virtio_net_can_receive(NetClientState *nc){ VirtIONet *n = qemu_get_nic_opaque(nc); VirtIODevice *vdev = VIRTIO_DEVICE(n); VirtIONetQueue *q = virtio_net_get_subqueue(nc); if (!vdev->vm_running) { return false; } if (nc->queue_index >= n->curr_queue_pairs) { return false; } if (!virtio_queue_ready(q->rx_vq) || !(vdev->status & VIRTIO_CONFIG_S_DRIVER_OK)) { return false; } return true; }int
virtio_queue_ready(VirtQueue *vq){ return vq->vring.avail != 0; }static void
__virtio_queue_reset(VirtIODevice *vdev, uint32_t i){ vdev->vq[i].vring.desc = 0; vdev->vq[i].vring.avail = 0; vdev->vq[i].vring.used = 0; vdev->vq[i].last_avail_idx = 0; vdev->vq[i].shadow_avail_idx = 0; vdev->vq[i].used_idx = 0; vdev->vq[i].last_avail_wrap_counter = true; vdev->vq[i].shadow_avail_wrap_counter = true; vdev->vq[i].used_wrap_counter = true; virtio_queue_set_vector(vdev, i, VIRTIO_NO_VECTOR); vdev->vq[i].signalled_used = 0; vdev->vq[i].signalled_used_valid = false; vdev->vq[i].notification = true; vdev->vq[i].vring.num = vdev->vq[i].vring.num_default; vdev->vq[i].inuse = 0; virtio_virtqueue_reset_region_cache(&vdev->vq[i]); }
Quoted 4 lines
Quoted 1 line
In the implementation of Per-Queue Reset, for RX, we stop RX by setting vdev->vq[i].vring.avail to 0.
Ok, but this is kind of fragile (especially when vIOMMU is enabled). I'd add an explicit check for reset there.
It's not great in that spec says avail 0 is actually legal. But I don't really want to see more and more checks.
If we are doing cleanups, the right way is probably a new "live" flag that transports can set correctly from the combination of DRIVER_OK, desc, kick, queue_enable, queue_reset and so on.
Quoted 34 lines
(probably on top).
Thanks
Quoted 30 lines
Then callback
can_receivewill return False.Thanks.
Quoted 23 lines
Thanks
Quoted 19 lines
Thanks.
Quoted 14 lines
E.g:
virtio_net_can_receive()
virtio_net_tx_{timer|bh}()Thanks
Quoted 6 lines
hw/net/virtio-net.c +0
-1return num_packets; } --2.32.0.3.g01195cf9f
Re: [PATCH v1 2/2] virtio-net: virtio_net_flush_tx() check for per-queue reset
Quoted 107 lines · Michael S. Tsirkin
Quoted 105 lines · Jason Wang
Quoted 103 lines · Xuan Zhuo
Quoted 43 lines · Jason Wang
Quoted 34 lines · Xuan Zhuo
Quoted 17 lines · Jason Wang
Quoted 16 lines · Xuan Zhuo
Check whether it is per-queue reset state in
virtio_net_flush_tx().Before per-queue reset, we need to recover async tx resources. At this time,
virtio_net_flush_tx()is called, but we should not try to send new packets, sovirtio_net_flush_tx()should check the current per-queue reset state.Fixes 7dc6be52 ("virtio-net: support queue reset")Reported-by Alexander Bulekov <[email protected]>Signed-off-by Xuan Zhuo <[email protected]>--- hw/net/virtio-net.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)Quoted 14 lines
hw/net/virtio-net.c static int32_t virtio_net_flush_tx(VirtIONetQueue *q) · line 2631
Quoted 11 lines
hw/net/virtio-net.c +2
-1@@ -2627,7 +2627,8 @@ static int32_t virtio_net_flush_tx(VirtIONetQueue *q)VirtQueueElement *elem;int32_t num_packets =0 ;int queue_index =vq2q (virtio_get_queue_index (q->tx_vq)); -if (!(vdev->status &VIRTIO_CONFIG_S_DRIVER_OK )) { +if (!(vdev->status &VIRTIO_CONFIG_S_DRIVER_OK ) || +virtio_queue_reset_state (q->tx_vq)) {We have other places that check
DRIVER_OKdo we need to check queue reset as well?Quoted 2 lines
I checked it again. I still think that the location of other checking
DRIVER_OKdoes not need to check the queue reset.For example, if we don't disable
can_receive()when the queue is reset, it means rx may go forvirtio_net_receive_rcu(). It means the Qemu is still trying to process the traffic from the network backend like tap which may waste cpu cycles.Quoted 7 lines
I think the correct way is to return false when the queue is reset in
can_receive(), then the backend poll will be disabled (e.g TAP). When the queue is enabled again,qemu_flush_queued_packets()will wake up the backend polling.Having had time to check other places but it would be better to mention why it doesn't need a check in the changelog.
static bool
virtio_net_can_receive(NetClientState *nc){ VirtIONet *n = qemu_get_nic_opaque(nc); VirtIODevice *vdev = VIRTIO_DEVICE(n); VirtIONetQueue *q = virtio_net_get_subqueue(nc); if (!vdev->vm_running) { return false; } if (nc->queue_index >= n->curr_queue_pairs) { return false; } if (!virtio_queue_ready(q->rx_vq) || !(vdev->status & VIRTIO_CONFIG_S_DRIVER_OK)) { return false; } return true; }int
virtio_queue_ready(VirtQueue *vq){ return vq->vring.avail != 0; }static void
__virtio_queue_reset(VirtIODevice *vdev, uint32_t i){ vdev->vq[i].vring.desc = 0; vdev->vq[i].vring.avail = 0; vdev->vq[i].vring.used = 0; vdev->vq[i].last_avail_idx = 0; vdev->vq[i].shadow_avail_idx = 0; vdev->vq[i].used_idx = 0; vdev->vq[i].last_avail_wrap_counter = true; vdev->vq[i].shadow_avail_wrap_counter = true; vdev->vq[i].used_wrap_counter = true; virtio_queue_set_vector(vdev, i, VIRTIO_NO_VECTOR); vdev->vq[i].signalled_used = 0; vdev->vq[i].signalled_used_valid = false; vdev->vq[i].notification = true; vdev->vq[i].vring.num = vdev->vq[i].vring.num_default; vdev->vq[i].inuse = 0; virtio_virtqueue_reset_region_cache(&vdev->vq[i]); }In the implementation of Per-Queue Reset, for RX, we stop RX by setting vdev->vq[i].vring.avail to 0.
Quoted 8 lines
Quoted 2 lines
Ok, but this is kind of fragile (especially when vIOMMU is enabled). I'd add an explicit check for reset there.
It's not great in that spec says avail 0 is actually legal. But I don't really want to see more and more checks.
If we are doing cleanups, the right way is probably a new "live" flag that transports can set correctly from the combination ofDRIVER_OK, desc, kick,queue_enable,queue_resetand so on.
I second this, but for kick, we can only do that unless it is mandated by the spec (otherwise we may break drivers silently).
Thanks
Quoted 36 lines
Quoted 35 lines
(probably on top).
Thanks
Quoted 30 lines
Then callback
can_receivewill return False.Thanks.
Quoted 23 lines
Thanks
Quoted 19 lines
Thanks.
Quoted 14 lines
E.g:
virtio_net_can_receive()
virtio_net_tx_{timer|bh}()Thanks
Quoted 6 lines
hw/net/virtio-net.c +0
-1return num_packets; } --2.32.0.3.g01195cf9f
Re: [PATCH v1 2/2] virtio-net: virtio_net_flush_tx() check for per-queue reset
In reply to Xuan ZhuoQuoted 6 lines · Xuan Zhuo
Check whether it is per-queue reset state in
virtio_net_flush_tx().Before per-queue reset, we need to recover async tx resources. At this time,
virtio_net_flush_tx()is called, but we should not try to send new packets, sovirtio_net_flush_tx()should check the current per-queue reset state.
What does "at this time" mean here?
Do you in fact mean it's called from flush_or_purge_queued_packets? What does the call stack look like?
If yes introducing a vq state just so virtio_net_flush_tx knows we are in the process of reset would be a bad idea. We want something much more local, ideally on stack even ...
Quoted 25 lines
Fixes 7dc6be52 ("virtio-net: support queue reset")Reported-by Alexander Bulekov <[email protected]>Signed-off-by Xuan Zhuo <[email protected]>--- hw/net/virtio-net.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)hw/net/virtio-net.c +2
-1@@ -2627,7 +2627,8 @@ static int32_t virtio_net_flush_tx(VirtIONetQueue *q)VirtQueueElement *elem;int32_t num_packets =0 ;int queue_index =vq2q (virtio_get_queue_index (q->tx_vq)); -if (!(vdev->status &VIRTIO_CONFIG_S_DRIVER_OK )) { +if (!(vdev->status &VIRTIO_CONFIG_S_DRIVER_OK ) || +virtio_queue_reset_state (q->tx_vq)) {return num_packets; }Signature · 1 line
2.32.0.3.g01195cf9f
Re: [PATCH v1 2/2] virtio-net: virtio_net_flush_tx() check for per-queue reset
Quoted 11 lines · Michael S. Tsirkin
Quoted 6 lines · Xuan Zhuo
Check whether it is per-queue reset state in
virtio_net_flush_tx().Before per-queue reset, we need to recover async tx resources. At this time,
virtio_net_flush_tx()is called, but we should not try to send new packets, sovirtio_net_flush_tx()should check the current per-queue reset state.What does "at this time" mean here?
Do you in fact mean it's called fromflush_or_purge_queued_packets?
Yes
virtio_queue_reset
k->queue_reset virtio_net_queue_reset flush_or_purge_queued_packets qemu_flush_or_purge_queued_packets ..... (callback) virtio_net_tx_complete virtio_net_flush_tx <-- here send new packet. We need stop it.
Because it is inside the callback, I can't pass information through the stack. I originally thought it was a general situation, so I wanted to put it in struct VirtQueue.
If it is not very suitable, it may be better to put it in VirtIONetQueue.
Thanks.
Quoted 33 lines
What does the call stack look like?
If yes introducing a vq state just so
virtio_net_flush_txknows we are in the process of reset would be a bad idea. We want something much more local, ideally on stack even ...Quoted 25 lines
Fixes 7dc6be52 ("virtio-net: support queue reset")Reported-by Alexander Bulekov <[email protected]>Signed-off-by Xuan Zhuo <[email protected]>--- hw/net/virtio-net.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)hw/net/virtio-net.c +2
-2@@ -2627,7 +2627,8 @@ static int32_t virtio_net_flush_tx(VirtIONetQueue *q)VirtQueueElement *elem;int32_t num_packets =0 ;int queue_index =vq2q (virtio_get_queue_index (q->tx_vq)); -if (!(vdev->status &VIRTIO_CONFIG_S_DRIVER_OK )) { +if (!(vdev->status &VIRTIO_CONFIG_S_DRIVER_OK ) || +virtio_queue_reset_state (q->tx_vq)) {return num_packets; } --2.32.0.3.g01195cf9f
Re: [PATCH v1 2/2] virtio-net: virtio_net_flush_tx() check for per-queue reset
Quoted 25 lines · Xuan Zhuo
Quoted 11 lines · Michael S. Tsirkin
Quoted 6 lines · Xuan Zhuo
Check whether it is per-queue reset state in
virtio_net_flush_tx().Before per-queue reset, we need to recover async tx resources. At this time,
virtio_net_flush_tx()is called, but we should not try to send new packets, sovirtio_net_flush_tx()should check the current per-queue reset state.What does "at this time" mean here?
Do you in fact mean it's called fromflush_or_purge_queued_packets?Yes
virtio_queue_resetk->queue_reset virtio_net_queue_reset flush_or_purge_queued_packets qemu_flush_or_purge_queued_packets ..... (callback) virtio_net_tx_complete virtio_net_flush_tx <-- here send new packet. We need stop it.
Quoted 7 lines
Because it is inside the callback, I can't pass information through the stack. I originally thought it was a general situation, so I wanted to put it in struct VirtQueue.
If it is not very suitable, it may be better to put it in VirtIONetQueue.
Thanks.
Hmm maybe. Another idea: isn't virtio_net_tx_complete called with length 0 here? Are there other cases where length is 0?
Quoted 16 lines
Quoted 16 lines
What does the call stack look like?
If yes introducing a vq state just so
virtio_net_flush_txknows we are in the process of reset would be a bad idea. We want something much more local, ideally on stack even ...Quoted 9 lines
Fixes 7dc6be52 ("virtio-net: support queue reset")Reported-by Alexander Bulekov <[email protected]>Signed-off-by Xuan Zhuo <[email protected]>--- hw/net/virtio-net.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
Quoted 11 lines
Quoted 11 lines
hw/net/virtio-net.c static int32_t virtio_net_flush_tx(VirtIONetQueue *q) · line 2631
Quoted 11 lines
hw/net/virtio-net.c +2
-1@@ -2627,7 +2627,8 @@ static int32_t virtio_net_flush_tx(VirtIONetQueue *q)VirtQueueElement *elem;int32_t num_packets =0 ;int queue_index =vq2q (virtio_get_queue_index (q->tx_vq)); -if (!(vdev->status &VIRTIO_CONFIG_S_DRIVER_OK )) { +if (!(vdev->status &VIRTIO_CONFIG_S_DRIVER_OK ) || +virtio_queue_reset_state (q->tx_vq)) {
btw this sounds like you are asking it to reset some state.
Quoted 1 line
Quoted 1 line
hw/net/virtio-net.c static int32_t virtio_net_flush_tx(VirtIONetQueue *q) · line 2632
Quoted 1 line
hw/net/virtio-net.c +0
-0return num_packets;
and then
ret = virtio_net_flush_tx(q);
if (ret >= n->tx_burst)will reschedule automatically won't it?
also why check in virtio_net_flush_tx and not virtio_net_tx_complete?
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
hw/net/virtio-net.c +0
-1} --2.32.0.3.g01195cf9f
Re: [PATCH v1 2/2] virtio-net: virtio_net_flush_tx() check for per-queue reset
Quoted 72 lines · Michael S. Tsirkin
Quoted 25 lines · Xuan Zhuo
Quoted 11 lines · Michael S. Tsirkin
Quoted 6 lines · Xuan Zhuo
Check whether it is per-queue reset state in
virtio_net_flush_tx().Before per-queue reset, we need to recover async tx resources. At this time,
virtio_net_flush_tx()is called, but we should not try to send new packets, sovirtio_net_flush_tx()should check the current per-queue reset state.What does "at this time" mean here?
Do you in fact mean it's called fromflush_or_purge_queued_packets?Yes
virtio_queue_resetk->queue_reset virtio_net_queue_reset flush_or_purge_queued_packets qemu_flush_or_purge_queued_packets ..... (callback) virtio_net_tx_complete virtio_net_flush_tx <-- here send new packet. We need stop it.Quoted 7 lines
Because it is inside the callback, I can't pass information through the stack. I originally thought it was a general situation, so I wanted to put it in struct VirtQueue.
If it is not very suitable, it may be better to put it in VirtIONetQueue.
Thanks.
Hmm maybe. Another idea: isn't
virtio_net_tx_completecalled with length 0 here? Are there other cases where length is 0?Quoted 16 lines
Quoted 16 lines
What does the call stack look like?
If yes introducing a vq state just so
virtio_net_flush_txknows we are in the process of reset would be a bad idea. We want something much more local, ideally on stack even ...Quoted 9 lines
Fixes 7dc6be52 ("virtio-net: support queue reset")Reported-by Alexander Bulekov <[email protected]>Signed-off-by Xuan Zhuo <[email protected]>--- hw/net/virtio-net.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)Quoted 11 lines
Quoted 11 lines
hw/net/virtio-net.c static int32_t virtio_net_flush_tx(VirtIONetQueue *q) · line 2631
Quoted 11 lines
hw/net/virtio-net.c +2
-1@@ -2627,7 +2627,8 @@ static int32_t virtio_net_flush_tx(VirtIONetQueue *q)VirtQueueElement *elem;int32_t num_packets =0 ;int queue_index =vq2q (virtio_get_queue_index (q->tx_vq)); -if (!(vdev->status &VIRTIO_CONFIG_S_DRIVER_OK )) { +if (!(vdev->status &VIRTIO_CONFIG_S_DRIVER_OK ) || +virtio_queue_reset_state (q->tx_vq)) {btw this sounds like you are asking it to reset some state.
Quoted 1 line
Quoted 1 line
hw/net/virtio-net.c static int32_t virtio_net_flush_tx(VirtIONetQueue *q) · line 2632
Quoted 1 line
hw/net/virtio-net.c +0
-0return num_packets;and then
Quoted 7 lines
ret = virtio_net_flush_tx(q); if (ret >= n->tx_burst)will reschedule automatically won't it?
also why check in
virtio_net_flush_txand notvirtio_net_tx_complete?
virtio_net_flush_tx may been called by timer.
Thanks.
Quoted 8 lines
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
hw/net/virtio-net.c +0
-1} --2.32.0.3.g01195cf9f
Re: [PATCH v1 2/2] virtio-net: virtio_net_flush_tx() check for per-queue reset
Quoted 77 lines · Xuan Zhuo
Quoted 76 lines · Michael S. Tsirkin
Quoted 25 lines · Xuan Zhuo
Quoted 11 lines · Michael S. Tsirkin
Quoted 6 lines · Xuan Zhuo
Check whether it is per-queue reset state in
virtio_net_flush_tx().Before per-queue reset, we need to recover async tx resources. At this time,
virtio_net_flush_tx()is called, but we should not try to send new packets, sovirtio_net_flush_tx()should check the current per-queue reset state.What does "at this time" mean here?
Do you in fact mean it's called fromflush_or_purge_queued_packets?Yes
virtio_queue_resetk->queue_reset virtio_net_queue_reset flush_or_purge_queued_packets qemu_flush_or_purge_queued_packets ..... (callback) virtio_net_tx_complete virtio_net_flush_tx <-- here send new packet. We need stop it.Quoted 7 lines
Because it is inside the callback, I can't pass information through the stack. I originally thought it was a general situation, so I wanted to put it in struct VirtQueue.
If it is not very suitable, it may be better to put it in VirtIONetQueue.
Thanks.
Hmm maybe. Another idea: isn't
virtio_net_tx_completecalled with length 0 here? Are there other cases where length is 0?Quoted 16 lines
Quoted 16 lines
What does the call stack look like?
If yes introducing a vq state just so
virtio_net_flush_txknows we are in the process of reset would be a bad idea. We want something much more local, ideally on stack even ...Quoted 9 lines
Fixes 7dc6be52 ("virtio-net: support queue reset")Reported-by Alexander Bulekov <[email protected]>Signed-off-by Xuan Zhuo <[email protected]>--- hw/net/virtio-net.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)Quoted 11 lines
Quoted 11 lines
hw/net/virtio-net.c static int32_t virtio_net_flush_tx(VirtIONetQueue *q) · line 2631
Quoted 11 lines
hw/net/virtio-net.c +2
-1@@ -2627,7 +2627,8 @@ static int32_t virtio_net_flush_tx(VirtIONetQueue *q)VirtQueueElement *elem;int32_t num_packets =0 ;int queue_index =vq2q (virtio_get_queue_index (q->tx_vq)); -if (!(vdev->status &VIRTIO_CONFIG_S_DRIVER_OK )) { +if (!(vdev->status &VIRTIO_CONFIG_S_DRIVER_OK ) || +virtio_queue_reset_state (q->tx_vq)) {btw this sounds like you are asking it to reset some state.
Quoted 1 line
Quoted 1 line
hw/net/virtio-net.c static int32_t virtio_net_flush_tx(VirtIONetQueue *q) · line 2632
Quoted 1 line
hw/net/virtio-net.c +0
-0return num_packets;and then
ret = virtio_net_flush_tx(q); if (ret >= n->tx_burst)
Quoted 7 lines
Quoted 3 lines
will reschedule automatically won't it?
also why check in
virtio_net_flush_txand notvirtio_net_tx_complete?
virtio_net_flush_txmay been called by timer.Thanks.
timer won't run while flush_or_purge_queued_packets is in progress.
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
hw/net/virtio-net.c +0
-1} --2.32.0.3.g01195cf9f
Re: [PATCH v1 2/2] virtio-net: virtio_net_flush_tx() check for per-queue reset
Quoted 80 lines · Michael S. Tsirkin
Quoted 79 lines · Xuan Zhuo
Quoted 78 lines · Michael S. Tsirkin
Quoted 25 lines · Xuan Zhuo
Quoted 11 lines · Michael S. Tsirkin
Quoted 6 lines · Xuan Zhuo
Check whether it is per-queue reset state in
virtio_net_flush_tx().Before per-queue reset, we need to recover async tx resources. At this time,
virtio_net_flush_tx()is called, but we should not try to send new packets, sovirtio_net_flush_tx()should check the current per-queue reset state.What does "at this time" mean here?
Do you in fact mean it's called fromflush_or_purge_queued_packets?Yes
virtio_queue_resetk->queue_reset virtio_net_queue_reset flush_or_purge_queued_packets qemu_flush_or_purge_queued_packets ..... (callback) virtio_net_tx_complete virtio_net_flush_tx <-- here send new packet. We need stop it.Quoted 7 lines
Because it is inside the callback, I can't pass information through the stack. I originally thought it was a general situation, so I wanted to put it in struct VirtQueue.
If it is not very suitable, it may be better to put it in VirtIONetQueue.
Thanks.
Hmm maybe. Another idea: isn't
virtio_net_tx_completecalled with length 0 here? Are there other cases where length is 0?Quoted 16 lines
Quoted 16 lines
What does the call stack look like?
If yes introducing a vq state just so
virtio_net_flush_txknows we are in the process of reset would be a bad idea. We want something much more local, ideally on stack even ...Quoted 9 lines
Fixes 7dc6be52 ("virtio-net: support queue reset")Reported-by Alexander Bulekov <[email protected]>Signed-off-by Xuan Zhuo <[email protected]>--- hw/net/virtio-net.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)Quoted 11 lines
Quoted 11 lines
hw/net/virtio-net.c static int32_t virtio_net_flush_tx(VirtIONetQueue *q) · line 2631
Quoted 11 lines
hw/net/virtio-net.c +2
-1@@ -2627,7 +2627,8 @@ static int32_t virtio_net_flush_tx(VirtIONetQueue *q)VirtQueueElement *elem;int32_t num_packets =0 ;int queue_index =vq2q (virtio_get_queue_index (q->tx_vq)); -if (!(vdev->status &VIRTIO_CONFIG_S_DRIVER_OK )) { +if (!(vdev->status &VIRTIO_CONFIG_S_DRIVER_OK ) || +virtio_queue_reset_state (q->tx_vq)) {btw this sounds like you are asking it to reset some state.
Quoted 1 line
Quoted 1 line
hw/net/virtio-net.c static int32_t virtio_net_flush_tx(VirtIONetQueue *q) · line 2632
Quoted 1 line
hw/net/virtio-net.c +0
-0return num_packets;and then
ret = virtio_net_flush_tx(q); if (ret >= n->tx_burst)will reschedule automatically won't it?
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
also why check in
virtio_net_flush_txand notvirtio_net_tx_complete?
virtio_net_flush_txmay been called by timer.Thanks.
timer won't run while
flush_or_purge_queued_packetsis in progress.
Is timer not executed during the VMEXIT process? Otherwise, we still have to consider that after the flush_or_purge_queued_packets, this process before the structure is cleared.
Even if it can be processed in virtio_net_tx_complete, is there any good way? This is a callback, it is not convenient to pass the parameters.
Thanks
Quoted 10 lines
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
hw/net/virtio-net.c +0
-1} --2.32.0.3.g01195cf9f
Re: [PATCH v1 2/2] virtio-net: virtio_net_flush_tx() check for per-queue reset
Quoted 85 lines · Xuan Zhuo
Quoted 84 lines · Michael S. Tsirkin
Quoted 83 lines · Xuan Zhuo
Quoted 72 lines · Michael S. Tsirkin
Quoted 25 lines · Xuan Zhuo
Quoted 11 lines · Michael S. Tsirkin
Quoted 6 lines · Xuan Zhuo
Check whether it is per-queue reset state in
virtio_net_flush_tx().Before per-queue reset, we need to recover async tx resources. At this time,
virtio_net_flush_tx()is called, but we should not try to send new packets, sovirtio_net_flush_tx()should check the current per-queue reset state.What does "at this time" mean here?
Do you in fact mean it's called fromflush_or_purge_queued_packets?Yes
virtio_queue_resetk->queue_reset virtio_net_queue_reset flush_or_purge_queued_packets qemu_flush_or_purge_queued_packets ..... (callback) virtio_net_tx_complete virtio_net_flush_tx <-- here send new packet. We need stop it.Quoted 7 lines
Because it is inside the callback, I can't pass information through the stack. I originally thought it was a general situation, so I wanted to put it in struct VirtQueue.
If it is not very suitable, it may be better to put it in VirtIONetQueue.
Thanks.
Hmm maybe. Another idea: isn't
virtio_net_tx_completecalled with length 0 here? Are there other cases where length is 0?Quoted 16 lines
Quoted 16 lines
What does the call stack look like?
If yes introducing a vq state just so
virtio_net_flush_txknows we are in the process of reset would be a bad idea. We want something much more local, ideally on stack even ...Quoted 9 lines
Fixes 7dc6be52 ("virtio-net: support queue reset")Reported-by Alexander Bulekov <[email protected]>Signed-off-by Xuan Zhuo <[email protected]>--- hw/net/virtio-net.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)Quoted 11 lines
Quoted 11 lines
hw/net/virtio-net.c static int32_t virtio_net_flush_tx(VirtIONetQueue *q) · line 2631
Quoted 11 lines
hw/net/virtio-net.c +2
-1@@ -2627,7 +2627,8 @@ static int32_t virtio_net_flush_tx(VirtIONetQueue *q)VirtQueueElement *elem;int32_t num_packets =0 ;int queue_index =vq2q (virtio_get_queue_index (q->tx_vq)); -if (!(vdev->status &VIRTIO_CONFIG_S_DRIVER_OK )) { +if (!(vdev->status &VIRTIO_CONFIG_S_DRIVER_OK ) || +virtio_queue_reset_state (q->tx_vq)) {btw this sounds like you are asking it to reset some state.
Quoted 1 line
Quoted 1 line
hw/net/virtio-net.c static int32_t virtio_net_flush_tx(VirtIONetQueue *q) · line 2632
Quoted 1 line
hw/net/virtio-net.c +0
-0return num_packets;and then
Quoted 7 lines
ret = virtio_net_flush_tx(q); if (ret >= n->tx_burst)will reschedule automatically won't it?
also why check in
virtio_net_flush_txand notvirtio_net_tx_complete?
virtio_net_flush_txmay been called by timer.
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
Thanks.
timer won't run while
flush_or_purge_queued_packetsis in progress.Is timer not executed during the VMEXIT process? Otherwise, we still have to consider that after the
flush_or_purge_queued_packets, this process before the structure is cleared.
void virtio_queue_reset(VirtIODevice *vdev, uint32_t queue_index)
{
VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
if (k->queue_reset) {
k->queue_reset(vdev, queue_index);
}
__virtio_queue_reset(vdev, queue_index);
}No timers do not run between k->queue_reset and __virtio_queue_reset.
Quoted 4 lines
Even if it can be processed in
virtio_net_tx_complete, is there any good way? This is a callback, it is not convenient to pass the parameters.Thanks
How about checking that length is 0?
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
hw/net/virtio-net.c +0
-1} --2.32.0.3.g01195cf9f
Re: [PATCH v1 2/2] virtio-net: virtio_net_flush_tx() check for per-queue reset
Quoted 111 lines · Michael S. Tsirkin
Quoted 85 lines · Xuan Zhuo
Quoted 84 lines · Michael S. Tsirkin
Quoted 83 lines · Xuan Zhuo
Quoted 72 lines · Michael S. Tsirkin
Quoted 25 lines · Xuan Zhuo
Quoted 11 lines · Michael S. Tsirkin
Quoted 6 lines · Xuan Zhuo
Check whether it is per-queue reset state in
virtio_net_flush_tx().Before per-queue reset, we need to recover async tx resources. At this time,
virtio_net_flush_tx()is called, but we should not try to send new packets, sovirtio_net_flush_tx()should check the current per-queue reset state.What does "at this time" mean here?
Do you in fact mean it's called fromflush_or_purge_queued_packets?Yes
virtio_queue_resetk->queue_reset virtio_net_queue_reset flush_or_purge_queued_packets qemu_flush_or_purge_queued_packets ..... (callback) virtio_net_tx_complete virtio_net_flush_tx <-- here send new packet. We need stop it.Quoted 7 lines
Because it is inside the callback, I can't pass information through the stack. I originally thought it was a general situation, so I wanted to put it in struct VirtQueue.
If it is not very suitable, it may be better to put it in VirtIONetQueue.
Thanks.
Hmm maybe. Another idea: isn't
virtio_net_tx_completecalled with length 0 here? Are there other cases where length is 0?Quoted 16 lines
Quoted 16 lines
What does the call stack look like?
If yes introducing a vq state just so
virtio_net_flush_txknows we are in the process of reset would be a bad idea. We want something much more local, ideally on stack even ...Quoted 9 lines
Fixes 7dc6be52 ("virtio-net: support queue reset")Reported-by Alexander Bulekov <[email protected]>Signed-off-by Xuan Zhuo <[email protected]>--- hw/net/virtio-net.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)Quoted 11 lines
Quoted 11 lines
hw/net/virtio-net.c static int32_t virtio_net_flush_tx(VirtIONetQueue *q) · line 2631
Quoted 11 lines
hw/net/virtio-net.c +2
-1@@ -2627,7 +2627,8 @@ static int32_t virtio_net_flush_tx(VirtIONetQueue *q)VirtQueueElement *elem;int32_t num_packets =0 ;int queue_index =vq2q (virtio_get_queue_index (q->tx_vq)); -if (!(vdev->status &VIRTIO_CONFIG_S_DRIVER_OK )) { +if (!(vdev->status &VIRTIO_CONFIG_S_DRIVER_OK ) || +virtio_queue_reset_state (q->tx_vq)) {btw this sounds like you are asking it to reset some state.
Quoted 1 line
Quoted 1 line
hw/net/virtio-net.c static int32_t virtio_net_flush_tx(VirtIONetQueue *q) · line 2632
Quoted 1 line
hw/net/virtio-net.c +0
-0return num_packets;and then
Quoted 7 lines
ret = virtio_net_flush_tx(q); if (ret >= n->tx_burst)will reschedule automatically won't it?
also why check in
virtio_net_flush_txand notvirtio_net_tx_complete?
virtio_net_flush_txmay been called by timer.Quoted 7 lines
Quoted 3 lines
Quoted 1 line
Thanks.
timer won't run while
flush_or_purge_queued_packetsis in progress.Is timer not executed during the VMEXIT process? Otherwise, we still have to consider that after the
flush_or_purge_queued_packets, this process before the structure is cleared.void
virtio_queue_reset(VirtIODevice *vdev, uint32_t queue_index){ VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev); if (k->queue_reset) { k->queue_reset(vdev, queue_index); } __virtio_queue_reset(vdev, queue_index); }No timers do not run between
k->queue_resetand__virtio_queue_reset.
Quoted 7 lines
Quoted 4 lines
Even if it can be processed in
virtio_net_tx_complete, is there any good way? This is a callback, it is not convenient to pass the parameters.Thanks
How about checking that length is 0?
I think you refer to the second parameter of virtio_net_tx_complete "len".
void qemu_net_queue_purge(NetQueue *queue, NetClientState *from)
{
NetPacket *packet, *next;
QTAILQ_FOREACH_SAFE(packet, &queue->packets, entry, next) {
if (packet->sender == from) {
QTAILQ_REMOVE(&queue->packets, packet, entry);
queue->nq_count--;
if (packet->sent_cb) {
packet->sent_cb(packet->sender, 0);
}
g_free(packet);
}
}
}qemu_net_queue_purge pass 0 as len. This function has been called in large quantities. I am not sure if it will have a bad impact. I will try if there is a good way to pass the parameters on the stack.
Thanks.
Quoted 13 lines
Quoted 12 lines
Quoted 12 lines
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
hw/net/virtio-net.c +0
-1} --2.32.0.3.g01195cf9f
Re: [PATCH v1 2/2] virtio-net: virtio_net_flush_tx() check for per-queue reset
In reply to Michael S. TsirkinQuoted 111 lines · Michael S. Tsirkin
Quoted 85 lines · Xuan Zhuo
Quoted 84 lines · Michael S. Tsirkin
Quoted 83 lines · Xuan Zhuo
Quoted 72 lines · Michael S. Tsirkin
Quoted 25 lines · Xuan Zhuo
Quoted 11 lines · Michael S. Tsirkin
Quoted 6 lines · Xuan Zhuo
Check whether it is per-queue reset state in
virtio_net_flush_tx().Before per-queue reset, we need to recover async tx resources. At this time,
virtio_net_flush_tx()is called, but we should not try to send new packets, sovirtio_net_flush_tx()should check the current per-queue reset state.What does "at this time" mean here?
Do you in fact mean it's called fromflush_or_purge_queued_packets?Yes
virtio_queue_resetk->queue_reset virtio_net_queue_reset flush_or_purge_queued_packets qemu_flush_or_purge_queued_packets ..... (callback) virtio_net_tx_complete virtio_net_flush_tx <-- here send new packet. We need stop it.Quoted 7 lines
Because it is inside the callback, I can't pass information through the stack. I originally thought it was a general situation, so I wanted to put it in struct VirtQueue.
If it is not very suitable, it may be better to put it in VirtIONetQueue.
Thanks.
Hmm maybe. Another idea: isn't
virtio_net_tx_completecalled with length 0 here? Are there other cases where length is 0?Quoted 16 lines
Quoted 16 lines
What does the call stack look like?
If yes introducing a vq state just so
virtio_net_flush_txknows we are in the process of reset would be a bad idea. We want something much more local, ideally on stack even ...Quoted 9 lines
Fixes 7dc6be52 ("virtio-net: support queue reset")Reported-by Alexander Bulekov <[email protected]>Signed-off-by Xuan Zhuo <[email protected]>--- hw/net/virtio-net.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)Quoted 11 lines
Quoted 11 lines
hw/net/virtio-net.c static int32_t virtio_net_flush_tx(VirtIONetQueue *q) · line 2631
Quoted 11 lines
hw/net/virtio-net.c +2
-1@@ -2627,7 +2627,8 @@ static int32_t virtio_net_flush_tx(VirtIONetQueue *q)VirtQueueElement *elem;int32_t num_packets =0 ;int queue_index =vq2q (virtio_get_queue_index (q->tx_vq)); -if (!(vdev->status &VIRTIO_CONFIG_S_DRIVER_OK )) { +if (!(vdev->status &VIRTIO_CONFIG_S_DRIVER_OK ) || +virtio_queue_reset_state (q->tx_vq)) {btw this sounds like you are asking it to reset some state.
Quoted 1 line
Quoted 1 line
hw/net/virtio-net.c static int32_t virtio_net_flush_tx(VirtIONetQueue *q) · line 2632
Quoted 1 line
hw/net/virtio-net.c +0
-0return num_packets;and then
Quoted 7 lines
ret = virtio_net_flush_tx(q); if (ret >= n->tx_burst)will reschedule automatically won't it?
also why check in
virtio_net_flush_txand notvirtio_net_tx_complete?
virtio_net_flush_txmay been called by timer.Quoted 7 lines
Quoted 3 lines
Quoted 1 line
Thanks.
timer won't run while
flush_or_purge_queued_packetsis in progress.Is timer not executed during the VMEXIT process? Otherwise, we still have to consider that after the
flush_or_purge_queued_packets, this process before the structure is cleared.void
virtio_queue_reset(VirtIODevice *vdev, uint32_t queue_index){ VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev); if (k->queue_reset) { k->queue_reset(vdev, queue_index); } __virtio_queue_reset(vdev, queue_index); }No timers do not run between
k->queue_resetand__virtio_queue_reset.
Quoted 7 lines
Quoted 4 lines
Even if it can be processed in
virtio_net_tx_complete, is there any good way? This is a callback, it is not convenient to pass the parameters.Thanks
How about checking that length is 0?
I think that check length is not a good way. This modifys the semantics of 0. It is not friendly to the future maintenance. On the other hand, qemu_net_queue_purge() will pass 0, and this function is called by many places.
How about we add an api in queue.c to replace the sent_cb callback on queue?
Thanks.
Quoted 13 lines
Quoted 12 lines
Quoted 12 lines
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
hw/net/virtio-net.c +0
-1} --2.32.0.3.g01195cf9f
Re: [PATCH v1 2/2] virtio-net: virtio_net_flush_tx() check for per-queue reset
Quoted 121 lines · Xuan Zhuo
Quoted 111 lines · Michael S. Tsirkin
Quoted 85 lines · Xuan Zhuo
Quoted 84 lines · Michael S. Tsirkin
Quoted 83 lines · Xuan Zhuo
Quoted 72 lines · Michael S. Tsirkin
Quoted 25 lines · Xuan Zhuo
Quoted 11 lines · Michael S. Tsirkin
Quoted 6 lines · Xuan Zhuo
Check whether it is per-queue reset state in
virtio_net_flush_tx().Before per-queue reset, we need to recover async tx resources. At this time,
virtio_net_flush_tx()is called, but we should not try to send new packets, sovirtio_net_flush_tx()should check the current per-queue reset state.What does "at this time" mean here?
Do you in fact mean it's called fromflush_or_purge_queued_packets?Yes
virtio_queue_resetk->queue_reset virtio_net_queue_reset flush_or_purge_queued_packets qemu_flush_or_purge_queued_packets ..... (callback) virtio_net_tx_complete virtio_net_flush_tx <-- here send new packet. We need stop it.Quoted 7 lines
Because it is inside the callback, I can't pass information through the stack. I originally thought it was a general situation, so I wanted to put it in struct VirtQueue.
If it is not very suitable, it may be better to put it in VirtIONetQueue.
Thanks.
Hmm maybe. Another idea: isn't
virtio_net_tx_completecalled with length 0 here? Are there other cases where length is 0?Quoted 16 lines
Quoted 16 lines
What does the call stack look like?
If yes introducing a vq state just so
virtio_net_flush_txknows we are in the process of reset would be a bad idea. We want something much more local, ideally on stack even ...Quoted 9 lines
Fixes 7dc6be52 ("virtio-net: support queue reset")Reported-by Alexander Bulekov <[email protected]>Signed-off-by Xuan Zhuo <[email protected]>--- hw/net/virtio-net.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)Quoted 11 lines
Quoted 11 lines
hw/net/virtio-net.c static int32_t virtio_net_flush_tx(VirtIONetQueue *q) · line 2631
Quoted 11 lines
hw/net/virtio-net.c +2
-1@@ -2627,7 +2627,8 @@ static int32_t virtio_net_flush_tx(VirtIONetQueue *q)VirtQueueElement *elem;int32_t num_packets =0 ;int queue_index =vq2q (virtio_get_queue_index (q->tx_vq)); -if (!(vdev->status &VIRTIO_CONFIG_S_DRIVER_OK )) { +if (!(vdev->status &VIRTIO_CONFIG_S_DRIVER_OK ) || +virtio_queue_reset_state (q->tx_vq)) {btw this sounds like you are asking it to reset some state.
Quoted 1 line
Quoted 1 line
hw/net/virtio-net.c static int32_t virtio_net_flush_tx(VirtIONetQueue *q) · line 2632
Quoted 1 line
hw/net/virtio-net.c +0
-0return num_packets;and then
Quoted 7 lines
ret = virtio_net_flush_tx(q); if (ret >= n->tx_burst)will reschedule automatically won't it?
also why check in
virtio_net_flush_txand notvirtio_net_tx_complete?
virtio_net_flush_txmay been called by timer.Quoted 7 lines
Quoted 3 lines
Quoted 1 line
Thanks.
timer won't run while
flush_or_purge_queued_packetsis in progress.Is timer not executed during the VMEXIT process? Otherwise, we still have to consider that after the
flush_or_purge_queued_packets, this process before the structure is cleared.void
virtio_queue_reset(VirtIODevice *vdev, uint32_t queue_index){ VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev); if (k->queue_reset) { k->queue_reset(vdev, queue_index); } __virtio_queue_reset(vdev, queue_index); }No timers do not run between
k->queue_resetand__virtio_queue_reset.Quoted 7 lines
Quoted 4 lines
Even if it can be processed in
virtio_net_tx_complete, is there any good way? This is a callback, it is not convenient to pass the parameters.Thanks
How about checking that length is 0?
Quoted 7 lines
I think that check length is not a good way. This modifys the semantics of 0. It is not friendly to the future maintenance. On the other hand,
qemu_net_queue_purge()will pass 0, and this function is called by many places.How about we add an api in
queue.cto replace thesent_cbcallback on queue?Thanks.
OK I guess. Jason?
Quoted 14 lines
Quoted 14 lines
Quoted 13 lines
Quoted 13 lines
Quoted 12 lines
Quoted 12 lines
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
hw/net/virtio-net.c +0
-1} --2.32.0.3.g01195cf9f
Re: [PATCH v1 2/2] virtio-net: virtio_net_flush_tx() check for per-queue reset
Quoted 83 lines · Michael S. Tsirkin
Quoted 81 lines · Xuan Zhuo
Quoted 80 lines · Michael S. Tsirkin
Quoted 79 lines · Xuan Zhuo
Quoted 78 lines · Michael S. Tsirkin
Quoted 77 lines · Xuan Zhuo
Quoted 76 lines · Michael S. Tsirkin
Quoted 25 lines · Xuan Zhuo
Quoted 11 lines · Michael S. Tsirkin
Quoted 6 lines · Xuan Zhuo
Check whether it is per-queue reset state in
virtio_net_flush_tx().Before per-queue reset, we need to recover async tx resources. At this time,
virtio_net_flush_tx()is called, but we should not try to send new packets, sovirtio_net_flush_tx()should check the current per-queue reset state.What does "at this time" mean here?
Do you in fact mean it's called fromflush_or_purge_queued_packets?Yes
virtio_queue_reset
k->queue_reset
virtio_net_queue_reset
flush_or_purge_queued_packets
qemu_flush_or_purge_queued_packets
.....
(callback)virtio_net_tx_complete
virtio_net_flush_tx<-- here send new packet. We need stop it.Quoted 7 lines
Because it is inside the callback, I can't pass information through the stack. I originally thought it was a general situation, so I wanted to put it in struct VirtQueue.
If it is not very suitable, it may be better to put it in VirtIONetQueue.
Thanks.
Hmm maybe. Another idea: isn't
virtio_net_tx_completecalled with length 0 here? Are there other cases where length is 0?Quoted 16 lines
Quoted 16 lines
What does the call stack look like?
If yes introducing a vq state just so
virtio_net_flush_txknows we are in the process of reset would be a bad idea. We want something much more local, ideally on stack even ...Quoted 9 lines
Fixes 7dc6be52 ("virtio-net: support queue reset")Reported-by Alexander Bulekov <[email protected]>Signed-off-by Xuan Zhuo <[email protected]>--- hw/net/virtio-net.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)Quoted 11 lines
Quoted 11 lines
hw/net/virtio-net.c static int32_t virtio_net_flush_tx(VirtIONetQueue *q) · line 2631
Quoted 11 lines
hw/net/virtio-net.c +2
-1@@ -2627,7 +2627,8 @@ static int32_t virtio_net_flush_tx(VirtIONetQueue *q)VirtQueueElement *elem;int32_t num_packets =0 ;int queue_index =vq2q (virtio_get_queue_index (q->tx_vq)); -if (!(vdev->status &VIRTIO_CONFIG_S_DRIVER_OK )) { +if (!(vdev->status &VIRTIO_CONFIG_S_DRIVER_OK ) || +virtio_queue_reset_state (q->tx_vq)) {btw this sounds like you are asking it to reset some state.
Quoted 1 line
Quoted 1 line
hw/net/virtio-net.c static int32_t virtio_net_flush_tx(VirtIONetQueue *q) · line 2632
Quoted 1 line
hw/net/virtio-net.c +0
-0return num_packets;and then
ret = virtio_net_flush_tx(q); if (ret >= n->tx_burst)
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 3 lines
will reschedule automatically won't it?
also why check in
virtio_net_flush_txand notvirtio_net_tx_complete?
virtio_net_flush_txmay been called by timer.
We stop timer/bh during device reset, do we need to do the same with vq reset?
Quoted 29 lines
Quoted 29 lines
Quoted 29 lines
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
Thanks.
timer won't run while
flush_or_purge_queued_packetsis in progress.Is timer not executed during the VMEXIT process? Otherwise, we still have to consider that after the
flush_or_purge_queued_packets, this process before the structure is cleared.void
virtio_queue_reset(VirtIODevice *vdev, uint32_t queue_index){ VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev); if (k->queue_reset) { k->queue_reset(vdev, queue_index); } __virtio_queue_reset(vdev, queue_index); }No timers do not run between
k->queue_resetand__virtio_queue_reset.Quoted 3 lines
Even if it can be processed in
virtio_net_tx_complete, is there any good way? This is a callback, it is not convenient to pass the parameters.
Quoted 7 lines
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Thanks
How about checking that length is 0?
I think that check length is not a good way. This modifys the semantics of 0.
0 seems to mean "purge" and
Quoted 3 lines
It is
Quoted 2 lines
not friendly to the future maintenance. On the other hand,
qemu_net_queue_purge()will pass 0, and this function is called by many places.
That's exactly what we want actually, when do purge we don't need a flush?
Quoted 6 lines
Quoted 4 lines
How about we add an api in
queue.cto replace thesent_cbcallback on queue?Thanks.
OK I guess. Jason?
Not sure, anything different from adding a check in virtio_net_tx_complete()? (assuming bh and timer is cancelled or deleted).
Thanks
Quoted 16 lines
Quoted 15 lines
Quoted 15 lines
Quoted 14 lines
Quoted 14 lines
Quoted 13 lines
Quoted 13 lines
Quoted 12 lines
Quoted 12 lines
Quoted 11 lines
hw/net/virtio-net.c +0
-1} --2.32.0.3.g01195cf9f
Re: [PATCH v1 2/2] virtio-net: virtio_net_flush_tx() check for per-queue reset
Quoted 129 lines · Jason Wang
Quoted 83 lines · Michael S. Tsirkin
Quoted 81 lines · Xuan Zhuo
Quoted 80 lines · Michael S. Tsirkin
Quoted 79 lines · Xuan Zhuo
Quoted 78 lines · Michael S. Tsirkin
Quoted 77 lines · Xuan Zhuo
Quoted 76 lines · Michael S. Tsirkin
Quoted 25 lines · Xuan Zhuo
Quoted 11 lines · Michael S. Tsirkin
Quoted 6 lines · Xuan Zhuo
Check whether it is per-queue reset state in
virtio_net_flush_tx().Before per-queue reset, we need to recover async tx resources. At this time,
virtio_net_flush_tx()is called, but we should not try to send new packets, sovirtio_net_flush_tx()should check the current per-queue reset state.What does "at this time" mean here?
Do you in fact mean it's called fromflush_or_purge_queued_packets?Yes
virtio_queue_reset
k->queue_reset
virtio_net_queue_reset
flush_or_purge_queued_packets
qemu_flush_or_purge_queued_packets
.....
(callback)virtio_net_tx_complete
virtio_net_flush_tx<-- here send new packet. We need stop it.Quoted 7 lines
Because it is inside the callback, I can't pass information through the stack. I originally thought it was a general situation, so I wanted to put it in struct VirtQueue.
If it is not very suitable, it may be better to put it in VirtIONetQueue.
Thanks.
Hmm maybe. Another idea: isn't
virtio_net_tx_completecalled with length 0 here? Are there other cases where length is 0?Quoted 16 lines
Quoted 16 lines
What does the call stack look like?
If yes introducing a vq state just so
virtio_net_flush_txknows we are in the process of reset would be a bad idea. We want something much more local, ideally on stack even ...Quoted 9 lines
Fixes 7dc6be52 ("virtio-net: support queue reset")Reported-by Alexander Bulekov <[email protected]>Signed-off-by Xuan Zhuo <[email protected]>--- hw/net/virtio-net.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)Quoted 11 lines
Quoted 11 lines
hw/net/virtio-net.c static int32_t virtio_net_flush_tx(VirtIONetQueue *q) · line 2631
Quoted 11 lines
hw/net/virtio-net.c +2
-1@@ -2627,7 +2627,8 @@ static int32_t virtio_net_flush_tx(VirtIONetQueue *q)VirtQueueElement *elem;int32_t num_packets =0 ;int queue_index =vq2q (virtio_get_queue_index (q->tx_vq)); -if (!(vdev->status &VIRTIO_CONFIG_S_DRIVER_OK )) { +if (!(vdev->status &VIRTIO_CONFIG_S_DRIVER_OK ) || +virtio_queue_reset_state (q->tx_vq)) {btw this sounds like you are asking it to reset some state.
Quoted 1 line
Quoted 1 line
hw/net/virtio-net.c static int32_t virtio_net_flush_tx(VirtIONetQueue *q) · line 2632
Quoted 1 line
hw/net/virtio-net.c +0
-0return num_packets;and then
ret = virtio_net_flush_tx(q); if (ret >= n->tx_burst)Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 3 lines
will reschedule automatically won't it?
also why check in
virtio_net_flush_txand notvirtio_net_tx_complete?
virtio_net_flush_txmay been called by timer.We stop timer/bh during device reset, do we need to do the same with vq reset?
Quoted 29 lines
Quoted 29 lines
Quoted 29 lines
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
Thanks.
timer won't run while
flush_or_purge_queued_packetsis in progress.Is timer not executed during the VMEXIT process? Otherwise, we still have to consider that after the
flush_or_purge_queued_packets, this process before the structure is cleared.void
virtio_queue_reset(VirtIODevice *vdev, uint32_t queue_index){ VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev); if (k->queue_reset) { k->queue_reset(vdev, queue_index); } __virtio_queue_reset(vdev, queue_index); }No timers do not run between
k->queue_resetand__virtio_queue_reset.Quoted 3 lines
Even if it can be processed in
virtio_net_tx_complete, is there any good way? This is a callback, it is not convenient to pass the parameters.Quoted 7 lines
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Thanks
How about checking that length is 0?
I think that check length is not a good way. This modifys the semantics of 0.
Quoted 7 lines
0 seems to mean "purge" and
Quoted 3 lines
It is
Quoted 2 lines
not friendly to the future maintenance. On the other hand,
qemu_net_queue_purge()will pass 0, and this function is called by many places.That's exactly what we want actually, when do purge we don't need a flush?
Yes, but I'm not sure. If we stop flush, there will be any other effects.
On the other hand, if we use "0" as a judgment condition, do you mean only the implementation of the purge in the flush_or_purge_queued_packets()?
Quoted 10 lines
Quoted 6 lines
Quoted 6 lines
How about we add an api in
queue.cto replace thesent_cbcallback on queue?Thanks.
Quoted 1 line
OK I guess. Jason?
Not sure, anything different from adding a check in
virtio_net_tx_complete()? (assuming bh and timer is cancelled or deleted).
We replaced the sent_cb with a function without flush.
Thanks.
Quoted 20 lines
Thanks
Quoted 16 lines
Quoted 15 lines
Quoted 15 lines
Quoted 14 lines
Quoted 14 lines
Quoted 13 lines
Quoted 13 lines
Quoted 12 lines
Quoted 12 lines
Quoted 11 lines
hw/net/virtio-net.c +0
-1} --2.32.0.3.g01195cf9f
Re: [PATCH v1 2/2] virtio-net: virtio_net_flush_tx() check for per-queue reset
Quoted 133 lines · Xuan Zhuo
Quoted 131 lines · Jason Wang
Quoted 83 lines · Michael S. Tsirkin
Quoted 81 lines · Xuan Zhuo
Quoted 80 lines · Michael S. Tsirkin
Quoted 79 lines · Xuan Zhuo
Quoted 78 lines · Michael S. Tsirkin
Quoted 77 lines · Xuan Zhuo
Quoted 76 lines · Michael S. Tsirkin
Quoted 25 lines · Xuan Zhuo
Quoted 11 lines · Michael S. Tsirkin
Quoted 6 lines · Xuan Zhuo
Check whether it is per-queue reset state in
virtio_net_flush_tx().Before per-queue reset, we need to recover async tx resources. At this time,
virtio_net_flush_tx()is called, but we should not try to send new packets, sovirtio_net_flush_tx()should check the current per-queue reset state.What does "at this time" mean here?
Do you in fact mean it's called fromflush_or_purge_queued_packets?Yes
virtio_queue_reset
k->queue_reset
virtio_net_queue_reset
flush_or_purge_queued_packets
qemu_flush_or_purge_queued_packets
.....
(callback)virtio_net_tx_complete
virtio_net_flush_tx<-- here send new packet. We need stop it.Quoted 7 lines
Because it is inside the callback, I can't pass information through the stack. I originally thought it was a general situation, so I wanted to put it in struct VirtQueue.
If it is not very suitable, it may be better to put it in VirtIONetQueue.
Thanks.
Hmm maybe. Another idea: isn't
virtio_net_tx_completecalled with length 0 here? Are there other cases where length is 0?Quoted 16 lines
Quoted 16 lines
What does the call stack look like?
If yes introducing a vq state just so
virtio_net_flush_txknows we are in the process of reset would be a bad idea. We want something much more local, ideally on stack even ...Quoted 9 lines
Fixes 7dc6be52 ("virtio-net: support queue reset")Reported-by Alexander Bulekov <[email protected]>Signed-off-by Xuan Zhuo <[email protected]>--- hw/net/virtio-net.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)Quoted 11 lines
Quoted 11 lines
hw/net/virtio-net.c static int32_t virtio_net_flush_tx(VirtIONetQueue *q) · line 2631
Quoted 11 lines
hw/net/virtio-net.c +2
-1@@ -2627,7 +2627,8 @@ static int32_t virtio_net_flush_tx(VirtIONetQueue *q)VirtQueueElement *elem;int32_t num_packets =0 ;int queue_index =vq2q (virtio_get_queue_index (q->tx_vq)); -if (!(vdev->status &VIRTIO_CONFIG_S_DRIVER_OK )) { +if (!(vdev->status &VIRTIO_CONFIG_S_DRIVER_OK ) || +virtio_queue_reset_state (q->tx_vq)) {btw this sounds like you are asking it to reset some state.
Quoted 1 line
Quoted 1 line
hw/net/virtio-net.c static int32_t virtio_net_flush_tx(VirtIONetQueue *q) · line 2632
Quoted 1 line
hw/net/virtio-net.c +0
-0return num_packets;and then
ret = virtio_net_flush_tx(q); if (ret >= n->tx_burst)Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 3 lines
will reschedule automatically won't it?
also why check in
virtio_net_flush_txand notvirtio_net_tx_complete?
virtio_net_flush_txmay been called by timer.We stop timer/bh during device reset, do we need to do the same with vq reset?
Quoted 29 lines
Quoted 29 lines
Quoted 29 lines
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
Thanks.
timer won't run while
flush_or_purge_queued_packetsis in progress.Is timer not executed during the VMEXIT process? Otherwise, we still have to consider that after the
flush_or_purge_queued_packets, this process before the structure is cleared.void
virtio_queue_reset(VirtIODevice *vdev, uint32_t queue_index){ VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev); if (k->queue_reset) { k->queue_reset(vdev, queue_index); } __virtio_queue_reset(vdev, queue_index); }No timers do not run between
k->queue_resetand__virtio_queue_reset.Quoted 3 lines
Even if it can be processed in
virtio_net_tx_complete, is there any good way? This is a callback, it is not convenient to pass the parameters.Quoted 7 lines
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Thanks
How about checking that length is 0?
I think that check length is not a good way. This modifys the semantics of 0.
0 seems to mean "purge" and
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
It is
Quoted 2 lines
not friendly to the future maintenance. On the other hand,
qemu_net_queue_purge()will pass 0, and this function is called by many places.That's exactly what we want actually, when do purge we don't need a flush?
Yes, but I'm not sure. If we stop flush, there will be any other effects.
So we did:
virtio_net_queue_reset():
nc = qemu_get_subqueue(n->nic, vq2q(queue_index);
flush_or_purge_queued_packets(nc);
qemu_flush_or_purge_queued_packets(nc->peer, true); // [1]
if (qemu_net_queue_flush(nc->incoming_queue)) {
....
} else if (purge) {
qemu_net_queue_purge(nc->incoming_queue, nc->peer);
packet->send_cb()
virtio_net_tx_complete()
virtio_net_flush_tx()
qemu_sendv_packet_async() // [2]
}We try to flush the tap's incoming queue and if we fail we will purge in [1]. But the sent_cb() tries to send more packets which could be queued to the tap incoming queue [2]. This breaks the semantic of qemu_flush_or_purge_queued_packets().
Quoted 3 lines
On the other hand, if we use "0" as a judgment condition, do you mean only the implementation of the purge in the
flush_or_purge_queued_packets()?
It should be all the users of qemu_net_queue_purge(). The rest users seems all fine:
virtio_net_vhost_status(), if we do flush, it may end up with touching vring during vhost is running.
filters: all do a flush before.
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
How about we add an api in
queue.cto replace thesent_cbcallback on queue?
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
Quoted 2 lines
Thanks.
Quoted 1 line
OK I guess. Jason?
Not sure, anything different from adding a check in
virtio_net_tx_complete()? (assuming bh and timer is cancelled or deleted).We replaced the
sent_cbwith a function without flush.
I meant it won't be different from adding a
if (virtio_queue_is_rest())
somewhere in virtio_net_tx_complete()?
Thanks
Quoted 25 lines
Thanks.
Quoted 20 lines
Thanks
Quoted 16 lines
Quoted 15 lines
Quoted 15 lines
Quoted 14 lines
Quoted 14 lines
Quoted 13 lines
Quoted 13 lines
Quoted 12 lines
Quoted 12 lines
Quoted 11 lines
hw/net/virtio-net.c +0
-1} --2.32.0.3.g01195cf9f
Re: [PATCH v1 2/2] virtio-net: virtio_net_flush_tx() check for per-queue reset
Quoted 158 lines · Jason Wang
Quoted 133 lines · Xuan Zhuo
Quoted 131 lines · Jason Wang
Quoted 83 lines · Michael S. Tsirkin
Quoted 81 lines · Xuan Zhuo
Quoted 80 lines · Michael S. Tsirkin
Quoted 79 lines · Xuan Zhuo
Quoted 78 lines · Michael S. Tsirkin
Quoted 77 lines · Xuan Zhuo
Quoted 76 lines · Michael S. Tsirkin
Quoted 25 lines · Xuan Zhuo
Quoted 11 lines · Michael S. Tsirkin
Quoted 6 lines · Xuan Zhuo
Check whether it is per-queue reset state in virtio_net_flush_tx().
Before per-queue reset, we need to recover async tx resources. At this
time, virtio_net_flush_tx() is called, but we should not try to send
new packets, so virtio_net_flush_tx() should check the current
per-queue reset state.What does "at this time" mean here?
Do you in fact mean it's called fromflush_or_purge_queued_packets?Yes
virtio_queue_reset
k->queue_reset
virtio_net_queue_reset
flush_or_purge_queued_packets
qemu_flush_or_purge_queued_packets
.....
(callback)virtio_net_tx_complete
virtio_net_flush_tx<-- here send new packet. We need stop it.Quoted 7 lines
Because it is inside the callback, I can't pass information through the stack. I originally thought it was a general situation, so I wanted to put it in struct VirtQueue.
If it is not very suitable, it may be better to put it in VirtIONetQueue.
Thanks.
Hmm maybe. Another idea: isn't
virtio_net_tx_completecalled with length 0 here? Are there other cases where length is 0?Quoted 16 lines
Quoted 16 lines
What does the call stack look like?
If yes introducing a vq state just so
virtio_net_flush_txknows we are in the process of reset would be a bad idea. We want something much more local, ideally on stack even ...Quoted 9 lines
Fixes: 7dc6be52 ("virtio-net: support queue reset")
Fixes: https://gitlab.com/qemu-project/qemu/-/issues/1451
Reported-by: Alexander Bulekov <[email protected]>
Signed-off-by: Xuan Zhuo <[email protected]>
---
hw/net/virtio-net.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
index 3ae909041a..fba6451a50 100644
--- a/hw/net/virtio-net.c
+++ b/hw/net/virtio-net.c
@@ -2627,7 +2627,8 @@ static int32_t virtio_net_flush_tx(VirtIONetQueue *q)
VirtQueueElement *elem;
int32_t num_packets = 0;
int queue_index = vq2q(virtio_get_queue_index(q->tx_vq));
- if (!(vdev->status & VIRTIO_CONFIG_S_DRIVER_OK)) {
+ if (!(vdev->status & VIRTIO_CONFIG_S_DRIVER_OK) ||
+ virtio_queue_reset_state(q->tx_vq)) {btw this sounds like you are asking it to reset some state.
Quoted 1 line
Quoted 1 line
Quoted 1 line
return num_packets;
and then
ret = virtio_net_flush_tx(q); if (ret >= n->tx_burst)Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 3 lines
will reschedule automatically won't it?
also why check in
virtio_net_flush_txand notvirtio_net_tx_complete?
virtio_net_flush_txmay been called by timer.We stop timer/bh during device reset, do we need to do the same with vq reset?
Quoted 29 lines
Quoted 29 lines
Quoted 29 lines
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
Thanks.
timer won't run while
flush_or_purge_queued_packetsis in progress.Is timer not executed during the VMEXIT process? Otherwise, we still have to consider that after the
flush_or_purge_queued_packets, this process before the structure is cleared.void
virtio_queue_reset(VirtIODevice *vdev, uint32_t queue_index){ VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev); if (k->queue_reset) { k->queue_reset(vdev, queue_index); } __virtio_queue_reset(vdev, queue_index); }No timers do not run between
k->queue_resetand__virtio_queue_reset.Quoted 3 lines
Even if it can be processed in
virtio_net_tx_complete, is there any good way? This is a callback, it is not convenient to pass the parameters.Quoted 7 lines
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Thanks
How about checking that length is 0?
I think that check length is not a good way. This modifys the semantics of 0.
0 seems to mean "purge" and
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
It is
Quoted 2 lines
not friendly to the future maintenance. On the other hand,
qemu_net_queue_purge()will pass 0, and this function is called by many places.That's exactly what we want actually, when do purge we don't need a flush?
Yes, but I'm not sure. If we stop flush, there will be any other effects.
So we did:
virtio_net_queue_reset():nc = qemu_get_subqueue(n->nic, vq2q(queue_index); flush_or_purge_queued_packets(nc); qemu_flush_or_purge_queued_packets(nc->peer, true); // [1] if (qemu_net_queue_flush(nc->incoming_queue)) { .... } else if (purge) { qemu_net_queue_purge(nc->incoming_queue, nc->peer); packet->send_cb() virtio_net_tx_complete() virtio_net_flush_tx() qemu_sendv_packet_async() // [2] }
Quoted 4 lines
We try to flush the tap's incoming queue and if we fail we will purge in [1]. But the
sent_cb()tries to send more packets which could be queued to the tap incoming queue [2]. This breaks the semantic ofqemu_flush_or_purge_queued_packets().
Sounds like good news, and I think so too.
Quoted 24 lines
Quoted 4 lines
On the other hand, if we use "0" as a judgment condition, do you mean only the implementation of the purge in the
flush_or_purge_queued_packets()?It should be all the users of
qemu_net_queue_purge(). The rest users seems all fine:
virtio_net_vhost_status(), if we do flush, it may end up with touching vring during vhost is running.
filters: all do a flush before.Quoted 12 lines
Quoted 11 lines
Quoted 7 lines
Quoted 7 lines
How about we add an api in
queue.cto replace thesent_cbcallback on queue?Thanks.
Quoted 1 line
OK I guess. Jason?
Not sure, anything different from adding a check in
virtio_net_tx_complete()? (assuming bh and timer is cancelled or deleted).
Quoted 7 lines
Quoted 1 line
We replaced the
sent_cbwith a function without flush.I meant it won't be different from adding a
if (
virtio_queue_is_rest())somewhere in
virtio_net_tx_complete()?
Only modify on the stack, without using a variable like disabled_by_reset.
Thanks.
Quoted 29 lines
Thanks
Quoted 25 lines
Thanks.
Quoted 20 lines
Thanks
Quoted 16 lines
Quoted 15 lines
Quoted 15 lines
Quoted 14 lines
Quoted 14 lines
Quoted 13 lines
Quoted 13 lines
Quoted 12 lines
Quoted 12 lines
Quoted 11 lines
}
--
2.32.0.3.g01195cf9f
Re: [PATCH v1 2/2] virtio-net: virtio_net_flush_tx() check for per-queue reset
Quoted 193 lines · Xuan Zhuo
Quoted 158 lines · Jason Wang
Quoted 133 lines · Xuan Zhuo
Quoted 131 lines · Jason Wang
Quoted 83 lines · Michael S. Tsirkin
Quoted 81 lines · Xuan Zhuo
Quoted 80 lines · Michael S. Tsirkin
Quoted 79 lines · Xuan Zhuo
Quoted 78 lines · Michael S. Tsirkin
Quoted 77 lines · Xuan Zhuo
Quoted 76 lines · Michael S. Tsirkin
Quoted 25 lines · Xuan Zhuo
Quoted 11 lines · Michael S. Tsirkin
On Sun, Jan 29, 2023 at 10:51:50AM +0800, Xuan Zhuo wrote:
Check whether it is per-queue reset state in virtio_net_flush_tx().Before per-queue reset, we need to recover async tx resources. At this
time, virtio_net_flush_tx() is called, but we should not try to send
new packets, so virtio_net_flush_tx() should check the current
per-queue reset state.What does "at this time" mean here?
Do you in fact mean it's called from flush_or_purge_queued_packets?Yes
virtio_queue_reset
k->queue_reset
virtio_net_queue_reset
flush_or_purge_queued_packets
qemu_flush_or_purge_queued_packets
.....
(callback)virtio_net_tx_complete
virtio_net_flush_tx<-- here send new packet. We need stop it.Quoted 7 lines
Because it is inside the callback, I can't pass information through the stack. I originally thought it was a general situation, so I wanted to put it in struct VirtQueue.
If it is not very suitable, it may be better to put it in VirtIONetQueue.
Thanks.
Hmm maybe. Another idea: isn't
virtio_net_tx_completecalled with length 0 here? Are there other cases where length is 0?Quoted 16 lines
Quoted 16 lines
What does the call stack look like?
If yes introducing a vq state just so virtio_net_flush_tx
knows we are in the process of reset would be a bad idea.
We want something much more local, ideally on stack even ...Fixes: 7dc6be52 ("virtio-net: support queue reset")
Fixes: https://gitlab.com/qemu-project/qemu/-/issues/1451
Reported-by: Alexander Bulekov <[email protected]>
Signed-off-by: Xuan Zhuo <[email protected]>
---
hw/net/virtio-net.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)Quoted 11 lines
Quoted 11 lines
diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
index 3ae909041a..fba6451a50 100644
--- a/hw/net/virtio-net.c
+++ b/hw/net/virtio-net.c
@@ -2627,7 +2627,8 @@ static int32_t virtio_net_flush_tx(VirtIONetQueue *q)
VirtQueueElement *elem;
int32_t num_packets = 0;
int queue_index = vq2q(virtio_get_queue_index(q->tx_vq));
- if (!(vdev->status & VIRTIO_CONFIG_S_DRIVER_OK)) {
+ if (!(vdev->status & VIRTIO_CONFIG_S_DRIVER_OK) ||
+ virtio_queue_reset_state(q->tx_vq)) {btw this sounds like you are asking it to reset some state.
Quoted 1 line
Quoted 1 line
return num_packets;
and then
ret = virtio_net_flush_tx(q); if (ret >= n->tx_burst)Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 3 lines
will reschedule automatically won't it?
also why check in
virtio_net_flush_txand notvirtio_net_tx_complete?
virtio_net_flush_txmay been called by timer.We stop timer/bh during device reset, do we need to do the same with vq reset?
Quoted 29 lines
Quoted 29 lines
Quoted 29 lines
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
Thanks.
timer won't run while
flush_or_purge_queued_packetsis in progress.Is timer not executed during the VMEXIT process? Otherwise, we still have to consider that after the
flush_or_purge_queued_packets, this process before the structure is cleared.void
virtio_queue_reset(VirtIODevice *vdev, uint32_t queue_index){ VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev); if (k->queue_reset) { k->queue_reset(vdev, queue_index); } __virtio_queue_reset(vdev, queue_index); }No timers do not run between
k->queue_resetand__virtio_queue_reset.Quoted 3 lines
Even if it can be processed in
virtio_net_tx_complete, is there any good way? This is a callback, it is not convenient to pass the parameters.Quoted 7 lines
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Thanks
How about checking that length is 0?
I think that check length is not a good way. This modifys the semantics of 0.
0 seems to mean "purge" and
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
It is
Quoted 2 lines
not friendly to the future maintenance. On the other hand,
qemu_net_queue_purge()will pass 0, and this function is called by many places.That's exactly what we want actually, when do purge we don't need a flush?
Yes, but I'm not sure. If we stop flush, there will be any other effects.
So we did:
virtio_net_queue_reset():nc = qemu_get_subqueue(n->nic, vq2q(queue_index); flush_or_purge_queued_packets(nc); qemu_flush_or_purge_queued_packets(nc->peer, true); // [1] if (qemu_net_queue_flush(nc->incoming_queue)) { .... } else if (purge) { qemu_net_queue_purge(nc->incoming_queue, nc->peer); packet->send_cb() virtio_net_tx_complete() virtio_net_flush_tx() qemu_sendv_packet_async() // [2] }Quoted 4 lines
We try to flush the tap's incoming queue and if we fail we will purge in [1]. But the
sent_cb()tries to send more packets which could be queued to the tap incoming queue [2]. This breaks the semantic ofqemu_flush_or_purge_queued_packets().Sounds like good news, and I think so too.
Quoted 26 lines
Quoted 4 lines
On the other hand, if we use "0" as a judgment condition, do you mean only the implementation of the purge in the
flush_or_purge_queued_packets()?It should be all the users of
qemu_net_queue_purge(). The rest users seems all fine:
virtio_net_vhost_status(), if we do flush, it may end up with touching vring during vhost is running.
filters: all do a flush before.Quoted 13 lines
Quoted 11 lines
Quoted 7 lines
Quoted 7 lines
How about we add an api in
queue.cto replace thesent_cbcallback on queue?Thanks.
Quoted 1 line
OK I guess. Jason?
Not sure, anything different from adding a check in
virtio_net_tx_complete()? (assuming bh and timer is cancelled or deleted).We replaced the
sent_cbwith a function without flush.
Quoted 8 lines
Quoted 5 lines
I meant it won't be different from adding a
if (
virtio_queue_is_rest())somewhere in
virtio_net_tx_complete()?Only modify on the stack, without using a variable like
disabled_by_reset.
Ok, but per discussion above, it looks to me we can simply check len against zero which seems simpler. (And it may fix other possible bugs)
Thanks
Quoted 34 lines
Thanks.
Quoted 29 lines
Thanks
Quoted 25 lines
Thanks.
Quoted 20 lines
Thanks
Quoted 16 lines
Quoted 15 lines
Quoted 15 lines
Quoted 14 lines
Quoted 14 lines
Quoted 13 lines
Quoted 13 lines
Quoted 12 lines
Quoted 12 lines
}
--
2.32.0.3.g01195cf9f
Re: [PATCH v1 2/2] virtio-net: virtio_net_flush_tx() check for per-queue reset
Quoted 198 lines · Jason Wang
Quoted 197 lines · Xuan Zhuo
Quoted 158 lines · Jason Wang
Quoted 133 lines · Xuan Zhuo
Quoted 131 lines · Jason Wang
Quoted 83 lines · Michael S. Tsirkin
Quoted 81 lines · Xuan Zhuo
Quoted 80 lines · Michael S. Tsirkin
Quoted 79 lines · Xuan Zhuo
Quoted 78 lines · Michael S. Tsirkin
Quoted 77 lines · Xuan Zhuo
Quoted 76 lines · Michael S. Tsirkin
Quoted 32 lines · Xuan Zhuo
On Sun, 29 Jan 2023 02:25:43 -0500, "Michael S. Tsirkin" <[email protected]> wrote:
On Sun, Jan 29, 2023 at 10:51:50AM +0800, Xuan Zhuo wrote:
Check whether it is per-queue reset state in virtio_net_flush_tx().Before per-queue reset, we need to recover async tx resources. At this
time, virtio_net_flush_tx() is called, but we should not try to send
new packets, so virtio_net_flush_tx() should check the current
per-queue reset state.What does "at this time" mean here?
Do you in fact mean it's called from flush_or_purge_queued_packets?Yes
virtio_queue_reset
k->queue_reset
virtio_net_queue_reset
flush_or_purge_queued_packets
qemu_flush_or_purge_queued_packets
.....
(callback) virtio_net_tx_complete
virtio_net_flush_tx <-- here send new packet. We need stop it.Because it is inside the callback, I can't pass information through the stack. I
originally thought it was a general situation, so I wanted to put it in
struct VirtQueue.If it is not very suitable, it may be better to put it in VirtIONetQueue.
Thanks.
Hmm maybe. Another idea: isn't
virtio_net_tx_completecalled with length 0 here? Are there other cases where length is 0?Quoted 27 lines
What does the call stack look like?
If yes introducing a vq state just so virtio_net_flush_tx
knows we are in the process of reset would be a bad idea.
We want something much more local, ideally on stack even ...Fixes: 7dc6be52 ("virtio-net: support queue reset")
Fixes: https://gitlab.com/qemu-project/qemu/-/issues/1451
Reported-by: Alexander Bulekov <[email protected]>
Signed-off-by: Xuan Zhuo <[email protected]>
---
hw/net/virtio-net.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
index 3ae909041a..fba6451a50 100644
--- a/hw/net/virtio-net.c
+++ b/hw/net/virtio-net.c
@@ -2627,7 +2627,8 @@ static int32_t virtio_net_flush_tx(VirtIONetQueue *q)
VirtQueueElement *elem;
int32_t num_packets = 0;
int queue_index = vq2q(virtio_get_queue_index(q->tx_vq));
- if (!(vdev->status & VIRTIO_CONFIG_S_DRIVER_OK)) {
+ if (!(vdev->status & VIRTIO_CONFIG_S_DRIVER_OK) ||
+ virtio_queue_reset_state(q->tx_vq)) {btw this sounds like you are asking it to reset some state.
Quoted 1 line
return num_packets;
and then
ret = virtio_net_flush_tx(q); if (ret >= n->tx_burst)Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 3 lines
will reschedule automatically won't it?
also why check in
virtio_net_flush_txand notvirtio_net_tx_complete?
virtio_net_flush_txmay been called by timer.We stop timer/bh during device reset, do we need to do the same with vq reset?
Quoted 29 lines
Quoted 29 lines
Quoted 29 lines
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
Thanks.
timer won't run while
flush_or_purge_queued_packetsis in progress.Is timer not executed during the VMEXIT process? Otherwise, we still have to consider that after the
flush_or_purge_queued_packets, this process before the structure is cleared.void
virtio_queue_reset(VirtIODevice *vdev, uint32_t queue_index){ VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev); if (k->queue_reset) { k->queue_reset(vdev, queue_index); } __virtio_queue_reset(vdev, queue_index); }No timers do not run between
k->queue_resetand__virtio_queue_reset.Quoted 3 lines
Even if it can be processed in
virtio_net_tx_complete, is there any good way? This is a callback, it is not convenient to pass the parameters.Quoted 7 lines
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Thanks
How about checking that length is 0?
I think that check length is not a good way. This modifys the semantics of 0.
0 seems to mean "purge" and
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
It is
Quoted 2 lines
not friendly to the future maintenance. On the other hand,
qemu_net_queue_purge()will pass 0, and this function is called by many places.That's exactly what we want actually, when do purge we don't need a flush?
Yes, but I'm not sure. If we stop flush, there will be any other effects.
So we did:
virtio_net_queue_reset():nc = qemu_get_subqueue(n->nic, vq2q(queue_index); flush_or_purge_queued_packets(nc); qemu_flush_or_purge_queued_packets(nc->peer, true); // [1] if (qemu_net_queue_flush(nc->incoming_queue)) { .... } else if (purge) { qemu_net_queue_purge(nc->incoming_queue, nc->peer); packet->send_cb() virtio_net_tx_complete() virtio_net_flush_tx() qemu_sendv_packet_async() // [2] }Quoted 4 lines
We try to flush the tap's incoming queue and if we fail we will purge in [1]. But the
sent_cb()tries to send more packets which could be queued to the tap incoming queue [2]. This breaks the semantic ofqemu_flush_or_purge_queued_packets().Sounds like good news, and I think so too.
Quoted 30 lines
Quoted 4 lines
On the other hand, if we use "0" as a judgment condition, do you mean only the implementation of the purge in the
flush_or_purge_queued_packets()?It should be all the users of
qemu_net_queue_purge(). The rest users seems all fine:
virtio_net_vhost_status(), if we do flush, it may end up with touching vring during vhost is running.
filters: all do a flush before.Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
How about we add an api in
queue.cto replace thesent_cbcallback on queue?Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
Quoted 2 lines
Thanks.
Quoted 1 line
OK I guess. Jason?
Not sure, anything different from adding a check in
virtio_net_tx_complete()? (assuming bh and timer is cancelled or deleted).We replaced the
sent_cbwith a function without flush.I meant it won't be different from adding a
if (
virtio_queue_is_rest())
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
somewhere in
virtio_net_tx_complete()?Only modify on the stack, without using a variable like
disabled_by_reset.Ok, but per discussion above, it looks to me we can simply check len against zero which seems simpler. (And it may fix other possible bugs)
Yes, if '0' means purge and we should not flush new packet for purge, that is a good way.
I will post patch soon.
Thanks.
Quoted 38 lines
Thanks
Quoted 34 lines
Thanks.
Quoted 29 lines
Thanks
Quoted 25 lines
Thanks.
Quoted 20 lines
Thanks
Quoted 16 lines
Quoted 15 lines
Quoted 15 lines
Quoted 14 lines
Quoted 14 lines
Quoted 13 lines
Quoted 13 lines
Quoted 12 lines
}
--
2.32.0.3.g01195cf9f
Re: [PATCH v1 2/2] virtio-net: virtio_net_flush_tx() check for per-queue reset
In reply to Jason WangQuoted 84 lines · Jason Wang
Quoted 83 lines · Michael S. Tsirkin
Quoted 81 lines · Xuan Zhuo
Quoted 80 lines · Michael S. Tsirkin
Quoted 79 lines · Xuan Zhuo
Quoted 78 lines · Michael S. Tsirkin
Quoted 77 lines · Xuan Zhuo
Quoted 76 lines · Michael S. Tsirkin
Quoted 25 lines · Xuan Zhuo
Quoted 11 lines · Michael S. Tsirkin
Quoted 6 lines · Xuan Zhuo
Check whether it is per-queue reset state in
virtio_net_flush_tx().Before per-queue reset, we need to recover async tx resources. At this time,
virtio_net_flush_tx()is called, but we should not try to send new packets, sovirtio_net_flush_tx()should check the current per-queue reset state.What does "at this time" mean here?
Do you in fact mean it's called fromflush_or_purge_queued_packets?Yes
virtio_queue_reset
k->queue_reset
virtio_net_queue_reset
flush_or_purge_queued_packets
qemu_flush_or_purge_queued_packets
.....
(callback)virtio_net_tx_complete
virtio_net_flush_tx<-- here send new packet. We need stop it.Quoted 7 lines
Because it is inside the callback, I can't pass information through the stack. I originally thought it was a general situation, so I wanted to put it in struct VirtQueue.
If it is not very suitable, it may be better to put it in VirtIONetQueue.
Thanks.
Hmm maybe. Another idea: isn't
virtio_net_tx_completecalled with length 0 here? Are there other cases where length is 0?Quoted 16 lines
Quoted 16 lines
What does the call stack look like?
If yes introducing a vq state just so
virtio_net_flush_txknows we are in the process of reset would be a bad idea. We want something much more local, ideally on stack even ...Quoted 9 lines
Fixes 7dc6be52 ("virtio-net: support queue reset")Reported-by Alexander Bulekov <[email protected]>Signed-off-by Xuan Zhuo <[email protected]>--- hw/net/virtio-net.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)Quoted 11 lines
Quoted 11 lines
hw/net/virtio-net.c static int32_t virtio_net_flush_tx(VirtIONetQueue *q) · line 2631
Quoted 11 lines
hw/net/virtio-net.c +2
-1@@ -2627,7 +2627,8 @@ static int32_t virtio_net_flush_tx(VirtIONetQueue *q)VirtQueueElement *elem;int32_t num_packets =0 ;int queue_index =vq2q (virtio_get_queue_index (q->tx_vq)); -if (!(vdev->status &VIRTIO_CONFIG_S_DRIVER_OK )) { +if (!(vdev->status &VIRTIO_CONFIG_S_DRIVER_OK ) || +virtio_queue_reset_state (q->tx_vq)) {btw this sounds like you are asking it to reset some state.
Quoted 1 line
Quoted 1 line
hw/net/virtio-net.c static int32_t virtio_net_flush_tx(VirtIONetQueue *q) · line 2632
Quoted 1 line
hw/net/virtio-net.c +0
-0return num_packets;and then
ret = virtio_net_flush_tx(q); if (ret >= n->tx_burst)
Quoted 7 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 3 lines
will reschedule automatically won't it?
also why check in
virtio_net_flush_txand notvirtio_net_tx_complete?
virtio_net_flush_txmay been called by timer.We stop timer/bh during device reset, do we need to do the same with vq reset?
Should I stop timer/bh?
Thanks.
Quoted 76 lines
Quoted 30 lines
Quoted 30 lines
Quoted 30 lines
Quoted 9 lines
Quoted 5 lines
Quoted 3 lines
Thanks.
timer won't run while
flush_or_purge_queued_packetsis in progress.Is timer not executed during the VMEXIT process? Otherwise, we still have to consider that after the
flush_or_purge_queued_packets, this process before the structure is cleared.void
virtio_queue_reset(VirtIODevice *vdev, uint32_t queue_index){ VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev); if (k->queue_reset) { k->queue_reset(vdev, queue_index); } __virtio_queue_reset(vdev, queue_index); }No timers do not run between
k->queue_resetand__virtio_queue_reset.Quoted 3 lines
Even if it can be processed in
virtio_net_tx_complete, is there any good way? This is a callback, it is not convenient to pass the parameters.Quoted 7 lines
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Thanks
How about checking that length is 0?
I think that check length is not a good way. This modifys the semantics of 0.
0 seems to mean "purge" and
Quoted 3 lines
It is
Quoted 2 lines
not friendly to the future maintenance. On the other hand,
qemu_net_queue_purge()will pass 0, and this function is called by many places.That's exactly what we want actually, when do purge we don't need a flush?
Quoted 6 lines
Quoted 4 lines
How about we add an api in
queue.cto replace thesent_cbcallback on queue?Thanks.
OK I guess. Jason?
Not sure, anything different from adding a check in
virtio_net_tx_complete()? (assuming bh and timer is cancelled or deleted).Thanks
Quoted 16 lines
Quoted 15 lines
Quoted 15 lines
Quoted 14 lines
Quoted 14 lines
Quoted 13 lines
Quoted 13 lines
Quoted 12 lines
Quoted 12 lines
Quoted 11 lines
hw/net/virtio-net.c +0
-1} --2.32.0.3.g01195cf9f
Quoted 15 lines · Xuan Zhuo
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/1451Before 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.
Quoted 4 lines
assert(!virtio_net_get_subqueue(nc)->async_tx.elem);This patch set introduce new item "reset" into struct VirtQueue, then device can know this virtqueue is per-queue reset state.
Better but I still don't exacctly understand what this state means. Sent some questions on the patches themselves.
Thanks!
Quoted 15 lines
v1:
1. rename "reset" todisabled_by_reset
2. add api:virtio_queue_reset_state()Xuan Zhuo (2):
virtio: struct VirtQueue introduce reset
virtio-net:virtio_net_flush_tx()check for per-queue resethw/net/virtio-net.c | 3 ++- hw/virtio/virtio.c | 15 +++++++++++++++ include/hw/virtio/virtio.h | 1 + 3 files changed, 18 insertions(+), 1 deletion(-)--
2.32.0.3.g01195cf9f