Introduce vhost_dev_virtqueue_restart(), which can restart the virtqueue when the vhost has already started running.
Meanwhile, vhost_dev_virtqueue_release(), which can ummap the vrings and the desc of a specific vq of a device. Combining the two functions, we can reset a virtqueue with a started vhost. Signed-off-by: Kangjie Xu <kangjie...@linux.alibaba.com> Signed-off-by: Xuan Zhuo <xuanz...@linux.alibaba.com> --- hw/virtio/vhost.c | 29 +++++++++++++++++++++++++++++ include/hw/virtio/vhost.h | 6 ++++++ 2 files changed, 35 insertions(+) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index e467dfc7bc..d158d71866 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -1904,3 +1904,32 @@ int vhost_net_set_backend(struct vhost_dev *hdev, return -ENOSYS; } + +void vhost_dev_virtqueue_release(struct vhost_dev *hdev, VirtIODevice *vdev, + int vq_index) +{ + int idx = vq_index - hdev->vq_index; + + idx = hdev->vhost_ops->vhost_get_vq_index(hdev, idx); + + vhost_virtqueue_unmap(hdev, + vdev, + hdev->vqs + idx, + hdev->vq_index + idx); +} + +int vhost_dev_virtqueue_restart(struct vhost_dev *hdev, VirtIODevice *vdev, + int vq_index) +{ + int idx = vq_index - hdev->vq_index; + int r = 0; + + idx = hdev->vhost_ops->vhost_get_vq_index(hdev, idx); + + r = vhost_virtqueue_start(hdev, + vdev, + hdev->vqs + idx, + hdev->vq_index + idx); + + return r; +} diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h index a346f23d13..7df7dbe24d 100644 --- a/include/hw/virtio/vhost.h +++ b/include/hw/virtio/vhost.h @@ -277,6 +277,12 @@ bool vhost_has_free_slot(void); int vhost_net_set_backend(struct vhost_dev *hdev, struct vhost_vring_file *file); + +void vhost_dev_virtqueue_release(struct vhost_dev *hdev, VirtIODevice *vdev, + int vq_index); +int vhost_dev_virtqueue_restart(struct vhost_dev *hdev, VirtIODevice *vdev, + int vq_index); + int vhost_device_iotlb_miss(struct vhost_dev *dev, uint64_t iova, int write); void vhost_dev_reset_inflight(struct vhost_inflight *inflight); -- 2.32.0