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 B062DA04C0; Tue, 29 Sep 2020 08:39:40 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 45E8A1D8DB; Tue, 29 Sep 2020 08:38:49 +0200 (CEST) Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by dpdk.org (Postfix) with ESMTP id DD1E11D183 for ; Tue, 29 Sep 2020 08:38:38 +0200 (CEST) IronPort-SDR: w+IJR7sIsdYMmZ3Dkyz/Tq/6JCFwLClchkL2WewxKXbWYb6P0kZXN2PY8xhhVm7A96IG++ZZ3Q BIL+Z/BB9aPw== X-IronPort-AV: E=McAfee;i="6000,8403,9758"; a="161356250" X-IronPort-AV: E=Sophos;i="5.77,317,1596524400"; d="scan'208";a="161356250" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Sep 2020 23:38:38 -0700 IronPort-SDR: WYFNwUQtIVymv7qPGlSCRu8t+FcWVmwSUzO8OhVarrS+ecx6D21Rb8o2HiWmKdfKUwlUFKGn1J Y0dXvAstOk7A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.77,317,1596524400"; d="scan'208";a="340745859" Received: from npg-dpdk-patrickfu-casc2.sh.intel.com ([10.67.119.92]) by orsmga008.jf.intel.com with ESMTP; 28 Sep 2020 23:38:36 -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 14:29:58 +0800 Message-Id: <20200929062958.2832351-5-patrick.fu@intel.com> X-Mailer: git-send-email 2.18.4 In-Reply-To: <20200929062958.2832351-1-patrick.fu@intel.com> References: <20200911015316.1903181-1-patrick.fu@intel.com> <20200929062958.2832351-1-patrick.fu@intel.com> Subject: [dpdk-dev] [PATCH v2 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 919a5bf7f..c247fc900 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 " @@ -1623,8 +1621,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; } @@ -1643,10 +1639,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