diff --git a/lib/vhost/rte_vhost_17_05/rte_vhost.h b/lib/vhost/rte_vhost_17_05/rte_vhost.h index 5fb9dfb88..b8419e3e9 100644 --- a/lib/vhost/rte_vhost_17_05/rte_vhost.h +++ b/lib/vhost/rte_vhost_17_05/rte_vhost.h @@ -82,6 +82,9 @@ struct rte_vhost_vring { int callfd; int kickfd; uint16_t size; + + uint16_t last_avail_idx; + uint16_t last_used_idx; }; /** @@ -424,4 +427,25 @@ int rte_vhost_get_mem_table(int vid, struct rte_vhost_memory **mem); int rte_vhost_get_vhost_vring(int vid, uint16_t vring_idx, struct rte_vhost_vring *vring); +/** + * Set id of the last descriptors in avail and used guest vrings. + * + * In case user application operates directly on buffers, it should use this + * function on device destruction to retrieve the same values later on in device + * creation via rte_vhost_get_vhost_vring(int, uint16_t, struct rte_vhost_vring *) + * + * @param vid + * vhost device ID + * @param vring_idx + * vring index + * @param last_avail_idx + * id of the last descriptor in avail ring to be set + * @param last_used_idx + * id of the last descriptor in used ring to be set + * @return + * 0 on success, -1 on failure + */ +int rte_vhost_set_vhost_vring_last_idx(int vid, uint16_t vring_idx, + uint16_t last_avail_idx, uint16_t last_used_idx); + #endif /* _RTE_VHOST_H_ */ diff --git a/lib/vhost/rte_vhost_17_05/vhost.c b/lib/vhost/rte_vhost_17_05/vhost.c index 0b19d2eb8..dc63208b0 100644 --- a/lib/vhost/rte_vhost_17_05/vhost.c +++ b/lib/vhost/rte_vhost_17_05/vhost.c @@ -407,6 +407,9 @@ rte_vhost_get_vhost_vring(int vid, uint16_t vring_idx, vring->kickfd = vq->kickfd; vring->size = vq->size; + vring->last_avail_idx = vq->last_avail_idx; + vring->last_used_idx = vq->last_used_idx; + return 0; } @@ -475,3 +478,26 @@ rte_vhost_log_used_vring(int vid, uint16_t vring_idx, vhost_log_used_vring(dev, vq, offset, len); } + +int +rte_vhost_set_vhost_vring_last_idx(int vid, uint16_t vring_idx, + uint16_t last_avail_idx, uint16_t last_used_idx) { + struct virtio_net *dev; + struct vhost_virtqueue *vq; + + dev = get_device(vid); + if (!dev) + return -1; + + if (vring_idx >= VHOST_MAX_VRING) + return -1; + + vq = dev->virtqueue[vring_idx]; + if (!vq) + return -1; + + vq->last_avail_idx = last_avail_idx; + vq->last_used_idx = last_used_idx; + + return 0; +}