[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v5 10/15] vhost-net: vhost-kernel: introduce vhost_net_virtqueue_
From: |
Xuan Zhuo |
Subject: |
[PATCH v5 10/15] vhost-net: vhost-kernel: introduce vhost_net_virtqueue_reset() |
Date: |
Wed, 14 Sep 2022 12:20:50 +0800 |
From: Kangjie Xu <kangjie.xu@linux.alibaba.com>
Introduce vhost_virtqueue_reset(), which can reset the specific
virtqueue in the device. Then it will unmap vrings and the desc
of the virtqueue.
Here we do not reuse the vhost_net_stop_one() or vhost_dev_stop(),
because they work at queue pair level. We do not use
vhost_virtqueue_stop() because it may stop the device in the
backend.
This patch only considers the case of vhost-kernel, when
NetClientDriver is NET_CLIENT_DRIVER_TAP.
Furthermore, we do not need net->nc->info->poll() because
it enables userspace datapath and we want to stop all
datapaths for this reset virtqueue here.
Signed-off-by: Kangjie Xu <kangjie.xu@linux.alibaba.com>
Signed-off-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
Acked-by: Jason Wang <jasowang@redhat.com>
---
hw/net/vhost_net.c | 25 +++++++++++++++++++++++++
include/net/vhost_net.h | 2 ++
2 files changed, 27 insertions(+)
diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c
index d28f8b974b..8beecb4d22 100644
--- a/hw/net/vhost_net.c
+++ b/hw/net/vhost_net.c
@@ -531,3 +531,28 @@ int vhost_net_set_mtu(struct vhost_net *net, uint16_t mtu)
return vhost_ops->vhost_net_set_mtu(&net->dev, mtu);
}
+
+void vhost_net_virtqueue_reset(VirtIODevice *vdev, NetClientState *nc,
+ int vq_index)
+{
+ VHostNetState *net = get_vhost_net(nc->peer);
+ const VhostOps *vhost_ops = net->dev.vhost_ops;
+ struct vhost_vring_file file = { .fd = -1 };
+ int idx;
+
+ /* should only be called after backend is connected */
+ assert(vhost_ops);
+
+ idx = vhost_ops->vhost_get_vq_index(&net->dev, vq_index);
+
+ if (net->nc->info->type == NET_CLIENT_DRIVER_TAP) {
+ file.index = idx;
+ int r = vhost_net_set_backend(&net->dev, &file);
+ assert(r >= 0);
+ }
+
+ vhost_virtqueue_stop(&net->dev,
+ vdev,
+ net->dev.vqs + idx,
+ net->dev.vq_index + idx);
+}
diff --git a/include/net/vhost_net.h b/include/net/vhost_net.h
index 387e913e4e..85d85a4957 100644
--- a/include/net/vhost_net.h
+++ b/include/net/vhost_net.h
@@ -48,4 +48,6 @@ uint64_t vhost_net_get_acked_features(VHostNetState *net);
int vhost_net_set_mtu(struct vhost_net *net, uint16_t mtu);
+void vhost_net_virtqueue_reset(VirtIODevice *vdev, NetClientState *nc,
+ int vq_index);
#endif
--
2.32.0.3.g01195cf9f
- [PATCH v5 00/15] Support VIRTIO_F_RING_RESET for virtio-net, vhost-net kernel in virtio pci-modern, Xuan Zhuo, 2022/09/14
- [PATCH v5 12/15] virtio-net: introduce flush_or_purge_queued_packets(), Xuan Zhuo, 2022/09/14
- [PATCH v5 10/15] vhost-net: vhost-kernel: introduce vhost_net_virtqueue_reset(),
Xuan Zhuo <=
- [PATCH v5 03/15] virtio: introduce virtio_queue_reset(), Xuan Zhuo, 2022/09/14
- [PATCH v5 09/15] vhost: expose vhost_virtqueue_stop(), Xuan Zhuo, 2022/09/14
- [PATCH v5 08/15] vhost: expose vhost_virtqueue_start(), Xuan Zhuo, 2022/09/14
- [PATCH v5 15/15] vhost: vhost-kernel: enable vq reset feature, Xuan Zhuo, 2022/09/14
- [PATCH v5 07/15] virtio-pci: support queue enable, Xuan Zhuo, 2022/09/14
- [PATCH v5 01/15] virtio: sync relevant definitions with linux, Xuan Zhuo, 2022/09/14
- [PATCH v5 14/15] virtio-net: support queue_enable, Xuan Zhuo, 2022/09/14
- [PATCH v5 05/15] virtio: core: vq reset feature negotation support, Xuan Zhuo, 2022/09/14
- [PATCH v5 02/15] virtio: introduce __virtio_queue_reset(), Xuan Zhuo, 2022/09/14