From a86029b96761c2c7701c44631deed5e3afc3a3a0 Mon Sep 17 00:00:00 2001 From: Darek Stojaczyk Date: Fri, 15 Mar 2019 13:35:08 +0100 Subject: [PATCH] virtio/pci: don't rely on phys_addr retrieved from spdk_malloc() The phys_addr param in spdk_*malloc() is about to be deprecated, so use a separate spdk_vtophys() call to retrieve physical addresses. This patch also adds error checks against SPDK_VTOPHYS_ERROR. The error handling paths are already there to account for spdk_*malloc() failures themselves, so reuse them in case of vtophys failures. Change-Id: I6d71a4c361f5ec1770d96676f3bb8f57ecd62716 Signed-off-by: Darek Stojaczyk Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/448167 Tested-by: SPDK CI Jenkins Reviewed-by: Changpeng Liu Reviewed-by: Jim Harris Reviewed-by: Shuhei Matsumoto --- lib/virtio/virtio_pci.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/virtio/virtio_pci.c b/lib/virtio/virtio_pci.c index f09bbea9b..3a05f8b8c 100644 --- a/lib/virtio/virtio_pci.c +++ b/lib/virtio/virtio_pci.c @@ -272,11 +272,17 @@ modern_setup_queue(struct virtio_dev *dev, struct virtqueue *vq) return -ENOMEM; } - queue_mem = spdk_dma_zmalloc(vq->vq_ring_size, VALUE_2MB, &queue_mem_phys_addr); + queue_mem = spdk_dma_zmalloc(vq->vq_ring_size, VALUE_2MB, NULL); 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); + return -EFAULT; + } + vq->vq_ring_mem = queue_mem_phys_addr; vq->vq_ring_virt_mem = queue_mem;