diff mbox series

vhost: use try_lock in rte_vhost_vring_call

Message ID 20220906022225.17215-1-changpeng.liu@intel.com (mailing list archive)
State Superseded, archived
Delegated to: Maxime Coquelin
Headers show
Series vhost: use try_lock in rte_vhost_vring_call | expand

Checks

Context Check Description
ci/intel-Testing success Testing PASS
ci/github-robot: build success github build: passed
ci/iol-x86_64-compile-testing success Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-x86_64-unit-testing fail Testing issues
ci/iol-aarch64-unit-testing success Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/Intel-compilation success Compilation OK
ci/checkpatch success coding style OK

Commit Message

Liu, Changpeng Sept. 6, 2022, 2:22 a.m. UTC
Note that this function is in data path, so the thread context
may not same as socket messages processing context, by using
try_lock here, users can have another try in case of VQ's access
lock is held by `vhost-events` thread.

Signed-off-by: Changpeng Liu <changpeng.liu@intel.com>
---
 lib/vhost/vhost.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

Comments

Stephen Hemminger Sept. 6, 2022, 9:15 p.m. UTC | #1
On Tue,  6 Sep 2022 10:22:25 +0800
Changpeng Liu <changpeng.liu@intel.com> wrote:

> Note that this function is in data path, so the thread context
> may not same as socket messages processing context, by using
> try_lock here, users can have another try in case of VQ's access
> lock is held by `vhost-events` thread.
> 
> Signed-off-by: Changpeng Liu <changpeng.liu@intel.com>
> ---
>  lib/vhost/vhost.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/lib/vhost/vhost.c b/lib/vhost/vhost.c
> index 60cb05a0ff..072d2acb7b 100644
> --- a/lib/vhost/vhost.c
> +++ b/lib/vhost/vhost.c
> @@ -1329,7 +1329,11 @@ rte_vhost_vring_call(int vid, uint16_t vring_idx)
>  	if (!vq)
>  		return -1;
>  
> -	rte_spinlock_lock(&vq->access_lock);
> +	if (!rte_spinlock_trylock(&vq->access_lock)) {
> +		VHOST_LOG_CONFIG(dev->ifname, DEBUG,
> +			"failed to kick guest, virtqueue busy.\n");
> +		return -1;
> +	}
>  

If it is a race, logging a message is not a good idea; the log will fill
with this noise.

Instead make it statistic that can be seen by xstats.
Liu, Changpeng Sept. 7, 2022, 12:40 a.m. UTC | #2
> -----Original Message-----
> From: Stephen Hemminger <stephen@networkplumber.org>
> Sent: Wednesday, September 7, 2022 5:16 AM
> To: Liu, Changpeng <changpeng.liu@intel.com>
> Cc: dev@dpdk.org; Maxime Coquelin <maxime.coquelin@redhat.com>; Xia,
> Chenbo <chenbo.xia@intel.com>
> Subject: Re: [PATCH] vhost: use try_lock in rte_vhost_vring_call
> 
> On Tue,  6 Sep 2022 10:22:25 +0800
> Changpeng Liu <changpeng.liu@intel.com> wrote:
> 
> > Note that this function is in data path, so the thread context
> > may not same as socket messages processing context, by using
> > try_lock here, users can have another try in case of VQ's access
> > lock is held by `vhost-events` thread.
> >
> > Signed-off-by: Changpeng Liu <changpeng.liu@intel.com>
> > ---
> >  lib/vhost/vhost.c | 6 +++++-
> >  1 file changed, 5 insertions(+), 1 deletion(-)
> >
> > diff --git a/lib/vhost/vhost.c b/lib/vhost/vhost.c
> > index 60cb05a0ff..072d2acb7b 100644
> > --- a/lib/vhost/vhost.c
> > +++ b/lib/vhost/vhost.c
> > @@ -1329,7 +1329,11 @@ rte_vhost_vring_call(int vid, uint16_t vring_idx)
> >  	if (!vq)
> >  		return -1;
> >
> > -	rte_spinlock_lock(&vq->access_lock);
> > +	if (!rte_spinlock_trylock(&vq->access_lock)) {
> > +		VHOST_LOG_CONFIG(dev->ifname, DEBUG,
> > +			"failed to kick guest, virtqueue busy.\n");
> > +		return -1;
> > +	}
> >
> 
> If it is a race, logging a message is not a good idea; the log will fill
> with this noise.
> 
> Instead make it statistic that can be seen by xstats.
It's a DEBUG log, users can't see it in practice.
Xia, Chenbo Sept. 20, 2022, 2:24 a.m. UTC | #3
Hi Changpeng,

> -----Original Message-----
> From: Liu, Changpeng <changpeng.liu@intel.com>
> Sent: Tuesday, September 6, 2022 10:22 AM
> To: dev@dpdk.org
> Cc: Liu, Changpeng <changpeng.liu@intel.com>; Maxime Coquelin
> <maxime.coquelin@redhat.com>; Xia, Chenbo <chenbo.xia@intel.com>
> Subject: [PATCH] vhost: use try_lock in rte_vhost_vring_call
> 
> Note that this function is in data path, so the thread context
> may not same as socket messages processing context, by using
> try_lock here, users can have another try in case of VQ's access
> lock is held by `vhost-events` thread.

Better to describe the issue this patch wants to fix and how does
it fix.

I remember it's a bz issue, do you want to backport? And it has
some bz ID, we need to add it in commit message.

> 
> Signed-off-by: Changpeng Liu <changpeng.liu@intel.com>
> ---
>  lib/vhost/vhost.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/lib/vhost/vhost.c b/lib/vhost/vhost.c
> index 60cb05a0ff..072d2acb7b 100644
> --- a/lib/vhost/vhost.c
> +++ b/lib/vhost/vhost.c
> @@ -1329,7 +1329,11 @@ rte_vhost_vring_call(int vid, uint16_t vring_idx)
>  	if (!vq)
>  		return -1;
> 
> -	rte_spinlock_lock(&vq->access_lock);
> +	if (!rte_spinlock_trylock(&vq->access_lock)) {
> +		VHOST_LOG_CONFIG(dev->ifname, DEBUG,

Should use VHOST_LOG_DATA

Thanks,
Chenbo

> +			"failed to kick guest, virtqueue busy.\n");
> +		return -1;
> +	}
> 
>  	if (vq_is_packed(dev))
>  		vhost_vring_call_packed(dev, vq);
> --
> 2.21.3
Liu, Changpeng Sept. 20, 2022, 2:34 a.m. UTC | #4
Hi Bo,

> -----Original Message-----
> From: Xia, Chenbo <chenbo.xia@intel.com>
> Sent: Tuesday, September 20, 2022 10:25 AM
> To: Liu, Changpeng <changpeng.liu@intel.com>; dev@dpdk.org
> Cc: Maxime Coquelin <maxime.coquelin@redhat.com>
> Subject: RE: [PATCH] vhost: use try_lock in rte_vhost_vring_call
> 
> Hi Changpeng,
> 
> > -----Original Message-----
> > From: Liu, Changpeng <changpeng.liu@intel.com>
> > Sent: Tuesday, September 6, 2022 10:22 AM
> > To: dev@dpdk.org
> > Cc: Liu, Changpeng <changpeng.liu@intel.com>; Maxime Coquelin
> > <maxime.coquelin@redhat.com>; Xia, Chenbo <chenbo.xia@intel.com>
> > Subject: [PATCH] vhost: use try_lock in rte_vhost_vring_call
> >
> > Note that this function is in data path, so the thread context
> > may not same as socket messages processing context, by using
> > try_lock here, users can have another try in case of VQ's access
> > lock is held by `vhost-events` thread.
> 
> Better to describe the issue this patch wants to fix and how does
> it fix.
> 
> I remember it's a bz issue, do you want to backport? And it has
> some bz ID, we need to add it in commit message.
Actually it's my intention not to add bz ID, as I think for this bz ID,
It's better not to lock all VQ's access lock for KICK/CALLFD messages,
What do you think? If this is identified as a fix, I can backport it to 22.05.
> 
> >
> > Signed-off-by: Changpeng Liu <changpeng.liu@intel.com>
> > ---
> >  lib/vhost/vhost.c | 6 +++++-
> >  1 file changed, 5 insertions(+), 1 deletion(-)
> >
> > diff --git a/lib/vhost/vhost.c b/lib/vhost/vhost.c
> > index 60cb05a0ff..072d2acb7b 100644
> > --- a/lib/vhost/vhost.c
> > +++ b/lib/vhost/vhost.c
> > @@ -1329,7 +1329,11 @@ rte_vhost_vring_call(int vid, uint16_t vring_idx)
> >  	if (!vq)
> >  		return -1;
> >
> > -	rte_spinlock_lock(&vq->access_lock);
> > +	if (!rte_spinlock_trylock(&vq->access_lock)) {
> > +		VHOST_LOG_CONFIG(dev->ifname, DEBUG,
> 
> Should use VHOST_LOG_DATA
OK.
> 
> Thanks,
> Chenbo
> 
> > +			"failed to kick guest, virtqueue busy.\n");
> > +		return -1;
> > +	}
> >
> >  	if (vq_is_packed(dev))
> >  		vhost_vring_call_packed(dev, vq);
> > --
> > 2.21.3
Xia, Chenbo Sept. 20, 2022, 2:53 a.m. UTC | #5
> -----Original Message-----
> From: Liu, Changpeng <changpeng.liu@intel.com>
> Sent: Tuesday, September 20, 2022 10:34 AM
> To: Xia, Chenbo <chenbo.xia@intel.com>; dev@dpdk.org
> Cc: Maxime Coquelin <maxime.coquelin@redhat.com>
> Subject: RE: [PATCH] vhost: use try_lock in rte_vhost_vring_call
> 
> Hi Bo,
> 
> > -----Original Message-----
> > From: Xia, Chenbo <chenbo.xia@intel.com>
> > Sent: Tuesday, September 20, 2022 10:25 AM
> > To: Liu, Changpeng <changpeng.liu@intel.com>; dev@dpdk.org
> > Cc: Maxime Coquelin <maxime.coquelin@redhat.com>
> > Subject: RE: [PATCH] vhost: use try_lock in rte_vhost_vring_call
> >
> > Hi Changpeng,
> >
> > > -----Original Message-----
> > > From: Liu, Changpeng <changpeng.liu@intel.com>
> > > Sent: Tuesday, September 6, 2022 10:22 AM
> > > To: dev@dpdk.org
> > > Cc: Liu, Changpeng <changpeng.liu@intel.com>; Maxime Coquelin
> > > <maxime.coquelin@redhat.com>; Xia, Chenbo <chenbo.xia@intel.com>
> > > Subject: [PATCH] vhost: use try_lock in rte_vhost_vring_call
> > >
> > > Note that this function is in data path, so the thread context
> > > may not same as socket messages processing context, by using
> > > try_lock here, users can have another try in case of VQ's access
> > > lock is held by `vhost-events` thread.
> >
> > Better to describe the issue this patch wants to fix and how does
> > it fix.
> >
> > I remember it's a bz issue, do you want to backport? And it has
> > some bz ID, we need to add it in commit message.
> Actually it's my intention not to add bz ID, as I think for this bz ID,
> It's better not to lock all VQ's access lock for KICK/CALLFD messages,

