vhost: export API to translate gpa to vva
authorYuanhan Liu <yuanhan.liu@linux.intel.com>
Sat, 1 Apr 2017 07:22:46 +0000 (15:22 +0800)
committerYuanhan Liu <yuanhan.liu@linux.intel.com>
Sat, 1 Apr 2017 08:42:44 +0000 (10:42 +0200)
Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>
lib/librte_vhost/rte_vhost_version.map
lib/librte_vhost/rte_virtio_net.h
lib/librte_vhost/vhost.h
lib/librte_vhost/virtio_net.c

index 93b6733..2b309b2 100644 (file)
@@ -39,5 +39,6 @@ DPDK_17.05 {
        rte_vhost_get_mtu;
        rte_vhost_get_negotiated_features;
        rte_vhost_get_vhost_vring;
+       rte_vhost_gpa_to_vva;
 
 } DPDK_16.07;
index 31e175b..66a7511 100644 (file)
@@ -103,6 +103,34 @@ struct virtio_net_device_ops {
        void *reserved[5]; /**< Reserved for future extension */
 };
 
+/**
+ * Convert guest physical address to host virtual address
+ *
+ * @param mem
+ *  the guest memory regions
+ * @param gpa
+ *  the guest physical address for querying
+ * @return
+ *  the host virtual address on success, 0 on failure
+ */
+static inline uint64_t __attribute__((always_inline))
+rte_vhost_gpa_to_vva(struct rte_vhost_memory *mem, uint64_t gpa)
+{
+       struct rte_vhost_mem_region *reg;
+       uint32_t i;
+
+       for (i = 0; i < mem->nregions; i++) {
+               reg = &mem->regions[i];
+               if (gpa >= reg->guest_phys_addr &&
+                   gpa <  reg->guest_phys_addr + reg->size) {
+                       return gpa - reg->guest_phys_addr +
+                              reg->host_user_addr;
+               }
+       }
+
+       return 0;
+}
+
 int rte_vhost_enable_guest_notification(int vid, uint16_t queue_id, int enable);
 
 /**
index 68ca197..b5c5046 100644 (file)
@@ -229,25 +229,6 @@ extern uint64_t VHOST_FEATURES;
 #define MAX_VHOST_DEVICE       1024
 extern struct virtio_net *vhost_devices[MAX_VHOST_DEVICE];
 
-/* Convert guest physical Address to host virtual address */
-static inline uint64_t __attribute__((always_inline))
-gpa_to_vva(struct virtio_net *dev, uint64_t gpa)
-{
-       struct rte_vhost_mem_region *reg;
-       uint32_t i;
-
-       for (i = 0; i < dev->mem->nregions; i++) {
-               reg = &dev->mem->regions[i];
-               if (gpa >= reg->guest_phys_addr &&
-                   gpa <  reg->guest_phys_addr + reg->size) {
-                       return gpa - reg->guest_phys_addr +
-                              reg->host_user_addr;
-               }
-       }
-
-       return 0;
-}
-
 /* Convert guest physical address to host physical address */
 static inline phys_addr_t __attribute__((always_inline))
 gpa_to_hpa(struct virtio_net *dev, uint64_t gpa, uint64_t size)
