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: Darek Stojaczyk <dariusz.stojaczyk@intel.com> Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/450550 Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com> Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
This commit is contained in:
parent
34fb79b15b
commit
01103b2e4d
@ -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);
|
size = sizeof(*vq) + vq_size * sizeof(struct vq_desc_extra);
|
||||||
|
|
||||||
vq = spdk_dma_zmalloc(size, RTE_CACHE_LINE_SIZE, NULL);
|
if (posix_memalign((void **)&vq, RTE_CACHE_LINE_SIZE, size)) {
|
||||||
if (vq == NULL) {
|
|
||||||
SPDK_ERRLOG("can not allocate vq\n");
|
SPDK_ERRLOG("can not allocate vq\n");
|
||||||
return -ENOMEM;
|
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);
|
rc = virtio_dev_backend_ops(dev)->setup_queue(dev, vq);
|
||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
SPDK_ERRLOG("setup_queue failed\n");
|
SPDK_ERRLOG("setup_queue failed\n");
|
||||||
spdk_dma_free(vq);
|
free(vq);
|
||||||
dev->vqs[vtpci_queue_idx] = NULL;
|
dev->vqs[vtpci_queue_idx] = NULL;
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
@ -198,11 +197,11 @@ virtio_free_queues(struct virtio_dev *dev)
|
|||||||
|
|
||||||
virtio_dev_backend_ops(dev)->del_queue(dev, vq);
|
virtio_dev_backend_ops(dev)->del_queue(dev, vq);
|
||||||
|
|
||||||
rte_free(vq);
|
free(vq);
|
||||||
dev->vqs[i] = NULL;
|
dev->vqs[i] = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
rte_free(dev->vqs);
|
free(dev->vqs);
|
||||||
dev->vqs = NULL;
|
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);
|
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) {
|
if (!dev->vqs) {
|
||||||
SPDK_ERRLOG("failed to allocate %"PRIu16" vqs\n", nr_vq);
|
SPDK_ERRLOG("failed to allocate %"PRIu16" vqs\n", nr_vq);
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
@ -272,14 +272,15 @@ modern_setup_queue(struct virtio_dev *dev, struct virtqueue *vq)
|
|||||||
return -ENOMEM;
|
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) {
|
if (queue_mem == NULL) {
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
queue_mem_phys_addr = spdk_vtophys(queue_mem, NULL);
|
queue_mem_phys_addr = spdk_vtophys(queue_mem, NULL);
|
||||||
if (queue_mem_phys_addr == SPDK_VTOPHYS_ERROR) {
|
if (queue_mem_phys_addr == SPDK_VTOPHYS_ERROR) {
|
||||||
spdk_dma_free(queue_mem);
|
spdk_free(queue_mem);
|
||||||
return -EFAULT;
|
return -EFAULT;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -287,7 +288,7 @@ modern_setup_queue(struct virtio_dev *dev, struct virtqueue *vq)
|
|||||||
vq->vq_ring_virt_mem = queue_mem;
|
vq->vq_ring_virt_mem = queue_mem;
|
||||||
|
|
||||||
if (!check_vq_phys_addr_ok(vq)) {
|
if (!check_vq_phys_addr_ok(vq)) {
|
||||||
spdk_dma_free(queue_mem);
|
spdk_free(queue_mem);
|
||||||
return -ENOMEM;
|
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_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
|
static void
|
||||||
|
@ -464,7 +464,8 @@ virtio_user_setup_queue(struct virtio_dev *vdev, struct virtqueue *vq)
|
|||||||
return -errno;
|
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) {
|
if (queue_mem == NULL) {
|
||||||
close(kickfd);
|
close(kickfd);
|
||||||
close(callfd);
|
close(callfd);
|
||||||
@ -482,7 +483,7 @@ virtio_user_setup_queue(struct virtio_dev *vdev, struct virtqueue *vq)
|
|||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
SPDK_ERRLOG("failed to send VHOST_USER_SET_VRING_ENABLE: %s\n",
|
SPDK_ERRLOG("failed to send VHOST_USER_SET_VRING_ENABLE: %s\n",
|
||||||
spdk_strerror(-rc));
|
spdk_strerror(-rc));
|
||||||
spdk_dma_free(queue_mem);
|
spdk_free(queue_mem);
|
||||||
return -rc;
|
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->callfds[vq->vq_queue_index] = -1;
|
||||||
dev->kickfds[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
|
static void
|
||||||
|
Loading…
Reference in New Issue
Block a user