From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id F318AA04B7; Wed, 14 Oct 2020 11:35:06 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id D45A91DD98; Wed, 14 Oct 2020 11:35:05 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by dpdk.org (Postfix) with ESMTP id 533951DD84 for ; Wed, 14 Oct 2020 11:35:03 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602668101; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lWaVjcqqe8jdTmzSTEOlMNLPunlmDVm3xrgiYd0rNBg=; b=UDAIv9txXlseAWUKnQ4yk1VWTqFkEAZJ4Az8+oTl20OyPVQEr8oBiw6NemqsJKGkv96fg6 c8kpdPO5fAfcJIA+WUrHVJP/daf/bxamTsJwdNBSLyu7YcaRsf414Z/A8UdivkYpLhRJ6R lxnJgiJMCsLFS70PAgcduDiKZUUTL1s= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-104-RbERKid7PCuZZ-JhCZNglg-1; Wed, 14 Oct 2020 05:35:00 -0400 X-MC-Unique: RbERKid7PCuZZ-JhCZNglg-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6F7E0106B1CF; Wed, 14 Oct 2020 09:34:57 +0000 (UTC) Received: from [10.36.110.38] (unknown [10.36.110.38]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4B52B75134; Wed, 14 Oct 2020 09:34:56 +0000 (UTC) To: Patrick Fu , dev@dpdk.org, chenbo.xia@intel.com Cc: zhihong.wang@intel.com, cheng1.jiang@intel.com References: <20200911015316.1903181-1-patrick.fu@intel.com> <20201013014546.2896162-1-patrick.fu@intel.com> <20201013014546.2896162-5-patrick.fu@intel.com> From: Maxime Coquelin Message-ID: <356521e5-d987-1973-c252-691867ca4bf0@redhat.com> Date: Wed, 14 Oct 2020 11:34:54 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.3.1 MIME-Version: 1.0 In-Reply-To: <20201013014546.2896162-5-patrick.fu@intel.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=maxime.coquelin@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Subject: Re: [dpdk-dev] [PATCH v4 4/4] vhost: fix async unregister deadlock X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" On 10/13/20 3:45 AM, Patrick Fu wrote: > When async unregister function is invoked in certain vhost event > callbacks (e.g. vring state change), deadlock may occur due to > recursive spinlock acquire. This patch uses trylock() primitive in > the unregister API to avoid deadlock. > > Fixes: 78639d54563a ("vhost: introduce async enqueue registration API") > > Signed-off-by: Patrick Fu > --- > lib/librte_vhost/vhost.c | 9 +++++++-- > lib/librte_vhost/vhost_user.c | 4 ++-- > 2 files changed, 9 insertions(+), 4 deletions(-) > > diff --git a/lib/librte_vhost/vhost.c b/lib/librte_vhost/vhost.c > index 323565898..6068c38ec 100644 > --- a/lib/librte_vhost/vhost.c > +++ b/lib/librte_vhost/vhost.c > @@ -1633,10 +1633,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 1656ec736..d20c8c57a 100644 > --- a/lib/librte_vhost/vhost_user.c > +++ b/lib/librte_vhost/vhost_user.c > @@ -1980,9 +1980,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; > } > Reviewed-by: Maxime Coquelin Thanks, Maxime