common/octeontx2: add polling based response mbox message
[dpdk.git] / lib / librte_vhost / vhost_user.c
index 47db316..9f14ea6 100644 (file)
@@ -1145,6 +1145,21 @@ vhost_user_set_mem_table(struct virtio_net **pdev, struct VhostUserMsg *msg,
                        goto err_mmap;
                }
                mmap_size = RTE_ALIGN_CEIL(mmap_size, alignment);
+               if (mmap_size == 0) {
+                       /*
+                        * It could happen if initial mmap_size + alignment
+                        * overflows the sizeof uint64, which could happen if
+                        * either mmap_size or alignment value is wrong.
+                        *
+                        * mmap() kernel implementation would return an error,
+                        * but better catch it before and provide useful info
+                        * in the logs.
+                        */
+                       VHOST_LOG_CONFIG(ERR, "mmap size (0x%" PRIx64 ") "
+                                       "or alignment (0x%" PRIx64 ") is invalid\n",
+                                       reg->size + mmap_offset, alignment);
+                       goto err_mmap;
+               }
 
                populate = (dev->dequeue_zero_copy) ? MAP_POPULATE : 0;
                mmap_addr = mmap(NULL, mmap_size, PROT_READ | PROT_WRITE,
@@ -1298,7 +1313,8 @@ vq_is_ready(struct virtio_net *dev, struct vhost_virtqueue *vq)
                return false;
 
        if (vq_is_packed(dev))
-               rings_ok = !!vq->desc_packed;
+               rings_ok = vq->desc_packed && vq->driver_event &&
+                       vq->device_event;
        else
                rings_ok = vq->desc && vq->avail && vq->used;
 
@@ -2840,6 +2856,42 @@ vhost_user_iotlb_miss(struct virtio_net *dev, uint64_t iova, uint8_t perm)
        return 0;
 }
 
+static int
+vhost_user_slave_config_change(struct virtio_net *dev, bool need_reply)
+{
+       int ret;
+       struct VhostUserMsg msg = {
+               .request.slave = VHOST_USER_SLAVE_CONFIG_CHANGE_MSG,
+               .flags = VHOST_USER_VERSION,
+               .size = 0,
+       };
+
+       if (need_reply)
+               msg.flags |= VHOST_USER_NEED_REPLY;
+
+       ret = send_vhost_slave_message(dev, &msg);
+       if (ret < 0) {
+               VHOST_LOG_CONFIG(ERR,
+                               "Failed to send config change (%d)\n",
+                               ret);
+               return ret;
+       }
+
+       return process_slave_message_reply(dev, &msg);
+}
+
+int
+rte_vhost_slave_config_change(int vid, bool need_reply)
+{
+       struct virtio_net *dev;
+
+       dev = get_device(vid);
+       if (!dev)
+               return -ENODEV;
+
+       return vhost_user_slave_config_change(dev, need_reply);
+}
+
 static int vhost_user_slave_set_vring_host_notifier(struct virtio_net *dev,
                                                    int index, int fd,
                                                    uint64_t offset,