Do you plan to add this change? I think that may be an improvement to current
locking implementation.

Maxime, what do you think of this idea about only locking specific queue when
handling vring related message (not global config like mem table)?

> What do you think? If this is identified as a fix, I can backport it to
> 22.05.

You can decide, if this is planned to be the fix, just backport. I am just
thinking if this is not the fix for the bz, do we still need this?

Thanks,
Chenbo

> >
> > >
> > > Signed-off-by: Changpeng Liu <changpeng.liu@intel.com>
> > > ---
> > >  lib/vhost/vhost.c | 6 +++++-
> > >  1 file changed, 5 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/lib/vhost/vhost.c b/lib/vhost/vhost.c
> > > index 60cb05a0ff..072d2acb7b 100644
> > > --- a/lib/vhost/vhost.c
> > > +++ b/lib/vhost/vhost.c
> > > @@ -1329,7 +1329,11 @@ rte_vhost_vring_call(int vid, uint16_t
> vring_idx)
> > >  	if (!vq)
> > >  		return -1;
> > >
> > > -	rte_spinlock_lock(&vq->access_lock);
> > > +	if (!rte_spinlock_trylock(&vq->access_lock)) {
> > > +		VHOST_LOG_CONFIG(dev->ifname, DEBUG,
> >
> > Should use VHOST_LOG_DATA
> OK.
> >
> > Thanks,
> > Chenbo
> >
> > > +			"failed to kick guest, virtqueue busy.\n");
> > > +		return -1;
> > > +	}
> > >
> > >  	if (vq_is_packed(dev))
> > >  		vhost_vring_call_packed(dev, vq);
> > > --
> > > 2.21.3
Liu, Changpeng Sept. 20, 2022, 3 a.m. UTC | #6
> -----Original Message-----
> From: Xia, Chenbo <chenbo.xia@intel.com>
> Sent: Tuesday, September 20, 2022 10:54 AM
> To: Liu, Changpeng <changpeng.liu@intel.com>; dev@dpdk.org
> Cc: Maxime Coquelin <maxime.coquelin@redhat.com>
> Subject: RE: [PATCH] vhost: use try_lock in rte_vhost_vring_call
> 
> > -----Original Message-----
> > From: Liu, Changpeng <changpeng.liu@intel.com>
> > Sent: Tuesday, September 20, 2022 10:34 AM
> > To: Xia, Chenbo <chenbo.xia@intel.com>; dev@dpdk.org
> > Cc: Maxime Coquelin <maxime.coquelin@redhat.com>
> > Subject: RE: [PATCH] vhost: use try_lock in rte_vhost_vring_call
> >
> > Hi Bo,
> >
> > > -----Original Message-----
> > > From: Xia, Chenbo <chenbo.xia@intel.com>
> > > Sent: Tuesday, September 20, 2022 10:25 AM
> > > To: Liu, Changpeng <changpeng.liu@intel.com>; dev@dpdk.org
> > > Cc: Maxime Coquelin <maxime.coquelin@redhat.com>
> > > Subject: RE: [PATCH] vhost: use try_lock in rte_vhost_vring_call
> > >
> > > Hi Changpeng,
> > >
> > > > -----Original Message-----
> > > > From: Liu, Changpeng <changpeng.liu@intel.com>
> > > > Sent: Tuesday, September 6, 2022 10:22 AM
> > > > To: dev@dpdk.org
> > > > Cc: Liu, Changpeng <changpeng.liu@intel.com>; Maxime Coquelin
> > > > <maxime.coquelin@redhat.com>; Xia, Chenbo <chenbo.xia@intel.com>
> > > > Subject: [PATCH] vhost: use try_lock in rte_vhost_vring_call
> > > >
> > > > Note that this function is in data path, so the thread context
> > > > may not same as socket messages processing context, by using
> > > > try_lock here, users can have another try in case of VQ's access
> > > > lock is held by `vhost-events` thread.
> > >
> > > Better to describe the issue this patch wants to fix and how does
> > > it fix.
> > >
> > > I remember it's a bz issue, do you want to backport? And it has
> > > some bz ID, we need to add it in commit message.
> > Actually it's my intention not to add bz ID, as I think for this bz ID,
> > It's better not to lock all VQ's access lock for KICK/CALLFD messages,
> 
> Do you plan to add this change? I think that may be an improvement to current
> locking implementation.
No, I don't have such a plan.
> 
> Maxime, what do you think of this idea about only locking specific queue when
> handling vring related message (not global config like mem table)?
> 
> > What do you think? If this is identified as a fix, I can backport it to
> > 22.05.
> 
> You can decide, if this is planned to be the fix, just backport. I am just
> thinking if this is not the fix for the bz, do we still need this?
Adding the bz ID is OK to me. From SPDK's view indeed it's a fix. Will send
V2 later. Thanks.
> 
> Thanks,
> Chenbo
> 
> > >
> > > >
> > > > Signed-off-by: Changpeng Liu <changpeng.liu@intel.com>
> > > > ---
> > > >  lib/vhost/vhost.c | 6 +++++-
> > > >  1 file changed, 5 insertions(+), 1 deletion(-)
> > > >
> > > > diff --git a/lib/vhost/vhost.c b/lib/vhost/vhost.c
> > > > index 60cb05a0ff..072d2acb7b 100644
> > > > --- a/lib/vhost/vhost.c
> > > > +++ b/lib/vhost/vhost.c
> > > > @@ -1329,7 +1329,11 @@ rte_vhost_vring_call(int vid, uint16_t
> > vring_idx)
> > > >  	if (!vq)
> > > >  		return -1;
> > > >
> > > > -	rte_spinlock_lock(&vq->access_lock);
> > > > +	if (!rte_spinlock_trylock(&vq->access_lock)) {
> > > > +		VHOST_LOG_CONFIG(dev->ifname, DEBUG,
> > >
> > > Should use VHOST_LOG_DATA
> > OK.
> > >
> > > Thanks,
> > > Chenbo
> > >
> > > > +			"failed to kick guest, virtqueue busy.\n");
> > > > +		return -1;
> > > > +	}
> > > >
> > > >  	if (vq_is_packed(dev))
> > > >  		vhost_vring_call_packed(dev, vq);
> > > > --
> > > > 2.21.3
Maxime Coquelin Sept. 20, 2022, 7:12 a.m. UTC | #7
On 9/7/22 02:40, Liu, Changpeng wrote:
> 
> 
>> -----Original Message-----
>> From: Stephen Hemminger <stephen@networkplumber.org>
>> Sent: Wednesday, September 7, 2022 5:16 AM
>> To: Liu, Changpeng <changpeng.liu@intel.com>
>> Cc: dev@dpdk.org; Maxime Coquelin <maxime.coquelin@redhat.com>; Xia,
>> Chenbo <chenbo.xia@intel.com>
>> Subject: Re: [PATCH] vhost: use try_lock in rte_vhost_vring_call
>>
>> On Tue,  6 Sep 2022 10:22:25 +0800
>> Changpeng Liu <changpeng.liu@intel.com> wrote:
>>
>>> Note that this function is in data path, so the thread context
>>> may not same as socket messages processing context, by using
>>> try_lock here, users can have another try in case of VQ's access
>>> lock is held by `vhost-events` thread.
>>>
>>> Signed-off-by: Changpeng Liu <changpeng.liu@intel.com>
>>> ---
>>>   lib/vhost/vhost.c | 6 +++++-
>>>   1 file changed, 5 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/lib/vhost/vhost.c b/lib/vhost/vhost.c
>>> index 60cb05a0ff..072d2acb7b 100644
>>> --- a/lib/vhost/vhost.c
>>> +++ b/lib/vhost/vhost.c
>>> @@ -1329,7 +1329,11 @@ rte_vhost_vring_call(int vid, uint16_t vring_idx)
>>>   	if (!vq)
>>>   		return -1;
>>>
>>> -	rte_spinlock_lock(&vq->access_lock);
>>> +	if (!rte_spinlock_trylock(&vq->access_lock)) {
>>> +		VHOST_LOG_CONFIG(dev->ifname, DEBUG,
>>> +			"failed to kick guest, virtqueue busy.\n");
>>> +		return -1;
>>> +	}
>>>
>>
>> If it is a race, logging a message is not a good idea; the log will fill
>> with this noise.
>>
>> Instead make it statistic that can be seen by xstats.
> It's a DEBUG log, users can't see it in practice.
> 

