在 2022/9/12 01:22, Kangjie Xu 写道:
> From: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
>
> virtio-net and vhost-kernel implement queue reset.
> Queued packets in the corresponding queue pair are flushed
> or purged.
>
> For virtio-net, userspace datapath will be disabled later in
> __virtio_queue_reset(). It will set addr of vring to 0 and idx to 0.
> Thus, virtio_net_receive() and virtio_net_flush_tx() will not receive
> or send packets.
>
> For vhost-net, the datapath will be disabled in vhost_net_virtqueue_reset().
>
> Signed-off-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
> Signed-off-by: Kangjie Xu <kangjie.xu@linux.alibaba.com>
Acked-by: Jason Wang <jasowang@redhat.com>
> ---
> hw/net/virtio-net.c | 18 ++++++++++++++++++
> 1 file changed, 18 insertions(+)
>
> diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
> index 27b59c0ad6..d774a3e652 100644
> --- a/hw/net/virtio-net.c
> +++ b/hw/net/virtio-net.c
> @@ -540,6 +540,23 @@ static RxFilterInfo *virtio_net_query_rxfilter(NetClientState *nc)
> return info;
> }
>
> +static void virtio_net_queue_reset(VirtIODevice *vdev, uint32_t queue_index)
> +{
> + VirtIONet *n = VIRTIO_NET(vdev);
> + NetClientState *nc = qemu_get_subqueue(n->nic, vq2q(queue_index));
> +
> + if (!nc->peer) {
> + return;
> + }
> +
> + if (get_vhost_net(nc->peer) &&
> + nc->peer->info->type == NET_CLIENT_DRIVER_TAP) {
> + vhost_net_virtqueue_reset(vdev, nc, queue_index);
> + }
> +
> + flush_or_purge_queued_packets(nc);
> +}
> +
> static void virtio_net_reset(VirtIODevice *vdev)
> {
> VirtIONet *n = VIRTIO_NET(vdev);
> @@ -3784,6 +3801,7 @@ static void virtio_net_class_init(ObjectClass *klass, void *data)
> vdc->set_features = virtio_net_set_features;
> vdc->bad_features = virtio_net_bad_features;
> vdc->reset = virtio_net_reset;
> + vdc->queue_reset = virtio_net_queue_reset;
> vdc->set_status = virtio_net_set_status;
> vdc->guest_notifier_mask = virtio_net_guest_notifier_mask;
> vdc->guest_notifier_pending = virtio_net_guest_notifier_pending;