From patchwork Mon Apr 22 15:25:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 13638625 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM02-DM3-obe.outbound.protection.outlook.com (mail-dm3nam02on2056.outbound.protection.outlook.com [40.107.95.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 02CB315350C for ; Mon, 22 Apr 2024 15:29:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.95.56 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713799754; cv=fail; b=GHYLF6HKSOyeTehpZA+hj8sNfswYYaHrc+POuT5dYDUgym0tSv1E+W4d+wMAzPPj4C0JAF4XDHhtZgW6qKnqd2+2x2p+2NKtO04lO1k+gZoh6WOfm8Zdtk2IoIeowcFpKzNPghT0P9z1tkrSnHEFPkRSjQhhwwjZq7wkteUtBr8= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713799754; c=relaxed/simple; bh=a4S4Ri0swmwO2O4rKAuTXHYYewl/nlZ3DTU3KE7ni0w=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=hCc6OzifYI6IrnIwx2rwyfrDro0mxDdDMkiqD31shGxyaod4mcxbmwtd0PwZ3FwKAzcnI7G+H+K9KRe8X4NhanJ7zrHJowfHxCpVMiDkYf6ksnSU2ijkkbSfEMsHeThZ3i7Q1vccRZ6kadWtABJA9Csl8yRhipWfOjputfuN6ng= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=mSbwq1gl; arc=fail smtp.client-ip=40.107.95.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="mSbwq1gl" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZoDRN42jUGyKBw8uAfeJk9/89ky0779D/gDqiHzOD+nShQFEmXlwWHRTwPn54aRNFZK9Lt6RFqJy5Vw5ZaZmEekC9AEJfIc4iDPVYqnB2w69Nw3LFr9WiZvTxGx1uNVFIFOvHh7LnBCBb9g+IjbIZL9x1zrgjqkdcJdGr+nftzCqrpNTcwAdd7M23Zn+hlzTjt3Plx5A4qg+m14BzzMuqBY5SSCKpNI5ZkmdaKk/psuoKmtrqh9Abwc75zw5guRKFQvYYKlksxytNGCZtyRzB/dsml3Yf1u/z2r2V6pjJPT7wkHxRKLduPvNADB9xi5A63WaiLBN+xicIaDFaQ0nLQ== 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=BSrp069sawwfwVnbgBJlTWQHFARtI0rPuo7xKXhOrjU=; b=i1WuS9BKfPWF12nSozKZxiDoiz5IT0KoS4FgQOpGZxFtvd3iAjp4c5YRKKJuFV7fhowm3Ga9T0+LVW+/j1DnspQt2LIQDU+wkDCia6V5GiRLpzics2aWcOQLnptANW0jF7x+tUDlHWTBOQAFH69aTHNpSbmQhSSQjwh7p4oDFXMOy3UIZD/9Fxqqrba1EAgrYbjMxv+530bY/mSwVyr6aBHrcJdUxOsRSGajOzplqeuquzD6hcJC83OzsX8HelSokk4kAWgHvPPA9zzOHqhysUgnLCQv2CqNlod0bmrMtYInoJc+eDJbXu1DPmlHBd5se8zDbVeM67sVGgy8pGtsHQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=davemloft.net 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=BSrp069sawwfwVnbgBJlTWQHFARtI0rPuo7xKXhOrjU=; b=mSbwq1gl/Eoel2nGbLh2teEiUX5tl4xbpXcHiQOGXCgZDW6gRMiPojunigNMlYaxsYhLofoF+zehV9b5nyjRRObWOtEcRkrmmcdeH8DWQ3tHTasN7nsr3MDvWgYS61Mrqwf+QFOwzPyRLfS1RBa5TQh4zgPMDjsQvlpxV6KNZRrYF10ja0I0givu9wI+poqDP6BHJ706t9w17AuYQVwIN7+2PgXXwjCzijtbSOgSy1MyacIYbfwSlOzgxZzsL07cRI92U+kuaTOlUr6PwV2jQtJMgthZ35S4lFymGTJRGjTwVVRgBNtrqsMI5Dw/BHrVDssSNyydEc9MzbcwGqMjFA== Received: from BN0PR03CA0046.namprd03.prod.outlook.com (2603:10b6:408:e7::21) by MW3PR12MB4380.namprd12.prod.outlook.com (2603:10b6:303:5a::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7472.44; Mon, 22 Apr 2024 15:29:09 +0000 Received: from BN1PEPF0000468B.namprd05.prod.outlook.com (2603:10b6:408:e7:cafe::c7) by BN0PR03CA0046.outlook.office365.com (2603:10b6:408:e7::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7495.34 via Frontend Transport; Mon, 22 Apr 2024 15:29:09 +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 BN1PEPF0000468B.mail.protection.outlook.com (10.167.243.136) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.19 via Frontend Transport; Mon, 22 Apr 2024 15:29:08 +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, 22 Apr 2024 08:28:50 -0700 Received: from localhost.localdomain (10.126.231.35) 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, 22 Apr 2024 08:28:46 -0700 From: Petr Machata To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , CC: Ido Schimmel , Jiri Pirko , "Petr Machata" , Alexander Zubkov , , Amit Cohen Subject: [PATCH net 1/9] mlxsw: spectrum_acl_tcam: Fix race in region ID allocation Date: Mon, 22 Apr 2024 17:25:54 +0200 Message-ID: X-Mailer: git-send-email 2.44.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail202.nvidia.com (10.129.68.7) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN1PEPF0000468B:EE_|MW3PR12MB4380:EE_ X-MS-Office365-Filtering-Correlation-Id: da6e7469-101b-494e-7326-08dc62e0f45f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Tu3FrgDxpqC2SuJPuxTWqa/um7hbKKd9IxclkxUEFRwe2sPh/cdyaXL0mk72/TM5uoUHScbF8xeccaaEb7DcBPrvORlA8e4aEawWwj/TDvxMBzmiCodJarI/7PAn4lNjV3awviSjQ53+Xza/EkoD/xx5ZkeAx0a9CvFI+3EmeR2kKf60M4JTQWDHQ+vA52FlVChjFEYeNvq0W38M0i9351jzQjvpopJNNn8LmwPfejETb8Tez9xH7l8PoHty0ksQL/lAR1j3RL0TBFkAem0vI4J/fs7wJ/yZHrjsVJM0msr4NciL5cOU2KTl9W7eG7EZqZ9q3+IR7Uki78564M2hAtwNtC6YTcW8OJIslMd31SSEmkWE7eyfuBgXTeUyf/Q6aGO+iDPE/nMozzfiFJqVzS7K6wgfyA7g4WadiqmUzrhGSwSRQHtdw56pXcsemOsOEKlZC4krG+8bVwswQh7HFZwiMZI8FeNeKrA0puNODgewiayT7IewKfTWDh8IbmCnrr7AvFkeIUdlquXnuwu/wWADcaAttuYMxW3JneZGgyEl2R0CBiQI8UkvRW3B3sYhw30+urODpDCfS1TPO0oj/BCszFvCHRoGJ5JcIhP1mHCKhKaO5kQkXvCrd9GF3qm7uZkf1BR+i4sFUUYHXkyJaSqRYv3R7NX8n0UQqtpikKYDGXzisbumzp1HxlZbgFR+AlkMvJki6RUwKQdndscuBTwVjYUouKygDvsOX9QQo9aRplUkYWuaU4SM/xooQU/1hJSKO3usiVmnnSzK2m2xFimkQfxOHLSnbXGBsUlsSuVNussHY5T70j3Sm5qhCDhKFk94CfZJcemarHa/HVCy5RsPAONSzhnUjo+ghIjj8DKcxg+sTodH1Nzz/9SaUOCWcuvFQAq8bq5BDPGXKLF3wzTedlCf95tCsmbo8/SnVjVXb0EJR5oSiupW2s73nJh8XRXe4p769jlq/czVKueT1S0s7UQ6veGNfnqjsGE7Jtqjaq5RlOa6N5n87ogh4DcPYhwMAjSddJFYor7tBjZK2whpy45DIrUoxBFyQZsWvAb/264hwMZ3vw87WftDXXdbuuttdOfFBTl9Svu6SApXc6JePTjoE3Dt+CUo4e2Y3qEgfTv5c/o5Jx+31Oe/npE7J065B2ELEKLqwp7YZcx/X+OyqwGYY299Lvk/K/blKBSlWy0+EwhJiWBUiTbh8USNQTxD1YxbKnF6SX+HvaBK6QZOEwLL3Hds2lRi23tRZs7rdq1q6/ALGzLelNfrUAZO0Lv1lZvpKCaoIS6+wOyBbioFQoZO9z7uIJdQQEFRAleB2ny5rivxGmBJoIzcp1Z06ZbVNtfN8nj7ymyMD1CmdvkXwZoK6Jc0B9qZW4m6AWTHM4yqvB1unIiDf7ah7eRY 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)(82310400014)(376005)(36860700004)(1800799015);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Apr 2024 15:29:08.9828 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: da6e7469-101b-494e-7326-08dc62e0f45f 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: BN1PEPF0000468B.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW3PR12MB4380 X-Patchwork-Delegate: kuba@kernel.org From: Ido Schimmel Region identifiers can be allocated both when user space tries to insert a new tc filter and when filters are migrated from one region to another as part of the rehash delayed work. There is no lock protecting the bitmap from which these identifiers are allocated from, which is racy and leads to bad parameter errors from the device's firmware. Fix by converting the bitmap to IDA which handles its own locking. For consistency, do the same for the group identifiers that are part of the same structure. Fixes: 2bffc5322fd8 ("mlxsw: spectrum_acl: Don't take mutex in mlxsw_sp_acl_tcam_vregion_rehash_work()") Reported-by: Amit Cohen Signed-off-by: Ido Schimmel Tested-by: Alexander Zubkov Reviewed-by: Petr Machata Signed-off-by: Petr Machata Reviewed-by: Simon Horman --- .../mellanox/mlxsw/spectrum_acl_tcam.c | 61 ++++++++----------- .../mellanox/mlxsw/spectrum_acl_tcam.h | 5 +- 2 files changed, 30 insertions(+), 36 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_tcam.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_tcam.c index f20052776b3f..b6a4652a6475 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_tcam.c +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_tcam.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -58,41 +59,43 @@ int mlxsw_sp_acl_tcam_priority_get(struct mlxsw_sp *mlxsw_sp, static int mlxsw_sp_acl_tcam_region_id_get(struct mlxsw_sp_acl_tcam *tcam, u16 *p_id) { - u16 id; + int id; - id = find_first_zero_bit(tcam->used_regions, tcam->max_regions); - if (id < tcam->max_regions) { - __set_bit(id, tcam->used_regions); - *p_id = id; - return 0; - } - return -ENOBUFS; + id = ida_alloc_max(&tcam->used_regions, tcam->max_regions - 1, + GFP_KERNEL); + if (id < 0) + return id; + + *p_id = id; + + return 0; } static void mlxsw_sp_acl_tcam_region_id_put(struct mlxsw_sp_acl_tcam *tcam, u16 id) { - __clear_bit(id, tcam->used_regions); + ida_free(&tcam->used_regions, id); } static int mlxsw_sp_acl_tcam_group_id_get(struct mlxsw_sp_acl_tcam *tcam, u16 *p_id) { - u16 id; + int id; - id = find_first_zero_bit(tcam->used_groups, tcam->max_groups); - if (id < tcam->max_groups) { - __set_bit(id, tcam->used_groups); - *p_id = id; - return 0; - } - return -ENOBUFS; + id = ida_alloc_max(&tcam->used_groups, tcam->max_groups - 1, + GFP_KERNEL); + if (id < 0) + return id; + + *p_id = id; + + return 0; } static void mlxsw_sp_acl_tcam_group_id_put(struct mlxsw_sp_acl_tcam *tcam, u16 id) { - __clear_bit(id, tcam->used_groups); + ida_free(&tcam->used_groups, id); } struct mlxsw_sp_acl_tcam_pattern { @@ -1549,19 +1552,11 @@ int mlxsw_sp_acl_tcam_init(struct mlxsw_sp *mlxsw_sp, if (max_tcam_regions < max_regions) max_regions = max_tcam_regions; - tcam->used_regions = bitmap_zalloc(max_regions, GFP_KERNEL); - if (!tcam->used_regions) { - err = -ENOMEM; - goto err_alloc_used_regions; - } + ida_init(&tcam->used_regions); tcam->max_regions = max_regions; max_groups = MLXSW_CORE_RES_GET(mlxsw_sp->core, ACL_MAX_GROUPS); - tcam->used_groups = bitmap_zalloc(max_groups, GFP_KERNEL); - if (!tcam->used_groups) { - err = -ENOMEM; - goto err_alloc_used_groups; - } + ida_init(&tcam->used_groups); tcam->max_groups = max_groups; tcam->max_group_size = MLXSW_CORE_RES_GET(mlxsw_sp->core, ACL_MAX_GROUP_SIZE); @@ -1575,10 +1570,8 @@ int mlxsw_sp_acl_tcam_init(struct mlxsw_sp *mlxsw_sp, return 0; err_tcam_init: - bitmap_free(tcam->used_groups); -err_alloc_used_groups: - bitmap_free(tcam->used_regions); -err_alloc_used_regions: + ida_destroy(&tcam->used_groups); + ida_destroy(&tcam->used_regions); mlxsw_sp_acl_tcam_rehash_params_unregister(mlxsw_sp); err_rehash_params_register: mutex_destroy(&tcam->lock); @@ -1591,8 +1584,8 @@ void mlxsw_sp_acl_tcam_fini(struct mlxsw_sp *mlxsw_sp, const struct mlxsw_sp_acl_tcam_ops *ops = mlxsw_sp->acl_tcam_ops; ops->fini(mlxsw_sp, tcam->priv); - bitmap_free(tcam->used_groups); - bitmap_free(tcam->used_regions); + ida_destroy(&tcam->used_groups); + ida_destroy(&tcam->used_regions); mlxsw_sp_acl_tcam_rehash_params_unregister(mlxsw_sp); mutex_destroy(&tcam->lock); } diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_tcam.h b/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_tcam.h index 462bf448497d..79a1d8606512 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_tcam.h +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_tcam.h @@ -6,15 +6,16 @@ #include #include +#include #include "reg.h" #include "spectrum.h" #include "core_acl_flex_keys.h" struct mlxsw_sp_acl_tcam { - unsigned long *used_regions; /* bit array */ + struct ida used_regions; unsigned int max_regions; - unsigned long *used_groups; /* bit array */ + struct ida used_groups; unsigned int max_groups; unsigned int max_group_size; struct mutex lock; /* guards vregion list */ From patchwork Mon Apr 22 15:25:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 13638626 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2055.outbound.protection.outlook.com [40.107.93.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 152F91534F4 for ; Mon, 22 Apr 2024 15:29:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.93.55 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713799757; cv=fail; b=A80QrfXSzHemtdmeCBEHQargnXFiNQSs/+2UZPa3nVlVCmUH09scy2YKaCY7nUZK5QKWIq2U2fbeOrX+fMAOWwru7y0jVp/xYw978sr9kyXu6FCLlHFCX+P8LroS/VDzrypnDx5Hlw7Q0uSdh0i/eT3b3bLMKYKLfiJTsdAdoWw= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713799757; c=relaxed/simple; bh=zjmDg7kQ95x+wvWuB+2TCy4i/6gAUTWSOYtvhLoWiXk=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Rxgf3CXncxnnSz+CR8fsYug1vB2K/JepLqlAzgt8QAoY4y4Pwf/ZICq730HiD19Vknscgy2hN7NPVdBhzeopqtKjyRwPl+6zsY5dOX9iN17/MJtO3LKr0QfYKYzPOGilfKpHmDmf7SPDWU4clqDUSLcsbB9R+jwBU5FYyD55VGk= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=kn9HjQRd; arc=fail smtp.client-ip=40.107.93.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="kn9HjQRd" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bBFoz1QPGkHAba4SLRReKwtYdUCTzAQFMLi0Ta1VHf1rHJiVQqp9T99NbS+TgLoEPzTNJmagbB4WARzlBl21zFo2zDhpCgXapXJd9Uuu+SWxQaKYqrznMVILKCA8tjqinyviylMbVXY+I6/r/Nfqn2vhPI133kLC8eBVp2eOEwrE8HV5YLAJ2/37qRmn76RvEpNHMQHsiH8ceaAKxnfbtyyhUkuXUnBhj2YsTmlaN1ar6kYnimFbfq6rmjjQiMXwgAaAyR0mdXiqx0AizOvTv9CIs5+O7JA3YEkeEFus1hJedVra3bOzfQLJaFyNXSR/hnENBkma+iUPsbldyU5nRw== 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=QNT04N5LC1Hh67iscuF1FoHCvNFzSTFAdHmYzlGRBAE=; b=N62owu4mngnoT4jqFhg0FCrbVfpMtsElWEmQm8M8ML3ViKuP8jlq4mt34ePkqxJBlS1YaGvoE8ZYpC9IWfAzj8LP50WgzuQtTKMsWmEn29fg/MrdVTBcKw7p1ce6aHrAH7YbduUp/vi1F1h012Q4gIVGKhCTtD63wPM+qksketuJ58Y0sFilXqm5FuS5a7opIlxKhpzOyRzy53n/56jc9fYyVwTJ6MPVJo8VhBXMTaEUj9Omk+hsscOuEED+w96dngQyBW0PD2Iap38MLNMEJBsn/n8EwD+u8FfGg+f4p9FviixHo6trcwisVkUlOZVW/5RcX975P4VjH55SEoVTLg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=davemloft.net 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=QNT04N5LC1Hh67iscuF1FoHCvNFzSTFAdHmYzlGRBAE=; b=kn9HjQRdRukZe5kHivVV1bykjaXCAbeC7BIcy73luZqwdBhkTJMXKNARkykDEhu8EiN8JzExW+OVm6WElkdfaJhfSzau/RHvwO4OPtjyHCbaZlgiSvz1znbCkkouhi0s3oU1pUmQq77Igh+Sh/10a/RDhyR/mDu9SkZJWdNmAJV8df3v+pcxhpsPxEv1QyV9xlxffG11qKwMNPGm7kouxrRYv+TYiIUWK/hvCB9G8qOcRR+8ugO4SyT8SqDxwIbim2TJ2UfsJyddGeIIty2UX+bWYi9I4VCfO4svsbjTUUyorQDq3W3JkE5e7s/f3OYGFMO+yvWmDtrT48Po8HnLjw== Received: from BN0PR03CA0049.namprd03.prod.outlook.com (2603:10b6:408:e7::24) by DM4PR12MB7672.namprd12.prod.outlook.com (2603:10b6:8:103::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7472.44; Mon, 22 Apr 2024 15:29:13 +0000 Received: from BN1PEPF0000468B.namprd05.prod.outlook.com (2603:10b6:408:e7:cafe::dd) by BN0PR03CA0049.outlook.office365.com (2603:10b6:408:e7::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7495.34 via Frontend Transport; Mon, 22 Apr 2024 15:29:13 +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 BN1PEPF0000468B.mail.protection.outlook.com (10.167.243.136) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.19 via Frontend Transport; Mon, 22 Apr 2024 15:29:12 +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, 22 Apr 2024 08:28:55 -0700 Received: from localhost.localdomain (10.126.231.35) 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, 22 Apr 2024 08:28:51 -0700 From: Petr Machata To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , CC: Ido Schimmel , Jiri Pirko , "Petr Machata" , Alexander Zubkov , Subject: [PATCH net 2/9] mlxsw: spectrum_acl_tcam: Fix race during rehash delayed work Date: Mon, 22 Apr 2024 17:25:55 +0200 Message-ID: <1ec1d54edf2bad0a369e6b4fa030aba64e1f124b.1713797103.git.petrm@nvidia.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail202.nvidia.com (10.129.68.7) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN1PEPF0000468B:EE_|DM4PR12MB7672:EE_ X-MS-Office365-Filtering-Correlation-Id: b2b20f75-da54-4e38-6bf7-08dc62e0f6bf X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: uJzGfVS8GSpRDc45RTJb551SE6Qk1/sc5LPrdZnUD9iDtl0DWG94i1B9/3le9kGCP0IwSuXlegg3imD7mWlWgdthYQQA4nTiauakHbPHj3lsnOOgge3X88rgOno8DcRnNMm5ov+Mhrj2lEE5bBQXABEHwUVyX7qvGR6iEvVlVBZBSXT4gUiXTz1NKeVq5KIJBr3xsiLlndMNyBq1PDBGKkP3Dlmdn/JwBdPs1quGLP8fZmSs1A34QcV0+EIcztWaQ3wCkpkR1h1mwtSnTgKaGfWPubq18PVhdfqmc8L+s1XKY+eLilXkcfz/tPzUxi4+Ue8HiE6299H5Fxpfd2Ug5Qtsmby6lhydSkeR2gG5jV6ndwQHrpuQl5a5lslT/+CgJjtwOMnCaW8iT3yVCZ48zLUalhkNNOAtu6JelhDuW/MWIh3NNOAsu8HsajwBZ88OTpklzg1mYaV30FNqbvaNbYuP0dPq7k7nnuCVsUe5jLawX4DD2UWswCjZqxqFDUc7WvHnofXQ6VbBtSnGUtp6PbDBN7ywFoFQogHmpU1DYgKAq2bfd6npoea7/pN1duTBrE9k8PRwXtnpTHS3KRCjy3z07FQKJTqxlJE0a7SPpI3wsE67YjYrGeBIi1PlL5jH9ayDwIx0LM7QRybnv15DQLHPV4HqodN1b7NWc4W3OJu6WS9wCR+LvhgPIdCYtkcmHkQoydznEkNwjaLeSC5nIlfT7HVK6E/FbrdbasDwRvVwgLad2aplOIEBuWMDKUQ/M2qkO8pNLKauL8i4v6F+hk7wJ4buHvsIVTb5aWUzeK8xa6vqgWc3yLRbR0x8rNljrsKHd9DpLyuFyJXrxZ1wYvAOC/4Zeqr88Mdr3ylz/E5mjErSMPirXG6Q2Zv4jqgUkvG4BdpvtA8Pt91Xhw5qkaPHCkuFzk1SRQ2m7bWc5RkYaPCg0EQEyREfn3Yusn5gVA5r5UR9Z6BvoKabTbzZQDBzCEWFAQMvyeTbKWsjNcy5/pOHA/2gv9zF919G0mxO/2CNXNjrGRnCWVbpQT8gFDUr8rTJLTI8+DRzYX0SVPwAQY7vwT1RvvbDstps3WaxIze8lA/Ju53U9pm0dUdlJ552l6x/uT8zkWRSfkdIgzUcMVpN0AnBotVArh5g/WyrquqLQPB13tbiufVQqPrIxPsy2SFufCPsVQQoWpdtS5/UBFO6TLo29LpOEfVdnE56RFJoY9IxtI/YHdzH+fjOwC6hC0a9y+2vdCdlNcDAUB5fxKEpRYeAijAD1lwJBwGLy37/C8midQ2jnd83PyiywA3RT7CaiTewvHXkfMCFACOkS4xUSoD28mQCHFVTyteZcXxAfzwu7wOpRdyCg2nVYdr2nDnHoqVPe81Ej4YHteXGFd1FQICekAXrAOUiLppC 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)(376005)(1800799015)(36860700004)(82310400014);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Apr 2024 15:29:12.9516 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b2b20f75-da54-4e38-6bf7-08dc62e0f6bf 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: BN1PEPF0000468B.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB7672 X-Patchwork-Delegate: kuba@kernel.org From: Ido Schimmel The purpose of the rehash delayed work is to reduce the number of masks (eRPs) used by an ACL region as the eRP bank is a global and limited resource. This is done in three steps: 1. Creating a new set of masks and a new ACL region which will use the new masks and to which the existing filters will be migrated to. The new region is assigned to 'vregion->region' and the region from which the filters are migrated from is assigned to 'vregion->region2'. 2. Migrating all the filters from the old region to the new region. 3. Destroying the old region and setting 'vregion->region2' to NULL. Only the second steps is performed under the 'vregion->lock' mutex although its comments says that among other things it "Protects consistency of region, region2 pointers". This is problematic as the first step can race with filter insertion from user space that uses 'vregion->region', but under the mutex. Fix by holding the mutex across the entirety of the delayed work and not only during the second step. Fixes: 2bffc5322fd8 ("mlxsw: spectrum_acl: Don't take mutex in mlxsw_sp_acl_tcam_vregion_rehash_work()") Signed-off-by: Ido Schimmel Tested-by: Alexander Zubkov Reviewed-by: Petr Machata Signed-off-by: Petr Machata Reviewed-by: Simon Horman --- drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_tcam.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_tcam.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_tcam.c index b6a4652a6475..9c0c728bb42d 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_tcam.c +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_tcam.c @@ -718,7 +718,9 @@ static void mlxsw_sp_acl_tcam_vregion_rehash_work(struct work_struct *work) rehash.dw.work); int credits = MLXSW_SP_ACL_TCAM_VREGION_REHASH_CREDITS; + mutex_lock(&vregion->lock); mlxsw_sp_acl_tcam_vregion_rehash(vregion->mlxsw_sp, vregion, &credits); + mutex_unlock(&vregion->lock); if (credits < 0) /* Rehash gone out of credits so it was interrupted. * Schedule the work as soon as possible to continue. @@ -1323,7 +1325,6 @@ mlxsw_sp_acl_tcam_vregion_migrate(struct mlxsw_sp *mlxsw_sp, int err, err2; trace_mlxsw_sp_acl_tcam_vregion_migrate(mlxsw_sp, vregion); - mutex_lock(&vregion->lock); err = mlxsw_sp_acl_tcam_vchunk_migrate_all(mlxsw_sp, vregion, ctx, credits); if (err) { @@ -1343,7 +1344,6 @@ mlxsw_sp_acl_tcam_vregion_migrate(struct mlxsw_sp *mlxsw_sp, /* Let the rollback to be continued later on. */ } } - mutex_unlock(&vregion->lock); trace_mlxsw_sp_acl_tcam_vregion_migrate_end(mlxsw_sp, vregion); return err; } From patchwork Mon Apr 22 15:25:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 13638627 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2084.outbound.protection.outlook.com [40.107.94.84]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2063E1534FB for ; Mon, 22 Apr 2024 15:29:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.94.84 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713799762; cv=fail; b=JvMLcWmp+Tt4yv/6ACssN4evZDOB3/B7EIQYacxVlFhtv7RVjQm8ZQqHEYB3o/0CKheKgSfV2NTMHHsh74u0cHHuquFDlxKUZ6QPMr3/V54RvnytAMxNkRjnRAfuDKNoOwHp1prupwc6SEFeecT7gPc5eh/fbtQ8jPbFEeifuag= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713799762; c=relaxed/simple; bh=/VxFjK9w+ruUocLIAZJ0Q1IQYugd6ZhtIGo+EahE5Ao=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=IfXBPGq9l6tsk8N0TR5AJfJb2oDndpjQf2tt8lNhNhVyjaKSN5PbMfAj7KkaWN6waVQXvXKatnDiDGYiS9bo2tt8sg0XgSE+QPPcnKi4T8ZaKBE765oJixGFXWIoygEFETjnrakQEvOg3xIYIPU7MjPtfoyEZJsxjw6qcZxR/9E= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=c0jGhb3r; arc=fail smtp.client-ip=40.107.94.84 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="c0jGhb3r" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BtMUwdxTnzezOm5jJiB0GWMEwR84gZcFQM7wdOi4L+DtVgnQZP3HIRFI6AVwO59BvjiUpDVHenGtUibUTfKPRbBaZZEZ1QSZt09QqApWazVJAAwaH963edkI847tvrUEFRkER3sXkYisx8Q1kG5eWJ9JiDS2cwtH+u0aQOTCxYdcLFPWI+SF2s7geSaKotaYxMEBsOyqzBeiD51+6vIYt6f83cjFiRYXFOewhiV0nKCNYfdpD8wxrRliZ6Xptac3tQ7bCquImpyncbRBFtf5xfnohR6/7VkMfGvgrt8iUjnY+C+ZJgftABqRQIiIlU/UEz9MCzOl+FgwwkUHdeCCSg== 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=L348D1DeLf8l/s+PxSCqI2gXu5nZa2JhK0B6AA2zVxU=; b=YrJMgHwr3KwTZ8dhdGecUziAe/86dGwwJd5aZGUm/xl/t8okwlTKb/VCbei2KSa9B2ps7HOuQQ5+ET0PZ4wN+UbxYv7Jz4yJzc/Dw12HljLt3NhOIjgL9Defm/3Of3oUEOtQg0K15hcp21g5xv/Lcwza+Wc09gVb5411iL4D3lvoyRwWXs8nZiAMn+XpsgH/r57ZTm3i11a5USQ6Tto/zQqccPy+rlFYq4d0gPHv7B28G312xZetXIgG3kOMg+Tex/vU1PGY4DVqeCkSAPpHf7lff2hil4CSo8vN6Lr4BH+rqUBPNeIisT/xhvmVW6Xbs63hL9HVrKoTmyen6+/ABQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=davemloft.net 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=L348D1DeLf8l/s+PxSCqI2gXu5nZa2JhK0B6AA2zVxU=; b=c0jGhb3rBr1FB/xbRI3iIziHRpMEB8IUu55HEpSwSLwN0dkQfXMHn67EaRQ/lXcHH9etGJM2sTPR0C9ukElCvADmSDphhWHb0GpE5ndeEvkCTZcoT2peI7zpFdQDjBtYquy0A9yFSYNuH3yREbwaWUXeWlCrFnzGuggdd3bd2BTImk5pBZwScTcNuSR4hFJP2t18ZrdGEQD+WclR2bfdaH00S024dkkLwUWyYEX97Db4DrXIJa54iEiC7R62Fin6fVQRyrqHLTGVsWNCuSzTjYvpxtg6P1NHbL4jQ+MwhpFY/PdPVY9EmmcKt7f7axFQ1TCfl9aURn/RMAdzes475Q== Received: from BN9PR03CA0089.namprd03.prod.outlook.com (2603:10b6:408:fc::34) by DM4PR12MB8476.namprd12.prod.outlook.com (2603:10b6:8:17e::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7472.44; Mon, 22 Apr 2024 15:29:18 +0000 Received: from BN1PEPF00004688.namprd05.prod.outlook.com (2603:10b6:408:fc:cafe::36) by BN9PR03CA0089.outlook.office365.com (2603:10b6:408:fc::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7495.31 via Frontend Transport; Mon, 22 Apr 2024 15:29:18 +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 BN1PEPF00004688.mail.protection.outlook.com (10.167.243.133) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.19 via Frontend Transport; Mon, 22 Apr 2024 15:29:18 +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, 22 Apr 2024 08:28:59 -0700 Received: from localhost.localdomain (10.126.231.35) 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, 22 Apr 2024 08:28:55 -0700 From: Petr Machata To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , CC: Ido Schimmel , Jiri Pirko , "Petr Machata" , Alexander Zubkov , Subject: [PATCH net 3/9] mlxsw: spectrum_acl_tcam: Fix possible use-after-free during activity update Date: Mon, 22 Apr 2024 17:25:56 +0200 Message-ID: <1fcce0a60b231ebeb2515d91022284ba7b4ffe7a.1713797103.git.petrm@nvidia.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail202.nvidia.com (10.129.68.7) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN1PEPF00004688:EE_|DM4PR12MB8476:EE_ X-MS-Office365-Filtering-Correlation-Id: 220909bf-e5dc-489f-4b05-08dc62e0f9c7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: W4Cst9Nh7HTlNxs5/RCI9ALxaWtNUhQcAXVQtu/g21BanYlI5oCEPt+uxuoaHdcG2CWSV18M8jk5ROMDGih3yPBHcxC3eWCf4rh4rqIvNmeTYJe7KKwNviw3wU8rnM8+PUdxtTUF1f+CouE5DaKF1zUVDXZLRwNCEPf9cTmxYTwTFAlCfPePx/V4jF4BgjStZaSI5VODKAOqi9sfBPJ/IP9isrvuv2MQVcj7Y7k9lndhHmyvke6ua9wQlIBC0sM+X5yfrPjGeXVwvYxUZujABJ4dl6rHAMYy1QeE7oSoOTClYmFkM68TGUce/e+VzFTR6RW7Wq5iZ7QQI5XOX/JEjwY6pYivxH0xK69Cle4QdIjabgbfwDunUn/mYCrqMWI9dQcjhlTA3eeHsninokV0Nx1/CKf511YioI39BbFmC+w5Z3EUC7Z35oIBL33rnw59R1h6e7ztzBpMkh0rC9TCsuvDUtB6fD3u5nklQcGYDyiL+kAdhThBKF1zDQTEuSp/ACRKb4+Qgfk7N13mvzSfeh3j41cPRItXAgtN2Hw6zd3GhLePcTzjf4QkMRhniWViBgrsbuNAX9fRs9/tWKKcRclGq1RATZ3y3S7XEDQJwrq8cnFQyGLb97LG5818jemeRMGxSBoD8dmIZkMRu8X+tbo2g6aFRzRK5mnlihQavb8A0mKjm5k5yCRh7ntJgnQb6DwFIokEsHVCbdNJt+0QpaaXdk8+u5s8YDqPcG2NzBl1GTKAphzz5IX1j+06vrGPCUYxf/CCyS5qCCmcwzHtYYGMEg4QOYi0s/9dLiS2wpDTsKGVtCMhnt13dbiGsE8zZzWDpNKF2Gk5moY4y6pMDdDkyDAZZy9aJV9KePvaxBOUVjXLxVbY8Tvrm+5sxrAi+IBxWHAbsSjn4ClrowbqCYnMcBYnwQeMfyOx6RNvVM1CWy7B2gIwYNdwehm3+fUPTAaGlsXX7UgZwxGC5VmYb+FYRHgIKDttXycryk5IZPOe1I3fBwlRon4eRzlEapQ2QNUXenOWnvmOvPE9Ep8ZTBSnD0CdZZ53w8vo0KsMEX5t3JWfVm6BDUtqwzXigAw5x+c49ANKSm3Ufz9X4gIoMf5y1u9DZ5fX17tccolX0ZWavCUka4Hj79RFwtshhA1a4zNzI8wpA0/SpiRDUwjZtH09WVeaYgP0s4p5xHXptevo0nOoj+Al3PIlbKurbD+UGoO4z/ScFhOiFHaDgVCdTv6N2+G8a8xpFvjkHiYIG9bQ75qxcc2otB1VqWwcJoHDDKhlE5/3L0ZxFLjCPlKCup9ERg4oKy+IxPscb+s9I/yY6msv+EOKab+8KCXPLgU10HxKaVrOJTtRHK9o3+mjXo/LI51vzFPNmUfiRThizPLyNI+eSrl2Bi/Jq85V/f7Y 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)(82310400014)(1800799015)(36860700004)(376005);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Apr 2024 15:29:18.0520 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 220909bf-e5dc-489f-4b05-08dc62e0f9c7 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: BN1PEPF00004688.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB8476 X-Patchwork-Delegate: kuba@kernel.org From: Ido Schimmel The rule activity update delayed work periodically traverses the list of configured rules and queries their activity from the device. As part of this task it accesses the entry pointed by 'ventry->entry', but this entry can be changed concurrently by the rehash delayed work, leading to a use-after-free [1]. Fix by closing the race and perform the activity query under the 'vregion->lock' mutex. [1] BUG: KASAN: slab-use-after-free in mlxsw_sp_acl_tcam_flower_rule_activity_get+0x121/0x140 Read of size 8 at addr ffff8881054ed808 by task kworker/0:18/181 CPU: 0 PID: 181 Comm: kworker/0:18 Not tainted 6.9.0-rc2-custom-00781-gd5ab772d32f7 #2 Hardware name: Mellanox Technologies Ltd. MSN3700/VMOD0005, BIOS 5.11 01/06/2019 Workqueue: mlxsw_core mlxsw_sp_acl_rule_activity_update_work Call Trace: dump_stack_lvl+0xc6/0x120 print_report+0xce/0x670 kasan_report+0xd7/0x110 mlxsw_sp_acl_tcam_flower_rule_activity_get+0x121/0x140 mlxsw_sp_acl_rule_activity_update_work+0x219/0x400 process_one_work+0x8eb/0x19b0 worker_thread+0x6c9/0xf70 kthread+0x2c9/0x3b0 ret_from_fork+0x4d/0x80 ret_from_fork_asm+0x1a/0x30 Allocated by task 1039: kasan_save_stack+0x33/0x60 kasan_save_track+0x14/0x30 __kasan_kmalloc+0x8f/0xa0 __kmalloc+0x19c/0x360 mlxsw_sp_acl_tcam_entry_create+0x7b/0x1f0 mlxsw_sp_acl_tcam_vchunk_migrate_all+0x30d/0xb50 mlxsw_sp_acl_tcam_vregion_rehash_work+0x157/0x1300 process_one_work+0x8eb/0x19b0 worker_thread+0x6c9/0xf70 kthread+0x2c9/0x3b0 ret_from_fork+0x4d/0x80 ret_from_fork_asm+0x1a/0x30 Freed by task 1039: kasan_save_stack+0x33/0x60 kasan_save_track+0x14/0x30 kasan_save_free_info+0x3b/0x60 poison_slab_object+0x102/0x170 __kasan_slab_free+0x14/0x30 kfree+0xc1/0x290 mlxsw_sp_acl_tcam_vchunk_migrate_all+0x3d7/0xb50 mlxsw_sp_acl_tcam_vregion_rehash_work+0x157/0x1300 process_one_work+0x8eb/0x19b0 worker_thread+0x6c9/0xf70 kthread+0x2c9/0x3b0 ret_from_fork+0x4d/0x80 ret_from_fork_asm+0x1a/0x30 Fixes: 2bffc5322fd8 ("mlxsw: spectrum_acl: Don't take mutex in mlxsw_sp_acl_tcam_vregion_rehash_work()") Signed-off-by: Ido Schimmel Tested-by: Alexander Zubkov Reviewed-by: Petr Machata Signed-off-by: Petr Machata Reviewed-by: Simon Horman --- .../net/ethernet/mellanox/mlxsw/spectrum_acl_tcam.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_tcam.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_tcam.c index 9c0c728bb42d..7e69225c057d 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_tcam.c +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_tcam.c @@ -1159,8 +1159,14 @@ mlxsw_sp_acl_tcam_ventry_activity_get(struct mlxsw_sp *mlxsw_sp, struct mlxsw_sp_acl_tcam_ventry *ventry, bool *activity) { - return mlxsw_sp_acl_tcam_entry_activity_get(mlxsw_sp, - ventry->entry, activity); + struct mlxsw_sp_acl_tcam_vregion *vregion = ventry->vchunk->vregion; + int err; + + mutex_lock(&vregion->lock); + err = mlxsw_sp_acl_tcam_entry_activity_get(mlxsw_sp, ventry->entry, + activity); + mutex_unlock(&vregion->lock); + return err; } static int From patchwork Mon Apr 22 15:25:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 13638630 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2040.outbound.protection.outlook.com [40.107.244.40]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4EAF7153579 for ; Mon, 22 Apr 2024 15:29:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.244.40 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713799778; cv=fail; b=GGZLyKnzmheYwL03Levu0j+y2Lt3LSBfISR5kwaOid0JYCo2UQb9LE62QQYQ8RjJgsjo4jwHX+80JaxF6UVjntcAiZzFucQGWmnlMJSFxQQMQ6TXgfi7YHkHz1isdeKrR8GmY1KGl7WefdaYgfK61t+u59YDsdLy92z+Bv0ihY4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713799778; c=relaxed/simple; bh=WPVMaZgf0c1BhE/LdBWGLOuVxLDiuow5XbgmFVSyBjw=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=EZCO5YU9tP8rqZNxiHK9LbHljiLoee9bSCJxlAW1SiIueTywCjb4ELGbS2Gplx9E26MMN0f7ChHPdEWqoJZ8SwzYuf/oIT1iodeztK+np5m0Kl7aovHi6o7eLOzAaWwiRAuqTt5NFiYkD+YjC3mTH7pseLiG59qnXApGogflVRk= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=GM6WVdkF; arc=fail smtp.client-ip=40.107.244.40 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="GM6WVdkF" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Gnml+WWAndGvdwMIZmvxISyXhPPGLLFFeBu5uG4IsuH0Olsvtp2oHQjKzh8AuCFFQd9ZDj6sdaj1sBygu9okIeTHoDgAa6KncjmNz9yY3xGZSlg+4zRoasDFyE9YvgeaLXTdNGWiWFMTLIhGtXL/YTxLLKNtKFV7hOA1EMLJLr/QaT4ShY3IZ0K6DeMgs9olXuwX1CQ42XdLaQq4Hx/iQL2L2va1NOb2o2KPgSJGrwcM+j38h5n+ZucvQPEP1JxenOvRjd7hCYJ47GHP2fqqjDXiZG2iiiO4wUalmm7KNlwOWWX1cJgXqTbwTLwNIb0Mj9NaUR+vsQApLdndULOZkA== 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=wwGWOuZbaFXS1D54uDpK2b9x0Mhjqyng+VGkHzJV0sk=; b=AqGptBbux3jPG321M88RY+LeQaQJmiOwQHYhmQcsU6mUpGZfztusiji5+ADuLFSoafISPDPyoQTEQ7kNGMgdbChZTOELfgi83siKp1neIbdpv0D8EvxtGR0251mloftSSp69ss1mshFKlFfi42eRc63ca9W+uT+foaGTCWfePyKh83WUEYaQxrEQl/ShAU6hT+aJGDXB0cgs76t5TZGGcLGH9qwaiFxzUO6tB1smMTc6lQnapB1mk5mVMlgWMUZS1PVPbM0G/BugJqkMfRQgyG12wVfQBcuj4nLwNUcKY2t+WOMxUWctmnvW4YDK7l7ftEA1IJ+/Cb2vSFeC44N4dw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=davemloft.net 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=wwGWOuZbaFXS1D54uDpK2b9x0Mhjqyng+VGkHzJV0sk=; b=GM6WVdkFC7pirLxT3gagy08p5oA9q2XubripDGgDs5wxlBGOeB9r2lmImhCLiR0jNtPy1cexySvkaPrHsa/YGHUj5ABE22yt1YDqWVc4b39Td6ruQc+2VkVgZe/ujmhVEDNDnFThFNKFD3eDqFk678bb/q7BMY1oNOnU2lL71+pTvNEYuK+ob0zpvUCIJmnpRFmERcYI79Rlnc3RRXAqZJ182NZNKMkSRJg/H/DOowCyFAATmlseLjtFfbo/dWz/OfaiQOacITsGJf+ZR+ILNgQ93bp5Bn8A65G2hfE5mwZbD/zy2GNQD9eJdoK2K1r4m6uuYB4fOotQJnBz1k63LA== Received: from BN0PR08CA0016.namprd08.prod.outlook.com (2603:10b6:408:142::35) by IA0PR12MB8207.namprd12.prod.outlook.com (2603:10b6:208:401::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7472.44; Mon, 22 Apr 2024 15:29:30 +0000 Received: from BN1PEPF00004689.namprd05.prod.outlook.com (2603:10b6:408:142:cafe::39) by BN0PR08CA0016.outlook.office365.com (2603:10b6:408:142::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7495.33 via Frontend Transport; Mon, 22 Apr 2024 15:29:27 +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 BN1PEPF00004689.mail.protection.outlook.com (10.167.243.134) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.19 via Frontend Transport; Mon, 22 Apr 2024 15:29:27 +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, 22 Apr 2024 08:29:04 -0700 Received: from localhost.localdomain (10.126.231.35) 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, 22 Apr 2024 08:29:00 -0700 From: Petr Machata To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , CC: Ido Schimmel , Jiri Pirko , "Petr Machata" , Alexander Zubkov , Subject: [PATCH net 4/9] mlxsw: spectrum_acl_tcam: Fix possible use-after-free during rehash Date: Mon, 22 Apr 2024 17:25:57 +0200 Message-ID: <3e412b5659ec2310c5c615760dfe5eac18dd7ebd.1713797103.git.petrm@nvidia.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail202.nvidia.com (10.129.68.7) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN1PEPF00004689:EE_|IA0PR12MB8207:EE_ X-MS-Office365-Filtering-Correlation-Id: 8f37392a-1868-43e4-ddb8-08dc62e0ff79 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: kJOMXnxSglffEQKOTD9BVko3iz19pwx/12Mb8WfPXnqRVzodxNLnZHUB4vSZeGqGCA6MRrvaRWDaJu2TSyoTX7z17QfmLjEa0MCPDucYcCQ6a4XtGIlBGt/+q+xvT/9MTuBmpFKE/oZS6pT08AjDRzcjcrBJvZaml7xVAo0/c0xzb8/kNnl35I7gpwKCcbqq8vCjdh+iL/wMEdm/sGEn/QGzeGAcaY7NB1lX92iuZb0yVu4o8LLrS/LqapMZnNCDz8oNRGQLV+Ci0kfPz4vBD/swFiN7ybCVZ96vgGS2vt4BeE6lxGHtwFWOJ2asVr3Vo9M9ctFXlmFmYH0Gw0ZAP76ODQP4PfBoW20zh4ycSfkUkNy/8n38V4DXk/RQibg+xGKJgKlwLWbE7RPLooNa309rSt6tmsjb6otvjUDMTUS8buzsGlHqNLSy1bBCT80zog+C76ugg+A/nOi4ZGQag0fpBKHh8qCZesskxoP8LSUjgmgb/UbfSNeg0dTrid+5JydFmO4hTAEDYYUvOB8I6MVCCmlMchfPHZnj4R2XnpXWdmfx4SbxszoRiTuS0XZczAFD3blNVWqtTt2JIzD6kF8bACGnDGltGd2ttYHWMqFTKkN7BI4LHKaVpPuakIlsDMEePnfEGZfm+LyR72TlUCGuMUC8YZgvpq05BYV6AIb8/fUt1fjQ8FF1pwAzkmlxy+xCGycN9W8YPjpnZWeGuiL3lb2t7pET3cLbUu/L+2im/5UcfHrdF2AkK/+ZVKj5y2DbFW9zIw8gFCZcHn4aQJ+Ize2bowGHzq6EQ3LXWDCfu2dua3sp76cHRI+yDJDl5RwlgOekhgPDCnNEpSR+raJm+yX053A6tDLvhEMKQPi9KdJ9heskD6WjCwthryujcWPIxzsJuTkh7NXykwu7LasMDoZs71we2XLmhu8X3sKWXCI+d8aEU0sIl/pI1gtnxWIhzZzOTvkM4vrFcE2aqI3+ZkVyjLqv6yvOjLt216i6c6W7h2RUwZflAidasbNcixtdivsunrrgtuaJ3dQaPQ5FsIJevV7LiN86yYcaA+4g+rDvI8krMds2GY+7t5qnamvo823abrycGyWxkHDmvGInOajgR+a8iSkqVvv2DJpUTGNSuvl9HJ53choKZTFLET2mt82gZcnzJXW9f8xQscSgeP+XpuKBMzyaNXCzQb0fqvuBLwnpt9wAynOKUd3lZaLL+88rFoqJCCSyxU3WryPLXRTt7AdKWSaCkM0E0FeLtyFU51m9Nuhw3xBCTRhqYhWyBOJ1ZDzyC/1zmsSrDgP9S+IBQbHiJItQkU47XVB/pMtPBbXD8YC7MjvNoYWL6nSmqds0Cd2WwvlMQJic9dtghzoQDh7jzX372Dx4/E2sk46z8PknvJCJtFqNTwZy 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)(36860700004)(1800799015)(82310400014)(376005);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Apr 2024 15:29:27.5953 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8f37392a-1868-43e4-ddb8-08dc62e0ff79 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: BN1PEPF00004689.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB8207 X-Patchwork-Delegate: kuba@kernel.org From: Ido Schimmel The rehash delayed work migrates filters from one region to another according to the number of available credits. The migrated from region is destroyed at the end of the work if the number of credits is non-negative as the assumption is that this is indicative of migration being complete. This assumption is incorrect as a non-negative number of credits can also be the result of a failed migration. The destruction of a region that still has filters referencing it can result in a use-after-free [1]. Fix by not destroying the region if migration failed. [1] BUG: KASAN: slab-use-after-free in mlxsw_sp_acl_ctcam_region_entry_remove+0x21d/0x230 Read of size 8 at addr ffff8881735319e8 by task kworker/0:31/3858 CPU: 0 PID: 3858 Comm: kworker/0:31 Tainted: G W 6.9.0-rc2-custom-00782-gf2275c2157d8 #5 Hardware name: Mellanox Technologies Ltd. MSN3700/VMOD0005, BIOS 5.11 01/06/2019 Workqueue: mlxsw_core mlxsw_sp_acl_tcam_vregion_rehash_work Call Trace: dump_stack_lvl+0xc6/0x120 print_report+0xce/0x670 kasan_report+0xd7/0x110 mlxsw_sp_acl_ctcam_region_entry_remove+0x21d/0x230 mlxsw_sp_acl_ctcam_entry_del+0x2e/0x70 mlxsw_sp_acl_atcam_entry_del+0x81/0x210 mlxsw_sp_acl_tcam_vchunk_migrate_all+0x3cd/0xb50 mlxsw_sp_acl_tcam_vregion_rehash_work+0x157/0x1300 process_one_work+0x8eb/0x19b0 worker_thread+0x6c9/0xf70 kthread+0x2c9/0x3b0 ret_from_fork+0x4d/0x80 ret_from_fork_asm+0x1a/0x30 Allocated by task 174: kasan_save_stack+0x33/0x60 kasan_save_track+0x14/0x30 __kasan_kmalloc+0x8f/0xa0 __kmalloc+0x19c/0x360 mlxsw_sp_acl_tcam_region_create+0xdf/0x9c0 mlxsw_sp_acl_tcam_vregion_rehash_work+0x954/0x1300 process_one_work+0x8eb/0x19b0 worker_thread+0x6c9/0xf70 kthread+0x2c9/0x3b0 ret_from_fork+0x4d/0x80 ret_from_fork_asm+0x1a/0x30 Freed by task 7: kasan_save_stack+0x33/0x60 kasan_save_track+0x14/0x30 kasan_save_free_info+0x3b/0x60 poison_slab_object+0x102/0x170 __kasan_slab_free+0x14/0x30 kfree+0xc1/0x290 mlxsw_sp_acl_tcam_region_destroy+0x272/0x310 mlxsw_sp_acl_tcam_vregion_rehash_work+0x731/0x1300 process_one_work+0x8eb/0x19b0 worker_thread+0x6c9/0xf70 kthread+0x2c9/0x3b0 ret_from_fork+0x4d/0x80 ret_from_fork_asm+0x1a/0x30 Fixes: c9c9af91f1d9 ("mlxsw: spectrum_acl: Allow to interrupt/continue rehash work") Signed-off-by: Ido Schimmel Tested-by: Alexander Zubkov Reviewed-by: Petr Machata Signed-off-by: Petr Machata Reviewed-by: Simon Horman --- drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_tcam.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_tcam.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_tcam.c index 7e69225c057d..1ff0b2c7c11d 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_tcam.c +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_tcam.c @@ -1451,6 +1451,7 @@ mlxsw_sp_acl_tcam_vregion_rehash(struct mlxsw_sp *mlxsw_sp, ctx, credits); if (err) { dev_err(mlxsw_sp->bus_info->dev, "Failed to migrate vregion\n"); + return; } if (*credits >= 0) From patchwork Mon Apr 22 15:25:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 13638628 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2061.outbound.protection.outlook.com [40.107.220.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2C850153503 for ; Mon, 22 Apr 2024 15:29:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.220.61 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713799771; cv=fail; b=akrjwDp3zfYWoZbFPZKbhOZwY6G+dpZHBn+Q+hpz1Cj6l2ENy3ZnN8fVQ0rZ4qV5Amgag9r0BAqeLoiHUKXfOolYDB0ZoQgQMFyLkJ4UeJlnXctsGlkyYqR5qvvmzCiJmtxU2PJPVlW9GwCmfDcxoCCUII9SRYKUaFdCBrBtn6Q= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713799771; c=relaxed/simple; bh=Y7Z5EoeVZCqtlXj2ln+Jl8DvaG8afwfAVTOYdE+ep6U=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=GLay0M2uPXL9E6tN9Tl7SMO6mXrqGuvich2hA6J9156YaXxRfzN4rvbWYouUYIKnHcsefyeu0wKNpm3fE8dD7R3722sj4TvnfeVKZPtrInJd8crR2cGYmCRHCcetsH4uusA7GydybpVu/FlBkC4Z8c4Vm9UVrwYDCTx8Y+5QcwQ= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=T7nVr9mw; arc=fail smtp.client-ip=40.107.220.61 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="T7nVr9mw" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JKZX2S0ULGY/FVRLMxryFbq5JbqP3FiSCMAcyMONOdIKAneWM6wX7RCRNB9eaoFORX84ODQ2VKq+3HxsIQh+HWcQDIFOe+VMMH6X1rt7+XVQnaKV0cE2fC81dEkhN7jJlfxuzud2KUBVfIGvMIDc45IikLTo8D9QcGjF3WBXZIWoekNKIfkrcVQZwaUEfkRleIGx8AjHMylhhvjMUfGRb09aFsyOxY6Ptr2QUgb8tnnD7D7MZFmd+0wrWwmUEapVXPG9K+drgOQBbJKPhf58YKFwHlvuGqTIvLvmCBLHCB+iIu0Cz9/ogACiiU/sQ4XlALmvJW39UqA8YoSE2FgdFQ== 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=sctuDcEJLQnxwZdOoVs2WOmWvQwyvvEClGVRjiPf65g=; b=aSkHswHsUPsfKAVC7MAyVjdjV90yPASw06frvf1oJ6yZuHtT24BuaYMs3+0d/OsB5v34P3FsSHYJtjI03g7hgoEpYhuTmTQTj/VHO0UG4cHRCuz2oqrc3Kv9vWmj892RTOtYRKFRYcrX2F1cV3YWSoQOG5/p7n1xshO5781Hrb8NgXG8uVByq23KYs7lPphBBdvfJmsrRNGf+mWKh3aCgNRGcV8DOo0pyOtjqTCSa754lExEGvvSnVEE1x21Ah7PYbVqdinXpBV2YPsyEh6/qLASOI2Z+r+oymd/n7lDBAIWU75AhgtJvkmMGXF7eBPqrtkv1AuGe/tTUdAKP7w9lw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=davemloft.net 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=sctuDcEJLQnxwZdOoVs2WOmWvQwyvvEClGVRjiPf65g=; b=T7nVr9mwSckDihOXSKSBTE3S0Pp09xNgA6jURCQYKpvvmu7iPyC3OhAr9Clq5555I1eWQyZCSfxQkXT7q1imoRNHfANUyw1gyukar03uESLfQsmhPMtuod+ImE4/PFIOPvz/0frlMn2wf0+1duIL8qTC0kI/7V4vI/LrhLd5tICx73MH12+UcdMR5L05efiYIaEv6ehCu3D681WXTYUEc9qkORiBIvSf4T7hbUsP6RzH7FaVG1uCXN6fAgWL6h4tYiEns+/tZ8GSdYbMMSFRwNHeajsO7RRRt90j4iK9Ws4Ym/JZkl/wVxREVnCE3PK1KfAuL8v1gmvwLrYT0y5tzQ== Received: from CH0PR04CA0002.namprd04.prod.outlook.com (2603:10b6:610:76::7) by DS0PR12MB8246.namprd12.prod.outlook.com (2603:10b6:8:de::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7472.44; Mon, 22 Apr 2024 15:29:26 +0000 Received: from CH2PEPF00000148.namprd02.prod.outlook.com (2603:10b6:610:76:cafe::29) by CH0PR04CA0002.outlook.office365.com (2603:10b6:610:76::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7495.34 via Frontend Transport; Mon, 22 Apr 2024 15:29:26 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) 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.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by CH2PEPF00000148.mail.protection.outlook.com (10.167.244.105) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.19 via Frontend Transport; Mon, 22 Apr 2024 15:29:25 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Mon, 22 Apr 2024 08:29:09 -0700 Received: from localhost.localdomain (10.126.231.35) 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, 22 Apr 2024 08:29:04 -0700 From: Petr Machata To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , CC: Ido Schimmel , Jiri Pirko , "Petr Machata" , Alexander Zubkov , Subject: [PATCH net 5/9] mlxsw: spectrum_acl_tcam: Rate limit error message Date: Mon, 22 Apr 2024 17:25:58 +0200 Message-ID: X-Mailer: git-send-email 2.44.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail202.nvidia.com (10.129.68.7) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH2PEPF00000148:EE_|DS0PR12MB8246:EE_ X-MS-Office365-Filtering-Correlation-Id: b4e22d39-ac32-4a8b-968f-08dc62e0fe79 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: j6r0RluA3Gw91sdhMhJtr/a+jn3wE8R0N9BPILG+EunQLEhERa/uDItuL56M4INp4TvUrZdg1QpSMDsykP7J2xaVXnCBZwi2WFE65HIz1DJZH0qzjGfpHFigOq5fNHWVHlNTZxb8jpks8VZm/e4zBbNHRAoMH2OWtCK3HyL+LHK6jj4ec9TOj7rGnE50LMoah/36ceO7sxKt4V//O16pEH16s7kyhB6YPq26g9GbFSHM9gRB83xNjjxGPntbTYYp2T1Sy4gsTbmgyAmCTgrmu0SsrSsaGUtcqmftZMs+iUaXWnkp0VTJgiKfXlAOtf8tE2MPj713vKMjPc5iie5hCzcVVvZlec1bmWVjTXpNDUehdhRU40Zfj2AtjcLB46P8apyLMhd6DuHOvPYFDpep+7XVOOpVGXTdjLKHlbaILAZDb9FWmW0e/g83VAn6QoUCbk4OVw57igqxNnK+KB7LZGvceDOF+lWlgVo1mVqDGhuxQMiDX1CPttDttTr7zse9/nWMGyUG+Mj2/7WgOEuiewDoT/mmoj/kTMvoJjr59GBL8ASZ6jXU5Ka8KcXZHms0l5KWtZ9jMdsbOr+rjnIMfPatlijAdTcZR8i1CIxcXKdNhkFKMsONoU4eqzjwM1iOVSw7bUfrN2AGlMrsER0KdmC7qLTdXVQd6CLqm5gyWp8eCypKnwxT1B70M1hiamE6zao2jfnzlSSla6jBDJrSMXe3A1KGvuFu5AcvS0TgpF1EdMvx+tcpEN7wi3cQtFaKqo3dMUVOPKBGB8lnm55g0GK3xpVlGkSQb0Nr+H7kxDxp6U+z2kDQAuSvyGdk9MSUQrAbGB4+c5BrxOdUuN9LTtrIrh0wBoW+tQk1YtWPymJZmJqit2JDdkGbal6WcBj7kQ5AtTLePRFu4hTBxGlfzpRzZ0v9rEQW+YOGRWj9WcwKohoaWia3MwfwZs5bO2THYpGCr7N0WCnWLQdhdgiCBTylmzmUKU4y4OfGcPLTVMNtVsNhlLTZiNQKImx6eRu6sjUCi/3bdKeXfQiONoIb7QBZg6kXuOx48jPjTDXdadqvaAqdyBGqUimQIv8aEFlCa8sEEtM+rFAaaEUeHZ5iQQPyblZlEMpBWoRBWezptDwjOLOjcd/iufoXgoeawHveSyKVJkpDEOCnRQgFml2CQ1mxtkPglY35voqvxRMHe8K8nTg/tgcWOZalxq2h48bGPbGue20YQDmkRpqb6CtW9C8putQ/BfIYCCf3Up5F52DZaC3v6iLZebc5Ai7y34ZZ1wH6ObST5qMiCXwixC8f+T11FaRB4Prieo6iVFc8mbQoqj1odEOp9d3E1nOwqLtgeKanmxVPE3psaoQxCo//XHOeGwD2L1rA52Ez3QhYfB6TesF0CdifYGScLEHE6wOk X-Forefront-Antispam-Report: CIP:216.228.117.161;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge2.nvidia.com;CAT:NONE;SFS:(13230031)(82310400014)(1800799015)(36860700004)(376005);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Apr 2024 15:29:25.9782 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b4e22d39-ac32-4a8b-968f-08dc62e0fe79 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.161];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CH2PEPF00000148.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB8246 X-Patchwork-Delegate: kuba@kernel.org From: Ido Schimmel In the rare cases when the device resources are exhausted it is likely that the rehash delayed work will fail. An error message will be printed whenever this happens which can be overwhelming considering the fact that the work is per-region and that there can be hundreds of regions. Fix by rate limiting the error message. Fixes: e5e7962ee5c2 ("mlxsw: spectrum_acl: Implement region migration according to hints") Signed-off-by: Ido Schimmel Tested-by: Alexander Zubkov Reviewed-by: Petr Machata Signed-off-by: Petr Machata Reviewed-by: Simon Horman --- drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_tcam.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_tcam.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_tcam.c index 1ff0b2c7c11d..568ae7092fe0 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_tcam.c +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_tcam.c @@ -1450,7 +1450,7 @@ mlxsw_sp_acl_tcam_vregion_rehash(struct mlxsw_sp *mlxsw_sp, err = mlxsw_sp_acl_tcam_vregion_migrate(mlxsw_sp, vregion, ctx, credits); if (err) { - dev_err(mlxsw_sp->bus_info->dev, "Failed to migrate vregion\n"); + dev_err_ratelimited(mlxsw_sp->bus_info->dev, "Failed to migrate vregion\n"); return; } From patchwork Mon Apr 22 15:25:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 13638629 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2079.outbound.protection.outlook.com [40.107.243.79]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 330EF153507 for ; Mon, 22 Apr 2024 15:29:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.243.79 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713799774; cv=fail; b=bS7xM2EjTKaLtvq49AgHd67sk0cVCi418LAvUGdsEHijgA2LDbB5z/WDIyUydLWH600++Q1ckZMTZCDtcW8XHDys4e3n5gfUkK/OEyiFTAYTtlVLi+K+bU2Jlf7r2RN0sl4EEfwncNQ9YGzguhvDQBHT8Z4ggAqmwNACwH5SOxk= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713799774; c=relaxed/simple; bh=ah0+LJyFNCpGgK3fuca8RLUJpg+s3d7XaoFAmLM5Urk=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=uQMwJAqhlzauxJij28Mjy0zlpZ27h0amTEjuaKZxPicAgLc6XvFrFJz6w5fo8MgAa77rc7bUWKmDWd+sDMyxccvQfGH3aM5eltvPQQxCoVhb626T95hJYu1GPkPgIT7iuqvivySzSfTx+wPhUuf0TwHk9MudeFBkYHfO3MLoIdA= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=EuwJCodq; arc=fail smtp.client-ip=40.107.243.79 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="EuwJCodq" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LgzknUWe836y3RPpo0cUP0VFy/NkyXppY+pIUFxzeNe0RGyQf06ZpMRrtSwucbuu7UERTYkon8Ucz3n8+yOcyeDkN4OoxB5yV7W9AWJMrv4Q93aCyTnWXMt/klSsGBaaQnA/A094lj7DWXtgoAp66bU8OKknZoetL59MO4vxDn5JXCgTLEI8BVbwZsltvj39QUhCbyx/BKlT+mS7tmdTLgRrjgXtRBAYY3kQXWxL0JzhIE1ctdlmj8YdOx0ONrArWBCLuynkHzYi8dEDH/af9daDyz1AY2e4jbZKb9lGZbTs6jOXpmlsBvv/3nZq159DcCn4xfy3mngNPVeZr6RQ+w== 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=KhmyKFOoc8Zl0G2Njk26RHjMiNWjqgZz6uqc8ameXAc=; b=AQT9UFtgmW4J8fQZWHtyVwKooC9xg+tjzFH7W98AWBUi7XHr8v/TJ2gY2Y/EA+s7+sEaTuRD/Kx2gV4x92qz9onraiCBMmWxn0buKA55SK/mHgfg0O98FNp2NTkNML8/TyTW6ViNfC9K5jmRB6qMfP8kB98mUcz7FQvUM7Gq474E1peL9Ox20wppVzPplh9Y0oIAZqm77sMKViPAaM2CD+Sti2OEZZEjqX897qS3Bg+Vv9z0LLFT+k2iHd6fisOmKf70y+KUGN0rnhvguZml8JGq/2WBLa3beQn19BNhv1X7c6ntQxdO/okYD3j7HiaO42WROn8iSXdz0i/V3V1MOQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=davemloft.net 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=KhmyKFOoc8Zl0G2Njk26RHjMiNWjqgZz6uqc8ameXAc=; b=EuwJCodqZPilnntEs0+FCbVSOr7zBgkLjJYu+lTxRc8PM0/Y2fJvOKL30MjPhrgvn+UPE9nT7NvExxgPr62IbLiGI5N7MVmtHI5JtfzON+Xt7uUL7qLowrZV4hIqncD5Po9SWpvNUMIDFHCpw1x803x9n9+5CFht4tlRxz84JfeXyW4cWVH2Iu+RpcZ4lnSeBQLdMuLfdRXp7nDX8Dw75goJkNCEBiI/pX8kE7Pl9qL9KYElzsBbh3xgwQJ0Q1aCsf3dZzDu+7k000Uh2Tq1ErQfMU3CbCXKUaGuPZhswq7pmqsixtYydLVk5ormD9ZX5jRkMQ0yBZ0BOwAjLZ9vzw== Received: from CH0P221CA0044.NAMP221.PROD.OUTLOOK.COM (2603:10b6:610:11d::27) by IA1PR12MB8335.namprd12.prod.outlook.com (2603:10b6:208:3fa::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7472.44; Mon, 22 Apr 2024 15:29:30 +0000 Received: from CH2PEPF00000147.namprd02.prod.outlook.com (2603:10b6:610:11d:cafe::2) by CH0P221CA0044.outlook.office365.com (2603:10b6:610:11d::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7495.34 via Frontend Transport; Mon, 22 Apr 2024 15:29:30 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) 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.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by CH2PEPF00000147.mail.protection.outlook.com (10.167.244.104) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.19 via Frontend Transport; Mon, 22 Apr 2024 15:29:29 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Mon, 22 Apr 2024 08:29:13 -0700 Received: from localhost.localdomain (10.126.231.35) 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, 22 Apr 2024 08:29:09 -0700 From: Petr Machata To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , CC: Ido Schimmel , Jiri Pirko , "Petr Machata" , Alexander Zubkov , Subject: [PATCH net 6/9] mlxsw: spectrum_acl_tcam: Fix memory leak during rehash Date: Mon, 22 Apr 2024 17:25:59 +0200 Message-ID: X-Mailer: git-send-email 2.44.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail202.nvidia.com (10.129.68.7) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH2PEPF00000147:EE_|IA1PR12MB8335:EE_ X-MS-Office365-Filtering-Correlation-Id: 9c545214-888f-4dad-3b1b-08dc62e100a3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: /XX/48Jiekk3q9TH8ijwTfXy1/wJrKvb1nPDbJRJu5QAZ7psJy8EMkVpNTpV+PoRnvdnJyj+7SWK2m4CNtnfNZM8eC73+wLdD6F4I5kCEtyZF3RY48r7QWrxQoTG7VosVDO36coZblRBOFmCdZhXfzNL/hr32Cm23gBEplR+lEWcwROOKwKF38SqGAzp/MMqHHzXkUXChXG802/3lI91/Lu0A3+QKEYtH7YKtrpQLV5wpH71HXXL0h5TtVHU1iDTpUhnTUL5nFcO7ZwyguypblCDXGk0MPjTbGqWboZhm+cc8rI8HtmImK/4v53iG8et4dl/RCnlw6v+9+OdMtcLveTY0rY1mYxmnfg+BLYuBrfXNDtHmLsU4mNwjyPTfInNPQlUCJcjK49RguoOyLIHvENKwBkKSeYxQaRFiYY9Fen1F9aBBgSEwhXSB3rmzj6rhEb4gchowT1Dl0+9fJ5hIgPjoLYDaiIY8X4sOSq6r1jiqaLue+OlgSkHlnNfZRzVS3yKo7uaJ1PRoyIxDDOO8abctiJiHqbwFKsyNBak7/TvQxOGRqVylIN/BT4ch879YVSVjBN1aoSGGJ4aFvcFlkRpF/U6dEjpnCM5Zi3gM1p0vu7enc3PW4xGsMbnCOrubg61c3zbmDu2BhhCV8+zKQLe3t3XlfMBlMuXAo9Elx74PWovw9vv/BkTUe+ZKjmcga5Yz5sLb2tI/7wznNllVNlRcWp5dRqdqPaxBEZMiLkAMk7zrLAxV06kbTmgnUMHOd5pyOgeDMSl+jUYmYaYoLuIqBTsy5PHjWeSO1BMkFS45tH7ZOKfPjslYgjvQ9HHvgcvyBrcBvxyMrMCn5xHMVL0XiARvbHZloQ8Eqj6UX0M5aGs3/WhPOUsBxVUAYiJI2BKy8M+IM0ZqfP3pIJok1qBtJwbdFRVtg19XyxKdtIvB+xphlTz7vb/M63B1zk3/4gPL6idpPYpIDJxBcZsiHxwJKtMuou7YegUtsu6lJYGJ8TyGVXOOifYF1Sc1Y6FXyO7gzgYdT4RMWDr/sOUWNEdvZH/ZYhXTc3RvTis8Fh4SEDcSQVI20b+o3iapfLnaM5EokNiYl/ue9NTrkh12rrW/BtozcjnzZwX/7fTPzq+gf5+vLYhHvvPvxi3zUpY78BDr07NIlZc9LKwDgLSY86WAaBPpI4EbV5TJXLsrX19NFIkyiCRmFg5Z3zcUsBbYHQYGY8aZK7hssNqqS25I+En4R2Z8x0qPipLdRMM52PnGXlccLw0ptfGXLOE0OtjXFZjBPf1QX701fMVsSX7lxkLR6uBxS0GAfKhESl6XHr8YOugZQJVZkaxzYsMlaGgtfacXgRekXpWoW1IC4ntm5BgCSoR371TuMgmyloKsGdmkJwU7cxQZESWdvKQztk8 X-Forefront-Antispam-Report: CIP:216.228.117.161;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge2.nvidia.com;CAT:NONE;SFS:(13230031)(82310400014)(1800799015)(36860700004)(376005);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Apr 2024 15:29:29.6066 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9c545214-888f-4dad-3b1b-08dc62e100a3 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.161];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CH2PEPF00000147.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB8335 X-Patchwork-Delegate: kuba@kernel.org From: Ido Schimmel The rehash delayed work migrates filters from one region to another. This is done by iterating over all chunks (all the filters with the same priority) in the region and in each chunk iterating over all the filters. If the migration fails, the code tries to migrate the filters back to the old region. However, the rollback itself can also fail in which case another migration will be erroneously performed. Besides the fact that this ping pong is not a very good idea, it also creates a problem. Each virtual chunk references two chunks: The currently used one ('vchunk->chunk') and a backup ('vchunk->chunk2'). During migration the first holds the chunk we want to migrate filters to and the second holds the chunk we are migrating filters from. The code currently assumes - but does not verify - that the backup chunk does not exist (NULL) if the currently used chunk does not reference the target region. This assumption breaks when we are trying to rollback a rollback, resulting in the backup chunk being overwritten and leaked [1]. Fix by not rolling back a failed rollback and add a warning to avoid future cases. [1] WARNING: CPU: 5 PID: 1063 at lib/parman.c:291 parman_destroy+0x17/0x20 Modules linked in: CPU: 5 PID: 1063 Comm: kworker/5:11 Tainted: G W 6.9.0-rc2-custom-00784-gc6a05c468a0b #14 Hardware name: Mellanox Technologies Ltd. MSN3700/VMOD0005, BIOS 5.11 01/06/2019 Workqueue: mlxsw_core mlxsw_sp_acl_tcam_vregion_rehash_work RIP: 0010:parman_destroy+0x17/0x20 [...] Call Trace: mlxsw_sp_acl_atcam_region_fini+0x19/0x60 mlxsw_sp_acl_tcam_region_destroy+0x49/0xf0 mlxsw_sp_acl_tcam_vregion_rehash_work+0x1f1/0x470 process_one_work+0x151/0x370 worker_thread+0x2cb/0x3e0 kthread+0xd0/0x100 ret_from_fork+0x34/0x50 ret_from_fork_asm+0x1a/0x30 Fixes: 843500518509 ("mlxsw: spectrum_acl: Do rollback as another call to mlxsw_sp_acl_tcam_vchunk_migrate_all()") Signed-off-by: Ido Schimmel Tested-by: Alexander Zubkov Reviewed-by: Petr Machata Signed-off-by: Petr Machata Reviewed-by: Simon Horman --- drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_tcam.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_tcam.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_tcam.c index 568ae7092fe0..0902eb7651e1 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_tcam.c +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_tcam.c @@ -1200,6 +1200,8 @@ mlxsw_sp_acl_tcam_vchunk_migrate_start(struct mlxsw_sp *mlxsw_sp, { struct mlxsw_sp_acl_tcam_chunk *new_chunk; + WARN_ON(vchunk->chunk2); + new_chunk = mlxsw_sp_acl_tcam_chunk_create(mlxsw_sp, vchunk, region); if (IS_ERR(new_chunk)) return PTR_ERR(new_chunk); @@ -1334,6 +1336,8 @@ mlxsw_sp_acl_tcam_vregion_migrate(struct mlxsw_sp *mlxsw_sp, err = mlxsw_sp_acl_tcam_vchunk_migrate_all(mlxsw_sp, vregion, ctx, credits); if (err) { + if (ctx->this_is_rollback) + return err; /* In case migration was not successful, we need to swap * so the original region pointer is assigned again * to vregion->region. From patchwork Mon Apr 22 15:26:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 13638631 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM02-BN1-obe.outbound.protection.outlook.com (mail-bn1nam02on2048.outbound.protection.outlook.com [40.107.212.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C260A153509 for ; Mon, 22 Apr 2024 15:29:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.212.48 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713799780; cv=fail; b=HtDDwyc/z+REFnLzBwOyvTDgbCgc40dJYF+6Q1MpMvX4248+G8SSShiwb3RJREjg2DT4bGfDnKqkvgN+Imopyr0jIiR9c0yFCpqEBHWo2aJt+i+2TJbJcxsp5xLHlc8UsIcQ5uXiWaVI1Rr3FNlFODT8WOHZf+oTnF0UkDgB4MM= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713799780; c=relaxed/simple; bh=JvMkbAnssz3dpC8ZYOIh0aqoFB9Zq+UeSo1pYZTFONc=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=k9GPsvB4nvg9eTsAZM1FICQTJTebiirwUjg+9WhcACTHIM546wTeXJaU2ZCPk15S8vwg9d3IuQolTO0lJwbEI0BC6z5nID5lCvPEeXC71mh9QJSkndvPRJT/8CdqE/wtn5mIWFUhKc+MwWq7hvJ5QG0KIH1lQJRCQEsTL6o3QqM= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=rNwk/Kl+; arc=fail smtp.client-ip=40.107.212.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="rNwk/Kl+" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=V41dZq0rBm880waRPvLD41xxuahQlvrxYl7+lTXV9DLL1Zb7sG4cctr+L+tkOeRXhZfGnF6sJ8qRE+H87xe01syVFd9CocUPm2Z+N77eIdhLWPzGiNvdZXCwhioC7cQ5Mw3aCMKs32m9rfh1/Wyq8LGzwqYh9whQFkleI6rPMCXjgbT5o1exLozuPe2nSuG7kyOjkjMUDsZnqUDsYX/8d7iRR93g5N/lPpgqrS/qrH326JH/tbn/7OMEL4KR9DOBBT0rqJPe4B3U0KlfWIB118UCwg6vc10+kyctaxQCAKMJgKoBOZnZBoJpvZ9rD29daBehixQBxYj6OH00X5n8iw== 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=WKvk8bsSXpMlMC26dyda5yn3mBdLJJBTHbIKxZ+AZJY=; b=LseeEHx1mTl9HQ0rcrEE1JDm/E6DNTDcF8hY968p/t3O6nmRx9VJPvW5mQZt0W/MgUA8Ap3it7lditGN6dpQB0f1MFZ9xCSfNwu0+WUj0RP/H4TA1LRtN1GJvBr38f7ljRMSMzuGi4A/j6xf16QRIRfypMl5EBYEpe6dvlPRDfdHm9CNe1OYKUGqGK18pxc7mwBeHN/V3v7I2eAr6sJqfKINphZHjpTTvAsEQgnMWOgP7/3PLyFxsXot0VPEd+SfFSIxczPUm9nBl8ttaCIpfqUeB1KgdI3Wc+OTkTTc9vR8gctcwNQ8J8Xpko7qSkEPwaAq3rIKI7vFtlmwyovLEQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=davemloft.net 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=WKvk8bsSXpMlMC26dyda5yn3mBdLJJBTHbIKxZ+AZJY=; b=rNwk/Kl+HtPz1mxhpQztE4r1UxelbEUeAhHoVjzzU7v1njZADdR5e+lJh+nptd20sLZL+5GKEAv6t00ilcW1Jb0DGXwgF8K0jfDJuISlx7y81c49tH6eq9NPzgEbxw8ry7ex4QI05ZTArPOp1RBYc6tr5qaNpdA6ZsXbHRQ6rdBrJ1Bq7mZXM02jsfWVDg/Zae1bztNV3SHuPbVT4VEWHRPWGwPQfDz+MEvodfZWmTfgLOnxf5v7+G2aCX3LunnO1q0+YZt9Q8I1x9S4B1QROg5YZAdoMkiaFqebd/f9xvhBqCim8heeVJ/QneLHV5/ACXHFh7xft51qujlEJ89LUQ== Received: from CH0PR04CA0012.namprd04.prod.outlook.com (2603:10b6:610:76::17) by CYYPR12MB8856.namprd12.prod.outlook.com (2603:10b6:930:c0::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7472.44; Mon, 22 Apr 2024 15:29:35 +0000 Received: from CH2PEPF00000145.namprd02.prod.outlook.com (2603:10b6:610:76:cafe::4b) by CH0PR04CA0012.outlook.office365.com (2603:10b6:610:76::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7495.34 via Frontend Transport; Mon, 22 Apr 2024 15:29:35 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) 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.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by CH2PEPF00000145.mail.protection.outlook.com (10.167.244.102) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.19 via Frontend Transport; Mon, 22 Apr 2024 15:29:35 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Mon, 22 Apr 2024 08:29:18 -0700 Received: from localhost.localdomain (10.126.231.35) 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, 22 Apr 2024 08:29:13 -0700 From: Petr Machata To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , CC: Ido Schimmel , Jiri Pirko , "Petr Machata" , Alexander Zubkov , Subject: [PATCH net 7/9] mlxsw: spectrum_acl_tcam: Fix warning during rehash Date: Mon, 22 Apr 2024 17:26:00 +0200 Message-ID: X-Mailer: git-send-email 2.44.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail202.nvidia.com (10.129.68.7) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH2PEPF00000145:EE_|CYYPR12MB8856:EE_ X-MS-Office365-Filtering-Correlation-Id: afca5b89-ead3-4950-277a-08dc62e103ed X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: DnddqTMoSA2WxJ/Fg88Rnmr3ZOXVNy+1Gh6T2RhmiZix9fxpWt5Oa4KFF++loIRJ1LIn5iZ/65+TubxTQPEZVejP3n5VVN7rWKUL6/l8f0U6IePODMYx/kbKM6+s7jTTOQR0LKu5NzZeApBrSw+3jQ12yhYxg7lQ1p+yRkxT7BNpjCdT3HbdLSlU8f7LcE4ZD2J/eTAiZ15e31VdCNxOLOzSzkwqyLcmOj1XYPBGhnA8FSWCfvrZ05GBSBApg+LPmQ7uYK3PSLXnDne/lGAeWX8KTa9akfGhZ6OHZfbg4awvYaCenGRimmx6d5ISmPyUu+8gG9KPR1zlCahjWYjN04r9w9FTypBU+5bWc/1T6rCU4LW6NRdM2qmgcl1ajnF5OvsMS03wDlMADcqOPPqDbCHJGB/UjEKYETWFsZVhsn0dTh3BzrG/TFibIMZuh7ZsHeEiRZ4kD4srSifjhn6fXrRW6LdMp2tiRoYUHCz/5twl3lmHx8dFpvxQzupuwHeKYatVmmteRZjTRWZOY303CTlKNxsIu2eQksnTmTq3DxeMgQqKmTg/tfd1uBO45POvanOiYpi4GkLQzvepSE5cgz5rEMSRHBpRK7TlHXSNt/8cuEC9vPy+TApWv0hKq8KFG+61Sar9ysDZ0kquPCwl9kUVjSEO9bT8lc7JmeAvQNjF2TY71PoHPJEu7saEN9PXKDRv5GWTgmlmGKw5RoEX8I1ori29oUbdA4R6GuFIBQdqgNZ3olfD3RmoU0ENlXS38B5wtOaoyviVg+j5vr86DjXp+DZAp0QMGqLtY8LhaEIMmpnTrH8aFsV3wy5T45Kh0mlUPfkzlcHvH1YzRej/9efMq02tF/FEKuUHSGhdqpbQ7s3I+w9YKWZR0roGut018Z8VZ/EFdNe+LTrvrlSAPzxfpDPMmQgYwPGKjI7K/GzL1CDLw6M9JUftRu1rYqUJ7jwykzuMUs8ExljiYZ7CUChZkYt769X+KlQLM6UXVLt9ffasw+7GEv5uCGQFMCZt428wGeEkG9+4SBt4FI7uDkdKN8B0F63bzSbtALw50zLaC40uX7wviR6fPf8USf+GrNwLC8EJ+94XN/M6/p6hCbIvT9V8ev6qClHH+2h5dKJT8hxrS3t+SGTbUYU4h2M1oeYLJ6rCT+tL3oUA2AmxBzer8Z/QPoO4ComGTI6Mx1WgYZWm9bOtNrUj+6RNX024tvOk2vb3Sv3lqmPIoKRVlFJclI9F/jozwbIowPW69myazXyRzfCKABP3WHzPVmOyWPAifiod2RjRtlLn90iCUP3JZLVroythOOdyJVCw7arWV9U4PbyEwpkyM8wzvoD8XLfOUXxRegrVc8Me0INS5Omg3psYn6CS9pJsmL80WL4= X-Forefront-Antispam-Report: CIP:216.228.117.161;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge2.nvidia.com;CAT:NONE;SFS:(13230031)(82310400014)(1800799015)(36860700004)(376005);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Apr 2024 15:29:35.1242 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: afca5b89-ead3-4950-277a-08dc62e103ed 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.161];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CH2PEPF00000145.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CYYPR12MB8856 X-Patchwork-Delegate: kuba@kernel.org From: Ido Schimmel As previously explained, the rehash delayed work migrates filters from one region to another. This is done by iterating over all chunks (all the filters with the same priority) in the region and in each chunk iterating over all the filters. When the work runs out of credits it stores the current chunk and entry as markers in the per-work context so that it would know where to resume the migration from the next time the work is scheduled. Upon error, the chunk marker is reset to NULL, but without resetting the entry markers despite being relative to it. This can result in migration being resumed from an entry that does not belong to the chunk being migrated. In turn, this will eventually lead to a chunk being iterated over as if it is an entry. Because of how the two structures happen to be defined, this does not lead to KASAN splats, but to warnings such as [1]. Fix by creating a helper that resets all the markers and call it from all the places the currently only reset the chunk marker. For good measures also call it when starting a completely new rehash. Add a warning to avoid future cases. [1] WARNING: CPU: 7 PID: 1076 at drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_keys.c:407 mlxsw_afk_encode+0x242/0x2f0 Modules linked in: CPU: 7 PID: 1076 Comm: kworker/7:24 Tainted: G W 6.9.0-rc3-custom-00880-g29e61d91b77b #29 Hardware name: Mellanox Technologies Ltd. MSN3700/VMOD0005, BIOS 5.11 01/06/2019 Workqueue: mlxsw_core mlxsw_sp_acl_tcam_vregion_rehash_work RIP: 0010:mlxsw_afk_encode+0x242/0x2f0 [...] Call Trace: mlxsw_sp_acl_atcam_entry_add+0xd9/0x3c0 mlxsw_sp_acl_tcam_entry_create+0x5e/0xa0 mlxsw_sp_acl_tcam_vchunk_migrate_all+0x109/0x290 mlxsw_sp_acl_tcam_vregion_rehash_work+0x6c/0x470 process_one_work+0x151/0x370 worker_thread+0x2cb/0x3e0 kthread+0xd0/0x100 ret_from_fork+0x34/0x50 Fixes: 6f9579d4e302 ("mlxsw: spectrum_acl: Remember where to continue rehash migration") Signed-off-by: Ido Schimmel Tested-by: Alexander Zubkov Reviewed-by: Petr Machata Signed-off-by: Petr Machata Reviewed-by: Simon Horman --- .../mellanox/mlxsw/spectrum_acl_tcam.c | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_tcam.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_tcam.c index 0902eb7651e1..e8c607886621 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_tcam.c +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_tcam.c @@ -730,6 +730,17 @@ static void mlxsw_sp_acl_tcam_vregion_rehash_work(struct work_struct *work) mlxsw_sp_acl_tcam_vregion_rehash_work_schedule(vregion); } +static void +mlxsw_sp_acl_tcam_rehash_ctx_vchunk_reset(struct mlxsw_sp_acl_tcam_rehash_ctx *ctx) +{ + /* The entry markers are relative to the current chunk and therefore + * needs to be reset together with the chunk marker. + */ + ctx->current_vchunk = NULL; + ctx->start_ventry = NULL; + ctx->stop_ventry = NULL; +} + static void mlxsw_sp_acl_tcam_rehash_ctx_vchunk_changed(struct mlxsw_sp_acl_tcam_vchunk *vchunk) { @@ -752,7 +763,7 @@ mlxsw_sp_acl_tcam_rehash_ctx_vregion_changed(struct mlxsw_sp_acl_tcam_vregion *v * the current chunk pointer to make sure all chunks * are properly migrated. */ - vregion->rehash.ctx.current_vchunk = NULL; + mlxsw_sp_acl_tcam_rehash_ctx_vchunk_reset(&vregion->rehash.ctx); } static struct mlxsw_sp_acl_tcam_vregion * @@ -1220,7 +1231,7 @@ mlxsw_sp_acl_tcam_vchunk_migrate_end(struct mlxsw_sp *mlxsw_sp, { mlxsw_sp_acl_tcam_chunk_destroy(mlxsw_sp, vchunk->chunk2); vchunk->chunk2 = NULL; - ctx->current_vchunk = NULL; + mlxsw_sp_acl_tcam_rehash_ctx_vchunk_reset(ctx); } static int @@ -1252,6 +1263,8 @@ mlxsw_sp_acl_tcam_vchunk_migrate_one(struct mlxsw_sp *mlxsw_sp, ventry = list_first_entry(&vchunk->ventry_list, typeof(*ventry), list); + WARN_ON(ventry->vchunk != vchunk); + list_for_each_entry_from(ventry, &vchunk->ventry_list, list) { /* During rollback, once we reach the ventry that failed * to migrate, we are done. @@ -1343,7 +1356,7 @@ mlxsw_sp_acl_tcam_vregion_migrate(struct mlxsw_sp *mlxsw_sp, * to vregion->region. */ swap(vregion->region, vregion->region2); - ctx->current_vchunk = NULL; + mlxsw_sp_acl_tcam_rehash_ctx_vchunk_reset(ctx); ctx->this_is_rollback = true; err2 = mlxsw_sp_acl_tcam_vchunk_migrate_all(mlxsw_sp, vregion, ctx, credits); @@ -1402,6 +1415,7 @@ mlxsw_sp_acl_tcam_vregion_rehash_start(struct mlxsw_sp *mlxsw_sp, ctx->hints_priv = hints_priv; ctx->this_is_rollback = false; + mlxsw_sp_acl_tcam_rehash_ctx_vchunk_reset(ctx); return 0; From patchwork Mon Apr 22 15:26:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 13638632 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM02-DM3-obe.outbound.protection.outlook.com (mail-dm3nam02on2059.outbound.protection.outlook.com [40.107.95.59]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0DA7C153810 for ; Mon, 22 Apr 2024 15:29:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.95.59 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713799788; cv=fail; b=FI4DDpFrFdIfgnApqU4wNd7GkjxPlmHVplLkZtbon971dp7QAYAQoufavkDZ6C53BB0MQ2z5rkcZf0vsnz68vU3rsQT21puNZr+UtVJgd+xOaRPTn8S1CqnOwr9VQ9y86BHr+f0pRlkqL6Ti0BfY+SZ7X4pY5sZeR4rBKYBIPmU= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713799788; c=relaxed/simple; bh=gUVrZvQDXnXucZiRSrCtcJ+DObdZST7dTwrT3+d2q5o=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=MoB5UApZl4QRZfvBLUwuBaxUpP0oJWVr9W9tNCc3JrY4dRQgUEsXR7ExvgzvIDx3Z4dfym53QBwKpCvM2jB+c78Z85bLqEMLhhm4beD9np2P7VYNguYEmciT6hhJHYH3wtcEwMfadPU8OiNoLCdgxoWqPnDMWxuneQY/mY4PlZs= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=RLNGok/F; arc=fail smtp.client-ip=40.107.95.59 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="RLNGok/F" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FaEpu0V7BOT2a6SzQUyx6bpejNoScmdat3C1fTuCOTiQ4Ux3VWwF+1ivV26qNs1aEz/ZCpuJ3DF/pwChODh7VIZtaZsYQYCbr5TAX4kx9q+RvqTa7E1wONHeqNHGGLp/gDmDPkuCEZ4i2td81sRjLrEIn6t+4QSPTdYhmv1oIH5oEO2th6jqgkklbkd/M23k/W6iBYlb/ssBE05Y6LNYg3KgzR37zroJeK9xEJFTd5aO5FKDW0+1L34a/IF07pQr0ZeZp36Rn4GqAvIekgRmR7ks9xYf9cOj7iZxh19EBKzuJa0FoZfGZ+WjQdDNEambzLb0Hz/7pboo9gZEDLHKDQ== 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=Xul+xZ1OnAj39+584nWmWL7301ymeXai1i3cUjK/0Ak=; b=BcyuWI+Hm2HV9Lt8lQr0Yg/nMenJzmJ5gRcrOhi29pVtjSgWYHIexN9kt4BMNb2bE1Euzzk5y5CXZhy92K3/DJ7449FVGuW1ica+e0Jno01DfuSXH/L4StvD1XDUsJbhOf6oc9XrdCnBrV0GRBMBu3eBO/hVgt9CVKjxeYkKURPyut9CBYZCQUZ2OxlRpnOKexvlEHKGvKEyqyKGhLPgCTo50YdDJ87bNkAHzqckpdGTgOa78jZZpWj88Mdj4M2Kp9ZX8LpoIHhGoUXb16dhg5t95e+3UwMOL7LB/FM0S5sIMW7yDoZGcG6GfCOOW5uMRk/YVD+kDfCx6uimONMVoA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=davemloft.net 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=Xul+xZ1OnAj39+584nWmWL7301ymeXai1i3cUjK/0Ak=; b=RLNGok/FtlrTsjR75ANZQAhgV8aW5t/c1slkSuVomLrZajY1A4Tsf30Wpuue1vzkbXRK+y+sOlldge98saYFcu8TbRA5QX6tJM1ksYwMjxNb6E20zHVqv5OAvfSmVGIYozRptsGp+NXZdurbuUc1pZf/t+U0e8VVJTqRv+D0dAGu6+8zL4CEuADIF0LnaSxh5300OF/vlVwBiGOm7qXeL3bdD0Tpwg6XVV5hHvN+SkOR31Vtrby/f3uFtfxSgM3q5/7zOe9ZZwaKOnNiMyP0VmUJ92c5E9nGKAl1p1Pq9XAmmvuJx7uPteJ1C2vPoUEg48SN6vBTSFkanKSuk6VPFQ== Received: from CH2PR03CA0018.namprd03.prod.outlook.com (2603:10b6:610:59::28) by CY5PR12MB6407.namprd12.prod.outlook.com (2603:10b6:930:3c::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7472.44; Mon, 22 Apr 2024 15:29:40 +0000 Received: from CH2PEPF00000146.namprd02.prod.outlook.com (2603:10b6:610:59:cafe::d5) by CH2PR03CA0018.outlook.office365.com (2603:10b6:610:59::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7495.34 via Frontend Transport; Mon, 22 Apr 2024 15:29:40 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) 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.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by CH2PEPF00000146.mail.protection.outlook.com (10.167.244.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.19 via Frontend Transport; Mon, 22 Apr 2024 15:29:40 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Mon, 22 Apr 2024 08:29:22 -0700 Received: from localhost.localdomain (10.126.231.35) 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, 22 Apr 2024 08:29:18 -0700 From: Petr Machata To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , CC: Ido Schimmel , Jiri Pirko , "Petr Machata" , Alexander Zubkov , Subject: [PATCH net 8/9] mlxsw: spectrum_acl_tcam: Fix incorrect list API usage Date: Mon, 22 Apr 2024 17:26:01 +0200 Message-ID: <4628e9a22d1d84818e28310abbbc498e7bc31bc9.1713797103.git.petrm@nvidia.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail202.nvidia.com (10.129.68.7) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH2PEPF00000146:EE_|CY5PR12MB6407:EE_ X-MS-Office365-Filtering-Correlation-Id: 011a38dd-e0d4-4893-09a3-08dc62e106dd X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: D1UtyFqeEjY6q7D8BLNprJDrXqIo6q3ginvszae7G+ivjp30OtlbWq+l8J0pMilhfRkv4DW0bCEGqXjwYAb8detyKlHzu2jR/3+P3YkWuj6/EyuTdgqZS9IgzFlVcT0B4Bon+yw8F7JNXlmkLhjqzpyTiTwpac6LXEyTy5gj4jQ9QxiGmZnLHFE1xGUZqFh80IAWX6hVFJarUazjnvOeX0PPFDi1JIG0wvztt+pr5+NB9dvY9r98Ab8brptK+/5WXmBxKdWo1GypJ/E30T9nJAQeAtcKZRpYedzbP8wl4RoV/bL3LBImOJi+ac2woBZbhy6Gsm9tlDM2m5TD0XgAzG3vzDBkHH8oRD1eKLSssOQX7G+edJ+aVfZIItgrJquqxe3JbOasbtk780+qT+/JECJD6BChp8CjOcK3fp+IjCt0AjmP++STVwM1dgggvT+fdV7kuHW30g5DSbi4v3+oO5I8Zidg0JjI5aTT+sc5uiP+rhQi3OWp3Ivnv5lMM5Xg08thF7Ln3/KkZc2FP/Po+dn3OrAJtGH5brpGhhPkeXLwuTcvopDaBZ8SUw9Nwp91L8olbxhuIfD9xDQdIM85b+Ju3GalOTyihyk3bQ2EajfZB7V1ga7G0xRQO+MRuuK4R2uU+jDFvuF0xdayXkfpTDwQprPvQPZik1qnyb0Hs70bKu+5zJuz1xUVKDMbsAN3AQHmB48ZYWEbXZI5Kwb6o9xR/QTEpCFt+44cxYhBVzLxC7/BG5utqMN/OY3aVLl7shfoXeBsvbKuTeTLEcshWyaSrxOPIOmLUSurkmHqIfjkwhymbl8EsgUuHZ1nAc4zDDKRF3aOUByzrHiHfroCaIju8zpDLFKZziUhfbY8I+Mfsc96uOGWpOY9+PfRU3dLdKouyxEJJ5aeNKQtilk9YHnP5Jlpmt/30xsvfwXbG3i9qF0DiLbtJJ0JEvAHoVIpd8xLK4McjDyGnLz06WlpC3TDLeN4zeaS7EZggbI1r5FW8OTKUQJDiolGHHXaQ7hDoQos72jMaILFphVei3+S9GXosbHSPWYC+cJ3/9uFXo3leOhEGQ7L8IctapMdRAD0dCBlvSWA5k0jeU+osPK5UF/+S3aj2VrqqBRUZxps3/Th+qZ+3QKqTOVHu2rmQsQ+HyfWmbvIFylLvt7cxt3G+mdEtFfM4iRXdeB7S6nL9Ajr1TyN9auosLvkNKIotZub/Ora+j2zvAcnPYJUX5LciUmpvJIkIfNtbanK14P/Ze8lco2XkBNr16HHECzmp/8A5b51pjhOsNh1zTSrUD+FdrWS9aUynJ5AY7kaFULru/5odCAHljL22wPSX4veN2s8xIp2uxqiicDeyolxjCVsu7hZLHKhkRgtle+q7ZO5PUjP0C1J5qLdA9uEJ/SaWGZb X-Forefront-Antispam-Report: CIP:216.228.117.161;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge2.nvidia.com;CAT:NONE;SFS:(13230031)(36860700004)(82310400014)(376005)(1800799015);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Apr 2024 15:29:40.0361 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 011a38dd-e0d4-4893-09a3-08dc62e106dd 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.161];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CH2PEPF00000146.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR12MB6407 X-Patchwork-Delegate: kuba@kernel.org From: Ido Schimmel Both the function that migrates all the chunks within a region and the function that migrates all the entries within a chunk call list_first_entry() on the respective lists without checking that the lists are not empty. This is incorrect usage of the API, which leads to the following warning [1]. Fix by returning if the lists are empty as there is nothing to migrate in this case. [1] WARNING: CPU: 0 PID: 6437 at drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_tcam.c:1266 mlxsw_sp_acl_tcam_vchunk_migrate_all+0x1f1/0> Modules linked in: CPU: 0 PID: 6437 Comm: kworker/0:37 Not tainted 6.9.0-rc3-custom-00883-g94a65f079ef6 #39 Hardware name: Mellanox Technologies Ltd. MSN3700/VMOD0005, BIOS 5.11 01/06/2019 Workqueue: mlxsw_core mlxsw_sp_acl_tcam_vregion_rehash_work RIP: 0010:mlxsw_sp_acl_tcam_vchunk_migrate_all+0x1f1/0x2c0 [...] Call Trace: mlxsw_sp_acl_tcam_vregion_rehash_work+0x6c/0x4a0 process_one_work+0x151/0x370 worker_thread+0x2cb/0x3e0 kthread+0xd0/0x100 ret_from_fork+0x34/0x50 ret_from_fork_asm+0x1a/0x30 Fixes: 6f9579d4e302 ("mlxsw: spectrum_acl: Remember where to continue rehash migration") Signed-off-by: Ido Schimmel Tested-by: Alexander Zubkov Reviewed-by: Petr Machata Signed-off-by: Petr Machata Reviewed-by: Simon Horman --- drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_tcam.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_tcam.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_tcam.c index e8c607886621..89a5ebc3463f 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_tcam.c +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_tcam.c @@ -1254,6 +1254,9 @@ mlxsw_sp_acl_tcam_vchunk_migrate_one(struct mlxsw_sp *mlxsw_sp, return 0; } + if (list_empty(&vchunk->ventry_list)) + goto out; + /* If the migration got interrupted, we have the ventry to start from * stored in context. */ @@ -1305,6 +1308,7 @@ mlxsw_sp_acl_tcam_vchunk_migrate_one(struct mlxsw_sp *mlxsw_sp, } } +out: mlxsw_sp_acl_tcam_vchunk_migrate_end(mlxsw_sp, vchunk, ctx); return 0; } @@ -1318,6 +1322,9 @@ mlxsw_sp_acl_tcam_vchunk_migrate_all(struct mlxsw_sp *mlxsw_sp, struct mlxsw_sp_acl_tcam_vchunk *vchunk; int err; + if (list_empty(&vregion->vchunk_list)) + return 0; + /* If the migration got interrupted, we have the vchunk * we are working on stored in context. */ From patchwork Mon Apr 22 15:26:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 13638633 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2052.outbound.protection.outlook.com [40.107.92.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0190915383B for ; Mon, 22 Apr 2024 15:29:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.92.52 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713799793; cv=fail; b=YPRAAp9eGI3iY8LRXawSUHCrKfY8MkK/opyhj9/msJRv8lDkf4UkYgcMMAZwPvNlqFhIMeSmJfV9kFQalK/PibIewv1wY7LB4H2JoGgEHeqxqBlxgYuAWT2i57XQbr2Z2zLwr2B1q6e7W/JfFC4TSElu3v+xMny4AXu3AY/v8DQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713799793; c=relaxed/simple; bh=kycO3wzgPKr79zKnJOsnx0tq5Ho10tnjOFmYIXX18WU=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=pOv5sX4iCUJedDvAscblr7EqOksaiwzlgjSiEgxExvKhJmVuUfZBKGd05D7SJ1hfZlQlX+POD1w6qPfodGocQikVBWigluc6YVGAXhbcat3vjrDZRNYE/rcXc2nehTOgZ243Se3FXV1KPtEMk3ZsyEMv+6AbMyw5TXQjwjlDaWM= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=YvIJgnpi; arc=fail smtp.client-ip=40.107.92.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="YvIJgnpi" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WliDZmC1Ua+IG+rof3NI3DttEEQWbJJjMUiAGRhK1EPqiWVcm4wy4RDGzu3m66eKp7tNFLbIrYD9cXZ7Gp3pBD/15Y9/Ai7S2ubGZ5E1OworUGTDpz7vzcRuadPRak+hudNg20UtTA2KJEwKUTwuzKN0OfDBeSnZR91kJAMAl4P/7oYIy1Ns20EQ8hrRYTiso3Tah7thickXdh5D1dT4MvCkJdpG9EkPWhLfXJvp1p82b1KCC7MrVlYd9pfS4ET9I/KHoA1E7WJ88NL30SrJEjqxL7qFWcC1N7xVtZyBIdbi7JCwkd7yIALGwRLjsOBirKLHsDC8+UyIlXR4pH0pGQ== 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=8hN8e89IfU0aP/ig1Le0jAO6LS7szZchFvutIdoVRBg=; b=Qjepa2PLwBtcLIsM4yJlxH2yZ40vetigIojWjCcT1vMZzXDsGabhB/J9DV/KMIYj5LOfqEGzrF5LBlcsInoYNXTvf4yCCZNwIIYTxphHWCg/b4nndnTn/AlSpKp+5rnn5MDViAuJLRdiUikUOqTnfiyPSKUBRf6jgIUDqXICWVWyjWTmK424+Vz9pwTsaAZh891B7s9OvhTmrgeHIwnWakGL73nDNUzLdAyIyYrN47ne9slnp7JTV8kZQseFQ9CQ6CZ4yRsgnv0jXEfroiTUH1AWzwAJNNeLFAmHI4RrhmgvAwjyoq9cGMshjsV2R3B1KCWQ/7MPfTY2MOBQy62zHg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=davemloft.net 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=8hN8e89IfU0aP/ig1Le0jAO6LS7szZchFvutIdoVRBg=; b=YvIJgnpiHnt0N6z8ttxVEAX1gbLbc3l+JpbogTZdq8JNNAENycoLHTEbeeIm96YQNBsIIPSS35er8O40VND5Ux+7IamFLupLnwWXHUQR1yf3PZFpD6VH+XinxL3KWqR2VX2N6kUk8tYxKrjQke604fh9ZlE/zztxo3vhYCOp2VTfKE71qWhO6+eaCRA/dSvDlyIVwUfWG4ktoRdjRM8XaXWgSFBZ5oaB2YB4GTHmKZ4pu8alPJrU3r8WL2wNtLhLYvVoUwO1YHic9nhvCvCkcTXNUPnd/4YOqHd6px5uf3oDCCkatxag2re7wwIk2ASUSTB1h1/eX3FOrp4gUFP1vw== Received: from CH2PR03CA0018.namprd03.prod.outlook.com (2603:10b6:610:59::28) by SN7PR12MB8790.namprd12.prod.outlook.com (2603:10b6:806:34b::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7472.44; Mon, 22 Apr 2024 15:29:44 +0000 Received: from CH2PEPF00000146.namprd02.prod.outlook.com (2603:10b6:610:59:cafe::14) by CH2PR03CA0018.outlook.office365.com (2603:10b6:610:59::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7495.34 via Frontend Transport; Mon, 22 Apr 2024 15:29:44 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) 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.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by CH2PEPF00000146.mail.protection.outlook.com (10.167.244.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.19 via Frontend Transport; Mon, 22 Apr 2024 15:29:44 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Mon, 22 Apr 2024 08:29:27 -0700 Received: from localhost.localdomain (10.126.231.35) 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, 22 Apr 2024 08:29:22 -0700 From: Petr Machata To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , CC: Ido Schimmel , Jiri Pirko , "Petr Machata" , Alexander Zubkov , Subject: [PATCH net 9/9] mlxsw: spectrum_acl_tcam: Fix memory leak when canceling rehash work Date: Mon, 22 Apr 2024 17:26:02 +0200 Message-ID: <0cc12ebb07c4d4c41a1265ee2c28b392ff997a86.1713797103.git.petrm@nvidia.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail202.nvidia.com (10.129.68.7) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH2PEPF00000146:EE_|SN7PR12MB8790:EE_ X-MS-Office365-Filtering-Correlation-Id: 33015e04-2ea1-41df-15a0-08dc62e10950 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: DSB3dPyrkVUBowYPHv2s964T5Efo0VtqwGJ5wmagg8blJqEkvsLLX1gD64bi9AbX+7RnpZa+7tY8mCUV7UVWA8WXO4Mzlhf3ORKPNPZqQ/FXljIXAScRJvmWi6OYzXZ2ofFwOZ99yjbSdYGzM8MeFDEAMlx2y8ufWp7pROwzyK4wAnX4z1B9eAs06su6jF97mlZK9hrkRQagFshfwFST3xcpwgmNZZXnaUpt6nJL9PSlmYQ4e3YwVomMd/MNtPnp8p9HbgoepzH3BVAS+vDKLWI41/EtqDi7T+GplFPJY25yJwZ8FLUCxMLt1Sc4g4PoNSnkPtIcF4kE0FuXdsrLjsw/wYCN5utN7fQs3bL2Bgmnbj1/6X6MqlYJcN3bA+9l0ee3auihJSzWVj+ZN7jRNW+sM7jsB0R20OymScLED4bChVXtq58MIznP5gR7Z+8y3TN7yzwTUfNAxWMUBhcAdnk6/P4rHtEly0g4nhVJnpaJcQ9u18Tm6k/5qucys82uG/ZmtWHpdJ5zJN/5Bt+rMkGWGdd2GgeaDYDXhG4pnm4k3w3g0MtGoO6DSHmeBufJNnFFknIA2Ukk98ZoqIY8bDqDTuLpSwx4/Agzd7Ox4xt/xRDyBch8Mh3nxNPK/alAYu6XpXaWm5NWayevs1b8Vr8xdNnxW0TyrJGIQnjcyO8Wh1JiSokJIUC5JzbPejVFPbk5InZL0oKwVwpMEIhDy6Z7AHZe9eRpz6aZZbaOUolkTrzuoWnmONa/gh2CyKTxUO/Im83o7yh7xoOqDaFd0ERUHJ6e+6KAEdQ8rd3DJDO/HWElsw4AruUkxmfwZoY+qxV8GC4VsZPtt/eRgNjbgDQvYrkUH6LrmO507UewxiGNeRHUwx9b78zRMdCZH7qNPo8VXb9mqZKtQIYubOy1lCehEmk1AIR1qXXfzsdyce910p3bhwZsma4XVnU54mHWegudrozkOPBfoYvSd0f7FolJ/X0zzmX7V+ht9Le4ZZnyv5CXFUiegt36WbQb4YLbc+oAe4AFf3mUPb0BR19zCiVeHPCLuP+orp2Yc2cDt9+cnkls3ctB5EgzJcZ4msXsyFjRblg5IXEYo0hLpaMKzHqKgHITy7FHU9FwM8sfZ2Xh8+YGlyhdsEoWk8ltnf1lLfI4yY/0spVK2FlGNhC3azMjFZ4x9GPX3GXqUJAG9RsyXtFzrdcxtA/aesCwNcr7YURL+UlPbzg5d2cpJ4JkmQ346PbmAlTxflts4frjQe4ehLffm1eUrFJiuwy/ALp2RmgKeUoaXd5dwfK6WuPPZnknbfjOMTfiEc6AkTl+ZeasWxAejA7RC+/kjvnbTKliAC+uLTirsUnZb8W3DOog3rIJFOXb+x4NeMuL5Ujj4tepT0WoPUHkHNnUgkWk9CS/ X-Forefront-Antispam-Report: CIP:216.228.117.161;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge2.nvidia.com;CAT:NONE;SFS:(13230031)(36860700004)(82310400014)(376005)(1800799015);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Apr 2024 15:29:44.1612 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 33015e04-2ea1-41df-15a0-08dc62e10950 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.161];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CH2PEPF00000146.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB8790 X-Patchwork-Delegate: kuba@kernel.org From: Ido Schimmel The rehash delayed work is rescheduled with a delay if the number of credits at end of the work is not negative as supposedly it means that the migration ended. Otherwise, it is rescheduled immediately. After "mlxsw: spectrum_acl_tcam: Fix possible use-after-free during rehash" the above is no longer accurate as a non-negative number of credits is no longer indicative of the migration being done. It can also happen if the work encountered an error in which case the migration will resume the next time the work is scheduled. The significance of the above is that it is possible for the work to be pending and associated with hints that were allocated when the migration started. This leads to the hints being leaked [1] when the work is canceled while pending as part of ACL region dismantle. Fix by freeing the hints if hints are associated with a work that was canceled while pending. Blame the original commit since the reliance on not having a pending work associated with hints is fragile. [1] unreferenced object 0xffff88810e7c3000 (size 256): comm "kworker/0:16", pid 176, jiffies 4295460353 hex dump (first 32 bytes): 00 30 95 11 81 88 ff ff 61 00 00 00 00 00 00 80 .0......a....... 00 00 61 00 40 00 00 00 00 00 00 00 04 00 00 00 ..a.@........... backtrace (crc 2544ddb9): [<00000000cf8cfab3>] kmalloc_trace+0x23f/0x2a0 [<000000004d9a1ad9>] objagg_hints_get+0x42/0x390 [<000000000b143cf3>] mlxsw_sp_acl_erp_rehash_hints_get+0xca/0x400 [<0000000059bdb60a>] mlxsw_sp_acl_tcam_vregion_rehash_work+0x868/0x1160 [<00000000e81fd734>] process_one_work+0x59c/0xf20 [<00000000ceee9e81>] worker_thread+0x799/0x12c0 [<00000000bda6fe39>] kthread+0x246/0x300 [<0000000070056d23>] ret_from_fork+0x34/0x70 [<00000000dea2b93e>] ret_from_fork_asm+0x1a/0x30 Fixes: c9c9af91f1d9 ("mlxsw: spectrum_acl: Allow to interrupt/continue rehash work") Signed-off-by: Ido Schimmel Tested-by: Alexander Zubkov Signed-off-by: Petr Machata Reviewed-by: Simon Horman --- drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_tcam.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_tcam.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_tcam.c index 89a5ebc3463f..92a406f02eae 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_tcam.c +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_tcam.c @@ -836,10 +836,14 @@ mlxsw_sp_acl_tcam_vregion_destroy(struct mlxsw_sp *mlxsw_sp, struct mlxsw_sp_acl_tcam *tcam = vregion->tcam; if (vgroup->vregion_rehash_enabled && ops->region_rehash_hints_get) { + struct mlxsw_sp_acl_tcam_rehash_ctx *ctx = &vregion->rehash.ctx; + mutex_lock(&tcam->lock); list_del(&vregion->tlist); mutex_unlock(&tcam->lock); - cancel_delayed_work_sync(&vregion->rehash.dw); + if (cancel_delayed_work_sync(&vregion->rehash.dw) && + ctx->hints_priv) + ops->region_rehash_hints_put(ctx->hints_priv); } mlxsw_sp_acl_tcam_vgroup_vregion_detach(mlxsw_sp, vregion); if (vregion->region2)