Having an xstat would enable live debugging & post-mortem analysis.
You can have both the stats and the debug log.

Regards,
Maxime
Maxime Coquelin Sept. 20, 2022, 7:19 a.m. UTC | #8
On 9/6/22 04:22, Changpeng Liu wrote:
> Note that this function is in data path, so the thread context
> may not same as socket messages processing context, by using
> try_lock here, users can have another try in case of VQ's access
> lock is held by `vhost-events` thread.
> 
> Signed-off-by: Changpeng Liu <changpeng.liu@intel.com>
> ---
>   lib/vhost/vhost.c | 6 +++++-
>   1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/lib/vhost/vhost.c b/lib/vhost/vhost.c
> index 60cb05a0ff..072d2acb7b 100644
> --- a/lib/vhost/vhost.c
> +++ b/lib/vhost/vhost.c
> @@ -1329,7 +1329,11 @@ rte_vhost_vring_call(int vid, uint16_t vring_idx)
>   	if (!vq)
>   		return -1;
>   
> -	rte_spinlock_lock(&vq->access_lock);
> +	if (!rte_spinlock_trylock(&vq->access_lock)) {
> +		VHOST_LOG_CONFIG(dev->ifname, DEBUG,
> +			"failed to kick guest, virtqueue busy.\n");
> +		return -1;
> +	}
>   
>   	if (vq_is_packed(dev))
>   		vhost_vring_call_packed(dev, vq);

I think that's problematic, because it will break other applications
that currently rely on the API to block until the call is done.

Just some internal DPDK usage of this API:
./drivers/vdpa/ifc/ifcvf_vdpa.c:871:	rte_vhost_vring_call(internal->vid, 
qid);
./examples/vhost/virtio_net.c:236:	rte_vhost_vring_call(dev->vid, queue_id);
./examples/vhost/virtio_net.c:446:	rte_vhost_vring_call(dev->vid, queue_id);
./examples/vhost_blk/vhost_blk.c:99: 
rte_vhost_vring_call(task->ctrlr->vid, vq->id);
./examples/vhost_blk/vhost_blk.c:134: 
rte_vhost_vring_call(task->ctrlr->vid, vq->id);

This change will break all the above uses.

And that's not counting external projects.

ou should better introduce a new API that does not block.

Regards,
Maxime
Maxime Coquelin Sept. 20, 2022, 7:23 a.m. UTC | #9
On 9/20/22 04:53, Xia, Chenbo wrote:
>> -----Original Message-----
>> From: Liu, Changpeng <changpeng.liu@intel.com>
>> Sent: Tuesday, September 20, 2022 10:34 AM
>> To: Xia, Chenbo <chenbo.xia@intel.com>; dev@dpdk.org
>> Cc: Maxime Coquelin <maxime.coquelin@redhat.com>
>> Subject: RE: [PATCH] vhost: use try_lock in rte_vhost_vring_call
>>
>> Hi Bo,
>>
>>> -----Original Message-----
>>> From: Xia, Chenbo <chenbo.xia@intel.com>
>>> Sent: Tuesday, September 20, 2022 10:25 AM
>>> To: Liu, Changpeng <changpeng.liu@intel.com>; dev@dpdk.org
>>> Cc: Maxime Coquelin <maxime.coquelin@redhat.com>
>>> Subject: RE: [PATCH] vhost: use try_lock in rte_vhost_vring_call
>>>
>>> Hi Changpeng,
>>>
>>>> -----Original Message-----
>>>> From: Liu, Changpeng <changpeng.liu@intel.com>
>>>> Sent: Tuesday, September 6, 2022 10:22 AM
>>>> To: dev@dpdk.org
>>>> Cc: Liu, Changpeng <changpeng.liu@intel.com>; Maxime Coquelin
>>>> <maxime.coquelin@redhat.com>; Xia, Chenbo <chenbo.xia@intel.com>
>>>> Subject: [PATCH] vhost: use try_lock in rte_vhost_vring_call
>>>>
>>>> Note that this function is in data path, so the thread context
>>>> may not same as socket messages processing context, by using
>>>> try_lock here, users can have another try in case of VQ's access
>>>> lock is held by `vhost-events` thread.
>>>
>>> Better to describe the issue this patch wants to fix and how does
>>> it fix.
>>>
>>> I remember it's a bz issue, do you want to backport? And it has
>>> some bz ID, we need to add it in commit message.
>> Actually it's my intention not to add bz ID, as I think for this bz ID,
>> It's better not to lock all VQ's access lock for KICK/CALLFD messages,
> 
> Do you plan to add this change? I think that may be an improvement to current
> locking implementation.
> 
> Maxime, what do you think of this idea about only locking specific queue when
> handling vring related message (not global config like mem table)?

I think this is not a good idea.
For example SET_VRING_KICK can currently call
translate_ring_addresses(), which itself can call numa_realloc().

numa_realloc() may reallocate the dev, so you don't want it to be used
by other queues while it happens.

>> What do you think? If this is identified as a fix, I can backport it to
>> 22.05.
> 
> You can decide, if this is planned to be the fix, just backport. I am just
> thinking if this is not the fix for the bz, do we still need this?
> 
> Thanks,
> Chenbo
> 
>>>
>>>>
>>>> Signed-off-by: Changpeng Liu <changpeng.liu@intel.com>
>>>> ---
>>>>   lib/vhost/vhost.c | 6 +++++-
>>>>   1 file changed, 5 insertions(+), 1 deletion(-)
>>>>
>>>> diff --git a/lib/vhost/vhost.c b/lib/vhost/vhost.c
>>>> index 60cb05a0ff..072d2acb7b 100644
>>>> --- a/lib/vhost/vhost.c
>>>> +++ b/lib/vhost/vhost.c
>>>> @@ -1329,7 +1329,11 @@ rte_vhost_vring_call(int vid, uint16_t
>> vring_idx)
>>>>   	if (!vq)
>>>>   		return -1;
>>>>
>>>> -	rte_spinlock_lock(&vq->access_lock);
>>>> +	if (!rte_spinlock_trylock(&vq->access_lock)) {
>>>> +		VHOST_LOG_CONFIG(dev->ifname, DEBUG,
>>>
>>> Should use VHOST_LOG_DATA
>> OK.
>>>
>>> Thanks,
>>> Chenbo
>>>
>>>> +			"failed to kick guest, virtqueue busy.\n");
>>>> +		return -1;
>>>> +	}
>>>>
>>>>   	if (vq_is_packed(dev))
>>>>   		vhost_vring_call_packed(dev, vq);
>>>> --
>>>> 2.21.3
>
Liu, Changpeng Sept. 20, 2022, 7:29 a.m. UTC | #10
Hi Maxime,

