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

* Re: [PATCH v22.11] vhost: fix missing spinlock unlock
  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-19 13:52 ` Xueming(Steven) Li
  2 siblings, 0 replies; 5+ messages in thread
From: David Marchand @ 2024-01-11 11:10 UTC (permalink / raw)
  To: Maxime Coquelin, Lingli Chen; +Cc: stable, xuemingl, ktraynor

On Thu, Jan 11, 2024 at 11:52 AM Maxime Coquelin
<maxime.coquelin@redhat.com> wrote:
>
> 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.
>

Bugzilla ID: 1338
> Fixes: a07736eb68da ("vhost: fix missing lock protection in power monitor API")
> Cc: stable@dpdk.org
>
> Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>


I backported the lock annotations for the vhost lib in 22.11.
Indeed, clang reports a deadlock in this part of the code which likely
explains the bug report.

[1/2] Compiling C object lib/librte_vhost.a.p/vhost_vhost.c.o
../lib/vhost/vhost.c:2092:1: warning: mutex 'vq->access_lock' is not
held on every path through here [-Wthread-safety-analysis]
}
^
../lib/vhost/vhost.c:2061:7: note: mutex acquired here
        if (!rte_spinlock_trylock(&vq->access_lock))
             ^
1 warning generated.
[2/2] Linking static target lib/librte_vhost.a


I applied this patch and the issue is gone.

Tested-by: David Marchand <david.marchand@redhat.com>

Can the bz reporter test this patch?


-- 
David Marchand


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

* RE: [PATCH v22.11] vhost: fix missing spinlock unlock
  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
  2 siblings, 1 reply; 5+ messages in thread
From: Xueming(Steven) Li @ 2024-01-11 11:11 UTC (permalink / raw)
  To: Xu, HailinX; +Cc: Maxime Coquelin, stable, ktraynor, dmarchan

Thanks Maxime!

Hailin, could you please confirm if it fixes https://bugs.dpdk.org/show_bug.cgi?id=1338?

> -----Original Message-----
> From: Maxime Coquelin <maxime.coquelin@redhat.com>
> Sent: 1/11/2024 18:52
> To: stable@dpdk.org; Xueming(Steven) Li <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
> 
> 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

* RE: [PATCH v22.11] vhost: fix missing spinlock unlock
  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-19 13:52 ` Xueming(Steven) Li
  2 siblings, 0 replies; 5+ messages in thread
From: Xueming(Steven) Li @ 2024-01-19 13:52 UTC (permalink / raw)
  To: Maxime Coquelin, stable, ktraynor, dmarchan

HI Maxime,

Patch queued to 22.11 branch, thanks for your help!

Regards,
Xueming

> -----Original Message-----
> From: Maxime Coquelin <maxime.coquelin@redhat.com>
> Sent: 1/11/2024 18:52
> To: stable@dpdk.org; Xueming(Steven) Li <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
> 
> 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

* RE: [PATCH v22.11] vhost: fix missing spinlock unlock
  2024-01-11 11:11 ` Xueming(Steven) Li
@ 2024-01-22 13:10   ` Xueming(Steven) Li
  0 siblings, 0 replies; 5+ messages in thread
From: Xueming(Steven) Li @ 2024-01-22 13:10 UTC (permalink / raw)
  To: Xu, HailinX; +Cc: Maxime Coquelin, stable, ktraynor, dmarchan

Hi Hailin,

> -----Original Message-----
> From: Xueming(Steven) Li <xuemingl@nvidia.com>
> Sent: 1/11/2024 19:11
> To: Xu, HailinX <hailinx.xu@intel.com>
> Cc: Maxime Coquelin <maxime.coquelin@redhat.com>; stable@dpdk.org;
> ktraynor@redhat.com; dmarchan@redhat.com
> Subject: RE: [PATCH v22.11] vhost: fix missing spinlock unlock
> 
> Thanks Maxime!
> 
> Hailin, could you please confirm if it fixes
> https://bugs.dpdk.org/show_bug.cgi?id=1338?

The CI passed with this fix, w/o your further confirmation, I'd assume it fixed.
I'll send out 22.11 release if no objections.

> 
> > -----Original Message-----
> > From: Maxime Coquelin <maxime.coquelin@redhat.com>
> > Sent: 1/11/2024 18:52
> > To: stable@dpdk.org; Xueming(Steven) Li <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
> >
> > 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).