Add support for the VDUSE_F_SUSPEND feature. The suspend feature allows the driver to stop the device from processing the virtqueues. This ensures that the virtqueue state can be fetched reliably in a live migration.
Signed-off-by: Eugenio Pérez <[email protected]> --- lib/vhost/vduse.c | 42 +++++++++++++++++++++++++++++++++++++++++- lib/vhost/vhost.h | 1 + 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/lib/vhost/vduse.c b/lib/vhost/vduse.c index 8f45e905b4b4..99d7102425ff 100644 --- a/lib/vhost/vduse.c +++ b/lib/vhost/vduse.c @@ -46,7 +46,8 @@ static const char * const vduse_reqs_str[] = { (id < RTE_DIM(vduse_reqs_str) ? \ vduse_reqs_str[id] : "Unknown") -static const uint64_t supported_vduse_features = RTE_BIT64(VDUSE_F_QUEUE_READY); +static const uint64_t supported_vduse_features = + RTE_BIT64(VDUSE_F_QUEUE_READY) | RTE_BIT64(VDUSE_F_SUSPEND); static uint64_t vduse_vq_to_group(struct virtio_net *dev, struct vhost_virtqueue *vq) { @@ -416,6 +417,7 @@ vduse_device_stop(struct virtio_net *dev) vhost_destroy_device_notify(dev); dev->flags &= ~VIRTIO_DEV_READY; + dev->vduse_suspended = false; for (i = 0; i < dev->nr_vring; i++) vduse_vring_cleanup(dev, i); @@ -537,6 +539,12 @@ vduse_events_handler(int fd, void *arg, int *close __rte_unused) resp.result = VDUSE_REQ_RESULT_FAILED; break; } + if (dev->vduse_suspended) { + VHOST_CONFIG_LOG(dev->ifname, ERR, + "SET_VQ_READY received on suspended device"); + resp.result = VDUSE_REQ_RESULT_FAILED; + break; + } i = req.vq_ready.num; if (i >= dev->nr_vring) { @@ -567,11 +575,43 @@ vduse_events_handler(int fd, void *arg, int *close __rte_unused) vq->enabled = req.vq_ready.ready; resp.result = VDUSE_REQ_RESULT_OK; break; + case VDUSE_SUSPEND: + if (!(dev->vduse_features & RTE_BIT64(VDUSE_F_SUSPEND))) { + VHOST_CONFIG_LOG(dev->ifname, ERR, + "Unnegotiated suspend message"); + resp.result = VDUSE_REQ_RESULT_FAILED; + break; + } + if (!(dev->status & VIRTIO_DEVICE_STATUS_DRIVER_OK)) { + VHOST_CONFIG_LOG(dev->ifname, ERR, + "Unexpected suspend message with no DRIVER_OK"); + resp.result = VDUSE_REQ_RESULT_FAILED; + break; + } + for (i = 0; dev->notify_ops != NULL && + dev->notify_ops->vring_state_changed != NULL && + i < dev->nr_vring; i++) { + if (dev->virtqueue[i] == dev->cvq) + continue; + + ret = dev->notify_ops->vring_state_changed(dev->vid, i, false); + if (ret) { + VHOST_CONFIG_LOG(dev->ifname, ERR, + "Failed to disable VQ %u for suspend", i); + resp.result = VDUSE_REQ_RESULT_FAILED; + goto out; + } + } + dev->vduse_suspended = true; + resp.result = VDUSE_REQ_RESULT_OK; + break; + default: resp.result = VDUSE_REQ_RESULT_FAILED; break; } +out: resp.request_id = req.request_id; ret = write(dev->vduse_dev_fd, &resp, sizeof(resp)); diff --git a/lib/vhost/vhost.h b/lib/vhost/vhost.h index c2b645c2d4b0..f0e7953e3bdc 100644 --- a/lib/vhost/vhost.h +++ b/lib/vhost/vhost.h @@ -534,6 +534,7 @@ struct __rte_cache_aligned virtio_net { int vduse_dev_fd; uint64_t vduse_api_ver; uint64_t vduse_features; + bool vduse_suspended; struct vhost_virtqueue *cvq; -- 2.55.0