> -----Original Message-----
> From: Maxime Coquelin <maxime.coquelin@redhat.com>
> Sent: Tuesday, September 20, 2022 3:19 PM
> To: Liu, Changpeng <changpeng.liu@intel.com>; dev@dpdk.org
> Cc: Xia, Chenbo <chenbo.xia@intel.com>
> Subject: Re: [PATCH] vhost: use try_lock in rte_vhost_vring_call
> 
> 
> 
> On 9/6/22 04:22, Changpeng Liu wrote:
> > Note that this function is in data path, so the thread context
> > may not same as socket messages processing context, by using
> > try_lock here, users can have another try in case of VQ's access
> > lock is held by `vhost-events` thread.
> >
> > Signed-off-by: Changpeng Liu <changpeng.liu@intel.com>
> > ---
> >   lib/vhost/vhost.c | 6 +++++-
> >   1 file changed, 5 insertions(+), 1 deletion(-)
> >
> > diff --git a/lib/vhost/vhost.c b/lib/vhost/vhost.c
> > index 60cb05a0ff..072d2acb7b 100644
> > --- a/lib/vhost/vhost.c
> > +++ b/lib/vhost/vhost.c
> > @@ -1329,7 +1329,11 @@ rte_vhost_vring_call(int vid, uint16_t vring_idx)
> >   	if (!vq)
> >   		return -1;
> >
> > -	rte_spinlock_lock(&vq->access_lock);
> > +	if (!rte_spinlock_trylock(&vq->access_lock)) {
> > +		VHOST_LOG_CONFIG(dev->ifname, DEBUG,
> > +			"failed to kick guest, virtqueue busy.\n");
> > +		return -1;
> > +	}
> >
> >   	if (vq_is_packed(dev))
> >   		vhost_vring_call_packed(dev, vq);
> 
> I think that's problematic, because it will break other applications
> that currently rely on the API to block until the call is done.
> 
> Just some internal DPDK usage of this API:
> ./drivers/vdpa/ifc/ifcvf_vdpa.c:871:	rte_vhost_vring_call(internal->vid,
> qid);
> ./examples/vhost/virtio_net.c:236:	rte_vhost_vring_call(dev->vid, queue_id);
> ./examples/vhost/virtio_net.c:446:	rte_vhost_vring_call(dev->vid, queue_id);
> ./examples/vhost_blk/vhost_blk.c:99:
> rte_vhost_vring_call(task->ctrlr->vid, vq->id);
> ./examples/vhost_blk/vhost_blk.c:134:
> rte_vhost_vring_call(task->ctrlr->vid, vq->id);
> 
> This change will break all the above uses.
> 
> And that's not counting external projects.
> 
> ou should better introduce a new API that does not block.
Could you add a new API to do this? 
I think we can use the new API in SPDK as a workaround, note that SPDK project is blocked for
a while which can't be used with DPDK 22.05 or newer.
Vhost-blk and scsi devices are not same with vhost-net, we need to cover SeaBIOS and VM
cases, so we need to start processing vrings after 1 vring is ready.
> 
> Regards,
> Maxime
Maxime Coquelin Sept. 20, 2022, 7:30 a.m. UTC | #11
On 9/20/22 09:23, Maxime Coquelin wrote:
> 
> 
> On 9/20/22 04:53, Xia, Chenbo wrote:
>>> -----Original Message-----
>>> From: Liu, Changpeng <changpeng.liu@intel.com>
>>> Sent: Tuesday, September 20, 2022 10:34 AM
>>> To: Xia, Chenbo <chenbo.xia@intel.com>; dev@dpdk.org
>>> Cc: Maxime Coquelin <maxime.coquelin@redhat.com>
>>> Subject: RE: [PATCH] vhost: use try_lock in rte_vhost_vring_call
>>>
>>> Hi Bo,
>>>
>>>> -----Original Message-----
>>>> From: Xia, Chenbo <chenbo.xia@intel.com>
>>>> Sent: Tuesday, September 20, 2022 10:25 AM
>>>> To: Liu, Changpeng <changpeng.liu@intel.com>; dev@dpdk.org
>>>> Cc: Maxime Coquelin <maxime.coquelin@redhat.com>
>>>> Subject: RE: [PATCH] vhost: use try_lock in rte_vhost_vring_call
>>>>
>>>> Hi Changpeng,
>>>>
>>>>> -----Original Message-----
>>>>> From: Liu, Changpeng <changpeng.liu@intel.com>
>>>>> Sent: Tuesday, September 6, 2022 10:22 AM
>>>>> To: dev@dpdk.org
>>>>> Cc: Liu, Changpeng <changpeng.liu@intel.com>; Maxime Coquelin
>>>>> <maxime.coquelin@redhat.com>; Xia, Chenbo <chenbo.xia@intel.com>
>>>>> Subject: [PATCH] vhost: use try_lock in rte_vhost_vring_call
>>>>>
>>>>> Note that this function is in data path, so the thread context
>>>>> may not same as socket messages processing context, by using
>>>>> try_lock here, users can have another try in case of VQ's access
>>>>> lock is held by `vhost-events` thread.
>>>>
>>>> Better to describe the issue this patch wants to fix and how does
>>>> it fix.
>>>>
>>>> I remember it's a bz issue, do you want to backport? And it has
>>>> some bz ID, we need to add it in commit message.
>>> Actually it's my intention not to add bz ID, as I think for this bz ID,
>>> It's better not to lock all VQ's access lock for KICK/CALLFD messages,
>>
>> Do you plan to add this change? I think that may be an improvement to 
>> current
>> locking implementation.
>>
>> Maxime, what do you think of this idea about only locking specific 
>> queue when
>> handling vring related message (not global config like mem table)?
> 
> I think this is not a good idea.
> For example SET_VRING_KICK can currently call
> translate_ring_addresses(), which itself can call numa_realloc().
> 
> numa_realloc() may reallocate the dev, so you don't want it to be used
> by other queues while it happens.

Hmm, actually that may be possible because numa_realloc() reallocs the 
dev only if it is not running.

So maybe you can propose something, but you will have to test it
carefully with use-cases involving NUMA reallocation.

>>> What do you think? If this is identified as a fix, I can backport it to
>>> 22.05.
>>
>> You can decide, if this is planned to be the fix, just backport. I am 
>> just
>> thinking if this is not the fix for the bz, do we still need this?
>>
>> Thanks,
>> Chenbo
>>
>>>>
>>>>>
>>>>> Signed-off-by: Changpeng Liu <changpeng.liu@intel.com>
>>>>> ---
>>>>>   lib/vhost/vhost.c | 6 +++++-
>>>>>   1 file changed, 5 insertions(+), 1 deletion(-)
>>>>>
>>>>> diff --git a/lib/vhost/vhost.c b/lib/vhost/vhost.c
>>>>> index 60cb05a0ff..072d2acb7b 100644
>>>>> --- a/lib/vhost/vhost.c
>>>>> +++ b/lib/vhost/vhost.c
>>>>> @@ -1329,7 +1329,11 @@ rte_vhost_vring_call(int vid, uint16_t
>>> vring_idx)
>>>>>       if (!vq)
>>>>>           return -1;
>>>>>
>>>>> -    rte_spinlock_lock(&vq->access_lock);
>>>>> +    if (!rte_spinlock_trylock(&vq->access_lock)) {
>>>>> +        VHOST_LOG_CONFIG(dev->ifname, DEBUG,
>>>>
>>>> Should use VHOST_LOG_DATA
>>> OK.
>>>>
>>>> Thanks,
>>>> Chenbo
>>>>
>>>>> +            "failed to kick guest, virtqueue busy.\n");
>>>>> +        return -1;
>>>>> +    }
>>>>>
>>>>>       if (vq_is_packed(dev))
>>>>>           vhost_vring_call_packed(dev, vq);
>>>>> -- 
>>>>> 2.21.3
>>
Maxime Coquelin Sept. 20, 2022, 7:34 a.m. UTC | #12
On 9/20/22 09:29, Liu, Changpeng wrote:
> Hi Maxime,
> 
>> -----Original Message-----
>> From: Maxime Coquelin <maxime.coquelin@redhat.com>
>> Sent: Tuesday, September 20, 2022 3:19 PM
>> To: Liu, Changpeng <changpeng.liu@intel.com>; dev@dpdk.org
>> Cc: Xia, Chenbo <chenbo.xia@intel.com>
>> Subject: Re: [PATCH] vhost: use try_lock in rte_vhost_vring_call
>>
>>
>>
>> On 9/6/22 04:22, Changpeng Liu wrote:
>>> Note that this function is in data path, so the thread context
>>> may not same as socket messages processing context, by using
>>> try_lock here, users can have another try in case of VQ's access
>>> lock is held by `vhost-events` thread.
>>>
>>> Signed-off-by: Changpeng Liu <changpeng.liu@intel.com>
>>> ---
>>>    lib/vhost/vhost.c | 6 +++++-
>>>    1 file changed, 5 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/lib/vhost/vhost.c b/lib/vhost/vhost.c
>>> index 60cb05a0ff..072d2acb7b 100644
>>> --- a/lib/vhost/vhost.c
>>> +++ b/lib/vhost/vhost.c
>>> @@ -1329,7 +1329,11 @@ rte_vhost_vring_call(int vid, uint16_t vring_idx)
>>>    	if (!vq)
>>>    		return -1;
>>>
>>> -	rte_spinlock_lock(&vq->access_lock);
>>> +	if (!rte_spinlock_trylock(&vq->access_lock)) {
>>> +		VHOST_LOG_CONFIG(dev->ifname, DEBUG,
>>> +			"failed to kick guest, virtqueue busy.\n");
>>> +		return -1;
>>> +	}
>>>
>>>    	if (vq_is_packed(dev))
>>>    		vhost_vring_call_packed(dev, vq);
>>
>> I think that's problematic, because it will break other applications
>> that currently rely on the API to block until the call is done.
>>
>> Just some internal DPDK usage of this API:
>> ./drivers/vdpa/ifc/ifcvf_vdpa.c:871:	rte_vhost_vring_call(internal->vid,
>> qid);
>> ./examples/vhost/virtio_net.c:236:	rte_vhost_vring_call(dev->vid, queue_id);
>> ./examples/vhost/virtio_net.c:446:	rte_vhost_vring_call(dev->vid, queue_id);
>> ./examples/vhost_blk/vhost_blk.c:99:
>> rte_vhost_vring_call(task->ctrlr->vid, vq->id);
>> ./examples/vhost_blk/vhost_blk.c:134:
>> rte_vhost_vring_call(task->ctrlr->vid, vq->id);
>>
>> This change will break all the above uses.
>>
>> And that's not counting external projects.
>>
>> ou should better introduce a new API that does not block.
> Could you add a new API to do this?
 >
> I think we can use the new API in SPDK as a workaround, note that SPDK project is blocked for
> a while which can't be used with DPDK 22.05 or newer.

DPDK v22.05?
What is the commit introducing the regression?

Note that if we introduce a new API, it won't be backported to stable
branches.


