From patchwork Thu Mar 19 06:41:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phil Yang X-Patchwork-Id: 66927 X-Patchwork-Delegate: xiaolong.ye@intel.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 57B90A0583; Thu, 19 Mar 2020 11:25:30 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 26EA925D9; Thu, 19 Mar 2020 11:25:29 +0100 (CET) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by dpdk.org (Postfix) with ESMTP id EE71B1515; Thu, 19 Mar 2020 11:25:26 +0100 (CET) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 23DF731B; Thu, 19 Mar 2020 03:25:26 -0700 (PDT) Received: from phil-VirtualBox.shanghai.arm.com (unknown [10.169.109.148]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 74C053F7BB; Wed, 18 Mar 2020 23:46:27 -0700 (PDT) From: Phil Yang To: dev@dpdk.org, konstantin.ananyev@intel.com, wenzhuo.lu@intel.com Cc: qi.z.zhang@intel.com, lijian.zhang@arm.com, gavin.hu@arm.com, honnappa.nagarahalli@arm.com, nd@arm.com, stable@dpdk.org Date: Thu, 19 Mar 2020 14:41:51 +0800 Message-Id: <1584600111-17412-1-git-send-email-phil.yang@arm.com> X-Mailer: git-send-email 2.7.4 Subject: [dpdk-dev] [PATCH] net/ixgbe: fix link state timing issue on fiber ports 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" With some models of fiber ports (e.g. X520-2 device ID 0x10fb), it is possible when a port is started to experience a timing issue which prevents the link from ever being fully set up. In ixgbe_dev_link_update_share(), if the media type is fiber and the link is down, a flag (IXGBE_FLAG_NEED_LINK_CONFIG) is set. A callback to ixgbe_dev_setup_link_thread_handler() is scheduled which should try to set up the link and clear the flag afterwards. If the device is started before the flag is cleared, the scheduled callback is cancelled. This causes the flag to remain set and subsequent calls to ixgbe_dev_link_update_share() return without trying to retrieve the link state because the flag is set. In ixgbe_dev_cancel_link_thread(), after cancelling the callback, unset the flag on the device to avoid this condition. Fixes: 819d0d1d57f1 ("net/ixgbe: fix blocking system events") Cc: stable@dpdk.org Bugzilla ID: 388 Signed-off-by: Phil Yang Signed-off-by: Lijian Zhang Reviewed-by: Gavin Hu --- drivers/net/ixgbe/ixgbe_ethdev.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/drivers/net/ixgbe/ixgbe_ethdev.c b/drivers/net/ixgbe/ixgbe_ethdev.c index 23b3f5b..2b65750 100644 --- a/drivers/net/ixgbe/ixgbe_ethdev.c +++ b/drivers/net/ixgbe/ixgbe_ethdev.c @@ -4147,11 +4147,19 @@ static void ixgbe_dev_cancel_link_thread(struct rte_eth_dev *dev) { struct ixgbe_adapter *ad = dev->data->dev_private; + struct ixgbe_interrupt *intr = + IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private); void *retval; if (rte_atomic32_read(&ad->link_thread_running)) { pthread_cancel(ad->link_thread_tid); pthread_join(ad->link_thread_tid, &retval); + /* clear this flag once the thread has been + * cancelled, to avoid link status error in + * case unfinished threads cannot clean up + * this flag. + */ + intr->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG; rte_atomic32_clear(&ad->link_thread_running); } } @@ -4262,8 +4270,12 @@ 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)) { + /* To avoid race condition between threads, set + * the IXGBE_FLAG_NEED_LINK_CONFIG flag only + * when there is no link thread running. + */ + intr->flags |= IXGBE_FLAG_NEED_LINK_CONFIG; if (rte_ctrl_thread_create(&ad->link_thread_tid, "ixgbe-link-handler", NULL,