From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by dpdk.org (Postfix) with ESMTP id B15277CA9 for ; Thu, 31 Aug 2017 11:52:02 +0200 (CEST) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0E59337E88; Thu, 31 Aug 2017 09:52:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 0E59337E88 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=maxime.coquelin@redhat.com Received: from localhost.localdomain (ovpn-112-32.ams2.redhat.com [10.36.112.32]) by smtp.corp.redhat.com (Postfix) with ESMTP id B2170841C2; Thu, 31 Aug 2017 09:51:54 +0000 (UTC) From: Maxime Coquelin To: dev@dpdk.org, yliu@fridaylinux.org, jfreiman@redhat.com, tiwei.bie@intel.com Cc: mst@redhat.com, vkaplans@redhat.com, jasowang@redhat.com, Maxime Coquelin Date: Thu, 31 Aug 2017 11:50:14 +0200 Message-Id: <20170831095023.21037-13-maxime.coquelin@redhat.com> In-Reply-To: <20170831095023.21037-1-maxime.coquelin@redhat.com> References: <20170831095023.21037-1-maxime.coquelin@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Thu, 31 Aug 2017 09:52:02 +0000 (UTC) Subject: [dpdk-dev] [PATCH 12/21] vhost: introduce guest IOVA to backend VA helper 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: Thu, 31 Aug 2017 09:52:03 -0000 This patch introduces vhost_iova_to_vva() function to translate guest's IO virtual addresses to backend's virtual addresses. When IOMMU is enabled, the IOTLB cache is queried to get the translation. If missing from the IOTLB cache, an IOTLB_MISS request is sent to Qemu, and IOTLB cache is queried again on IOTLB event notification. When IOMMU is disabled, the passed address is a guest's physical address, so the legacy rte_vhost_gpa_to_vva() API is used. Signed-off-by: Maxime Coquelin --- lib/librte_vhost/vhost.c | 27 +++++++++++++++++++++++++++ lib/librte_vhost/vhost.h | 3 +++ 2 files changed, 30 insertions(+) diff --git a/lib/librte_vhost/vhost.c b/lib/librte_vhost/vhost.c index bae98b02d..0e8c0386a 100644 --- a/lib/librte_vhost/vhost.c +++ b/lib/librte_vhost/vhost.c @@ -48,9 +48,11 @@ #include #include #include +#include #include "iotlb.h" #include "vhost.h" +#include "vhost_user.h" struct vhost_device { struct virtio_net *dev; @@ -60,6 +62,31 @@ struct vhost_device { /* Declared as static so that .lock is initialized */ static struct vhost_device vhost_devices[MAX_VHOST_DEVICE]; +uint64_t vhost_iova_to_vva(struct virtio_net *dev, struct vhost_virtqueue *vq, + uint64_t iova, uint64_t size, uint8_t perm) +{ + uint64_t vva, tmp_size; + + if (unlikely(!size)) + return 0; + + if (!(dev->features & (1ULL << VIRTIO_F_IOMMU_PLATFORM))) + return rte_vhost_gpa_to_vva(dev->mem, iova); + + tmp_size = size; + + vva = vhost_user_iotlb_cache_find(vq, iova, &tmp_size, perm); + if (tmp_size == size) + return vva; + + if (!vhost_user_iotlb_pending_miss(vq, iova + tmp_size, perm)) { + vhost_user_iotlb_pending_insert(vq, iova + tmp_size, perm); + vhost_user_iotlb_miss(dev, iova + tmp_size, perm); + } + + return 0; +} + static inline struct virtio_net * __get_device(int vid) { diff --git a/lib/librte_vhost/vhost.h b/lib/librte_vhost/vhost.h index a41bacea7..2653ec123 100644 --- a/lib/librte_vhost/vhost.h +++ b/lib/librte_vhost/vhost.h @@ -352,4 +352,7 @@ struct vhost_device_ops const *vhost_driver_callback_get(const char *path); */ void vhost_backend_cleanup(struct virtio_net *dev); +uint64_t vhost_iova_to_vva(struct virtio_net *dev, struct vhost_virtqueue *vq, + uint64_t iova, uint64_t size, uint8_t perm); + #endif /* _VHOST_NET_CDEV_H_ */ -- 2.13.3