From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 8EA0FA055B; Mon, 27 Jun 2022 07:53:39 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 6C44F410EF; Mon, 27 Jun 2022 07:53:39 +0200 (CEST) Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by mails.dpdk.org (Postfix) with ESMTP id 7122140E78; Mon, 27 Jun 2022 07:53:37 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1656309217; x=1687845217; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=anhS2NAI0JQuUeSp0K8weWrgTjWacWFfi0Cpzc42sPM=; b=ZQqYrFpPCUp68aRTyYj7sHl3nsj9WcW7cbne7r7TuRMwcvTxx7SW37RS pe+tRzIqHO3zbwVT4FAaOy6YynPxtlBAPitNYdwMH3B3MzHTJnDD59xtu qsYMHh8hiP/W3CpagtBbfO+Vcbl0YwOcoWB2ZrP2rilswOzF7twueAhY0 Z4iZy5QeR6ga1vmBE0aYTd6hgJs03seiPi3e2E70Y8tdDOQ03Bl6I2iAP 5J6Vdc8bat8lYM8rEiIFG6VjDVPgmx2DX2WENzfMCVBZlEt9JlvwRuDyl hs9C+wHb3Yvj/ysOUmGiUvjjDN8oIkC1rKbm2qFpVaoMwpAQz7mCOojCg g==; X-IronPort-AV: E=McAfee;i="6400,9594,10390"; a="345366300" X-IronPort-AV: E=Sophos;i="5.92,225,1650956400"; d="scan'208";a="345366300" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jun 2022 22:53:36 -0700 X-IronPort-AV: E=Sophos;i="5.92,225,1650956400"; d="scan'208";a="646268446" Received: from unknown (HELO localhost.localdomain) ([10.239.252.55]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jun 2022 22:53:33 -0700 From: Yuan Wang To: maxime.coquelin@redhat.com, chenbo.xia@intel.com, dev@dpdk.org Cc: jiayu.hu@intel.com, xingguang.he@intel.com, cheng1.jiang@intel.com, weix.ling@intel.com, Yuan Wang , stable@dpdk.org Subject: [PATCH v2] net/vhost: fix deadlock on vring state change Date: Mon, 27 Jun 2022 13:51:25 +0800 Message-Id: <20220627055125.1541652-1-yuanx.wang@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220601142541.605301-1-yuanx.wang@intel.com> References: <20220601142541.605301-1-yuanx.wang@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org If vring state changes after pmd starts working, the locked vring notifies pmd, thus calling update_queuing_status(), the latter will wait for pmd to finish accessing vring, while pmd is also waiting for vring to be unlocked, thus causing deadlock. Actually, update_queuing_status() only needs to wait while destroy/stopping the device, but not in other cases. This patch adds a flag for whether or not to wait to fix this issue. Fixes: 1ce3c7fe149f ("net/vhost: emulate device start/stop behavior") Cc: stable@dpdk.org Signed-off-by: Yuan Wang --- V2: rewrite the commit log. --- drivers/net/vhost/rte_eth_vhost.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/net/vhost/rte_eth_vhost.c b/drivers/net/vhost/rte_eth_vhost.c index d75d256040..7e512d94bf 100644 --- a/drivers/net/vhost/rte_eth_vhost.c +++ b/drivers/net/vhost/rte_eth_vhost.c @@ -741,7 +741,7 @@ eth_vhost_install_intr(struct rte_eth_dev *dev) } static void -update_queuing_status(struct rte_eth_dev *dev) +update_queuing_status(struct rte_eth_dev *dev, bool wait_queuing) { struct pmd_internal *internal = dev->data->dev_private; struct vhost_queue *vq; @@ -767,7 +767,7 @@ update_queuing_status(struct rte_eth_dev *dev) rte_atomic32_set(&vq->allow_queuing, 1); else rte_atomic32_set(&vq->allow_queuing, 0); - while (rte_atomic32_read(&vq->while_queuing)) + while (wait_queuing && rte_atomic32_read(&vq->while_queuing)) rte_pause(); } @@ -779,7 +779,7 @@ update_queuing_status(struct rte_eth_dev *dev) rte_atomic32_set(&vq->allow_queuing, 1); else rte_atomic32_set(&vq->allow_queuing, 0); - while (rte_atomic32_read(&vq->while_queuing)) + while (wait_queuing && rte_atomic32_read(&vq->while_queuing)) rte_pause(); } } @@ -868,7 +868,7 @@ new_device(int vid) vhost_dev_csum_configure(eth_dev); rte_atomic32_set(&internal->dev_attached, 1); - update_queuing_status(eth_dev); + update_queuing_status(eth_dev, false); VHOST_LOG(INFO, "Vhost device %d created\n", vid); @@ -898,7 +898,7 @@ destroy_device(int vid) internal = eth_dev->data->dev_private; rte_atomic32_set(&internal->dev_attached, 0); - update_queuing_status(eth_dev); + update_queuing_status(eth_dev, true); eth_dev->data->dev_link.link_status = RTE_ETH_LINK_DOWN; @@ -1008,7 +1008,7 @@ vring_state_changed(int vid, uint16_t vring, int enable) state->max_vring = RTE_MAX(vring, state->max_vring); rte_spinlock_unlock(&state->lock); - update_queuing_status(eth_dev); + update_queuing_status(eth_dev, false); VHOST_LOG(INFO, "vring%u is %s\n", vring, enable ? "enabled" : "disabled"); @@ -1197,7 +1197,7 @@ eth_dev_start(struct rte_eth_dev *eth_dev) } rte_atomic32_set(&internal->started, 1); - update_queuing_status(eth_dev); + update_queuing_status(eth_dev, false); return 0; } @@ -1209,7 +1209,7 @@ eth_dev_stop(struct rte_eth_dev *dev) dev->data->dev_started = 0; rte_atomic32_set(&internal->started, 0); - update_queuing_status(dev); + update_queuing_status(dev, true); return 0; } -- 2.25.1