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 4917EA0543; Tue, 21 Jun 2022 11:10:36 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 24BB44069C; Tue, 21 Jun 2022 11:10:36 +0200 (CEST) Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by mails.dpdk.org (Postfix) with ESMTP id 3F9CC40151; Tue, 21 Jun 2022 11:10:35 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1655802635; x=1687338635; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=cI5jVCkFNj9q3VVgJr9zqJRl6qPzVURlVOpx1i3o5Rc=; b=Mlxl77xh+x11PPjzC3oheBA34oXVkOIdLtnXdrqIFoDCnSBiMzYgYsAr W0gNgG7KKuHIVBxR/C+dLH8eiiUWInGlGgT2WpfP7xUcajSJvW535uh9j l/nXnvCGVS3O/3/H/MJdUNL3XgjxyrFVivbMGmW9FOxAJqjbawUQko16U fUwvmgZwVzhy4SKI/r3psNV1RsHc0Ctf6fSsoOXadSImj7qquod3N5vOj Rfvr7fKMtRoWfa9hVqUL4z98dF8ZgAP0zRzMKdWUgPIYURjlq34h/FMXU QjLmIikV42NTuC1iz+ruUyBxAnqB/8L7VfsFardq1oDnZOy8TY97NMG+y Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10384"; a="277620361" X-IronPort-AV: E=Sophos;i="5.92,209,1650956400"; d="scan'208";a="277620361" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Jun 2022 02:10:34 -0700 X-IronPort-AV: E=Sophos;i="5.92,209,1650956400"; d="scan'208";a="643536484" Received: from unknown (HELO localhost.localdomain) ([10.239.252.104]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Jun 2022 02:10:32 -0700 From: Ke Zhang To: xiaoyun.li@intel.com, aman.deep.singh@intel.com, yuying.zhang@intel.com, dev@dpdk.org Cc: Ke Zhang , stable@dpdk.org Subject: [PATCH v2] app/testpmd: fix quit testpmd with vfs and pf Date: Tue, 21 Jun 2022 17:03:25 +0800 Message-Id: <20220621090325.184668-1-ke1x.zhang@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220322071833.199619-1-ke1x.zhang@intel.com> References: <20220322071833.199619-1-ke1x.zhang@intel.com> 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. Fixes: 08fd782b8454 ("app/testpmd: fix quit to stop all ports before close") Cc: stable@dpdk.org Signed-off-by: Ke Zhang --- app/test-pmd/testpmd.c | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c index 04c39adc21..67b4941942 100644 --- a/app/test-pmd/testpmd.c +++ b/app/test-pmd/testpmd.c @@ -3491,17 +3491,34 @@ pmd_test_exit(void) } } #endif + portid_t ethports[RTE_MAX_ETHPORTS]; + int count; + int index; if (ports != NULL) { no_link_check = 1; + count = 0; + + /* Fetch the valid port id from port list*/ RTE_ETH_FOREACH_DEV(pt_id) { - printf("\nStopping port %d...\n", pt_id); + ethports[count] = pt_id; + count++; + } + + /* + * 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