> Vhost-blk and scsi devices are not same with vhost-net, we need to cover SeaBIOS and VM
> cases, so we need to start processing vrings after 1 vring is ready.
>>
>> Regards,
>> Maxime
>
Liu, Changpeng Sept. 20, 2022, 7:45 a.m. UTC | #13
> -----Original Message-----
> From: Maxime Coquelin <maxime.coquelin@redhat.com>
> Sent: Tuesday, September 20, 2022 3:35 PM
> To: Liu, Changpeng <changpeng.liu@intel.com>; dev@dpdk.org
> Cc: Xia, Chenbo <chenbo.xia@intel.com>
> Subject: Re: [PATCH] vhost: use try_lock in rte_vhost_vring_call
> 
> 
> 
> On 9/20/22 09:29, Liu, Changpeng wrote:
> > Hi Maxime,
> >
> >> -----Original Message-----
> >> From: Maxime Coquelin <maxime.coquelin@redhat.com>
> >> Sent: Tuesday, September 20, 2022 3:19 PM
> >> To: Liu, Changpeng <changpeng.liu@intel.com>; dev@dpdk.org
> >> Cc: Xia, Chenbo <chenbo.xia@intel.com>
> >> Subject: Re: [PATCH] vhost: use try_lock in rte_vhost_vring_call
> >>
> >>
> >>
> >> On 9/6/22 04:22, Changpeng Liu wrote:
> >>> Note that this function is in data path, so the thread context
> >>> may not same as socket messages processing context, by using
> >>> try_lock here, users can have another try in case of VQ's access
> >>> lock is held by `vhost-events` thread.
> >>>
> >>> Signed-off-by: Changpeng Liu <changpeng.liu@intel.com>
> >>> ---
> >>>    lib/vhost/vhost.c | 6 +++++-
> >>>    1 file changed, 5 insertions(+), 1 deletion(-)
> >>>
> >>> diff --git a/lib/vhost/vhost.c b/lib/vhost/vhost.c
> >>> index 60cb05a0ff..072d2acb7b 100644
> >>> --- a/lib/vhost/vhost.c
> >>> +++ b/lib/vhost/vhost.c
> >>> @@ -1329,7 +1329,11 @@ rte_vhost_vring_call(int vid, uint16_t vring_idx)
> >>>    	if (!vq)
> >>>    		return -1;
> >>>
> >>> -	rte_spinlock_lock(&vq->access_lock);
> >>> +	if (!rte_spinlock_trylock(&vq->access_lock)) {
> >>> +		VHOST_LOG_CONFIG(dev->ifname, DEBUG,
> >>> +			"failed to kick guest, virtqueue busy.\n");
> >>> +		return -1;
> >>> +	}
> >>>
> >>>    	if (vq_is_packed(dev))
> >>>    		vhost_vring_call_packed(dev, vq);
> >>
> >> I think that's problematic, because it will break other applications
> >> that currently rely on the API to block until the call is done.
> >>
> >> Just some internal DPDK usage of this API:
> >> ./drivers/vdpa/ifc/ifcvf_vdpa.c:871:	rte_vhost_vring_call(internal->vid,
> >> qid);
> >> ./examples/vhost/virtio_net.c:236:	rte_vhost_vring_call(dev->vid, queue_id);
> >> ./examples/vhost/virtio_net.c:446:	rte_vhost_vring_call(dev->vid, queue_id);
> >> ./examples/vhost_blk/vhost_blk.c:99:
> >> rte_vhost_vring_call(task->ctrlr->vid, vq->id);
> >> ./examples/vhost_blk/vhost_blk.c:134:
> >> rte_vhost_vring_call(task->ctrlr->vid, vq->id);
> >>
> >> This change will break all the above uses.
> >>
> >> And that's not counting external projects.
> >>
> >> ou should better introduce a new API that does not block.
> > Could you add a new API to do this?
>  >
> > I think we can use the new API in SPDK as a workaround, note that SPDK project
> is blocked for
> > a while which can't be used with DPDK 22.05 or newer.
> 
> DPDK v22.05?
> What is the commit introducing the regression?
Here is the commit introducing this issue
c5736998305d ("vhost: fix missing virtqueue lock protection")
Bugzilla ID: 1015
> 
> Note that if we introduce a new API, it won't be backported to stable
> branches.
I understand, but do we have better idea in short time? we're planning
to release SPDK 22.09 recently.
> 
> 
> > Vhost-blk and scsi devices are not same with vhost-net, we need to cover
> SeaBIOS and VM
> > cases, so we need to start processing vrings after 1 vring is ready.
> >>
> >> Regards,
> >> Maxime
> >
Maxime Coquelin Sept. 20, 2022, 8:12 a.m. UTC | #14
On 9/20/22 09:45, Liu, Changpeng wrote:
> 
> 
>> -----Original Message-----
>> From: Maxime Coquelin <maxime.coquelin@redhat.com>
>> Sent: Tuesday, September 20, 2022 3:35 PM
>> To: Liu, Changpeng <changpeng.liu@intel.com>; dev@dpdk.org
>> Cc: Xia, Chenbo <chenbo.xia@intel.com>
>> Subject: Re: [PATCH] vhost: use try_lock in rte_vhost_vring_call
>>
>>
>>
>> On 9/20/22 09:29, Liu, Changpeng wrote:
>>> Hi Maxime,
>>>
>>>> -----Original Message-----
>>>> From: Maxime Coquelin <maxime.coquelin@redhat.com>
>>>> Sent: Tuesday, September 20, 2022 3:19 PM
>>>> To: Liu, Changpeng <changpeng.liu@intel.com>; dev@dpdk.org
>>>> Cc: Xia, Chenbo <chenbo.xia@intel.com>
>>>> Subject: Re: [PATCH] vhost: use try_lock in rte_vhost_vring_call
>>>>
>>>>
>>>>
>>>> On 9/6/22 04:22, Changpeng Liu wrote:
>>>>> Note that this function is in data path, so the thread context
>>>>> may not same as socket messages processing context, by using
>>>>> try_lock here, users can have another try in case of VQ's access
>>>>> lock is held by `vhost-events` thread.
>>>>>
>>>>> Signed-off-by: Changpeng Liu <changpeng.liu@intel.com>
>>>>> ---
>>>>>     lib/vhost/vhost.c | 6 +++++-
>>>>>     1 file changed, 5 insertions(+), 1 deletion(-)
>>>>>
>>>>> diff --git a/lib/vhost/vhost.c b/lib/vhost/vhost.c
>>>>> index 60cb05a0ff..072d2acb7b 100644
>>>>> --- a/lib/vhost/vhost.c
>>>>> +++ b/lib/vhost/vhost.c
>>>>> @@ -1329,7 +1329,11 @@ rte_vhost_vring_call(int vid, uint16_t vring_idx)
>>>>>     	if (!vq)
>>>>>     		return -1;
>>>>>
>>>>> -	rte_spinlock_lock(&vq->access_lock);
>>>>> +	if (!rte_spinlock_trylock(&vq->access_lock)) {
>>>>> +		VHOST_LOG_CONFIG(dev->ifname, DEBUG,
>>>>> +			"failed to kick guest, virtqueue busy.\n");
>>>>> +		return -1;
>>>>> +	}
>>>>>
>>>>>     	if (vq_is_packed(dev))
>>>>>     		vhost_vring_call_packed(dev, vq);
>>>>
>>>> I think that's problematic, because it will break other applications
>>>> that currently rely on the API to block until the call is done.
>>>>
>>>> Just some internal DPDK usage of this API:
>>>> ./drivers/vdpa/ifc/ifcvf_vdpa.c:871:	rte_vhost_vring_call(internal->vid,
>>>> qid);
>>>> ./examples/vhost/virtio_net.c:236:	rte_vhost_vring_call(dev->vid, queue_id);
>>>> ./examples/vhost/virtio_net.c:446:	rte_vhost_vring_call(dev->vid, queue_id);
>>>> ./examples/vhost_blk/vhost_blk.c:99:
>>>> rte_vhost_vring_call(task->ctrlr->vid, vq->id);
>>>> ./examples/vhost_blk/vhost_blk.c:134:
>>>> rte_vhost_vring_call(task->ctrlr->vid, vq->id);
>>>>
>>>> This change will break all the above uses.
>>>>
>>>> And that's not counting external projects.
>>>>
>>>> ou should better introduce a new API that does not block.
>>> Could you add a new API to do this?
>>   >
>>> I think we can use the new API in SPDK as a workaround, note that SPDK project
>> is blocked for
>>> a while which can't be used with DPDK 22.05 or newer.
>>
>> DPDK v22.05?
>> What is the commit introducing the regression?
> Here is the commit introducing this issue
> c5736998305d ("vhost: fix missing virtqueue lock protection")
> Bugzilla ID: 1015

Ok, it cannot be reverted, as it prevents some undefined
behaviors/crashes.

>>
>> Note that if we introduce a new API, it won't be backported to stable
>> branches.
> I understand, but do we have better idea in short time? we're planning
> to release SPDK 22.09 recently.

You can have another thread that sends the call?

