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 17B4444145 for ; Mon, 3 Jun 2024 12:49:36 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D3AE642E48; Mon, 3 Jun 2024 12:49:35 +0200 (CEST) Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam04on2087.outbound.protection.outlook.com [40.107.101.87]) by mails.dpdk.org (Postfix) with ESMTP id 563B642E17; Mon, 3 Jun 2024 12:49:33 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=T5gBaFjnpL33+J/lIta8DdiGlH8HhDDS/N5LqgQYFP7pS+t7apWonRKwgU5sGejnuIfQ88vbpwb41+ePIXddSAyh5r2vYMHwtg5HqX5Q7Nz/60CMfst1r/2RbzBl0VWUQ9RCzAe1cyKTyMDhToOSHswRwbirxxJslkZM5VMUD/XJM58TQhbQueOMcFqniUcPUozLDrLrWWMqGkjKgPresFjwUyxwIs7pXr2BILzH4U/1QUYnmDFNaDXzgENNYGwc2vZX9tZ9B+SWSuBFlWPcGfqkhl/DjQu7pSULB2Eb/Xn2R+afurVuC9RPhKMBG7X6YBjz0isGgtLwHr44Z3njJw== 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=rPVwHrQF8w79x1X5ZzgeQ8NxYirUCMrPtPmfxDSHdyM=; b=LTDz5zmG4LqUnTu/mpVJHucH6ofPLvjOWq4oqrNmEVlSxPCCLR1TVDKT8fWzWhrq+g7ofsnpW3+ys+61R4dxjRSXCHzxbT3HCY9ZSNBC09ol5a9gSaF8/89M8Jcl5dzeWwTWoB39ZThC5tO1HcNdmot4yIYbmocKzk3i9J0gwDkDDp4znut3FW9bLjEDfIXYnpiMeJCALtl3P1KMJBfIajPrbqWeF5LEd2aUqndEVQW6oZXL4722/rL6VcYjY6GT47w91p8jfXTCTQGfLeQt43sgn0xHnAgo300MWBXt7/IJF3il4X38pyZBO7PbPNNaE7yTrFgIHvpxoNhHhK9qwg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) 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=rPVwHrQF8w79x1X5ZzgeQ8NxYirUCMrPtPmfxDSHdyM=; b=FfrDyOPnjL1KqImOXuWg6bXXWbyekReQqMoy2Lvru0I+42cDBl1/HfkPugLbZaNee1R4kjIZbFk9qQzCj16tZgLyXIXG3cvfVcdxB6TXzpInyr+OSNYYD9c0naqngDKImgznEwnoVSnPruH8eU7w05eyjR3MVDsEkrynYhODR5Xctg4G/nERbj3oBEAYrIHvNpBaAowiAuWc3wAf9bjytbL82OIyFIDSisnWNxO5hPHuwlTp77XLqnbm2Rz1UTC29bQN9tDFcEYOUI0+v4udaJU8+D3PqpQGfyol0c2ESr1T7o2T1xBsB0AuB3ZcWtX89hNlEGzrWPxhvKT8PMhX5A== Received: from SA9PR13CA0084.namprd13.prod.outlook.com (2603:10b6:806:23::29) by MN2PR12MB4256.namprd12.prod.outlook.com (2603:10b6:208:1d2::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.27; Mon, 3 Jun 2024 10:49:30 +0000 Received: from SN1PEPF000397AF.namprd05.prod.outlook.com (2603:10b6:806:23:cafe::62) by SA9PR13CA0084.outlook.office365.com (2603:10b6:806:23::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7656.14 via Frontend Transport; Mon, 3 Jun 2024 10:49:30 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) 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.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by SN1PEPF000397AF.mail.protection.outlook.com (10.167.248.53) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.15 via Frontend Transport; Mon, 3 Jun 2024 10:49:30 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Mon, 3 Jun 2024 03:49:20 -0700 Received: from rnnvmail203.nvidia.com (10.129.68.9) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Mon, 3 Jun 2024 03:49:19 -0700 Received: from nvidia.com (10.127.8.14) by mail.nvidia.com (10.129.68.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4 via Frontend Transport; Mon, 3 Jun 2024 03:49:17 -0700 From: Maayan Kashani To: CC: , , , , Viacheslav Ovsiienko , Ori Kam , Suanming Mou , Matan Azrad Subject: [PATCH v3 06/11] net/mlx5: fix segfault on counter pool destroy Date: Mon, 3 Jun 2024 13:48:45 +0300 Message-ID: <20240603104850.9935-6-mkashani@nvidia.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20240603104850.9935-1-mkashani@nvidia.com> References: <20240602102802.196920-1-mkashani@nvidia.com> <20240603104850.9935-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: SN1PEPF000397AF:EE_|MN2PR12MB4256:EE_ X-MS-Office365-Filtering-Correlation-Id: 8baf8f9a-7066-4432-1c3b-08dc83bad8b4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230031|82310400017|376005|1800799015|36860700004; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?RCAhjLkYdYn1kyWrysFyCASBjJfl6OqLGWnuojb3vItESALYbSo68NPfcb6j?= =?us-ascii?Q?wAOd340o9euQWlTK3yTZmWMmedR/OwKH0PVZ9w51XGoHcrL/+1Ms+KAuEkBp?= =?us-ascii?Q?XjLzGfczurkKp/Kl/y3W/RYplf9t1/jRXJjMOD4BjvjtewE8TiGUjpYpmf1i?= =?us-ascii?Q?kuV8p+/A5/TAo2Z155dav8H2yud8bPFoI/zN5r68CeqsYoykkmsm0WeDa7u9?= =?us-ascii?Q?roDGV84HV6IBXnO4kWyO+Mcw8yIcIZOGeW1H5MgpHvpAI/5mRqEmUNIMDqem?= =?us-ascii?Q?782Y+8dA/07IykiGScyG/y3tRcUwz2JeL3LHwNriAd9Wy8PMMg+O4wkEtrNj?= =?us-ascii?Q?1rHX/0/JgHgJ+93MYRSawGKa5kSO5zKR3re7xQ7wIxTZ2NOtRHtquq2mHuV4?= =?us-ascii?Q?jJW5TyUFingwal7dnR1E9b4MNp6PGDKR6MFfIl8wlmB2KL9PEh3E7AIU/xtv?= =?us-ascii?Q?uwPipb5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qu/S0IB?= =?us-ascii?Q?ReAJtBuzimCD5d6hdUViuX1RPqyM?= X-Forefront-Antispam-Report: CIP:216.228.117.160; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:dc6edge1.nvidia.com; CAT:NONE; SFS:(13230031)(82310400017)(376005)(1800799015)(36860700004); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Jun 2024 10:49:30.1199 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8baf8f9a-7066-4432-1c3b-08dc83bad8b4 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.117.160]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: SN1PEPF000397AF.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4256 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 --- 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 36d422bdfa..a46a4bd94e 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.25.1