patch 'vhost: fix missing vring call check on virtqueue access' has been queued to stable release 22.11.4

Xueming Li xuemingl at nvidia.com
Mon Dec 11 11:10:32 CET 2023


Hi,

FYI, your patch has been queued to stable release 22.11.4

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/13/23. 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.

Queued patches are on a temporary branch at:
https://git.dpdk.org/dpdk-stable/log/?h=22.11-staging

This queued commit can be viewed at:
https://git.dpdk.org/dpdk-stable/commit/?h=22.11-staging&id=ac1162d97a7053a702f3d063d99af431a40d49f2

Thanks.

Xueming Li <xuemingl at nvidia.com>

---
>From ac1162d97a7053a702f3d063d99af431a40d49f2 Mon Sep 17 00:00:00 2001
From: Maxime Coquelin <maxime.coquelin at redhat.com>
Date: Fri, 20 Oct 2023 10:47:58 +0200
Subject: [PATCH] vhost: fix missing vring call check on virtqueue access
Cc: Xueming Li <xuemingl at nvidia.com>

[ upstream commit af7f683615244675fc4f472a2aa42880896476ad ]

Acquiring the access lock is not enough to ensure
virtqueue's metadata such as vring pointers are valid.

The access status must also be checked.

Fixes: 6c299bb7322f ("vhost: introduce vring call API")
Fixes: c5736998305d ("vhost: fix missing virtqueue lock protection")
Fixes: 830f7e790732 ("vhost: add non-blocking API for posting interrupt")

Reported-by: Li Feng <fengli at smartx.com>
Signed-off-by: Maxime Coquelin <maxime.coquelin at redhat.com>
Acked-by: David Marchand <david.marchand at redhat.com>
---
 lib/vhost/vhost.c | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/lib/vhost/vhost.c b/lib/vhost/vhost.c
index 19c7b92c32..69e1a9b049 100644
--- a/lib/vhost/vhost.c
+++ b/lib/vhost/vhost.c
@@ -1294,6 +1294,7 @@ rte_vhost_vring_call(int vid, uint16_t vring_idx)
 {
 	struct virtio_net *dev;
 	struct vhost_virtqueue *vq;
+	int ret = 0;
 
 	dev = get_device(vid);
 	if (!dev)
@@ -1308,14 +1309,20 @@ rte_vhost_vring_call(int vid, uint16_t vring_idx)
 
 	rte_spinlock_lock(&vq->access_lock);
 
+	if (unlikely(!vq->access_ok)) {
+		ret = -1;
+		goto out_unlock;
+	}
+
 	if (vq_is_packed(dev))
 		vhost_vring_call_packed(dev, vq);
 	else
 		vhost_vring_call_split(dev, vq);
 
+out_unlock:
 	rte_spinlock_unlock(&vq->access_lock);
 
-	return 0;
+	return ret;
 }
 
 int
@@ -1323,6 +1330,7 @@ rte_vhost_vring_call_nonblock(int vid, uint16_t vring_idx)
 {
 	struct virtio_net *dev;
 	struct vhost_virtqueue *vq;
+	int ret = 0;
 
 	dev = get_device(vid);
 	if (!dev)
@@ -1338,14 +1346,20 @@ rte_vhost_vring_call_nonblock(int vid, uint16_t vring_idx)
 	if (!rte_spinlock_trylock(&vq->access_lock))
 		return -EAGAIN;
 
+	if (unlikely(!vq->access_ok)) {
+		ret = -1;
+		goto out_unlock;
+	}
+
 	if (vq_is_packed(dev))
 		vhost_vring_call_packed(dev, vq);
 	else
 		vhost_vring_call_split(dev, vq);
 
+out_unlock:
 	rte_spinlock_unlock(&vq->access_lock);
 
-	return 0;
+	return ret;
 }
 
 uint16_t
-- 
2.25.1

---
  Diff of the applied patch vs upstream commit (please double-check if non-empty:
---
--- -	2023-12-11 17:56:23.478214400 +0800
+++ 0007-vhost-fix-missing-vring-call-check-on-virtqueue-acce.patch	2023-12-11 17:56:22.887652300 +0800
@@ -1 +1 @@
-From af7f683615244675fc4f472a2aa42880896476ad Mon Sep 17 00:00:00 2001
+From ac1162d97a7053a702f3d063d99af431a40d49f2 Mon Sep 17 00:00:00 2001
@@ -4,0 +5,3 @@
+Cc: Xueming Li <xuemingl at nvidia.com>
+
+[ upstream commit af7f683615244675fc4f472a2aa42880896476ad ]
@@ -14 +16,0 @@
-Cc: stable at dpdk.org
@@ -24 +26 @@
-index bdcf85bece..b438330063 100644
+index 19c7b92c32..69e1a9b049 100644
@@ -27 +29 @@
-@@ -1332,6 +1332,7 @@ rte_vhost_vring_call(int vid, uint16_t vring_idx)
+@@ -1294,6 +1294,7 @@ rte_vhost_vring_call(int vid, uint16_t vring_idx)
@@ -35 +37 @@
-@@ -1346,14 +1347,20 @@ rte_vhost_vring_call(int vid, uint16_t vring_idx)
+@@ -1308,14 +1309,20 @@ rte_vhost_vring_call(int vid, uint16_t vring_idx)
@@ -37 +39 @@
- 	rte_rwlock_read_lock(&vq->access_lock);
+ 	rte_spinlock_lock(&vq->access_lock);
@@ -50 +52 @@
- 	rte_rwlock_read_unlock(&vq->access_lock);
+ 	rte_spinlock_unlock(&vq->access_lock);
@@ -57 +59 @@
-@@ -1361,6 +1368,7 @@ rte_vhost_vring_call_nonblock(int vid, uint16_t vring_idx)
+@@ -1323,6 +1330,7 @@ rte_vhost_vring_call_nonblock(int vid, uint16_t vring_idx)
@@ -65,2 +67,2 @@
-@@ -1376,14 +1384,20 @@ rte_vhost_vring_call_nonblock(int vid, uint16_t vring_idx)
- 	if (rte_rwlock_read_trylock(&vq->access_lock))
+@@ -1338,14 +1346,20 @@ rte_vhost_vring_call_nonblock(int vid, uint16_t vring_idx)
+ 	if (!rte_spinlock_trylock(&vq->access_lock))
@@ -80 +82 @@
- 	rte_rwlock_read_unlock(&vq->access_lock);
+ 	rte_spinlock_unlock(&vq->access_lock);


More information about the stable mailing list