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 D5B9EA04C0; Tue, 29 Sep 2020 11:39:33 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 96D021D9C7; Tue, 29 Sep 2020 11:38:43 +0200 (CEST) Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by dpdk.org (Postfix) with ESMTP id 89B4F1D94A for ; Tue, 29 Sep 2020 11:38:37 +0200 (CEST) IronPort-SDR: LinveBrKyh3GfYNQinAfkXA0ZVhExmw5lxNPvekQPjNXqou0RaHmB1FZN+kALj8lVqP7Z/HTfb LzxcWxpFFV6Q== X-IronPort-AV: E=McAfee;i="6000,8403,9758"; a="159485215" X-IronPort-AV: E=Sophos;i="5.77,318,1596524400"; d="scan'208";a="159485215" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Sep 2020 02:38:37 -0700 IronPort-SDR: bdllUY8miX+I1ieIITKh9c/R/PJiUwU5SHqoiM7gMUAKcZa/34HjLmi7gsa0+WyLv7RmfD8KJv wiWy/0ouZN+g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.77,318,1596524400"; d="scan'208";a="457216029" Received: from npg-dpdk-patrickfu-casc2.sh.intel.com ([10.67.119.92]) by orsmga004.jf.intel.com with ESMTP; 29 Sep 2020 02:38:35 -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, 29 Sep 2020 17:29:55 +0800 Message-Id: <20200929092955.2848419-5-patrick.fu@intel.com> X-Mailer: git-send-email 2.18.4 In-Reply-To: <20200929092955.2848419-1-patrick.fu@intel.com> References: <20200911015316.1903181-1-patrick.fu@intel.com> <20200929092955.2848419-1-patrick.fu@intel.com> Subject: [dpdk-dev] [PATCH v3 4/4] vhost: fix async register/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 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. Fixes: 78639d54563a ("vhost: introduce async enqueue registration API") Signed-off-by: Patrick Fu --- 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); - 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; } -- 2.18.4