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 5A6F3A04F9 for ; Thu, 9 Jan 2020 18:58:37 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 51E781E540; Thu, 9 Jan 2020 18:58:37 +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 409CC1E543 for ; Thu, 9 Jan 2020 18:58:36 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1578592715; 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=+YkcFS0CCjRiNSNHsmz0Hfvp3luSZSdRQsxk0xWGSwY=; b=O70XDzqRySrrLlXmoBc8uRDyW/FVoyoMH2vgMivyN/12/zoWZjRvC8050s/beL2sVp0FsI /1P88y5y/g5LnlPJbkOpsqhN/llp5TCmes0Vepc1mUgiAdm3g5mGDe7OiXp7Vs5W+5zeCn YasFTKz+cjxV8mtwhAYuiIt55veL6IY= 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-114-AZeOlqNRNYq06sDJtTuhgQ-1; Thu, 09 Jan 2020 12:58:32 -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 9D884800D48; Thu, 9 Jan 2020 17:58:31 +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 8681386CB8; Thu, 9 Jan 2020 17:58:30 +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:21 +0100 Message-Id: <20200109175821.24849-2-amorenoz@redhat.com> In-Reply-To: <20200109175821.24849-1-amorenoz@redhat.com> References: <20200109175821.24849-1-amorenoz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-MC-Unique: AZeOlqNRNYq06sDJtTuhgQ-1 X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Subject: [dpdk-stable] [PATCH 17.11 1/1] vhost: fix vring memory partially mapped 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 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") Cc: stable@dpdk.org Signed-off-by: Adrian Moreno Reviewed-by: Maxime Coquelin --- lib/librte_vhost/vhost_user.c | 54 +++++++++++------------------------ 1 file changed, 17 insertions(+), 37 deletions(-) diff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c index 7bb286801..4390132a6 100644 --- a/lib/librte_vhost/vhost_user.c +++ b/lib/librte_vhost/vhost_user.c @@ -450,11 +450,13 @@ 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; =09} @@ -1238,50 +1240,28 @@ vhost_user_set_req_fd(struct virtio_net *dev, struc= t VhostUserMsg *msg) =09return 0; } =20 -static int -is_vring_iotlb_update(struct vhost_virtqueue *vq, struct vhost_iotlb_msg *= imsg) + +static int is_vring_iotlb(struct vhost_virtqueue *vq, +=09=09=09 struct vhost_iotlb_msg *imsg) { =09struct vhost_vring_addr *ra; -=09uint64_t start, end; +=09uint64_t start, end, len; =20 =09start =3D imsg->iova; =09end =3D start + imsg->size; =20 =09ra =3D &vq->ring_addrs; -=09if (ra->desc_user_addr >=3D start && ra->desc_user_addr < end) -=09=09return 1; -=09if (ra->avail_user_addr >=3D start && ra->avail_user_addr < end) -=09=09return 1; -=09if (ra->used_user_addr >=3D start && ra->used_user_addr < end) -=09=09return 1; - -=09return 0; -} - -static int -is_vring_iotlb_invalidate(struct vhost_virtqueue *vq, -=09=09=09=09struct vhost_iotlb_msg *imsg) -{ -=09uint64_t istart, iend, vstart, vend; - -=09istart =3D imsg->iova; -=09iend =3D istart + imsg->size - 1; - -=09vstart =3D (uintptr_t)vq->desc; -=09vend =3D vstart + sizeof(struct vring_desc) * vq->size - 1; -=09if (vstart <=3D iend && istart <=3D vend) +=09len =3D sizeof(struct vring_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_avail) + sizeof(uint16_t) * vq->size; +=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_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 =09return 0; @@ -1308,7 +1288,7 @@ vhost_user_iotlb_msg(struct virtio_net **pdev, struct= VhostUserMsg *msg) =09=09=09vhost_user_iotlb_cache_insert(vq, imsg->iova, vva, =09=09=09=09=09len, imsg->perm); =20 -=09=09=09if (is_vring_iotlb_update(vq, imsg)) +=09=09=09if (is_vring_iotlb(vq, imsg)) =09=09=09=09*pdev =3D dev =3D translate_ring_addresses(dev, i); =09=09} =09=09break; @@ -1319,7 +1299,7 @@ vhost_user_iotlb_msg(struct virtio_net **pdev, struct= VhostUserMsg *msg) =09=09=09vhost_user_iotlb_cache_remove(vq, imsg->iova, =09=09=09=09=09imsg->size); =20 -=09=09=09if (is_vring_iotlb_invalidate(vq, imsg)) +=09=09=09if (is_vring_iotlb(vq, imsg)) =09=09=09=09vring_invalidate(dev, vq); =09=09} =09=09break; --=20 2.21.1