From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx1.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by dpdk.org (Postfix) with ESMTP id 9EAEF1BB4B for ; Fri, 22 Jun 2018 15:43:47 +0200 (CEST) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3C1F581A4EBE; Fri, 22 Jun 2018 13:43:47 +0000 (UTC) Received: from localhost.localdomain (ovpn-112-42.ams2.redhat.com [10.36.112.42]) by smtp.corp.redhat.com (Postfix) with ESMTP id 304952026D6B; Fri, 22 Jun 2018 13:43:45 +0000 (UTC) From: Maxime Coquelin To: tiwei.bie@intel.com, zhihong.wang@intel.com, jfreimann@redhat.com, dev@dpdk.org Cc: mst@redhat.com, jasowang@redhat.com, wexu@redhat.com, Yuanhan Liu , Jens Freimann , Maxime Coquelin Date: Fri, 22 Jun 2018 15:43:15 +0200 Message-Id: <20180622134327.18973-4-maxime.coquelin@redhat.com> In-Reply-To: <20180622134327.18973-1-maxime.coquelin@redhat.com> References: <20180622134327.18973-1-maxime.coquelin@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Fri, 22 Jun 2018 13:43:47 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Fri, 22 Jun 2018 13:43:47 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'maxime.coquelin@redhat.com' RCPT:'' Subject: [dpdk-dev] [PATCH v5 03/15] vhost: vring address setup for packed queues 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: , X-List-Received-Date: Fri, 22 Jun 2018 13:43:48 -0000 From: Yuanhan Liu Add code to set up packed queues when enabled. Signed-off-by: Yuanhan Liu Signed-off-by: Jens Freimann Signed-off-by: Maxime Coquelin --- lib/librte_vhost/vhost.c | 44 ++++++++++++++++++++++++++++++++++++++----- lib/librte_vhost/vhost.h | 7 ++++++- lib/librte_vhost/vhost_user.c | 29 +++++++++++++++++++++++++++- 3 files changed, 73 insertions(+), 7 deletions(-) diff --git a/lib/librte_vhost/vhost.c b/lib/librte_vhost/vhost.c index afded4952..a85c6646f 100644 --- a/lib/librte_vhost/vhost.c +++ b/lib/librte_vhost/vhost.c @@ -23,6 +23,7 @@ #include "iotlb.h" #include "vhost.h" #include "vhost_user.h" +#include "virtio-packed.h" struct virtio_net *vhost_devices[MAX_VHOST_DEVICE]; @@ -115,14 +116,11 @@ free_device(struct virtio_net *dev) rte_free(dev); } -int -vring_translate(struct virtio_net *dev, struct vhost_virtqueue *vq) +static int +vring_translate_split(struct virtio_net *dev, struct vhost_virtqueue *vq) { uint64_t req_size, size; - if (!(dev->features & (1ULL << VIRTIO_F_IOMMU_PLATFORM))) - goto out; - req_size = sizeof(struct vring_desc) * vq->size; size = req_size; vq->desc = (struct vring_desc *)(uintptr_t)vhost_iova_to_vva(dev, vq, @@ -153,6 +151,40 @@ vring_translate(struct virtio_net *dev, struct vhost_virtqueue *vq) if (!vq->used || size != req_size) return -1; + return 0; +} + +static int +vring_translate_packed(struct virtio_net *dev, struct vhost_virtqueue *vq) +{ + uint64_t req_size, size; + + req_size = sizeof(struct vring_desc_packed) * vq->size; + size = req_size; + vq->desc_packed = + (struct vring_desc_packed *)(uintptr_t)vhost_iova_to_vva(dev, + vq, vq->ring_addrs.desc_user_addr, + &size, VHOST_ACCESS_RW); + if (!vq->desc || size != req_size) + return -1; + + return 0; +} + +int +vring_translate(struct virtio_net *dev, struct vhost_virtqueue *vq) +{ + + if (!(dev->features & (1ULL << VIRTIO_F_IOMMU_PLATFORM))) + goto out; + + if (vq_is_packed(dev)) { + if (vring_translate_packed(dev, vq) < 0) + return -1; + } else { + if (vring_translate_split(dev, vq) < 0) + return -1; + } out: vq->access_ok = 1; @@ -234,6 +266,8 @@ alloc_vring_queue(struct virtio_net *dev, uint32_t vring_idx) dev->virtqueue[vring_idx] = vq; init_vring_queue(dev, vring_idx); rte_spinlock_init(&vq->access_lock); + vq->avail_wrap_counter = 1; + vq->used_wrap_counter = 1; dev->nr_vring += 1; diff --git a/lib/librte_vhost/vhost.h b/lib/librte_vhost/vhost.h index 34a614c97..671b4b3bf 100644 --- a/lib/librte_vhost/vhost.h +++ b/lib/librte_vhost/vhost.h @@ -84,7 +84,10 @@ struct log_cache_entry { * Structure contains variables relevant to RX/TX virtqueues. */ struct vhost_virtqueue { - struct vring_desc *desc; + union { + struct vring_desc *desc; + struct vring_desc_packed *desc_packed; + }; struct vring_avail *avail; struct vring_used *used; uint32_t size; @@ -122,6 +125,8 @@ struct vhost_virtqueue { struct batch_copy_elem *batch_copy_elems; uint16_t batch_copy_nb_elems; + uint16_t used_wrap_counter; + uint16_t avail_wrap_counter; struct log_cache_entry log_cache[VHOST_LOG_CACHE_NR]; uint16_t log_cache_nb_elem; diff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c index 947290fc3..b6097c085 100644 --- a/lib/librte_vhost/vhost_user.c +++ b/lib/librte_vhost/vhost_user.c @@ -39,6 +39,7 @@ #include "iotlb.h" #include "vhost.h" #include "vhost_user.h" +#include "virtio-packed.h" #define VIRTIO_MIN_MTU 68 #define VIRTIO_MAX_MTU 65535 @@ -477,6 +478,30 @@ translate_ring_addresses(struct virtio_net *dev, int vq_index) struct vhost_vring_addr *addr = &vq->ring_addrs; uint64_t len; + if (vq_is_packed(dev)) { + len = sizeof(struct vring_desc_packed) * vq->size; + vq->desc_packed = (struct vring_desc_packed *) ring_addr_to_vva + (dev, vq, addr->desc_user_addr, &len); + vq->desc = NULL; + vq->avail = NULL; + vq->used = NULL; + vq->log_guest_addr = 0; + if (vq->desc_packed == 0 || + len != sizeof(struct vring_desc_packed) * + vq->size) { + RTE_LOG(DEBUG, VHOST_CONFIG, + "(%d) failed to map desc_packed ring.\n", + dev->vid); + return dev; + } + + dev = numa_realloc(dev, vq_index); + vq = dev->virtqueue[vq_index]; + addr = &vq->ring_addrs; + + return dev; + } + /* The addresses are converted from QEMU virtual to Vhost virtual. */ if (vq->desc && vq->avail && vq->used) return dev; @@ -490,6 +515,7 @@ translate_ring_addresses(struct virtio_net *dev, int vq_index) dev->vid); return dev; } + vq->desc_packed = NULL; dev = numa_realloc(dev, vq_index); vq = dev->virtqueue[vq_index]; @@ -888,7 +914,8 @@ vhost_user_set_mem_table(struct virtio_net **pdev, struct VhostUserMsg *pmsg) static int vq_is_ready(struct vhost_virtqueue *vq) { - return vq && vq->desc && vq->avail && vq->used && + return vq && + (vq->desc_packed || (vq->desc && vq->avail && vq->used)) && vq->kickfd != VIRTIO_UNINITIALIZED_EVENTFD && vq->callfd != VIRTIO_UNINITIALIZED_EVENTFD; } -- 2.14.4