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 9CD76A04F3 for ; Thu, 19 Dec 2019 15:36:13 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 92C4C330; Thu, 19 Dec 2019 15:36:13 +0100 (CET) Received: from mail-wr1-f65.google.com (mail-wr1-f65.google.com [209.85.221.65]) by dpdk.org (Postfix) with ESMTP id 75F9F1BF7D for ; Thu, 19 Dec 2019 15:36:12 +0100 (CET) Received: by mail-wr1-f65.google.com with SMTP id g17so6223799wro.2 for ; Thu, 19 Dec 2019 06:36:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ZffoPDx+Sd7IJ8+VtZpvKhiFAZ+orCNRfcbdcYfDmAI=; b=MuU8kynljhYwz2FIKzb7BD4prpmjvIhWdeWPzKP/Nop5CjDui5oTntPRMgVEvVgfYf CAOww9UhvbT8tozj0xiJw1DQ7Gr4GHBS0p7snByb1I1qmwB2dAxWk+D/+xZuArL6V2W7 q5Ucb7yuMYlFeHEf/fgl2bbJFa1nGk6sl2wTtrpfivh/dnyg98ZkVfPCdt0Ld1peh3V0 y/6FCXQ3tQBGPfbLTFF9oo4xRHf0ILfFw7yN4kBTNJHb0Zph0ebeL3So+F58B9OCb1gh 3EY6s1Osyppqas6Kf9xR/DV1SXhVHsiwylzXbFuRvN+eCxDcQ21/iM7F9/NG1ml07YvV u+ag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ZffoPDx+Sd7IJ8+VtZpvKhiFAZ+orCNRfcbdcYfDmAI=; b=f/9OfRizwPNXoy0ISv3L8dQyM8x/dJWaQUZPJoKSIB85OTZw5Rt61dys+1SKDnb+SB mstURJBx3zHzNki1IdwpuhwsGUfKfA3Y48r9JdrRigFi/GtFB4Ik5ZTpxPihT4gkBURh UuF3JyXYYRolAKnH0Zu3LRc0hx6fqGjkaZLlPsOp2FPCEpQ6iOk0Aq9m4kJNveVPQc4G Uucq2oiwhh7MploBy88tC/3MMssx+EK4Gpegg9zfPVZqcEnRHa9McMocfGgaORYNjqR/ 0Cz/sFjR8UhW9hUcKomB6CRZdaNkKftCm9Fa5ago1tC5ansTL/pMy04Pi00jMuM1bmM+ 0d0g== X-Gm-Message-State: APjAAAVDZsxukaGRraYoq0vFafpXfVDhXGg39kBF8wF/mi+kD2vnsFUr cR2oisO8+Ain5oh131I+V88= X-Google-Smtp-Source: APXvYqxspA3yrUkSnmBw8vvWrNThnD00yNrWcBYe8gCxJEuQXfNSPVl+6tsCyJbww5L2qUe88QMjhQ== X-Received: by 2002:a5d:62d1:: with SMTP id o17mr10492461wrv.9.1576766172171; Thu, 19 Dec 2019 06:36:12 -0800 (PST) Received: from localhost ([88.98.246.218]) by smtp.gmail.com with ESMTPSA id q8sm6151900wmq.3.2019.12.19.06.36.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Dec 2019 06:36:11 -0800 (PST) From: luca.boccassi@gmail.com To: Tiwei Bie Cc: Peng He , Maxime Coquelin , dpdk stable Date: Thu, 19 Dec 2019 14:32:59 +0000 Message-Id: <20191219143447.21506-32-luca.boccassi@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191219143447.21506-1-luca.boccassi@gmail.com> References: <20191219143447.21506-1-luca.boccassi@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-stable] patch 'vhost: protect vring access done by application' has been queued to LTS release 17.11.10 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 17.11.10 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/21/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 rebasing (ie: not only metadata diffs), please double check that the rebase was correctly done. Thanks. Luca Boccassi --- >From 553c27798e7b3ca0ccf8f7e2191543097b4d467d 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 | 42 ++++++++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/lib/librte_vhost/vhost.c b/lib/librte_vhost/vhost.c index 78fedc6a47..08ab6eab35 100644 --- a/lib/librte_vhost/vhost.c +++ b/lib/librte_vhost/vhost.c @@ -538,22 +538,32 @@ rte_vhost_avail_entries(int vid, uint16_t queue_id) { struct virtio_net *dev; struct vhost_virtqueue *vq; + uint16_t ret = 0; dev = get_device(vid); if (!dev) return 0; vq = dev->virtqueue[queue_id]; - if (!vq->enabled) - return 0; - return *(volatile uint16_t *)&vq->avail->idx - vq->last_used_idx; + rte_spinlock_lock(&vq->access_lock); + + if (unlikely(!vq->enabled || vq->avail == NULL)) + goto out; + + ret = *(volatile uint16_t *)&vq->avail->idx - vq->last_used_idx; + +out: + rte_spinlock_unlock(&vq->access_lock); + return ret; } int rte_vhost_enable_guest_notification(int vid, uint16_t queue_id, int enable) { struct virtio_net *dev = get_device(vid); + struct vhost_virtqueue *vq; + int ret = 0; if (dev == NULL) return -1; @@ -564,8 +574,21 @@ rte_vhost_enable_guest_notification(int vid, uint16_t queue_id, int enable) return -1; } + vq = dev->virtqueue[queue_id]; + + rte_spinlock_lock(&vq->access_lock); + + if (vq->used == NULL) { + ret = -1; + goto out; + } + dev->virtqueue[queue_id]->used->flags = VRING_USED_F_NO_NOTIFY; - return 0; + +out: + rte_spinlock_unlock(&vq->access_lock); + + return ret; } void @@ -604,6 +627,7 @@ rte_vhost_rx_queue_count(int vid, uint16_t qid) { struct virtio_net *dev; struct vhost_virtqueue *vq; + uint32_t ret = 0; dev = get_device(vid); if (dev == NULL) @@ -619,8 +643,14 @@ rte_vhost_rx_queue_count(int vid, uint16_t qid) if (vq == NULL) return 0; + rte_spinlock_lock(&vq->access_lock); + if (unlikely(vq->enabled == 0 || vq->avail == NULL)) - return 0; + goto out; - return *((volatile uint16_t *)&vq->avail->idx) - vq->last_avail_idx; + ret = *((volatile uint16_t *)&vq->avail->idx) - vq->last_avail_idx; + +out: + rte_spinlock_unlock(&vq->access_lock); + return ret; } -- 2.20.1 --- Diff of the applied patch vs upstream commit (please double-check if non-empty: --- --- - 2019-12-19 14:32:27.626988674 +0000 +++ 0032-vhost-protect-vring-access-done-by-application.patch 2019-12-19 14:32:25.785291480 +0000 @@ -1,26 +1,27 @@ -From 4e0de8dac8531b82d4c328791a67f49eadfed5f0 Mon Sep 17 00:00:00 2001 +From 553c27798e7b3ca0ccf8f7e2191543097b4d467d 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") -Cc: stable@dpdk.org 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(-) + lib/librte_vhost/vhost.c | 42 ++++++++++++++++++++++++++++++++++------ + 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/lib/librte_vhost/vhost.c b/lib/librte_vhost/vhost.c -index 77be160697..cea44df8cb 100644 +index 78fedc6a47..08ab6eab35 100644 --- a/lib/librte_vhost/vhost.c +++ b/lib/librte_vhost/vhost.c -@@ -785,22 +785,33 @@ rte_vhost_avail_entries(int vid, uint16_t queue_id) +@@ -538,22 +538,32 @@ rte_vhost_avail_entries(int vid, uint16_t queue_id) { struct virtio_net *dev; struct vhost_virtqueue *vq; @@ -47,77 +48,39 @@ + return ret; } --static inline void -+static inline int - vhost_enable_notify_split(struct virtio_net *dev, - struct vhost_virtqueue *vq, int enable) - { -+ if (vq->used == NULL) -+ return -1; -+ - if (!(dev->features & (1ULL << VIRTIO_RING_F_EVENT_IDX))) { - if (enable) - vq->used->flags &= ~VRING_USED_F_NO_NOTIFY; -@@ -810,17 +821,21 @@ vhost_enable_notify_split(struct virtio_net *dev, - if (enable) - vhost_avail_event(vq) = vq->last_avail_idx; - } -+ return 0; - } - --static inline void -+static inline int - vhost_enable_notify_packed(struct virtio_net *dev, - struct vhost_virtqueue *vq, int enable) - { - uint16_t flags; - -+ if (vq->device_event == NULL) -+ return -1; -+ - if (!enable) { - vq->device_event->flags = VRING_EVENT_F_DISABLE; -- return; -+ return 0; - } - - flags = VRING_EVENT_F_ENABLE; -@@ -833,6 +848,7 @@ vhost_enable_notify_packed(struct virtio_net *dev, - rte_smp_wmb(); - - vq->device_event->flags = flags; -+ return 0; - } - int -@@ -840,18 +856,23 @@ rte_vhost_enable_guest_notification(int vid, uint16_t queue_id, int enable) + rte_vhost_enable_guest_notification(int vid, uint16_t queue_id, int enable) { struct virtio_net *dev = get_device(vid); - struct vhost_virtqueue *vq; -+ int ret; ++ struct vhost_virtqueue *vq; ++ int ret = 0; - if (!dev) + if (dev == NULL) return -1; +@@ -564,8 +574,21 @@ rte_vhost_enable_guest_notification(int vid, uint16_t queue_id, int enable) + return -1; + } - vq = dev->virtqueue[queue_id]; - ++ vq = dev->virtqueue[queue_id]; ++ + rte_spinlock_lock(&vq->access_lock); + - if (vq_is_packed(dev)) -- vhost_enable_notify_packed(dev, vq, enable); -+ ret = vhost_enable_notify_packed(dev, vq, enable); - else -- vhost_enable_notify_split(dev, vq, enable); -+ ret = vhost_enable_notify_split(dev, vq, enable); - ++ if (vq->used == NULL) { ++ ret = -1; ++ goto out; ++ } ++ + dev->virtqueue[queue_id]->used->flags = VRING_USED_F_NO_NOTIFY; - return 0; ++ ++out: + rte_spinlock_unlock(&vq->access_lock); + + return ret; } void -@@ -890,6 +911,7 @@ rte_vhost_rx_queue_count(int vid, uint16_t qid) +@@ -604,6 +627,7 @@ rte_vhost_rx_queue_count(int vid, uint16_t qid) { struct virtio_net *dev; struct vhost_virtqueue *vq; @@ -125,7 +88,7 @@ dev = get_device(vid); if (dev == NULL) -@@ -905,10 +927,16 @@ rte_vhost_rx_queue_count(int vid, uint16_t qid) +@@ -619,8 +643,14 @@ rte_vhost_rx_queue_count(int vid, uint16_t qid) if (vq == NULL) return 0; @@ -142,8 +105,6 @@ + rte_spinlock_unlock(&vq->access_lock); + return ret; } - - int rte_vhost_get_vdpa_device_id(int vid) -- 2.20.1