To support kick in secondary process, we propose callfd_pri and kickfd_pri to store the value in primary process; and by a new API, rte_vhost_set_vring_effective_fd(), we can set effective callfd and kickfd which can be used by secondary process.
Note in this case, either primary process or the secondary process can kick the frontend; that is, they cannot kick a vring at the same time. Signed-off-by: Jianfeng Tan <jianfeng....@intel.com> --- lib/librte_vhost/rte_vhost.h | 3 +++ lib/librte_vhost/vhost.c | 27 +++++++++++++++++++++++++-- lib/librte_vhost/vhost.h | 3 +++ lib/librte_vhost/vhost_user.c | 4 ++-- 4 files changed, 33 insertions(+), 4 deletions(-) diff --git a/lib/librte_vhost/rte_vhost.h b/lib/librte_vhost/rte_vhost.h index 8c974eb..c82f249 100644 --- a/lib/librte_vhost/rte_vhost.h +++ b/lib/librte_vhost/rte_vhost.h @@ -432,6 +432,9 @@ 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); +int rte_vhost_set_vring_effective_fd(int vid, uint16_t vring_idx, + int callfd, int kickfd); + /** * Get vhost RX queue avail count. * diff --git a/lib/librte_vhost/vhost.c b/lib/librte_vhost/vhost.c index 2b687ea..d2e4500 100644 --- a/lib/librte_vhost/vhost.c +++ b/lib/librte_vhost/vhost.c @@ -435,13 +435,36 @@ rte_vhost_get_vhost_vring(int vid, uint16_t vring_idx, vring->used = vq->used; vring->log_guest_addr = vq->log_guest_addr; - vring->callfd = vq->callfd; - vring->kickfd = vq->kickfd; + vring->callfd = vq->callfd_pri; + vring->kickfd = vq->kickfd_pri; vring->size = vq->size; return 0; } +int +rte_vhost_set_vring_effective_fd(int vid, uint16_t vring_idx, + int callfd, int kickfd) +{ + 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->callfd = callfd; + vq->kickfd = kickfd; + + return 0; +} uint16_t rte_vhost_avail_entries(int vid, uint16_t queue_id) { diff --git a/lib/librte_vhost/vhost.h b/lib/librte_vhost/vhost.h index bc1f31e..be57c52 100644 --- a/lib/librte_vhost/vhost.h +++ b/lib/librte_vhost/vhost.h @@ -98,9 +98,12 @@ struct vhost_virtqueue { /* Backend value to determine if device should started/stopped */ int backend; /* Used to notify the guest (trigger interrupt) */ + int callfd_pri; int callfd; /* Currently unused as polling mode is enabled */ + int kickfd_pri; int kickfd; + int enabled; /* Physical address of used ring, for logging */ diff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c index ad2e8d3..72f2b40 100644 --- a/lib/librte_vhost/vhost_user.c +++ b/lib/librte_vhost/vhost_user.c @@ -664,7 +664,7 @@ vhost_user_set_vring_call(struct virtio_net *dev, struct VhostUserMsg *pmsg) if (vq->callfd >= 0) close(vq->callfd); - vq->callfd = file.fd; + vq->callfd_pri = vq->callfd = file.fd; } static void @@ -684,7 +684,7 @@ vhost_user_set_vring_kick(struct virtio_net *dev, struct VhostUserMsg *pmsg) vq = dev->virtqueue[file.index]; if (vq->kickfd >= 0) close(vq->kickfd); - vq->kickfd = file.fd; + vq->kickfd_pri = vq->kickfd = file.fd; } static void -- 2.7.4