vhost: fix name not null terminated
[dpdk.git] / lib / librte_vhost / virtio-net.c
index 764810e..f4695af 100644 (file)
@@ -167,8 +167,8 @@ init_vring_queue(struct vhost_virtqueue *vq, int qp_idx)
 {
        memset(vq, 0, sizeof(struct vhost_virtqueue));
 
-       vq->kickfd = -1;
-       vq->callfd = -1;
+       vq->kickfd = VIRTIO_UNINITIALIZED_EVENTFD;
+       vq->callfd = VIRTIO_UNINITIALIZED_EVENTFD;
 
        /* Backends are set to -1 indicating an inactive device. */
        vq->backend = -1;
@@ -293,6 +293,9 @@ vhost_destroy_device(struct vhost_device_ctx ctx)
 {
        struct virtio_net *dev = get_device(ctx);
 
+       if (dev == NULL)
+               return;
+
        if (dev->flags & VIRTIO_DEV_RUNNING)
                notify_ops->destroy_device(dev);
 
@@ -317,6 +320,7 @@ vhost_set_ifname(struct vhost_device_ctx ctx,
                sizeof(dev->ifname) : if_len;
 
        strncpy(dev->ifname, if_name, len);
+       dev->ifname[sizeof(dev->ifname) - 1] = '\0';
 }
 
 
@@ -448,6 +452,13 @@ numa_realloc(struct virtio_net *dev, int index)
        struct vhost_virtqueue *old_vq, *vq;
        int ret;
 
+       /*
+        * vq is allocated on pairs, we should try to do realloc
+        * on first queue of one queue pair only.
+        */
+       if (index % VIRTIO_QNUM != 0)
+               return dev;
+
        old_dev = dev;
        vq = old_vq = dev->virtqueue[index];
 
@@ -465,11 +476,12 @@ numa_realloc(struct virtio_net *dev, int index)
        if (oldnode != newnode) {
                RTE_LOG(INFO, VHOST_CONFIG,
                        "reallocate vq from %d to %d node\n", oldnode, newnode);
-               vq = rte_malloc_socket(NULL, sizeof(*vq), 0, newnode);
+               vq = rte_malloc_socket(NULL, sizeof(*vq) * VIRTIO_QNUM, 0,
+                                      newnode);
                if (!vq)
                        return dev;
 
-               memcpy(vq, old_vq, sizeof(*vq));
+               memcpy(vq, old_vq, sizeof(*vq) * VIRTIO_QNUM);
                rte_free(old_vq);
        }
 
@@ -497,6 +509,7 @@ numa_realloc(struct virtio_net *dev, int index)
 
 out:
        dev->virtqueue[index] = vq;
+       dev->virtqueue[index + 1] = vq + 1;
        vhost_devices[dev->device_fh] = dev;
 
        return dev;