[dpdk-dev] [PATCH v5 3/8] virtio: enable use virtual address to fill desc

Yuanhan Liu yuanhan.liu at linux.intel.com
Wed Jun 1 10:03:41 CEST 2016


On Mon, May 30, 2016 at 10:55:34AM +0000, Jianfeng Tan wrote:
> This patch is related to how to calculate relative address for vhost
> backend.
> 
> The principle is that: based on one or multiple shared memory regions,
> vhost maintains a reference system with the frontend start address,
> backend start address, and length for each segment, so that each
> frontend address (GPA, Guest Physical Address) can be translated into
> vhost-recognizable backend address. To make the address translation
> efficient, we need to maintain as few regions as possible. In the case
> of VM, GPA is always locally continuous. But for some other case, like
> virtio-user, we use virtual address here.
> 
> It basically means:
>   a. when set_base_addr, VA address is used;
>   b. when preparing RX's descriptors, VA address is used;
>   c. when transmitting packets, VA is filled in TX's descriptors;
>   d. in TX and CQ's header, VA is used.
> 
> Signed-off-by: Huawei Xie <huawei.xie at intel.com>
> Signed-off-by: Jianfeng Tan <jianfeng.tan at intel.com>
> Acked-by: Neil Horman <nhorman at tuxdriver.com>
> ---
>  drivers/net/virtio/virtio_ethdev.c      | 21 ++++++++++++++++-----
>  drivers/net/virtio/virtio_rxtx.c        |  5 ++---
>  drivers/net/virtio/virtio_rxtx_simple.c | 13 +++++++------
>  drivers/net/virtio/virtqueue.h          | 13 ++++++++++++-
>  4 files changed, 37 insertions(+), 15 deletions(-)
> 
> @@ -419,8 +419,6 @@ int virtio_dev_queue_setup(struct rte_eth_dev *dev,
>  		vq->virtio_net_hdr_mem = hdr_mz->phys_addr;
>  
>  		memset(hdr_mz->addr, 0, hdr_mz_sz);
> -		vring_hdr_desc_init(vq);
> -
>  	} else if (queue_type == VTNET_CQ) {
>  		/* Allocate a page for control vq command, data and status */
>  		snprintf(vq_name, sizeof(vq_name), "port%d_cvq_hdrzone",
> @@ -441,6 +439,19 @@ int virtio_dev_queue_setup(struct rte_eth_dev *dev,
>  		memset(vq->virtio_net_hdr_mz->addr, 0, PAGE_SIZE);
>  	}
>  
> +	if (dev->pci_dev)
> +		vq->offset = offsetof(struct rte_mbuf, buf_physaddr);
> +	else {
> +		vq->vq_ring_mem = (phys_addr_t)vq->mz->addr;
> +		vq->offset = offsetof(struct rte_mbuf, buf_addr);
> +		if (vq->virtio_net_hdr_mz)
> +			vq->virtio_net_hdr_mem =
> +				(phys_addr_t)vq->virtio_net_hdr_mz->addr;
> +	}

I guess this piece of code deserves some comments. Say, for virtio-user
case (that is when dev->pci_dev is NULL), we use virtual address,
because, bala, bala ...


> @@ -165,6 +173,7 @@ struct virtqueue {
>  	void        *vq_ring_virt_mem;    /**< linear address of vring*/
>  	unsigned int vq_ring_size;
>  	phys_addr_t vq_ring_mem;          /**< physical address of vring */
> +					  /**< use virtual address for vdev. */

Replace vdev with "virtio-user" is better here?

	--yliu


More information about the dev mailing list