DPDK patches and discussions
 help / color / mirror / Atom feed
From: Ke Zhang <ke1x.zhang@intel.com>
To: xiaoyun.li@intel.com, aman.deep.singh@intel.com,
	yuying.zhang@intel.com, dev@dpdk.org
Cc: Ke Zhang <ke1x.zhang@intel.com>
Subject: [PATCH] app/testpmd: fix quit testpmd with vfs and pf
Date: Tue, 22 Mar 2022 08:05:29 +0000	[thread overview]
Message-ID: <20220322080529.200942-1-ke1x.zhang@intel.com> (raw)

When testpmd startups with pf and vfs,this error occurs when quitting,
results in pf is released before vfs ,so the vf would access an
freed heap memory.

The solution is two steps:
1. Fetch the valid port value from RTE_ETH_FOREACH_DEV.
2. free the port in reverse order.

Signed-off-by: Ke Zhang <ke1x.zhang@intel.com>
---
 app/test-pmd/testpmd.c | 28 +++++++++++++++++++++++-----
 1 file changed, 23 insertions(+), 5 deletions(-)

diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c
index f7e18aee25..2299aef3dd 100644
--- a/app/test-pmd/testpmd.c
+++ b/app/test-pmd/testpmd.c
@@ -3378,8 +3378,11 @@ detach_devargs(char *identifier)
 void
 pmd_test_exit(void)
 {
+	unsigned int ethports[RTE_MAX_ETHPORTS];
+	unsigned int count = 0;
 	portid_t pt_id;
 	unsigned int i;
+	int index;
 	int ret;
 
 	if (test_done == 0)
@@ -3396,15 +3399,30 @@ pmd_test_exit(void)
 #endif
 	if (ports != NULL) {
 		no_link_check = 1;
+		i = 0;
+
+		/* Fetch the valid port id from port list*/
 		RTE_ETH_FOREACH_DEV(pt_id) {
-			printf("\nStopping port %d...\n", pt_id);
+			ethports[i] = pt_id;
+			i++;
+		}
+
+		count = i;
+		/*
+		 * Free the port from Reverse order, as general,
+		 * PF port < VF port, VF should be free before PF
+		 * be free.
+		 */
+		for (index = count - 1 ; index >= 0 ; index--) {
+			printf("\nStopping port %d...\n", ethports[index]);
 			fflush(stdout);
-			stop_port(pt_id);
+			stop_port(ethports[index]);
 		}
-		RTE_ETH_FOREACH_DEV(pt_id) {
-			printf("\nShutting down port %d...\n", pt_id);
+
+		for (index = count - 1 ; index >= 0 ; index--) {
+			printf("\nShutting down port %d...\n", ethports[index]);
 			fflush(stdout);
-			close_port(pt_id);
+			close_port(ethports[index]);
 		}
 	}
 
-- 
2.25.1


             reply	other threads:[~2022-03-22  8:10 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-22  8:05 Ke Zhang [this message]
  -- strict thread matches above, loose matches on Subject: below --
2022-03-22  7:18 Ke Zhang
2022-03-28 10:06 ` Singh, Aman Deep
2022-03-31  8:28   ` Singh, Aman Deep
2022-06-17 18:53   ` Ferruh Yigit

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=20220322080529.200942-1-ke1x.zhang@intel.com \
    --to=ke1x.zhang@intel.com \
    --cc=aman.deep.singh@intel.com \
    --cc=dev@dpdk.org \
    --cc=xiaoyun.li@intel.com \
    --cc=yuying.zhang@intel.com \
    /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).