patches for DPDK stable branches
 help / color / mirror / Atom feed
* [PATCH 1/8] net/nfp: fix resource leak of secondary process
       [not found] <20240419031226.1191069-1-chaoyong.he@corigine.com>
@ 2024-04-19  3:12 ` Chaoyong He
  2024-04-19  3:12 ` [PATCH 2/8] net/nfp: fix configuration BAR problem Chaoyong He
       [not found] ` <20240419052349.1294696-1-chaoyong.he@corigine.com>
  2 siblings, 0 replies; 4+ messages in thread
From: Chaoyong He @ 2024-04-19  3:12 UTC (permalink / raw)
  To: dev; +Cc: oss-drivers, Chaoyong He, stable, Long Wu, Peng Zhang

Fix one resource leak problem in the abnormal logic of secondary process.

Fixes: 016141b18b3a ("net/nfp: refactor secondary process probe")
Cc: stable@dpdk.org

Signed-off-by: Chaoyong He <chaoyong.he@corigine.com>
Reviewed-by: Long Wu <long.wu@corigine.com>
Reviewed-by: Peng Zhang <peng.zhang@corigine.com>
---
 drivers/net/nfp/nfp_ethdev.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/net/nfp/nfp_ethdev.c b/drivers/net/nfp/nfp_ethdev.c
index b711e15b9f..98d8e87028 100644
--- a/drivers/net/nfp/nfp_ethdev.c
+++ b/drivers/net/nfp/nfp_ethdev.c
@@ -2123,7 +2123,7 @@ nfp_pf_secondary_init(struct rte_pci_device *pci_dev)
 	if (sym_tbl == NULL) {
 		PMD_INIT_LOG(ERR, "Something is wrong with the firmware symbol table");
 		ret = -EIO;
-		goto sync_free;
+		goto cpp_cleanup;
 	}
 
 	/* Read the app ID of the firmware loaded */
@@ -2171,6 +2171,8 @@ nfp_pf_secondary_init(struct rte_pci_device *pci_dev)
 
 sym_tbl_cleanup:
 	free(sym_tbl);
+cpp_cleanup:
+	nfp_cpp_free(cpp);
 sync_free:
 	nfp_sync_free(sync);
 pf_cleanup:
-- 
2.39.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 2/8] net/nfp: fix configuration BAR problem
       [not found] <20240419031226.1191069-1-chaoyong.he@corigine.com>
  2024-04-19  3:12 ` [PATCH 1/8] net/nfp: fix resource leak of secondary process Chaoyong He
@ 2024-04-19  3:12 ` Chaoyong He
       [not found] ` <20240419052349.1294696-1-chaoyong.he@corigine.com>
  2 siblings, 0 replies; 4+ messages in thread
From: Chaoyong He @ 2024-04-19  3:12 UTC (permalink / raw)
  To: dev; +Cc: oss-drivers, Chaoyong He, stable, Long Wu, Peng Zhang

All the configuration bars are sit in an array, and the initial logic
sort all the configuration BAR from small to large based on size and index,
which result all valid bars are behind the invalid bars.
But the BAR alloc logic search this array from the very beginning and
only try limited times (equal to the valid bars number).
It's ok for primary process because which has enough valid bars, and
finally it can find one to use.

But for secondary process and run with igb_uio driver, the valid bars
are very limit, and it can not find one, and the logic will fail.

Fix this by drop the sort logic, and search the bar array from the end
to begin.

Fixes: 1fbe51cd9c3a ("net/nfp: extend usage of BAR from 8 to 24")
Cc: stable@dpdk.org

Signed-off-by: Chaoyong He <chaoyong.he@corigine.com>
Reviewed-by: Long Wu <long.wu@corigine.com>
Reviewed-by: Peng Zhang <peng.zhang@corigine.com>
---
 drivers/net/nfp/nfpcore/nfp6000_pcie.c | 34 +++++++++-----------------
 1 file changed, 11 insertions(+), 23 deletions(-)

diff --git a/drivers/net/nfp/nfpcore/nfp6000_pcie.c b/drivers/net/nfp/nfpcore/nfp6000_pcie.c
index a6fd89b6c8..ef1ffd6d01 100644
--- a/drivers/net/nfp/nfpcore/nfp6000_pcie.c
+++ b/drivers/net/nfp/nfpcore/nfp6000_pcie.c
@@ -263,19 +263,6 @@ nfp_bitsize_calc(uint64_t mask)
 	return bit_size;
 }
 
-static int
-nfp_cmp_bars(const void *ptr_a,
-		const void *ptr_b)
-{
-	const struct nfp_bar *a = ptr_a;
-	const struct nfp_bar *b = ptr_b;
-
-	if (a->bitsize == b->bitsize)
-		return a->index - b->index;
-	else
-		return a->bitsize - b->bitsize;
-}
-
 static bool
 nfp_bars_for_secondary(uint32_t index)
 {
@@ -383,9 +370,6 @@ nfp_enable_bars(struct nfp_pcie_user *nfp)
 	if (nfp_bar_write(nfp, bar, barcfg_msix_general) < 0)
 		return -EIO;
 
-	/* Sort bars by bit size - use the smallest possible first. */
-	qsort(&nfp->bar[0], nfp->bars, sizeof(nfp->bar[0]), nfp_cmp_bars);
-
 	return 0;
 }
 
