Commit 01103b2e authored by Darek Stojaczyk's avatar Darek Stojaczyk
Browse files

virtio: allocate virtqueue structs using regular calloc



The DMA-able vrings are allocated separately, so
the general virtqueue object can be allocated with
regular malloc - it only contains some local PMD
context.

While here, also allocate those DMA-able vrings using
spdk_zmalloc() instead of spdk_dma_zmalloc(), as
spdk_dma_*malloc() is about to be deprecated.

Change-Id: I06b9e0256c14c21747c253f05b63ef2361f465c7
Signed-off-by: default avatarDarek Stojaczyk <dariusz.stojaczyk@intel.com>
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/450550


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
parent 34fb79b1
Loading
Loading
Loading
Loading
+5 −6
Original line number Diff line number Diff line
@@ -141,8 +141,7 @@ virtio_init_queue(struct virtio_dev *dev, uint16_t vtpci_queue_idx)

	size = sizeof(*vq) + vq_size * sizeof(struct vq_desc_extra);

	vq = spdk_dma_zmalloc(size, RTE_CACHE_LINE_SIZE, NULL);
	if (vq == NULL) {
	if (posix_memalign((void **)&vq, RTE_CACHE_LINE_SIZE, size)) {
		SPDK_ERRLOG("can not allocate vq\n");
		return -ENOMEM;
	}
@@ -165,7 +164,7 @@ virtio_init_queue(struct virtio_dev *dev, uint16_t vtpci_queue_idx)
	rc = virtio_dev_backend_ops(dev)->setup_queue(dev, vq);
	if (rc < 0) {
		SPDK_ERRLOG("setup_queue failed\n");
		spdk_dma_free(vq);
		free(vq);
		dev->vqs[vtpci_queue_idx] = NULL;
		return rc;
	}
@@ -198,11 +197,11 @@ virtio_free_queues(struct virtio_dev *dev)

		virtio_dev_backend_ops(dev)->del_queue(dev, vq);

		rte_free(vq);
		free(vq);
		dev->vqs[i] = NULL;
	}

	rte_free(dev->vqs);
	free(dev->vqs);
	dev->vqs = NULL;
}

@@ -220,7 +219,7 @@ virtio_alloc_queues(struct virtio_dev *dev, uint16_t request_vq_num, uint16_t fi
	}

	assert(dev->vqs == NULL);
	dev->vqs = rte_zmalloc(NULL, sizeof(struct virtqueue *) * nr_vq, 0);
	dev->vqs = calloc(1, sizeof(struct virtqueue *) * nr_vq);
	if (!dev->vqs) {
		SPDK_ERRLOG("failed to allocate %"PRIu16" vqs\n", nr_vq);
		return -ENOMEM;
+5 −4
Original line number Diff line number Diff line
@@ -272,14 +272,15 @@ modern_setup_queue(struct virtio_dev *dev, struct virtqueue *vq)
		return -ENOMEM;
	}

	queue_mem = spdk_dma_zmalloc(vq->vq_ring_size, VALUE_2MB, NULL);
	queue_mem = spdk_zmalloc(vq->vq_ring_size, VALUE_2MB, NULL,
				 SPDK_ENV_LCORE_ID_ANY, SPDK_MALLOC_DMA);
	if (queue_mem == NULL) {
		return -ENOMEM;
	}

	queue_mem_phys_addr = spdk_vtophys(queue_mem, NULL);
	if (queue_mem_phys_addr == SPDK_VTOPHYS_ERROR) {
		spdk_dma_free(queue_mem);
		spdk_free(queue_mem);
		return -EFAULT;
	}

@@ -287,7 +288,7 @@ modern_setup_queue(struct virtio_dev *dev, struct virtqueue *vq)
	vq->vq_ring_virt_mem = queue_mem;

	if (!check_vq_phys_addr_ok(vq)) {
		spdk_dma_free(queue_mem);
		spdk_free(queue_mem);
		return -ENOMEM;
	}

@@ -337,7 +338,7 @@ modern_del_queue(struct virtio_dev *dev, struct virtqueue *vq)

	spdk_mmio_write_2(&hw->common_cfg->queue_enable, 0);

	spdk_dma_free(vq->vq_ring_virt_mem);
	spdk_free(vq->vq_ring_virt_mem);
}

static void
+4 −3
Original line number Diff line number Diff line
@@ -464,7 +464,8 @@ virtio_user_setup_queue(struct virtio_dev *vdev, struct virtqueue *vq)
		return -errno;
	}

	queue_mem = spdk_dma_zmalloc(vq->vq_ring_size, VIRTIO_PCI_VRING_ALIGN, NULL);
	queue_mem = spdk_zmalloc(vq->vq_ring_size, VIRTIO_PCI_VRING_ALIGN, NULL,
				 SPDK_ENV_LCORE_ID_ANY, SPDK_MALLOC_DMA);
	if (queue_mem == NULL) {
		close(kickfd);
		close(callfd);
@@ -482,7 +483,7 @@ virtio_user_setup_queue(struct virtio_dev *vdev, struct virtqueue *vq)
		if (rc < 0) {
			SPDK_ERRLOG("failed to send VHOST_USER_SET_VRING_ENABLE: %s\n",
				    spdk_strerror(-rc));
			spdk_dma_free(queue_mem);
			spdk_free(queue_mem);
			return -rc;
		}
	}
@@ -523,7 +524,7 @@ virtio_user_del_queue(struct virtio_dev *vdev, struct virtqueue *vq)
	dev->callfds[vq->vq_queue_index] = -1;
	dev->kickfds[vq->vq_queue_index] = -1;

	spdk_dma_free(vq->vq_ring_virt_mem);
	spdk_free(vq->vq_ring_virt_mem);
}

static void