From mboxrd@z Thu Jan 1 00:00:00 1970 From: Stephen Hemminger Subject: Re: [PATCH] virtio: fix the vq size issue Date: Fri, 17 Jul 2015 09:27:56 -0700 Message-ID: <20150717092756.16d7265e@urahara> References: <1435736930-26737-1-git-send-email-changchun.ouyang@intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Cc: dev@dpdk.org To: Ouyang Changchun Return-path: Received: from mail-pa0-f42.google.com (mail-pa0-f42.google.com [209.85.220.42]) by dpdk.org (Postfix) with ESMTP id 674D1569D for ; Fri, 17 Jul 2015 18:27:48 +0200 (CEST) Received: by pacan13 with SMTP id an13so63598909pac.1 for ; Fri, 17 Jul 2015 09:27:47 -0700 (PDT) In-Reply-To: <1435736930-26737-1-git-send-email-changchun.ouyang@intel.com> List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" On Wed, 1 Jul 2015 15:48:50 +0800 Ouyang Changchun wrote: > This commit breaks virtio basic packets rx functionality: > d78deadae4dca240e85054bf2d604a801676becc > > The QEMU use 256 as default vring size, also use this default value to calculate the virtio > avail ring base address and used ring base address, and vhost in the backend use the ring base > address to do packet IO. > > Virtio spec also says the queue size in PCI configuration is read-only, so virtio front end > can't change it. just need use the read-only value to allocate space for vring and calculate the > avail and used ring base address. Otherwise, the avail and used ring base address will be different > between host and guest, accordingly, packet IO can't work normally. > > Signed-off-by: Changchun Ouyang > --- > drivers/net/virtio/virtio_ethdev.c | 14 +++----------- > 1 file changed, 3 insertions(+), 11 deletions(-) > > diff --git a/drivers/net/virtio/virtio_ethdev.c b/drivers/net/virtio/virtio_ethdev.c > index fe5f9a1..d84de13 100644 > --- a/drivers/net/virtio/virtio_ethdev.c > +++ b/drivers/net/virtio/virtio_ethdev.c > @@ -263,8 +263,6 @@ int virtio_dev_queue_setup(struct rte_eth_dev *dev, > */ > vq_size = VIRTIO_READ_REG_2(hw, VIRTIO_PCI_QUEUE_NUM); > PMD_INIT_LOG(DEBUG, "vq_size: %d nb_desc:%d", vq_size, nb_desc); > - if (nb_desc == 0) > - nb_desc = vq_size; command queue is setup with nb_desc = 0 > if (vq_size == 0) { > PMD_INIT_LOG(ERR, "%s: virtqueue does not exist", __func__); > return -EINVAL; > @@ -275,15 +273,9 @@ int virtio_dev_queue_setup(struct rte_eth_dev *dev, > return -EINVAL; > } > > - if (nb_desc < vq_size) { > - if (!rte_is_power_of_2(nb_desc)) { > - PMD_INIT_LOG(ERR, > - "nb_desc(%u) size is not powerof 2", > - nb_desc); > - return -EINVAL; > - } > - vq_size = nb_desc; > - } > + if (nb_desc != vq_size) > + PMD_INIT_LOG(ERR, "Warning: nb_desc(%d) is not equal to vq size (%d), fall to vq size", > + nb_desc, vq_size); Nack. This breaks onn Google Compute Engine the vring size is 16K. An application that wants to work on both QEMU and GCE will want to pass a reasonable size and have the negotiation resolve to best value. For example, vRouter passes 512 as Rx ring size. On QEMU this gets rounded down to 256 and on GCE only 512 elements are used. This is what the Linux kernel virtio does.