From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=40.93.201.68 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796198503; b=ZZ6X9YGR9i+BlW7/ALPhS9GnLcCW+G0gfGgLj4SABDfGpTWKZM4TycRfyE7/iK/jB5P/ MLUkrWKQVw4XV3zRKzgSlSnoEGq2Q9XHlhItk7wD/VjBpgPXyrUK8bmdu3mTF683I9Wh9 0NdLSd0ofzDfwFanbPPzGAr5oGOXpSA7xW50p6/j+6m0GjMcdqerpqLYY5Nwh8/BCs5yr rvsiGL4RWeGY98YNcF5cKNLuoxeEfYXl9oujs1u0KsOy5LygKzTPEGCBZpvC0WJQ7QyaI aeslfpJezP3MmhEd9AJ5n2IP0FgOOZTbtcWHhpuuTMSYuHWpuVb64KPloX1WBxIzqbw== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796198503; h=DMARC-Filter:DKIM-Signature:Received:Received: X-MS-Exchange-Authentication-Results:Received-SPF:Received:Received: Received:Message-ID:Date:MIME-Version:User-Agent:Subject:To:CC: References:Content-Language:From:In-Reply-To:Content-Type: Content-Transfer-Encoding:X-Originating-IP:X-ClientProxiedBy: X-EOPAttributedMessage:X-MS-PublicTrafficType: X-MS-TrafficTypeDiagnostic:X-MS-Office365-Filtering-Correlation-Id: X-MS-Exchange-SenderADCheck:X-MS-Exchange-AntiSpam-Relay: X-Microsoft-Antispam:X-Microsoft-Antispam-Message-Info: X-Forefront-Antispam-Report: X-MS-Exchange-AntiSpam-MessageData-ChunkCount: X-MS-Exchange-AntiSpam-MessageData-0:X-OriginatorOrg: X-MS-Exchange-CrossTenant-OriginalArrivalTime: X-MS-Exchange-CrossTenant-Network-Message-Id: X-MS-Exchange-CrossTenant-Id: X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: X-MS-Exchange-CrossTenant-AuthSource:X-MS-Exchange-CrossTenant-AuthAs: X-MS-Exchange-CrossTenant-FromEntityHeader: X-MS-Exchange-Transport-CrossTenantHeadersStamped; bh=bKc6Ap9ddnYnnBQQDFGjmGyI+axYB45QDTJ1sb97qto=; b=GCxPkataOocw/S4HB7PzknJR+uRiXcvsQPs4aHE9EPZO3RzMogZCN1pAqDtdEfY/wKBO xONVC9tHiaIdIJd+lRYiqPN7aFgePq5O9WUB5vLQmb9RlWRSpv3wezkcNril1NIpLuPcm QE9zsaFOiC50WODphAcUYwwUInzsZYK4ZZwhhBeTMk4Z7v9c/3Xaf7qjSpKQfpDSLOPk4 UsCFHmdtLp+e4h23lvUG0OukLXy929cz9J8aCMiQgp478hv9UrpqJnHQK51sDX37UwBYn jLOZhbyMxLABSQSB29w/2V/29U6NpCEcRUUHHzKCdfwVUkDTefLCzh1RMbTzmOBWz+g== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=dMPKVmtP; arc=pass header.oldest-pass=0 smtp.remote-ip=40.93.201.68 Received: from CY3PR05CU001.outbound.protection.outlook.com (mail-westcentralusazon11013068.outbound.protection.outlook.com [40.93.201.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (secp384r1) server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D5007606A31A; Wed, 2 Dec 2026 08:01:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org D5007606A31A 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, unprotected) header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=dMPKVmtP ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=w8/BNAo/APNa9V1h7hcKvE5D8Z7/XWUu747UGprF7Guhb8GIoytuBVJqq0bdus+c71WB2gn1hsyaL/hHe2Q9poEMZM3XHy4tFlA+20nMNyntt9d68wGQXhY+Depukj8kXAce1rsgXVL/KvatRcxdfeZtYOkmwNHcQP4SurgNp35OLSEDIRUvCt7aq+T344H/FwWK3Jt0sqBwqiIk8oO+WID2cFyOzLAk3d9LS0W83dksTNFvrxtQK4x4Cd02JEXOcranaGzT3FUGvjINOKtgzjEno+eteZtEHBxDDPRCDSAOoF2OEM5c4BrxTm7e6UrKdF7fljtGGxYbTOG1N1Mg0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=bKc6Ap9ddnYnnBQQDFGjmGyI+axYB45QDTJ1sb97qto=; b=xfz+SAYJkjLx/DGN3WtdzdKTJotanz6Oqr7m3g2KkLXG4TpOa6NPnfLl/p1A0OKxmPDMHI1T2RVSW9qo180gHdGRc2QBJ2bmXDOg/Okar3auC0VVVZ1KihSRb0PB8TNqZThPslqWpMna+X7jJ4RcFJL13Ff5YVIAH2giJMTQ8Zy8BXfoYO+oVCYlMFxWH9KAfIhmCZNSx2INr/X+B/D71F+s8yoYp91av8mIj1gmzZimvuarhSFjyuKnAwJpT/22t1NMl5t5BCBFxWjoGf2KpEuLnrSRwQJmqvpT9SDHoGRoGAwvq7rsZV0AADieMqQ8lYHK0nmI5bhRi40kMx5Wbw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=kernel.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=bKc6Ap9ddnYnnBQQDFGjmGyI+axYB45QDTJ1sb97qto=; b=dMPKVmtPhw2d9txT7LtCoIvldwMOzh7eH7uJEe2N2hAEdShxaqLZJYOMARi1FXGyvZHg72NSRHt7asqFwmhcZQPxQDCYHhFRiJ3DlqyafGnhyC3Ok7S12kIEERv+/QHR6w0sWGY56ilJL+tRSz4IkWVgcH5Yd33hUQpXaoZR6y18ULkSZ/UkTSuPO8cjHrcQnjplQphMU0tUCgH1l21DRJsM1xX6JLv8XN6O7qyqofx7Ik63Dd6yf2L4MSYcZto1/DzCXM/wL//MHWLjVDtrHmFhnc96xC/MSenp8gcuQdWbEhPrAYNtOKhbnksEZH6m/Q0N0RmwQCgkes12vGgyDA== Received: from MW4PR04CA0374.namprd04.prod.outlook.com (2603:10b6:303:81::19) by PH7PR12MB9201.namprd12.prod.outlook.com (2603:10b6:510:2e8::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.688.10; Wed, 2 Dec 2026 08:01:34 +0000 Received: from CO1PEPF0001885B.namprd02.prod.outlook.com (2603:10b6:303:81:cafe::78) by MW4PR04CA0374.outlook.office365.com (2603:10b6:303:81::19) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.688.10 via Frontend Transport; Wed, 2 Dec 2026 08:01:34 +0000 X-MS-Exchange-Authentication-Results: mx.microsoft.com 1; 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 CO1PEPF0001885B.mail.protection.outlook.com (10.167.249.244) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.688.5 via Frontend Transport; Wed, 2 Dec 2026 08:01:34 +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.2562.57; Wed, 2 Dec 2026 00:01:12 -0800 Received: from [172.29.246.212] (10.126.230.37) 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.2562.57; Wed, 2 Dec 2026 00:01:07 -0800 Message-ID: Date: Wed, 2 Dec 2026 16:01:00 +0800 X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH net-next 2/2] net/mlx5: Add controller number for SF and ECVF phys_port_name To: , CC: , , , , , , , , , , , , , , , , References: <20261125212032.243064-3-tariqt@nvidia.com> <179573101472.3135.6016882066220406695@kernel.org> Content-Language: en-US From: Chris Mi In-Reply-To: <179573101472.3135.6016882066220406695@kernel.org> Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit X-ClientProxiedBy: rnnvmail202.nvidia.com (10.129.68.7) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1PEPF0001885B:EE_|PH7PR12MB9201:EE_ X-MS-Office365-Filtering-Correlation-Id: 94038e1d-9227-44d8-823d-08df504a7ba2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700016|1800799024|7416014|376014|23010399003|82310400026|22082099003|260925021311599003|56012099006|260925021911599003|260925022911599003|261028144727099003|261026135527099003|261021123027099003|261102123227099003|261026140227099003|261021121427099003|261026130827099003|261021133027099003|261026121527099003|261021135927099003|261022075727099003|261022113327099003|261022105027099003|261022115727099003|261021130227099003|10067099003|261009223027099003|4143699003|11063799006|5023799004|18002099003|6133799003; X-Microsoft-Antispam-Message-Info: 1iiFYpPeRu+m9cVZXXLQIK7/mQfwOHZ7NhQxozETcgwBlGkn1UmgLWQxlPhAdtobo36P1yWe9uYlgdRL53WC7bVxjXiblvhWG9GojJfVdNXAc1O6cNRc+cl0DJ3G4qrGIqd5xcSPNajGnSVgIx0GGiCGL+BAhH6Zo1F5SfARXdC0IRC3LmoYdCoeQVMXzNnyS8xiGbNIXKveNZ/U903O7ZCBRSeXb24Tnbfgv+nlINRtQacaBt7HUyGiB4cF1G8zeL90fN9A0aMjniuamnlTf1dNbF4+TkJAA0HlKlqfAVFqEt8d1jHvBqoIXuZF1xUNP0vA5JunYwpT62kcz262FnTsrQ8f1j3W2XKymapqrv6W1feic87cLQ6Ai2Bd3+Cn6l0Tn3gn1eqpgzWlVvHOUQgF9ANYHvipTPrGBdQ5VpL7bdoXoljmyWP2YsvfRD5Zk/61B56+bvRhALP3hvlzAc2IWjA9R6L9t7LNT27jy+oJRDQHHgWNCVttoHVxWRm5qVsBHNPxFzTmPLW1VMAmEN2KRqHi34ObWACdxK5rRZO2q6eGiyKEAIwJCjOTyAmEl40NdN3aNyGkROcqpOxITYUbp5U55Wc7u0UKhs+Itbz61P5/boS0LPeegWiD68I4rudh6yVMGAChbvFxXYRRMr33LhtUNPp1HRpzbzWMJxIWXIdYXOUwV9NUpijWVoT/HoO6oqAxYe1/0qZf3n2Wmw== 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)(36860700016)(1800799024)(7416014)(376014)(23010399003)(82310400026)(22082099003)(260925021311599003)(56012099006)(260925021911599003)(260925022911599003)(261028144727099003)(261026135527099003)(261021123027099003)(261102123227099003)(261026140227099003)(261021121427099003)(261026130827099003)(261021133027099003)(261026121527099003)(261021135927099003)(261022075727099003)(261022113327099003)(261022105027099003)(261022115727099003)(261021130227099003)(10067099003)(261009223027099003)(4143699003)(11063799006)(5023799004)(18002099003)(6133799003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: TLC/TGjBZyUfdhK5yxgPtdI6z0baWmvviPzlrn1WPW511yYbk7t3Ccq6e/5hvy0PNvhsikoxq4lTpCAnIvsPJahfhOLOx6QkslFdRUMRVnXGv+ZyTPWgyUVO8xIfj5AHaLuPUeFydvkCL7UWK84X0hjjLndhKj6VG1R2lic1QAm23U3fhyCae4B+wsPDV0GAKBuipziRWt7MTaKk9RNv9pasD9CvX80oaYRVPQGwqFoZczVNIzhooKjxFtcjYBvUYwN5sVLCrIxwNq5YbSEePs4x1xY1cmUAXBbsJZgZYlb+rJ19ZldK8xzo1/ouIQ/9gXALxYzBegjKmXDxDw7gBwGIUzavxZzIE+yDKUbmHQfa3MCk15Y12ajqrJ4SZc8D7b35wrrniQNaMYpm2mJGDZHlJpFki80Nx/6lAAnIqS2uIM0HHZASFoaq4uDQTXBN X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Dec 2026 08:01:34.0923 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 94038e1d-9227-44d8-823d-08df504a7ba2 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: CO1PEPF0001885B.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB9201 On 11/27/2026 6:10 AM, netdev-bot+sashiko@kernel.org wrote: > Thank you for your contribution! Sashiko AI review found 6 potential > issue(s) to consider. > > Critical: 0 · High: 1 · Medium: 5 · Low: 0 > > If you believe none of the issues are legitimate, please reply to each > issue of Medium severity or higher and explain why the AI is wrong. > If any of them are legitimate and you plan to respin, please let patchwork > know by including "pw-bot: cr" as a separate line at the end of your reply > (one such reply per series is enough). > > - [High] The controller prefix only reaches devlink ports created while > the shared FDB is active, so phys_port_names can still collide. > - [Medium] The SF-add validators disagree on what the 'self controller' > is. > - [Medium] Local SFs on the non-master link now carry a non-zero > sf->controller (phys_port_cnum, via mlx5_sf_get_self_controller() ->… > - [Medium] Nothing serialises esw_funcs->phys_port_cnum between its > writers and the devlink SF port_new readers. > - [Medium] mlx5_esw_sf_controller_to_pfnum_valid() now accepts any > satellite PF whose (host_number+1, pf_num) matches the request. > - [Medium] The patch gives the self PF controller_num = QUERY_PF > host_number + 1. > > -- > > net/mlx5: Add controller number for SF and ECVF phys_port_name > > This commit gives the non-master PCI link in a BlueField-4 Socket-Direct > shared FDB a non-zero controller number (QUERY_PF host_number + 1). SFs > and EC VFs on that link then get a cN prefix in phys_port_name. It tracks > the self PF controller and pfnum in the eswitch, sets and resets > phys_port_cnum on shared FDB create and destroy, and updates SF > validation and hwc table selection. > >> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/esw/devlink_port.c b/drivers/net/ethernet/mellanox/mlx5/core/esw/devlink_port.c >> index 8b46634203b37..fa07a571c1b99 100644 >> --- a/drivers/net/ethernet/mellanox/mlx5/core/esw/devlink_port.c >> +++ b/drivers/net/ethernet/mellanox/mlx5/core/esw/devlink_port.c >> @@ -83,7 +83,9 @@ static void mlx5_esw_offloads_pf_vf_devlink_port_attrs_set(struct mlx5_eswitch * >> >> memcpy(dl_port->attrs.switch_id.id, ppid.id, ppid.id_len); >> dl_port->attrs.switch_id.id_len = ppid.id_len; >> - devlink_port_attrs_pci_vf_set(dl_port, 0, pfnum, >> + controller_num = mlx5_esw_get_self_pf_ctrl_num(esw); >> + pfnum = mlx5_esw_get_self_pf_pfnum(esw); >> + devlink_port_attrs_pci_vf_set(dl_port, controller_num, pfnum, >> vport_num - base_vport, false); > > [Severity: High] > Are these attrs ever refreshed after phys_port_cnum changes? > > mlx5_esw_get_self_pf_ctrl_num() reads phys_port_cnum here only once, when > the EC VF vport is loaded. Only mlx5_self_controller_set() sets > phys_port_cnum, and it runs as the last step of > mlx5_lag_shared_fdb_create(). > > In the SD flow, mlx5_devlink_eswitch_mode_set() runs esw_offloads_start() > first: > > esw_offloads_start() > mlx5_eswitch_enable_pf_vf_vports() > mlx5_eswitch_load_ec_vf_vports() > mlx5_eswitch_load_pf_vf_vport() > mlx5_esw_offloads_init_pf_vf_rep() > mlx5_esw_offloads_pf_vf_devlink_port_attrs_set() > > Only after that does it run: > > mlx5_sd_eswitch_mode_set() > mlx5_sd_activate_shared_fdb() > mlx5_lag_shared_fdb_create() > mlx5_self_controller_set() > > The later rep reload paths (mlx5_eswitch_reload_reps_blocked() and the IB > rep reload) reuse the existing vport->dl_port, so the attrs keep > controller 0. > > Would EC VFs that exist at switchdev entry still be named pf0vf0 and > collide with the master's ports? The same question applies to SFs added > through mlx5_sf_get_self_controller() before the shared FDB exists, which > would still be named pf0sf0. > > In the other direction, mlx5_self_controller_reset() clears phys_port_cnum > on destroy. Ports that are already registered keep the cN prefix, while > new ones get none. Does phys_port_name then depend on the order of > operations? > You're right, there are corner cases here that this patch doesn't handle. We decided not to cover them in this series to keep it reviewable: it has already grown from one ~100-line commit to two commits of ~360 lines. >> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c >> index 8c2c55ba5c35e..09a29280c48e3 100644 >> --- a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c >> +++ b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c > > [ ... ] > >> +bool mlx5_esw_sf_controller_to_pfnum_valid(struct mlx5_core_dev *dev, >> + u32 controller, u32 pfnum) >> { >> struct mlx5_eswitch *esw = dev->priv.eswitch; >> struct mlx5_esw_functions *esw_funcs; >> + bool known_controller = false; >> int i; >> >> - if (!controller) >> - return PCI_FUNC(dev->pdev->devfn); >> + if (!MLX5_CAP_GEN(dev, query_host_net_function_v1)) >> + return pfnum == PCI_FUNC(dev->pdev->devfn); >> >> esw_funcs = &esw->esw_funcs; >> - for (i = 0; i < esw_funcs->num_spfs; i++) >> - if (controller == esw_funcs->spfs[i].host_number + 1) >> - return esw_funcs->spfs[i].pf_num; >> + if (!controller || controller == esw_funcs->controller_num) { >> + known_controller = true; >> + if (mlx5_esw_get_self_pf_pfnum(esw) == pfnum) >> + return true; >> + } > > [Severity: Medium] > Does this check agree with mlx5_esw_offloads_controller_valid()? > > This function accepts controller_num with the self pfnum on every device, > whatever the LAG or master state. mlx5_sf_controller_to_hwc() also maps > (controller_num, self pfnum) to hwc[MLX5_SF_HWC_LOCAL] on any device. > > mlx5_esw_offloads_controller_valid(), however, accepts the self controller > only when it equals a non-zero phys_port_cnum. > > mlx5_sf_new_check_attr() rejects an explicit controller 0 when > phys_port_cnum is set. It has no matching rejection of an explicit > controller_num when phys_port_cnum is 0, which is the case on the master, > on a standalone device, or after mlx5_lag_shared_fdb_destroy(). > > On such a device, "devlink port add ... pfnum controller > " passes mlx5_sf_new_check_attr() and this function. After > that, it either fails in mlx5_sf_alloc() with "Invalid controller number", > or it succeeds if an SPF shares that host_number. > > In the success case, would a local SF taken from the LOCAL hwc be labelled > cNpfXsfY on the master? > > The commit message says: > > But if user specifies other controller number, command fails. > > Does that still hold for this case? > > The "Local controller is always valid" comment in > mlx5_esw_offloads_controller_valid() also looks stale now, because an > explicit controller 0 is rejected earlier when phys_port_cnum is set. > > [ ... ] > Good catch. On the master, on a standalone device and after mlx5_lag_shared_fdb_destroy(), phys_port_cnum is 0 and the local controller is 0, so SFs are created there as before. An explicit controller with the self pfnum was not rejected in that state. In the next version mlx5_esw_sf_controller_to_pfnum_valid() matches the self PF against phys_port_cnum, like mlx5_esw_offloads_controller_valid() does, so that command is now rejected. mlx5_sf_controller_to_hwc() still uses controller_num on purpose: it has to resolve the hwc table of SFs created before the shared FDB was destroyed. The stale comment is removed too. Will fix it in v2. >> +static int mlx5_esw_self_pf_init(struct mlx5_eswitch *esw) >> +{ >> + struct mlx5_esw_functions *esw_funcs = &esw->esw_funcs; >> + struct mlx5_core_dev *dev = esw->dev; > > [ ... ] > >> + entry = MLX5_ADDR_OF(query_esw_functions_out, out, net_function_params); >> + for (i = 0; i < num_entries; i++) { >> + int pf_type; >> + >> + pf_type = MLX5_GET(network_function_params, entry, pci_pf_type); >> + if (pf_type != MLX5_PCI_PF_TYPE_QUERY_PF) { >> + entry += MLX5_UN_SZ_BYTES(net_function_params); >> + continue; >> + } >> + >> + esw_funcs->controller_num = >> + MLX5_GET(network_function_params, >> + entry, host_number) + 1; >> + esw_funcs->self_pf_pfnum = >> + MLX5_GET(network_function_params, >> + entry, pci_device_function); > > [Severity: Medium] > Is pci_device_function enough to tell the self PF apart from a satellite > PF? > > The commit message says the self PF and the satellite PFs share a > controller number, so self_pf_pfnum is the only tie-breaker. Neither this > function nor mlx5_esw_spfs_init() records pci_bus from > network_function_params, and pci_device_function is only unique per bus. > > Suppose a self PF and an SPF of the same host both report function 0 on > different buses, like 0002:01:00.0 and 0006:01:00.0 in the commit example. > mlx5_sf_controller_to_hwc() would then return hwc[MLX5_SF_HWC_LOCAL] > before it scans the SPF tables. mlx5_esw_sf_controller_to_pfnum_valid() > would also accept the request as a self PF SF before it checks the SPFs. > > Would an SF requested on the SPF then be allocated from the self PF's > function ID range via mlx5_sf_sw_to_hw_id()? If so, the SPF's hwc table > could not be reached for that controller/pfnum pair. > > [ ... ] > Self PF and SPFs on the same controller are told apart by pfnum: FW reports distinct pci_device_function values for them. The devlink UAPI only carries controller and pfnum, so pci_bus can't be used as a key anyway. I'll add "Device guarantees pfnum is unique per controller." to the commit message. >> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lag/shared_fdb.c b/drivers/net/ethernet/mellanox/mlx5/core/lag/shared_fdb.c >> index 404278a15ef73..fb96e9c3a5d84 100644 >> --- a/drivers/net/ethernet/mellanox/mlx5/core/lag/shared_fdb.c >> +++ b/drivers/net/ethernet/mellanox/mlx5/core/lag/shared_fdb.c >> @@ -190,6 +190,44 @@ void mlx5_lag_destroy_single_fdb(struct mlx5_lag *ldev) >> mlx5_lag_destroy_single_fdb_filter(ldev, MLX5_LAG_FILTER_ALL); >> } >> >> +static void mlx5_self_controller_set(struct mlx5_lag *ldev, u32 filter) >> +{ >> + struct mlx5_core_dev *dev, *master_dev = NULL; >> + struct mlx5_esw_functions *esw_funcs; >> + struct mlx5_eswitch *esw; >> + int i; >> + >> + mlx5_lag_for_each(i, 0, ldev, filter) { >> + dev = mlx5_lag_fn(ldev, i)->dev; >> + esw = dev->priv.eswitch; >> + esw_funcs = &esw->esw_funcs; >> + if (!mlx5_lag_is_master(dev)) >> + esw_funcs->phys_port_cnum = esw_funcs->controller_num; >> + else >> + master_dev = dev; >> + } >> + >> + if (!master_dev) >> + return; >> + >> + mlx5_lag_for_each(i, 0, ldev, filter) { > > [ ... ] > >> + if (host_ctrl_num == master_host_ctrl_num) >> + esw_funcs->phys_port_cnum = 0; >> + } >> +} > > [Severity: Medium] > What serializes phys_port_cnum against the devlink port_new path? > > mlx5_self_controller_set() and mlx5_self_controller_reset() run under > ldev->lock, called from bond work or mlx5_sd_activate_shared_fdb(). They > write this field for every eswitch in the group, including peers whose > devlink lock isn't held. > > mlx5_devlink_sf_port_new() holds only the PF devlink instance lock. It > reads phys_port_cnum three separate times: > > mlx5_sf_new_check_attr() > mlx5_sf_add() > mlx5_sf_get_self_controller() > mlx5_sf_alloc() > mlx5_esw_offloads_controller_valid() > > Suppose mlx5_sf_new_check_attr() sees 0 and accepts an explicit controller > 0, and the shared FDB is then created with phys_port_cnum set to 4. Can > the SF be created as pf0sf0 and collide with the master? > > In the reverse order, mlx5_sf_get_self_controller() returns 4 and a > concurrent destroy then resets the field. Can > mlx5_esw_offloads_controller_valid(4) then fail with a spurious "Invalid > controller number"? > > This function also writes in two passes. It first sets controller_num on > every non-master, then zeroes the ones that match the master. Can a > concurrent reader see the transient non-zero value? > > The EC VF read in mlx5_esw_get_self_pf_ctrl_num() is not synchronized > either. > > [ ... ] > Right, port_new can race with shared-FDB create/destroy. These are configuration-ordering corner cases, not a common path, and they don't come up when BF4 is set up as the cookbook describes. We'd rather not grow this series further. >> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/sf/devlink.c b/drivers/net/ethernet/mellanox/mlx5/core/sf/devlink.c >> index 2002b7f376ee6..c8aa1b0b9319d 100644 >> --- a/drivers/net/ethernet/mellanox/mlx5/core/sf/devlink.c >> +++ b/drivers/net/ethernet/mellanox/mlx5/core/sf/devlink.c >> @@ -237,6 +237,18 @@ int mlx5_devlink_sf_port_fn_state_set(struct devlink_port *dl_port, >> return mlx5_sf_state_set(dev, table, sf, state, extack); >> } >> >> +static u32 >> +mlx5_sf_get_self_controller(struct mlx5_eswitch *esw, >> + const struct devlink_port_new_attrs *new_attr) >> +{ >> + struct mlx5_esw_functions *esw_funcs = &esw->esw_funcs; >> + >> + if (!new_attr->controller_valid && esw_funcs->phys_port_cnum) >> + return esw_funcs->phys_port_cnum; >> + >> + return new_attr->controller; >> +} > > [Severity: Medium] > Local SFs on the non-master link now carry a non-zero sf->controller. > Existing code treats any non-zero controller as an external host SF. Does > that code handle these local SFs correctly? > > When the external host PF is disabled, esw_vfs_changed_event_handler() > calls mlx5_sf_table_esw_changed_event_handler(). That handler only skips > SFs whose sf->controller is 0: > > if (!sf->controller) > continue; > > if (sf->hw_state == MLX5_VHCA_STATE_IN_USE) > sf->hw_state = MLX5_VHCA_STATE_ACTIVE; > else if (sf->hw_state == MLX5_VHCA_STATE_TEARDOWN_REQUEST) > sf->hw_state = MLX5_VHCA_STATE_ALLOCATED; > > Take a deactivated local SF that gets rolled back from TEARDOWN_REQUEST to > ALLOCATED. A later port del goes through mlx5_sf_dealloc() -> > mlx5_sf_free() -> mlx5_sf_hw_table_sf_free() and skips > mlx5_sf_hw_table_sf_deferred_free(). > > Could the function ID then be reused while firmware still holds it, and > would opstate report the wrong value? > > Also, mlx5_sf_hw_table_sf_alloc() arms vhca events under "if > (controller)", and its comment says that is for external controllers. Is > it intended to arm them for these local SFs too? > > The same applies to SFs created on the master with an explicit > controller_num, as described above. > > [ ... ] > Good catch. "controller != 0" no longer means external now that self PF SFs can carry a controller number. Added mlx5_esw_sf_is_external() (non-zero controller that isn't the self PF's controller/pfnum) and used it in the esw changed handler and in the vhca event arming. Will fix it in v2. >> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/sf/hw_table.c b/drivers/net/ethernet/mellanox/mlx5/core/sf/hw_table.c >> index d8d0616834978..b7e8a8d7cc646 100644 >> --- a/drivers/net/ethernet/mellanox/mlx5/core/sf/hw_table.c >> +++ b/drivers/net/ethernet/mellanox/mlx5/core/sf/hw_table.c >> @@ -40,8 +40,18 @@ static struct mlx5_sf_hwc_table * >> mlx5_sf_controller_to_hwc(struct mlx5_core_dev *dev, u32 controller, u32 pfnum) >> { >> struct mlx5_sf_hw_table *table = dev->priv.sf_hw_table; >> + struct mlx5_eswitch *esw = dev->priv.eswitch; >> + struct mlx5_esw_functions *esw_funcs; >> int i; >> >> + /* If shared fdb is destroyed, phys_port_cnum is reset to 0. >> + * So use controller_num directly which is read from firmware. >> + */ >> + esw_funcs = &esw->esw_funcs; >> + if (controller == esw_funcs->controller_num && >> + pfnum == mlx5_esw_get_self_pf_pfnum(esw)) >> + return &table->hwc[MLX5_SF_HWC_LOCAL]; >> + >> for (i = MLX5_SF_HWC_FIRST_SPF; i < table->num_hwc; i++) { >> if (table->hwc[i].controller == controller) >> return &table->hwc[i]; > > [Severity: Medium] > mlx5_esw_sf_controller_to_pfnum_valid() now accepts any SPF whose > host_number + 1 and pf_num both match. This loop, however, still picks > the SPF hwc by controller alone. > > Suppose two SPFs on one eswitch share a host_number. Could a request for > the second SPF's pfnum pass validation and then be allocated from the > first SPF's hwc range? Both mlx5_sf_hw_table_id_alloc() and > mlx5_sf_sw_to_hw_id() take the first match, while the devlink port would > report the second pfnum. > > Before this patch, mlx5_esw_sf_controller_to_pfnum() returned only the > first matching SPF's pf_num, so validation and hwc selection agreed. > Good catch. The SPF hwc lookup matched on controller only, while validation matches controller and pfnum. The SPF hwc now records pfnum and the lookup matches both. Will fix it in v2. pw-bot: cr