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 88C3843BBA for ; Thu, 7 Mar 2024 12:20:48 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 3554E42E74; 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 B729C410D5 for ; Thu, 7 Mar 2024 12:20:46 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LufrxXqsXDhcK/zXOzil6fw1P1rVbTjiwW5kuLfy4rwnGFxJmZ1rYzpw0tE2yqwXhXJ239f1y+l7h2ldXo04crUGtTmVcGuL1OBTn9HPmmdPHufZ98stIZhyIlysifr7m28uF/SvL0DXdZOGY/WBT0dr1W/2hWREpkdwvaLH2g3Hs8BApIVKLUiBXbNh3CQQLdzc3YUZmhQu8yJcfSTC2kARA0uow1b2eW3UCwhpiS1AVvDEM8AYNsfEUjnVRQX4m8MNN+OVJLBf39fQHMdm8OdI1MjcUK/q+WFkqJH/HAIQsgzayPnSbJpFnqNJVWJu5jKK7EGZHwGtLKmnEVk3GA== 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=DUOcmPgnYA+DVr1aX5TS44h49czaR11+c2Et/BA91X4=; b=KvR2LOLkd6NsPyMTJbUALAulePFX6NjAOBr8H/pq7LgbWn7+pt81wT4ZRt4B11ykse9JuTUCtT+gDaiqoQjPZDAhHLYICqkZ2O8+dPRVpqeHLRB0PdecoYb/DeLF81rFl+ohNjD/EDtLP9cZNaIjjBeON5k+h8P05lJKIEB88aL010QnGabfgZKNWqvEj1cocbQwnFk2iMemTFeyvmaQRyuwNtOHL8BJx7GyXy7kxC/3sqk6zXjgyGI0Lt74FDsIjocsNAstT3Ql+StkFn4itX6TMGb8BGk6obF0h6kcpYcHoLhWys020pztK+kyzjxuk4PLt6xWrpf7nPyiPCSPfA== 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=DUOcmPgnYA+DVr1aX5TS44h49czaR11+c2Et/BA91X4=; b=UJjYTzZfxopUIbDVXRLExpBzN50tL90ttI0sxnSc5AqsVKc3vlWS0VWNB2T/ahFYhPrtLLb8QxOIB9N0VBgMZuuKjyKlCAccejNP1l2YLCiTIlgMoNEkfBfHSXuJa03NEbWNvSVecO7nGwzDgS6W2wBdxx/YO4bPIfqN3T9Kd0U= 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:44 +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:44 +0000 From: Chaoyong He To: stable@dpdk.org Cc: oss-drivers@corigine.com, Chaoyong He Subject: [PATCH 22.11 v2 2/7] net/nfp: fix resource leak for flower firmware Date: Thu, 7 Mar 2024 19:20:18 +0800 Message-Id: <20240307112023.1867765-3-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: dd716b1c-9976-455a-382a-08dc3e98a147 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: KklgNee8ztGfAshs9gif6gyvwg/cIxBBD+T7G7CVdueJ0ePqi6nelGSbv7TIUnri1EwwxF5BXo9zA/pG4xedT+nba6/G4ONdTTnwfpLfKVxl+InxbxJc1MUpEUlkgZM8Z/RfWz+FsrB4hWElVosOjkEgGBI6xWiMBYJ1Gt4OZ51gmKGAFGgLxDkreO79636moN5m+bM/kolOC6ck3ExCo2CmLaVCRA1s3IWm4b5bo5zJjWThAnJiSHta/rmlTUXX2EvIRrkDhjYHhAGXu/AZZbSZe20+WOpSQbM4EgLnnc/x0qHmNGlmlgrCOF3+aZNAl50Tz+8vR/R3YJJHrdCMvtBOLKGFxbtmdzVoPiyfggLkw1yzJrcv0olXAIaIgSQNbzZtOlcHxlUKVjdBX0iAYTCLiS0ckTt7XUqEERTxAps6yo92NRRKIjj2mglV42q9mUC/W82ue4Ymvugo290Pgb74x15LOwvQN8fgeV/oeuYkSAnWolkB12jPe5xjfNc5Njdo5+0DFM6fXeAHOuLYNaL/6QUYMaUBCXp/zXfGPy32nTgZo+36s7TM2qeo+NGcLrPDXEDX9VH9msIiuQPWUY+V5BbMJUju5F7oqo1VVgWYSGY7duphEckjgMm3jmWKtXt3ujEnEktXx+HHxdM3Fw+otd40QvFCzW6iHcIES8NFUSK2frHUmaHaPLS/NxfgHoyq132uR+GjHRUrE1f3Dhn+0lL3Te+UeY7tbMKdh7k= 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?AaEi7qqCj/p/JzMhPr02zPT0UNsKdJMaXZSGy9Qitf4YE7v2bxtIwMxwsF30?= =?us-ascii?Q?NOV52VnCW2YPmk49EdiPMymldRsVjhrJ/UnpbAE4q0t4h94mStbCEOMo+30P?= =?us-ascii?Q?sabVVbWqwSlYdpXPThSxMglBEjPvvDMZBTuGHYL/J4t16+7dinmYTJNBSNsE?= =?us-ascii?Q?0abpvYYNOk7SE0pDOO3uQpyXv/vIbUJIl+MpSNq09njnOKqwSzL+xbQ5IpB5?= =?us-ascii?Q?1KJFO5mp31ZSZanMvxrItDlyicPIgiOoR4mkJsWMY9npCHrBJPMO7xPIpsp9?= =?us-ascii?Q?Au6Ix8gC0W0QKQJt6nrHf/a3V3uN7bE2dKfpAUsT02LFbea1nEQvFx3tzI5k?= =?us-ascii?Q?oqGkoNWCtdGZk7Wo6mGKASEOkGRt4UZkoOWJ88gYc5vx04xvlgMEysYyDx08?= =?us-ascii?Q?QIUc49KpSyfuVgyW+9y9nz0Nxbo1q10zDjdC34eVqbd/O1OVFJMp/Ye3PY+l?= =?us-ascii?Q?CfzZF53Enjc2IPTf1IxqJX77FODBS93hqrFit+eOTofAU69rGbr4+sJc5UGf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Jw2sZxx+u4N+k4Dwt1Sugi?= =?us-ascii?Q?kToMYFFYEmo77qQj0Pgj/J2aUeDAVSmW/RoCLqZVkSK8Tc1clgE8nO3DTetR?= =?us-ascii?Q?Xe6EVzZN96LbkKwLctmEI0x1BwpSArXAslDXFP5iOPgrtMIfGrVzNY95x+ks?= =?us-ascii?Q?QKJ7d6QeSI0AVegfUm306y0E1uDaCgReGo11LKyOXfnTXtOmIGgSpfGGGPt8?= =?us-ascii?Q?BA=3D=3D?= X-OriginatorOrg: corigine.com X-MS-Exchange-CrossTenant-Network-Message-Id: dd716b1c-9976-455a-382a-08dc3e98a147 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:44.4143 (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: LtGysZTzJaZda1D3ap9APyKUI8Cnhw/9HGrxGU+Gn76cVdQ7X9ArJqRzq3MQpUZcs+b3zihXNioMy9cSiJB9RcQlQQQzpkxRm2Kog3ZRkdo= 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 7c596721ae5f41d1dbab8b936a4983928d6b5603 ] Fix the resource leak problem in the logic of flower firmware application. Fixes: e1124c4f8a45 ("net/nfp: add flower representor framework") Signed-off-by: Chaoyong He --- .../net/nfp/flower/nfp_flower_representor.c | 89 ++++++++++++++++++- .../net/nfp/flower/nfp_flower_representor.h | 1 + 2 files changed, 86 insertions(+), 4 deletions(-) diff --git a/drivers/net/nfp/flower/nfp_flower_representor.c b/drivers/net/nfp/flower/nfp_flower_representor.c index 32c4574..3ff54a9 100644 --- a/drivers/net/nfp/flower/nfp_flower_representor.c +++ b/drivers/net/nfp/flower/nfp_flower_representor.c @@ -524,6 +524,43 @@ nfp_flower_repr_tx_burst(void *tx_queue, return sent; } +static int +nfp_flower_repr_uninit(struct rte_eth_dev *eth_dev) +{ + struct nfp_flower_representor *repr; + + repr = eth_dev->data->dev_private; + rte_ring_free(repr->ring); + + return 0; +} + +static int +nfp_flower_pf_repr_uninit(__rte_unused struct rte_eth_dev *eth_dev) +{ + return 0; +} + +static void +nfp_flower_repr_free(struct nfp_flower_representor *repr, + enum nfp_repr_type repr_type) +{ + switch (repr_type) { + case NFP_REPR_TYPE_PHYS_PORT: + rte_eth_dev_destroy(repr->eth_dev, nfp_flower_repr_uninit); + break; + case NFP_REPR_TYPE_PF: + rte_eth_dev_destroy(repr->eth_dev, nfp_flower_pf_repr_uninit); + break; + case NFP_REPR_TYPE_VF: + rte_eth_dev_destroy(repr->eth_dev, nfp_flower_repr_uninit); + break; + default: + PMD_DRV_LOG(ERR, "Unsupported repr port type."); + break; + } +} + static const struct eth_dev_ops nfp_flower_pf_repr_dev_ops = { .dev_infos_get = nfp_flower_repr_dev_infos_get, @@ -640,6 +677,7 @@ nfp_flower_pf_repr_init(struct rte_eth_dev *eth_dev, repr->app_fw_flower->pf_repr = repr; repr->app_fw_flower->pf_hw->eth_dev = eth_dev; + repr->eth_dev = eth_dev; return 0; } @@ -731,6 +769,8 @@ nfp_flower_repr_init(struct rte_eth_dev *eth_dev, app_fw_flower->vf_reprs[index] = repr; } + repr->eth_dev = eth_dev; + return 0; mac_cleanup: @@ -741,6 +781,35 @@ nfp_flower_repr_init(struct rte_eth_dev *eth_dev, return ret; } +static void +nfp_flower_repr_free_all(struct nfp_app_fw_flower *app_fw_flower) +{ + uint32_t i; + struct nfp_flower_representor *repr; + + for (i = 0; i < MAX_FLOWER_VFS; i++) { + repr = app_fw_flower->vf_reprs[i]; + if (repr != NULL) { + nfp_flower_repr_free(repr, NFP_REPR_TYPE_VF); + app_fw_flower->vf_reprs[i] = NULL; + } + } + + for (i = 0; i < MAX_FLOWER_PHYPORTS; i++) { + repr = app_fw_flower->phy_reprs[i]; + if (repr != NULL) { + nfp_flower_repr_free(repr, NFP_REPR_TYPE_PHYS_PORT); + app_fw_flower->phy_reprs[i] = NULL; + } + } + + repr = app_fw_flower->pf_repr; + if (repr != NULL) { + nfp_flower_repr_free(repr, NFP_REPR_TYPE_PF); + app_fw_flower->pf_repr = NULL; + } +} + static int nfp_flower_repr_alloc(struct nfp_app_fw_flower *app_fw_flower) { @@ -816,7 +885,7 @@ nfp_flower_repr_alloc(struct nfp_app_fw_flower *app_fw_flower) } if (i < app_fw_flower->num_phyport_reprs) - return ret; + goto repr_free; /* * Now allocate eth_dev's for VF representors. @@ -845,9 +914,14 @@ nfp_flower_repr_alloc(struct nfp_app_fw_flower *app_fw_flower) } if (i < app_fw_flower->num_vf_reprs) - return ret; + goto repr_free; return 0; + +repr_free: + nfp_flower_repr_free_all(app_fw_flower); + + return ret; } int @@ -866,7 +940,7 @@ nfp_flower_repr_create(struct nfp_app_fw_flower *app_fw_flower) /* Allocate a switch domain for the flower app */ if (app_fw_flower->switch_domain_id == RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID && - rte_eth_switch_domain_alloc(&app_fw_flower->switch_domain_id)) { + rte_eth_switch_domain_alloc(&app_fw_flower->switch_domain_id) != 0) { PMD_INIT_LOG(WARNING, "failed to allocate switch domain for device"); } @@ -908,8 +982,15 @@ nfp_flower_repr_create(struct nfp_app_fw_flower *app_fw_flower) ret = nfp_flower_repr_alloc(app_fw_flower); if (ret != 0) { PMD_INIT_LOG(ERR, "representors allocation failed"); - return -EINVAL; + ret = -EINVAL; + goto domain_free; } return 0; + +domain_free: + if (rte_eth_switch_domain_free(app_fw_flower->switch_domain_id) != 0) + PMD_INIT_LOG(WARNING, "Failed to free switch domain for device"); + + return ret; } diff --git a/drivers/net/nfp/flower/nfp_flower_representor.h b/drivers/net/nfp/flower/nfp_flower_representor.h index 685cbe4..c043214 100644 --- a/drivers/net/nfp/flower/nfp_flower_representor.h +++ b/drivers/net/nfp/flower/nfp_flower_representor.h @@ -34,6 +34,7 @@ struct nfp_flower_representor { struct rte_ring *ring; struct rte_eth_link link; struct rte_eth_stats repr_stats; + struct rte_eth_dev *eth_dev; }; int nfp_flower_repr_create(struct nfp_app_fw_flower *app_fw_flower); -- 2.39.1