From patchwork Mon Oct 16 14:22:17 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 30435 X-Patchwork-Delegate: yuanhan.liu@linux.intel.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 91A7A1B724; Mon, 16 Oct 2017 16:22:40 +0200 (CEST) Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by dpdk.org (Postfix) with ESMTP id 9C53D1B6E7 for ; Mon, 16 Oct 2017 16:22:39 +0200 (CEST) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 81BDB883CA; Mon, 16 Oct 2017 14:22:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 81BDB883CA Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=maxime.coquelin@redhat.com Received: from localhost.localdomain (ovpn-112-40.ams2.redhat.com [10.36.112.40]) by smtp.corp.redhat.com (Postfix) with ESMTP id 851F75E1BA; Mon, 16 Oct 2017 14:22:33 +0000 (UTC) From: Maxime Coquelin To: lei.a.yao@intel.com, yliu@fridaylinux.org, dev@dpdk.org Cc: jfreiman@redhat.com, thomas@monjalon.net, Maxime Coquelin Date: Mon, 16 Oct 2017 16:22:17 +0200 Message-Id: <20171016142217.19646-1-maxime.coquelin@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Mon, 16 Oct 2017 14:22:38 +0000 (UTC) Subject: [dpdk-dev] [PATCH] vhost: translate addrs in set_vring_addr if ring already enabled X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Commit 3ea7052f4b1b ("vhost: postpone rings addresses translation") moves rings addresses translation at either vring kick or enable time, depending on whether protocol features are enabled or not. This is done not interpret ring information as long as the vring is not fully initialized. The problem is that with old QEMU versions, like v2.5, the ring is enabled before addresses are sent, so addresses are never translated. This patch fixes the issue by doing the translation in VHOST_USER_SET_VRING_ADDR handling if ring is already enabled. Reported-by: Yao, Lei A Fixes: 3ea7052f4b1b ("vhost: postpone rings addresses translation") Signed-off-by: Maxime Coquelin --- lib/librte_vhost/vhost_user.c | 66 +++++++++++++++++++++++++------------------ 1 file changed, 38 insertions(+), 28 deletions(-) diff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c index 76c4eeca5..1f6cba4b9 100644 --- a/lib/librte_vhost/vhost_user.c +++ b/lib/librte_vhost/vhost_user.c @@ -372,33 +372,6 @@ ring_addr_to_vva(struct virtio_net *dev, struct vhost_virtqueue *vq, return qva_to_vva(dev, ra); } -/* - * The virtio device sends us the desc, used and avail ring addresses. - * This function then converts these to our address space. - */ -static int -vhost_user_set_vring_addr(struct virtio_net *dev, VhostUserMsg *msg) -{ - struct vhost_virtqueue *vq; - struct vhost_vring_addr *addr = &msg->payload.addr; - - if (dev->mem == NULL) - return -1; - - /* addr->index refers to the queue index. The txq 1, rxq is 0. */ - vq = dev->virtqueue[msg->payload.addr.index]; - - /* - * Rings addresses should not be interpreted as long as the ring is not - * started and enabled - */ - memcpy(&vq->ring_addrs, addr, sizeof(*addr)); - - vring_invalidate(dev, vq); - - return 0; -} - static struct virtio_net * translate_ring_addresses(struct virtio_net *dev, int vq_index) { @@ -464,6 +437,43 @@ translate_ring_addresses(struct virtio_net *dev, int vq_index) } /* + * The virtio device sends us the desc, used and avail ring addresses. + * This function then converts these to our address space. + */ +static int +vhost_user_set_vring_addr(struct virtio_net **pdev, VhostUserMsg *msg) +{ + struct vhost_virtqueue *vq; + struct vhost_vring_addr *addr = &msg->payload.addr; + struct virtio_net *dev = *pdev; + + if (dev->mem == NULL) + return -1; + + /* addr->index refers to the queue index. The txq 1, rxq is 0. */ + vq = dev->virtqueue[msg->payload.addr.index]; + + /* + * Rings addresses should not be interpreted as long as the ring is not + * started and enabled + */ + memcpy(&vq->ring_addrs, addr, sizeof(*addr)); + + vring_invalidate(dev, vq); + + if (vq->enabled && (dev->features & + (1ULL << VHOST_USER_F_PROTOCOL_FEATURES))) { + dev = translate_ring_addresses(dev, msg->payload.state.index); + if (!dev) + return -1; + + *pdev = dev; + } + + return 0; +} + +/* * The virtio device sends us the available ring last used index. */ static int @@ -1273,7 +1283,7 @@ vhost_user_msg_handler(int vid, int fd) vhost_user_set_vring_num(dev, &msg); break; case VHOST_USER_SET_VRING_ADDR: - vhost_user_set_vring_addr(dev, &msg); + vhost_user_set_vring_addr(&dev, &msg); break; case VHOST_USER_SET_VRING_BASE: vhost_user_set_vring_base(dev, &msg);