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 845FFA04FF; Tue, 22 Mar 2022 08:23:29 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 2E8B7427ED; Tue, 22 Mar 2022 08:23:29 +0100 (CET) Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by mails.dpdk.org (Postfix) with ESMTP id EE155410E5 for ; Tue, 22 Mar 2022 08:23:27 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1647933808; x=1679469808; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=Ewbbdi4a/XKwq1RYUd/PtZyLWQ2tC9KAV1eKCA55MgM=; b=UlJR+UH2YstW8+MxUllzjqpJiVl+ZObM1Z8BSKQfFCDE+Z9XYbC9qZBe 8sgyGeiEL+BGv/bFl01bcKhTcrzV79+93lKDJDfcCqZ2ILsL9H70YlzEX 0n8DOdFHccWm0H6cj+TQoaoizvNqxGcjib/IS3cKmyHvlEMbW+Mw5v4aG 5V6a/XHWb+fWJS/paddyEuwT96EW95iAKM3DdhzDMTA+5I7sJMJ+nWwnl SZc/cXNJOcDs7kzs/hk3ksXMgzW4Y6bFRJ+GaAzzR6XdyU95Bn0s0+pFz /qOq145wA8atcFmULtfrmdSGecy9CIB9SaQYGBLCUpqyi+UEUgtd8dEPB Q==; X-IronPort-AV: E=McAfee;i="6200,9189,10293"; a="320948674" X-IronPort-AV: E=Sophos;i="5.90,201,1643702400"; d="scan'208";a="320948674" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Mar 2022 00:23:02 -0700 X-IronPort-AV: E=Sophos;i="5.90,201,1643702400"; d="scan'208";a="543572812" Received: from intel-corei7-64.sh.intel.com (HELO localhost.localdomain) ([10.239.251.104]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Mar 2022 00:23:00 -0700 From: Ke Zhang To: xiaoyun.li@intel.com, aman.deep.singh@intel.com, yuying.zhang@intel.com, dev@dpdk.org Cc: Ke Zhang Subject: [PATCH] app/testpmd: fix quit testpmd with vfs and pf Date: Tue, 22 Mar 2022 07:18:33 +0000 Message-Id: <20220322071833.199619-1-ke1x.zhang@intel.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org 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 --- 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..ca6c77b14b 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 ports[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); + ports[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", ports[index]); fflush(stdout); - stop_port(pt_id); + stop_port(ports[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", ports[index]); fflush(stdout); - close_port(pt_id); + close_port(ports[index]); } } -- 2.25.1