[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC v3 12/29] vhost: add vhost_kernel_vring_pause
From: |
Eugenio Pérez |
Subject: |
[RFC v3 12/29] vhost: add vhost_kernel_vring_pause |
Date: |
Wed, 19 May 2021 18:28:46 +0200 |
This is just a commit to allow the testing with vhost-net, not intended
for the final version or any other device.
vhost_kernel_vring_pause stops the device, so qemu can ask for its status
(next available idx the device was going to consume) and to replace
vring addresses. When SVQ starts it can resume consuming the guest's
driver ring, without notice from the latter. Not stopping the device
before of the swapping could imply that it process more buffers than
reported, what would duplicate the device action.
Mimic vhost-vdpa behavior, vhost_kernel_start is intended to resume the
device. In the former it performs a full reset. Since this is a
temporary commit to allow testing with vhost-net, the latter just set a
new backend, that is enough for vhost-net to realize the new vring
addresses.
Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
---
hw/virtio/vhost-backend.c | 42 +++++++++++++++++++++++++++++++++++++++
1 file changed, 42 insertions(+)
diff --git a/hw/virtio/vhost-backend.c b/hw/virtio/vhost-backend.c
index 31b33bde37..9653b7fddb 100644
--- a/hw/virtio/vhost-backend.c
+++ b/hw/virtio/vhost-backend.c
@@ -201,6 +201,46 @@ static int vhost_kernel_get_vq_index(struct vhost_dev
*dev, int idx)
return idx - dev->vq_index;
}
+static int vhost_kernel_set_vq_pause(struct vhost_dev *dev, unsigned idx,
+ bool pause)
+{
+ struct vhost_vring_file file = {
+ .index = idx,
+ };
+
+ if (pause) {
+ file.fd = -1; /* Pass -1 to unbind from file. */
+ } else {
+ struct vhost_net *vn_dev = container_of(dev, struct vhost_net, dev);
+ file.fd = vn_dev->backend;
+ }
+
+ return vhost_kernel_net_set_backend(dev, &file);
+}
+
+static int vhost_kernel_vring_pause(struct vhost_dev *dev)
+{
+ int i;
+
+ for (i = 0; i < dev->nvqs; ++i) {
+ vhost_kernel_set_vq_pause(dev, i, true);
+ }
+
+ return 0;
+}
+
+static int vhost_kernel_start(struct vhost_dev *dev, bool start)
+{
+ int i;
+
+ assert(start);
+ for (i = 0; i < dev->nvqs; ++i) {
+ vhost_kernel_set_vq_pause(dev, i, false);
+ }
+
+ return 0;
+}
+
#ifdef CONFIG_VHOST_VSOCK
static int vhost_kernel_vsock_set_guest_cid(struct vhost_dev *dev,
uint64_t guest_cid)
@@ -317,6 +357,8 @@ static const VhostOps kernel_ops = {
.vhost_set_owner = vhost_kernel_set_owner,
.vhost_reset_device = vhost_kernel_reset_device,
.vhost_get_vq_index = vhost_kernel_get_vq_index,
+ .vhost_dev_start = vhost_kernel_start,
+ .vhost_vring_pause = vhost_kernel_vring_pause,
#ifdef CONFIG_VHOST_VSOCK
.vhost_vsock_set_guest_cid = vhost_kernel_vsock_set_guest_cid,
.vhost_vsock_set_running = vhost_kernel_vsock_set_running,
--
2.27.0
- Re: [RFC v3 04/29] vhost: Add x-vhost-enable-shadow-vq qmp, (continued)
- [RFC v3 06/29] virtio-net: Honor VIRTIO_CONFIG_S_DEVICE_STOPPED, Eugenio Pérez, 2021/05/19
- [RFC v3 07/29] vhost: Route guest->host notification through shadow virtqueue, Eugenio Pérez, 2021/05/19
- [RFC v3 08/29] vhost: Route host->guest notification through shadow virtqueue, Eugenio Pérez, 2021/05/19
- [RFC v3 09/29] vhost: Avoid re-set masked notifier in shadow vq, Eugenio Pérez, 2021/05/19
- [RFC v3 10/29] virtio: Add vhost_shadow_vq_get_vring_addr, Eugenio Pérez, 2021/05/19
- [RFC v3 11/29] vhost: Add vhost_vring_pause operation, Eugenio Pérez, 2021/05/19
- [RFC v3 12/29] vhost: add vhost_kernel_vring_pause,
Eugenio Pérez <=
- [RFC v3 13/29] vhost: Add vhost_get_iova_range operation, Eugenio Pérez, 2021/05/19
- [RFC v3 14/29] vhost: add vhost_has_limited_iova_range, Eugenio Pérez, 2021/05/19
- [RFC v3 15/29] vhost: Add enable_custom_iommu to VhostOps, Eugenio Pérez, 2021/05/19
- [RFC v3 16/29] vhost-vdpa: Add vhost_vdpa_enable_custom_iommu, Eugenio Pérez, 2021/05/19
- [RFC v3 17/29] vhost: Shadow virtqueue buffers forwarding, Eugenio Pérez, 2021/05/19
- [RFC v3 18/29] vhost: Use vhost_enable_custom_iommu to unmap everything if available, Eugenio Pérez, 2021/05/19