patches for DPDK stable branches
 help / color / mirror / Atom feed
From: Maxime Coquelin <maxime.coquelin@redhat.com>
To: stable@dpdk.org, xuemingl@nvidia.com, ktraynor@redhat.com,
	dmarchan@redhat.com
Cc: Maxime Coquelin <maxime.coquelin@redhat.com>
Subject: [PATCH v22.11] vhost: fix missing spinlock unlock
Date: Thu, 11 Jan 2024 11:51:58 +0100	[thread overview]
Message-ID: <20240111105158.3508078-1-maxime.coquelin@redhat.com> (raw)

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


             reply	other threads:[~2024-01-11 10:52 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-11 10:51 Maxime Coquelin [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240111105158.3508078-1-maxime.coquelin@redhat.com \
    --to=maxime.coquelin@redhat.com \
    --cc=dmarchan@redhat.com \
    --cc=ktraynor@redhat.com \
    --cc=stable@dpdk.org \
    --cc=xuemingl@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).