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 D3473A04B5 for ; Tue, 3 Dec 2019 19:27:47 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id C9A8C37AF; Tue, 3 Dec 2019 19:27:47 +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 7EA7D4C99 for ; Tue, 3 Dec 2019 19:27:46 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1575397666; 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=8juN+Cpf3P7boIpQ/8Jt43dvUQ514pHq+Ek2U5A+7tE=; b=c8+jZfr80EOg2+xX6e5ovZaY5gIW1VBY2ntnTkE6pWIChvkd39vZOq982/j4c+c4QAWvc4 y8+ulRuTIUi/oAaEQMp0CfbZWYlcQz2aM3EaGU4YgTItypnz3B3kI3HCQOCR1/n0MRage5 Sys9+5/CDieWnKS9puP6EZg9kqU8hjg= 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-328-DSl5YRbJMouMABo9N7ofXw-1; Tue, 03 Dec 2019 13:27:42 -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 BE3C8800D41; Tue, 3 Dec 2019 18:27:41 +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 96D8E5C240; Tue, 3 Dec 2019 18:27:40 +0000 (UTC) From: Kevin Traynor To: Tiwei Bie Cc: Peng He , Maxime Coquelin , dpdk stable Date: Tue, 3 Dec 2019 18:26:17 +0000 Message-Id: <20191203182714.17297-8-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: DSl5YRbJMouMABo9N7ofXw-1 X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Subject: [dpdk-stable] patch 'vhost: protect vring access done by application' 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/b0818bac8e25cf4bd0= 24673956b52609dae1b8ba Thanks. Kevin. --- >From b0818bac8e25cf4bd024673956b52609dae1b8ba Mon Sep 17 00:00:00 2001 From: Tiwei Bie Date: Mon, 19 Aug 2019 19:34:57 +0800 Subject: [PATCH] vhost: protect vring access done by application [ upstream commit 4e0de8dac8531b82d4c328791a67f49eadfed5f0 ] Besides the enqueue/dequeue API, other APIs of the builtin net backend should also be protected. Fixes: a3688046995f ("vhost: protect active rings from async ring changes") Reported-by: Peng He Signed-off-by: Tiwei Bie Reviewed-by: Maxime Coquelin --- lib/librte_vhost/vhost.c | 50 +++++++++++++++++++++++++++++++--------- 1 file changed, 39 insertions(+), 11 deletions(-) diff --git a/lib/librte_vhost/vhost.c b/lib/librte_vhost/vhost.c index 0b5ee0307..f7d132cd4 100644 --- a/lib/librte_vhost/vhost.c +++ b/lib/librte_vhost/vhost.c @@ -635,4 +635,5 @@ rte_vhost_avail_entries(int vid, uint16_t queue_id) =09struct virtio_net *dev; =09struct vhost_virtqueue *vq; +=09uint16_t ret =3D 0; =20 =09dev =3D get_device(vid); @@ -641,14 +642,24 @@ rte_vhost_avail_entries(int vid, uint16_t queue_id) =20 =09vq =3D dev->virtqueue[queue_id]; -=09if (!vq->enabled) -=09=09return 0; =20 -=09return *(volatile uint16_t *)&vq->avail->idx - vq->last_used_idx; +=09rte_spinlock_lock(&vq->access_lock); + +=09if (unlikely(!vq->enabled || vq->avail =3D=3D NULL)) +=09=09goto out; + +=09ret =3D *(volatile uint16_t *)&vq->avail->idx - vq->last_used_idx; + +out: +=09rte_spinlock_unlock(&vq->access_lock); +=09return ret; } =20 -static inline void +static inline int vhost_enable_notify_split(struct virtio_net *dev, =09=09struct vhost_virtqueue *vq, int enable) { +=09if (vq->used =3D=3D NULL) +=09=09return -1; + =09if (!(dev->features & (1ULL << VIRTIO_RING_F_EVENT_IDX))) { =09=09if (enable) @@ -660,7 +671,8 @@ vhost_enable_notify_split(struct virtio_net *dev, =09=09=09vhost_avail_event(vq) =3D vq->last_avail_idx; =09} +=09return 0; } =20 -static inline void +static inline int vhost_enable_notify_packed(struct virtio_net *dev, =09=09struct vhost_virtqueue *vq, int enable) @@ -668,7 +680,10 @@ vhost_enable_notify_packed(struct virtio_net *dev, =09uint16_t flags; =20 +=09if (vq->device_event =3D=3D NULL) +=09=09return -1; + =09if (!enable) { =09=09vq->device_event->flags =3D VRING_EVENT_F_DISABLE; -=09=09return; +=09=09return 0; =09} =20 @@ -683,4 +698,5 @@ vhost_enable_notify_packed(struct virtio_net *dev, =20 =09vq->device_event->flags =3D flags; +=09return 0; } =20 @@ -690,4 +706,5 @@ rte_vhost_enable_guest_notification(int vid, uint16_t q= ueue_id, int enable) =09struct virtio_net *dev =3D get_device(vid); =09struct vhost_virtqueue *vq; +=09int ret; =20 =09if (!dev) @@ -696,10 +713,14 @@ rte_vhost_enable_guest_notification(int vid, uint16_t= queue_id, int enable) =09vq =3D dev->virtqueue[queue_id]; =20 +=09rte_spinlock_lock(&vq->access_lock); + =09if (vq_is_packed(dev)) -=09=09vhost_enable_notify_packed(dev, vq, enable); +=09=09ret =3D vhost_enable_notify_packed(dev, vq, enable); =09else -=09=09vhost_enable_notify_split(dev, vq, enable); +=09=09ret =3D vhost_enable_notify_split(dev, vq, enable); =20 -=09return 0; +=09rte_spinlock_unlock(&vq->access_lock); + +=09return ret; } =20 @@ -740,4 +761,5 @@ rte_vhost_rx_queue_count(int vid, uint16_t qid) =09struct virtio_net *dev; =09struct vhost_virtqueue *vq; +=09uint16_t ret =3D 0; =20 =09dev =3D get_device(vid); @@ -755,8 +777,14 @@ rte_vhost_rx_queue_count(int vid, uint16_t qid) =09=09return 0; =20 +=09rte_spinlock_lock(&vq->access_lock); + =09if (unlikely(vq->enabled =3D=3D 0 || vq->avail =3D=3D NULL)) -=09=09return 0; +=09=09goto out; =20 -=09return *((volatile uint16_t *)&vq->avail->idx) - vq->last_avail_idx; +=09ret =3D *((volatile uint16_t *)&vq->avail->idx) - vq->last_avail_idx; + +out: +=09rte_spinlock_unlock(&vq->access_lock); +=09return ret; } =20 --=20 2.21.0 --- Diff of the applied patch vs upstream commit (please double-check if non-= empty: --- --- -=092019-12-03 17:29:52.286908156 +0000 +++ 0008-vhost-protect-vring-access-done-by-application.patch=092019-12-03 = 17:29:51.702750953 +0000 @@ -1 +1 @@ -From 4e0de8dac8531b82d4c328791a67f49eadfed5f0 Mon Sep 17 00:00:00 2001 +From b0818bac8e25cf4bd024673956b52609dae1b8ba Mon Sep 17 00:00:00 2001 @@ -5,0 +6,2 @@ +[ upstream commit 4e0de8dac8531b82d4c328791a67f49eadfed5f0 ] + @@ -10 +11,0 @@ -Cc: stable@dpdk.org @@ -20 +21 @@ -index 77be16069..cea44df8c 100644 +index 0b5ee0307..f7d132cd4 100644 @@ -23 +24 @@ -@@ -786,4 +786,5 @@ rte_vhost_avail_entries(int vid, uint16_t queue_id) +@@ -635,4 +635,5 @@ rte_vhost_avail_entries(int vid, uint16_t queue_id) @@ -29 +30 @@ -@@ -792,14 +793,24 @@ rte_vhost_avail_entries(int vid, uint16_t queue_id) +@@ -641,14 +642,24 @@ rte_vhost_avail_entries(int vid, uint16_t queue_id) @@ -58 +59 @@ -@@ -811,7 +822,8 @@ vhost_enable_notify_split(struct virtio_net *dev, +@@ -660,7 +671,8 @@ vhost_enable_notify_split(struct virtio_net *dev, @@ -68 +69 @@ -@@ -819,7 +831,10 @@ vhost_enable_notify_packed(struct virtio_net *dev, +@@ -668,7 +680,10 @@ vhost_enable_notify_packed(struct virtio_net *dev, @@ -80 +81 @@ -@@ -834,4 +849,5 @@ vhost_enable_notify_packed(struct virtio_net *dev, +@@ -683,4 +698,5 @@ vhost_enable_notify_packed(struct virtio_net *dev, @@ -86 +87 @@ -@@ -841,4 +857,5 @@ rte_vhost_enable_guest_notification(int vid, uint16_t = queue_id, int enable) +@@ -690,4 +706,5 @@ rte_vhost_enable_guest_notification(int vid, uint16_t = queue_id, int enable) @@ -92 +93 @@ -@@ -847,10 +864,14 @@ rte_vhost_enable_guest_notification(int vid, uint16_= t queue_id, int enable) +@@ -696,10 +713,14 @@ rte_vhost_enable_guest_notification(int vid, uint16_= t queue_id, int enable) @@ -110 +111 @@ -@@ -891,4 +912,5 @@ rte_vhost_rx_queue_count(int vid, uint16_t qid) +@@ -740,4 +761,5 @@ rte_vhost_rx_queue_count(int vid, uint16_t qid) @@ -113 +114 @@ -+=09uint32_t ret =3D 0; ++=09uint16_t ret =3D 0; @@ -116 +117 @@ -@@ -906,8 +928,14 @@ rte_vhost_rx_queue_count(int vid, uint16_t qid) +@@ -755,8 +777,14 @@ rte_vhost_rx_queue_count(int vid, uint16_t qid)