From patchwork Mon Jul 8 14:23:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 13726664 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2072.outbound.protection.outlook.com [40.107.237.72]) (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 A9A9178C75 for ; Mon, 8 Jul 2024 14:26:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.237.72 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720448812; cv=fail; b=GOuLyQmwCRcz3aZ3Jh4E7XDJpX9B8A4RYgrOrhk8FCwF9iX3SdIoqr/ZJsU3U6tO7f4hRgNVavJ54IJvZaVxcuVtGQmmxR0OmTqGgt1KqpsMOpSZ4xl6jVGgcOq9JRyq7xJbXFzltiwUUvHXuPNghWzB+3xTm4Zp0A0sprS7EqE= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720448812; c=relaxed/simple; bh=N5sMfDbtA4gHxegq62Rv9X736i8B8UGV6QzOCMEUWrM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=mYp2ivYZxH7jifuf2bw75Qn4IonDcqY8sOxHq50LrFJhgTg8LREz/rM66kVKQBaBrt/N//66MrpToYc05Jqy8rL3PBTnc4iBmxexbtTRUbNTxo9BIGRE23LZVOEG324/wNup0c9gWVhqP8TKC9dF/pE458gjyqDXI+qhy+bNqMk= 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=riT2IpCw; arc=fail smtp.client-ip=40.107.237.72 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="riT2IpCw" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ONjKTUzOPkCDdGvjrir5p+sikE5Q7ACwoYXpXBNIW9EDfSby3h5miVgdABVWtc2nZe2W3pnIoOd//TJcCqaOZaqYxOiQd6oMp8TNYw6OJPmTA10B+pj/OmTdJSi7Lgt71wTgzYMU19RB5p9D3lwUNu748nChqilw1SMdhZ3JtAb5brPdRg112iwC5McgFpDVJrccCkOi5aF/gXxOGf27hwLf0LFoJtOkw/lpDG3AOwYstiEVerOISRD1Uge74TjgyPtgikOyMUIvZc7bxY2qUFTXDZ8qonnpnjjzTkAzyqD4cDih5a/k9hw6Tesru3pNNJAXJ/kh6XcswlurzDTT9w== 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=N3E2qsYq7ZfrRI6LdJl7e3ON8xH0mY3qWoSuadfDx1U=; b=VoVDWCBbRyJRh5vuujUO12+YlPgqgHenQ6VoXTowVUdq6cTseTIvWcq25BKBHsXXVqzTRvr7fZ+6ye6Zqjs5xY8SQsrMjyvMBIEgO/fkktaM2YsMoJsdWakKqPD/DCDuyggAMIBC1r3C8Ja3yRQVuNjh3hDgwnopzFbBginNVMnOvYyilogJkbyPnwRqB2QonodSpQqCe7o89b2crG5z40BCx/q3uOTDA220k9RE1S3jVlutHOjNtVWoqt+qW18EQJZHyag0vir5Ib66C2VkUvmnj3tG9QQWZgLZbY+ruDhE+GHR3HKkjcMqz2rfV3JekhosFT8JNfEF/l5JfBpzZQ== 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=N3E2qsYq7ZfrRI6LdJl7e3ON8xH0mY3qWoSuadfDx1U=; b=riT2IpCwWLCNG2pMOxRICaIv4UHpCjIxKyGdBuG49q/rC12ZmL3++sBSWFt7RxhTxyFf9hOAKUsJjkCTW34BVWEsnbxkAWvttAqecLm9sAdooZr61NM9sTFst+s2iznh8O83Ap8gEFmnmhvC9W/20RlPC7KmmcI3j6NGA9xfWrzpq/aMyajGrRSGnmAfbfo/XPnBePPBjT5yjVnYbVTOJhZR4TkwPDcxI3rDcKLf6y2Fbsd0tN/bucHQFryLQ0rV2PJJlUb5Xl5sBjbv7v0ZqddYyaGnzzKEQcAgy6TmbCdGC5ClbYpmP/3CjKSOCQzvq8gD/8i9F43Hhr9huHzvTg== Received: from PH8PR15CA0015.namprd15.prod.outlook.com (2603:10b6:510:2d2::23) by SA3PR12MB9198.namprd12.prod.outlook.com (2603:10b6:806:39f::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7741.36; Mon, 8 Jul 2024 14:26:42 +0000 Received: from CY4PEPF0000EE3A.namprd03.prod.outlook.com (2603:10b6:510:2d2:cafe::d5) by PH8PR15CA0015.outlook.office365.com (2603:10b6:510:2d2::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7741.35 via Frontend Transport; Mon, 8 Jul 2024 14:26:42 +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 CY4PEPF0000EE3A.mail.protection.outlook.com (10.167.242.12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7762.17 via Frontend Transport; Mon, 8 Jul 2024 14:26:41 +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, 8 Jul 2024 07:26:21 -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, 8 Jul 2024 07:26:17 -0700 From: Petr Machata To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , CC: Petr Machata , Ido Schimmel , Subject: [PATCH net-next v2 1/3] mlxsw: Warn about invalid accesses to array fields Date: Mon, 8 Jul 2024 16:23:40 +0200 Message-ID: X-Mailer: git-send-email 2.45.2 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: rnnvmail203.nvidia.com (10.129.68.9) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EE3A:EE_|SA3PR12MB9198:EE_ X-MS-Office365-Filtering-Correlation-Id: 4cb6634c-c4a6-4b01-c20c-08dc9f59fc8c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|36860700013|1800799024|376014; X-Microsoft-Antispam-Message-Info: 4Isbu/RMWY2K8o6S9b6uH6jVZ3XJ43vjtF/0lFFbLQU/iY8ebZbNTehbE4GQHm3w6hqlOHyP2BDeg/yNAI3fO2hC7Bvr11aitDwlPdg+DC5XwVuC6XYzcquGXrp4FEr33PKzR2Pgub3XaBiC/1mVmvIKw2g7564yYuKe/+3gTH04kkw578nnp1UV1uctQKREKPu2NrhM8uatrueHSXdnO7jk099Gwm2uxgOSUkwTrJU4HlsUzLbiG5b0USVyG5R/VBnLoe1M4U5VciO0v6U0w26OID1J0IqimnjA1jKNM6e7+5kUhSCq2K+X7IxPnuBqpSYMpzIfaMcfTRZMzpteVVR0LbMao9iXYkNPInusjc+78l0iJhIuueCrFsqb4cV67OD6TjtTV3Wxd3KBMXE82819xbyxzHxf9G/O9XOaXaVk/U2J7CkWBZjKVJ+KE8sBiMM5dNHSj/pNtUl5crKiYEsAiqhqBxr0/YjA5DleIbwQOyIm6I5T1x+2xXazWs7g/Vx4Ef/RVe4yB3ca/DfTUEoFpZ6OMjva16qgsM+NbmwMqHcxSFeRxo6kDkANaSmUwtWv2VUvW6jI1uFZXD4VgyVdPlt4b7bxx4G+UKYo+riN4RkYcP2YC6NZL1xTHTHiD13NDkBMdBD1Z6amDqpnDnAygfvhxhB7C4OdqRE4NQr7J/nTmw078UHaQa/K5Z80iEYO5zdfqyTPXRbW5QTCSHQ7VbhXDGn3mFMFKMIMUqGd3SfZBLGkR71c9PM8quWjdV2/3QwbxslY+QKiNEiRCCe9FjQtKoZKCXA0JAx+G7B+zCvP8qa1KXiej9PYhU1D1HZ/BK0gYApQFtUsJExXc1n9aRe8+hOg2C7AsZtVG52EFrdaORZPnYB9QISUIu1A2cPE/SgN3q3h1xCV8BZtidEtrFHM8PJUKa+5HHzMiPafVZ8KVmqun42BbDDF5R7Ldxh0Hxx491cAXG7yLnGDXfqEGScQPs2VuMxwxGNJekrn10902jWkClMEfZRpSQgmm4PX2KwwyXWS/JwwBsCKme/NuN+yfI3yjboyD63JhLu/jZPXiJuzVSu13e3CMQ0jzbArZmpCrMpZaShG9B72dm0AZPJIdOmBuPOv5GOShz0q0bfatBZfSvmc/V4PpudIsDqgYXokRn4/sUV6jAYhk2V6L8m9vyaGM9ga+o4S1r967A8Q2lIQgc1GgGefkLyLterJ9qzCZaUjUCHM008Z3ZR7Y5yX/0pKQkyqhamf9O6EV3qMd9FKofaKtLm7A6C7GTUorFXZcy1sn1MfLvDGFr/BEpSRp3f1ImT1gD7ZzXSyBGP+X4Xxd+XGJIftRjLHzKK0Wieb16rzuqxAklQbvzBva8T1QZpdXB7g4CjoFUE2DDamRPqaOLfKM4739Rjo4RUUATsIPOdudBJEkGrs2/5PUKpJjViidPpCXEGxl5Bk7bPKiBDAqXc2dfsJrJZD 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:(13230040)(82310400026)(36860700013)(1800799024)(376014);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Jul 2024 14:26:41.6350 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4cb6634c-c4a6-4b01-c20c-08dc9f59fc8c 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: CY4PEPF0000EE3A.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA3PR12MB9198 X-Patchwork-Delegate: kuba@kernel.org A forgotten or buggy variable initialization can cause out-of-bounds access to a register or other item array field. For an overflow, such access would mangle adjacent parts of the register payload. For an underflow, due to all variables being unsigned, the access would likely trample unrelated memory. Since neither is correct, replace these accesses with accesses at the index of 0, and warn about the issue. Suggested-by: Ido Schimmel Signed-off-by: Petr Machata Reviewed-by: Ido Schimmel --- Notes: v2: - changed to WARN_ONCE() with some prints drivers/net/ethernet/mellanox/mlxsw/item.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/net/ethernet/mellanox/mlxsw/item.h b/drivers/net/ethernet/mellanox/mlxsw/item.h index cfafbeb42586..a619a0736bd1 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/item.h +++ b/drivers/net/ethernet/mellanox/mlxsw/item.h @@ -218,6 +218,10 @@ __mlxsw_item_bit_array_offset(const struct mlxsw_item *item, } max_index = (item->size.bytes << 3) / item->element_size - 1; + if (WARN_ONCE(index > max_index, + "name=%s,index=%u,max_index=%u\n", item->name, index, + max_index)) + index = 0; be_index = max_index - index; offset = be_index * item->element_size >> 3; in_byte_index = index % (BITS_PER_BYTE / item->element_size); From patchwork Mon Jul 8 14:23:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 13726672 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2077.outbound.protection.outlook.com [40.107.236.77]) (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 CEF6E13CFBD; Mon, 8 Jul 2024 14:26:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.236.77 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720448814; cv=fail; b=akapJV+I7RvFr3X9FajW6Sd6xx2fc6tybVEisdA+Q9oD2tXKGh/Tn2FkARnMzfFGV5tuxaiChfAnjvpK6Wn6cZKmx0zwwzYMZ2t3rQQh9OFeQ1Vq18VCehakWchufPpP+bi8kFfXeM2Wir6GUppPMeoODZKwPmbFZSJn96keWtE= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720448814; c=relaxed/simple; bh=LWHXojcV63pqtIbL/LqkpUcsf37p3TRMnS5Ao47Tgx0=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=h6pOG8ImUc/8psUlNIXCiQJATHQsk8/t0ss6SDT8+rh2QVHKj3Gf61cdJ2+nHrEK/5WW4h3DdnwFeUSR60MXavy8FAumrY3ECERNmjksySvp1hD/vM/JCGNdOXhstI+y53zOUUWk4AlrzX7nzir0Q7fKLNf+hHiLyhe5cbkZ79Y= 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=IoZjOxHf; arc=fail smtp.client-ip=40.107.236.77 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="IoZjOxHf" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=A+EoHIgFsKMZumatJHJnsRxiY/aG2wAuOWZTh6TapT2ORQVlqKndD/53seGg8YDZ2UMUbf3wzsN9uKCm2ehUNcEDy9IeD0TH2ZVYSZhvQcAm+UuNY/FOV2X6MqTU2/Nl64IeeRywglrqYi0Ss8QUh196hQ9oRuHhu4VaXulwx3nPSEIVlzY+q8mdieGPVldgm971CW3nlLZxIDxsMMc7/+PGWlpyz2k2DyUp6K8PpgiDhcmoWOI5ckTCv1Sar0L0iBGx4kfRy0ZDIcsfF+c0BEn927Wp3/iPqbBNK1EYM7apymYGMi9qzEaEwuqep9ndBVAgu4yrX/P4NN2mrSkNNA== 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=sG6kwJAVtN1UIgdt39aR7MoDM7+d/jbz9ba7PJuO0z0=; b=GPiNq7kMDuTKYJV8JNaEPsFzIzcJmbUDZ6hnuGfMztFz6ub/8ep3LSZjUTdkzTQ8UPj/FHY03+oGUnL+Vb+BanAlNxxec4D21lzc5VfMOY3w7Jhgd3CIDgAsLmbn/OYOd10JvQPJVEMItmXvlA6WaWb06qDPhzsBe7DA2blOz/qj3dgdfxWXbwiEE4jRjuqLPinXZr+Eo82vkoCABTAuZRYl1PMuxqYXEsInJVyzjTy/62KUblzDZ2YMnDgstypqgjK8qQMtp/yT5rTq9oVjc4++Dz6XzqJ3eGubJ11zd3+uOGxnqY/L6TQiNGRvXl0mw+BNvbt53lnFm0+/x5QmZQ== 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=sG6kwJAVtN1UIgdt39aR7MoDM7+d/jbz9ba7PJuO0z0=; b=IoZjOxHfyymFhf7EDdrQI4lAYFBiQIL8Esto8+u4m9bPLX2eMIFFA/a4hIRChdjSHvu55fNbmX7eWXBJtP2veBAHg+Yf7m+2bix1IeV+Q3+f/UTD3OJIWHiy6XkRYtimSw88atgEmqIIpFSBtLAg9KhK6me/VaYaJQFLUhXT6KEJvGu7eeMxTFh2EnOyjKkmdexWk18K4ehFHjesuRUUMxKTiRR2/iR++5tGgUytJODbyNHvQ3DUvalvEwlY33TWJInqGG/YtEywo/K0XRVeWC5maLWeqzYzsmjXByGXo7+MbRwegY+T25zhFshKukgSir9YBTXHcL8o/l5uLdS+RQ== Received: from DM6PR06CA0029.namprd06.prod.outlook.com (2603:10b6:5:120::42) by MN0PR12MB5740.namprd12.prod.outlook.com (2603:10b6:208:373::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7741.35; Mon, 8 Jul 2024 14:26:45 +0000 Received: from CY4PEPF0000EE3C.namprd03.prod.outlook.com (2603:10b6:5:120:cafe::dc) by DM6PR06CA0029.outlook.office365.com (2603:10b6:5:120::42) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7741.36 via Frontend Transport; Mon, 8 Jul 2024 14:26:45 +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 CY4PEPF0000EE3C.mail.protection.outlook.com (10.167.242.13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7762.17 via Frontend Transport; Mon, 8 Jul 2024 14:26: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, 8 Jul 2024 07:26: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, 8 Jul 2024 07:26:22 -0700 From: Petr Machata To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , CC: Petr Machata , Ido Schimmel , , , Vadim Pasternak Subject: [PATCH net-next v2 2/3] mlxsw: core_thermal: Report valid current state during cooling device registration Date: Mon, 8 Jul 2024 16:23:41 +0200 Message-ID: X-Mailer: git-send-email 2.45.2 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: rnnvmail203.nvidia.com (10.129.68.9) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EE3C:EE_|MN0PR12MB5740:EE_ X-MS-Office365-Filtering-Correlation-Id: 3aff30be-a136-4ce2-2cc4-08dc9f59fe71 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|376014|1800799024|36860700013; X-Microsoft-Antispam-Message-Info: RIm8DD8ZhaSrrxJNvh80ibfpx/PTRVjKZvk8zCZS8RjrfBZMglTFfzRTMs/nF8ciqLXUk9imIfAaAkTy91ATlcugPSw1TWqaRBbcywmruIkSd7+9e4F6ztCEM6NTd68Im28SdOF2uO1tRo7Mt3j5Efm7kBMtxDh7zViok0dApdyo4ydiM55XzGctvNKkwNJi1Voxu59v0PcXp17MuRZBcHEHbe4gyvmyP2tzdsa0i7pZXd8tnjNIQFx0jFLpreY5aTfilorfhWP9JeuOp+nl3pHLaQ9M0+NibrTHQq99nsgBF4sjcrDIcgrNxghEdxztaC21ZTfPnPHsYj2ixc3orwvC3qfyZY55k5ItMwjks8wL+BNKFdRvIXNnJHTc6Z39zXDacYjBE8EyWkPEm3PN0ucGc5HYI3STGwMbUkSHqYseosVhAsHQV5d5NqMyqUU7sXXsBOKJ2LdcsV+PMOTQUMMS6/bHQYFkbYR0UkrkBGzrmiZ3Smd5Ym8MpSVcPEY1bsRmUpmeiDh/ZKwa15lhk4iu6aKFNrqkg14CkpULz4Ow9To6N24WXeZTy0MkAI1M+eCjzTzdEqUdfYVFcyhgJ7G5K9H2Oap7f/i7dR1uA2zBln3JBUkrazHGXy+uo8d1OENipgionmSXThNwBtdZzUF9nFVtaXIW9dodyng8xXrDg2OBTI/VPyRIxoYY0DQ9Ptqd2NGnnSo9DWVbDX8j3JQoI7f5oAVSo8GsZniemPF22Zrw7fxKragBqnPZGTe2DVTTELqcXgzCcv0uiA6Z/jbWaupZFd4b0Yw4LzLxvu1JtOPcFwNbQnDpuB5lCO6NqKdLkCzdQt5jUZZEFowKw19xnyncCX3dhhPX7C642TgajqdBZkNm5rRX5VFJsriYmCuAMHtWXvVGYB3LvHtjHDqUlXbhIX7ZueeOIxtHyh0YVXIx8eqBNnxWb8YhINJmSesKfAfWH5URqwAjCggY/vmgACKnZGFW70/z3XYeWL7Omv6AGStX10O82BLNydaq/QLwONDMILUvpXwUySpkuPrs9cOGLqkejSduThL7W7NtIFiDo8ZyaowbbGRj1R3ajbosuJSf7AxJ34+RGbDj0rYUzMEqRiwhZRpCRiz+INA2SSWmpLDYjcMPZluFAbcUds1fczeSPsIaUdzvoLvbANv0nZ7GlOcKLd8pil9NXp+7uLGXOkcCm/hxpeQf2F43E5xNMLpdAjhvLCNlg8LtiBwhu3s+mnV234Viet4978TIt9Oh53Ne+gtGWXLV/xw6ewGrtXaUqcyWRAojQpJaAZbPenv0ed9kUIpuSWb36D0pWeh9+EsIAaatKr3sRNMGeMH6eqSJcN5oTl2P9M/uwgG1bhqxHshgdICIyncroGixvW2+99vuuFU/lKmW0OMpKtSNzabpsEzK5umzo/iwhCMnT/WH6g8AsDbAEM1MXsbuZiHC4/xiQBloSYX5x3vP 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:(13230040)(82310400026)(376014)(1800799024)(36860700013);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Jul 2024 14:26:44.8097 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3aff30be-a136-4ce2-2cc4-08dc9f59fe71 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: CY4PEPF0000EE3C.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB5740 X-Patchwork-Delegate: kuba@kernel.org From: Ido Schimmel Commit 31a0fa0019b0 ("thermal/debugfs: Pass cooling device state to thermal_debug_cdev_add()") changed the thermal core to read the current state of the cooling device as part of the cooling device's registration. This is incompatible with the current implementation of the cooling device operations in mlxsw, leading to initialization failure with errors such as: mlxsw_spectrum 0000:01:00.0: Failed to register cooling device mlxsw_spectrum 0000:01:00.0: cannot register bus device The reason for the failure is that when the get current state operation is invoked the driver tries to derive the index of the cooling device by walking a per thermal zone array and looking for the matching cooling device pointer. However, the pointer is returned from the registration function and therefore only set in the array after the registration. The issue was later fixed by commit 1af89dedc8a5 ("thermal: core: Do not fail cdev registration because of invalid initial state") by not failing the registration of the cooling device if it cannot report a valid current state during registration, although drivers are responsible for ensuring that this will not happen. Therefore, make sure the driver is able to report a valid current state for the cooling device during registration by passing to the registration function a per cooling device private data that already has the cooling device index populated. While at it, call thermal_cooling_device_unregister() unconditionally since the function returns immediately if the cooling device pointer is NULL. Cc: linux-pm@vger.kernel.org Reviewed-by: Vadim Pasternak Signed-off-by: Ido Schimmel Signed-off-by: Petr Machata --- Notes: v2: - call thermal_cooling_device_unregister() unconditionally and mention it in the commit message .../ethernet/mellanox/mlxsw/core_thermal.c | 51 +++++++++---------- 1 file changed, 25 insertions(+), 26 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c b/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c index 5c511e1a8efa..d61478c0c632 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c +++ b/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c @@ -100,6 +100,12 @@ static const struct mlxsw_cooling_states default_cooling_states[] = { struct mlxsw_thermal; +struct mlxsw_thermal_cooling_device { + struct mlxsw_thermal *thermal; + struct thermal_cooling_device *cdev; + unsigned int idx; +}; + struct mlxsw_thermal_module { struct mlxsw_thermal *parent; struct thermal_zone_device *tzdev; @@ -123,7 +129,7 @@ struct mlxsw_thermal { const struct mlxsw_bus_info *bus_info; struct thermal_zone_device *tzdev; int polling_delay; - struct thermal_cooling_device *cdevs[MLXSW_MFCR_PWMS_MAX]; + struct mlxsw_thermal_cooling_device cdevs[MLXSW_MFCR_PWMS_MAX]; struct thermal_trip trips[MLXSW_THERMAL_NUM_TRIPS]; struct mlxsw_cooling_states cooling_states[MLXSW_THERMAL_NUM_TRIPS]; struct mlxsw_thermal_area line_cards[]; @@ -147,7 +153,7 @@ static int mlxsw_get_cooling_device_idx(struct mlxsw_thermal *thermal, int i; for (i = 0; i < MLXSW_MFCR_PWMS_MAX; i++) - if (thermal->cdevs[i] == cdev) + if (thermal->cdevs[i].cdev == cdev) return i; /* Allow mlxsw thermal zone binding to an external cooling device */ @@ -352,17 +358,14 @@ static int mlxsw_thermal_get_cur_state(struct thermal_cooling_device *cdev, unsigned long *p_state) { - struct mlxsw_thermal *thermal = cdev->devdata; + struct mlxsw_thermal_cooling_device *mlxsw_cdev = cdev->devdata; + struct mlxsw_thermal *thermal = mlxsw_cdev->thermal; struct device *dev = thermal->bus_info->dev; char mfsc_pl[MLXSW_REG_MFSC_LEN]; - int err, idx; u8 duty; + int err; - idx = mlxsw_get_cooling_device_idx(thermal, cdev); - if (idx < 0) - return idx; - - mlxsw_reg_mfsc_pack(mfsc_pl, idx, 0); + mlxsw_reg_mfsc_pack(mfsc_pl, mlxsw_cdev->idx, 0); err = mlxsw_reg_query(thermal->core, MLXSW_REG(mfsc), mfsc_pl); if (err) { dev_err(dev, "Failed to query PWM duty\n"); @@ -378,22 +381,19 @@ static int mlxsw_thermal_set_cur_state(struct thermal_cooling_device *cdev, unsigned long state) { - struct mlxsw_thermal *thermal = cdev->devdata; + struct mlxsw_thermal_cooling_device *mlxsw_cdev = cdev->devdata; + struct mlxsw_thermal *thermal = mlxsw_cdev->thermal; struct device *dev = thermal->bus_info->dev; char mfsc_pl[MLXSW_REG_MFSC_LEN]; - int idx; int err; if (state > MLXSW_THERMAL_MAX_STATE) return -EINVAL; - idx = mlxsw_get_cooling_device_idx(thermal, cdev); - if (idx < 0) - return idx; - /* Normalize the state to the valid speed range. */ state = max_t(unsigned long, MLXSW_THERMAL_MIN_STATE, state); - mlxsw_reg_mfsc_pack(mfsc_pl, idx, mlxsw_state_to_duty(state)); + mlxsw_reg_mfsc_pack(mfsc_pl, mlxsw_cdev->idx, + mlxsw_state_to_duty(state)); err = mlxsw_reg_write(thermal->core, MLXSW_REG(mfsc), mfsc_pl); if (err) { dev_err(dev, "Failed to write PWM duty\n"); @@ -753,17 +753,21 @@ int mlxsw_thermal_init(struct mlxsw_core *core, } for (i = 0; i < MLXSW_MFCR_PWMS_MAX; i++) { if (pwm_active & BIT(i)) { + struct mlxsw_thermal_cooling_device *mlxsw_cdev; struct thermal_cooling_device *cdev; + mlxsw_cdev = &thermal->cdevs[i]; + mlxsw_cdev->thermal = thermal; + mlxsw_cdev->idx = i; cdev = thermal_cooling_device_register("mlxsw_fan", - thermal, + mlxsw_cdev, &mlxsw_cooling_ops); if (IS_ERR(cdev)) { err = PTR_ERR(cdev); dev_err(dev, "Failed to register cooling device\n"); goto err_thermal_cooling_device_register; } - thermal->cdevs[i] = cdev; + mlxsw_cdev->cdev = cdev; } } @@ -824,8 +828,7 @@ int mlxsw_thermal_init(struct mlxsw_core *core, err_thermal_zone_device_register: err_thermal_cooling_device_register: for (i = 0; i < MLXSW_MFCR_PWMS_MAX; i++) - if (thermal->cdevs[i]) - thermal_cooling_device_unregister(thermal->cdevs[i]); + thermal_cooling_device_unregister(thermal->cdevs[i].cdev); err_reg_write: err_reg_query: kfree(thermal); @@ -847,12 +850,8 @@ void mlxsw_thermal_fini(struct mlxsw_thermal *thermal) thermal->tzdev = NULL; } - for (i = 0; i < MLXSW_MFCR_PWMS_MAX; i++) { - if (thermal->cdevs[i]) { - thermal_cooling_device_unregister(thermal->cdevs[i]); - thermal->cdevs[i] = NULL; - } - } + for (i = 0; i < MLXSW_MFCR_PWMS_MAX; i++) + thermal_cooling_device_unregister(thermal->cdevs[i].cdev); kfree(thermal); } From patchwork Mon Jul 8 14:23:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 13726665 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2062.outbound.protection.outlook.com [40.107.92.62]) (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 5B7B113C667; Mon, 8 Jul 2024 14:26:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.92.62 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720448813; cv=fail; b=cCcX+2G3c0TZAXyxg+tEFSEnDiCCVAGq8b/j3Va7jJ9SYiAIpZysJkjRhwrSJvy8PoURpae8nZ2Z8qFqXZERbdjzVDWFZx+EgTKEuBmf0XTTAudGnBN8o6B7lZ/s6XUdzUGFzq0XFJjC25D7+aI3O5GoHKPAjCEWolMhCNkh+Hk= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720448813; c=relaxed/simple; bh=KX28DEDILzWnnfwqBHPItKkJVz35IYJqmr5HQEu//FY=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=LqDySeZfBnEe2ePM7hrnk5GbQwWvwuulqE4K35Rz3dX+w8YtvC3XRm8K2tmGYD6qJ4q6X3FZPdB4F0+0szx9IXGMIQmDyZkrEaRav2q0IBhTPZNxI5NlJRamqM/FAS9PfpsLF8wsuZToDGXMlPniae863lht49LpPk8KLF4PoWk= 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=jqqPs3TD; arc=fail smtp.client-ip=40.107.92.62 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="jqqPs3TD" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RYqP+wIDLl4ybZK7Pa/xwOQpSDpsDad7wfWcea6bbmzfeVCuAvT2IAnRhPqp1WRwh30eXE+olFtWWzyhcLJMA4OYkN+tDceC2wh+j22TBAMsv3mRw6zlctbVTN2oAVCmmjHAX4k+hhckrza8GwM8XVrk3vjnuNog05XK1yC+d+6kr+tPIKT5/jOAj3vNYkJ3IpmDltI1NVgqJXSi6rHYNScEje1WXo+PVJ6cMBVRDlXHvauTvP7piYh4PSc3DwE4UDQQ+0pb8d5nB8sjB2Rnjsq+XUYu5/0RlFlZAA+rxGuX1zQZ1sswgZdByTN/ZOj3cHz3W+L5Q/08QtkTSsl4sg== 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=+OEH92MjfxuhwHQODLUjtsLea5pyUD0sfINcSsPya+I=; b=LwnD1CGUZ8bhJsQbVHFxDie3WrEMRBHyHm3QAsVeOcwfQCLxW6fp0+dSd6De7cSVVXiLUMIBtzPAv2lSzxcRF+yrPn0PkDZi+Fnxn63e29stwce6JyXA2xUogQzuyhLPOCFLpc6rhntamX+CrGuDaOjo6VB5ZzZDy/B7jnCGKmoyMN9yZ4+U9g9G5Hw1uOCENkXIjzfJ95IqPqwng6A6BtpPYKcFjTsYYP8/xWfKJSSL98V2zQsZWVwOIqQ05aai+Pa8R7Ag97H2J6GlmLpKxBiul+b8080DhJgB1QcglArOg1in82e9EhYlIUUb/43NMNfU7IV6Z5xBOf4Iw9kYaw== 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=+OEH92MjfxuhwHQODLUjtsLea5pyUD0sfINcSsPya+I=; b=jqqPs3TDX72LTmcczDopn4LJnevwFZp4h9bz+9jpZwGvGCHnpU4ThCnTY+YoDhgFw5gJmMLRpe2CrbqHUsd6Tz9f11WupBGc2fzfTNPOAVJ8eJhbhSi9ZyuGEiMOiesl4QPvNFbiXti8qyLFJO5D+EotLDmY4oAhyMG9OZk10dm7yq2jz1JB1QurCMDXwUH9zbwfksbE30/mP4GnwamljXFCBKvc9TwveIHohuu0hOTi/JjtiqdnEQqb40QuE3V2eDtA6ZGaCAotawMeNthvO3rpT/N4gAGIkRvN9cTwrOO9S2a0iI4KwaMJQ9jCHOCCl5Rqu88DUwidLoCLIswaug== Received: from BN9PR03CA0786.namprd03.prod.outlook.com (2603:10b6:408:13f::11) by IA1PR12MB6210.namprd12.prod.outlook.com (2603:10b6:208:3e6::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7741.35; Mon, 8 Jul 2024 14:26:48 +0000 Received: from BN1PEPF00006002.namprd05.prod.outlook.com (2603:10b6:408:13f:cafe::ed) by BN9PR03CA0786.outlook.office365.com (2603:10b6:408:13f::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7741.36 via Frontend Transport; Mon, 8 Jul 2024 14:26:48 +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 BN1PEPF00006002.mail.protection.outlook.com (10.167.243.234) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7762.17 via Frontend Transport; Mon, 8 Jul 2024 14:26:48 +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, 8 Jul 2024 07:26:31 -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, 8 Jul 2024 07:26:27 -0700 From: Petr Machata To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , CC: Petr Machata , Ido Schimmel , , Subject: [PATCH net-next v2 3/3] mlxsw: pci: Lock configuration space of upstream bridge during reset Date: Mon, 8 Jul 2024 16:23:42 +0200 Message-ID: <9937b0afdb50f2f2825945393c94c093c04a5897.1720447210.git.petrm@nvidia.com> X-Mailer: git-send-email 2.45.2 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: rnnvmail203.nvidia.com (10.129.68.9) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN1PEPF00006002:EE_|IA1PR12MB6210:EE_ X-MS-Office365-Filtering-Correlation-Id: b90634eb-505e-4f7c-be41-08dc9f5a00a0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|36860700013|376014|1800799024; X-Microsoft-Antispam-Message-Info: mHqvjKLvBBPc20BG532m36owGXgxnIHrPdee3jfAr5lGeh3++XW+Klxyl3e86n9UTGtOwTV57vufKbTT15he8caYqk/Fz54SGAzE0wcdLK66ktERo/eA2aQ1XulmSsXCIg9c9aTIeonGhaND9nb7ouFK54LsnGdEX7BI8lBElBBH3FaR5z8a+rk98efldsRVvm6gh4P3BIyJZTJtB5BNk5Tv58xxL0meIn7whVs9vWIuj0NHKo72FjSaq9vWPuZNg4ST94yFDS89I3U9ECwF8Xdcr7e1LYAILMUKfJZsYrEl4nlYkYXCXAX61Eb3RDepJAYIWm/eWyC5Xe80IecFk/3hF66m9pOdJKOBO+jfTn37BStv8kjlSj4LxRpcJbxe20RnXQAQNIaFazuim7KaEGUg8PuolG/AioC3bh1jq7EYD+ixO6JLbk7BFuCmx3t0FIoNeKTfd5c5sFv+VEVr1BjmjNm8KnfC5/eEUd/qI8aGnrDW7fQ/ZweD2RZ/HwvYL0a+2tbj9hVXmPrIXM6Ejf39mDRAZrg+rG9ClBSglWRLx21Fr0JRa/gAOlD36G8VkNNlNUpnauPKcMdi68f9LKbv6LddIeDKeUBCPDVHXqnJuXJvit7bI6zL7rbZau0IHEycPOMA70qZJJdwdk2aOGSoJNuBRIVBdU4vXxCQjdfB2Uh8Ui0pWdfwwjgLF5y7LxkMU0u3p1yu8oPO3UmnYTR8wXbCYb5P973f00NepW+Nlbuv+BlfDizOP09TQ64SGO4mczxqSlqyl3mMdoVkmYMGlGVGBLMRRWXWdOPQC79qK5JeyX5qZLMBxLY9rsDPvd20J+qqUGry4n4hUcRn73aHU+Cp+y36JPNA5ikMfaIhM1aKFBGZ02aOZ3tH6h2v+Nm90ENzOgI24MXbww572WpzMX8KG792cV9QmOS/j22xSrNEUY+7NgTmWmDb6Lew+MG866JNoqX0pJcv5J/WvqtiLzqBo2bsXzYA65oqe7ZbN479QYfp8/gG2GYv0NV4IJo2or9vY7A0rDqqyi6r33eNt/5OjLLm7F6TMJ2mfLzXvYP61JOT/rs/se86bzMaZubg9sgT+/IFta+98ypAozpN/Lff7Ia0K6qwH+CK39WqB1mc0jjjRxONZDVLTWmiSxqcT0NaHiLAXwonmfnEz9D9AyNMOZfMqlyc4DHCj3yeevQnHVK9FVb8Vwe0MOVlFggLtmTXfrINZUOQ2iAcKMJF+9Uu45AteGyuEq1bnRsDwrsFqaekgAO1qkLkRBDEOc1pqocGfM1E5pBVUvTwTEgCEKIQzJD6gG2puwvPpMTCaDOo6gMazjlLVl4Piyhu2aIM515uXiXKnzCKWCBr1RmoLH+txU16n+QZAT1HLivur3/FhsX2jcGmXYQ4MNAw+RqbsdHKr5oH1cPz32Iczo6xmwQxIQ27OPyD85D8J2r4ixfDcBomTDWYIM/mEukj1qNuh6AfqlFCKa10DUtHKQ== 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:(13230040)(82310400026)(36860700013)(376014)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Jul 2024 14:26:48.4300 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b90634eb-505e-4f7c-be41-08dc9f5a00a0 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: BN1PEPF00006002.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB6210 X-Patchwork-Delegate: kuba@kernel.org From: Ido Schimmel The driver triggers a "Secondary Bus Reset" (SBR) by calling __pci_reset_function_locked() which asserts the SBR bit in the "Bridge Control Register" in the configuration space of the upstream bridge for 2ms. This is done without locking the configuration space of the upstream bridge port, allowing user space to access it concurrently. Linux 6.11 will start warning about such unlocked resets [1][2]: pcieport 0000:00:01.0: unlocked secondary bus reset via: pci_reset_bus_function+0x51c/0x6a0 Avoid the warning and the concurrent access by locking the configuration space of the upstream bridge prior to the reset and unlocking it afterwards. [1] https://lore.kernel.org/all/171711746953.1628941.4692125082286867825.stgit@dwillia2-xfh.jf.intel.com/ [2] https://lore.kernel.org/all/20240531213150.GA610983@bhelgaas/ Cc: linux-pci@vger.kernel.org Signed-off-by: Ido Schimmel Signed-off-by: Petr Machata --- Notes: v2: - reword the commit message to reflect the fact that the change both suppresses a warning and avoid concurrent access drivers/net/ethernet/mellanox/mlxsw/pci.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/net/ethernet/mellanox/mlxsw/pci.c b/drivers/net/ethernet/mellanox/mlxsw/pci.c index 0320dabd1380..060e5b939211 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/pci.c +++ b/drivers/net/ethernet/mellanox/mlxsw/pci.c @@ -1784,6 +1784,7 @@ static int mlxsw_pci_reset_at_pci_disable(struct mlxsw_pci *mlxsw_pci, { struct pci_dev *pdev = mlxsw_pci->pdev; char mrsr_pl[MLXSW_REG_MRSR_LEN]; + struct pci_dev *bridge; int err; if (!pci_reset_sbr_supported) { @@ -1800,6 +1801,9 @@ static int mlxsw_pci_reset_at_pci_disable(struct mlxsw_pci *mlxsw_pci, sbr: device_lock_assert(&pdev->dev); + bridge = pci_upstream_bridge(pdev); + if (bridge) + pci_cfg_access_lock(bridge); pci_cfg_access_lock(pdev); pci_save_state(pdev); @@ -1809,6 +1813,8 @@ static int mlxsw_pci_reset_at_pci_disable(struct mlxsw_pci *mlxsw_pci, pci_restore_state(pdev); pci_cfg_access_unlock(pdev); + if (bridge) + pci_cfg_access_unlock(bridge); return err; }