From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 19ED4A0500 for ; Tue, 17 Dec 2019 19:07:13 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 111C81BE9E; Tue, 17 Dec 2019 19:07:13 +0100 (CET) Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) by dpdk.org (Postfix) with ESMTP id E2F851BE9E for ; Tue, 17 Dec 2019 19:07:11 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1576606031; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ObXQuzSg8LuUC0jlUkUr5FKssE+3i9dJ6QB735L6PD4=; b=P7aGdGL7Ps0YQD5iM2NObDQYTWTpUH4gZeFHK6ESys88kIh1sXZL4zDCSA1BFoTwvfrRXB 4bvqoLgZ2QR8g1Xo/kpBLUPDyguTBILx1s/gd4mn9Jqq0FWOGwBW/eOZkMhZRC7QWtgH5p 92EsfyiNtFn3s8pEsh0+esvXHDmmPZc= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-45-SEYwqZgrOsqMWH9uL1jsYg-1; Tue, 17 Dec 2019 13:07:09 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B511D8017DF for ; Tue, 17 Dec 2019 18:07:08 +0000 (UTC) Received: from amorenoz.users.ipa.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3B1E57C839; Tue, 17 Dec 2019 18:07:05 +0000 (UTC) From: Adrian Moreno To: stable@dpdk.org Cc: ktraynor@redhat.com, maxime.coquelin@redhat.com, Adrian Moreno Date: Tue, 17 Dec 2019 19:06:40 +0100 Message-Id: <20191217180640.17993-8-amorenoz@redhat.com> In-Reply-To: <20191217180640.17993-1-amorenoz@redhat.com> References: <20191217180640.17993-1-amorenoz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-MC-Unique: SEYwqZgrOsqMWH9uL1jsYg-1 X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Subject: [dpdk-stable] [PATCH 18.11 7/7] vhost: convert buffer addresses to GPA for logging X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org Sender: "stable" [ upstream commit 1fc3b3f06aa9c79c749e8587859d75d237ba9161 ] Add IOVA versions of dirty page logging functions. Note that the API facing rte_vhost_log_write is not modified. So, make explicit that it expects the address in GPA space. Fixes: 69c90e98f483 ("vhost: enable IOMMU support") Cc: stable@dpdk.org Signed-off-by: Adrian Moreno Reviewed-by: Maxime Coquelin Conflicts: =09lib/librte_vhost/vdpa.c: Due to not having [1] [1] b13ad2dec vhost: provide helpers for virtio ring relay --- lib/librte_vhost/rte_vhost.h | 2 +- lib/librte_vhost/vhost.c | 40 +++++++++++++++++++++++++++++++++++ lib/librte_vhost/vhost.h | 31 +++++++++++++++++++++++++++ lib/librte_vhost/virtio_net.c | 12 ++++++----- 4 files changed, 79 insertions(+), 6 deletions(-) diff --git a/lib/librte_vhost/rte_vhost.h b/lib/librte_vhost/rte_vhost.h index ae96ed715..ce1f12e1d 100644 --- a/lib/librte_vhost/rte_vhost.h +++ b/lib/librte_vhost/rte_vhost.h @@ -225,7 +225,7 @@ rte_vhost_va_from_guest_pa(struct rte_vhost_memory *mem= , * @param vid * vhost device ID * @param addr - * the starting address for write + * the starting address for write (in guest physical address space) * @param len * the length to write */ diff --git a/lib/librte_vhost/vhost.c b/lib/librte_vhost/vhost.c index 1b62fde68..f00efb382 100644 --- a/lib/librte_vhost/vhost.c +++ b/lib/librte_vhost/vhost.c @@ -115,6 +115,26 @@ __vhost_log_write(struct virtio_net *dev, uint64_t add= r, uint64_t len) =09} } =20 +void +__vhost_log_write_iova(struct virtio_net *dev, struct vhost_virtqueue *vq, +=09=09=09 uint64_t iova, uint64_t len) +{ +=09uint64_t hva, gpa, map_len; +=09map_len =3D len; + +=09hva =3D __vhost_iova_to_vva(dev, vq, iova, &map_len, VHOST_ACCESS_RW); +=09if (map_len !=3D len) { +=09=09RTE_LOG(ERR, VHOST_CONFIG, +=09=09=09"Failed to write log for IOVA 0x%" PRIx64 ". No IOTLB entry found= \n", +=09=09=09iova); +=09=09return; +=09} + +=09gpa =3D hva_to_gpa(dev, hva, len); +=09if (gpa) +=09=09__vhost_log_write(dev, gpa, len); +} + void __vhost_log_cache_sync(struct virtio_net *dev, struct vhost_virtqueue *vq) { @@ -200,6 +220,26 @@ __vhost_log_cache_write(struct virtio_net *dev, struct= vhost_virtqueue *vq, =09} } =20 +void +__vhost_log_cache_write_iova(struct virtio_net *dev, struct vhost_virtqueu= e *vq, +=09=09=09 uint64_t iova, uint64_t len) +{ +=09uint64_t hva, gpa, map_len; +=09map_len =3D len; + +=09hva =3D __vhost_iova_to_vva(dev, vq, iova, &map_len, VHOST_ACCESS_RW); +=09if (map_len !=3D len) { +=09=09RTE_LOG(ERR, VHOST_CONFIG, +=09=09=09"Failed to write log for IOVA 0x%" PRIx64 ". No IOTLB entry found= \n", +=09=09=09iova); +=09=09return; +=09} + +=09gpa =3D hva_to_gpa(dev, hva, len); +=09if (gpa) +=09=09__vhost_log_cache_write(dev, vq, gpa, len); +} + void * vhost_alloc_copy_ind_table(struct virtio_net *dev, struct vhost_virtqueue = *vq, =09=09uint64_t desc_addr, uint64_t desc_len) diff --git a/lib/librte_vhost/vhost.h b/lib/librte_vhost/vhost.h index 5a857b155..4279db95a 100644 --- a/lib/librte_vhost/vhost.h +++ b/lib/librte_vhost/vhost.h @@ -402,9 +402,14 @@ desc_is_avail(struct vring_packed_desc *desc, bool wra= p_counter) void __vhost_log_cache_write(struct virtio_net *dev, =09=09struct vhost_virtqueue *vq, =09=09uint64_t addr, uint64_t len); +void __vhost_log_cache_write_iova(struct virtio_net *dev, +=09=09struct vhost_virtqueue *vq, +=09=09uint64_t iova, uint64_t len); void __vhost_log_cache_sync(struct virtio_net *dev, =09=09struct vhost_virtqueue *vq); void __vhost_log_write(struct virtio_net *dev, uint64_t addr, uint64_t len= ); +void __vhost_log_write_iova(struct virtio_net *dev, struct vhost_virtqueue= *vq, +=09=09=09 uint64_t iova, uint64_t len); =20 static __rte_always_inline void vhost_log_write(struct virtio_net *dev, uint64_t addr, uint64_t len) @@ -442,6 +447,32 @@ vhost_log_used_vring(struct virtio_net *dev, struct vh= ost_virtqueue *vq, =09vhost_log_write(dev, vq->log_guest_addr + offset, len); } =20 +static __rte_always_inline void +vhost_log_cache_write_iova(struct virtio_net *dev, struct vhost_virtqueue = *vq, +=09=09=09 uint64_t iova, uint64_t len) +{ +=09if (likely(!(dev->features & (1ULL << VHOST_F_LOG_ALL)))) +=09=09return; + +=09if (dev->features & (1ULL << VIRTIO_F_IOMMU_PLATFORM)) +=09=09__vhost_log_cache_write_iova(dev, vq, iova, len); +=09else +=09=09__vhost_log_cache_write(dev, vq, iova, len); +} + +static __rte_always_inline void +vhost_log_write_iova(struct virtio_net *dev, struct vhost_virtqueue *vq, +=09=09=09 uint64_t iova, uint64_t len) +{ +=09if (likely(!(dev->features & (1ULL << VHOST_F_LOG_ALL)))) +=09=09return; + +=09if (dev->features & (1ULL << VIRTIO_F_IOMMU_PLATFORM)) +=09=09__vhost_log_write_iova(dev, vq, iova, len); +=09else +=09=09__vhost_log_write(dev, iova, len); +} + /* Macros for printing using RTE_LOG */ #define RTE_LOGTYPE_VHOST_CONFIG RTE_LOGTYPE_USER1 #define RTE_LOGTYPE_VHOST_DATA RTE_LOGTYPE_USER1 diff --git a/lib/librte_vhost/virtio_net.c b/lib/librte_vhost/virtio_net.c index 83046cc6b..ebeec8fd1 100644 --- a/lib/librte_vhost/virtio_net.c +++ b/lib/librte_vhost/virtio_net.c @@ -184,7 +184,8 @@ do_data_copy_enqueue(struct virtio_net *dev, struct vho= st_virtqueue *vq) =20 =09for (i =3D 0; i < count; i++) { =09=09rte_memcpy(elem[i].dst, elem[i].src, elem[i].len); -=09=09vhost_log_cache_write(dev, vq, elem[i].log_addr, elem[i].len); +=09=09vhost_log_cache_write_iova(dev, vq, elem[i].log_addr, +=09=09=09=09=09 elem[i].len); =09=09PRINT_PACKET(dev, (uintptr_t)elem[i].dst, elem[i].len, 0); =09} =20 @@ -640,7 +641,7 @@ copy_vnet_hdr_to_desc(struct virtio_net *dev, struct vh= ost_virtqueue *vq, =20 =09=09PRINT_PACKET(dev, (uintptr_t)dst, =09=09=09=09(uint32_t)len, 0); -=09=09vhost_log_cache_write(dev, vq, +=09=09vhost_log_cache_write_iova(dev, vq, =09=09=09=09iova, len); =20 =09=09remain -=3D len; @@ -740,7 +741,7 @@ copy_mbuf_to_desc(struct virtio_net *dev, struct vhost_= virtqueue *vq, =09=09=09} else { =09=09=09=09PRINT_PACKET(dev, (uintptr_t)hdr_addr, =09=09=09=09=09=09dev->vhost_hlen, 0); -=09=09=09=09vhost_log_cache_write(dev, vq, +=09=09=09=09vhost_log_cache_write_iova(dev, vq, =09=09=09=09=09=09buf_vec[0].buf_iova, =09=09=09=09=09=09dev->vhost_hlen); =09=09=09} @@ -755,8 +756,9 @@ copy_mbuf_to_desc(struct virtio_net *dev, struct vhost_= virtqueue *vq, =09=09=09rte_memcpy((void *)((uintptr_t)(buf_addr + buf_offset)), =09=09=09=09rte_pktmbuf_mtod_offset(m, void *, mbuf_offset), =09=09=09=09cpy_len); -=09=09=09vhost_log_cache_write(dev, vq, buf_iova + buf_offset, -=09=09=09=09=09cpy_len); +=09=09=09vhost_log_cache_write_iova(dev, vq, +=09=09=09=09=09=09 buf_iova + buf_offset, +=09=09=09=09=09=09 cpy_len); =09=09=09PRINT_PACKET(dev, (uintptr_t)(buf_addr + buf_offset), =09=09=09=09cpy_len, 0); =09=09} else { --=20 2.21.0