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 B47FE4326D; Thu, 2 Nov 2023 11:21:09 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 38F0D40282; Thu, 2 Nov 2023 11:21:09 +0100 (CET) Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.93]) by mails.dpdk.org (Postfix) with ESMTP id 7564140262; Thu, 2 Nov 2023 11:21:06 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1698920466; x=1730456466; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=tbe7eVEQLdFvI60SD9zOSJ+bkbAJwmfgp4hT33wbj8s=; b=BhmkgXPeRll3jW+iT5KqGxhy46ZY5JNFbWx9kFceJYXlBanckZF16u/H Sd9s0Z0hz74nf6DiUWvgfcVLglvjpBwVVs+WzU08557lXM9ZTaLPqXnNw UXybwKCVhMQwsRHYL3tPRm6ivRAq0c/6Y1WMh0uBfP7EqLgsyfVdcBA98 rwfO62/9/NqMj7+vufuQFF9+Jz/Mlt/ZeDxRwJSwNUgJM5bIPVmHkH4iG qX3v0zYPu04PJxh8Ggxo3/6H0ArlqiuImFEjC5P1dPgAuHhIi0a+io4c/ EjHABGUNAocLsHBKn/Q70OvQpTu1INDZhz0ZTMlFr55ZGXDt9yGtB6HuL A==; X-IronPort-AV: E=McAfee;i="6600,9927,10881"; a="385855800" X-IronPort-AV: E=Sophos;i="6.03,271,1694761200"; d="scan'208";a="385855800" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Nov 2023 03:21:05 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10881"; a="1092674824" X-IronPort-AV: E=Sophos;i="6.03,271,1694761200"; d="scan'208";a="1092674824" Received: from unknown (HELO localhost.localdomain) ([10.239.252.253]) by fmsmga005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Nov 2023 03:21:02 -0700 From: Mingjin Ye To: dev@dpdk.org Cc: qiming.yang@intel.com, yidingx.zhou@intel.com, Mingjin Ye , stable@dpdk.org, Qi Zhang Subject: [PATCH v4] net/ice: fix crash on closing representor ports Date: Thu, 2 Nov 2023 10:11:03 +0000 Message-Id: <20231102101103.3707173-1-mingjinx.ye@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231101101347.3570418-1-mingjinx.ye@intel.com> References: <20231101101347.3570418-1-mingjinx.ye@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 Since the representor port needs to access the resource of the associated DCF when it is closing. Therefore, all the representor port should be closed first, and then close the associated DCF port. If the DCF port is closed before the representor port on PMD exit. This will result in accessing freed resources and eventually a core dump will occur. This patch fixes this issue by notifying each other to unassociate when the DCF port and the representor port are closed. Fixes: 5674465a32c8 ("net/ice: add DCF VLAN handling") Fixes: c7e1a1a3bfeb ("net/ice: refactor DCF VLAN handling") Fixes: da9cdcd1f372 ("net/ice: fix crash on representor port closing") Cc: stable@dpdk.org Signed-off-by: Mingjin Ye --- v2: Reformat code to remove unneeded fixlines. --- v3: New solution. --- v4: Optimize v2 patch. --- drivers/net/ice/ice_dcf_ethdev.c | 20 ++++++++++++++++++++ drivers/net/ice/ice_dcf_ethdev.h | 2 ++ drivers/net/ice/ice_dcf_vf_representor.c | 23 ++++++++++++++++++----- 3 files changed, 40 insertions(+), 5 deletions(-) diff --git a/drivers/net/ice/ice_dcf_ethdev.c b/drivers/net/ice/ice_dcf_ethdev.c index 065ec728c2..63e63a23de 100644 --- a/drivers/net/ice/ice_dcf_ethdev.c +++ b/drivers/net/ice/ice_dcf_ethdev.c @@ -1618,6 +1618,26 @@ ice_dcf_free_repr_info(struct ice_dcf_adapter *dcf_adapter) } } +int +ice_dcf_handle_vf_repr_uninit(struct ice_dcf_adapter *dcf_adapter, + uint16_t vf_id) +{ + struct ice_dcf_repr_info *vf_rep_info; + + if (dcf_adapter->num_reprs >= vf_id) { + PMD_DRV_LOG(ERR, "Invalid VF id: %d", vf_id); + return -1; + } + + if (!dcf_adapter->repr_infos) + return 0; + + vf_rep_info = &dcf_adapter->repr_infos[vf_id]; + vf_rep_info->vf_rep_eth_dev = NULL; + + return 0; +} + static int ice_dcf_init_repr_info(struct ice_dcf_adapter *dcf_adapter) { diff --git a/drivers/net/ice/ice_dcf_ethdev.h b/drivers/net/ice/ice_dcf_ethdev.h index 4baaec4b8b..094e2a36db 100644 --- a/drivers/net/ice/ice_dcf_ethdev.h +++ b/drivers/net/ice/ice_dcf_ethdev.h @@ -60,6 +60,7 @@ struct ice_dcf_vf_repr { struct rte_ether_addr mac_addr; uint16_t switch_domain_id; uint16_t vf_id; + bool dcf_valid; struct ice_dcf_vlan outer_vlan_info; /* DCF always handle outer VLAN */ }; @@ -81,5 +82,6 @@ int ice_dcf_vf_repr_uninit(struct rte_eth_dev *vf_rep_eth_dev); int ice_dcf_vf_repr_init_vlan(struct rte_eth_dev *vf_rep_eth_dev); void ice_dcf_vf_repr_stop_all(struct ice_dcf_adapter *dcf_adapter); bool ice_dcf_adminq_need_retry(struct ice_adapter *ad); +int ice_dcf_handle_vf_repr_uninit(struct ice_dcf_adapter *dcf_adapter, uint16_t vf_id); #endif /* _ICE_DCF_ETHDEV_H_ */ diff --git a/drivers/net/ice/ice_dcf_vf_representor.c b/drivers/net/ice/ice_dcf_vf_representor.c index b9fcfc80ad..167abaa780 100644 --- a/drivers/net/ice/ice_dcf_vf_representor.c +++ b/drivers/net/ice/ice_dcf_vf_representor.c @@ -45,6 +45,9 @@ ice_dcf_vf_repr_dev_start(struct rte_eth_dev *dev) static int ice_dcf_vf_repr_dev_stop(struct rte_eth_dev *dev) { + struct ice_dcf_vf_repr *repr = dev->data->dev_private; + + repr->dcf_valid = false; dev->data->dev_link.link_status = RTE_ETH_LINK_DOWN; return 0; @@ -111,14 +114,15 @@ ice_dcf_vf_repr_link_update(__rte_unused struct rte_eth_dev *ethdev, static __rte_always_inline struct ice_dcf_hw * ice_dcf_vf_repr_hw(struct ice_dcf_vf_repr *repr) { - struct ice_dcf_adapter *dcf_adapter = - repr->dcf_eth_dev->data->dev_private; + struct ice_dcf_adapter *dcf_adapter; - if (!dcf_adapter) { + if (!repr->dcf_valid) { PMD_DRV_LOG(ERR, "DCF for VF representor has been released\n"); return NULL; } + dcf_adapter = repr->dcf_eth_dev->data->dev_private; + return &dcf_adapter->real_hw; } @@ -414,6 +418,7 @@ ice_dcf_vf_repr_init(struct rte_eth_dev *vf_rep_eth_dev, void *init_param) repr->dcf_eth_dev = param->dcf_eth_dev; repr->switch_domain_id = param->switch_domain_id; repr->vf_id = param->vf_id; + repr->dcf_valid = true; repr->outer_vlan_info.port_vlan_ena = false; repr->outer_vlan_info.stripping_ena = false; repr->outer_vlan_info.tpid = RTE_ETHER_TYPE_VLAN; @@ -437,6 +442,14 @@ ice_dcf_vf_repr_init(struct rte_eth_dev *vf_rep_eth_dev, void *init_param) int ice_dcf_vf_repr_uninit(struct rte_eth_dev *vf_rep_eth_dev) { + struct ice_dcf_vf_repr *repr = vf_rep_eth_dev->data->dev_private; + struct ice_dcf_adapter *dcf_adapter; + + if (repr->dcf_valid) { + dcf_adapter = repr->dcf_eth_dev->data->dev_private; + ice_dcf_handle_vf_repr_uninit(dcf_adapter, repr->vf_id); + } + vf_rep_eth_dev->data->mac_addrs = NULL; return 0; @@ -480,11 +493,11 @@ ice_dcf_vf_repr_stop_all(struct ice_dcf_adapter *dcf_adapter) for (vf_id = 0; vf_id < dcf_adapter->real_hw.num_vfs; vf_id++) { struct rte_eth_dev *vf_rep_eth_dev = dcf_adapter->repr_infos[vf_id].vf_rep_eth_dev; - if (!vf_rep_eth_dev || vf_rep_eth_dev->data->dev_started == 0) + if (!vf_rep_eth_dev) continue; ret = ice_dcf_vf_repr_dev_stop(vf_rep_eth_dev); if (!ret) - vf_rep_eth_dev->data->dev_started = 0; + dcf_adapter->repr_infos[vf_id].vf_rep_eth_dev = NULL; } } -- 2.25.1