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 06AE1A054F; Wed, 1 Jun 2022 08:36:46 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id DCF1C40694; Wed, 1 Jun 2022 08:36:45 +0200 (CEST) Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by mails.dpdk.org (Postfix) with ESMTP id 5E90F40689; Wed, 1 Jun 2022 08:36:44 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1654065404; x=1685601404; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=n01WzL3kj63kY4gEYm9mLCS3WT+3rJFH1hwfOUqtwNs=; b=eYTUNJxcqAGqAnHebIgkkekMhPllUs93KMr2aYJhc2/9ZMNpcnz//LY/ xdPpl/YAHnE2eleXDf9iaAi3CbhYfn0/6pXaQbmEMTbtwaIRBP61f4l/H /A2muKUfy3Yi6jnKws5FQcc243MU/h1lOdDoX1VshOhjyJyrr1Rwt70uq G6P57wt2Mljj38K/lJbQ6cxyYOCLrkRmXYu8bYcaxSG435JuGgj8L/7Kk W9reuquTyzIuwTNY2w5Z6mi8qirnHmYNADUPsbwbTAYXxmM+KsNZbEuON LPqE2Nz64yDBSKE9Vtej/3TOhNwmm8aIDIghksPH4fLmHpxa+G1jNqqoc w==; X-IronPort-AV: E=McAfee;i="6400,9594,10364"; a="273054767" X-IronPort-AV: E=Sophos;i="5.91,266,1647327600"; d="scan'208";a="273054767" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 May 2022 23:36:43 -0700 X-IronPort-AV: E=Sophos;i="5.91,266,1647327600"; d="scan'208";a="576787675" Received: from unknown (HELO localhost.localdomain) ([10.239.251.55]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 May 2022 23:36:40 -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, yuanx.wang@intel.com, stable@dpdk.org Subject: [PATCH] net/vhost: add flag to control wait queuing Date: Wed, 1 Jun 2022 22:25:41 +0800 Message-Id: <20220601142541.605301-1-yuanx.wang@intel.com> X-Mailer: git-send-email 2.25.1 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 update_queuing_status prevents PMD queue operations from affecting the data plane by waiting for rx/tx_pkt_burst to stops accessing the vhost device. In fact, it is only necessary to wait when destroy/stop the device, new/start device and vring_state_changed cases do not need. Since vring is locked when vring state changes, unconditional waiting may also cause deadlocks. To avoid deadlocks and unnecessary waiting, this patch adds a flag to control whether waiting is required. Fixes: 9dc6bb0682 (net/vhost: fix access to freed memory) Fixes: 1ce3c7fe14 (net/vhost: emulate device start/stop behavior) Cc: stable@dpdk.org Signed-off-by: Yuan Wang --- 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 a248a65df4..a280e788fb 100644 --- a/drivers/net/vhost/rte_eth_vhost.c +++ b/drivers/net/vhost/rte_eth_vhost.c @@ -716,7 +716,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; @@ -742,7 +742,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(); } @@ -754,7 +754,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(); } } @@ -836,7 +836,7 @@ new_device(int vid) eth_dev->data->dev_link.link_status = RTE_ETH_LINK_UP; 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); @@ -866,7 +866,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; @@ -976,7 +976,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"); @@ -1163,7 +1163,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; } @@ -1175,7 +1175,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