From: Super User <[email protected]> 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]> --- kernel/linux/uapi/linux/vduse.h | 4 ++++ lib/vhost/vduse.c | 40 ++++++++++++++++++++++++++++++++- lib/vhost/vhost.h | 1 + 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/kernel/linux/uapi/linux/vduse.h b/kernel/linux/uapi/linux/vduse.h index 156446cdc712..ca510027cac2 100644 --- a/kernel/linux/uapi/linux/vduse.h +++ b/kernel/linux/uapi/linux/vduse.h @@ -21,6 +21,9 @@ /* The VDUSE instance expects a request for vq ready */ #define VDUSE_F_QUEUE_READY 0 +/* The VDUSE instance expects a request for suspend */ +#define VDUSE_F_SUSPEND 1 + /* * Get the version of VDUSE API that kernel supported (VDUSE_API_VERSION). * This is used for future extension. @@ -338,6 +341,7 @@ enum vduse_req_type { VDUSE_UPDATE_IOTLB, VDUSE_SET_VQ_GROUP_ASID, VDUSE_SET_VQ_READY, + VDUSE_SUSPEND, }; /** diff --git a/lib/vhost/vduse.c b/lib/vhost/vduse.c index 9c0801453605..2f421a06a2d2 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) { @@ -521,6 +522,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; vq = dev->virtqueue[i]; @@ -544,6 +551,37 @@ 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_api_ver < 2) { + VHOST_CONFIG_LOG(dev->ifname, ERR, + "Unexpected suspend message with ver %"PRIu64, + dev->vduse_api_ver); + resp.result = VDUSE_REQ_RESULT_FAILED; + break; + } + 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->vring_state_changed && + i < dev->nr_vring; i++) { + if (dev->virtqueue[i] == dev->cvq) + continue; + + dev->notify_ops->vring_state_changed(dev->vid, i, false); + } + dev->vduse_suspended = true; + resp.result = VDUSE_REQ_RESULT_OK; + break; + default: resp.result = VDUSE_REQ_RESULT_FAILED; break; diff --git a/lib/vhost/vhost.h b/lib/vhost/vhost.h index ce2e1a271c6f..73f0c9397cd0 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.53.0

