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 A54D5A0545 for ; Tue, 21 Jun 2022 11:20:15 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 9B48D427E9; Tue, 21 Jun 2022 11:20:15 +0200 (CEST) Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1anam02on2062.outbound.protection.outlook.com [40.107.96.62]) by mails.dpdk.org (Postfix) with ESMTP id C0D5740151; Tue, 21 Jun 2022 11:20:13 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jIk15Q41JDRzpobVEtRa9vrhOzYYklENslw5FexHCY4tEnNXtwbOm6lnJ7udHWLfWRnOhdPJNEG3Vgx36FTMM2EQQRVEA+/ZpPApcpIke1PzZYr/PXz0Tm1BjX5IkWDAS6XvtGErumPVwe+eWzq6hEmQgLuOZSgndt3gpPMcso8A4N25R0onZAWCk9Ft2LzPW1tu7J/nCvkPWm8OAAoFN0+7cb2dWS9wwSGcz74fK1GJ2Yj9aGPCXXGRUL4V7feOBs5lo14fPPJZO5W+6jU6JCpWf6PFTPjMk6IoI5HBaknp8jc9AhB12qtshrXJXMRSaDZ6N7G2T73x7NW42Bxi7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=kh2nLz95twvVCYBDI7MCI7vCmCXi8KzHi/Asj7FxHD8=; b=S6/o6M9l5a3W7m3l9jw3T4YRF5FgrlEL33LoRtwtTXh3nmsZljx9P1j6TIXf8Q84nH1mtG7fNrOCug7eaMoAk6cvD/cjcKtVkD9jr4fq/4HHeh/g1e2Ian1H4s0Jg8ioQLUaM5jINFXUN9rb0PpBhK8oSFIXOxdU1mC+Nk8+duUNFccVqm09zK2orMIOufECBGOR69mVhn82ouHsAHpv2qCp6Du4W6VG3OexCvO6omzCw0uZWGMu/6WnHljXtbeTkcrz5Gja0IVQEj4GOb2DRb3c+yydCOuAz5NwoM0rWULjD6mWSCLKoQcjuYJXkJQzduflzzTmP7KyYZ6eH3HC6g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 149.199.80.198) smtp.rcpttodomain=intel.com smtp.mailfrom=xilinx.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=xilinx.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xilinx.onmicrosoft.com; s=selector2-xilinx-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=kh2nLz95twvVCYBDI7MCI7vCmCXi8KzHi/Asj7FxHD8=; b=T3o6sUoRF5rGbwI2vAmDO057yTyL1JQXPZCQ5bZ1/cea4e7egEnQFbe141hUReRK0wcaeeBilEZXprmZsBRlF0QoiLFz7PAxXpSftk2mjDPHzzthAMOI8HrB8ERjIoz5z9/q1IQFIVcagzDD2vnRKk0Am9RpUj51MGbts2ioAQY= Received: from DS7PR03CA0287.namprd03.prod.outlook.com (2603:10b6:5:3ad::22) by DM6PR02MB4252.namprd02.prod.outlook.com (2603:10b6:5:a6::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5353.13; Tue, 21 Jun 2022 09:20:02 +0000 Received: from DM3NAM02FT049.eop-nam02.prod.protection.outlook.com (2603:10b6:5:3ad:cafe::d7) by DS7PR03CA0287.outlook.office365.com (2603:10b6:5:3ad::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5353.16 via Frontend Transport; Tue, 21 Jun 2022 09:20:02 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 149.199.80.198) smtp.mailfrom=xilinx.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=xilinx.com; Received-SPF: Pass (protection.outlook.com: domain of xilinx.com designates 149.199.80.198 as permitted sender) receiver=protection.outlook.com; client-ip=149.199.80.198; helo=xir-pvapexch01.xlnx.xilinx.com; pr=C Received: from xir-pvapexch01.xlnx.xilinx.com (149.199.80.198) by DM3NAM02FT049.mail.protection.outlook.com (10.13.5.68) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5353.14 via Frontend Transport; Tue, 21 Jun 2022 09:20:02 +0000 Received: from xir-pvapexch02.xlnx.xilinx.com (172.21.17.17) by xir-pvapexch01.xlnx.xilinx.com (172.21.17.15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.14; Tue, 21 Jun 2022 10:20:01 +0100 Received: from smtp.xilinx.com (172.21.105.198) by xir-pvapexch02.xlnx.xilinx.com (172.21.17.17) with Microsoft SMTP Server id 15.1.2176.14 via Frontend Transport; Tue, 21 Jun 2022 10:20:01 +0100 Envelope-to: ke1x.zhang@intel.com, stable@dpdk.org, xiaoyun.li@intel.com, aman.deep.singh@intel.com, yuying.zhang@intel.com, dev@dpdk.org Received: from [10.71.119.54] (port=51741) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1o3a3F-0002t0-0x; Tue, 21 Jun 2022 10:20:01 +0100 Message-ID: <6a8160b1-1b52-095e-f293-88290f489972@xilinx.com> Date: Tue, 21 Jun 2022 10:20:00 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.10.0 Subject: Re: [PATCH v2] app/testpmd: fix quit testpmd with vfs and pf Content-Language: en-US To: Ke Zhang CC: , , , , References: <20220322071833.199619-1-ke1x.zhang@intel.com> <20220621090325.184668-1-ke1x.zhang@intel.com> From: Ferruh Yigit In-Reply-To: <20220621090325.184668-1-ke1x.zhang@intel.com> Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 25b8fe7e-4920-4a4a-467c-08da536738b4 X-MS-TrafficTypeDiagnostic: DM6PR02MB4252:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: HDj4I69946IsVcHafXiVC/8XbKL7e8VChUBTcRhXAizV6chopv6qGmNwHNwM0Qw0Wgia9wABCuWuc5VzBW/NTpLNHdWNEsZGXQRIFJO1dpAHrs2y9ZHB/GkzQa/Hcvg1/u6b6bsdT2RsNjtGchOxIL2Qh25orSYopWQzAgT7TX0Uvz7cJfZw8CFzG23qaUPU392jinITmADXM9BLz1ckEQ6uri7DwJSR243aY6AdOGpaAJm8fGgwnJtNJysLgXH+V065EDUDfIGtH99DVZzTqoeggR8grPF19ph4tPXHuLeOwkyio07eFVkbxBf55K4hLDfVj9GEGcbqGadJK7iJPMCk3xFz/Wn4R6OVSGy22GWKXSvr4geLNtTBGn9PHMsLmjFQXjcIL58a7voYNcEYr/RfzfG/FnKqJRRb3DB3m+I28m7x7YiXVKBYU/ECzGyv2CmBVcEDu/aKSiUWsh+g0R8E83byvvBHjWf7nSfXIphMGOX3qJ+ePwSjDX0pFdJlV4Zj9/vQ4xMi/uuijF9f7Do/1iue9KDHUnan9eI4Z+A8RsZtkIbC5Tin9rPSia80cS1+q47x+quBzskMM362zvyPSQUoPSX/rSsxYYYHvL19tosI2uvDlPem36FRAc/VjoRM8VDRNKMtOjbLLLIc7u5NPSCgEH12uZzYjnhdaxPNqsiSEodauM/lusVBpk9r1Ek5MbEwr1jMpGr88IbgBdUlu4WA56w/vbiCgbG+SzrzBfOHkkB4lrC2ft4sS60EWf0ehj36I1xoEudaczb+KA== X-Forefront-Antispam-Report: CIP:149.199.80.198; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:xir-pvapexch01.xlnx.xilinx.com; PTR:unknown-80-198.xilinx.com; CAT:NONE; SFS:(13230016)(4636009)(136003)(396003)(346002)(376002)(39860400002)(36840700001)(46966006)(40470700004)(31696002)(40460700003)(82740400003)(44832011)(2906002)(53546011)(7636003)(5660300002)(36756003)(31686004)(356005)(9786002)(36860700001)(8936002)(26005)(2616005)(70586007)(82310400005)(41300700001)(83380400001)(4326008)(70206006)(186003)(40480700001)(316002)(336012)(47076005)(426003)(54906003)(8676002)(478600001)(6916009)(50156003)(43740500002); DIR:OUT; SFP:1101; X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Jun 2022 09:20:02.2234 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 25b8fe7e-4920-4a4a-467c-08da536738b4 X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c; Ip=[149.199.80.198]; Helo=[xir-pvapexch01.xlnx.xilinx.com] X-MS-Exchange-CrossTenant-AuthSource: DM3NAM02FT049.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR02MB4252 X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org On 6/21/2022 10:03 AM, Ke Zhang wrote: > 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; Hi Ke, These variables only used in the 'if' block, to reduce the scope of them can you please move them at the very top of the block: if (ports != NULL) { portid_t ethports[RTE_MAX_ETHPORTS]; int count = 0; int index; no_link_check = 1; ... > 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]); > } > } >