[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 46/86] vhost-net: vhost-kernel: introduce vhost_net_virtqueue_rest
From: |
Michael S. Tsirkin |
Subject: |
[PULL 46/86] vhost-net: vhost-kernel: introduce vhost_net_virtqueue_restart() |
Date: |
Mon, 31 Oct 2022 08:52:54 -0400 |
From: Kangjie Xu <kangjie.xu@linux.alibaba.com>
Introduce vhost_net_virtqueue_restart(), which can restart the
specific virtqueue when the vhost net started running before.
If it fails to restart the virtqueue, the device will be stopped.
Here we do not reuse vhost_net_start_one() or vhost_dev_start()
because they work at queue pair level. The mem table and features
do not change, so we can call the vhost_virtqueue_start() to
restart a specific queue.
This patch only considers the case of vhost-kernel, when
NetClientDriver is NET_CLIENT_DRIVER_TAP.
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>
Message-Id: <20221017092558.111082-11-xuanzhuo@linux.alibaba.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
include/net/vhost_net.h | 2 ++
hw/net/vhost_net-stub.c | 6 +++++
hw/net/vhost_net.c | 53 +++++++++++++++++++++++++++++++++++++++++
3 files changed, 61 insertions(+)
diff --git a/include/net/vhost_net.h b/include/net/vhost_net.h
index 85d85a4957..40b9a40074 100644
--- a/include/net/vhost_net.h
+++ b/include/net/vhost_net.h
@@ -50,4 +50,6 @@ int vhost_net_set_mtu(struct vhost_net *net, uint16_t mtu);
void vhost_net_virtqueue_reset(VirtIODevice *vdev, NetClientState *nc,
int vq_index);
+int vhost_net_virtqueue_restart(VirtIODevice *vdev, NetClientState *nc,
+ int vq_index);
#endif
diff --git a/hw/net/vhost_net-stub.c b/hw/net/vhost_net-stub.c
index 2d745e359c..9f7daae99c 100644
--- a/hw/net/vhost_net-stub.c
+++ b/hw/net/vhost_net-stub.c
@@ -107,3 +107,9 @@ void vhost_net_virtqueue_reset(VirtIODevice *vdev,
NetClientState *nc,
{
}
+
+int vhost_net_virtqueue_restart(VirtIODevice *vdev, NetClientState *nc,
+ int vq_index)
+{
+ return 0;
+}
diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c
index 519dced899..f2ada02781 100644
--- a/hw/net/vhost_net.c
+++ b/hw/net/vhost_net.c
@@ -34,6 +34,7 @@
#include "standard-headers/linux/virtio_ring.h"
#include "hw/virtio/vhost.h"
#include "hw/virtio/virtio-bus.h"
+#include "linux-headers/linux/vhost.h"
/* Features supported by host kernel. */
@@ -556,3 +557,55 @@ void vhost_net_virtqueue_reset(VirtIODevice *vdev,
NetClientState *nc,
net->dev.vqs + idx,
net->dev.vq_index + idx);
}
+
+int vhost_net_virtqueue_restart(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 = { };
+ int idx, r;
+
+ if (!net->dev.started) {
+ return -EBUSY;
+ }
+
+ /* should only be called after backend is connected */
+ assert(vhost_ops);
+
+ idx = vhost_ops->vhost_get_vq_index(&net->dev, vq_index);
+
+ r = vhost_virtqueue_start(&net->dev,
+ vdev,
+ net->dev.vqs + idx,
+ net->dev.vq_index + idx);
+ if (r < 0) {
+ goto err_start;
+ }
+
+ if (net->nc->info->type == NET_CLIENT_DRIVER_TAP) {
+ file.index = idx;
+ file.fd = net->backend;
+ r = vhost_net_set_backend(&net->dev, &file);
+ if (r < 0) {
+ r = -errno;
+ goto err_start;
+ }
+ }
+
+ return 0;
+
+err_start:
+ error_report("Error when restarting the queue.");
+
+ if (net->nc->info->type == NET_CLIENT_DRIVER_TAP) {
+ file.fd = VHOST_FILE_UNBIND;
+ file.index = idx;
+ int r = vhost_net_set_backend(&net->dev, &file);
+ assert(r >= 0);
+ }
+
+ vhost_dev_stop(&net->dev, vdev);
+
+ return r;
+}
--
MST
- [PULL 38/86] virtio: introduce virtio_queue_reset(), (continued)
- [PULL 38/86] virtio: introduce virtio_queue_reset(), Michael S. Tsirkin, 2022/10/31
- [PULL 28/86] hw/mem/cxl-type3: Add MSIX support, Michael S. Tsirkin, 2022/10/31
- [PULL 34/86] vhost-user: Support vhost_dev_start, Michael S. Tsirkin, 2022/10/31
- [PULL 39/86] virtio: introduce virtio_queue_enable(), Michael S. Tsirkin, 2022/10/31
- [PULL 40/86] virtio: core: vq reset feature negotation support, Michael S. Tsirkin, 2022/10/31
- [PULL 41/86] virtio-pci: support queue reset, Michael S. Tsirkin, 2022/10/31
- [PULL 42/86] virtio-pci: support queue enable, Michael S. Tsirkin, 2022/10/31
- [PULL 43/86] vhost: expose vhost_virtqueue_start(), Michael S. Tsirkin, 2022/10/31
- [PULL 44/86] vhost: expose vhost_virtqueue_stop(), Michael S. Tsirkin, 2022/10/31
- [PULL 45/86] vhost-net: vhost-kernel: introduce vhost_net_virtqueue_reset(), Michael S. Tsirkin, 2022/10/31
- [PULL 46/86] vhost-net: vhost-kernel: introduce vhost_net_virtqueue_restart(),
Michael S. Tsirkin <=
- [PULL 47/86] virtio-net: introduce flush_or_purge_queued_packets(), Michael S. Tsirkin, 2022/10/31
- [PULL 49/86] virtio-net: support queue_enable, Michael S. Tsirkin, 2022/10/31
- [PULL 48/86] virtio-net: support queue reset, Michael S. Tsirkin, 2022/10/31
- [PULL 51/86] virtio-net: enable vq reset feature, Michael S. Tsirkin, 2022/10/31
- [PULL 50/86] vhost: vhost-kernel: enable vq reset feature, Michael S. Tsirkin, 2022/10/31
- [PULL 52/86] virtio-rng-pci: Allow setting nvectors, so we can use MSI-X, Michael S. Tsirkin, 2022/10/31
- [PULL 53/86] vhost-user: Fix out of order vring host notification handling, Michael S. Tsirkin, 2022/10/31
- [PULL 54/86] acpi: pc: vga: use AcpiDevAmlIf interface to build VGA device descriptors, Michael S. Tsirkin, 2022/10/31
- [PULL 55/86] tests: acpi: whitelist DSDT before generating PCI-ISA bridge AML automatically, Michael S. Tsirkin, 2022/10/31
- [PULL 56/86] acpi: pc/q35: drop ad-hoc PCI-ISA bridge AML routines and let bus ennumeration generate AML, Michael S. Tsirkin, 2022/10/31