@@ -466,16 +450,18 @@ find_matching_bar(struct nfp_pcie_user *nfp,
 		int width)
 {
 	uint32_t n;
+	uint32_t index;
 
-	for (n = 0; n < nfp->bars; n++) {
-		struct nfp_bar *bar = &nfp->bar[n];
+	for (n = RTE_DIM(nfp->bar) ; n > 0; n--) {
+		index = n - 1;
+		struct nfp_bar *bar = &nfp->bar[index];
 
 		if (bar->lock)
 			continue;
 
 		if (matching_bar_exist(bar, target, action, token,
 				offset, size, width))
-			return n;
+			return index;
 	}
 
 	return -1;
@@ -493,10 +479,12 @@ find_unused_bar_noblock(struct nfp_pcie_user *nfp,
 {
 	int ret;
 	uint32_t n;
+	uint32_t index;
 	const struct nfp_bar *bar;
 
-	for (n = 0; n < nfp->bars; n++) {
-		bar = &nfp->bar[n];
+	for (n = RTE_DIM(nfp->bar); n > 0; n--) {
+		index = n - 1;
+		bar = &nfp->bar[index];
 
 		if (bar->bitsize == 0)
 			continue;
@@ -508,7 +496,7 @@ find_unused_bar_noblock(struct nfp_pcie_user *nfp,
 			continue;
 
 		if (!bar->lock)
-			return n;
+			return index;
 	}
 
 	return -EAGAIN;
@@ -561,7 +549,7 @@ nfp_disable_bars(struct nfp_pcie_user *nfp)
 	uint32_t i;
 	struct nfp_bar *bar;
 
-	for (i = 0; i < nfp->bars; i++) {
+	for (i = 0; i < RTE_DIM(nfp->bar); i++) {
 		bar = &nfp->bar[i];
 		if (bar->iomem != NULL) {
 			bar->iomem = NULL;
-- 
2.39.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2 1/8] net/nfp: fix resource leak of secondary process
       [not found] ` <20240419052349.1294696-1-chaoyong.he@corigine.com>
@ 2024-04-19  5:23   ` Chaoyong He
  2024-04-19  5:23   ` [PATCH v2 2/8] net/nfp: fix configuration BAR problem Chaoyong He
  1 sibling, 0 replies; 4+ messages in thread
From: Chaoyong He @ 2024-04-19  5:23 UTC (permalink / raw)
  To: dev; +Cc: oss-drivers, Chaoyong He, stable, Long Wu, Peng Zhang

Fix one resource leak problem in the abnormal logic of secondary process.

Fixes: 016141b18b3a ("net/nfp: refactor secondary process probe")
Cc: stable@dpdk.org

Signed-off-by: Chaoyong He <chaoyong.he@corigine.com>
Reviewed-by: Long Wu <long.wu@corigine.com>
Reviewed-by: Peng Zhang <peng.zhang@corigine.com>
---
 drivers/net/nfp/nfp_ethdev.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/net/nfp/nfp_ethdev.c b/drivers/net/nfp/nfp_ethdev.c
index b711e15b9f..98d8e87028 100644
--- a/drivers/net/nfp/nfp_ethdev.c
+++ b/drivers/net/nfp/nfp_ethdev.c
@@ -2123,7 +2123,7 @@ nfp_pf_secondary_init(struct rte_pci_device *pci_dev)
 	if (sym_tbl == NULL) {
 		PMD_INIT_LOG(ERR, "Something is wrong with the firmware symbol table");
 		ret = -EIO;
-		goto sync_free;
+		goto cpp_cleanup;
 	}
 
 	/* Read the app ID of the firmware loaded */
@@ -2171,6 +2171,8 @@ nfp_pf_secondary_init(struct rte_pci_device *pci_dev)
 
 sym_tbl_cleanup:
 	free(sym_tbl);
+cpp_cleanup:
+	nfp_cpp_free(cpp);
 sync_free:
 	nfp_sync_free(sync);
 pf_cleanup:
-- 
2.39.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2 2/8] net/nfp: fix configuration BAR problem
       [not found] ` <20240419052349.1294696-1-chaoyong.he@corigine.com>
  2024-04-19  5:23   ` [PATCH v2 1/8] net/nfp: fix resource leak of secondary process Chaoyong He
@ 2024-04-19  5:23   ` Chaoyong He
  1 sibling, 0 replies; 4+ messages in thread
From: Chaoyong He @ 2024-04-19  5:23 UTC (permalink / raw)
  To: dev; +Cc: oss-drivers, Chaoyong He, stable, Long Wu, Peng Zhang

All the configuration bars are sit in an array, and the initial logic
sort all the configuration BAR from small to large based on size and index,
which result all valid bars are behind the invalid bars.
But the BAR alloc logic search this array from the very beginning and
only try limited times (equal to the valid bars number).
It's ok for primary process because which has enough valid bars, and
finally it can find one to use.

But for secondary process and run with igb_uio driver, the valid bars
are very limit, and it can not find one, and the logic will fail.

Fix this by drop the sort logic, and search the bar array from the end
to begin.

Fixes: 1fbe51cd9c3a ("net/nfp: extend usage of BAR from 8 to 24")
Cc: stable@dpdk.org

Signed-off-by: Chaoyong He <chaoyong.he@corigine.com>
Reviewed-by: Long Wu <long.wu@corigine.com>
Reviewed-by: Peng Zhang <peng.zhang@corigine.com>
---
 drivers/net/nfp/nfpcore/nfp6000_pcie.c | 34 +++++++++-----------------
 1 file changed, 11 insertions(+), 23 deletions(-)

diff --git a/drivers/net/nfp/nfpcore/nfp6000_pcie.c b/drivers/net/nfp/nfpcore/nfp6000_pcie.c
index a6fd89b6c8..ef1ffd6d01 100644
--- a/drivers/net/nfp/nfpcore/nfp6000_pcie.c
+++ b/drivers/net/nfp/nfpcore/nfp6000_pcie.c
@@ -263,19 +263,6 @@ nfp_bitsize_calc(uint64_t mask)
 	return bit_size;
 }
 
-static int
-nfp_cmp_bars(const void *ptr_a,
-		const void *ptr_b)
-{
-	const struct nfp_bar *a = ptr_a;
-	const struct nfp_bar *b = ptr_b;
-
-	if (a->bitsize == b->bitsize)
-		return a->index - b->index;
-	else
-		return a->bitsize - b->bitsize;
-}
-
 static bool
 nfp_bars_for_secondary(uint32_t index)
 {
@@ -383,9 +370,6 @@ nfp_enable_bars(struct nfp_pcie_user *nfp)
 	if (nfp_bar_write(nfp, bar, barcfg_msix_general) < 0)
 		return -EIO;
 
-	/* Sort bars by bit size - use the smallest possible first. */
-	qsort(&nfp->bar[0], nfp->bars, sizeof(nfp->bar[0]), nfp_cmp_bars);
-
 	return 0;
 }
 
@@ -466,16 +450,18 @@ find_matching_bar(struct nfp_pcie_user *nfp,
 		int width)
 {
 	uint32_t n;
+	uint32_t index;
 
-	for (n = 0; n < nfp->bars; n++) {
-		struct nfp_bar *bar = &nfp->bar[n];
+	for (n = RTE_DIM(nfp->bar) ; n > 0; n--) {
+		index = n - 1;
+		struct nfp_bar *bar = &nfp->bar[index];
 
 		if (bar->lock)
 			continue;
 
 		if (matching_bar_exist(bar, target, action, token,
 				offset, size, width))
-			return n;
+			return index;
 	}
 
 	return -1;
@@ -493,10 +479,12 @@ find_unused_bar_noblock(struct nfp_pcie_user *nfp,
 {
 	int ret;
 	uint32_t n;
+	uint32_t index;
 	const struct nfp_bar *bar;
 
-	for (n = 0; n < nfp->bars; n++) {
-		bar = &nfp->bar[n];
+	for (n = RTE_DIM(nfp->bar); n > 0; n--) {
+		index = n - 1;
+		bar = &nfp->bar[index];
 
 		if (bar->bitsize == 0)
 			continue;
@@ -508,7 +496,7 @@ find_unused_bar_noblock(struct nfp_pcie_user *nfp,
 			continue;
 
 		if (!bar->lock)
-			return n;
+			return index;
 	}
 
 	return -EAGAIN;
@@ -561,7 +549,7 @@ nfp_disable_bars(struct nfp_pcie_user *nfp)
 	uint32_t i;
 	struct nfp_bar *bar;
 
-	for (i = 0; i < nfp->bars; i++) {
+	for (i = 0; i < RTE_DIM(nfp->bar); i++) {
 		bar = &nfp->bar[i];
 		if (bar->iomem != NULL) {
 			bar->iomem = NULL;
-- 
2.39.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-04-19  5:24 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20240419031226.1191069-1-chaoyong.he@corigine.com>
2024-04-19  3:12 ` [PATCH 1/8] net/nfp: fix resource leak of secondary process Chaoyong He
2024-04-19  3:12 ` [PATCH 2/8] net/nfp: fix configuration BAR problem Chaoyong He
     [not found] ` <20240419052349.1294696-1-chaoyong.he@corigine.com>
2024-04-19  5:23   ` [PATCH v2 1/8] net/nfp: fix resource leak of secondary process Chaoyong He
2024-04-19  5:23   ` [PATCH v2 2/8] net/nfp: fix configuration BAR problem Chaoyong He

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).