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 18197A0093; Fri, 17 Jun 2022 20:53:10 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id E57B540F19; Fri, 17 Jun 2022 20:53:09 +0200 (CEST) Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2067.outbound.protection.outlook.com [40.107.236.67]) by mails.dpdk.org (Postfix) with ESMTP id 21C1140E2D for ; Fri, 17 Jun 2022 20:53:08 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=a7uRMzD5m9pYn4q80VGa8hEh4dhf37ljxQgdQdNhgJrT9vNljpcYipIFSp3vV9KETAChPYHRAuwpGmX5EjqQXKLHEGmCR/UpDcp5s9T9NiKXK65i7yjYf15K/S1O54BXRldx+Z1kgvdE8yn5GcsFT6PbY7zi8g1C9DxlOBBxObDmkX3AITWAzvkqS/w38FPA7THZkupPz5Lv1eQGTOTT0Gg4o6BhEZZKlj9fxNCnEaqAXX90eM8rx07v4h5WTYaJF+dRASwtoNNXsTR34TuXzMAw7hOukj0sORyIRY95YiVbNFp1swFfQjvDL42MHhuPy7vVlwXyQac57BLC9WMcEg== 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=9BanbKjJ8t2cKBdnSTP8Nqog1FNY/zkdgLkDrv7OA20=; b=Y1hzMs1Ku9SEcnlTlYk8birh+KWlKYMQW4vSSusEqSpthNwneY9gX/50ppjcPNBLVNGXLwFAXDAJvNKt0X4d2ZkSRPncqexzz1ZFFaSNSX7pS67PhkPKfh1gFiDx0tAKcLE6wYeZUpGkD88chuQljSQBvflg/0/5HnRp9fw0RoCOytZV7krqA20XX/unjPFBoNq9R3WNl3xjZfc2H2/02o/87YGEuskNzkTms/7sMPVPg+V6XAw3/Dj+YYuqT55zeB+MiUQeAFX/bnEIoR+58+ERtzsym3Pea0FlIc3TgSocn8Rzqr0rQ/6M4/6KuViJynma+2gC+AH6hGzLeQ9CeQ== 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=9BanbKjJ8t2cKBdnSTP8Nqog1FNY/zkdgLkDrv7OA20=; b=sufGooqwiimFnu1IGKPukLGaP0EJtX/L41iZjKx4b9b1QqvvJjdmq7QNEqytXrK43uXD4ereqlJDcCmo7AveesBVawfBvvN3XOb47reLyMC23xjXCqDqtb35RBiF4yXNdfd2dGT/vvraHRCGuBKOqm0UwApDrMSqZPj81mfa8Gk= Received: from BN0PR10CA0001.namprd10.prod.outlook.com (2603:10b6:408:143::31) by CY5PR02MB8966.namprd02.prod.outlook.com (2603:10b6:930:39::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5332.13; Fri, 17 Jun 2022 18:53:06 +0000 Received: from BN1NAM02FT057.eop-nam02.prod.protection.outlook.com (2603:10b6:408:143:cafe::5b) by BN0PR10CA0001.outlook.office365.com (2603:10b6:408:143::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5353.16 via Frontend Transport; Fri, 17 Jun 2022 18:53:06 +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 BN1NAM02FT057.mail.protection.outlook.com (10.13.2.165) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5353.14 via Frontend Transport; Fri, 17 Jun 2022 18:53:06 +0000 Received: from xir-pvapexch01.xlnx.xilinx.com (172.21.17.15) 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; Fri, 17 Jun 2022 19:53:05 +0100 Received: from smtp.xilinx.com (172.21.105.198) by xir-pvapexch01.xlnx.xilinx.com (172.21.17.15) with Microsoft SMTP Server id 15.1.2176.14 via Frontend Transport; Fri, 17 Jun 2022 19:53:05 +0100 Envelope-to: aman.deep.singh@intel.com, ke1x.zhang@intel.com, xiaoyun.li@intel.com, yuying.zhang@intel.com, dev@dpdk.org Received: from [10.71.119.26] (port=52958) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1o2H5c-0002mQ-00; Fri, 17 Jun 2022 19:53:05 +0100 Message-ID: <64d0e2e9-6449-b961-3bff-1f422af706d7@xilinx.com> Date: Fri, 17 Jun 2022 19:53:03 +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] app/testpmd: fix quit testpmd with vfs and pf Content-Language: en-US To: "Singh, Aman Deep" , Ke Zhang , , , References: <20220322071833.199619-1-ke1x.zhang@intel.com> From: Ferruh Yigit In-Reply-To: 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: 0a62e301-8e61-4df4-8209-08da50929d83 X-MS-TrafficTypeDiagnostic: CY5PR02MB8966: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: h8UvTN7Sk4yXOWbHuLrRupvXKk3EX8jLzazPwsW/NWdvK5xIWVs6wpUIFzmJg1uPwqjGoN1G0PnPoHnQBIpJtoNnMKznFXwcjvLiuxyErN9Fd9A5eQZJa4zK+JDh+HdGLs3XEKJOJanhQoaZRbuifz4vBEx72JpcJd6kPxF9hbh27geAiqaEGJruNF7nS5oYjoCwSJOSAPeQ9akpt7chsBG8gH4iaNafLejAJuTlkwwnBS95Na/CTJNymAw9p6vmavgAc4rFdbUewWaup9sYvqUWhl8u8BTpENE2HxILPJuTiJrgepAMMU1R//mqABcDtc6jWVO1X25ZODGYEzUZGaY7U+CpryajpQhle+PZZy8Pp+df85pIgZyC8xXlQ7ld9t6Y8rUiOZK0twsHIYP9yfCyYCmJQM75CxQujowx8+SZdJH6Qpv437474K+yWmPKgXFo2lsC19HveS6him3PCLSHkiQk12K/arBuK++SzQzBELNJthCiPw3Uu77jFGMrjsWhN928zVsXFI+2HIgXRZ2IcOF6VpcBDmBHVrO9TtLAqCrTRaCy2T7kq1GPKxaPiwq0Sowolis8L635hNq0m0otmGRF2ZqY9Y85yhUTc6YJqMpuly/WsCqlMAbzhee3ehpX6EtGgiQaTt/i8KJQ29+SE4QsyvKxbn2A8Bw5IeJyq+RxkvZKPkeqmGh4OVPDIAq9B9V1eokfkR/CFBPUJPNT5sWqz6ZXi58xgmi827U= 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)(36840700001)(46966006)(40470700004)(336012)(40460700003)(70586007)(31686004)(498600001)(110136005)(36756003)(47076005)(44832011)(316002)(9786002)(2616005)(186003)(8936002)(36860700001)(426003)(31696002)(8676002)(26005)(83380400001)(356005)(82310400005)(2906002)(53546011)(7636003)(5660300002)(70206006)(50156003)(43740500002); DIR:OUT; SFP:1101; X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Jun 2022 18:53:06.2716 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0a62e301-8e61-4df4-8209-08da50929d83 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: BN1NAM02FT057.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR02MB8966 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 On 3/28/2022 11:06 AM, Singh, Aman Deep wrote: > > > On 3/22/2022 12:48 PM, 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. >> >> Signed-off-by: Ke Zhang >> --- > This fix looks similar to series: 21823. Please check Ferruh's comments > on it. > > There is a scenario, where this fix may not work. > "if there is an earlier port id which is released, after that new > vf is created taking that port id. In such case port id of vf < pf port id" > > This patch covers most of the cases and that way its an improvement. > So I am ok with it. > > Acked-by: Aman Singh Agree that patch covers most of the cases with simple/small change, so OK to continue with it. @Ke, can you please check minor comments below. >>   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]; testpmd holds port IDs as 'portid_t', so can you please change type form 'int' to 'portid_t'? >> +    unsigned int count = 0; For 'index' & 'count', no reason to make one 'unsigned int' and other 'int', better to keep type same for both, and both can be 'int'. >>       portid_t pt_id; >>       unsigned int i; >> +    int index; These new variables only used in one if block, can you please move declaring them to that scope, to the beginning of that block. >>       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++; Can use 'count' directly, instead of '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]); >>           } >>       } >