DPDK patches and discussions
 help / color / mirror / Atom feed
From: Maxime Coquelin <maxime.coquelin@redhat.com>
To: Patrick Fu <patrick.fu@intel.com>, dev@dpdk.org, chenbo.xia@intel.com
Cc: zhihong.wang@intel.com, cheng1.jiang@intel.com
Subject: Re: [dpdk-dev] [PATCH v3 4/4] vhost: fix async register/unregister deadlock
Date: Mon, 5 Oct 2020 16:25:57 +0200	[thread overview]
Message-ID: <82d290c9-02f0-a521-f38f-c5a726db99aa@redhat.com> (raw)
In-Reply-To: <20200929092955.2848419-5-patrick.fu@intel.com>



On 9/29/20 11:29 AM, Patrick Fu wrote:
> When async register/unregister function is invoked in certain vhost
> event callbacks (e.g. vring state change), deadlock may occur due to
> recursive spinlock acquire. This patch removes unnecessary spinlock
> from register API and use trylock() primitive in the unregister API
> to avoid deadlock.

I am not convinced it is unnecessary in every cases.


> Fixes: 78639d54563a ("vhost: introduce async enqueue registration API")
> 
> Signed-off-by: Patrick Fu <patrick.fu@intel.com>
> ---
>  lib/librte_vhost/vhost.c      | 13 +++++++------
>  lib/librte_vhost/vhost_user.c |  4 ++--
>  2 files changed, 9 insertions(+), 8 deletions(-)
> 
> diff --git a/lib/librte_vhost/vhost.c b/lib/librte_vhost/vhost.c
> index 05b578c2f..ba504a00a 100644
> --- a/lib/librte_vhost/vhost.c
> +++ b/lib/librte_vhost/vhost.c
> @@ -1577,8 +1577,6 @@ int rte_vhost_async_channel_register(int vid, uint16_t queue_id,
>  		ops->transfer_data == NULL))
>  		return -1;
>  
> -	rte_spinlock_lock(&vq->access_lock);
> -

What if a virtqueue is being destroyed while this function is called?

