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 691DEA04B6; Tue, 13 Oct 2020 03:57:22 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 033BE1DA09; Tue, 13 Oct 2020 03:56:27 +0200 (CEST) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by dpdk.org (Postfix) with ESMTP id AA9151DA03 for ; Tue, 13 Oct 2020 03:56:22 +0200 (CEST) IronPort-SDR: mnVAvupSn5/0SGF3x4RxDsqYT/f9In0bq0SS3t4bsXMkkmIPcJyq4nfBRO0yZJx6ufB+PsRoMV h9qwHNK7xWlw== X-IronPort-AV: E=McAfee;i="6000,8403,9772"; a="183300521" X-IronPort-AV: E=Sophos;i="5.77,369,1596524400"; d="scan'208";a="183300521" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Oct 2020 18:56:18 -0700 IronPort-SDR: 1KsHxPQt4/R5P5oRbxmc8srAi2qC8oeXLk+xQprB7DrrPzBTCuU+5SALRB+uytK70A0OnBCAII cp92E2CSadVg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.77,369,1596524400"; d="scan'208";a="519805861" Received: from npg-dpdk-patrickfu-casc2.sh.intel.com ([10.67.119.92]) by fmsmga006.fm.intel.com with ESMTP; 12 Oct 2020 18:56:13 -0700 From: Patrick Fu To: dev@dpdk.org, maxime.coquelin@redhat.com, chenbo.xia@intel.com Cc: zhihong.wang@intel.com, cheng1.jiang@intel.com, patrick.fu@intel.com Date: Tue, 13 Oct 2020 09:45:46 +0800 Message-Id: <20201013014546.2896162-5-patrick.fu@intel.com> X-Mailer: git-send-email 2.18.4 In-Reply-To: <20201013014546.2896162-1-patrick.fu@intel.com> References: <20200911015316.1903181-1-patrick.fu@intel.com> <20201013014546.2896162-1-patrick.fu@intel.com> Subject: [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" 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; } -- 2.18.4