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 D93C8A04F9 for ; Thu, 9 Jan 2020 18:59:00 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id CBB781E540; Thu, 9 Jan 2020 18:59:00 +0100 (CET) Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) by dpdk.org (Postfix) with ESMTP id 4D9FB1E547 for ; Thu, 9 Jan 2020 18:58:58 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1578592738; 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=2JNI0QuiLlw/ma3UcdeUSsgi8o0L7r0yWwWWxdw/5oQ=; b=Ld1G15sHnb+akz3zSmh+AcenKQ9fsgMVLHHFZ3B0tlhvQ/sadhGECrejoKiS+6QeXtxw6v kQgda38fISGuw9v/CV5Lb5NFnb+wqSOw/Ufkc46+5dubXpiQuAQ1Dp6XlK3efBwtpeYkre cs9bgs0IpvIY1C75TOxrSvmN/HyVZcc= 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-138-mwptdHNHOAaICaDe4O2IPA-1; Thu, 09 Jan 2020 12:58:55 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6F0F7107ACC5; Thu, 9 Jan 2020 17:58:54 +0000 (UTC) Received: from amorenoz.users.ipa.redhat.com (ovpn-117-44.ams2.redhat.com [10.36.117.44]) by smtp.corp.redhat.com (Postfix) with ESMTP id 624037C3B5; Thu, 9 Jan 2020 17:58:53 +0000 (UTC) From: Adrian Moreno To: stable@dpdk.org Cc: luca.boccassi@gmail.com, maxime.coquelin@redhat.com, Adrian Moreno Date: Thu, 9 Jan 2020 18:58:42 +0100 Message-Id: <20200109175842.24905-3-amorenoz@redhat.com> In-Reply-To: <20200109175842.24905-1-amorenoz@redhat.com> References: <20200109175842.24905-1-amorenoz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-MC-Unique: mwptdHNHOAaICaDe4O2IPA-1 X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Subject: [dpdk-stable] [PATCH 17.11 2/2] 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 --- 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 | 18 +++++++++------- 4 files changed, 82 insertions(+), 9 deletions(-) diff --git a/lib/librte_vhost/rte_vhost.h b/lib/librte_vhost/rte_vhost.h index 3fc6034de..eccaa3ed5 100644 --- a/lib/librte_vhost/rte_vhost.h +++ b/lib/librte_vhost/rte_vhost.h @@ -204,7 +204,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 4b4ef56e1..6a8f54fba 100644 --- a/lib/librte_vhost/vhost.c +++ b/lib/librte_vhost/vhost.c @@ -156,6 +156,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) { @@ -244,6 +264,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); +} + static void cleanup_vq(struct vhost_virtqueue *vq, int destroy) { diff --git a/lib/librte_vhost/vhost.h b/lib/librte_vhost/vhost.h index 34e2ecc4c..aa4c4c941 100644 --- a/lib/librte_vhost/vhost.h +++ b/lib/librte_vhost/vhost.h @@ -274,9 +274,14 @@ struct virtio_net { 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) @@ -314,6 +319,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 b302c384d..b8f43900d 100644 --- a/lib/librte_vhost/virtio_net.c +++ b/lib/librte_vhost/virtio_net.c @@ -161,7 +161,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} } @@ -278,7 +279,7 @@ copy_mbuf_to_desc(struct virtio_net *dev, struct vhost_= virtqueue *vq, =09=09virtio_enqueue_offload(m, =09=09=09=09(struct virtio_net_hdr *)(uintptr_t)desc_addr); =09=09PRINT_PACKET(dev, (uintptr_t)desc_addr, dev->vhost_hlen, 0); -=09=09vhost_log_cache_write(dev, vq, desc_gaddr, dev->vhost_hlen); +=09=09vhost_log_cache_write_iova(dev, vq, desc_gaddr, dev->vhost_hlen); =09} else { =09=09struct virtio_net_hdr vnet_hdr; =09=09uint64_t remain =3D dev->vhost_hlen; @@ -301,7 +302,7 @@ copy_mbuf_to_desc(struct virtio_net *dev, struct vhost_= virtqueue *vq, =09=09=09=09=09(void *)(uintptr_t)src, len); =20 =09=09=09PRINT_PACKET(dev, (uintptr_t)dst, (uint32_t)len, 0); -=09=09=09vhost_log_cache_write(dev, vq, guest_addr, len); +=09=09=09vhost_log_cache_write_iova(dev, vq, guest_addr, len); =09=09=09remain -=3D len; =09=09=09guest_addr +=3D len; =09=09=09dst +=3D len; @@ -382,8 +383,9 @@ copy_mbuf_to_desc(struct virtio_net *dev, struct vhost_= virtqueue *vq, =09=09=09=09=09=09=09desc_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, desc_gaddr + desc_offset, -=09=09=09=09=09cpy_len); +=09=09=09vhost_log_cache_write_iova(dev, vq, +=09=09=09=09=09=09 desc_gaddr + desc_offset, +=09=09=09=09=09=09 cpy_len); =09=09=09PRINT_PACKET(dev, (uintptr_t)(desc_addr + desc_offset), =09=09=09=09 cpy_len, 0); =09=09} else { @@ -808,7 +810,7 @@ copy_mbuf_to_desc_mergeable(struct virtio_net *dev, str= uct vhost_virtqueue *vq, =20 =09=09=09=09=09PRINT_PACKET(dev, (uintptr_t)dst, =09=09=09=09=09=09=09(uint32_t)len, 0); -=09=09=09=09=09vhost_log_cache_write(dev, vq, +=09=09=09=09=09vhost_log_cache_write_iova(dev, vq, =09=09=09=09=09=09=09guest_addr, len); =20 =09=09=09=09=09remain -=3D len; @@ -818,7 +820,7 @@ copy_mbuf_to_desc_mergeable(struct virtio_net *dev, str= uct 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, hdr_phys_addr, +=09=09=09=09vhost_log_cache_write_iova(dev, vq, hdr_phys_addr, =09=09=09=09=09=09dev->vhost_hlen); =09=09=09} =20 @@ -832,7 +834,7 @@ copy_mbuf_to_desc_mergeable(struct virtio_net *dev, str= uct vhost_virtqueue *vq, =09=09=09=09=09=09=09desc_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, desc_gaddr + desc_offset, +=09=09=09vhost_log_cache_write_iova(dev, vq, desc_gaddr + desc_offset, =09=09=09=09=09cpy_len); =09=09=09PRINT_PACKET(dev, (uintptr_t)(desc_addr + desc_offset), =09=09=09=09cpy_len, 0); --=20 2.21.1