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/rte_vhost_version.map |  7 +++++++
 lib/librte_vhost/vhost.c               | 37 ++++++++++++++++++++++++++++------
 lib/librte_vhost/vhost.h               |  3 +++
 lib/librte_vhost/vhost_user.c          | 17 ++++++++--------
 5 files changed, 53 insertions(+), 14 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/rte_vhost_version.map 
b/lib/librte_vhost/rte_vhost_version.map
index 1e70495..02142df 100644
--- a/lib/librte_vhost/rte_vhost_version.map
+++ b/lib/librte_vhost/rte_vhost_version.map
@@ -52,3 +52,10 @@ DPDK_17.08 {
        rte_vhost_rx_queue_count;
 
 } DPDK_17.05;
+
+DPDK_17.11 {
+       global:
+
+       rte_vhost_set_vring_effective_fd;
+
+} DPDK_17.08;
diff --git a/lib/librte_vhost/vhost.c b/lib/librte_vhost/vhost.c
index 2b687ea..11a3db1 100644
--- a/lib/librte_vhost/vhost.c
+++ b/lib/librte_vhost/vhost.c
@@ -98,10 +98,10 @@ get_device(int vid)
 static void
 cleanup_vq(struct vhost_virtqueue *vq, int destroy)
 {
-       if ((vq->callfd >= 0) && (destroy != 0))
-               close(vq->callfd);
-       if (vq->kickfd >= 0)
-               close(vq->kickfd);
+       if ((vq->callfd_pri >= 0) && (destroy != 0))
+               close(vq->callfd_pri);
+       if (vq->kickfd_pri >= 0)
+               close(vq->kickfd_pri);
 }
 
 /*
@@ -146,6 +146,8 @@ init_vring_queue(struct vhost_virtqueue *vq)
 
        vq->kickfd = VIRTIO_UNINITIALIZED_EVENTFD;
        vq->callfd = VIRTIO_UNINITIALIZED_EVENTFD;
+       vq->kickfd_pri = VIRTIO_UNINITIALIZED_EVENTFD;
+       vq->callfd_pri = VIRTIO_UNINITIALIZED_EVENTFD;
 
        /* Backends are set to -1 indicating an inactive device. */
        vq->backend = -1;
@@ -435,13 +437,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..3d1eea4 100644
--- a/lib/librte_vhost/vhost_user.c
+++ b/lib/librte_vhost/vhost_user.c
@@ -661,10 +661,10 @@ vhost_user_set_vring_call(struct virtio_net *dev, struct 
VhostUserMsg *pmsg)
                "vring call idx:%d file:%d\n", file.index, file.fd);
 
        vq = dev->virtqueue[file.index];
-       if (vq->callfd >= 0)
-               close(vq->callfd);
+       if (vq->callfd_pri >= 0)
+               close(vq->callfd_pri);
 
-       vq->callfd = file.fd;
+       vq->callfd_pri = vq->callfd = file.fd;
 }
 
 static void
@@ -682,9 +682,9 @@ vhost_user_set_vring_kick(struct virtio_net *dev, struct 
VhostUserMsg *pmsg)
                "vring kick idx:%d file:%d\n", file.index, file.fd);
 
        vq = dev->virtqueue[file.index];
-       if (vq->kickfd >= 0)
-               close(vq->kickfd);
-       vq->kickfd = file.fd;
+       if (vq->kickfd_pri >= 0)
+               close(vq->kickfd_pri);
+       vq->kickfd_pri = vq->kickfd = file.fd;
 }
 
 static void
@@ -731,10 +731,11 @@ vhost_user_get_vring_base(struct virtio_net *dev,
         * sent and only sent in vhost_vring_stop.
         * TODO: cleanup the vring, it isn't usable since here.
         */
-       if (vq->kickfd >= 0)
-               close(vq->kickfd);
+       if (vq->kickfd_pri >= 0)
+               close(vq->kickfd_pri);
 
        vq->kickfd = VIRTIO_UNINITIALIZED_EVENTFD;
+       vq->kickfd_pri = VIRTIO_UNINITIALIZED_EVENTFD;
 
        if (dev->dequeue_zero_copy)
                free_zmbufs(vq);
-- 
2.7.4

Reply via email to