patch 'vhost: fix checking virtqueue access in stats API' has been queued to stable release 22.11.4

Xueming Li xuemingl at nvidia.com
Mon Dec 11 11:10:37 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=8c291d87783d2e22e6234cddc23bee27d0f14dae

Thanks.

Xueming Li <xuemingl at nvidia.com>

---
>From 8c291d87783d2e22e6234cddc23bee27d0f14dae Mon Sep 17 00:00:00 2001
From: Maxime Coquelin <maxime.coquelin at redhat.com>
Date: Fri, 20 Oct 2023 10:48:04 +0200
Subject: [PATCH] vhost: fix checking virtqueue access in stats API
Cc: Xueming Li <xuemingl at nvidia.com>

[ upstream commit a004501a147889d608008ab6f18355e9b0ceff65 ]

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: be75dc99ea1f ("vhost: support per-virtqueue statistics")

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

diff --git a/lib/vhost/vhost.c b/lib/vhost/vhost.c
index 6e1bba4391..40ac350e21 100644
--- a/lib/vhost/vhost.c
+++ b/lib/vhost/vhost.c
@@ -2138,6 +2138,7 @@ rte_vhost_vring_stats_get(int vid, uint16_t queue_id,
 	struct virtio_net *dev = get_device(vid);
 	struct vhost_virtqueue *vq;
 	unsigned int i;
+	int ret = VHOST_NB_VQ_STATS;
 
 	if (dev == NULL)
 		return -1;
@@ -2154,14 +2155,22 @@ rte_vhost_vring_stats_get(int vid, uint16_t queue_id,
 	vq = dev->virtqueue[queue_id];
 
 	rte_spinlock_lock(&vq->access_lock);
+
+	if (unlikely(!vq->access_ok)) {
+		ret = -1;
+		goto out_unlock;
+	}
+
 	for (i = 0; i < VHOST_NB_VQ_STATS; i++) {
 		stats[i].value =
 			*(uint64_t *)(((char *)vq) + vhost_vq_stat_strings[i].offset);
 		stats[i].id = i;
 	}
+
+out_unlock:
 	rte_spinlock_unlock(&vq->access_lock);
 
-	return VHOST_NB_VQ_STATS;
+	return ret;
 }
 
 int rte_vhost_vring_stats_reset(int vid, uint16_t queue_id)
@@ -2182,10 +2191,17 @@ int rte_vhost_vring_stats_reset(int vid, uint16_t queue_id)
 	vq = dev->virtqueue[queue_id];
 
 	rte_spinlock_lock(&vq->access_lock);
+
+	if (unlikely(!vq->access_ok)) {
+		ret = -1;
+		goto out_unlock;
+	}
 	memset(&vq->stats, 0, sizeof(vq->stats));
+
+out_unlock:
 	rte_spinlock_unlock(&vq->access_lock);
 
-	return 0;
+	return ret;
 }
 
 int
-- 
2.25.1

---
  Diff of the applied patch vs upstream commit (please double-check if non-empty:
---
--- -	2023-12-11 17:56:23.623239500 +0800
+++ 0012-vhost-fix-checking-virtqueue-access-in-stats-API.patch	2023-12-11 17:56:22.887652300 +0800
@@ -1 +1 @@
-From a004501a147889d608008ab6f18355e9b0ceff65 Mon Sep 17 00:00:00 2001
+From 8c291d87783d2e22e6234cddc23bee27d0f14dae Mon Sep 17 00:00:00 2001
@@ -4,0 +5,3 @@
+Cc: Xueming Li <xuemingl at nvidia.com>
+
+[ upstream commit a004501a147889d608008ab6f18355e9b0ceff65 ]
@@ -12 +14,0 @@
-Cc: stable at dpdk.org
@@ -17,2 +19,2 @@
- lib/vhost/vhost.c | 21 +++++++++++++++++++--
- 1 file changed, 19 insertions(+), 2 deletions(-)
+ lib/vhost/vhost.c | 20 ++++++++++++++++++--
+ 1 file changed, 18 insertions(+), 2 deletions(-)
@@ -21 +23 @@
-index 9a7403c28d..8a1f992d9d 100644
+index 6e1bba4391..40ac350e21 100644
@@ -24 +26 @@
-@@ -2201,6 +2201,7 @@ rte_vhost_vring_stats_get(int vid, uint16_t queue_id,
+@@ -2138,6 +2138,7 @@ rte_vhost_vring_stats_get(int vid, uint16_t queue_id,
@@ -32 +34 @@
-@@ -2217,6 +2218,12 @@ rte_vhost_vring_stats_get(int vid, uint16_t queue_id,
+@@ -2154,14 +2155,22 @@ rte_vhost_vring_stats_get(int vid, uint16_t queue_id,
@@ -35 +37 @@
- 	rte_rwlock_write_lock(&vq->access_lock);
+ 	rte_spinlock_lock(&vq->access_lock);
@@ -43,3 +45 @@
- 		/*
- 		 * No need to the read atomic counters as such, due to the
-@@ -2226,15 +2233,18 @@ rte_vhost_vring_stats_get(int vid, uint16_t queue_id,
+ 		stats[i].value =
@@ -51 +51 @@
- 	rte_rwlock_write_unlock(&vq->access_lock);
+ 	rte_spinlock_unlock(&vq->access_lock);
@@ -58,8 +58 @@
- {
- 	struct virtio_net *dev = get_device(vid);
- 	struct vhost_virtqueue *vq;
-+	int ret = 0;
- 
- 	if (dev == NULL)
- 		return -1;
-@@ -2248,14 +2258,21 @@ int rte_vhost_vring_stats_reset(int vid, uint16_t queue_id)
+@@ -2182,10 +2191,17 @@ int rte_vhost_vring_stats_reset(int vid, uint16_t queue_id)
@@ -68 +61 @@
- 	rte_rwlock_write_lock(&vq->access_lock);
+ 	rte_spinlock_lock(&vq->access_lock);
@@ -74,4 +66,0 @@
- 	/*
- 	 * No need to the reset atomic counters as such, due to the
- 	 * above write access_lock preventing them to be updated.
- 	 */
@@ -81 +70 @@
- 	rte_rwlock_write_unlock(&vq->access_lock);
+ 	rte_spinlock_unlock(&vq->access_lock);


More information about the stable mailing list