patches for DPDK stable branches
 help / color / mirror / Atom feed
From: Chaoyong He <chaoyong.he@corigine.com>
To: stable@dpdk.org
Cc: oss-drivers@corigine.com, Chaoyong He <chaoyong.he@corigine.com>
Subject: [PATCH 22.11 v2 2/7] net/nfp: fix resource leak for flower firmware
Date: Thu,  7 Mar 2024 19:20:18 +0800	[thread overview]
Message-ID: <20240307112023.1867765-3-chaoyong.he@corigine.com> (raw)
In-Reply-To: <20240307112023.1867765-1-chaoyong.he@corigine.com>

[ 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 <chaoyong.he@corigine.com>
---
 .../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


  parent reply	other threads:[~2024-03-07 11:20 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-07 11:20 [PATCH 22.11 v2 0/7] backport patch series from NFP PMD Chaoyong He
2024-03-07 11:20 ` [PATCH 22.11 v2 1/7] net/nfp: fix resource leak for CoreNIC firmware Chaoyong He
2024-03-07 11:20 ` Chaoyong He [this message]
2024-03-07 11:20 ` [PATCH 22.11 v2 3/7] net/nfp: fix resource leak for exit of " Chaoyong He
2024-03-07 11:20 ` [PATCH 22.11 v2 4/7] net/nfp: fix resource leak for exit of flower firmware Chaoyong He
2024-03-07 11:20 ` [PATCH 22.11 v2 5/7] net/nfp: fix device close Chaoyong He
2024-03-07 11:20 ` [PATCH 22.11 v2 6/7] net/nfp: fix device resource freeing Chaoyong He
2024-03-07 11:20 ` [PATCH 22.11 v2 7/7] net/nfp: free switch domain ID on close Chaoyong He
2024-03-07 12:45 ` [PATCH 22.11 v2 0/7] backport patch series from NFP PMD Luca Boccassi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240307112023.1867765-3-chaoyong.he@corigine.com \
    --to=chaoyong.he@corigine.com \
    --cc=oss-drivers@corigine.com \
    --cc=stable@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).