index d0a3b11..c1187d4 100644 (file)
@@ -199,7 +199,7 @@ copy_mbuf_to_desc(struct virtio_net *dev, struct vring_desc *descs,
        uint16_t nr_desc = 1;
 
        desc = &descs[desc_idx];
-       desc_addr = gpa_to_vva(dev, desc->addr);
+       desc_addr = rte_vhost_gpa_to_vva(dev->mem, desc->addr);
        /*
         * Checking of 'desc_addr' placed outside of 'unlikely' macro to avoid
         * performance issue with some versions of gcc (4.8.4 and 5.3.0) which
@@ -239,7 +239,7 @@ copy_mbuf_to_desc(struct virtio_net *dev, struct vring_desc *descs,
                                return -1;
 
                        desc = &descs[desc->next];
-                       desc_addr = gpa_to_vva(dev, desc->addr);
+                       desc_addr = rte_vhost_gpa_to_vva(dev->mem, desc->addr);
                        if (unlikely(!desc_addr))
                                return -1;
 
@@ -323,7 +323,8 @@ virtio_dev_rx(struct virtio_net *dev, uint16_t queue_id,
                int err;
 
                if (vq->desc[desc_idx].flags & VRING_DESC_F_INDIRECT) {
-                       descs = (struct vring_desc *)(uintptr_t)gpa_to_vva(dev,
+                       descs = (struct vring_desc *)(uintptr_t)
+                               rte_vhost_gpa_to_vva(dev->mem,
                                        vq->desc[desc_idx].addr);
                        if (unlikely(!descs)) {
                                count = i;
@@ -383,7 +384,7 @@ fill_vec_buf(struct virtio_net *dev, struct vhost_virtqueue *vq,
 
        if (vq->desc[idx].flags & VRING_DESC_F_INDIRECT) {
                descs = (struct vring_desc *)(uintptr_t)
-                                       gpa_to_vva(dev, vq->desc[idx].addr);
+                       rte_vhost_gpa_to_vva(dev->mem, vq->desc[idx].addr);
                if (unlikely(!descs))
                        return -1;
 
@@ -473,7 +474,7 @@ copy_mbuf_to_desc_mergeable(struct virtio_net *dev, struct rte_mbuf *m,
        if (unlikely(m == NULL))
                return -1;
 
-       desc_addr = gpa_to_vva(dev, buf_vec[vec_idx].buf_addr);
+       desc_addr = rte_vhost_gpa_to_vva(dev->mem, buf_vec[vec_idx].buf_addr);
        if (buf_vec[vec_idx].buf_len < dev->vhost_hlen || !desc_addr)
                return -1;
 
@@ -495,7 +496,8 @@ copy_mbuf_to_desc_mergeable(struct virtio_net *dev, struct rte_mbuf *m,
                /* done with current desc buf, get the next one */
                if (desc_avail == 0) {
                        vec_idx++;
-                       desc_addr = gpa_to_vva(dev, buf_vec[vec_idx].buf_addr);
+                       desc_addr = rte_vhost_gpa_to_vva(dev->mem,
+                                       buf_vec[vec_idx].buf_addr);
                        if (unlikely(!desc_addr))
                                return -1;
 
@@ -798,7 +800,7 @@ copy_desc_to_mbuf(struct virtio_net *dev, struct vring_desc *descs,
                        (desc->flags & VRING_DESC_F_INDIRECT))
                return -1;
 
-       desc_addr = gpa_to_vva(dev, desc->addr);
+       desc_addr = rte_vhost_gpa_to_vva(dev->mem, desc->addr);
        if (unlikely(!desc_addr))
                return -1;
 
@@ -818,7 +820,7 @@ copy_desc_to_mbuf(struct virtio_net *dev, struct vring_desc *descs,
                if (unlikely(desc->flags & VRING_DESC_F_INDIRECT))
                        return -1;
 
-               desc_addr = gpa_to_vva(dev, desc->addr);
+               desc_addr = rte_vhost_gpa_to_vva(dev->mem, desc->addr);
                if (unlikely(!desc_addr))
                        return -1;
 
@@ -882,7 +884,7 @@ copy_desc_to_mbuf(struct virtio_net *dev, struct vring_desc *descs,
                        if (unlikely(desc->flags & VRING_DESC_F_INDIRECT))
                                return -1;
 
-                       desc_addr = gpa_to_vva(dev, desc->addr);
+                       desc_addr = rte_vhost_gpa_to_vva(dev->mem, desc->addr);
                        if (unlikely(!desc_addr))
                                return -1;
 
@@ -1125,7 +1127,8 @@ rte_vhost_dequeue_burst(int vid, uint16_t queue_id,
                        rte_prefetch0(&vq->desc[desc_indexes[i + 1]]);
 
                if (vq->desc[desc_indexes[i]].flags & VRING_DESC_F_INDIRECT) {
-                       desc = (struct vring_desc *)(uintptr_t)gpa_to_vva(dev,
+                       desc = (struct vring_desc *)(uintptr_t)
+                               rte_vhost_gpa_to_vva(dev->mem,
                                        vq->desc[desc_indexes[i]].addr);
                        if (unlikely(!desc))
                                break;