maintainers: sort crypto drivers list
[dpdk.git] / lib / librte_vhost / vhost_user.c
index 1e73974..76c4eec 100644 (file)
@@ -314,6 +314,9 @@ out:
        dev->virtqueue[index] = vq;
        vhost_devices[dev->vid] = dev;
 
+       if (old_vq != vq)
+               vhost_user_iotlb_init(dev, index);
+
        return dev;
 }
 #else
@@ -391,11 +394,7 @@ vhost_user_set_vring_addr(struct virtio_net *dev, VhostUserMsg *msg)
         */
        memcpy(&vq->ring_addrs, addr, sizeof(*addr));
 
-       vq->desc = NULL;
-       vq->avail = NULL;
-       vq->used = NULL;
-
-       vq->access_ok = 0;
+       vring_invalidate(dev, vq);
 
        return 0;
 }
@@ -421,6 +420,7 @@ translate_ring_addresses(struct virtio_net *dev, int vq_index)
 
        dev = numa_realloc(dev, vq_index);
        vq = dev->virtqueue[vq_index];
+       addr = &vq->ring_addrs;
 
        vq->avail = (struct vring_avail *)(uintptr_t)ring_addr_to_vva(dev,
                        vq, addr->avail_user_addr, sizeof(struct vring_avail));
@@ -1011,6 +1011,35 @@ is_vring_iotlb_update(struct vhost_virtqueue *vq, struct vhost_iotlb_msg *imsg)
        return 0;
 }
 
+static int
+is_vring_iotlb_invalidate(struct vhost_virtqueue *vq,
+                               struct vhost_iotlb_msg *imsg)
+{
+       uint64_t istart, iend, vstart, vend;
+
+       istart = imsg->iova;
+       iend = istart + imsg->size - 1;
+
+       vstart = (uintptr_t)vq->desc;
+       vend = vstart + sizeof(struct vring_desc) * vq->size - 1;
+       if (vstart <= iend && istart <= vend)
+               return 1;
+
+       vstart = (uintptr_t)vq->avail;
+       vend = vstart + sizeof(struct vring_avail);
+       vend += sizeof(uint16_t) * vq->size - 1;
+       if (vstart <= iend && istart <= vend)
+               return 1;
+
+       vstart = (uintptr_t)vq->used;
+       vend = vstart + sizeof(struct vring_used);
+       vend += sizeof(struct vring_used_elem) * vq->size - 1;
+       if (vstart <= iend && istart <= vend)
+               return 1;
+
+       return 0;
+}
+
 static int
 vhost_user_iotlb_msg(struct virtio_net **pdev, struct VhostUserMsg *msg)
 {
@@ -1041,6 +1070,9 @@ vhost_user_iotlb_msg(struct virtio_net **pdev, struct VhostUserMsg *msg)
 
                        vhost_user_iotlb_cache_remove(vq, imsg->iova,
                                        imsg->size);
+
+                       if (is_vring_iotlb_invalidate(vq, imsg))
+                               vring_invalidate(dev, vq);
                }
                break;
        default:
@@ -1114,7 +1146,7 @@ vhost_user_check_and_alloc_queue_pair(struct virtio_net *dev, VhostUserMsg *msg)
 {
        uint16_t vring_idx;
 
-       switch (msg->request) {
+       switch (msg->request.master) {
        case VHOST_USER_SET_VRING_KICK:
        case VHOST_USER_SET_VRING_CALL:
        case VHOST_USER_SET_VRING_ERR:
@@ -1166,7 +1198,7 @@ vhost_user_msg_handler(int vid, int fd)
        }
 
        ret = read_vhost_message(fd, &msg);
-       if (ret <= 0 || msg.request >= VHOST_USER_MAX) {
+       if (ret <= 0 || msg.request.master >= VHOST_USER_MAX) {
                if (ret < 0)
                        RTE_LOG(ERR, VHOST_CONFIG,
                                "vhost read message failed\n");
@@ -1181,12 +1213,12 @@ vhost_user_msg_handler(int vid, int fd)
        }
 
        ret = 0;
-       if (msg.request != VHOST_USER_IOTLB_MSG)
+       if (msg.request.master != VHOST_USER_IOTLB_MSG)
                RTE_LOG(INFO, VHOST_CONFIG, "read message %s\n",
-                       vhost_message_str[msg.request]);
+                       vhost_message_str[msg.request.master]);
        else
                RTE_LOG(DEBUG, VHOST_CONFIG, "read message %s\n",
-                       vhost_message_str[msg.request]);
+                       vhost_message_str[msg.request.master]);
 
        ret = vhost_user_check_and_alloc_queue_pair(dev, &msg);
        if (ret < 0) {
@@ -1195,7 +1227,7 @@ vhost_user_msg_handler(int vid, int fd)
                return -1;
        }
 
-       switch (msg.request) {
+       switch (msg.request.master) {
        case VHOST_USER_GET_FEATURES:
                msg.payload.u64 = vhost_user_get_features(dev);
                msg.size = sizeof(msg.payload.u64);
@@ -1325,7 +1357,7 @@ vhost_user_iotlb_miss(struct virtio_net *dev, uint64_t iova, uint8_t perm)
 {
        int ret;
        struct VhostUserMsg msg = {
-               .request = (enum VhostUserRequest)VHOST_USER_SLAVE_IOTLB_MSG,
+               .request.slave = VHOST_USER_SLAVE_IOTLB_MSG,
                .flags = VHOST_USER_VERSION,
                .size = sizeof(msg.payload.iotlb),
                .payload.iotlb = {