DPDK patches and discussions
 help / color / mirror / Atom feed
From: Ouyang Changchun <changchun.ouyang@intel.com>
To: dev@dpdk.org
Subject: [dpdk-dev] [PATCH v4 04/12] vhost: set memory layout for multiple queues mode
Date: Wed, 12 Aug 2015 16:02:39 +0800	[thread overview]
Message-ID: <1439366567-3402-5-git-send-email-changchun.ouyang@intel.com> (raw)
In-Reply-To: <1439366567-3402-1-git-send-email-changchun.ouyang@intel.com>

QEMU sends separate commands orderly to set the memory layout for each queue
in one virtio device, accordingly vhost need keep memory layout information
for each queue of the virtio device.

This also need adjust the interface a bit for function gpa_to_vva by
introducing the queue index to specify queue of device to look up its
virtual vhost address for the incoming guest physical address.

Signed-off-by: Changchun Ouyang <changchun.ouyang@intel.com>
---
Chagnes in v4
  - rebase and fix conflicts
  - call calloc for dev.mem_arr

Chagnes in v3
  - fix coding style

Chagnes in v2
  - q_idx is changed into qp_idx
  - dynamically alloc mem for dev mem_arr
  - fix checkpatch errors

 examples/vhost/main.c                         | 21 +++++-----
 lib/librte_vhost/rte_virtio_net.h             | 10 +++--
 lib/librte_vhost/vhost_cuse/virtio-net-cdev.c | 57 ++++++++++++++------------
 lib/librte_vhost/vhost_rxtx.c                 | 22 +++++-----
 lib/librte_vhost/vhost_user/virtio-net-user.c | 59 ++++++++++++++-------------
 lib/librte_vhost/virtio-net.c                 | 38 ++++++++++++-----
 6 files changed, 119 insertions(+), 88 deletions(-)