>>
>>
>>> Vhost-blk and scsi devices are not same with vhost-net, we need to cover
>> SeaBIOS and VM
>>> cases, so we need to start processing vrings after 1 vring is ready.
>>>>
>>>> Regards,
>>>> Maxime
>>>
>
Liu, Changpeng Sept. 20, 2022, 8:43 a.m. UTC | #15
> -----Original Message-----
> From: Maxime Coquelin <maxime.coquelin@redhat.com>
> Sent: Tuesday, September 20, 2022 4:13 PM
> To: Liu, Changpeng <changpeng.liu@intel.com>; dev@dpdk.org
> Cc: Xia, Chenbo <chenbo.xia@intel.com>
> Subject: Re: [PATCH] vhost: use try_lock in rte_vhost_vring_call
> 
> 
> 
> On 9/20/22 09:45, Liu, Changpeng wrote:
> >
> >
> >> -----Original Message-----
> >> From: Maxime Coquelin <maxime.coquelin@redhat.com>
> >> Sent: Tuesday, September 20, 2022 3:35 PM
> >> To: Liu, Changpeng <changpeng.liu@intel.com>; dev@dpdk.org
> >> Cc: Xia, Chenbo <chenbo.xia@intel.com>
> >> Subject: Re: [PATCH] vhost: use try_lock in rte_vhost_vring_call
> >>
> >>
> >>
> >> On 9/20/22 09:29, Liu, Changpeng wrote:
> >>> Hi Maxime,
> >>>
> >>>> -----Original Message-----
> >>>> From: Maxime Coquelin <maxime.coquelin@redhat.com>
> >>>> Sent: Tuesday, September 20, 2022 3:19 PM
> >>>> To: Liu, Changpeng <changpeng.liu@intel.com>; dev@dpdk.org
> >>>> Cc: Xia, Chenbo <chenbo.xia@intel.com>
> >>>> Subject: Re: [PATCH] vhost: use try_lock in rte_vhost_vring_call
> >>>>
> >>>>
> >>>>
> >>>> On 9/6/22 04:22, Changpeng Liu wrote:
> >>>>> Note that this function is in data path, so the thread context
> >>>>> may not same as socket messages processing context, by using
> >>>>> try_lock here, users can have another try in case of VQ's access
> >>>>> lock is held by `vhost-events` thread.
> >>>>>
> >>>>> Signed-off-by: Changpeng Liu <changpeng.liu@intel.com>
> >>>>> ---
> >>>>>     lib/vhost/vhost.c | 6 +++++-
> >>>>>     1 file changed, 5 insertions(+), 1 deletion(-)
> >>>>>
> >>>>> diff --git a/lib/vhost/vhost.c b/lib/vhost/vhost.c
> >>>>> index 60cb05a0ff..072d2acb7b 100644
> >>>>> --- a/lib/vhost/vhost.c
> >>>>> +++ b/lib/vhost/vhost.c
> >>>>> @@ -1329,7 +1329,11 @@ rte_vhost_vring_call(int vid, uint16_t vring_idx)
> >>>>>     	if (!vq)
> >>>>>     		return -1;
> >>>>>
> >>>>> -	rte_spinlock_lock(&vq->access_lock);
> >>>>> +	if (!rte_spinlock_trylock(&vq->access_lock)) {
> >>>>> +		VHOST_LOG_CONFIG(dev->ifname, DEBUG,
> >>>>> +			"failed to kick guest, virtqueue busy.\n");
> >>>>> +		return -1;
> >>>>> +	}
> >>>>>
> >>>>>     	if (vq_is_packed(dev))
> >>>>>     		vhost_vring_call_packed(dev, vq);
> >>>>
> >>>> I think that's problematic, because it will break other applications
> >>>> that currently rely on the API to block until the call is done.
> >>>>
> >>>> Just some internal DPDK usage of this API:
> >>>> ./drivers/vdpa/ifc/ifcvf_vdpa.c:871:	rte_vhost_vring_call(internal->vid,
> >>>> qid);
> >>>> ./examples/vhost/virtio_net.c:236:	rte_vhost_vring_call(dev->vid,
> queue_id);
> >>>> ./examples/vhost/virtio_net.c:446:	rte_vhost_vring_call(dev->vid,
> queue_id);
> >>>> ./examples/vhost_blk/vhost_blk.c:99:
> >>>> rte_vhost_vring_call(task->ctrlr->vid, vq->id);
> >>>> ./examples/vhost_blk/vhost_blk.c:134:
> >>>> rte_vhost_vring_call(task->ctrlr->vid, vq->id);
> >>>>
> >>>> This change will break all the above uses.
> >>>>
> >>>> And that's not counting external projects.
> >>>>
> >>>> ou should better introduce a new API that does not block.
> >>> Could you add a new API to do this?
> >>   >
> >>> I think we can use the new API in SPDK as a workaround, note that SPDK
> project
> >> is blocked for
> >>> a while which can't be used with DPDK 22.05 or newer.
> >>
> >> DPDK v22.05?
> >> What is the commit introducing the regression?
> > Here is the commit introducing this issue
> > c5736998305d ("vhost: fix missing virtqueue lock protection")
> > Bugzilla ID: 1015
> 
> Ok, it cannot be reverted, as it prevents some undefined
> behaviors/crashes.
> 
> >>
> >> Note that if we introduce a new API, it won't be backported to stable
> >> branches.
> > I understand, but do we have better idea in short time? we're planning
> > to release SPDK 22.09 recently.
> 
> You can have another thread that sends the call?
We already use two threads to do this. Here is the example for existing code in SPDK:

DPDK vhost-events thread                        SPDK thread

    SET_VRING_KICK VQ1       ---->            Start polling VQ1
    Reply to DPDK                    <----              Done
    SET_VRING_KICK VQ2       ---->            thread is blocked on VQ's access lock, SPDK thread can't provide reply message                               
 
For example, we can just return for  SET_VRING_KICK VQ2 message without checking SPDK thread, but this leave
uncertain replies to VM.
> 
> >>
> >>
> >>> Vhost-blk and scsi devices are not same with vhost-net, we need to cover
> >> SeaBIOS and VM
> >>> cases, so we need to start processing vrings after 1 vring is ready.
> >>>>
> >>>> Regards,
> >>>> Maxime
> >>>
> >
Maxime Coquelin Sept. 21, 2022, 9:41 a.m. UTC | #16
On 9/20/22 10:43, Liu, Changpeng wrote:
> 
> 
>> -----Original Message-----
>> From: Maxime Coquelin <maxime.coquelin@redhat.com>
>> Sent: Tuesday, September 20, 2022 4:13 PM
>> To: Liu, Changpeng <changpeng.liu@intel.com>; dev@dpdk.org
>> Cc: Xia, Chenbo <chenbo.xia@intel.com>
>> Subject: Re: [PATCH] vhost: use try_lock in rte_vhost_vring_call
>>
>>
>>
>> On 9/20/22 09:45, Liu, Changpeng wrote:
>>>
>>>
>>>> -----Original Message-----
>>>> From: Maxime Coquelin <maxime.coquelin@redhat.com>
>>>> Sent: Tuesday, September 20, 2022 3:35 PM
>>>> To: Liu, Changpeng <changpeng.liu@intel.com>; dev@dpdk.org
>>>> Cc: Xia, Chenbo <chenbo.xia@intel.com>
>>>> Subject: Re: [PATCH] vhost: use try_lock in rte_vhost_vring_call
>>>>
>>>>
>>>>
>>>> On 9/20/22 09:29, Liu, Changpeng wrote:
>>>>> Hi Maxime,
>>>>>
>>>>>> -----Original Message-----
>>>>>> From: Maxime Coquelin <maxime.coquelin@redhat.com>
>>>>>> Sent: Tuesday, September 20, 2022 3:19 PM
>>>>>> To: Liu, Changpeng <changpeng.liu@intel.com>; dev@dpdk.org
>>>>>> Cc: Xia, Chenbo <chenbo.xia@intel.com>
>>>>>> Subject: Re: [PATCH] vhost: use try_lock in rte_vhost_vring_call
>>>>>>
>>>>>>
>>>>>>
>>>>>> On 9/6/22 04:22, Changpeng Liu wrote:
>>>>>>> Note that this function is in data path, so the thread context
>>>>>>> may not same as socket messages processing context, by using
>>>>>>> try_lock here, users can have another try in case of VQ's access
>>>>>>> lock is held by `vhost-events` thread.
>>>>>>>
>>>>>>> Signed-off-by: Changpeng Liu <changpeng.liu@intel.com>
>>>>>>> ---
>>>>>>>      lib/vhost/vhost.c | 6 +++++-
>>>>>>>      1 file changed, 5 insertions(+), 1 deletion(-)
>>>>>>>
>>>>>>> diff --git a/lib/vhost/vhost.c b/lib/vhost/vhost.c
>>>>>>> index 60cb05a0ff..072d2acb7b 100644
>>>>>>> --- a/lib/vhost/vhost.c
>>>>>>> +++ b/lib/vhost/vhost.c
>>>>>>> @@ -1329,7 +1329,11 @@ rte_vhost_vring_call(int vid, uint16_t vring_idx)
>>>>>>>      	if (!vq)
>>>>>>>      		return -1;
>>>>>>>
>>>>>>> -	rte_spinlock_lock(&vq->access_lock);
>>>>>>> +	if (!rte_spinlock_trylock(&vq->access_lock)) {
>>>>>>> +		VHOST_LOG_CONFIG(dev->ifname, DEBUG,
>>>>>>> +			"failed to kick guest, virtqueue busy.\n");
>>>>>>> +		return -1;
>>>>>>> +	}
>>>>>>>
>>>>>>>      	if (vq_is_packed(dev))
>>>>>>>      		vhost_vring_call_packed(dev, vq);
>>>>>>
>>>>>> I think that's problematic, because it will break other applications
>>>>>> that currently rely on the API to block until the call is done.
>>>>>>
>>>>>> Just some internal DPDK usage of this API:
>>>>>> ./drivers/vdpa/ifc/ifcvf_vdpa.c:871:	rte_vhost_vring_call(internal->vid,
>>>>>> qid);
>>>>>> ./examples/vhost/virtio_net.c:236:	rte_vhost_vring_call(dev->vid,
>> queue_id);
>>>>>> ./examples/vhost/virtio_net.c:446:	rte_vhost_vring_call(dev->vid,
>> queue_id);
>>>>>> ./examples/vhost_blk/vhost_blk.c:99:
>>>>>> rte_vhost_vring_call(task->ctrlr->vid, vq->id);
>>>>>> ./examples/vhost_blk/vhost_blk.c:134:
>>>>>> rte_vhost_vring_call(task->ctrlr->vid, vq->id);
>>>>>>
>>>>>> This change will break all the above uses.
>>>>>>
>>>>>> And that's not counting external projects.
>>>>>>
>>>>>> ou should better introduce a new API that does not block.
>>>>> Could you add a new API to do this?
>>>>    >
>>>>> I think we can use the new API in SPDK as a workaround, note that SPDK
>> project
>>>> is blocked for
>>>>> a while which can't be used with DPDK 22.05 or newer.
>>>>
>>>> DPDK v22.05?
>>>> What is the commit introducing the regression?
>>> Here is the commit introducing this issue
>>> c5736998305d ("vhost: fix missing virtqueue lock protection")
>>> Bugzilla ID: 1015
>>
>> Ok, it cannot be reverted, as it prevents some undefined
>> behaviors/crashes.
>>
>>>>
>>>> Note that if we introduce a new API, it won't be backported to stable
>>>> branches.
>>> I understand, but do we have better idea in short time? we're planning
>>> to release SPDK 22.09 recently.
>>
>> You can have another thread that sends the call?
> We already use two threads to do this. Here is the example for existing code in SPDK:
> 
> DPDK vhost-events thread                        SPDK thread
> 
>      SET_VRING_KICK VQ1       ---->            Start polling VQ1
>      Reply to DPDK                    <----              Done
>      SET_VRING_KICK VQ2       ---->            thread is blocked on VQ's access lock, SPDK thread can't provide reply message
>   
> For example, we can just return for  SET_VRING_KICK VQ2 message without checking SPDK thread, but this leave
> uncertain replies to VM.

