patches for DPDK stable branches
 help / color / mirror / Atom feed
* [PATCH v22.11] vhost: fix missing spinlock unlock
@ 2024-01-11 10:51 Maxime Coquelin
  2024-01-11 11:10 ` David Marchand
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Maxime Coquelin @ 2024-01-11 10:51 UTC (permalink / raw)
  To: stable, xuemingl, ktraynor, dmarchan; +Cc: Maxime Coquelin

Two regressions were introduced when backporting below
patch:
b4c4e5675c85 ("vhost: fix missing lock protection in power monitor API")

First, rte_vhost_get_monitor_addr did not release the lock
in the success case. Then, rte_rwlock_read_lock() was
converted to rte_spinlock_trylock() instead of
rte_spinlock_lock().

This patch addresses both of these issues.

Fixes: a07736eb68da ("vhost: fix missing lock protection in power monitor API")
Cc: stable@dpdk.org

Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
---
 lib/vhost/vhost.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/lib/vhost/vhost.c b/lib/vhost/vhost.c
index 40ac350e21..9e28198528 100644
--- a/lib/vhost/vhost.c
+++ b/lib/vhost/vhost.c
@@ -2060,6 +2060,7 @@ rte_vhost_get_monitor_addr(int vid, uint16_t queue_id,
 {
 	struct virtio_net *dev = get_device(vid);
 	struct vhost_virtqueue *vq;
+	int ret = 0;
 
 	if (dev == NULL)
 		return -1;
@@ -2070,11 +2071,12 @@ rte_vhost_get_monitor_addr(int vid, uint16_t queue_id,
 	if (vq == NULL)
 		return -1;
 
-	if (!rte_spinlock_trylock(&vq->access_lock))
-		return -1;
+	rte_spinlock_lock(&vq->access_lock);
 
-	if (unlikely(!vq->access_ok))
+	if (unlikely(!vq->access_ok)) {
+		ret = -1;
 		goto out_unlock;
+	}
 
 	if (vq_is_packed(dev)) {
 		struct vring_packed_desc *desc;
@@ -2095,12 +2097,10 @@ rte_vhost_get_monitor_addr(int vid, uint16_t queue_id,
 		pmc->match = 0;
 	}
 
-	return 0;
-
 out_unlock:
 	rte_spinlock_unlock(&vq->access_lock);
 
-	return -1;
+	return ret;
 }
 
 
-- 
2.43.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-01-22 13:10 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-11 10:51 [PATCH v22.11] vhost: fix missing spinlock unlock Maxime Coquelin
2024-01-11 11:10 ` David Marchand
2024-01-11 11:11 ` Xueming(Steven) Li
2024-01-22 13:10   ` Xueming(Steven) Li
2024-01-19 13:52 ` Xueming(Steven) Li

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).