diff --git a/examples/vhost/main.c b/examples/vhost/main.c
index 1b137b9..d3c45dd 100644
--- a/examples/vhost/main.c
+++ b/examples/vhost/main.c
@@ -1466,11 +1466,11 @@ attach_rxmbuf_zcp(struct virtio_net *dev)
 		desc = &vq->desc[desc_idx];
 		if (desc->flags & VRING_DESC_F_NEXT) {
 			desc = &vq->desc[desc->next];
-			buff_addr = gpa_to_vva(dev, desc->addr);
+			buff_addr = gpa_to_vva(dev, 0, desc->addr);
 			phys_addr = gpa_to_hpa(vdev, desc->addr, desc->len,
 					&addr_type);
 		} else {
-			buff_addr = gpa_to_vva(dev,
+			buff_addr = gpa_to_vva(dev, 0,
 					desc->addr + vq->vhost_hlen);
 			phys_addr = gpa_to_hpa(vdev,
 					desc->addr + vq->vhost_hlen,
@@ -1722,7 +1722,7 @@ virtio_dev_rx_zcp(struct virtio_net *dev, struct rte_mbuf **pkts,
 			rte_pktmbuf_data_len(buff), 0);
 
 		/* Buffer address translation for virtio header. */
-		buff_hdr_addr = gpa_to_vva(dev, desc->addr);
+		buff_hdr_addr = gpa_to_vva(dev, 0, desc->addr);
 		packet_len = rte_pktmbuf_data_len(buff) + vq->vhost_hlen;
 
 		/*
@@ -1946,7 +1946,7 @@ virtio_dev_tx_zcp(struct virtio_net *dev)
 		desc = &vq->desc[desc->next];
 
 		/* Buffer address translation. */
-		buff_addr = gpa_to_vva(dev, desc->addr);
+		buff_addr = gpa_to_vva(dev, 0, desc->addr);
 		/* Need check extra VLAN_HLEN size for inserting VLAN tag */
 		phys_addr = gpa_to_hpa(vdev, desc->addr, desc->len + VLAN_HLEN,
 			&addr_type);
@@ -2604,13 +2604,14 @@ new_device (struct virtio_net *dev)
 	dev->priv = vdev;
 
 	if (zero_copy) {
-		vdev->nregions_hpa = dev->mem->nregions;
-		for (regionidx = 0; regionidx < dev->mem->nregions; regionidx++) {
+		struct virtio_memory *dev_mem = dev->mem_arr[0];
+		vdev->nregions_hpa = dev_mem->nregions;
+		for (regionidx = 0; regionidx < dev_mem->nregions; regionidx++) {
 			vdev->nregions_hpa
 				+= check_hpa_regions(
-					dev->mem->regions[regionidx].guest_phys_address
-					+ dev->mem->regions[regionidx].address_offset,
-					dev->mem->regions[regionidx].memory_size);
+					dev_mem->regions[regionidx].guest_phys_address
+					+ dev_mem->regions[regionidx].address_offset,
+					dev_mem->regions[regionidx].memory_size);
 
 		}
 
@@ -2626,7 +2627,7 @@ new_device (struct virtio_net *dev)
 
 
 		if (fill_hpa_memory_regions(
-			vdev->regions_hpa, dev->mem
+			vdev->regions_hpa, dev_mem
 			) != vdev->nregions_hpa) {
 
 			RTE_LOG(ERR, VHOST_CONFIG,
diff --git a/lib/librte_vhost/rte_virtio_net.h b/lib/librte_vhost/rte_virtio_net.h
index d9e887f..8520d96 100644
--- a/lib/librte_vhost/rte_virtio_net.h
+++ b/lib/librte_vhost/rte_virtio_net.h
@@ -95,14 +95,15 @@ struct vhost_virtqueue {
  * Device structure contains all configuration information relating to the device.
  */
 struct virtio_net {
-	struct virtio_memory	*mem;		/**< QEMU memory and memory region information. */
 	struct vhost_virtqueue	**virtqueue;    /**< Contains all virtqueue information. */
+	struct virtio_memory    **mem_arr;      /**< Array for QEMU memory and memory region information. */
 	uint64_t		features;	/**< Negotiated feature set. */
 	uint64_t		device_fh;	/**< device identifier. */
 	uint32_t		flags;		/**< Device flags. Only used to check if device is running on data core. */
 #define IF_NAME_SZ (PATH_MAX > IFNAMSIZ ? PATH_MAX : IFNAMSIZ)
 	char			ifname[IF_NAME_SZ];	/**< Name of the tap device or socket path. */
 	uint32_t		virt_qp_nb;
+	uint32_t		mem_idx;	/** Used in set memory layout, unique for each queue within virtio device. */
 	void			*priv;		/**< private context */
 } __rte_cache_aligned;
 
@@ -153,14 +154,15 @@ rte_vring_available_entries(struct virtio_net *dev, uint16_t queue_id)
  * This is used to convert guest virtio buffer addresses.
  */
 static inline uint64_t __attribute__((always_inline))
-gpa_to_vva(struct virtio_net *dev, uint64_t guest_pa)
+gpa_to_vva(struct virtio_net *dev, uint32_t q_idx, uint64_t guest_pa)
 {
 	struct virtio_memory_regions *region;
+	struct virtio_memory *dev_mem = dev->mem_arr[q_idx];
 	uint32_t regionidx;
 	uint64_t vhost_va = 0;
 
-	for (regionidx = 0; regionidx < dev->mem->nregions; regionidx++) {
-		region = &dev->mem->regions[regionidx];
+	for (regionidx = 0; regionidx < dev_mem->nregions; regionidx++) {
+		region = &dev_mem->regions[regionidx];
 		if ((guest_pa >= region->guest_phys_address) &&
 			(guest_pa <= region->guest_phys_address_end)) {
 			vhost_va = region->address_offset + guest_pa;
diff --git a/lib/librte_vhost/vhost_cuse/virtio-net-cdev.c b/lib/librte_vhost/vhost_cuse/virtio-net-cdev.c
index ae2c3fa..34648f6 100644
--- a/lib/librte_vhost/vhost_cuse/virtio-net-cdev.c
+++ b/lib/librte_vhost/vhost_cuse/virtio-net-cdev.c
@@ -273,28 +273,32 @@ cuse_set_mem_table(struct vhost_device_ctx ctx,
 		((uint64_t)(uintptr_t)mem_regions_addr + size);
 	uint64_t base_address = 0, mapped_address, mapped_size;
 	struct virtio_net *dev;
+	struct virtio_memory *dev_mem = NULL;
 
 	dev = get_device(ctx);
 	if (dev == NULL)
-		return -1;
-
-	if (dev->mem && dev->mem->mapped_address) {
-		munmap((void *)(uintptr_t)dev->mem->mapped_address,
-			(size_t)dev->mem->mapped_size);
-		free(dev->mem);
-		dev->mem = NULL;
+		goto error;
+
+	dev_mem = dev->mem_arr[dev->mem_idx];
+	if (dev_mem && dev_mem->mapped_address) {
+		munmap((void *)(uintptr_t)dev_mem->mapped_address,
+			(size_t)dev_mem->mapped_size);
+		free(dev_mem);
+		dev->mem_arr[dev->mem_idx] = NULL;
 	}
 
-	dev->mem = calloc(1, sizeof(struct virtio_memory) +
+	dev->mem_arr[dev->mem_idx] = calloc(1, sizeof(struct virtio_memory) +
 		sizeof(struct virtio_memory_regions) * nregions);
-	if (dev->mem == NULL) {
+	dev_mem = dev->mem_arr[dev->mem_idx];
+
+	if (dev_mem == NULL) {
 		RTE_LOG(ERR, VHOST_CONFIG,
-			"(%"PRIu64") Failed to allocate memory for dev->mem\n",
-			dev->device_fh);
-		return -1;
+			"(%"PRIu64") Failed to allocate memory for dev->mem_arr[%d]\n",
+			dev->device_fh, dev->mem_idx);
+		goto error;
 	}
 
-	pregion = &dev->mem->regions[0];
+	pregion = &dev_mem->regions[0];
 
 	for (idx = 0; idx < nregions; idx++) {
 		pregion[idx].guest_phys_address =
@@ -320,14 +324,12 @@ cuse_set_mem_table(struct vhost_device_ctx ctx,
 				pregion[idx].userspace_address;
 			/* Map VM memory file */
 			if (host_memory_map(ctx.pid, base_address,
-				&mapped_address, &mapped_size) != 0) {
-				free(dev->mem);
-				dev->mem = NULL;
-				return -1;
-			}
-			dev->mem->mapped_address = mapped_address;
-			dev->mem->base_address = base_address;
-			dev->mem->mapped_size = mapped_size;
+				&mapped_address, &mapped_size) != 0)
+				goto free;
+
+			dev_mem->mapped_address = mapped_address;
+			dev_mem->base_address = base_address;
+			dev_mem->mapped_size = mapped_size;
 		}
 	}
 
@@ -335,9 +337,7 @@ cuse_set_mem_table(struct vhost_device_ctx ctx,
 	if (base_address == 0) {
 		RTE_LOG(ERR, VHOST_CONFIG,
 			"Failed to find base address of qemu memory file.\n");
-		free(dev->mem);
-		dev->mem = NULL;
-		return -1;
+		goto free;
 	}
 
 	valid_regions = nregions;
@@ -369,9 +369,16 @@ cuse_set_mem_table(struct vhost_device_ctx ctx,
 			pregion[idx].userspace_address -
 			pregion[idx].guest_phys_address;
 	}
-	dev->mem->nregions = valid_regions;
 
+	dev_mem->nregions = valid_regions;
+	dev->mem_idx = (dev->mem_idx + 1) % (dev->virt_qp_nb * VIRTIO_QNUM);
 	return 0;
+
+free:
+	free(dev_mem);
+	dev->mem_arr[dev->mem_idx] = NULL;
+error:
+	return -1;
 }
 
 /*
diff --git a/lib/librte_vhost/vhost_rxtx.c b/lib/librte_vhost/vhost_rxtx.c
index db4ad88..a60b542 100644
--- a/lib/librte_vhost/vhost_rxtx.c
+++ b/lib/librte_vhost/vhost_rxtx.c
@@ -139,7 +139,7 @@ virtio_dev_rx(struct virtio_net *dev, uint16_t queue_id,
 		buff = pkts[packet_success];
 
 		/* Convert from gpa to vva (guest physical addr -> vhost virtual addr) */
-		buff_addr = gpa_to_vva(dev, desc->addr);
+		buff_addr = gpa_to_vva(dev, queue_id / VIRTIO_QNUM, desc->addr);
 		/* Prefetch buffer address. */
 		rte_prefetch0((void *)(uintptr_t)buff_addr);
 
@@ -154,7 +154,7 @@ virtio_dev_rx(struct virtio_net *dev, uint16_t queue_id,
 			(desc->len == vq->vhost_hlen)) {
 			desc = &vq->desc[desc->next];
 			/* Buffer address translation. */
-			buff_addr = gpa_to_vva(dev, desc->addr);
+			buff_addr = gpa_to_vva(dev, queue_id / VIRTIO_QNUM, desc->addr);
 		} else {
 			vb_offset += vq->vhost_hlen;
 			hdr = 1;
@@ -191,7 +191,7 @@ virtio_dev_rx(struct virtio_net *dev, uint16_t queue_id,
 			if (vb_offset == desc->len) {
 				if (desc->flags & VRING_DESC_F_NEXT) {
 					desc = &vq->desc[desc->next];
-					buff_addr = gpa_to_vva(dev, desc->addr);
+					buff_addr = gpa_to_vva(dev, queue_id, desc->addr);
 					vb_offset = 0;
 				} else {
 					/* Room in vring buffer is not enough */
@@ -281,8 +281,8 @@ copy_from_mbuf_to_vring(struct virtio_net *dev, uint16_t queue_id,
 	 * (guest physical addr -> vhost virtual addr)
 	 */
 	vq = dev->virtqueue[queue_id];
-	vb_addr =
-		gpa_to_vva(dev, vq->buf_vec[vec_idx].buf_addr);
+	vb_addr = gpa_to_vva(dev, queue_id / VIRTIO_QNUM,
+			vq->buf_vec[vec_idx].buf_addr);
 	vb_hdr_addr = vb_addr;
 
 	/* Prefetch buffer address. */
@@ -322,7 +322,8 @@ copy_from_mbuf_to_vring(struct virtio_net *dev, uint16_t queue_id,
 		}
 
 		vec_idx++;
-		vb_addr = gpa_to_vva(dev, vq->buf_vec[vec_idx].buf_addr);
+		vb_addr = gpa_to_vva(dev, queue_id / VIRTIO_QNUM,
+			vq->buf_vec[vec_idx].buf_addr);
 
 		/* Prefetch buffer address. */
 		rte_prefetch0((void *)(uintptr_t)vb_addr);
@@ -367,7 +368,7 @@ copy_from_mbuf_to_vring(struct virtio_net *dev, uint16_t queue_id,
 			}
 
 			vec_idx++;
-			vb_addr = gpa_to_vva(dev,
+			vb_addr = gpa_to_vva(dev, queue_id / VIRTIO_QNUM,
 				vq->buf_vec[vec_idx].buf_addr);
 			vb_offset = 0;
 			vb_avail = vq->buf_vec[vec_idx].buf_len;
@@ -410,7 +411,7 @@ copy_from_mbuf_to_vring(struct virtio_net *dev, uint16_t queue_id,
 
 					/* Get next buffer from buf_vec. */
 					vec_idx++;
-					vb_addr = gpa_to_vva(dev,
+					vb_addr = gpa_to_vva(dev, queue_id / VIRTIO_QNUM,
 						vq->buf_vec[vec_idx].buf_addr);
 					vb_avail =
 						vq->buf_vec[vec_idx].buf_len;
@@ -639,7 +640,7 @@ rte_vhost_dequeue_burst(struct virtio_net *dev, uint16_t queue_id,
 		}
 
 		/* Buffer address translation. */
-		vb_addr = gpa_to_vva(dev, desc->addr);
+		vb_addr = gpa_to_vva(dev, queue_id / VIRTIO_QNUM, desc->addr);
 		/* Prefetch buffer address. */
 		rte_prefetch0((void *)(uintptr_t)vb_addr);
 
@@ -743,7 +744,8 @@ rte_vhost_dequeue_burst(struct virtio_net *dev, uint16_t queue_id,
 					desc = &vq->desc[desc->next];
 
 					/* Buffer address translation. */
-					vb_addr = gpa_to_vva(dev, desc->addr);
+					vb_addr = gpa_to_vva(dev,
+						queue_id / VIRTIO_QNUM, desc->addr);
 					/* Prefetch buffer address. */
 					rte_prefetch0((void *)(uintptr_t)vb_addr);
 					vb_offset = 0;
diff --git a/lib/librte_vhost/vhost_user/virtio-net-user.c b/lib/librte_vhost/vhost_user/virtio-net-user.c
index 4c1d4df..d749f27 100644
--- a/lib/librte_vhost/vhost_user/virtio-net-user.c
+++ b/lib/librte_vhost/vhost_user/virtio-net-user.c
@@ -70,17 +70,17 @@ get_blk_size(int fd)
 }
 
 static void
-free_mem_region(struct virtio_net *dev)
+free_mem_region(struct virtio_memory *dev_mem)
 {
 	struct orig_region_map *region;
 	unsigned int idx;
 	uint64_t alignment;
 
-	if (!dev || !dev->mem)
+	if (!dev_mem)
 		return;
 
-	region = orig_region(dev->mem, dev->mem->nregions);
-	for (idx = 0; idx < dev->mem->nregions; idx++) {
+	region = orig_region(dev_mem, dev_mem->nregions);
+	for (idx = 0; idx < dev_mem->nregions; idx++) {
 		if (region[idx].mapped_address) {
 			alignment = region[idx].blksz;
 			munmap((void *)(uintptr_t)
@@ -103,37 +103,37 @@ user_set_mem_table(struct vhost_device_ctx ctx, struct VhostUserMsg *pmsg)
 	unsigned int idx = 0;
 	struct orig_region_map *pregion_orig;
 	uint64_t alignment;
+	struct virtio_memory *dev_mem = NULL;
 
 	/* unmap old memory regions one by one*/
 	dev = get_device(ctx);
 	if (dev == NULL)
 		return -1;
 
-	/* Remove from the data plane. */
-	if (dev->flags & VIRTIO_DEV_RUNNING)
-		notify_ops->destroy_device(dev);
-
-	if (dev->mem) {
-		free_mem_region(dev);
-		free(dev->mem);
-		dev->mem = NULL;
+	dev_mem = dev->mem_arr[dev->mem_idx];
+	if (dev_mem) {
+		free_mem_region(dev_mem);
+		free(dev_mem);
+		dev->mem_arr[dev->mem_idx] = NULL;
 	}
 
-	dev->mem = calloc(1,
+	dev->mem_arr[dev->mem_idx] = calloc(1,
 		sizeof(struct virtio_memory) +
 		sizeof(struct virtio_memory_regions) * memory.nregions +
 		sizeof(struct orig_region_map) * memory.nregions);
-	if (dev->mem == NULL) {
+
+	dev_mem = dev->mem_arr[dev->mem_idx];
+	if (dev_mem == NULL) {
 		RTE_LOG(ERR, VHOST_CONFIG,
-			"(%"PRIu64") Failed to allocate memory for dev->mem\n",
-			dev->device_fh);
+			"(%"PRIu64") Failed to allocate memory for dev->mem_arr[%d]\n",
+			dev->device_fh, dev->mem_idx);
 		return -1;
 	}
-	dev->mem->nregions = memory.nregions;
+	dev_mem->nregions = memory.nregions;
 
-	pregion_orig = orig_region(dev->mem, memory.nregions);
+	pregion_orig = orig_region(dev_mem, memory.nregions);
 	for (idx = 0; idx < memory.nregions; idx++) {
-		pregion = &dev->mem->regions[idx];
+		pregion = &dev_mem->regions[idx];
 		pregion->guest_phys_address =
 			memory.regions[idx].guest_phys_addr;
 		pregion->guest_phys_address_end =
@@ -175,9 +175,9 @@ user_set_mem_table(struct vhost_device_ctx ctx, struct VhostUserMsg *pmsg)
 			pregion->guest_phys_address;
 
 		if (memory.regions[idx].guest_phys_addr == 0) {
-			dev->mem->base_address =
+			dev_mem->base_address =
 				memory.regions[idx].userspace_addr;
-			dev->mem->mapped_address =
+			dev_mem->mapped_address =
 				pregion->address_offset;
 		}
 
@@ -189,6 +189,7 @@ user_set_mem_table(struct vhost_device_ctx ctx, struct VhostUserMsg *pmsg)
 			 pregion->memory_size);
 	}
 
+	dev->mem_idx = (dev->mem_idx + 1) % (dev->virt_qp_nb * VIRTIO_QNUM);
 	return 0;
 
 err_mmap:
@@ -200,8 +201,8 @@ err_mmap:
 					alignment));
 		close(pregion_orig[idx].fd);
 	}
-	free(dev->mem);
-	dev->mem = NULL;
+	free(dev_mem);
+	dev->mem_arr[dev->mem_idx] = NULL;
 	return -1;
 }
 
@@ -346,13 +347,15 @@ void
 user_destroy_device(struct vhost_device_ctx ctx)
 {
 	struct virtio_net *dev = get_device(ctx);
+	uint32_t i;
 
 	if (dev && (dev->flags & VIRTIO_DEV_RUNNING))
 		notify_ops->destroy_device(dev);
 
-	if (dev && dev->mem) {
-		free_mem_region(dev);
-		free(dev->mem);
-		dev->mem = NULL;
-	}
+	for (i = 0; i < dev->virt_qp_nb; i++)
+		if (dev && dev->mem_arr[i]) {
+			free_mem_region(dev->mem_arr[i]);
+			free(dev->mem_arr[i]);
+			dev->mem_arr[i] = NULL;
+		}
 }
diff --git a/lib/librte_vhost/virtio-net.c b/lib/librte_vhost/virtio-net.c
index 2a4b791..fd66a06 100644
--- a/lib/librte_vhost/virtio-net.c
+++ b/lib/librte_vhost/virtio-net.c
@@ -81,15 +81,16 @@ static uint64_t VHOST_FEATURES = VHOST_SUPPORTED_FEATURES;
  * used to convert the ring addresses to our address space.
  */
 static uint64_t
-qva_to_vva(struct virtio_net *dev, uint64_t qemu_va)
+qva_to_vva(struct virtio_net *dev, uint32_t q_idx, uint64_t qemu_va)
 {
 	struct virtio_memory_regions *region;
 	uint64_t vhost_va = 0;
 	uint32_t regionidx = 0;
+	struct virtio_memory *dev_mem = dev->mem_arr[q_idx];
 
 	/* Find the region where the address lives. */
-	for (regionidx = 0; regionidx < dev->mem->nregions; regionidx++) {
-		region = &dev->mem->regions[regionidx];
+	for (regionidx = 0; regionidx < dev_mem->nregions; regionidx++) {
+		region = &dev_mem->regions[regionidx];
 		if ((qemu_va >= region->userspace_address) &&
 			(qemu_va <= region->userspace_address +
 			region->memory_size)) {
@@ -186,10 +187,13 @@ cleanup_device(struct virtio_net *dev)
 	uint32_t qp_idx;
 
 	/* Unmap QEMU memory file if mapped. */
-	if (dev->mem) {
-		munmap((void *)(uintptr_t)dev->mem->mapped_address,
-			(size_t)dev->mem->mapped_size);
-		free(dev->mem);
+	for (qp_idx = 0; qp_idx < dev->virt_qp_nb; qp_idx++) {
+		struct virtio_memory *dev_mem = dev->mem_arr[qp_idx];
+		if (dev_mem) {
+			munmap((void *)(uintptr_t)dev_mem->mapped_address,
+				(size_t)dev_mem->mapped_size);
+			free(dev_mem);
+		}
 	}
 
 	/* Close any event notifiers opened by device. */
@@ -218,6 +222,8 @@ free_device(struct virtio_net_config_ll *ll_dev)
 	/*
 	 * Free any malloc'd memory.
 	 */
+	free(ll_dev->dev.mem_arr);
+
 	/* Free every queue pair. */
 	for (qp_idx = 0; qp_idx < ll_dev->dev.virt_qp_nb; qp_idx++) {
 		uint32_t virt_rx_q_idx = qp_idx * VIRTIO_QNUM + VIRTIO_RXQ;
@@ -289,7 +295,7 @@ init_device(struct virtio_net *dev)
 	 * Virtqueues have already been malloced so
 	 * we don't want to set them to NULL.
 	 */
-	vq_offset = offsetof(struct virtio_net, mem);
+	vq_offset = offsetof(struct virtio_net, features);
 
 	/* Set everything to 0. */
 	memset((void *)(uintptr_t)((uint64_t)(uintptr_t)dev + vq_offset), 0,
@@ -359,6 +365,16 @@ new_device(struct vhost_device_ctx ctx)
 		return -1;
 	}
 
+	new_ll_dev->dev.mem_arr =
+		calloc(VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MAX, sizeof(struct virtio_memory *));
+	if (new_ll_dev->dev.mem_arr == NULL) {
+		RTE_LOG(ERR, VHOST_CONFIG,
+			"(%"PRIu64") Failed to allocate memory for dev.mem_arr.\n",
+			ctx.fh);
+		free_device(new_ll_dev);
+		return -1;
+	}
+
 	/* Initialise device and virtqueues. */
 	init_device(&new_ll_dev->dev);
 
@@ -637,7 +653,7 @@ set_vring_addr(struct vhost_device_ctx ctx, struct vhost_vring_addr *addr)
 
 	/* The addresses are converted from QEMU virtual to Vhost virtual. */
 	vq->desc = (struct vring_desc *)(uintptr_t)qva_to_vva(dev,
-			addr->desc_user_addr);
+			addr->index / VIRTIO_QNUM, addr->desc_user_addr);
 	if (vq->desc == 0) {
 		RTE_LOG(ERR, VHOST_CONFIG,
 			"(%"PRIu64") Failed to find desc ring address.\n",
@@ -649,7 +665,7 @@ set_vring_addr(struct vhost_device_ctx ctx, struct vhost_vring_addr *addr)
 	vq = dev->virtqueue[addr->index];
 
 	vq->avail = (struct vring_avail *)(uintptr_t)qva_to_vva(dev,
-			addr->avail_user_addr);
+			addr->index / VIRTIO_QNUM, addr->avail_user_addr);
 	if (vq->avail == 0) {
 		RTE_LOG(ERR, VHOST_CONFIG,
 			"(%"PRIu64") Failed to find avail ring address.\n",
@@ -658,7 +674,7 @@ set_vring_addr(struct vhost_device_ctx ctx, struct vhost_vring_addr *addr)
 	}
 
 	vq->used = (struct vring_used *)(uintptr_t)qva_to_vva(dev,
-			addr->used_user_addr);
+			addr->index / VIRTIO_QNUM, addr->used_user_addr);
 	if (vq->used == 0) {
 		RTE_LOG(ERR, VHOST_CONFIG,
 			"(%"PRIu64") Failed to find used ring address.\n",
-- 
1.8.4.2

  parent reply	other threads:[~2015-08-12  8:03 UTC|newest]

Thread overview: 65+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-21  7:49 [dpdk-dev] [PATCH 0/6] Support multiple queues in vhost Ouyang Changchun
2015-05-21  7:49 ` [dpdk-dev] [PATCH 1/6] ixgbe: Support VMDq RSS in non-SRIOV environment Ouyang Changchun
2015-08-24 10:41   ` Qiu, Michael
2015-08-25  0:38     ` Ouyang, Changchun
2015-05-21  7:49 ` [dpdk-dev] [PATCH 2/6] lib_vhost: Support multiple queues in virtio dev Ouyang Changchun
2015-06-03  2:47   ` Xie, Huawei
2015-05-21  7:49 ` [dpdk-dev] [PATCH 3/6] lib_vhost: Set memory layout for multiple queues mode Ouyang Changchun
2015-06-02  3:33   ` Xie, Huawei
2015-05-21  7:49 ` [dpdk-dev] [PATCH 4/6] vhost: Add new command line option: rxq Ouyang Changchun
2015-05-22  1:39   ` Thomas F Herbert
2015-05-22  6:05     ` Ouyang, Changchun
2015-05-22 12:51       ` Thomas F Herbert
2015-05-23  1:25         ` Ouyang, Changchun
2015-05-26  7:21           ` Ouyang, Changchun
2015-05-21  7:49 ` [dpdk-dev] [PATCH 5/6] vhost: Support multiple queues Ouyang Changchun
2015-05-21  7:49 ` [dpdk-dev] [PATCH 6/6] virtio: Resolve for control queue Ouyang Changchun
2015-05-22  1:13 ` [dpdk-dev] [PATCH 0/6] Support multiple queues in vhost Thomas F Herbert
2015-05-22  6:08   ` Ouyang, Changchun
2015-06-10  5:52 ` [dpdk-dev] [PATCH v2 0/7] " Ouyang Changchun
2015-06-10  5:52   ` [dpdk-dev] [PATCH v2 1/7] ixgbe: Support VMDq RSS in non-SRIOV environment Ouyang Changchun
2015-06-10  5:52   ` [dpdk-dev] [PATCH v2 2/7] lib_vhost: Support multiple queues in virtio dev Ouyang Changchun
2015-06-11  9:54     ` Panu Matilainen
2015-06-10  5:52   ` [dpdk-dev] [PATCH v2 3/7] lib_vhost: Set memory layout for multiple queues mode Ouyang Changchun
2015-06-10  5:52   ` [dpdk-dev] [PATCH v2 4/7] vhost: Add new command line option: rxq Ouyang Changchun
2015-06-10  5:52   ` [dpdk-dev] [PATCH v2 5/7] vhost: Support multiple queues Ouyang Changchun
2015-06-10  5:52   ` [dpdk-dev] [PATCH v2 6/7] virtio: Resolve for control queue Ouyang Changchun
2015-06-10  5:52   ` [dpdk-dev] [PATCH v2 7/7] vhost: Add per queue stats info Ouyang Changchun
2015-06-15  7:56   ` [dpdk-dev] [PATCH v3 0/9] Support multiple queues in vhost Ouyang Changchun
2015-06-15  7:56     ` [dpdk-dev] [PATCH v3 1/9] ixgbe: Support VMDq RSS in non-SRIOV environment Ouyang Changchun
2015-06-15  7:56     ` [dpdk-dev] [PATCH v3 2/9] lib_vhost: Support multiple queues in virtio dev Ouyang Changchun
2015-06-18 13:16       ` Flavio Leitner
2015-06-19  1:06         ` Ouyang, Changchun
2015-06-18 13:34       ` Flavio Leitner
2015-06-19  1:17         ` Ouyang, Changchun
2015-06-15  7:56     ` [dpdk-dev] [PATCH v3 3/9] lib_vhost: Set memory layout for multiple queues mode Ouyang Changchun
2015-06-15  7:56     ` [dpdk-dev] [PATCH v3 4/9] lib_vhost: Check the virtqueue address's validity Ouyang Changchun
2015-06-15  7:56     ` [dpdk-dev] [PATCH v3 5/9] vhost: Add new command line option: rxq Ouyang Changchun
2015-06-15  7:56     ` [dpdk-dev] [PATCH v3 6/9] vhost: Support multiple queues Ouyang Changchun
2015-06-15  7:56     ` [dpdk-dev] [PATCH v3 7/9] virtio: Resolve for control queue Ouyang Changchun
2015-06-15  7:56     ` [dpdk-dev] [PATCH v3 8/9] vhost: Add per queue stats info Ouyang Changchun
2015-06-15  7:56     ` [dpdk-dev] [PATCH v3 9/9] doc: Update doc for vhost multiple queues Ouyang Changchun
2015-08-12  8:02     ` [dpdk-dev] [PATCH v4 00/12] Support multiple queues in vhost Ouyang Changchun
2015-08-12  8:02       ` [dpdk-dev] [PATCH v4 01/12] ixgbe: support VMDq RSS in non-SRIOV environment Ouyang Changchun
2015-08-12  8:22         ` Vincent JARDIN
2015-08-12  8:02       ` [dpdk-dev] [PATCH v4 02/12] vhost: support multiple queues in virtio dev Ouyang Changchun
2015-08-13 12:52         ` Flavio Leitner
2015-08-14  2:29           ` Ouyang, Changchun
2015-08-14 12:16             ` Flavio Leitner
2015-08-19  3:52         ` Yuanhan Liu
2015-08-19  5:54           ` Ouyang, Changchun
2015-08-19  6:28             ` Yuanhan Liu
2015-08-19  6:39               ` Yuanhan Liu
2015-09-03  2:27         ` Tetsuya Mukawa
2015-09-06  2:25           ` Ouyang, Changchun
2015-08-12  8:02       ` [dpdk-dev] [PATCH v4 03/12] vhost: update version map file Ouyang Changchun
2015-08-12  8:24         ` Panu Matilainen
2015-08-12  8:02       ` Ouyang Changchun [this message]
2015-08-12  8:02       ` [dpdk-dev] [PATCH v4 05/12] vhost: check the virtqueue address's validity Ouyang Changchun
2015-08-12  8:02       ` [dpdk-dev] [PATCH v4 06/12] vhost: support protocol feature Ouyang Changchun
2015-08-12  8:02       ` [dpdk-dev] [PATCH v4 07/12] vhost: add new command line option: rxq Ouyang Changchun
2015-08-12  8:02       ` [dpdk-dev] [PATCH v4 08/12] vhost: support multiple queues Ouyang Changchun
2015-08-12  8:02       ` [dpdk-dev] [PATCH v4 09/12] virtio: resolve for control queue Ouyang Changchun
2015-08-12  8:02       ` [dpdk-dev] [PATCH v4 10/12] vhost: add per queue stats info Ouyang Changchun
2015-08-12  8:02       ` [dpdk-dev] [PATCH v4 11/12] vhost: alloc core to virtq Ouyang Changchun
2015-08-12  8:02       ` [dpdk-dev] [PATCH v4 12/12] doc: update doc for vhost multiple queues Ouyang Changchun

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1439366567-3402-5-git-send-email-changchun.ouyang@intel.com \
    --to=changchun.ouyang@intel.com \
    --cc=dev@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).