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 09EABA04B5 for ; Tue, 3 Dec 2019 19:27:52 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id EF49258C4; Tue, 3 Dec 2019 19:27:51 +0100 (CET) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by dpdk.org (Postfix) with ESMTP id 52CA21F5 for ; Tue, 3 Dec 2019 19:27:50 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1575397669; 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=n2Z3OeZuoHeM8tX3KK62+1hvn1uTOa2ydnXKVBDi9/s=; b=Ttn4+jwDjQ7UJtEDQcZg24xEBNPnbxQdEimsBrDmTTZwy30t0sr4tOf17dcsOMLx9dpBlP +MsSc/qOJkc6t1tOCacbGF1HTozZTGhx9+iu4+z5NWQQkkeKbXhsCw96Rxe/ZYJ+rcMPYf knjHZYo8qY/vpkRet9ZkI6Up+iqfgGs= 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-406-RE-KwJ_pOIKmCTrwnk8gJg-1; Tue, 03 Dec 2019 13:27:46 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 10BAC1005509 for ; Tue, 3 Dec 2019 18:27:46 +0000 (UTC) Received: from rh.redhat.com (ovpn-117-10.ams2.redhat.com [10.36.117.10]) by smtp.corp.redhat.com (Postfix) with ESMTP id 06A845C240; Tue, 3 Dec 2019 18:27:44 +0000 (UTC) From: Kevin Traynor To: Adrian Moreno Cc: Maxime Coquelin , dpdk stable Date: Tue, 3 Dec 2019 18:26:19 +0000 Message-Id: <20191203182714.17297-10-ktraynor@redhat.com> In-Reply-To: <20191203182714.17297-1-ktraynor@redhat.com> References: <20191203182714.17297-1-ktraynor@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-MC-Unique: RE-KwJ_pOIKmCTrwnk8gJg-1 X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Subject: [dpdk-stable] patch 'vhost: fix vring memory partially mapped' has been queued to LTS release 18.11.6 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" Hi, FYI, your patch has been queued to LTS release 18.11.6 Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet. It will be pushed if I get no objections before 12/10/19. So please shout if anyone has objections. Also note that after the patch there's a diff of the upstream commit vs the patch applied to the branch. This will indicate if there was any rebasing needed to apply to the stable branch. If there were code changes for rebasi= ng (ie: not only metadata diffs), please double check that the rebase was correctly done. Queued patches are on a temporary branch at: https://github.com/kevintraynor/dpdk-stable-queue This queued commit can be viewed at: https://github.com/kevintraynor/dpdk-stable-queue/commit/45b95bb27f259e814d= d4f1f6e4ecd5dd78441e8e Thanks. Kevin. --- >From 45b95bb27f259e814dd4f1f6e4ecd5dd78441e8e Mon Sep 17 00:00:00 2001 From: Adrian Moreno Date: Fri, 6 Sep 2019 14:50:20 +0200 Subject: [PATCH] vhost: fix vring memory partially mapped [ upstream commit 5d9dc18e1bccfe74c6fc962042d01147b49a5bed ] Only the mapping of the vring addresses is being ensured. This causes errors when the vring size is larger than the IOTLB page size. E.g: queue sizes > 256 for 4K IOTLB pages Ensure the entire vring memory range gets mapped. Refactor duplicated code for for IOTLB UPDATE and IOTLB INVALIDATE and add packed virtqueue support. Fixes: 09927b524969 ("vhost: translate ring addresses when IOMMU enabled") Signed-off-by: Adrian Moreno Reviewed-by: Maxime Coquelin --- lib/librte_vhost/vhost_user.c | 64 +++++++++++++++++++++-------------- 1 file changed, 39 insertions(+), 25 deletions(-) diff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c index bb74d0b93..0d318cd93 100644 --- a/lib/librte_vhost/vhost_user.c +++ b/lib/librte_vhost/vhost_user.c @@ -617,9 +617,11 @@ ring_addr_to_vva(struct virtio_net *dev, struct vhost_= virtqueue *vq, =09if (dev->features & (1ULL << VIRTIO_F_IOMMU_PLATFORM)) { =09=09uint64_t vva; +=09=09uint64_t req_size =3D *size; =20 =09=09vva =3D vhost_user_iotlb_cache_find(vq, ra, =09=09=09=09=09size, VHOST_ACCESS_RW); -=09=09if (!vva) -=09=09=09vhost_user_iotlb_miss(dev, ra, VHOST_ACCESS_RW); +=09=09if (req_size !=3D *size) +=09=09=09vhost_user_iotlb_miss(dev, (ra + *size), +=09=09=09=09=09 VHOST_ACCESS_RW); =20 =09=09return vva; @@ -1693,8 +1695,8 @@ vhost_user_set_req_fd(struct virtio_net **pdev, struc= t VhostUserMsg *msg, =20 static int -is_vring_iotlb_update(struct vhost_virtqueue *vq, struct vhost_iotlb_msg *= imsg) +is_vring_iotlb_split(struct vhost_virtqueue *vq, struct vhost_iotlb_msg *i= msg) { =09struct vhost_vring_addr *ra; -=09uint64_t start, end; +=09uint64_t start, end, len; =20 =09start =3D imsg->iova; @@ -1702,9 +1704,15 @@ is_vring_iotlb_update(struct vhost_virtqueue *vq, st= ruct vhost_iotlb_msg *imsg) =20 =09ra =3D &vq->ring_addrs; -=09if (ra->desc_user_addr >=3D start && ra->desc_user_addr < end) +=09len =3D sizeof(struct vring_desc) * vq->size; +=09if (ra->desc_user_addr < end && (ra->desc_user_addr + len) > start) =09=09return 1; -=09if (ra->avail_user_addr >=3D start && ra->avail_user_addr < end) + +=09len =3D sizeof(struct vring_avail) + sizeof(uint16_t) * vq->size; +=09if (ra->avail_user_addr < end && (ra->avail_user_addr + len) > start) =09=09return 1; -=09if (ra->used_user_addr >=3D start && ra->used_user_addr < end) + +=09len =3D sizeof(struct vring_used) + +=09 sizeof(struct vring_used_elem) * vq->size; +=09if (ra->used_user_addr < end && (ra->used_user_addr + len) > start) =09=09return 1; =20 @@ -1713,27 +1721,23 @@ is_vring_iotlb_update(struct vhost_virtqueue *vq, s= truct vhost_iotlb_msg *imsg) =20 static int -is_vring_iotlb_invalidate(struct vhost_virtqueue *vq, -=09=09=09=09struct vhost_iotlb_msg *imsg) +is_vring_iotlb_packed(struct vhost_virtqueue *vq, struct vhost_iotlb_msg *= imsg) { -=09uint64_t istart, iend, vstart, vend; +=09struct vhost_vring_addr *ra; +=09uint64_t start, end, len; =20 -=09istart =3D imsg->iova; -=09iend =3D istart + imsg->size - 1; +=09start =3D imsg->iova; +=09end =3D start + imsg->size; =20 -=09vstart =3D (uintptr_t)vq->desc; -=09vend =3D vstart + sizeof(struct vring_desc) * vq->size - 1; -=09if (vstart <=3D iend && istart <=3D vend) +=09ra =3D &vq->ring_addrs; +=09len =3D sizeof(struct vring_packed_desc) * vq->size; +=09if (ra->desc_user_addr < end && (ra->desc_user_addr + len) > start) =09=09return 1; =20 -=09vstart =3D (uintptr_t)vq->avail; -=09vend =3D vstart + sizeof(struct vring_avail); -=09vend +=3D sizeof(uint16_t) * vq->size - 1; -=09if (vstart <=3D iend && istart <=3D vend) +=09len =3D sizeof(struct vring_packed_desc_event); +=09if (ra->avail_user_addr < end && (ra->avail_user_addr + len) > start) =09=09return 1; =20 -=09vstart =3D (uintptr_t)vq->used; -=09vend =3D vstart + sizeof(struct vring_used); -=09vend +=3D sizeof(struct vring_used_elem) * vq->size - 1; -=09if (vstart <=3D iend && istart <=3D vend) +=09len =3D sizeof(struct vring_packed_desc_event); +=09if (ra->used_user_addr < end && (ra->used_user_addr + len) > start) =09=09return 1; =20 @@ -1741,4 +1745,14 @@ is_vring_iotlb_invalidate(struct vhost_virtqueue *vq= , } =20 +static int is_vring_iotlb(struct virtio_net *dev, +=09=09=09 struct vhost_virtqueue *vq, +=09=09=09 struct vhost_iotlb_msg *imsg) +{ +=09if (vq_is_packed(dev)) +=09=09return is_vring_iotlb_packed(vq, imsg); +=09else +=09=09return is_vring_iotlb_split(vq, imsg); +} + static int vhost_user_iotlb_msg(struct virtio_net **pdev, struct VhostUserMsg *msg, @@ -1766,5 +1780,5 @@ vhost_user_iotlb_msg(struct virtio_net **pdev, struct= VhostUserMsg *msg, =09=09=09=09=09len, imsg->perm); =20 -=09=09=09if (is_vring_iotlb_update(vq, imsg)) +=09=09=09if (is_vring_iotlb(dev, vq, imsg)) =09=09=09=09*pdev =3D dev =3D translate_ring_addresses(dev, i); =09=09} @@ -1777,5 +1791,5 @@ vhost_user_iotlb_msg(struct virtio_net **pdev, struct= VhostUserMsg *msg, =09=09=09=09=09imsg->size); =20 -=09=09=09if (is_vring_iotlb_invalidate(vq, imsg)) +=09=09=09if (is_vring_iotlb(dev, vq, imsg)) =09=09=09=09vring_invalidate(dev, vq); =09=09} --=20 2.21.0 --- Diff of the applied patch vs upstream commit (please double-check if non-= empty: --- --- -=092019-12-03 17:29:52.397185300 +0000 +++ 0010-vhost-fix-vring-memory-partially-mapped.patch=092019-12-03 17:29:5= 1.704750911 +0000 @@ -1 +1 @@ -From 5d9dc18e1bccfe74c6fc962042d01147b49a5bed Mon Sep 17 00:00:00 2001 +From 45b95bb27f259e814dd4f1f6e4ecd5dd78441e8e Mon Sep 17 00:00:00 2001 @@ -5,0 +6,2 @@ +[ upstream commit 5d9dc18e1bccfe74c6fc962042d01147b49a5bed ] + @@ -15 +16,0 @@ -Cc: stable@dpdk.org @@ -24 +25 @@ -index 3d2db6edf..ce4e9fb32 100644 +index bb74d0b93..0d318cd93 100644 @@ -27 +28 @@ -@@ -562,9 +562,11 @@ ring_addr_to_vva(struct virtio_net *dev, struct vhost= _virtqueue *vq, +@@ -617,9 +617,11 @@ ring_addr_to_vva(struct virtio_net *dev, struct vhost= _virtqueue *vq, @@ -41 +42 @@ -@@ -1585,8 +1587,8 @@ vhost_user_set_req_fd(struct virtio_net **pdev, stru= ct VhostUserMsg *msg, +@@ -1693,8 +1695,8 @@ vhost_user_set_req_fd(struct virtio_net **pdev, stru= ct VhostUserMsg *msg, @@ -52 +53 @@ -@@ -1594,9 +1596,15 @@ is_vring_iotlb_update(struct vhost_virtqueue *vq, s= truct vhost_iotlb_msg *imsg) +@@ -1702,9 +1704,15 @@ is_vring_iotlb_update(struct vhost_virtqueue *vq, s= truct vhost_iotlb_msg *imsg) @@ -71 +72 @@ -@@ -1605,27 +1613,23 @@ is_vring_iotlb_update(struct vhost_virtqueue *vq, = struct vhost_iotlb_msg *imsg) +@@ -1713,27 +1721,23 @@ is_vring_iotlb_update(struct vhost_virtqueue *vq, = struct vhost_iotlb_msg *imsg) @@ -111 +112 @@ -@@ -1633,4 +1637,14 @@ is_vring_iotlb_invalidate(struct vhost_virtqueue *v= q, +@@ -1741,4 +1745,14 @@ is_vring_iotlb_invalidate(struct vhost_virtqueue *v= q, @@ -126 +127 @@ -@@ -1655,5 +1669,5 @@ vhost_user_iotlb_msg(struct virtio_net **pdev, struc= t VhostUserMsg *msg, +@@ -1766,5 +1780,5 @@ vhost_user_iotlb_msg(struct virtio_net **pdev, struc= t VhostUserMsg *msg, @@ -133 +134 @@ -@@ -1666,5 +1680,5 @@ vhost_user_iotlb_msg(struct virtio_net **pdev, struc= t VhostUserMsg *msg, +@@ -1777,5 +1791,5 @@ vhost_user_iotlb_msg(struct virtio_net **pdev, struc= t VhostUserMsg *msg,