I'm sorry but you will have to find a workaround while v22.11 is out and
you can consume it. We can neither backport new API nor we can break all
the other applications not handling locking failure.

Regarding the new API for v22.11, I should be named something like
rte_vhost_vring_call_nonblock(), and ideally should return some like
-EAGAIN instead of -1 o that the applications can distinguish between a
real failure and a need for retry.

Regards,
Maxime

>>
>>>>
>>>>
>>>>> Vhost-blk and scsi devices are not same with vhost-net, we need to cover
>>>> SeaBIOS and VM
>>>>> cases, so we need to start processing vrings after 1 vring is ready.
>>>>>>
>>>>>> Regards,
>>>>>> Maxime
>>>>>
>>>
>
Liu, Changpeng Sept. 21, 2022, 9:52 a.m. UTC | #17
> -----Original Message-----
> From: Maxime Coquelin <maxime.coquelin@redhat.com>
> Sent: Wednesday, September 21, 2022 5:41 PM
> To: Liu, Changpeng <changpeng.liu@intel.com>; dev@dpdk.org
> Cc: Xia, Chenbo <chenbo.xia@intel.com>
> Subject: Re: [PATCH] vhost: use try_lock in rte_vhost_vring_call
> 
> 
> 
> On 9/20/22 10:43, Liu, Changpeng wrote:
> >
> >
> >> -----Original Message-----
> >> From: Maxime Coquelin <maxime.coquelin@redhat.com>
> >> Sent: Tuesday, September 20, 2022 4:13 PM
> >> To: Liu, Changpeng <changpeng.liu@intel.com>; dev@dpdk.org
> >> Cc: Xia, Chenbo <chenbo.xia@intel.com>
> >> Subject: Re: [PATCH] vhost: use try_lock in rte_vhost_vring_call
> >>
> >>
> >>
> >> On 9/20/22 09:45, Liu, Changpeng wrote:
> >>>
> >>>
> >>>> -----Original Message-----
> >>>> From: Maxime Coquelin <maxime.coquelin@redhat.com>
> >>>> Sent: Tuesday, September 20, 2022 3:35 PM
> >>>> To: Liu, Changpeng <changpeng.liu@intel.com>; dev@dpdk.org
> >>>> Cc: Xia, Chenbo <chenbo.xia@intel.com>
> >>>> Subject: Re: [PATCH] vhost: use try_lock in rte_vhost_vring_call
> >>>>
> >>>>
> >>>>
> >>>> On 9/20/22 09:29, Liu, Changpeng wrote:
> >>>>> Hi Maxime,
> >>>>>
> >>>>>> -----Original Message-----
> >>>>>> From: Maxime Coquelin <maxime.coquelin@redhat.com>
> >>>>>> Sent: Tuesday, September 20, 2022 3:19 PM
> >>>>>> To: Liu, Changpeng <changpeng.liu@intel.com>; dev@dpdk.org
> >>>>>> Cc: Xia, Chenbo <chenbo.xia@intel.com>
> >>>>>> Subject: Re: [PATCH] vhost: use try_lock in rte_vhost_vring_call
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>> On 9/6/22 04:22, Changpeng Liu wrote:
> >>>>>>> Note that this function is in data path, so the thread context
> >>>>>>> may not same as socket messages processing context, by using
> >>>>>>> try_lock here, users can have another try in case of VQ's access
> >>>>>>> lock is held by `vhost-events` thread.
> >>>>>>>
> >>>>>>> Signed-off-by: Changpeng Liu <changpeng.liu@intel.com>
> >>>>>>> ---
> >>>>>>>      lib/vhost/vhost.c | 6 +++++-
> >>>>>>>      1 file changed, 5 insertions(+), 1 deletion(-)
> >>>>>>>
> >>>>>>> diff --git a/lib/vhost/vhost.c b/lib/vhost/vhost.c
> >>>>>>> index 60cb05a0ff..072d2acb7b 100644
> >>>>>>> --- a/lib/vhost/vhost.c
> >>>>>>> +++ b/lib/vhost/vhost.c
> >>>>>>> @@ -1329,7 +1329,11 @@ rte_vhost_vring_call(int vid, uint16_t
> vring_idx)
> >>>>>>>      	if (!vq)
> >>>>>>>      		return -1;
> >>>>>>>
> >>>>>>> -	rte_spinlock_lock(&vq->access_lock);
> >>>>>>> +	if (!rte_spinlock_trylock(&vq->access_lock)) {
> >>>>>>> +		VHOST_LOG_CONFIG(dev->ifname, DEBUG,
> >>>>>>> +			"failed to kick guest, virtqueue busy.\n");
> >>>>>>> +		return -1;
> >>>>>>> +	}
> >>>>>>>
> >>>>>>>      	if (vq_is_packed(dev))
> >>>>>>>      		vhost_vring_call_packed(dev, vq);
> >>>>>>
> >>>>>> I think that's problematic, because it will break other applications
> >>>>>> that currently rely on the API to block until the call is done.
> >>>>>>
> >>>>>> Just some internal DPDK usage of this API:
> >>>>>> ./drivers/vdpa/ifc/ifcvf_vdpa.c:871:	rte_vhost_vring_call(internal->vid,
> >>>>>> qid);
> >>>>>> ./examples/vhost/virtio_net.c:236:	rte_vhost_vring_call(dev->vid,
> >> queue_id);
> >>>>>> ./examples/vhost/virtio_net.c:446:	rte_vhost_vring_call(dev->vid,
> >> queue_id);
> >>>>>> ./examples/vhost_blk/vhost_blk.c:99:
> >>>>>> rte_vhost_vring_call(task->ctrlr->vid, vq->id);
> >>>>>> ./examples/vhost_blk/vhost_blk.c:134:
> >>>>>> rte_vhost_vring_call(task->ctrlr->vid, vq->id);
> >>>>>>
> >>>>>> This change will break all the above uses.
> >>>>>>
> >>>>>> And that's not counting external projects.
> >>>>>>
> >>>>>> ou should better introduce a new API that does not block.
> >>>>> Could you add a new API to do this?
> >>>>    >
> >>>>> I think we can use the new API in SPDK as a workaround, note that SPDK
> >> project
> >>>> is blocked for
> >>>>> a while which can't be used with DPDK 22.05 or newer.
> >>>>
> >>>> DPDK v22.05?
> >>>> What is the commit introducing the regression?
> >>> Here is the commit introducing this issue
> >>> c5736998305d ("vhost: fix missing virtqueue lock protection")
> >>> Bugzilla ID: 1015
> >>
> >> Ok, it cannot be reverted, as it prevents some undefined
> >> behaviors/crashes.
> >>
> >>>>
> >>>> Note that if we introduce a new API, it won't be backported to stable
> >>>> branches.
> >>> I understand, but do we have better idea in short time? we're planning
> >>> to release SPDK 22.09 recently.
> >>
> >> You can have another thread that sends the call?
> > We already use two threads to do this. Here is the example for existing code in
> SPDK:
> >
> > DPDK vhost-events thread                        SPDK thread
> >
> >      SET_VRING_KICK VQ1       ---->            Start polling VQ1
> >      Reply to DPDK                    <----              Done
> >      SET_VRING_KICK VQ2       ---->            thread is blocked on VQ's access lock,
> SPDK thread can't provide reply message
> >
> > For example, we can just return for  SET_VRING_KICK VQ2 message without
> checking SPDK thread, but this leave
> > uncertain replies to VM.
> 
> I'm sorry but you will have to find a workaround while v22.11 is out and
> you can consume it. We can neither backport new API nor we can break all
> the other applications not handling locking failure.
By processing vhost-user message in asynchronous way in SPDK can be a
workaround now, we can backport the workaround to SPDK earlier version
so that it can work with distro DPDK releases.
> 
> Regarding the new API for v22.11, I should be named something like
> rte_vhost_vring_call_nonblock(), and ideally should return some like
> -EAGAIN instead of -1 o that the applications can distinguish between a
> real failure and a need for retry.
Agreed, then we can switch to the new API finally.
> 
> Regards,
> Maxime
> 
> >>
> >>>>
> >>>>
> >>>>> Vhost-blk and scsi devices are not same with vhost-net, we need to cover
> >>>> SeaBIOS and VM
> >>>>> cases, so we need to start processing vrings after 1 vring is ready.
> >>>>>>
> >>>>>> Regards,
> >>>>>> Maxime
> >>>>>
> >>>
> >
Maxime Coquelin Oct. 11, 2022, 11:56 a.m. UTC | #18
Hi Changpeng,

