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 C8CAB41F51 for ; Sun, 9 Jun 2024 13:01:45 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id B71F140E18; Sun, 9 Jun 2024 13:01:45 +0200 (CEST) Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2056.outbound.protection.outlook.com [40.107.93.56]) by mails.dpdk.org (Postfix) with ESMTP id 95B9C40BA2; Sun, 9 Jun 2024 13:01:41 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Z+wO8N/rG9wcIioPb/Gl1aMhB7qHky16eQy92C8fHk9pyd8/1l26a8BPvEFK16aCLPq7bm2+D2S3fYv7+/QhW/Ku8M237gLFUzrVwcUuft9WZsX/vgY795MSGWxAVZz0mJGl8VZsMjwZZwqtZDQTk6hRU4B5Kgr8qx6ED9/UbH2Bgv7JbhGfWySTRNzcPH/SRAAnglqKbOCZu5pt170aoOMjdNCkDJ540LZ51ivCnxR3WK28m7egagF4q0HECU398rUHZNQW/5a0VJx+5RB8ACIgQmurhNCJZCqXd2VwgTyGxA6ZGHtsQOT+fIIVBEwOf7uogQeHZG+M4M5J5eC/jQ== 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=ee6+0hd/uRqqDtD4N+pg/HXX0BNKiHfNuZARlbZHepc=; b=LoDNeyQdKedg//RrfZdEiE1OR+r9ONnHze3wukuqduKNMjJJtjM3Mb/BnJEX0gWuUqSTcWZm7UaTt1szJzvXpl+h6vKedzOEgKSOwW2aulMckVx5ey+76niMKX27tW+M0KxsNymf2fDUV/RapAZUvAltR3RVNorf/sHxO5wb1gyAVfAN+e0csu+M1NMEo1oQ/MRXWGt0DawntbD0hUqcVuwORfeMAwYqv/oNhdaF2cZ50AzKXctiNvQXu1+EiwjXF2WT1tdIYd6hJkN4QtWWwQAcOpKUiedIcCcoDYXhPUtstP1uJscYGPucoc9ogDqrnrmBdvM6FkjueBwOeItjdw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.232) smtp.rcpttodomain=dpdk.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ee6+0hd/uRqqDtD4N+pg/HXX0BNKiHfNuZARlbZHepc=; b=HdsV0N0Ei55p8hhQS34KOXToBQX6fq5d4V/sx8kxnqsu3BVorR0MxxV3HkZNARjQyWT3Z8op/7CV/7gkBPKu+AYMjhBtLSrDnrVeG3e/2BSt4I/AihLeckLu7WxYI9CW8oPsra+5FJc6/sVGshafAfof4HMONN7FXJLV1bz3zPp7N9SsGjZ8FdZ0TmHQ1CJZsSxp5SSXoLODX4jA+QmasiPBqMDXdJ+q3PmxLaGL3m49ceThTt/VZ5LUxN7Wb/181QaBXBStEm9QvVjk1BEoFKciKYhTG3HUcVrKFzmRJGNt4x1GdFh5NyDDbCHPtLb1cFtqcGbkvyLtTCbuBLh11g== Received: from BYAPR03CA0017.namprd03.prod.outlook.com (2603:10b6:a02:a8::30) by IA0PR12MB8256.namprd12.prod.outlook.com (2603:10b6:208:407::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.36; Sun, 9 Jun 2024 11:01:39 +0000 Received: from SJ1PEPF00002315.namprd03.prod.outlook.com (2603:10b6:a02:a8:cafe::f1) by BYAPR03CA0017.outlook.office365.com (2603:10b6:a02:a8::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7656.24 via Frontend Transport; Sun, 9 Jun 2024 11:01:38 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.118.232) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.118.232 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.118.232; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.118.232) by SJ1PEPF00002315.mail.protection.outlook.com (10.167.242.169) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7677.15 via Frontend Transport; Sun, 9 Jun 2024 11:01:38 +0000 Received: from drhqmail202.nvidia.com (10.126.190.181) by mail.nvidia.com (10.127.129.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Sun, 9 Jun 2024 04:01:33 -0700 Received: from drhqmail201.nvidia.com (10.126.190.180) by drhqmail202.nvidia.com (10.126.190.181) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Sun, 9 Jun 2024 04:01:32 -0700 Received: from nvidia.com (10.127.8.14) by mail.nvidia.com (10.126.190.180) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4 via Frontend Transport; Sun, 9 Jun 2024 04:01:30 -0700 From: Maayan Kashani To: CC: , , , , Viacheslav Ovsiienko , Ori Kam , Suanming Mou , Matan Azrad Subject: [PATCH v7 06/11] net/mlx5: fix segfault on counter pool destroy Date: Sun, 9 Jun 2024 14:01:02 +0300 Message-ID: <20240609110107.92009-6-mkashani@nvidia.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20240609110107.92009-1-mkashani@nvidia.com> References: <20240609085600.87274-1-mkashani@nvidia.com> <20240609110107.92009-1-mkashani@nvidia.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ1PEPF00002315:EE_|IA0PR12MB8256:EE_ X-MS-Office365-Filtering-Correlation-Id: d649429d-5baf-4b76-4023-08dc88738913 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230031|82310400017|1800799015|36860700004|376005; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?lGTJHOcqzRdBcwTZ8ED0msIPGIJt4m2O3+2yslFt5gFvbKz2Nzz8Ddl1A9es?= =?us-ascii?Q?nFKDGy3DQnKfmT1PRAiS6qdea3xErPIxvcpQHWBxM1MoE9a72mwcnFJpaApD?= =?us-ascii?Q?3PiPSxOiejv9D+vgy3b2P2LNPxdOCSKS4SOSNYyyYTg4Y7acq02fGqMHpHn6?= =?us-ascii?Q?dIYR88u4XVhU82NDw89p5rxdxJsyK/Z8njMSc+nxMx/k2a503RLFK4xwKkon?= =?us-ascii?Q?DVye7RVKu48BOOFQS3qQeKWm+4EwkkJTOUVvJnC8Nj9FV8ghj5gecYHsUsnS?= =?us-ascii?Q?FA5Scvxo8E9moMC9CgdV8UMx4cxLZ+8g5mXHdKtwFINFL2dxdXPVWsCU0dW0?= =?us-ascii?Q?ntLkkj/xUJ//rAnCA94yPX1RXm+VkdbqzUCDpxkfr7ySyq12XF2fGddfuXTk?= =?us-ascii?Q?XhtnKL4F6CfYiaA7lMWykW7J5t1scxXBLtkyiL/b2M9gXGttJJcF0OyiUkya?= =?us-ascii?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acYOpHUMntYR/lM1JiVFYP6HjUFa2c1eclWUL?= =?us-ascii?Q?r0KAxsRoHvsIGCFHNUYu5tICJM2vhr4wwHrjB2IGIpOjHL75pw=3D=3D?= X-Forefront-Antispam-Report: CIP:216.228.118.232; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:dc7edge1.nvidia.com; CAT:NONE; SFS:(13230031)(82310400017)(1800799015)(36860700004)(376005); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Jun 2024 11:01:38.1968 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d649429d-5baf-4b76-4023-08dc88738913 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.118.232]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: SJ1PEPF00002315.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB8256 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 If the counter pool was not added to list, and an error state was reached, on attempt to destroy the counter pool, segmentation fault was received during list remove action. Added a check to verify the list is not empty before trying to remove the cpool from the list. Invalid state, leading to segfault, can also be reached in the following scenario: 1. mlx5_hws_cnt_pool_init() does a zmalloc and initializes most of the fields of cpool, but does not initialize the next field. 2. mlx5_hws_cnt_pool_dcs_alloc() attempts to bulk allocate flow counters. If this fails, we skip straight to 4. In HW, this can fail simply if FW doesn't support bulk flow counter allocation. 3. Right before the goto error, we insert the cpool to the hws_cpool_list. This is where the next field is initialized. 4. mlx5_hws_cnt_pool_destroy() assumes the cpool's next field is initialized and SEGVs if not. So, added a guard against cases where the entry was uninitialized (checking le_prev field is not NULL). Fixes: 6ac2104ac125 ("net/mlx5: fix counter query during port close") Cc: stable@dpdk.org Signed-off-by: Maayan Kashani Acked-by: Dariusz Sosnowski --- drivers/net/mlx5/mlx5_hws_cnt.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/net/mlx5/mlx5_hws_cnt.c b/drivers/net/mlx5/mlx5_hws_cnt.c index 36d422bdfa5..a46a4bd94e8 100644 --- a/drivers/net/mlx5/mlx5_hws_cnt.c +++ b/drivers/net/mlx5/mlx5_hws_cnt.c @@ -718,7 +718,9 @@ mlx5_hws_cnt_pool_destroy(struct mlx5_dev_ctx_shared *sh, * Maybe blocked for at most 200ms here. */ rte_spinlock_lock(&sh->cpool_lock); - LIST_REMOVE(cpool, next); + /* Try to remove cpool before it was added to list caused segfault. */ + if (!LIST_EMPTY(&sh->hws_cpool_list) && cpool->next.le_prev) + LIST_REMOVE(cpool, next); rte_spinlock_unlock(&sh->cpool_lock); if (cpool->cfg.host_cpool == NULL) { if (--sh->cnt_svc->refcnt == 0) -- 2.21.0