From patchwork Thu May 9 11:29:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tariq Toukan X-Patchwork-Id: 13659666 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam04on2059.outbound.protection.outlook.com [40.107.101.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 139791311A0 for ; Thu, 9 May 2024 11:31:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.101.59 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715254300; cv=fail; b=O8qQw3zgl8h1lhNWtHdYXhHrqYU+m/gJ6ZhQQARo5s8uMcsyFgDc1JUBrxBZVuEBEnUZ6CIivOvTgiRdeLgrsGELvEDF6vC9D2ifVmKAGfQsaSWz9n96DHpkxjg7XK28x+wAamIiIG9+WOVF/aAeqZBpLvraBz5w9T6JY9HnXXM= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715254300; c=relaxed/simple; bh=X0zdo3XDxnSuJVgaCU2FDMJpDa5kUDd6NJ0lvle3S2U=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=oURtlPWGJ6slW/shlxapzD8iDbuZ2E1s7NqRvYJgBRZEpJ53rLn7yJX29mNtJHM6igv+SzUIBHS+UXLoimmo1lPtXfOVhyhjpKJTOR21Hd4BQv5lRRQv+bD7YL6GMPlddEwdAaSrzFawEtTnelrmr0ouoQ8GpMCXPFjK5l22F1g= 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=SpJZQeT+; arc=fail smtp.client-ip=40.107.101.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="SpJZQeT+" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DDApJflAtWza3JwOexIuae4bBCMuaH4VptuDohA5ZubsAZjVpm82GWLqcxYOJ8RBYaoJ6zeXpZkdryLTQtxBB2XlOnmAwwvy/frqe6SRBcgZhQp/ME0hguIw2fgcoTs4WSgV9bV/GrxBXnErpvAAZ6qSQfSvB4f8iTyUMeLxbsC1tK75bNGEA8N+4scxtSa9Nsbzfc5E9HDyC1JwcSSTU5bOQcFfnnj8lCzj2Cby/y8uE2Zzwg7KEEhDS7EeKs511X5+XP3HLvtvr6A4OPVhoNQbRvfQ+8+lUsFoyvded0lejwV0smVKQ5m6Oxp0Y7gzhMUnjrUIoSfCOa0tLweDXw== 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=wm2KQURsJkdSK8BHayPEipc+Nz2Z6JQRekBiQLlqUzU=; b=gXlBKfaaGCS9RiOtcOYgPUwesnpu0Xl+SNjpdm3UjGvrjOtqfPPZqvC7G8Hz4jak0n5fQ97m9TREDLM/drhQf3PiB4cbPaYOrA0v7f12UEAjd7kzZgY3GwO+OVvvCrFjAee+AJcxdLr9+txEhVkJMags7AO6jbWwqCyaiAsOmW+JpLKhytTncn+YemDq53d5SS9SzWtzFVetaZs+xMx6JatgagIo8udogDXhKtlJPkMeeJOV2wPN7YdFIK+A1offf7Eebb1oPgnc1UE37zZBKRuqr3TPKGqG/efVGgmhBjUk4BXVf+u544JSOeTA9IHjAKwD6LpOlpK9SMquLylNKA== 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=wm2KQURsJkdSK8BHayPEipc+Nz2Z6JQRekBiQLlqUzU=; b=SpJZQeT+wz7O0rR6h1KHxPp9hPTFrwcSZTx8mAZX3wZOrEUYX9iFf8pfCS/n0ByYYWZXK2Z+1r7NoIo+qU+XG0Pk7+fx9ZqToIeiGil5qS3WLEkQnCMddlJXUffVvShmgTVcg/GV5ZzW+frLFlnytf919T+9pHJlUTdH6v0vTXRz37JlfHEzG1LsB6mPpmDeeDj7zssCh/+BiSW7MAUeR+uges3lFzg2V2ZY78aU/XD2G2EuHrx8UQJK/zQXqAM3kw1h1mdnb0XtqocwKQqZ1CFrZSFblysENlVBJQDAJITuDnWK5/I2yw7dcapXgi44QLu6dfd0Sni5ybwIXjpRhQ== Received: from SJ0PR13CA0185.namprd13.prod.outlook.com (2603:10b6:a03:2c3::10) by CY5PR12MB6408.namprd12.prod.outlook.com (2603:10b6:930:3b::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.47; Thu, 9 May 2024 11:31:31 +0000 Received: from MWH0EPF000A672E.namprd04.prod.outlook.com (2603:10b6:a03:2c3:cafe::ab) by SJ0PR13CA0185.outlook.office365.com (2603:10b6:a03:2c3::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.46 via Frontend Transport; Thu, 9 May 2024 11:31:31 +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 MWH0EPF000A672E.mail.protection.outlook.com (10.167.249.20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.18 via Frontend Transport; Thu, 9 May 2024 11:31:31 +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; Thu, 9 May 2024 04:31:08 -0700 Received: from rnnvmail205.nvidia.com (10.129.68.10) 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; Thu, 9 May 2024 04:31:07 -0700 Received: from vdi.nvidia.com (10.127.8.10) by mail.nvidia.com (10.129.68.10) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Thu, 9 May 2024 04:31:05 -0700 From: Tariq Toukan To: "David S. Miller" , Jakub Kicinski , Paolo Abeni , Eric Dumazet CC: , Saeed Mahameed , Gal Pressman , Leon Romanovsky , Shay Drory , Tariq Toukan Subject: [PATCH net 1/5] net/mlx5e: Fix netif state handling Date: Thu, 9 May 2024 14:29:47 +0300 Message-ID: <20240509112951.590184-2-tariqt@nvidia.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240509112951.590184-1-tariqt@nvidia.com> References: <20240509112951.590184-1-tariqt@nvidia.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MWH0EPF000A672E:EE_|CY5PR12MB6408:EE_ X-MS-Office365-Filtering-Correlation-Id: b454f8a4-8dc4-4380-299a-08dc701b92f3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|376005|82310400017|36860700004|1800799015; X-Microsoft-Antispam-Message-Info: f9kdzSSujFcK7Gp9XqijCuN1MrGTiIjiCqvWCmUz0RBuPGBqX4hbKb+35P1I0LYfrJ9PSucv2ZzLmCxnP0UtIGGYD0CE2v+SDy9n0k1kmVtmDvHF1ODlYhGiV3xAmzUTMCib0yiKwJiBXrnGGYx6oWqWKS4iuB1zs9S3Dv0NMr6ZqlZ4Kk+i27h+AffUGPfsfzWPxjLIBJhEDazyiP2IAE+1hlyGRQledxlpuPgHw7HHsWd0dAwcZWf82Dod+SFbMVqPvrIlQD+XkXoxo2L8smpFc5u6kHSTf8tRFGcP9hm+DD26m5W97vTGRrb8LCCaeY7gAq2+i922NzB1NRUflF2MhtD0ARd/ir1ZTndCrnrAhQYvH0BzOxHf5xKs1p16eFI1bQTXbRUNuHJ+hBoTdaNghnTpJkdVDpcMXSJ1F3jSqQcfg/hfrIbkfznfXmGLJsaRknwTtzMw76oYZ1w1GRZjUzzi06xzhK1I55EmH/54mimAECQbN5HEFgbZYifODCbcQsOUF0HEksVpyqWmZMcxlPGHB8djZRaJpwzzlV+NkV8C2RSaUz9m1MIfOBC2thd8leldnamnJCOWeWhzqiY3mlrnA/BqI9p3BPOmx4V8/MOIuZ12IWN2EpDKvaqRl7WvQFQsQoYV3u2qoZef7PG01/6Ic6EbCu1LGl9bjWALmsHxib9Wck4ypN15RiNHz23whzq9jKWOnl5qBLIPJdkdqAaplP5hY1qsIxMUulU14MeFhlDzXxC87OT6G46Qz9bcDH2uleHGD/+/SIeqDBD3lv9jLAzCwkOU0uD8PvoaYK+c1TWgVo1Pzg7SEX9s3HTA2lLJ4q/Yzc6Q1P9EUzOoTauBlqWLnL6E/PRQLVixQUZoqfD2VBJ+OJKtqGA3vBdDZDiKcnL7Ow1H4P7/oh8M/uJ+BBPCG+ym7+oAeC6yRcFf7cbwG6C2dmAenGLsKuNPeUt7IP/r1o/6FX8FpDheI7XZ/gxr6HqyRejDSkCDDVl4/3Rx+b+GD1d87jOhDjJ7RHd1zPeLUPzq26b8v1Lavj4JcO8wLcNj+zvyZatZQf3sTAKUnbnT+D0B5l359Z0w3bnhQqw7Sk3PO2oBHoM9G0iTPOJkJXzHy7CRDemPFt/iWOGjNDd+DSA0N0DsQhF1t27/fED9ZmLTjLheUcUnLQbDPlxoEK1kABaen7bPNhZ5L+LWHVY0VFyclWOtSPEnid59K/HSfWD91+3kIz8teKlZxxHZsA/dHj74Hx/kklD01ekcn/Rb8dQTrxtZBhWHgkLzkELpBG8dmc7i80/t1/l5zmljYzFXFPZyggjA3x1yqdrmaUv33s3l44954utjDSzHmam4PmcPAt9ByAqp9uf9xU7QfLLAtvj2nTSsFMK40o2AVUbpMNXNhGQg 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)(82310400017)(36860700004)(1800799015);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 May 2024 11:31:31.0667 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b454f8a4-8dc4-4380-299a-08dc701b92f3 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: MWH0EPF000A672E.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR12MB6408 X-Patchwork-Delegate: kuba@kernel.org From: Shay Drory mlx5e_suspend cleans resources only if netif_device_present() returns true. However, mlx5e_resume changes the state of netif, via mlx5e_nic_enable, only if reg_state == NETREG_REGISTERED. In the below case, the above leads to NULL-ptr Oops[1] and memory leaks: mlx5e_probe _mlx5e_resume mlx5e_attach_netdev mlx5e_nic_enable <-- netdev not reg, not calling netif_device_attach() register_netdev <-- failed for some reason. ERROR_FLOW: _mlx5e_suspend <-- netif_device_present return false, resources aren't freed :( Hence, clean resources in this case as well. [1] BUG: kernel NULL pointer dereference, address: 0000000000000000 PGD 0 P4D 0 Oops: 0010 [#1] SMP CPU: 2 PID: 9345 Comm: test-ovs-ct-gen Not tainted 6.5.0_for_upstream_min_debug_2023_09_05_16_01 #1 Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS rel-1.13.0-0-gf21b5a4aeb02-prebuilt.qemu.org 04/01/2014 RIP: 0010:0x0 Code: Unable to access opcode bytes at0xffffffffffffffd6. RSP: 0018:ffff888178aaf758 EFLAGS: 00010246 Call Trace: ? __die+0x20/0x60 ? page_fault_oops+0x14c/0x3c0 ? exc_page_fault+0x75/0x140 ? asm_exc_page_fault+0x22/0x30 notifier_call_chain+0x35/0xb0 blocking_notifier_call_chain+0x3d/0x60 mlx5_blocking_notifier_call_chain+0x22/0x30 [mlx5_core] mlx5_core_uplink_netdev_event_replay+0x3e/0x60 [mlx5_core] mlx5_mdev_netdev_track+0x53/0x60 [mlx5_ib] mlx5_ib_roce_init+0xc3/0x340 [mlx5_ib] __mlx5_ib_add+0x34/0xd0 [mlx5_ib] mlx5r_probe+0xe1/0x210 [mlx5_ib] ? auxiliary_match_id+0x6a/0x90 auxiliary_bus_probe+0x38/0x80 ? driver_sysfs_add+0x51/0x80 really_probe+0xc9/0x3e0 ? driver_probe_device+0x90/0x90 __driver_probe_device+0x80/0x160 driver_probe_device+0x1e/0x90 __device_attach_driver+0x7d/0x100 bus_for_each_drv+0x80/0xd0 __device_attach+0xbc/0x1f0 bus_probe_device+0x86/0xa0 device_add+0x637/0x840 __auxiliary_device_add+0x3b/0xa0 add_adev+0xc9/0x140 [mlx5_core] mlx5_rescan_drivers_locked+0x22a/0x310 [mlx5_core] mlx5_register_device+0x53/0xa0 [mlx5_core] mlx5_init_one_devl_locked+0x5c4/0x9c0 [mlx5_core] mlx5_init_one+0x3b/0x60 [mlx5_core] probe_one+0x44c/0x730 [mlx5_core] local_pci_probe+0x3e/0x90 pci_device_probe+0xbf/0x210 ? kernfs_create_link+0x5d/0xa0 ? sysfs_do_create_link_sd+0x60/0xc0 really_probe+0xc9/0x3e0 ? driver_probe_device+0x90/0x90 __driver_probe_device+0x80/0x160 driver_probe_device+0x1e/0x90 __device_attach_driver+0x7d/0x100 bus_for_each_drv+0x80/0xd0 __device_attach+0xbc/0x1f0 pci_bus_add_device+0x54/0x80 pci_iov_add_virtfn+0x2e6/0x320 sriov_enable+0x208/0x420 mlx5_core_sriov_configure+0x9e/0x200 [mlx5_core] sriov_numvfs_store+0xae/0x1a0 kernfs_fop_write_iter+0x10c/0x1a0 vfs_write+0x291/0x3c0 ksys_write+0x5f/0xe0 do_syscall_64+0x3d/0x90 entry_SYSCALL_64_after_hwframe+0x46/0xb0 CR2: 0000000000000000 ---[ end trace 0000000000000000 ]--- Fixes: 2c3b5beec46a ("net/mlx5e: More generic netdev management API") Signed-off-by: Shay Drory Signed-off-by: Tariq Toukan Reviewed-by: Simon Horman --- drivers/net/ethernet/mellanox/mlx5/core/en_main.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c index 319930c04093..64497b6eebd3 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c @@ -6058,7 +6058,7 @@ static int mlx5e_resume(struct auxiliary_device *adev) return 0; } -static int _mlx5e_suspend(struct auxiliary_device *adev) +static int _mlx5e_suspend(struct auxiliary_device *adev, bool pre_netdev_reg) { struct mlx5e_dev *mlx5e_dev = auxiliary_get_drvdata(adev); struct mlx5e_priv *priv = mlx5e_dev->priv; @@ -6067,7 +6067,7 @@ static int _mlx5e_suspend(struct auxiliary_device *adev) struct mlx5_core_dev *pos; int i; - if (!netif_device_present(netdev)) { + if (!pre_netdev_reg && !netif_device_present(netdev)) { if (test_bit(MLX5E_STATE_DESTROYING, &priv->state)) mlx5_sd_for_each_dev(i, mdev, pos) mlx5e_destroy_mdev_resources(pos); @@ -6090,7 +6090,7 @@ static int mlx5e_suspend(struct auxiliary_device *adev, pm_message_t state) actual_adev = mlx5_sd_get_adev(mdev, adev, edev->idx); if (actual_adev) - err = _mlx5e_suspend(actual_adev); + err = _mlx5e_suspend(actual_adev, false); mlx5_sd_cleanup(mdev); return err; @@ -6157,7 +6157,7 @@ static int _mlx5e_probe(struct auxiliary_device *adev) return 0; err_resume: - _mlx5e_suspend(adev); + _mlx5e_suspend(adev, true); err_profile_cleanup: profile->cleanup(priv); err_destroy_netdev: @@ -6197,7 +6197,7 @@ static void _mlx5e_remove(struct auxiliary_device *adev) mlx5_core_uplink_netdev_set(mdev, NULL); mlx5e_dcbnl_delete_app(priv); unregister_netdev(priv->netdev); - _mlx5e_suspend(adev); + _mlx5e_suspend(adev, false); priv->profile->cleanup(priv); mlx5e_destroy_netdev(priv); mlx5e_devlink_port_unregister(mlx5e_dev); From patchwork Thu May 9 11:29:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tariq Toukan X-Patchwork-Id: 13659665 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2066.outbound.protection.outlook.com [40.107.237.66]) (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 221761311BC for ; Thu, 9 May 2024 11:31:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.237.66 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715254299; cv=fail; b=UtDukflP4HS+v64RkOq9vmrbkd3Rh9Hk5IM9us0bEdfuK9lR0z+r2SpBy6LyQ7vLC821PVqe5ViH2reRoPKqasSIJLprxn+Yt/5iJGyUxTcqbsOxx+TK8QSfu7vs/xKRQBqX5uRrQoHCdqbqqkjWqm6eFA17Zu5DYZylH/Rg6xY= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715254299; c=relaxed/simple; bh=UpqT9vV2gRAMrcoLvBDlSS5U1yp6aQofkhodpv7+PHM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=LMp9xgbT5yjzpLwoLh+jd9uJINVfvTLvD0lTIesaelgvAKo6TeB6YhkmuR3kIpQE5WRnzGvo3FJIN6rrLZ86wtBCXEr1+LrI28PX9z1TCa938mqEsT/kFmf2komgV3o0CtXZ45OZp1bkhGZIgOjIY4JX/ROl3MoaXypGmQU9ZUs= 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=IJ/1BSSz; arc=fail smtp.client-ip=40.107.237.66 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="IJ/1BSSz" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=J/8Rpqz0aJmfmcY4u/Qup0er/32c7aZ1sj39Rpgs43kVxmxWpnqJqMKZhFxC0nV34ZZQ9vBmnWa0z8tWCi0yeXz3YBGn0D6D5MEVsgLGRSufjS4DuxRejG/bsQEbredRatGDlkInrwJl5TU4YNVPoHACjVTve+pNOrg7otg2QYBUEN6zfml/xZ2DRXn+noKmywbGXs9GGwhQIE1zF6YLRwKzwwJabu8Zl/gfLF5MoosTwZ9ueEP+a18aMzd0CUT4NSm0THb2bqk4RnFT0Usz0ANuCy1YPLsl2jygmcUhUMECBvinUhQHVCHlmWURyGo/XbEtjLBdpUykVDVV6H1MtQ== 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=noMMNVCftQKYLIrLwGv7Yny8dZSDXz0o5ejBmleXBQQ=; b=hiU+BwODQEzCBlWWw+dZDK3EmvF4TdXwF2MxLiPKOf0gwKs1TErEp8vh5d+QEkvkVHKd7Ah+hkzxZXk55N/B30AIR5dJvd+LBJ9zonooI2MbqkYXU5RVMHegDFkCyCpeLs5ExmwmLpCP+2zSWw/BheV6TChbVIF7kxPjOA/85R0Qdvm5r8gSEb+dP+muAJyHaRCncuiJLSitomXhTBOQxqlUpQVRpvITVDUzMY3LmWPPJgThVuSiDw6GSXrX7BsCS59fDrcmHxubctu1xF9XRpIPf0Gwfj99pHis0y0jsUdrLGSlRagik77RZcZQxSEv+doGF/x+3EWOOVP0lBZNxQ== 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=noMMNVCftQKYLIrLwGv7Yny8dZSDXz0o5ejBmleXBQQ=; b=IJ/1BSSzEbUEAYd6zoeGzNyRWGGbdVIgrwBMHrS4IQdZGrH3BsAA2f4/nKazt5sqc5q0tA+GBChz+CDk7YZplgBd4AFQUovdcGcJthXiGPeAqMZTOYDHEJPQ4SxfbG4pTEIfCGzuLC7/VUbAZapSXB7P5KfVoMc8MH6SY+WUFGZdR13qW22zYI05FUFoV4ymraAK/Q+PrcUcDSuBxWEDDj5Qt9luEVKZGRTFgOHplvyKh06ggsqOijA6H/WGLk598jOxYeQjoRgvem21cgzWP1s62CLZTbAsPAhQnBqHI5ZTST8lSBKwPtBIp33jWh8Dle90PWtqZZXQSyKlFwvJQQ== Received: from SA1P222CA0148.NAMP222.PROD.OUTLOOK.COM (2603:10b6:806:3c2::14) by MW4PR12MB7481.namprd12.prod.outlook.com (2603:10b6:303:212::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.47; Thu, 9 May 2024 11:31:34 +0000 Received: from SA2PEPF00003AE8.namprd02.prod.outlook.com (2603:10b6:806:3c2:cafe::39) by SA1P222CA0148.outlook.office365.com (2603:10b6:806:3c2::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.43 via Frontend Transport; Thu, 9 May 2024 11:31:34 +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 SA2PEPF00003AE8.mail.protection.outlook.com (10.167.248.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.18 via Frontend Transport; Thu, 9 May 2024 11:31:33 +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; Thu, 9 May 2024 04:31:11 -0700 Received: from rnnvmail205.nvidia.com (10.129.68.10) 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; Thu, 9 May 2024 04:31:11 -0700 Received: from vdi.nvidia.com (10.127.8.10) by mail.nvidia.com (10.129.68.10) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Thu, 9 May 2024 04:31:08 -0700 From: Tariq Toukan To: "David S. Miller" , Jakub Kicinski , Paolo Abeni , Eric Dumazet CC: , Saeed Mahameed , Gal Pressman , Leon Romanovsky , Shay Drory , Moshe Shemesh , Tariq Toukan Subject: [PATCH net 2/5] net/mlx5: Fix peer devlink set for SF representor devlink port Date: Thu, 9 May 2024 14:29:48 +0300 Message-ID: <20240509112951.590184-3-tariqt@nvidia.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240509112951.590184-1-tariqt@nvidia.com> References: <20240509112951.590184-1-tariqt@nvidia.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA2PEPF00003AE8:EE_|MW4PR12MB7481:EE_ X-MS-Office365-Filtering-Correlation-Id: 21a1f99b-7414-46ba-9aa3-08dc701b945c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|36860700004|1800799015|376005|82310400017; X-Microsoft-Antispam-Message-Info: BkNOi6eoHhTEkg+DlieuFbl7sngfeRZb5Tnolq3IrC6fPKBFK7pPGYqoZ2e2ZbxGZSAZAyJ4Ylz4SSZOjrV8KRpz5ppOBLj8DK22WG43UCerKGxbH9bCpv3feKnbL0vfWwitRwmZF6aSmZK03A5sGikn5Sce/MP11GmYlGqB8C/dV0TBP1vJnWW/jmZ2/GgRKlX6Pzl/RYDNHfi2xMPBWmMsKlKvKrIWpM1eiP+f91bZ+oFy8fmr9dk61mz/Sdw0zjjPGQqTiCrhjwdx1MZDZsAPsTCqlgOyKM/ijF6/doESsmso5DB7EvquRjb9WnVoUtD7tRnypJwJur2UiDL56OHMn4Miqfq6ZicOrZUo5Rz1CukhZP6Yb26K6B2DHouIznHfi3o9BFtWZtAYxO2eAnvnwgnZgt7ksf93RD52sXgxEjx1hrtoHWhn1HZHj+vM5XWtzeGn/EyWErtfi7DFgUvWQCzxCcKdckZ2br17wDswe3hEnDuM7sKnVA/Jm6hc/YeVi+l96iKFw5nxmtJPBIHCtoTN6GdwKatV5GiELz27gox0K6tjDmCws8vZ/pT/svWDKB+F8Mq/r1MtFfI4wtNiLV7ydEsUXdFZLHjYNXPjNXSETbBIMstVkj0GMjBBRz8IZhcaaOr/kRrKaZZzs1ehKFbUSQu/Ug6mxYk/nlbkxJbQqlC3oLXM4e56QiTKxmrnBqcfLG4B4jh0CMYVQR3MEXzZrQR5xVLz6s6ckJAH9Ed8GbyAKB4fZv0iADkQ8OyyC+6+Z452N+iErf4+IsR6J47ueWO5apWGUOB2B9j+4kLm2n9rvtyISYhlKTVe4X9sq8M9blMSSrfRv2APu98yoVx5CoGd7/dlZxkxIXPCN0WwxybdT4d2W/0ElAv+3dc2aT1KtlfjCgRaFaN4gBdSSn9njbvcFAn97o97h+t1JHIJvgnq3m9l15/CPEUQ3nQnCEYIWCq+H1Vp2wk0MiWWsTZr482LU9FTD8MJBMJJ4mVbSp3lC2Z/a9BV18nP4AQDj69RGAAocFJfdqpxGWymDIOGqbkEk9sgfGeFPOV6GZNy+JhvI3lzSqs+81n3O7/3tJPkX7Bdr56OliOTwSnCLkQWQyAjYUIBkKXQ6sA+evWXrneM0+JmNW+fGt49wNuzLCwabehlEfl8P+4cSa7TQuTu1f5XlA3sz+9/Wq6F2iorVqEvojwmdSuYppSE4nlSlBdDd+VK8+nL0smb9IRKZvFP87REKYa7jvI3nbb4j6zJ2+VAuKse/uUfWMYP6ZeuDY3tXf4HVID7NsEfIiPIWhVvzDaZozDoMq9uj9WdWECyCa7CRtN63qYu+DMg1Ea/OVuW8nSGRawJxvWCWLj1Qx6LsD8q66vHUpE7J/sLoOo0Jo6xch2ZRNGHUG06 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)(376005)(82310400017);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 May 2024 11:31:33.3886 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 21a1f99b-7414-46ba-9aa3-08dc701b945c 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: SA2PEPF00003AE8.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR12MB7481 X-Patchwork-Delegate: kuba@kernel.org From: Shay Drory The cited patch change register devlink flow, and neglect to reflect the changes for peer devlink set logic. Peer devlink set is triggering a call trace if done after devl_register.[1] Hence, align peer devlink set logic with register devlink flow. [1] WARNING: CPU: 4 PID: 3394 at net/devlink/core.c:155 devlink_rel_nested_in_add+0x177/0x180 CPU: 4 PID: 3394 Comm: kworker/u40:1 Not tainted 6.9.0-rc4_for_linust_min_debug_2024_04_16_14_08 #1 Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS rel-1.13.0-0-gf21b5a4aeb02-prebuilt.qemu.org 04/01/2014 Workqueue: mlx5_vhca_event0 mlx5_vhca_state_work_handler [mlx5_core] RIP: 0010:devlink_rel_nested_in_add+0x177/0x180 Call Trace: ? __warn+0x78/0x120 ? devlink_rel_nested_in_add+0x177/0x180 ? report_bug+0x16d/0x180 ? handle_bug+0x3c/0x60 ? exc_invalid_op+0x14/0x70 ? asm_exc_invalid_op+0x16/0x20 ? devlink_port_init+0x30/0x30 ? devlink_port_type_clear+0x50/0x50 ? devlink_rel_nested_in_add+0x177/0x180 ? devlink_rel_nested_in_add+0xdd/0x180 mlx5_sf_mdev_event+0x74/0xb0 [mlx5_core] notifier_call_chain+0x35/0xb0 blocking_notifier_call_chain+0x3d/0x60 mlx5_blocking_notifier_call_chain+0x22/0x30 [mlx5_core] mlx5_sf_dev_probe+0x185/0x3e0 [mlx5_core] auxiliary_bus_probe+0x38/0x80 ? driver_sysfs_add+0x51/0x80 really_probe+0xc5/0x3a0 ? driver_probe_device+0x90/0x90 __driver_probe_device+0x80/0x160 driver_probe_device+0x1e/0x90 __device_attach_driver+0x7d/0x100 bus_for_each_drv+0x80/0xd0 __device_attach+0xbc/0x1f0 bus_probe_device+0x86/0xa0 device_add+0x64f/0x860 __auxiliary_device_add+0x3b/0xa0 mlx5_sf_dev_add+0x139/0x330 [mlx5_core] mlx5_sf_dev_state_change_handler+0x1e4/0x250 [mlx5_core] notifier_call_chain+0x35/0xb0 blocking_notifier_call_chain+0x3d/0x60 mlx5_vhca_state_work_handler+0x151/0x200 [mlx5_core] process_one_work+0x13f/0x2e0 worker_thread+0x2bd/0x3c0 ? rescuer_thread+0x410/0x410 kthread+0xc4/0xf0 ? kthread_complete_and_exit+0x20/0x20 ret_from_fork+0x2d/0x50 ? kthread_complete_and_exit+0x20/0x20 ret_from_fork_asm+0x11/0x20 Fixes: bf729988303a ("net/mlx5: Restore mistakenly dropped parts in register devlink flow") Fixes: c6e77aa9dd82 ("net/mlx5: Register devlink first under devlink lock") Signed-off-by: Shay Drory Reviewed-by: Moshe Shemesh Signed-off-by: Tariq Toukan Reviewed-by: Simon Horman --- .../net/ethernet/mellanox/mlx5/core/main.c | 14 +++++--------- .../mellanox/mlx5/core/sf/dev/driver.c | 19 ++++++++----------- 2 files changed, 13 insertions(+), 20 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/main.c b/drivers/net/ethernet/mellanox/mlx5/core/main.c index 331ce47f51a1..6574c145dc1e 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/main.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/main.c @@ -1680,6 +1680,8 @@ int mlx5_init_one_light(struct mlx5_core_dev *dev) struct devlink *devlink = priv_to_devlink(dev); int err; + devl_lock(devlink); + devl_register(devlink); dev->state = MLX5_DEVICE_STATE_UP; err = mlx5_function_enable(dev, true, mlx5_tout_ms(dev, FW_PRE_INIT_TIMEOUT)); if (err) { @@ -1693,27 +1695,21 @@ int mlx5_init_one_light(struct mlx5_core_dev *dev) goto query_hca_caps_err; } - devl_lock(devlink); - devl_register(devlink); - err = mlx5_devlink_params_register(priv_to_devlink(dev)); if (err) { mlx5_core_warn(dev, "mlx5_devlink_param_reg err = %d\n", err); - goto params_reg_err; + goto query_hca_caps_err; } devl_unlock(devlink); return 0; -params_reg_err: - devl_unregister(devlink); - devl_unlock(devlink); query_hca_caps_err: - devl_unregister(devlink); - devl_unlock(devlink); mlx5_function_disable(dev, true); out: dev->state = MLX5_DEVICE_STATE_INTERNAL_ERROR; + devl_unregister(devlink); + devl_unlock(devlink); return err; } diff --git a/drivers/net/ethernet/mellanox/mlx5/core/sf/dev/driver.c b/drivers/net/ethernet/mellanox/mlx5/core/sf/dev/driver.c index 7ebe71280827..b2986175d9af 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/sf/dev/driver.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/sf/dev/driver.c @@ -60,6 +60,13 @@ static int mlx5_sf_dev_probe(struct auxiliary_device *adev, const struct auxilia goto remap_err; } + /* Peer devlink logic expects to work on unregistered devlink instance. */ + err = mlx5_core_peer_devlink_set(sf_dev, devlink); + if (err) { + mlx5_core_warn(mdev, "mlx5_core_peer_devlink_set err=%d\n", err); + goto peer_devlink_set_err; + } + if (MLX5_ESWITCH_MANAGER(sf_dev->parent_mdev)) err = mlx5_init_one_light(mdev); else @@ -69,20 +76,10 @@ static int mlx5_sf_dev_probe(struct auxiliary_device *adev, const struct auxilia goto init_one_err; } - err = mlx5_core_peer_devlink_set(sf_dev, devlink); - if (err) { - mlx5_core_warn(mdev, "mlx5_core_peer_devlink_set err=%d\n", err); - goto peer_devlink_set_err; - } - return 0; -peer_devlink_set_err: - if (mlx5_dev_is_lightweight(sf_dev->mdev)) - mlx5_uninit_one_light(sf_dev->mdev); - else - mlx5_uninit_one(sf_dev->mdev); init_one_err: +peer_devlink_set_err: iounmap(mdev->iseg); remap_err: mlx5_mdev_uninit(mdev); From patchwork Thu May 9 11:29:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tariq Toukan X-Patchwork-Id: 13659667 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2043.outbound.protection.outlook.com [40.107.236.43]) (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 64B9013172F for ; Thu, 9 May 2024 11:31:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.236.43 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715254302; cv=fail; b=gEr20B6Z9VUn9QWhnAWkC3dr0pCJ01tvfDrDagHeU8m2i6//lb+pG0j8LUTxsj5k+yZSJYvqmXHsXillUfvsPhoHeIdekNRtA6bAG5LnJENK7C05hjWuLWfl51cYYKWkAQEe1d8a12aw6HiWW1M8ejbM7/xT6rIR7/kUjWsfmY4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715254302; c=relaxed/simple; bh=A/2nIPTBXEIB5HVrtYPUp6p4CMTkuANxp1H+hreAp2k=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Axb6JPwUK1aRQSuVRYOdFegN52jDtzqUnlSTJyH3ozYxRfHtxSmbT+cNPn0mUFWaEqn6fUG9QxmsESgZOmh5rJ7DJfke/sprtkw2w/ITqpHoFL+Hi1gBt6gPE/QpOujBpRoxWVmV0JVSsSs3c0TdAKAjErNP00MRmQ/8HZGkswE= 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=RH5Eo/mL; arc=fail smtp.client-ip=40.107.236.43 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="RH5Eo/mL" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fesqwokc4E9fFi+hTZGNpRiStRIcglXeNAR0QPXkOPc6bnAZqBjhzyKgvRh6P2x+Gk3pu+VxINinkoLQHcVrLhFUDDG1GMXQNDo5hHptlKWTpLKb9wzp+iBNjx9SJ4oHaK9ntcXwXCHaB1OrIhdB5iZIuYrudd5B3Hw0Tfx50GBnvm42axl2a4tdWOeHvoRjsX8jvlp2ksQBxzIwCULZyNIroDkE5SlUXRQcxVcpzWtgzsZInubyxh9v219OtYVsqqZOTC49NgtZvhgTAJZVWwOjBySMnYHKrzJtaSXcnQMBD4R7B1XaGV+3ArOG01JPJGkyIaOzI5mYmi+jUyQXdQ== 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=hoV5TJ+sUED9nWbLBvuH1qNRMZatb0F/SZvvzkdoorI=; b=R73rMw24FdUPS0Bc1dLfAWzfI6Uddv0BPdPwvkrG8Ipe4VVM12HQgsMUOpRIr5OAiux6LZlVpl2aAXz+uGLBO2d8GS+2OKQZpZvGEQEq+NNFKg5S0nceXZqhfyGeGdrZLDViJzDIEZM22O11dn1eRk0Xos3EGPxXa6gK9Utsc0e+fJFIdJAtwlL+RUdZN3N/q+00uHkos6J+Fs+cAfq8+Bji3ZlXCaTFu1UlUVz1/ugCUYBZxc4pcIOJ3cn0MAfw3cje7Hptp17rlKHylsTyHTlnSp4QEyiQhCyqPdSoRM7WgwQIOrQ+SWBQuIKozAmAaBJbwZ6pexlPYa8UKLFRFA== 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=hoV5TJ+sUED9nWbLBvuH1qNRMZatb0F/SZvvzkdoorI=; b=RH5Eo/mL5nwTRFOlhu8aVtah8VnmRJ56saD6Yy+fmgdDOmZU4ajEkO74HBZEscd4sqy8NtTExSpZoOvzb7V8veXpZoB803V+niXjntdrBTL/Be06t6uK1bdti6DRMlKHUnfaqeZEhU8eFxEW5VUi/xFrmMJKOcD0kXrZD6VNkoYWK7TMMZtGpfY4F/olddUUo9Doui3otljnfY39tUv1yl62rl0wpMYOjJdk/bSEgWBviKQz1cP5SI8fLc8jkrBy1wzbmPcmu3htvKFF8SaICZG6xcTLn+PBrFNDmf36WrknU444keNhlV7ffrQQy/E+YNjYPlOdZ5BpW2YQVqag4A== Received: from PH8PR07CA0015.namprd07.prod.outlook.com (2603:10b6:510:2cd::20) by CH0PR12MB8461.namprd12.prod.outlook.com (2603:10b6:610:183::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.47; Thu, 9 May 2024 11:31:37 +0000 Received: from MWH0EPF000A672F.namprd04.prod.outlook.com (2603:10b6:510:2cd:cafe::56) by PH8PR07CA0015.outlook.office365.com (2603:10b6:510:2cd::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.48 via Frontend Transport; Thu, 9 May 2024 11:31:36 +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 MWH0EPF000A672F.mail.protection.outlook.com (10.167.249.21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.18 via Frontend Transport; Thu, 9 May 2024 11:31:35 +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; Thu, 9 May 2024 04:31:15 -0700 Received: from rnnvmail205.nvidia.com (10.129.68.10) 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; Thu, 9 May 2024 04:31:14 -0700 Received: from vdi.nvidia.com (10.127.8.10) by mail.nvidia.com (10.129.68.10) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Thu, 9 May 2024 04:31:11 -0700 From: Tariq Toukan To: "David S. Miller" , Jakub Kicinski , Paolo Abeni , Eric Dumazet CC: , Saeed Mahameed , Gal Pressman , Leon Romanovsky , Maher Sanalla , Mark Bloch , Tariq Toukan Subject: [PATCH net 3/5] net/mlx5: Reload only IB representors upon lag disable/enable Date: Thu, 9 May 2024 14:29:49 +0300 Message-ID: <20240509112951.590184-4-tariqt@nvidia.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240509112951.590184-1-tariqt@nvidia.com> References: <20240509112951.590184-1-tariqt@nvidia.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MWH0EPF000A672F:EE_|CH0PR12MB8461:EE_ X-MS-Office365-Filtering-Correlation-Id: 53e0fa75-76d9-42a4-69fc-08dc701b95d8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|1800799015|82310400017|36860700004|376005; X-Microsoft-Antispam-Message-Info: owDp07IaGydAFL/sQ1TvcsIV8F3M50UtIltpmyh0d8rCQaCuiZBWpxiDPNPVEsK5rYys2u2cz088IRVrTZCiI62dnx4q4YoYfkYJ0MdYkv5YypifBzgRRsb66GQl1GJng7bJwGcnFhu3DOMqaoSu8oabN5DlUG/9iommDd4oZETOhybMkWQE7MoKgiUDup2l2DLTDj00oHhg1oiWc5MbiPcqF+hcDybFeEKyS4Yvy+YwDX7kBpTdmPAAR6toHyNI260uAJO+TEgdPheIbFVeNeqI7Qcqq7cAshbPHZr+Sbat/mC8dDd6qljWyx1iXM8ePrsvsrEvIbrPg+EMBMRcHUIYmn3K4zvELlflOhimAKO0t5D1VyxUrISuMjp2g1mcpWWBtZRqy+CWBss5tjjkRWBR+OYkSqjMfxMYkRjVESXQnvby2b+FvZzC6wF5PCnTPFWhNmjUeCTeWuzXgfMyPSU7Km33PLyygl/FDbM4gSX5kUoRziw9xbLPJYgjo95kYl+3nZWyr59ShXL9ZkFtXXL/EVFwQzdhChGtzvQIoqR//paU7dNna9RssVQN0LsjnXaM3K2t6XmJUu61FbWkqTZu0Mbp0x7e1zXQw6gl2+n6M7yvGznNwHzTYrmXlrk6h2D5KflNutfYbg59wwoAtM3Ac65kDb1YtUP0oJTFdoVqmP4mPY/21vz2bPrRTdQvJ5vARrQjKz1stwPWCMGEn9iV/g+gkvZTFNsyioSdozrUThzO8rA9LLRujRVbSKdzaCmFhiGHRVjj9D/KnLnI7CWC995VkBFgFQhzxEVxSYGeIqSjueipZY/xCoa3ITPLWFEul//cqVIgxuccQfpo49FFwWaqXLrB4a/M5earN53qmvlRfCGthl3PzSg8oTm8wApkKHyls9rMN+By7C+0wb8smdH3Gk6tw5aOgM7+JAiJpuE+QLPOB2gQwN26Gh+H9Ova9mPFQP9gDJ84CDErWJcrQecOMxGvJBMb7D9qSehL7QOy6lXcCYdQHw7XP9V0x2gXET+PiRxWyFzvatv+V9pXEPS5ZmoGJsrMk79oPdTSIu4yZVvjloimfBMC0ISAeAAyL1tHtpiHgjPVUNL/mZSgnwEbScmve32sHdemTAvHiEOQSEJTU8G8hogBvTrOy93nB6GC1tq7lroYlP6CZCVQF80vnzt38MyK6MURjyTNulTYeFJXdpXcJYv7upFGGE3bU710UODVJr9XyH5MgNrSWPYAd2Fs+bsPO+ncpeDi5vjyuO+39vN08f6n2cBw7fpFvQ0vdZwg2o9trwl382Dy6eFGf5rjKCcqf7NKtPtnQ0nGhChjKhNQWWaRFov8iCGRoZEwwkIGuepzsVvmqUVElTbF/+e+Dh5VnRY8Lgo= 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)(1800799015)(82310400017)(36860700004)(376005);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 May 2024 11:31:35.9246 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 53e0fa75-76d9-42a4-69fc-08dc701b95d8 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: MWH0EPF000A672F.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR12MB8461 X-Patchwork-Delegate: kuba@kernel.org From: Maher Sanalla On lag disable, the bond IB device along with all of its representors are destroyed, and then the slaves' representors get reloaded. In case the slave IB representor load fails, the eswitch error flow unloads all representors, including ethernet representors, where the netdevs get detached and removed from lag bond. Such flow is inaccurate as the lag driver is not responsible for loading/unloading ethernet representors. Furthermore, the flow described above begins by holding lag lock to prevent bond changes during disable flow. However, when reaching the ethernet representors detachment from lag, the lag lock is required again, triggering the following deadlock: Call trace: __switch_to+0xf4/0x148 __schedule+0x2c8/0x7d0 schedule+0x50/0xe0 schedule_preempt_disabled+0x18/0x28 __mutex_lock.isra.13+0x2b8/0x570 __mutex_lock_slowpath+0x1c/0x28 mutex_lock+0x4c/0x68 mlx5_lag_remove_netdev+0x3c/0x1a0 [mlx5_core] mlx5e_uplink_rep_disable+0x70/0xa0 [mlx5_core] mlx5e_detach_netdev+0x6c/0xb0 [mlx5_core] mlx5e_netdev_change_profile+0x44/0x138 [mlx5_core] mlx5e_netdev_attach_nic_profile+0x28/0x38 [mlx5_core] mlx5e_vport_rep_unload+0x184/0x1b8 [mlx5_core] mlx5_esw_offloads_rep_load+0xd8/0xe0 [mlx5_core] mlx5_eswitch_reload_reps+0x74/0xd0 [mlx5_core] mlx5_disable_lag+0x130/0x138 [mlx5_core] mlx5_lag_disable_change+0x6c/0x70 [mlx5_core] // hold ldev->lock mlx5_devlink_eswitch_mode_set+0xc0/0x410 [mlx5_core] devlink_nl_cmd_eswitch_set_doit+0xdc/0x180 genl_family_rcv_msg_doit.isra.17+0xe8/0x138 genl_rcv_msg+0xe4/0x220 netlink_rcv_skb+0x44/0x108 genl_rcv+0x40/0x58 netlink_unicast+0x198/0x268 netlink_sendmsg+0x1d4/0x418 sock_sendmsg+0x54/0x60 __sys_sendto+0xf4/0x120 __arm64_sys_sendto+0x30/0x40 el0_svc_common+0x8c/0x120 do_el0_svc+0x30/0xa0 el0_svc+0x20/0x30 el0_sync_handler+0x90/0xb8 el0_sync+0x160/0x180 Thus, upon lag enable/disable, load and unload only the IB representors of the slaves preventing the deadlock mentioned above. While at it, refactor the mlx5_esw_offloads_rep_load() function to have a static helper method for its internal logic, in symmetry with the representor unload design. Fixes: 598fe77df855 ("net/mlx5: Lag, Create shared FDB when in switchdev mode") Co-developed-by: Mark Bloch Signed-off-by: Mark Bloch Signed-off-by: Maher Sanalla Signed-off-by: Tariq Toukan Reviewed-by: Simon Horman --- .../net/ethernet/mellanox/mlx5/core/eswitch.h | 4 +-- .../mellanox/mlx5/core/eswitch_offloads.c | 28 ++++++++++++------- .../net/ethernet/mellanox/mlx5/core/lag/lag.c | 6 ++-- .../ethernet/mellanox/mlx5/core/lag/mpesw.c | 4 +-- 4 files changed, 25 insertions(+), 17 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.h b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.h index 349e28a6dd8d..ef55674876cb 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.h +++ b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.h @@ -833,7 +833,7 @@ int mlx5_eswitch_offloads_single_fdb_add_one(struct mlx5_eswitch *master_esw, struct mlx5_eswitch *slave_esw, int max_slaves); void mlx5_eswitch_offloads_single_fdb_del_one(struct mlx5_eswitch *master_esw, struct mlx5_eswitch *slave_esw); -int mlx5_eswitch_reload_reps(struct mlx5_eswitch *esw); +int mlx5_eswitch_reload_ib_reps(struct mlx5_eswitch *esw); bool mlx5_eswitch_block_encap(struct mlx5_core_dev *dev); void mlx5_eswitch_unblock_encap(struct mlx5_core_dev *dev); @@ -925,7 +925,7 @@ mlx5_eswitch_offloads_single_fdb_del_one(struct mlx5_eswitch *master_esw, static inline int mlx5_eswitch_get_npeers(struct mlx5_eswitch *esw) { return 0; } static inline int -mlx5_eswitch_reload_reps(struct mlx5_eswitch *esw) +mlx5_eswitch_reload_ib_reps(struct mlx5_eswitch *esw) { return 0; } diff --git a/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c b/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c index 844d3e3a65dd..e8caf12f4c4f 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c @@ -2502,6 +2502,16 @@ void esw_offloads_cleanup(struct mlx5_eswitch *esw) esw_offloads_cleanup_reps(esw); } +static int __esw_offloads_load_rep(struct mlx5_eswitch *esw, + struct mlx5_eswitch_rep *rep, u8 rep_type) +{ + if (atomic_cmpxchg(&rep->rep_data[rep_type].state, + REP_REGISTERED, REP_LOADED) == REP_REGISTERED) + return esw->offloads.rep_ops[rep_type]->load(esw->dev, rep); + + return 0; +} + static void __esw_offloads_unload_rep(struct mlx5_eswitch *esw, struct mlx5_eswitch_rep *rep, u8 rep_type) { @@ -2526,13 +2536,11 @@ static int mlx5_esw_offloads_rep_load(struct mlx5_eswitch *esw, u16 vport_num) int err; rep = mlx5_eswitch_get_rep(esw, vport_num); - for (rep_type = 0; rep_type < NUM_REP_TYPES; rep_type++) - if (atomic_cmpxchg(&rep->rep_data[rep_type].state, - REP_REGISTERED, REP_LOADED) == REP_REGISTERED) { - err = esw->offloads.rep_ops[rep_type]->load(esw->dev, rep); - if (err) - goto err_reps; - } + for (rep_type = 0; rep_type < NUM_REP_TYPES; rep_type++) { + err = __esw_offloads_load_rep(esw, rep, rep_type); + if (err) + goto err_reps; + } return 0; @@ -3277,7 +3285,7 @@ static void esw_destroy_offloads_acl_tables(struct mlx5_eswitch *esw) esw_vport_destroy_offloads_acl_tables(esw, vport); } -int mlx5_eswitch_reload_reps(struct mlx5_eswitch *esw) +int mlx5_eswitch_reload_ib_reps(struct mlx5_eswitch *esw) { struct mlx5_eswitch_rep *rep; unsigned long i; @@ -3290,13 +3298,13 @@ int mlx5_eswitch_reload_reps(struct mlx5_eswitch *esw) if (atomic_read(&rep->rep_data[REP_ETH].state) != REP_LOADED) return 0; - ret = mlx5_esw_offloads_rep_load(esw, MLX5_VPORT_UPLINK); + ret = __esw_offloads_load_rep(esw, rep, REP_IB); if (ret) return ret; mlx5_esw_for_each_rep(esw, i, rep) { if (atomic_read(&rep->rep_data[REP_ETH].state) == REP_LOADED) - mlx5_esw_offloads_rep_load(esw, rep->vport); + __esw_offloads_load_rep(esw, rep, REP_IB); } return 0; diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c b/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c index 69d482f7c5a2..37598d116f3b 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c @@ -814,7 +814,7 @@ void mlx5_disable_lag(struct mlx5_lag *ldev) if (shared_fdb) for (i = 0; i < ldev->ports; i++) if (!(ldev->pf[i].dev->priv.flags & MLX5_PRIV_FLAGS_DISABLE_ALL_ADEV)) - mlx5_eswitch_reload_reps(ldev->pf[i].dev->priv.eswitch); + mlx5_eswitch_reload_ib_reps(ldev->pf[i].dev->priv.eswitch); } static bool mlx5_shared_fdb_supported(struct mlx5_lag *ldev) @@ -922,7 +922,7 @@ static void mlx5_do_bond(struct mlx5_lag *ldev) mlx5_rescan_drivers_locked(dev0); for (i = 0; i < ldev->ports; i++) { - err = mlx5_eswitch_reload_reps(ldev->pf[i].dev->priv.eswitch); + err = mlx5_eswitch_reload_ib_reps(ldev->pf[i].dev->priv.eswitch); if (err) break; } @@ -933,7 +933,7 @@ static void mlx5_do_bond(struct mlx5_lag *ldev) mlx5_deactivate_lag(ldev); mlx5_lag_add_devices(ldev); for (i = 0; i < ldev->ports; i++) - mlx5_eswitch_reload_reps(ldev->pf[i].dev->priv.eswitch); + mlx5_eswitch_reload_ib_reps(ldev->pf[i].dev->priv.eswitch); mlx5_core_err(dev0, "Failed to enable lag\n"); return; } diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lag/mpesw.c b/drivers/net/ethernet/mellanox/mlx5/core/lag/mpesw.c index 82889f30506e..571ea26edd0c 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/lag/mpesw.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/lag/mpesw.c @@ -99,7 +99,7 @@ static int enable_mpesw(struct mlx5_lag *ldev) dev0->priv.flags &= ~MLX5_PRIV_FLAGS_DISABLE_IB_ADEV; mlx5_rescan_drivers_locked(dev0); for (i = 0; i < ldev->ports; i++) { - err = mlx5_eswitch_reload_reps(ldev->pf[i].dev->priv.eswitch); + err = mlx5_eswitch_reload_ib_reps(ldev->pf[i].dev->priv.eswitch); if (err) goto err_rescan_drivers; } @@ -113,7 +113,7 @@ static int enable_mpesw(struct mlx5_lag *ldev) err_add_devices: mlx5_lag_add_devices(ldev); for (i = 0; i < ldev->ports; i++) - mlx5_eswitch_reload_reps(ldev->pf[i].dev->priv.eswitch); + mlx5_eswitch_reload_ib_reps(ldev->pf[i].dev->priv.eswitch); mlx5_mpesw_metadata_cleanup(ldev); return err; } From patchwork Thu May 9 11:29:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tariq Toukan X-Patchwork-Id: 13659668 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2080.outbound.protection.outlook.com [40.107.93.80]) (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 529281311A0 for ; Thu, 9 May 2024 11:31:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.93.80 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715254304; cv=fail; b=YBE8E3YOtlhQEoJB4uexWEFDDOAxMgTmWw53K6EC4XXFjW5JJV/OOGBqH26ZsXkbEOlg6Q8W4/p3BAkgl8xglghrhmhV0UFMBGfxUOegJj0+ZnU7DYE4EX7+jvggLvV1WyDkA5xrpZMnAIWK2YkYGe4RofJAktrQgr5iM2Rdv7M= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715254304; c=relaxed/simple; bh=74qneyqWlMghymUdoDfqxHUG6E+xzpTT1KqimUNnFpY=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Ssxja3TJReKQImw/8Ck62dnvLhFHp+WQRWh3Ctp6Be7xO52VnTI+xkCyZuRuOWzRX3onoCM+gucyhG31fhs9Cniz9A9tO1yAntNnBADG9pJTVI04KK0eMV/rlgNCWPJ/OLnVf0kOkn/3L7dP7CjK7f0z5YJRLrVRpWddjFA++qQ= 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=AEHlW0wy; arc=fail smtp.client-ip=40.107.93.80 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="AEHlW0wy" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mE/sZjupQsUk/M5AGmhw+flo8dW653WAdbTHQQAZtLC7X+/FYb9Z6iDy+egIrzJ84M88SRM+DbMBDGL9oD1mJYDtUos6+5f8q78gdANVDjJ/V+cBiFjxAq158CavEsDDtL/cFRq3tWolhH9y3MyEN52PU8dGsvftN6+qbk06TPiONeGcpJPaS+LByRArdhx0OrlnIyhfkFsT82ywbMjlXGH3cBCQWPhPexUyb4PLLaiOd2AZNqbJ3vJ6/tKvC8w01E8O7wcd2wzYMzrCFAFXhJkiTZxuDkPSpJaIQropNigZa0dSs56OENSWL0sE7JSOZwu834Qq//cZz/g0oFGKtQ== 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=xQqfcbXUJ4EKiMknVoTD0/B1CfkgdV+BMaqOwBNiAAs=; b=EtEgfBpFrX5a2MCVL7jfgDfVtaRrEXpEO8IFwE+er3uargh9rO5pdp+/foWUvdE9+8wfmgXIMVW5yG3SRfbaWyCtK20OBEfFIH+klp6e7vK98cZcHkJJucbef2+hINIelrVDjKle+W7Qwu32N8I7DAmn3fvJ9oWKHgEhviBElGHs/YA9j/tWPQ0AakgQzjLJCE0gZv7QvX5VuGuCLZfJIHnd1ptgPYuB9J3nt5ghQ8qyhQNGyMZoiOj/Lt0Rxo5xZsbSOfd4U3O5pkQsyTc/VuSUTA5xEQnXo6hKq3OdU9ivngX8CiMaqdHfY9MgF92sYH3UEFXQ6DsZylWSAQ3JWA== 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=xQqfcbXUJ4EKiMknVoTD0/B1CfkgdV+BMaqOwBNiAAs=; b=AEHlW0wywPEamZOBABO++Ltm0Pq5LgGWHKZO2JqjVMeGo2l4RMhywu4ICgqEM95RQSHzNy1ZJ1p+MbyIVP+U+iw8TsXXc7ia/E8h3ALQsD2eSMqZDCKvs5FovZ/e7Tulu/11K8/IGlijFvPnZJ1RLZvce//smgggS9tKn1zz0zCtYGhHbqH9kXbdRFKlokXiYNUDATbzR9krsm6vh21KJKZab2O42mMgydjmrUaiy3Q3ciEJaU7c/vgjZ0wvSUsQb6n5oB/Oq6E+zR4MzgFZfH7x1rCLW7IE8eZhg7SjeSxFZQ/NQagTyRk2GZAzQ99UpJ3tUT5XP0saU0E4EaQnsQ== Received: from SA1P222CA0127.NAMP222.PROD.OUTLOOK.COM (2603:10b6:806:3c2::17) by SJ2PR12MB8955.namprd12.prod.outlook.com (2603:10b6:a03:542::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.47; Thu, 9 May 2024 11:31:35 +0000 Received: from SN1PEPF0002BA51.namprd03.prod.outlook.com (2603:10b6:806:3c2:cafe::d8) by SA1P222CA0127.outlook.office365.com (2603:10b6:806:3c2::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.47 via Frontend Transport; Thu, 9 May 2024 11:31:34 +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 SN1PEPF0002BA51.mail.protection.outlook.com (10.167.242.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.18 via Frontend Transport; Thu, 9 May 2024 11:31:34 +0000 Received: from rnnvmail205.nvidia.com (10.129.68.10) 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; Thu, 9 May 2024 04:31:18 -0700 Received: from rnnvmail205.nvidia.com (10.129.68.10) by rnnvmail205.nvidia.com (10.129.68.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Thu, 9 May 2024 04:31:18 -0700 Received: from vdi.nvidia.com (10.127.8.10) by mail.nvidia.com (10.129.68.10) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Thu, 9 May 2024 04:31:15 -0700 From: Tariq Toukan To: "David S. Miller" , Jakub Kicinski , Paolo Abeni , Eric Dumazet CC: , Saeed Mahameed , Gal Pressman , Leon Romanovsky , Akiva Goldberger , Moshe Shemesh , Tariq Toukan Subject: [PATCH net 4/5] net/mlx5: Add a timeout to acquire the command queue semaphore Date: Thu, 9 May 2024 14:29:50 +0300 Message-ID: <20240509112951.590184-5-tariqt@nvidia.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240509112951.590184-1-tariqt@nvidia.com> References: <20240509112951.590184-1-tariqt@nvidia.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN1PEPF0002BA51:EE_|SJ2PR12MB8955:EE_ X-MS-Office365-Filtering-Correlation-Id: 99b7df2c-1914-4e73-99f0-08dc701b94ef X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|82310400017|36860700004|376005|1800799015; X-Microsoft-Antispam-Message-Info: JQePeTiacIS5AYteOqqD3is8m3grMX0zoFEwGb/6eyh5qruu1zgiKr6A9CbYfggTCsgqFBc4bFC3slg7R+oMnS/Gl8b3WOCpD95K2BUO/5kFFc/xbJnwypBlJXwSi6l3Zc1tth/6hSOIjXEwy3FpEwjsEeSCpeMLn5s36uze0Xf+z1fSvF68ftrV4ychQvf6Xcrn2fyVW8iqrBb4SjjLmG1+RX4FLFKWLLQx2bbVtnBFq9Z/0WPTnFynll/IHodncRu7Ss7zbb/NFgx0LZ8VuZTuspxDcffGLlks1/icbZwgO4o/495elgTFcrH6SQgnhxubxoz65vZ1P8O2AgzFykRj5zV4K8rkAwEc74zu0oHNtv/ElkVGODVVNDZRJcM2QnAGclnHRhCtlXDz0hrQlbek+B4QChVQybZJ8GqgKL49hBvwKRx/l3ccasw1cN4cTfaGfqiKEXYnfQRryC2QnUNlovTDMb4D1Sudt5Pi97BzxAGh50lBw9SyqSCAhaCpT1Yhhl/51q3YVcAX7yOXgRgfh0vxxkLWchY74VJlCy7rZeOHVqE1cZ4+KsD9bbv+9b6fsBCO+q6hKL+SyWb01Cnrf3cM2bR60yMvNOR4sxXr7JvIBPe52wm3mbwVuQxixJIq0QrLCgr/0xbGns9OCXkv5zbV9rJyvuzm7R2L+ZhV2u78tjlI3uiLipTtimJ2beJy8HAvpeXu7RxfrPqhC9ChEqgbDZfXH0eKU4BEBXu7YwKjf9OrxMsK5HCBEjd5tD7Uh5zjQfT1zdFrghoms+wo4ELL3LB3MeOt6mI70uq2D6DI6mQf+C0382XENnpucPM8snIzSJWSOF6YhHn5SO1J1zNnHQLxFUbIy55SemHb01W7CsfkkPjKAVkrjFP7fGRaRNmpam/ODaAYIqLF1xNdtPgOYkX2iCpBTp2XhmB8TYAgKthOwOSIRJ3uGP/+kAGI3aU81Lt24mKPMCkY1J+GgbLBCZBzEXnxkijHOj2Vod1mczdNjBQJykipASygkb+m08FFbCK3Jv3DQhJVIi2OcfBAlRa27wslgL1X9n9ZygV4RAVNikWnZm+Gl0l+95EB2f9gcsm4mPcd4W83rsFMpqSxP3mnEwx4SC1c7qgQwsBHnXkaN+ibkySMqB2W8sOd2wQbDHLcS2TtPrSS78TO4NlHSQsDN+vMLrYw1SOfmWXw1rABNEFoByfTsHk8W3isHY7T4IlgW9l5ysh3imWhLQbS9YXtbA/c6e1YqTFchTAz4Bqe2ZZX6KWFCH3Jhcanm6ZpdmI4QTrvsbudoY3WhfpX/b30HHcZwb925WfQHQivYcrRmhcSmXmpspJ3PYASFwYYQTGkG9zDiU6dqnt2LJnvhYE1uorO5oeoGee81XleSERkcxIkDeVw4bMM 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)(82310400017)(36860700004)(376005)(1800799015);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 May 2024 11:31:34.3519 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 99b7df2c-1914-4e73-99f0-08dc701b94ef 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: SN1PEPF0002BA51.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR12MB8955 X-Patchwork-Delegate: kuba@kernel.org From: Akiva Goldberger Prevent forced completion handling on an entry that has not yet been assigned an index, causing an out of bounds access on idx = -22. Instead of waiting indefinitely for the sem, blocking flow now waits for index to be allocated or a sem acquisition timeout before beginning the timer for FW completion. Kernel log example: mlx5_core 0000:06:00.0: wait_func_handle_exec_timeout:1128:(pid 185911): cmd[-22]: CREATE_UCTX(0xa04) No done completion Fixes: 8e715cd613a1 ("net/mlx5: Set command entry semaphore up once got index free") Signed-off-by: Akiva Goldberger Reviewed-by: Moshe Shemesh Signed-off-by: Tariq Toukan --- drivers/net/ethernet/mellanox/mlx5/core/cmd.c | 41 +++++++++++++++---- include/linux/mlx5/driver.h | 1 + 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/cmd.c b/drivers/net/ethernet/mellanox/mlx5/core/cmd.c index 4957412ff1f6..511e7fee39ac 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/cmd.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/cmd.c @@ -969,19 +969,32 @@ static void cmd_work_handler(struct work_struct *work) bool poll_cmd = ent->polling; struct mlx5_cmd_layout *lay; struct mlx5_core_dev *dev; - unsigned long cb_timeout; - struct semaphore *sem; + unsigned long timeout; unsigned long flags; int alloc_ret; int cmd_mode; + complete(&ent->handling); + dev = container_of(cmd, struct mlx5_core_dev, cmd); - cb_timeout = msecs_to_jiffies(mlx5_tout_ms(dev, CMD)); + timeout = msecs_to_jiffies(mlx5_tout_ms(dev, CMD)); - complete(&ent->handling); - sem = ent->page_queue ? &cmd->vars.pages_sem : &cmd->vars.sem; - down(sem); if (!ent->page_queue) { + if (down_timeout(&cmd->vars.sem, timeout)) { + mlx5_core_warn(dev, "%s(0x%x) timed out while waiting for a slot.\n", + mlx5_command_str(ent->op), ent->op); + if (ent->callback) { + ent->callback(-EBUSY, ent->context); + mlx5_free_cmd_msg(dev, ent->out); + free_msg(dev, ent->in); + cmd_ent_put(ent); + } else { + ent->ret = -EBUSY; + complete(&ent->done); + } + complete(&ent->slotted); + return; + } alloc_ret = cmd_alloc_index(cmd, ent); if (alloc_ret < 0) { mlx5_core_err_rl(dev, "failed to allocate command entry\n"); @@ -994,10 +1007,11 @@ static void cmd_work_handler(struct work_struct *work) ent->ret = -EAGAIN; complete(&ent->done); } - up(sem); + up(&cmd->vars.sem); return; } } else { + down(&cmd->vars.pages_sem); ent->idx = cmd->vars.max_reg_cmds; spin_lock_irqsave(&cmd->alloc_lock, flags); clear_bit(ent->idx, &cmd->vars.bitmask); @@ -1005,6 +1019,8 @@ static void cmd_work_handler(struct work_struct *work) spin_unlock_irqrestore(&cmd->alloc_lock, flags); } + complete(&ent->slotted); + lay = get_inst(cmd, ent->idx); ent->lay = lay; memset(lay, 0, sizeof(*lay)); @@ -1023,7 +1039,7 @@ static void cmd_work_handler(struct work_struct *work) ent->ts1 = ktime_get_ns(); cmd_mode = cmd->mode; - if (ent->callback && schedule_delayed_work(&ent->cb_timeout_work, cb_timeout)) + if (ent->callback && schedule_delayed_work(&ent->cb_timeout_work, timeout)) cmd_ent_get(ent); set_bit(MLX5_CMD_ENT_STATE_PENDING_COMP, &ent->state); @@ -1143,6 +1159,9 @@ static int wait_func(struct mlx5_core_dev *dev, struct mlx5_cmd_work_ent *ent) ent->ret = -ECANCELED; goto out_err; } + + wait_for_completion(&ent->slotted); + if (cmd->mode == CMD_MODE_POLLING || ent->polling) wait_for_completion(&ent->done); else if (!wait_for_completion_timeout(&ent->done, timeout)) @@ -1157,6 +1176,9 @@ static int wait_func(struct mlx5_core_dev *dev, struct mlx5_cmd_work_ent *ent) } else if (err == -ECANCELED) { mlx5_core_warn(dev, "%s(0x%x) canceled on out of queue timeout.\n", mlx5_command_str(ent->op), ent->op); + } else if (err == -EBUSY) { + mlx5_core_warn(dev, "%s(0x%x) timeout while waiting for command semaphore.\n", + mlx5_command_str(ent->op), ent->op); } mlx5_core_dbg(dev, "err %d, delivery status %s(%d)\n", err, deliv_status_to_str(ent->status), ent->status); @@ -1208,6 +1230,7 @@ static int mlx5_cmd_invoke(struct mlx5_core_dev *dev, struct mlx5_cmd_msg *in, ent->polling = force_polling; init_completion(&ent->handling); + init_completion(&ent->slotted); if (!callback) init_completion(&ent->done); @@ -1225,7 +1248,7 @@ static int mlx5_cmd_invoke(struct mlx5_core_dev *dev, struct mlx5_cmd_msg *in, return 0; /* mlx5_cmd_comp_handler() will put(ent) */ err = wait_func(dev, ent); - if (err == -ETIMEDOUT || err == -ECANCELED) + if (err == -ETIMEDOUT || err == -ECANCELED || err == -EBUSY) goto out_free; ds = ent->ts2 - ent->ts1; diff --git a/include/linux/mlx5/driver.h b/include/linux/mlx5/driver.h index bf9324a31ae9..80452bd98253 100644 --- a/include/linux/mlx5/driver.h +++ b/include/linux/mlx5/driver.h @@ -862,6 +862,7 @@ struct mlx5_cmd_work_ent { void *context; int idx; struct completion handling; + struct completion slotted; struct completion done; struct mlx5_cmd *cmd; struct work_struct work; From patchwork Thu May 9 11:29:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tariq Toukan X-Patchwork-Id: 13659669 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2069.outbound.protection.outlook.com [40.107.236.69]) (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 35A2013172B for ; Thu, 9 May 2024 11:31:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.236.69 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715254305; cv=fail; b=I8VqotijBBQmFHHA2gpL69sbsHkVLyvsBw7ywKKOU0m0cf03jbxTpAqrdxS4LOwKW02maR3k04Vn5nzM107Jjqb0/Ysd3Yj+G7ijS9nFDPTgO9x/Ei0vfqkUfl6RnWGZuEd0UhicTwPzuREZxSJ5yeSAZJwTzaAgwcg5GZBlLUE= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715254305; c=relaxed/simple; bh=pWyA5CbvPcePRn9+zxkQI1drOT28RCuJIhFNVK2C+nw=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=nAGQVrjuPLQTQxqIFwx4Kv0wJCc/nPQjItY50AzFz0By6QGczJq2SqiZ0B3LFDGCKQHX1mQqrvXHxPKrmGMl6CKWZOZvIgN/Yts7KSdzKKmfYTkISzjA40vsxymeRz3UKHeCDk2zkkfYkqQsIvCJd39Nx+3g5rXS+Ky0oIdsHW0= 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=K3aUJsAz; arc=fail smtp.client-ip=40.107.236.69 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="K3aUJsAz" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mFsMO0axPf75wUfIQXxZsruIFbhL7oGV9EVsvBh/Y5Yddx2tTN6sX4gJ7jkCvfWzyzgBZL5XqWm6ckP4+XtcruJmAIp0S2Wy5rmES+P7iNwQJU4o9TwK7HJDWHFBc0HvsJ1YtKdwJ1HZHP9v6Vlgj4p+ETXMufbWxTenMUn7VqoFbtVr1m54NMJFAAsszPUd4Wxcqmsg8CW9608QzJFbDCbxmH6PvwZcyvQqCFMGtt7Uarf4w1JREdhXQPpudgmQ3FTifubJLUljtK1828sS3NRoe20KVRSLNKMtAnYrOyW1RroSB5/nP1ZRyY9x/jX5mRD0k1tOlietwDBIXBGKvw== 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=wXOfpUYR1958LdBCQxjl+tZsSDx6KPiY8X4QwpE5umY=; b=Y0pxzYMobFzUJM2Ahwk853HIA91OP1btNokgJwzpm2gs8Be18MRWf/gUGtM8ynmgCNy7Ns9YSxA8qDZOLvzaYhYkt3qQmu4XWbbLuUtFw/1ph3m04qihwbo+eMYsBifeocT0IXiZayX1FuWmgCrgGm+jjOKbynowFMNEYptsYUYeElEohBs6qhpCPOVbDHYatQoXgGjgGJlm1ty+tXQBjPfD24KpouzA11j18oOxeZKuvTQGSIttg5MR9CcVrNihLlQ6wTLms8NmgpNzmpvrf/E3YAWYlyrVdawIafKKAwAn+X0W2ISkmQLO+xpBfkGfOTtCyDUETc4s8iWf2KjPQQ== 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=wXOfpUYR1958LdBCQxjl+tZsSDx6KPiY8X4QwpE5umY=; b=K3aUJsAzJrXBigEJetUEZzk7SzKMesAgQewbzA4YTADt4GR3gYX+9ZpndzGSOok0KBLPpjyfVVFwSf3xTtV2CrAcOUDt1vmvK7uf6IreLCN+xw2Uh7vbN92rUPK1MbSRBHlLPW4GB74QIPbjuD1n2EcQ4tF0I5C6ws14uDXXlWZSo5sj9PScN8QtJFIEJkXkRud1Yz6gQUlojNMucsv9MWwHkDBfqtWuksbDRLSfvAhe56gOuWtan5+D8aHu414/SqyiVL/wgVQlXKKsWVDnb0BvTHufWgEz8H4Gqf+sIqHON9d39TXrvk/UdiuRhgoNopEam3G+2y4iTYWm+tLaJQ== Received: from SN1PR12CA0046.namprd12.prod.outlook.com (2603:10b6:802:20::17) by DM4PR12MB5722.namprd12.prod.outlook.com (2603:10b6:8:5d::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.43; Thu, 9 May 2024 11:31:40 +0000 Received: from SA2PEPF00003AE9.namprd02.prod.outlook.com (2603:10b6:802:20:cafe::30) by SN1PR12CA0046.outlook.office365.com (2603:10b6:802:20::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.48 via Frontend Transport; Thu, 9 May 2024 11:31:40 +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 SA2PEPF00003AE9.mail.protection.outlook.com (10.167.248.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.18 via Frontend Transport; Thu, 9 May 2024 11:31:40 +0000 Received: from rnnvmail205.nvidia.com (10.129.68.10) 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; Thu, 9 May 2024 04:31:22 -0700 Received: from rnnvmail205.nvidia.com (10.129.68.10) by rnnvmail205.nvidia.com (10.129.68.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Thu, 9 May 2024 04:31:21 -0700 Received: from vdi.nvidia.com (10.127.8.10) by mail.nvidia.com (10.129.68.10) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Thu, 9 May 2024 04:31:18 -0700 From: Tariq Toukan To: "David S. Miller" , Jakub Kicinski , Paolo Abeni , Eric Dumazet CC: , Saeed Mahameed , Gal Pressman , Leon Romanovsky , Akiva Goldberger , Moshe Shemesh , Tariq Toukan Subject: [PATCH net 5/5] net/mlx5: Discard command completions in internal error Date: Thu, 9 May 2024 14:29:51 +0300 Message-ID: <20240509112951.590184-6-tariqt@nvidia.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240509112951.590184-1-tariqt@nvidia.com> References: <20240509112951.590184-1-tariqt@nvidia.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA2PEPF00003AE9:EE_|DM4PR12MB5722:EE_ X-MS-Office365-Filtering-Correlation-Id: e4cea40d-4427-4c44-735b-08dc701b9859 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|82310400017|1800799015|36860700004|376005; X-Microsoft-Antispam-Message-Info: FTyr6h63GhqyVQl7w7rekGrz7QCtf8a3yYjLpoGbUsZHtUX9L8De2VmcLRJFILcnOw/awJ0BOCUy4K5N8+PV1lq4uIQmxz1cvvRS3d17SRcDa/6ze55WFeStaXilu+vVUxC94AOXeAgf3pTJBTNqDMrj+AcMYcEJcTwXQEQqVmLDDugj9dY0saask5tnSlWgDO3+esmVT+/Z5obLBRv10CbptVqcMm9XU/RsylisV2XzcHaCM6tmtHLWWs0pDIGRql0vgYsdKCGiwQjuIvF4FHFk9jlFuh2NMdiLWezcGYzXVqEstA2Sob2ymfTbBkMPOVrqRynk0LRMtAu1TeYfc/xu3rkO8mt8PwUV6ShrVZkzZ3oSbzfS+qgOnwFZ7RrnGVqqDdO7thOZxgEq6hrbMhXKhG1lkF/BWiPt8J0RnN6yyiioZ3HESxR40Y6p3DCKyiJf7Ya8kP7394JHxbCFE6OXwO7o1BgchzQQ2VI5y6xcKG6Ia6WHLPHpDdiJFyDCU7vHnpU1aMcNKS/H2Zqdf9hlQ+USa5kqvHm1m32Yx0nSi/eFp4V7fQ299kf1OW8TI/9px+IV5TQaEKNyMo/lmQGUCfwapd2NSzMq9RBPxzj13EEGwVLQnr4GKcuywfmRbYDV0rIkU35Qh89w4hQK0XsSaUTAGdKJrLyBVluUPMiNw2uyrYrClgB6nZRvpz2p6IqrTc80LGjmT1AgHQf2dyrpc7Tz6FWB38eLZ3/c3Zwz8EqucCkeBJZG3/zITUyWKoBDxxOBwHYg1ieypHqhHYlHjKXHX76GDEMug2IgyY8wi2+oEq9XVmIQeXC0MMlTbb4Eh5z3xRYG75bIIB5vBCatO4mdWXRVBFhQTcNNrG7k1QYbYlUFSDW6v0EYqCGYBbji6Ew8QP/cXp/2L7Zr2aFtk0qB+72e0aId1iWZm26iv6ta7DC3PsLU4wvx0zaxp8qbtSfZe7eupT80F8gz8z9VNI1j+MDuZ18aWThTd5elWZq8qJqyWONFDh2meZ9pgsb55WfyDP0Az4sA4IHHAiIMARGTXS6yYZymqho/27KlE4Vv8fwVRECv3rgYncsk9KsH68m0TJlChU+zqIkQVitD21tJm/dAjzCRMsZsjkDugHkN4xQP/8KUm93nSB9U1ZL8lt1JE6AJVjpQVTQwt6quFv3GU64yLFlrstgcl1bxYq5m3JV2nDLU9RjNIOH13S3ovTKQvLwiVYkm8DJkHQCSWGVddEJpbTkbsKPAIqyp+x+yvyOZbpIp+ssPNRCrl/P6XjL66TNOoPVorajwzw5QKNoWtw3O0D281HFyVbpDXpY46hcyh9tp4JDO+jB01h8gwInX3Cvp+7vH77CKkA+EY0++dep/AR4UcgUszvfktgWFLWo1MY03rqUqGFBE X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230031)(82310400017)(1800799015)(36860700004)(376005);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 May 2024 11:31:40.0788 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e4cea40d-4427-4c44-735b-08dc701b9859 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: SA2PEPF00003AE9.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB5722 X-Patchwork-Delegate: kuba@kernel.org From: Akiva Goldberger Fix use after free when FW completion arrives while device is in internal error state. Avoid calling completion handler in this case, since the device will flush the command interface and trigger all completions manually. Kernel log: ------------[ cut here ]------------ refcount_t: underflow; use-after-free. ... RIP: 0010:refcount_warn_saturate+0xd8/0xe0 ... Call Trace: ? __warn+0x79/0x120 ? refcount_warn_saturate+0xd8/0xe0 ? report_bug+0x17c/0x190 ? handle_bug+0x3c/0x60 ? exc_invalid_op+0x14/0x70 ? asm_exc_invalid_op+0x16/0x20 ? refcount_warn_saturate+0xd8/0xe0 cmd_ent_put+0x13b/0x160 [mlx5_core] mlx5_cmd_comp_handler+0x5f9/0x670 [mlx5_core] cmd_comp_notifier+0x1f/0x30 [mlx5_core] notifier_call_chain+0x35/0xb0 atomic_notifier_call_chain+0x16/0x20 mlx5_eq_async_int+0xf6/0x290 [mlx5_core] notifier_call_chain+0x35/0xb0 atomic_notifier_call_chain+0x16/0x20 irq_int_handler+0x19/0x30 [mlx5_core] __handle_irq_event_percpu+0x4b/0x160 handle_irq_event+0x2e/0x80 handle_edge_irq+0x98/0x230 __common_interrupt+0x3b/0xa0 common_interrupt+0x7b/0xa0 asm_common_interrupt+0x22/0x40 Fixes: 51d138c2610a ("net/mlx5: Fix health error state handling") Signed-off-by: Akiva Goldberger Reviewed-by: Moshe Shemesh Signed-off-by: Tariq Toukan --- drivers/net/ethernet/mellanox/mlx5/core/cmd.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/cmd.c b/drivers/net/ethernet/mellanox/mlx5/core/cmd.c index 511e7fee39ac..20768ef2e9d2 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/cmd.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/cmd.c @@ -1634,6 +1634,9 @@ static int cmd_comp_notifier(struct notifier_block *nb, dev = container_of(cmd, struct mlx5_core_dev, cmd); eqe = data; + if (dev->state == MLX5_DEVICE_STATE_INTERNAL_ERROR) + return NOTIFY_DONE; + mlx5_cmd_comp_handler(dev, be32_to_cpu(eqe->data.cmd.vector), false); return NOTIFY_OK;