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 0343443BBA for ; Thu, 7 Mar 2024 12:20:49 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 885FF427D8; Thu, 7 Mar 2024 12:20:48 +0100 (CET) Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2135.outbound.protection.outlook.com [40.107.244.135]) by mails.dpdk.org (Postfix) with ESMTP id 22F8B42D83 for ; Thu, 7 Mar 2024 12:20:47 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=B0qpkGFNrQh4WbufnW60A63If1WG7jDxCZPnzvl96nra6Tl/CRxq95MoQH+Mk3aoyF/aHdVCs6STHStbquXGeliDnLwdVneCSxGWnLrdlRaGxuhWQNgqGuhF14+eHE+HjCj/qFwJK1IGJP0TwZvYKrYczjGMinYoCnmkPBpgxoSMvfl0P9HvadjvHTgHOn77TVGQi6/omIIIk0N4AzpUX0dAj3nSbP3Tg7dF8AK72DZOQQXYuQSERZkqXPO0Jn0nfE+3Zl29Lmzgu2zTi0NnRQrX02z7XfzCMIzxKI2OizFJpfpd4B8HLcxm4nL6aLWQf4LNQ2luLn/owRvuFkjIxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=dbZJGK1k3yrq/6yb9EgWEytdbWSGFhDPMASzSCwhKoc=; b=h3+QpslfhIgMjj3hhj0GBIDB2BTtgJnoqdrZnyjh/jyj2qimXPiWwW07JAD53LT8+uLgMe/eafuuBxSgP59dFp83hcleeFe2qcW83f9Kvx0UYtfaUBy4/OBdqLlY8Z9NdSBpx98Arff1lUp9eBJXgD8/BxYPwvoqlzD9nIYB6tG2LsFKZxYLaA0XjznTQLlRc9zLpZYQkFQdXitHezgT3ZYbYCJPHwrMP9zP/SK/9LbG52ivVJr1fGceeCJh9u6MLHLS27rme23TDdmymwbrjmzIlBKrnZPppPtbmdpw3QnYUGIJ+xd4QV/TSGxu95uIr63sHC3ijBvYifgE5+c5OQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=corigine.com; dmarc=pass action=none header.from=corigine.com; dkim=pass header.d=corigine.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=corigine.onmicrosoft.com; s=selector2-corigine-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=dbZJGK1k3yrq/6yb9EgWEytdbWSGFhDPMASzSCwhKoc=; b=FuBpabAhuMaBR2OIrN4kr6dAU24ZjpMi61RIw1USBaty0Im1W5aqVr4jDwqX1Dg9AT06WZ1wsal/UMKHuQjntUPbWTefxSWBm2/mBiBrIW6FmMP0JQ4PeHVslJR/epKQ2q9yxQqTCmPVv5b3T9kL4/mFSR/wOyGEltQdtM+JppA= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=corigine.com; Received: from SJ0PR13MB5545.namprd13.prod.outlook.com (2603:10b6:a03:424::5) by PH7PR13MB5959.namprd13.prod.outlook.com (2603:10b6:510:15d::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7362.26; Thu, 7 Mar 2024 11:20:46 +0000 Received: from SJ0PR13MB5545.namprd13.prod.outlook.com ([fe80::ec12:7411:559a:850e]) by SJ0PR13MB5545.namprd13.prod.outlook.com ([fe80::ec12:7411:559a:850e%5]) with mapi id 15.20.7339.035; Thu, 7 Mar 2024 11:20:46 +0000 From: Chaoyong He To: stable@dpdk.org Cc: oss-drivers@corigine.com, Chaoyong He Subject: [PATCH 22.11 v2 3/7] net/nfp: fix resource leak for exit of CoreNIC firmware Date: Thu, 7 Mar 2024 19:20:19 +0800 Message-Id: <20240307112023.1867765-4-chaoyong.he@corigine.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20240307112023.1867765-1-chaoyong.he@corigine.com> References: <20240307112023.1867765-1-chaoyong.he@corigine.com> Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: BYAPR01CA0045.prod.exchangelabs.com (2603:10b6:a03:94::22) To SJ0PR13MB5545.namprd13.prod.outlook.com (2603:10b6:a03:424::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ0PR13MB5545:EE_|PH7PR13MB5959:EE_ X-MS-Office365-Filtering-Correlation-Id: 85aa729a-0b71-4dfc-a483-08dc3e98a22d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: khgytkrAkIEeSKc318uj3Q3ZjEPaJ7iJPNfeEWiUfLPh8sGTaKXd+r25Qg0U0RaVOk56+RZKslDePWzpjwlrsmz+1rE2q57YzXn14zng4iuyp+fEsTZQiSccC9xbmHZVZ37OO+tcqOsA2lxuxUiTyNVMQE9Zu1ryNNQqiI2wQNtbJ3iL2qMo7nP1NnlCzNZsEldnEmzJfmIzd6gUt4smTYWtdTJWKIv3yAc23XVZ8xHDI04SCmZdeiWlN5/ukG3FN/g5d49rCKI0Qw3BltU30W+M05s0fbfQgZs2AC6+E8i1yFPnNprvFtIEjB8awAFtGj9IM2b+lYLHgRDrpSZTFktsxcUKsFsLphggDFS/KuNLXvI+qVL6FdAWg/y5Vc3jVtLYAIJyrNyoU9A4L9+3aC9MijctE1wblF6m6thKoXMi47U9mE5mtYnEtkoCkhM23dkwCsnjDy7YPMqJuLwpvb3VUjMdyYV2itINIZtFOZp6q4GtAM0Pju1KmyC3E4ghw/To3U5CWALD8bcjb2E/Popb0XInTHQi79XZ/tLlyqFYplcFIfdCAog/Fynfp6zmJwfe7XO2T80773NXuVX8NrWFsyJgIyxEIxWM73/1kyGIVdpmNhxB0gNbSjxqo7O0xJmP0kO2DCLLL4Hbbi3iaAcmAj9XRHNIEc/KrIpizeSxP7w61siNtWwGUpWEx2WVCQjRRNlhQ0zDkW647srsYDyTcnbXPgT3pifyzxlwU4o= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:SJ0PR13MB5545.namprd13.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230031)(376005)(38350700005); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?t35BqnF/XPBqTGob3T2Hy5OL9GMfb5bNhUIrOQ5ZMPyNbfeBLtCYKIP1QNxK?= =?us-ascii?Q?X8dV2XWCfdjGAoP+OWJ4CQTrbHmQ86djSEid7cmE0LwwSgtVD5HEeTXcZtxy?= =?us-ascii?Q?uUeNvBCVhsfQSvgYRdtrT9kc9sEpIB4dxLl0xmmBnxablYINKga5ti81eWGM?= =?us-ascii?Q?8+Q6KDNU41yldZ7NWG40cO9IDAW+lkTCTTr/9/u0duFBRSv3nfQ6n9JNIxhA?= =?us-ascii?Q?mo25jAa8jF+8edZDIYYJUuyeoEW1+60aTve3CeOcP1A1zjMqB10FY/z5FlZH?= =?us-ascii?Q?nQcfWwtSnoD7+kxYuEaTWVkv3Oyc2iqoWqYObEitvajIffyJfr5iHVk0OjJf?= =?us-ascii?Q?sqqO/8bSChlH70lPGVuR/VNy7bbJ3BsuRe22bYJihOxdHGnPYz3EgenaP5hC?= =?us-ascii?Q?yq4qoQXbrWNK3L4nENGMpACqUtqqPUenZbX3uuBpB9whZe1TdAjC4T71Zl/j?= =?us-ascii?Q?Aja3IGq6HTO7egQuZDhpWzkUo/B5MAkh0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fRDIUpuYfUTYeI2XUcmyaMfBQOHCZ5Dwutgpq/79i+?= =?us-ascii?Q?UNbszIuCF8xPdRN7ybYocoGNFVE3vvm2rN8p+ZL0XqQoM7eO25u1Q2jkCOo/?= =?us-ascii?Q?Qo+yTqEic8G25dCMbluYyBpHJayx9mjwub7Rxqpn8gncJKKNylHNu4aiJD09?= =?us-ascii?Q?mr+8HTRC3ooJpXvGYrE4bSvbYqLx+m89ne8zbmY+STKOIKZXLjWQZsnDSNmZ?= =?us-ascii?Q?Zw=3D=3D?= X-OriginatorOrg: corigine.com X-MS-Exchange-CrossTenant-Network-Message-Id: 85aa729a-0b71-4dfc-a483-08dc3e98a22d X-MS-Exchange-CrossTenant-AuthSource: SJ0PR13MB5545.namprd13.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Mar 2024 11:20:45.9353 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: fe128f2c-073b-4c20-818e-7246a585940c X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: dQ5FbZdXnTFtPrOVYGgfsamkfOHsijslrh+FAltDE0CvbT7orr75uWrndwPrhG1i1/oZ26AJ+DPX0yLmxv7uTV5mnVYQMHSkAAxjKTTkDjM= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR13MB5959 X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.29 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 [ upstream commit 66d5f53d3e1beebf31de3b3b2e15371ffe322866 ] Fix the resource leak problem in the exit logic of CoreNIC firmware. Fixes: 646ea79ce481 ("net/nfp: move PF functions into its own file") Signed-off-by: Chaoyong He --- drivers/net/nfp/nfp_common.h | 1 + drivers/net/nfp/nfp_ethdev.c | 77 ++++++++++++++++++++++++++++-------- 2 files changed, 61 insertions(+), 17 deletions(-) diff --git a/drivers/net/nfp/nfp_common.h b/drivers/net/nfp/nfp_common.h index d1a07f5..5b5c0aa 100644 --- a/drivers/net/nfp/nfp_common.h +++ b/drivers/net/nfp/nfp_common.h @@ -450,6 +450,7 @@ void nfp_net_close_tx_queue(struct rte_eth_dev *dev); int nfp_net_set_vxlan_port(struct nfp_net_hw *hw, size_t idx, uint16_t port); int nfp_net_check_dma_mask(struct nfp_net_hw *hw, char *name); void nfp_net_irq_unmask(struct rte_eth_dev *dev); +void nfp_pf_uninit(struct nfp_pf_dev *pf_dev); #define NFP_NET_DEV_PRIVATE_TO_HW(adapter)\ (&((struct nfp_net_adapter *)adapter)->hw) diff --git a/drivers/net/nfp/nfp_ethdev.c b/drivers/net/nfp/nfp_ethdev.c index 77f573c..68fd67a 100644 --- a/drivers/net/nfp/nfp_ethdev.c +++ b/drivers/net/nfp/nfp_ethdev.c @@ -264,6 +264,45 @@ nfp_net_set_link_down(struct rte_eth_dev *dev) hw->nfp_idx, 0); } +static void +nfp_cleanup_port_app_fw_nic(struct nfp_pf_dev *pf_dev, + uint8_t id) +{ + struct nfp_app_fw_nic *app_fw_nic; + + app_fw_nic = pf_dev->app_fw_priv; + if (app_fw_nic->ports[id] != NULL) + app_fw_nic->ports[id] = NULL; +} + +static void +nfp_uninit_app_fw_nic(struct nfp_pf_dev *pf_dev) +{ + nfp_cpp_area_release_free(pf_dev->ctrl_area); + rte_free(pf_dev->app_fw_priv); +} + +void +nfp_pf_uninit(struct nfp_pf_dev *pf_dev) +{ + nfp_cpp_area_release_free(pf_dev->hwqueues_area); + free(pf_dev->sym_tbl); + free(pf_dev->nfp_eth_table); + free(pf_dev->hwinfo); + nfp_cpp_free(pf_dev->cpp); + rte_free(pf_dev); +} + +static int +nfp_pf_secondary_uninit(struct nfp_pf_dev *pf_dev) +{ + free(pf_dev->sym_tbl); + nfp_cpp_free(pf_dev->cpp); + rte_free(pf_dev); + + return 0; +} + /* Reset and stop device. The device can not be restarted. */ static int nfp_net_close(struct rte_eth_dev *dev) @@ -274,8 +313,19 @@ nfp_net_close(struct rte_eth_dev *dev) struct nfp_app_fw_nic *app_fw_nic; int i; - if (rte_eal_process_type() != RTE_PROC_PRIMARY) + /* + * In secondary process, a released eth device can be found by its name + * in shared memory. + * If the state of the eth device is RTE_ETH_DEV_UNUSED, it means the + * eth device has been released. + */ + if (rte_eal_process_type() == RTE_PROC_SECONDARY) { + if (dev->state == RTE_ETH_DEV_UNUSED) + return 0; + + nfp_pf_secondary_uninit(dev->process_private); return 0; + } PMD_INIT_LOG(DEBUG, "Close"); @@ -303,7 +353,11 @@ nfp_net_close(struct rte_eth_dev *dev) /* Only free PF resources after all physical ports have been closed */ /* Mark this port as unused and free device priv resources*/ nn_cfg_writeb(hw, NFP_NET_CFG_LSC, 0xff); - app_fw_nic->ports[hw->idx] = NULL; + + if (pf_dev->app_fw_id != NFP_APP_FW_CORE_NIC) + return -EINVAL; + + nfp_cleanup_port_app_fw_nic(pf_dev, hw->idx); for (i = 0; i < app_fw_nic->total_phyports; i++) { /* Check to see if ports are still in use */ @@ -311,26 +365,15 @@ nfp_net_close(struct rte_eth_dev *dev) return 0; } - /* Now it is safe to free all PF resources */ - PMD_INIT_LOG(INFO, "Freeing PF resources"); - nfp_cpp_area_free(pf_dev->ctrl_area); - nfp_cpp_area_free(pf_dev->hwqueues_area); - free(pf_dev->hwinfo); - free(pf_dev->sym_tbl); - nfp_cpp_free(pf_dev->cpp); - rte_free(app_fw_nic); - rte_free(pf_dev); - + /* Enable in nfp_net_start() */ rte_intr_disable(pci_dev->intr_handle); - /* unregister callback func from eal lib */ + /* Register in nfp_net_init() */ rte_intr_callback_unregister(pci_dev->intr_handle, nfp_net_dev_interrupt_handler, (void *)dev); - /* - * The ixgbe PMD disables the pcie master on the - * device. The i40e does not... - */ + nfp_uninit_app_fw_nic(pf_dev); + nfp_pf_uninit(pf_dev); return 0; } -- 2.39.1