On 9/21/22 11:52, Liu, Changpeng wrote:
> 
> 
>> -----Original Message-----
>> From: Maxime Coquelin <maxime.coquelin@redhat.com>
>> Sent: Wednesday, September 21, 2022 5:41 PM
>> To: Liu, Changpeng <changpeng.liu@intel.com>; dev@dpdk.org
>> Cc: Xia, Chenbo <chenbo.xia@intel.com>
>> Subject: Re: [PATCH] vhost: use try_lock in rte_vhost_vring_call
>>
>>
>>
>> On 9/20/22 10:43, Liu, Changpeng wrote:
>>>
>>>
>>>> -----Original Message-----
>>>> From: Maxime Coquelin <maxime.coquelin@redhat.com>
>>>> Sent: Tuesday, September 20, 2022 4:13 PM
>>>> To: Liu, Changpeng <changpeng.liu@intel.com>; dev@dpdk.org
>>>> Cc: Xia, Chenbo <chenbo.xia@intel.com>
>>>> Subject: Re: [PATCH] vhost: use try_lock in rte_vhost_vring_call
>>>>
>>>>
>>>>
>>>> On 9/20/22 09:45, Liu, Changpeng wrote:
>>>>>
>>>>>
>>>>>> -----Original Message-----
>>>>>> From: Maxime Coquelin <maxime.coquelin@redhat.com>
>>>>>> Sent: Tuesday, September 20, 2022 3:35 PM
>>>>>> To: Liu, Changpeng <changpeng.liu@intel.com>; dev@dpdk.org
>>>>>> Cc: Xia, Chenbo <chenbo.xia@intel.com>
>>>>>> Subject: Re: [PATCH] vhost: use try_lock in rte_vhost_vring_call
>>>>>>
>>>>>>
>>>>>>
>>>>>> On 9/20/22 09:29, Liu, Changpeng wrote:
>>>>>>> Hi Maxime,
>>>>>>>
>>>>>>>> -----Original Message-----
>>>>>>>> From: Maxime Coquelin <maxime.coquelin@redhat.com>
>>>>>>>> Sent: Tuesday, September 20, 2022 3:19 PM
>>>>>>>> To: Liu, Changpeng <changpeng.liu@intel.com>; dev@dpdk.org
>>>>>>>> Cc: Xia, Chenbo <chenbo.xia@intel.com>
>>>>>>>> Subject: Re: [PATCH] vhost: use try_lock in rte_vhost_vring_call
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> On 9/6/22 04:22, Changpeng Liu wrote:
>>>>>>>>> Note that this function is in data path, so the thread context
>>>>>>>>> may not same as socket messages processing context, by using
>>>>>>>>> try_lock here, users can have another try in case of VQ's access
>>>>>>>>> lock is held by `vhost-events` thread.
>>>>>>>>>
>>>>>>>>> Signed-off-by: Changpeng Liu <changpeng.liu@intel.com>
>>>>>>>>> ---
>>>>>>>>>       lib/vhost/vhost.c | 6 +++++-
>>>>>>>>>       1 file changed, 5 insertions(+), 1 deletion(-)
>>>>>>>>>
>>>>>>>>> diff --git a/lib/vhost/vhost.c b/lib/vhost/vhost.c
>>>>>>>>> index 60cb05a0ff..072d2acb7b 100644
>>>>>>>>> --- a/lib/vhost/vhost.c
>>>>>>>>> +++ b/lib/vhost/vhost.c
>>>>>>>>> @@ -1329,7 +1329,11 @@ rte_vhost_vring_call(int vid, uint16_t
>> vring_idx)
>>>>>>>>>       	if (!vq)
>>>>>>>>>       		return -1;
>>>>>>>>>
>>>>>>>>> -	rte_spinlock_lock(&vq->access_lock);
>>>>>>>>> +	if (!rte_spinlock_trylock(&vq->access_lock)) {
>>>>>>>>> +		VHOST_LOG_CONFIG(dev->ifname, DEBUG,
>>>>>>>>> +			"failed to kick guest, virtqueue busy.\n");
>>>>>>>>> +		return -1;
>>>>>>>>> +	}
>>>>>>>>>
>>>>>>>>>       	if (vq_is_packed(dev))
>>>>>>>>>       		vhost_vring_call_packed(dev, vq);
>>>>>>>>
>>>>>>>> I think that's problematic, because it will break other applications
>>>>>>>> that currently rely on the API to block until the call is done.
>>>>>>>>
>>>>>>>> Just some internal DPDK usage of this API:
>>>>>>>> ./drivers/vdpa/ifc/ifcvf_vdpa.c:871:	rte_vhost_vring_call(internal->vid,
>>>>>>>> qid);
>>>>>>>> ./examples/vhost/virtio_net.c:236:	rte_vhost_vring_call(dev->vid,
>>>> queue_id);
>>>>>>>> ./examples/vhost/virtio_net.c:446:	rte_vhost_vring_call(dev->vid,
>>>> queue_id);
>>>>>>>> ./examples/vhost_blk/vhost_blk.c:99:
>>>>>>>> rte_vhost_vring_call(task->ctrlr->vid, vq->id);
>>>>>>>> ./examples/vhost_blk/vhost_blk.c:134:
>>>>>>>> rte_vhost_vring_call(task->ctrlr->vid, vq->id);
>>>>>>>>
>>>>>>>> This change will break all the above uses.
>>>>>>>>
>>>>>>>> And that's not counting external projects.
>>>>>>>>
>>>>>>>> ou should better introduce a new API that does not block.
>>>>>>> Could you add a new API to do this?
>>>>>>     >
>>>>>>> I think we can use the new API in SPDK as a workaround, note that SPDK
>>>> project
>>>>>> is blocked for
>>>>>>> a while which can't be used with DPDK 22.05 or newer.
>>>>>>
>>>>>> DPDK v22.05?
>>>>>> What is the commit introducing the regression?
>>>>> Here is the commit introducing this issue
>>>>> c5736998305d ("vhost: fix missing virtqueue lock protection")
>>>>> Bugzilla ID: 1015
>>>>
>>>> Ok, it cannot be reverted, as it prevents some undefined
>>>> behaviors/crashes.
>>>>
>>>>>>
>>>>>> Note that if we introduce a new API, it won't be backported to stable
>>>>>> branches.
>>>>> I understand, but do we have better idea in short time? we're planning
>>>>> to release SPDK 22.09 recently.
>>>>
>>>> You can have another thread that sends the call?
>>> We already use two threads to do this. Here is the example for existing code in
>> SPDK:
>>>
>>> DPDK vhost-events thread                        SPDK thread
>>>
>>>       SET_VRING_KICK VQ1       ---->            Start polling VQ1
>>>       Reply to DPDK                    <----              Done
>>>       SET_VRING_KICK VQ2       ---->            thread is blocked on VQ's access lock,
>> SPDK thread can't provide reply message
>>>
>>> For example, we can just return for  SET_VRING_KICK VQ2 message without
>> checking SPDK thread, but this leave
>>> uncertain replies to VM.
>>
>> I'm sorry but you will have to find a workaround while v22.11 is out and
>> you can consume it. We can neither backport new API nor we can break all
>> the other applications not handling locking failure.
> By processing vhost-user message in asynchronous way in SPDK can be a
> workaround now, we can backport the workaround to SPDK earlier version
> so that it can work with distro DPDK releases.
>>
>> Regarding the new API for v22.11, I should be named something like
>> rte_vhost_vring_call_nonblock(), and ideally should return some like
>> -EAGAIN instead of -1 o that the applications can distinguish between a
>> real failure and a need for retry.
> Agreed, then we can switch to the new API finally.

Just a reminder that -rc2 is in ~ two weeks, have you prepared the patch
adding the new API?

Regards,
Maxime

>> Regards,
>> Maxime
>>
>>>>
>>>>>>
>>>>>>
>>>>>>> Vhost-blk and scsi devices are not same with vhost-net, we need to cover
>>>>>> SeaBIOS and VM
>>>>>>> cases, so we need to start processing vrings after 1 vring is ready.
>>>>>>>>
>>>>>>>> Regards,
>>>>>>>> Maxime
>>>>>>>
>>>>>
>>>
>
diff mbox series

Patch

diff --git a/lib/vhost/vhost.c b/lib/vhost/vhost.c
index 60cb05a0ff..072d2acb7b 100644
--- a/lib/vhost/vhost.c
+++ b/lib/vhost/vhost.c
@@ -1329,7 +1329,11 @@  rte_vhost_vring_call(int vid, uint16_t vring_idx)
 	if (!vq)
 		return -1;
 
-	rte_spinlock_lock(&vq->access_lock);
+	if (!rte_spinlock_trylock(&vq->access_lock)) {
+		VHOST_LOG_CONFIG(dev->ifname, DEBUG,
+			"failed to kick guest, virtqueue busy.\n");
+		return -1;
+	}
 
 	if (vq_is_packed(dev))
 		vhost_vring_call_packed(dev, vq);