>  	if (unlikely(vq->async_registered)) {
>  		VHOST_LOG_CONFIG(ERR,
>  			"async register failed: channel already registered "
> @@ -1627,8 +1625,6 @@ int rte_vhost_async_channel_register(int vid, uint16_t queue_id,
>  	vq->async_registered = true;
>  
>  reg_out:
> -	rte_spinlock_unlock(&vq->access_lock);
> -
>  	return 0;
>  }
>  
> @@ -1647,10 +1643,15 @@ int rte_vhost_async_channel_unregister(int vid, uint16_t queue_id)
>  		return ret;
>  
>  	ret = 0;
> -	rte_spinlock_lock(&vq->access_lock);
>  
>  	if (!vq->async_registered)
> -		goto out;
> +		return ret;
> +
> +	if (!rte_spinlock_trylock(&vq->access_lock)) {
> +		VHOST_LOG_CONFIG(ERR, "Failed to unregister async channel. "
> +			"virt queue busy.\n");
> +		return -1;
> +	}
>  
>  	if (vq->async_pkts_inflight_n) {
>  		VHOST_LOG_CONFIG(ERR, "Failed to unregister async channel. "
> diff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c
> index 67d2a2d43..c8d74bde6 100644
> --- a/lib/librte_vhost/vhost_user.c
> +++ b/lib/librte_vhost/vhost_user.c
> @@ -2043,9 +2043,9 @@ vhost_user_set_vring_enable(struct virtio_net **pdev,
>  		"set queue enable: %d to qp idx: %d\n",
>  		enable, index);
>  
> -	if (!enable && dev->virtqueue[index]->async_registered) {
> +	if (enable && dev->virtqueue[index]->async_registered) {
>  		if (dev->virtqueue[index]->async_pkts_inflight_n) {
> -			VHOST_LOG_CONFIG(ERR, "failed to disable vring. "
> +			VHOST_LOG_CONFIG(ERR, "failed to enable vring. "
>  			"async inflight packets must be completed first\n");
>  			return RTE_VHOST_MSG_RESULT_ERR;
>  		}
> 


  reply	other threads:[~2020-10-05 14:26 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-11  1:53 [dpdk-dev] [PATCH v1 0/4] optimize async data path Patrick Fu
2020-09-11  1:53 ` [dpdk-dev] [PATCH v1 1/4] vhost: simplify async copy completion Patrick Fu
2020-09-23  9:07   ` Maxime Coquelin
2020-09-11  1:53 ` [dpdk-dev] [PATCH v1 2/4] vhost: dynamically alloc async memory Patrick Fu
2020-09-23  9:15   ` Maxime Coquelin
2020-09-29  5:55     ` Fu, Patrick
2020-09-11  1:53 ` [dpdk-dev] [PATCH v1 3/4] vhost: fix async vec buf overrun Patrick Fu
2020-09-23  9:21   ` Maxime Coquelin
2020-09-29  2:23     ` Fu, Patrick
2020-09-11  1:53 ` [dpdk-dev] [PATCH v1 4/4] vhost: fix async register/unregister deadlock Patrick Fu
2020-09-29  6:29 ` [dpdk-dev] [PATCH v2 0/4] optimize async data path Patrick Fu
2020-09-29  6:29   ` [dpdk-dev] [PATCH v2 1/4] vhost: simplify async copy completion Patrick Fu
2020-09-29  6:29   ` [dpdk-dev] [PATCH v2 2/4] vhost: dynamically allocate async memory Patrick Fu
2020-09-29  6:29   ` [dpdk-dev] [PATCH v2 3/4] vhost: fix async vector buffer overrun Patrick Fu
2020-09-29  6:29   ` [dpdk-dev] [PATCH v2 4/4] vhost: fix async register/unregister deadlock Patrick Fu
2020-09-29  9:29 ` [dpdk-dev] [PATCH v3 0/4] optimize async data path Patrick Fu
2020-09-29  9:29   ` [dpdk-dev] [PATCH v3 1/4] vhost: simplify async copy completion Patrick Fu
2020-10-05 13:46     ` Maxime Coquelin
2020-10-09 11:16       ` Fu, Patrick
2020-09-29  9:29   ` [dpdk-dev] [PATCH v3 2/4] vhost: dynamically allocate async memory Patrick Fu
2020-10-05 13:50     ` Maxime Coquelin
2020-09-29  9:29   ` [dpdk-dev] [PATCH v3 3/4] vhost: fix async vector buffer overrun Patrick Fu
2020-10-05 14:19     ` Maxime Coquelin
2020-09-29  9:29   ` [dpdk-dev] [PATCH v3 4/4] vhost: fix async register/unregister deadlock Patrick Fu
2020-10-05 14:25     ` Maxime Coquelin [this message]
2020-10-09 10:54       ` Fu, Patrick
2020-10-13  1:45 ` [dpdk-dev] [PATCH v4 0/4] optimize async data path Patrick Fu
2020-10-13  1:45   ` [dpdk-dev] [PATCH v4 1/4] vhost: simplify async copy completion Patrick Fu
2020-10-14  9:28     ` Maxime Coquelin
2020-10-13  1:45   ` [dpdk-dev] [PATCH v4 2/4] vhost: dynamically allocate async memory Patrick Fu
2020-10-14  9:30     ` Maxime Coquelin
2020-10-13  1:45   ` [dpdk-dev] [PATCH v4 3/4] vhost: fix async vector buffer overrun Patrick Fu
2020-10-14  9:33     ` Maxime Coquelin
2020-10-13  1:45   ` [dpdk-dev] [PATCH v4 4/4] vhost: fix async unregister deadlock Patrick Fu
2020-10-14  9:34     ` Maxime Coquelin
2020-10-15 15:40   ` [dpdk-dev] [PATCH v4 0/4] optimize async data path Maxime Coquelin

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=82d290c9-02f0-a521-f38f-c5a726db99aa@redhat.com \
    --to=maxime.coquelin@redhat.com \
    --cc=chenbo.xia@intel.com \
    --cc=cheng1.jiang@intel.com \
    --cc=dev@dpdk.org \
    --cc=patrick.fu@intel.com \
    --cc=zhihong.wang@intel.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).