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 3BD27A04FF; Tue, 22 Mar 2022 09:10:09 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id CE87A427ED; Tue, 22 Mar 2022 09:10:08 +0100 (CET) Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by mails.dpdk.org (Postfix) with ESMTP id B9D69410E5 for ; Tue, 22 Mar 2022 09:10:06 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1647936607; x=1679472607; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=qVcJlOygGLcIZP+eTRQSi8e22LFZ0rjaYJSU0HnvVdU=; b=geu7SWJYZmZuWquV/Q3I8irIqLIOvTN5LjqORkk0UjmovZN6zD12CS9g /vrwR3B0A4HhSq7xOQbiezBU7551ZWQqDb7dd8cGYpKwiwbjnzMnmnPWk SEsu/sUcagXyFpPxPsUK69+4+hLfBGkIzrmmRGHZpJwif7MEMaSPb/ERw PN2d+B5FbtKkqZg28qaHb3JNtZ1GURh+NUbKrBvt6KBbWwCgpLdjweW2t NfnfVB3x41DXzfvHMJKseO8fClfjCkzLUfx8QXIkgix1AreE91XPvI1ly 8qcI4bQiB2HNj65BP6NSuMq/CVn5UHNAQ6LweoVdQmV6EIPmzW5Qn8XrV Q==; X-IronPort-AV: E=McAfee;i="6200,9189,10293"; a="238361845" X-IronPort-AV: E=Sophos;i="5.90,201,1643702400"; d="scan'208";a="238361845" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Mar 2022 01:09:58 -0700 X-IronPort-AV: E=Sophos;i="5.90,201,1643702400"; d="scan'208";a="716833233" Received: from intel-corei7-64.sh.intel.com (HELO localhost.localdomain) ([10.239.251.104]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Mar 2022 01:09:56 -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 08:05:29 +0000 Message-Id: <20220322080529.200942-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..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