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 B029DA055E for ; Wed, 26 Feb 2020 10:25:17 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 840E31BF8D; Wed, 26 Feb 2020 10:25:17 +0100 (CET) Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by dpdk.org (Postfix) with ESMTP id 3A0661BF8D for ; Wed, 26 Feb 2020 10:25:16 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 26 Feb 2020 01:25:15 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,487,1574150400"; d="scan'208";a="350347767" Received: from unknown (HELO localhost.localdomain) ([10.239.250.16]) by fmsmga001.fm.intel.com with ESMTP; 26 Feb 2020 01:25:13 -0800 From: taox.zhu@intel.com To: qabuild@intel.com Cc: Zhu Tao , stable@dpdk.org Date: Wed, 26 Feb 2020 17:06:39 +0800 Message-Id: <20200226090639.11339-1-taox.zhu@intel.com> X-Mailer: git-send-email 2.17.1 Subject: [dpdk-stable] [DPDK] net/ixgbe: fix link status inconsistencies X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org Sender: "stable" From: Zhu Tao Setting LINK UP or LINK DOWN is divided into two parts, with the main task done in a separate thread, which can take up to 9 seconds. If cancel the thread in execution, may cause state inconsistencies. Therefore, must wait for the previous setting to exit normally before setting the new state. Fixes: 819d0d1d57 ("net/ixgbe: fix blocking system events") Cc: stable@dpdk.org Signed-off-by: Zhu Tao --- drivers/net/ixgbe/ixgbe_ethdev.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/drivers/net/ixgbe/ixgbe_ethdev.c b/drivers/net/ixgbe/ixgbe_ethdev.c index 23b3f5b0c..2c5797635 100644 --- a/drivers/net/ixgbe/ixgbe_ethdev.c +++ b/drivers/net/ixgbe/ixgbe_ethdev.c @@ -4143,16 +4143,35 @@ ixgbevf_check_link(struct ixgbe_hw *hw, ixgbe_link_speed *speed, return ret_val; } +/* return 1: setup complete, return 0: setup not complete, and wait timeout*/ +static int +ixgbe_dev_wait_setup_link_complete(struct rte_eth_dev *dev) +{ +#define DELAY_INTERVAL 100 /* 100ms */ +#define MAX_TIMEOUT 90 /* 9s (90 * 100ms) in total */ + struct ixgbe_adapter *ad = dev->data->dev_private; + int timeout = MAX_TIMEOUT; + + while (rte_atomic32_read(&ad->link_thread_running) && timeout) { + msec_delay(DELAY_INTERVAL); + timeout--; + } + + + return !!timeout; +} + static void ixgbe_dev_cancel_link_thread(struct rte_eth_dev *dev) { struct ixgbe_adapter *ad = dev->data->dev_private; void *retval; - if (rte_atomic32_read(&ad->link_thread_running)) { + if (!ixgbe_dev_wait_setup_link_complete(dev)) { pthread_cancel(ad->link_thread_tid); pthread_join(ad->link_thread_tid, &retval); rte_atomic32_clear(&ad->link_thread_running); + PMD_DRV_LOG(ERR, "Link thread not complete, cancel it!"); } } @@ -4263,7 +4282,8 @@ ixgbe_dev_link_update_share(struct rte_eth_dev *dev, if (link_up == 0) { if (ixgbe_get_media_type(hw) == ixgbe_media_type_fiber) { intr->flags |= IXGBE_FLAG_NEED_LINK_CONFIG; - if (rte_atomic32_test_and_set(&ad->link_thread_running)) { + if (ixgbe_dev_wait_setup_link_complete(dev) && + rte_atomic32_test_and_set(&ad->link_thread_running)) { if (rte_ctrl_thread_create(&ad->link_thread_tid, "ixgbe-link-handler", NULL, -- 2.17.1