From nobody Sat Feb 7 17:09:28 2026 Received: from CO1PR03CU002.outbound.protection.outlook.com (mail-westus2azon11010010.outbound.protection.outlook.com [52.101.46.10]) (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 C42E334EEF7; Wed, 28 Jan 2026 11:27:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.46.10 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769599669; cv=fail; b=Qzg/+Xmi11X9/QXYc7Hrms8MLMKUAbOg7+VWpntnimQgYvigV/oyeXWafj8zx5y4yYOfOkcIo74qWQtUOkOkg3BKW0tkZCeyYVWmvOK7Y/kJsVE4pRRxkFYcg+1MMQ/tvKLZt6c5X9Vbv8uZPL8LUkcliajQNzaB50TBV2Gl/P4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769599669; c=relaxed/simple; bh=Px4IPIY6SwUyEEZFZ/FdSudSxntNHlDUPcL2co0azRE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=tQN5Tzyh7efYOocLwjHv9Xo1FHp6w82oQRAgVWtm1uc5yngUfZgfTVfzHJe4l6Nkk2ExDUC/Kxzd/P72Bl/YeHO4q0SsiW6W8TCBVfDPYxadWwA89cM0f7CxO2QK4u8eyn2rrsRLMDwJgnKlA6dRSfik8BTXWiYXMIfUNl52PUk= 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=fD9onBhi; arc=fail smtp.client-ip=52.101.46.10 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="fD9onBhi" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=yyzOGg7f54OHzEYRCkeHOLWq6aofjgICIV4zwtSeB8eovIFgrYVUfy1oTeiAzEDJU0FhvIY2Np+2xI2i4nVqdqCvrGbs1ZIhicRapAsrksOJlpzNAqylEBO5cdkTIMsOScG6+7CsD3uZrUoghrp7HyjPaZI3qSZSC4l8cxvzFfeJYZoddBKgOBk0i+zdLOFGZ1a/wl4Axm4svVryfPBGpl6f0u8R/QyH80613VnGB9KwCXXVLZSSG16Di01huetVv71um4U5EPdzM1V3ir7IjGqjSl5JzmK9CGgJ0JcSIUj+BVJKctKMZzuy+4XZaV7jkFnpwc522OEou30NB87RDQ== 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=bYM8Tenv7+fBmCxmfjmrZBh5DZ7QWZYDmeM5IxQxc1A=; b=D26iLKoDmrGcAD5/T4zy/bPhhSm8CoBvoURVwVW6/+/C8bwrCavMddQq4lGdlpUEvmrdMyp7Ral1GVkZzNNyxvYHjvnDzMQZvxpn33F+5aKG2FbONR/dnpZmEpWtkVJTlGXpBHi4bMAwwMw9Lf+n2XJyAWiA1HR4QBwWlRReal+bu6Pkc7DyP9fIC63f1d+1Bf+l1DEpeF1c74v9mgrhm2eMD1nu7zy6YiLLg9gkR995Rq0o2ymm8uRbgkqLIWiuUkKfulPTfzLb8ZwAFUyCop5GpqLIVqdLomiORGregabVMTaqrM1KaZfG7onfkFVcVgE46SBlecjNhDmVGvrQCg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=google.com 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=bYM8Tenv7+fBmCxmfjmrZBh5DZ7QWZYDmeM5IxQxc1A=; b=fD9onBhiEmoGOqJvbbIZiNztu1uSkiQ9HEsE7ovR3OHm8SvZBC70+z3/FJkvAgZf2aYVPq+HRJjyB3p1PfHCZIT1B8KB7tM1vydH0lKOl5z/nejWOExdEf0q10HRZkHZDRLSwxb973t1EIp7gvKLCRwf/ZNjvmzNf9R9CtFRJpFtcSa3D7kttHCr/MIkhy21A3/bLXwQHTObXSb1Phbintc5duyQVjgyO50IvN3+j913gg3zog1mWNCVYlHc0G55m0TD2FjMXwFAvzsirlwkN6u47MawLzBR78b47+EVVmOHNa9HadraQ8C8px2Wkb6rK6Dztk/HaX+Oy9r9K8Kg0A== Received: from PH8P221CA0058.NAMP221.PROD.OUTLOOK.COM (2603:10b6:510:349::7) by LV2PR12MB5966.namprd12.prod.outlook.com (2603:10b6:408:171::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9564.7; Wed, 28 Jan 2026 11:27:43 +0000 Received: from SN1PEPF0002BA4C.namprd03.prod.outlook.com (2603:10b6:510:349:cafe::5) by PH8P221CA0058.outlook.office365.com (2603:10b6:510:349::7) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9564.8 via Frontend Transport; Wed, 28 Jan 2026 11:27:42 +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 SN1PEPF0002BA4C.mail.protection.outlook.com (10.167.242.69) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9564.3 via Frontend Transport; Wed, 28 Jan 2026 11:27:42 +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.2562.20; Wed, 28 Jan 2026 03:27:30 -0800 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.2562.20; Wed, 28 Jan 2026 03:27:29 -0800 Received: from vdi.nvidia.com (10.127.8.10) by mail.nvidia.com (10.129.68.10) with Microsoft SMTP Server id 15.2.2562.20 via Frontend Transport; Wed, 28 Jan 2026 03:27:23 -0800 From: Tariq Toukan To: Eric Dumazet , Jakub Kicinski , Paolo Abeni , Andrew Lunn , "David S. Miller" CC: Donald Hunter , Jiri Pirko , Jonathan Corbet , Saeed Mahameed , "Leon Romanovsky" , Tariq Toukan , Mark Bloch , , , , , Gal Pressman , Moshe Shemesh , Carolina Jubran , Cosmin Ratiu , Jiri Pirko , Randy Dunlap , Simon Horman , Krzysztof Kozlowski Subject: [PATCH net-next V7 01/14] documentation: networking: add shared devlink documentation Date: Wed, 28 Jan 2026 13:25:31 +0200 Message-ID: <20260128112544.1661250-2-tariqt@nvidia.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20260128112544.1661250-1-tariqt@nvidia.com> References: <20260128112544.1661250-1-tariqt@nvidia.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN1PEPF0002BA4C:EE_|LV2PR12MB5966:EE_ X-MS-Office365-Filtering-Correlation-Id: e90648d8-a89b-4b15-ffd4-08de5e604096 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|7416014|376014|1800799024|36860700013|30052699003; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?fIyd+suL6H9ZikbpmAaviSVyPhi6JUFOM34zCPNmv0yBTSP2JdcdVOBKm7pR?= =?us-ascii?Q?QnzDn9ehevOmiotk1eoI/Xlw+rhLwvwlPgW+0hz7/YSCMaXUluJgj5pXHWAq?= =?us-ascii?Q?23DsLWC5hqX7EzTzxDeYuZqKnts9RDN20Yqt5KwGR6YeN2ZVSSkbph6kTuOm?= =?us-ascii?Q?gwB5026RmZAzV//9UbRlINQ7GopGHlBCM5e0ZWBOUKNxTROoXSv0hZhtg52l?= =?us-ascii?Q?u4jnUXT6K+FPY3hlCyXzPuwe5pzMG9fe1qKz2NiOQOT5RekWdV5vK/xc7VzG?= =?us-ascii?Q?5GvH7DBw9T5wPvboP8giJ6nVccQb2Vex4WmF1iloGICPvTu2QhQFPMKERxMI?= =?us-ascii?Q?Ht0TWzD9qeKSGkxredbEF+HWlMmlnvk9CbXuTpabtJlDhhQrWJq8tNa7G3iY?= =?us-ascii?Q?Ey24yqJOYnjIy5PZIyAsYjsYKQGGFAS6F3Tz5CEV9+bFdlboqZ8fBLT6mEWs?= =?us-ascii?Q?+k4eBOhISIiY5/wqwz1Xc+cbrf1oKsW1Kmha59/w0voCVVwQRO96W7fxrjIn?= =?us-ascii?Q?xWWGjH6rC2JLZu3QiGz+nJvaPpqJozk9wvA2N23zVtVbkzBvXI8bJ8Xx+i3g?= =?us-ascii?Q?W4QnMZa9z98rJeGpXYuQZnayoR+lWJ0Oc8LYMowA2sRyZgkdoWI8Jen6mHOJ?= =?us-ascii?Q?rn2d6Fnf4DtEXbEBGLJ/6JhFjYNmLWFVi2mDAqE5MLcBL//dfLbXvuBAeoI+?= =?us-ascii?Q?5YrAzTbOp6qVREyrOP0u8vF7e9zS3O+jGwh1wb9WytSSca3vvaIG3xlmWqcb?= =?us-ascii?Q?GWN6IwKZuX5A7iXR6SVe3Ef6qPqCuQuDL/AD0frNEA7zHPoEKI/AO+04esam?= =?us-ascii?Q?7jDcYOFso6HH+AtVbALZmTEcExonH8c/7tcRlhDji46hrrvxj5ISEnQa5cfQ?= =?us-ascii?Q?Ebe8mOqkOMyGFuDAWFuvk1pJSHZpY3yTPLn+NBSuMmvkFeRurjY1GxhSzHHL?= =?us-ascii?Q?9Nhakxu29J5RWmQBsVgjeqJuunl2DVbwDD/o5S93aLxzMy6Db38ik3N6gJXU?= =?us-ascii?Q?QW95eNghA56lfrnk9axzQJFacFbZq5YNP+h4RN8FwdEDJooxepO//rsrXY2e?= =?us-ascii?Q?M7rmGooLfVo4oST/xGuU6Z8dOW6WEiRABJcexBVTfRfJ5PApbCrCwboNF30a?= =?us-ascii?Q?y3nnA6CMy+YZCrnr0u+Sy+96+XWM7/ULAEbvKifGNv5NDpPBjnB++y9/z3OY?= =?us-ascii?Q?/PzCcX5i6ZtPltMcM4RNzLyXtk+QF462BJADo+cAWFcJbfvj9N8rjWz2BluD?= =?us-ascii?Q?GxWIUPsmbZTBG9M+G12GgsbS5f02XY/Ro95L9EGqO8JAQvHma1msAaPYPgLk?= =?us-ascii?Q?ESfxMV/nyQhZ5KA/WKvM0181mb4pfSCrn2mluoAtM3Kcrwj8Qa+4WyfMYKBi?= =?us-ascii?Q?JvBPQplJI+9UmXlxTIa+kXh+TL4pXEzdTru/fV5n6JzNHmz/8axTiG4GrT9l?= =?us-ascii?Q?QEAhIOjqdwiQNP8/Ir0P3XuyT9DlhojSx/g1LM4UNShAvX0VR5X5C7Fu1YRk?= =?us-ascii?Q?r9BAa3nNdBUvCEjwwiT1MNiHcNmPK9vDBNE76FaN6XZaUuWNAimGTadAZLCx?= =?us-ascii?Q?M2LIKsryDRVm665HQf4GK6gR6KXXt+IRu9SX5pnIr756/T6v83uiMLa4Jihz?= =?us-ascii?Q?HzxhCiX+BA5Tw+Nn+TOs5gowFCHHI2D2klt33kUCZ8H+GvXXaTcvkfklPTxG?= =?us-ascii?Q?TDvLSA=3D=3D?= X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230040)(82310400026)(7416014)(376014)(1800799024)(36860700013)(30052699003);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Jan 2026 11:27:42.5306 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e90648d8-a89b-4b15-ffd4-08de5e604096 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: SN1PEPF0002BA4C.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV2PR12MB5966 Content-Type: text/plain; charset="utf-8" From: Jiri Pirko Document shared devlink instances for multiple PFs on the same chip. Signed-off-by: Jiri Pirko Reviewed-by: Cosmin Ratiu Signed-off-by: Tariq Toukan --- .../networking/devlink/devlink-shared.rst | 95 +++++++++++++++++++ Documentation/networking/devlink/index.rst | 1 + 2 files changed, 96 insertions(+) create mode 100644 Documentation/networking/devlink/devlink-shared.rst diff --git a/Documentation/networking/devlink/devlink-shared.rst b/Document= ation/networking/devlink/devlink-shared.rst new file mode 100644 index 000000000000..74655dc671bc --- /dev/null +++ b/Documentation/networking/devlink/devlink-shared.rst @@ -0,0 +1,95 @@ +.. SPDX-License-Identifier: GPL-2.0 + +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D +Devlink Shared Instances +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D + +Overview +=3D=3D=3D=3D=3D=3D=3D=3D + +Shared devlink instances allow multiple physical functions (PFs) on the sa= me +chip to share an additional devlink instance for chip-wide operations. This +is implemented within individual drivers alongside the individual PF devli= nk +instances, not replacing them. + +Multiple PFs may reside on the same physical chip, running a single firmwa= re. +Some of the resources and configurations may be shared among these PFs. The +shared devlink instance provides an object to pin configuration knobs on. + +The shared devlink instance is backed by a faux device and provides a comm= on +interface for operations that affect the entire chip rather than individua= l PFs. +A faux device is used as a backing device for the 'entire chip' since ther= e's no +additional real device instantiated by hardware besides the PF devices. + +Implementation +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +Architecture +------------ + +The implementation uses: + +* **Faux device**: Virtual device backing the shared devlink instance +* **Chip identification**: PFs are grouped by chip using a driver-specific= identifier +* **Shared instance management**: Global list of shared instances with ref= erence counting + +API Functions +------------- + +The following functions are provided for managing shared devlink instances: + +* ``devlink_shd_get()``: Get or create a shared devlink instance identifie= d by a string ID +* ``devlink_shd_put()``: Release a reference on a shared devlink instance +* ``devlink_shd_get_priv()``: Get private data from shared devlink instance + +Initialization Flow +------------------- + +1. **PF calls shared devlink init** during driver probe +2. **Chip identification** using driver-specific method to determine devic= e identity +3. **Get or create shared instance** using ``devlink_shd_get()``: + + * The function looks up existing instance by identifier + * If none exists, creates new instance: + - Creates faux device with chip identifier as name + - Allocates and registers devlink instance + - Adds to global shared instances list + - Increments reference count + +4. **Set nested devlink instance** for the PF devlink instance using + ``devl_nested_devlink_set()`` before registering the PF devlink instance + +Cleanup Flow +------------ + +1. **Cleanup** when PF is removed +2. **Call** ``devlink_shd_put()`` to release reference (decrements referen= ce count) +3. **Shared instance is automatically destroyed** when the last PF removes= (device list becomes empty) + +Chip Identification +------------------- + +PFs belonging to the same chip are identified using a driver-specific meth= od. +The driver is free to choose any identifier that is suitable for determini= ng +whether two PFs are part of the same device. Examples include: + +* **PCI VPD serial numbers**: Extract from PCI VPD +* **Device tree properties**: Read chip identifier from device tree +* **Other hardware-specific identifiers**: Any unique identifier that grou= ps PFs by chip + +Locking +------- + +A global mutex (``shd_mutex``) protects the shared instances list during +registration/deregistration. + +Similarly to other nested devlink instance relationships, devlink lock of +the shared instance should be always taken after the devlink lock of PF. + +Reference Counting +------------------ + +Each shared devlink instance maintains a reference count (``refcount_t ref= count``). +The reference count is incremented when ``devlink_shd_get()`` is called and +decremented when ``devlink_shd_put()`` is called. When the reference count +reaches zero, the shared instance is automatically destroyed. diff --git a/Documentation/networking/devlink/index.rst b/Documentation/net= working/devlink/index.rst index 35b12a2bfeba..f7ba7dcf477d 100644 --- a/Documentation/networking/devlink/index.rst +++ b/Documentation/networking/devlink/index.rst @@ -68,6 +68,7 @@ general. devlink-resource devlink-selftests devlink-trap + devlink-shared =20 Driver-specific documentation ----------------------------- --=20 2.44.0 From nobody Sat Feb 7 17:09:28 2026 Received: from SN4PR0501CU005.outbound.protection.outlook.com (mail-southcentralusazon11011004.outbound.protection.outlook.com [40.93.194.4]) (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 19DC634DCDF; Wed, 28 Jan 2026 11:27:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.93.194.4 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769599677; cv=fail; b=Lcq6TeKrHsYcnKJL9xUC4z2cVpLnYuJvCEnstWwXOeyv31c4i1bNU/fkA4nAFIaxZV9gbxz6p8fXkI4FMPesJ9BXr3wU96KZsgep9qEtENmV9wXAeFsF+u/7FuIt4pr+npEwjicVhNo5o4h9d247PKFXlksRNiXxXzUkwjocadI= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769599677; c=relaxed/simple; bh=nBtMJd+3hkvSoU6PrNskqfdNZsmPSEsCiJPZwwVf390=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=k36K5YWElfkUdd70e8iL/tY01B2Ep3h7TRtLjiDW7ls3DUUeSp6/oRTcRQK+gdXO8k7VLFVW/gXTd3Wi2+nG8TML5PQObzF7tjzZWoEg5LQRxZ5n5k667CKOBh112r+0zpUXULoyJaBRvVMkXmwGSed3GKRys/o7jc0NT7f7n7Q= 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=S7g2qSX8; arc=fail smtp.client-ip=40.93.194.4 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="S7g2qSX8" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Bw9ib91gJRevRCAX55iLUz7q788ybM+SCbG9y/eitJ94DcWTO/xQuTu+eD4K0gBqKa9oqiHoxV+hkE5Bsg5iTlHfsRkD9bjiNul2UpurBGbEGYBgjOQfNoNMTGsIjCtIzz8MDP0n+KCv28Xf3hOUWQZFnE6SCW+VXxsm9f7G4UjdOk7XErP1eddKFnaE+Q4IwjB5j/iGVaxmB8YJ5KIUUDfnM5CRI9UixLqza+a61fi8+vRURnE5+wo9YjVP/pbNEzvTAaNa2xveILYPEqOSquLWcMxgokcxQVMOIRa8VVk48X3WslAZwU/5uwXchYM+bWLoRtWJ5+UHuwCoXlyZOA== 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=fwt4JzvHHI1Y/vwTzWObSNYmSbVYxiK4dsVaYneuqtQ=; b=v8oDvIOim2PFlTVOFbH63MFvBgdW77ZHeZ66Lt++Z2pU894hUMJKr9jHgouE/otrxfWTWmsWWLbTAgULoL2iAwoj6jmbfqhcvcApFGpzDDKrnGuLWL5glmY0n5LCEHZglM0G6+wJsctnZiO/LqGbHEaqz0zsxftiMOuNzcYaW1WatbFx4aAlz00ceCZpRrgTGrLrHPml775o9iJ/Ogp/RJ4UOO1jIXLpa9OeNVN212/M8tKGW/+rJGdiwElMI6RBKSW28uFHUu/v/MiP2ZzrAxrnmUuAzw/Bpn6+ewFsQ9t2jXu5BtR88hviOeehTxGy7mFyUBENLxD5z10mz9YGCg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=google.com 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=fwt4JzvHHI1Y/vwTzWObSNYmSbVYxiK4dsVaYneuqtQ=; b=S7g2qSX8617Kc1Evdk0KpsORAXoyVf/YNhwzK7BgufCES/k6ZUNmRoW+KJ4Q77NdsV8Cei8MzAKoQkZJyViVkvGWZuKuNKzHBh3WjIa8bCub2YPEmljjmOcg3ZkmKQ66GrMdoFpbbhZBVixPuBDqVc3+gfR2VpdDJE3iefXKMSag3esYzqowrHa5lzLxBXiSTptCa4VdoyRfDpRnw6NYYbK5BHisZZM3thCCem6ypguX9WngF1qW+DDRZY7w0ZmyB6WWaM+ygB2YJkDrjUxeTK5sb1fj6j8p/i/OdiiGKmty5lMMUawRmmwjh79Qb+ucfPWtwFy6c9fInZa3RRz3yg== Received: from PH8PR07CA0020.namprd07.prod.outlook.com (2603:10b6:510:2cd::12) by BL3PR12MB6642.namprd12.prod.outlook.com (2603:10b6:208:38e::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9564.7; Wed, 28 Jan 2026 11:27:50 +0000 Received: from SN1PEPF0002BA4E.namprd03.prod.outlook.com (2603:10b6:510:2cd:cafe::8f) by PH8PR07CA0020.outlook.office365.com (2603:10b6:510:2cd::12) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9564.8 via Frontend Transport; Wed, 28 Jan 2026 11:27:49 +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 SN1PEPF0002BA4E.mail.protection.outlook.com (10.167.242.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9564.3 via Frontend Transport; Wed, 28 Jan 2026 11:27:50 +0000 Received: from rnnvmail204.nvidia.com (10.129.68.6) 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.2562.20; Wed, 28 Jan 2026 03:27:36 -0800 Received: from rnnvmail205.nvidia.com (10.129.68.10) by rnnvmail204.nvidia.com (10.129.68.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.20; Wed, 28 Jan 2026 03:27:35 -0800 Received: from vdi.nvidia.com (10.127.8.10) by mail.nvidia.com (10.129.68.10) with Microsoft SMTP Server id 15.2.2562.20 via Frontend Transport; Wed, 28 Jan 2026 03:27:30 -0800 From: Tariq Toukan To: Eric Dumazet , Jakub Kicinski , Paolo Abeni , Andrew Lunn , "David S. Miller" CC: Donald Hunter , Jiri Pirko , Jonathan Corbet , Saeed Mahameed , "Leon Romanovsky" , Tariq Toukan , Mark Bloch , , , , , Gal Pressman , Moshe Shemesh , Carolina Jubran , Cosmin Ratiu , Jiri Pirko , Randy Dunlap , Simon Horman , Krzysztof Kozlowski Subject: [PATCH net-next V7 02/14] devlink: introduce shared devlink instance for PFs on same chip Date: Wed, 28 Jan 2026 13:25:32 +0200 Message-ID: <20260128112544.1661250-3-tariqt@nvidia.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20260128112544.1661250-1-tariqt@nvidia.com> References: <20260128112544.1661250-1-tariqt@nvidia.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN1PEPF0002BA4E:EE_|BL3PR12MB6642:EE_ X-MS-Office365-Filtering-Correlation-Id: 5cea2ebb-1d7e-40c7-a0bb-08de5e60455d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|7416014|1800799024|376014|30052699003|36860700013; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?yoRYS+/Cq4Dtft5cebFr4va81nG/saR39mE6zS5LJHjDxc3uTUbj4VbAslta?= =?us-ascii?Q?7czMLeezHKG7ivZDzVozFQZTl+vUS/fpmH/TuHXrzbkkBG1wyLGpaot94wZr?= =?us-ascii?Q?gUaaUpAS0UUkM2c/P/bhu0WNljv8/dganJ1fMtf5gx+rlkpIneMOXFsHPgKj?= =?us-ascii?Q?FUzfA/sygb2qky2Uktpsk/x9vTanHce69rxSDDhAF39feA9y3ce1eIY+OQt9?= =?us-ascii?Q?ADx4wygEkv0tazEYKZ2HDIpbk60r05lC4BM9c7PEXuNITd2g6J3/D8LFxmRa?= =?us-ascii?Q?9zeRWs3ELnPXCDyUUhR82v7YqZYDtCWDOtFRpnYoxwahpZz98xct4uLRADUP?= =?us-ascii?Q?8oevFyVqd09WywexDFO80dM+oh4/19UerDTavlgstqG3qmCipK2lNLPnx1kz?= =?us-ascii?Q?5GH8FDzuV3mu3JjQiezQNOHCtm3ZhKfqwUy242og/iMFC0jw7MnW0IEhQl7g?= =?us-ascii?Q?3uQK/JEdFfYpb9Qo5qp2Xnl/kxQnux0Cpbqb8ntP5DjySewFWWl07lEpMMf+?= =?us-ascii?Q?Ew6AONFTE8U+TeKAu1RAy6Yfggc5n9HViGZeJiTGpuFKpdqI7tuYB2EAVq7h?= =?us-ascii?Q?hWnZzYFcJjIHUbxXUwZX0LmSPbZf8PjN50lugNesLNqZ6q8vfqEojHwTy+Eg?= =?us-ascii?Q?CdGgt9MsC/lDOTRHzYvNWkkUmTDIDoHPTTi4yIsZm21yVapj2Vo+diNRRSUR?= =?us-ascii?Q?PHxQ2i6F5IrWiF8GEukqMc2xkJ5zIaLGFqqelUahPDyuX32lzv5vZqx3Gyb3?= =?us-ascii?Q?8jqsKPEpH1Ou8Urqbb6o9BMQDv0u9H0Yw/35iqNbKbIrADQImvHDLLjGqsm2?= =?us-ascii?Q?GHGM2GO1aisXQU9nEkzHUZ0Picv54uHHuUNn6wYz9ka/koOFMqIheU+Hkify?= =?us-ascii?Q?GnYZ9xSQ2hQGXIk8zfukYT2BbORUm4vh8tCFZVSn44934wwmCzXfVaSKuKJR?= =?us-ascii?Q?PPxaKLjQ5tF7Wq366DY8fRQErAVon0NlA0YCtHvCDNafl1yR8CgcjsgeJ0b2?= =?us-ascii?Q?u6fAeuzJ9TeR4OL3iEmDAO3/47gWQG/oxMoGmG8E43JNEictGOqaj19OcxzL?= =?us-ascii?Q?ii/HfSV1U/2IqlBYXz1SF/IMUvKfHDahxAmrK6tDsIXWvTBWbECySF2HAq/d?= =?us-ascii?Q?MNuAKwYdo4isnIXwW38HgK+sMJt5Fe24a1qvYGFM+L3BB2wf16UYQJe1aG7T?= =?us-ascii?Q?FyrYXHyu7EDpQft2+87c78yBsI6Vq3og6Dux9xZC28eEKrJVcWUNVMf7lFmX?= =?us-ascii?Q?Ubpj0Y/pSTpXoJeSZq/0EHei+leR9BElELVW3ub/jdm/TigNeZFusqzWMzSW?= =?us-ascii?Q?b0pdSkymm5WptDk8EdYS6GmHu0pW2OEY3O5XmURjYHGo+xeUHN2NmzY2DGOH?= =?us-ascii?Q?GipkC3VB99qaB5UlVD8qUrAWlGJ4/a7oslpY7j7unFR7J9Ttyd10S/zBIImF?= =?us-ascii?Q?sqsPTBvv46wRcpv/+rDT0T2BSW/z4gZ1OFouHu0dAcqGjYQudNIB87rU4OiA?= =?us-ascii?Q?6FFjmTwLqzi8UZaXM8BvMgCeWHOFnre5b85c1Qi6ILMIIIJdmNpbRsr5dE6g?= =?us-ascii?Q?3R4W6lJ1y/S3eSXIiB2Jq+YO3i1uQXg91pgAcFqvA1KEkyA83iKbWIP8xrnA?= =?us-ascii?Q?VcwEJxauzf/FbW48k+dL6mjFJvXzvGvybH8DNQ7uNGaP2ufz58xdaSZSx1pH?= =?us-ascii?Q?qaJhIw=3D=3D?= X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230040)(82310400026)(7416014)(1800799024)(376014)(30052699003)(36860700013);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Jan 2026 11:27:50.5564 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5cea2ebb-1d7e-40c7-a0bb-08de5e60455d 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: SN1PEPF0002BA4E.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL3PR12MB6642 Content-Type: text/plain; charset="utf-8" From: Jiri Pirko Multiple PFs may reside on the same physical chip, running a single firmware. Some of the resources and configurations may be shared among these PFs. Currently, there is no good object to pin the configuration knobs on. Introduce a shared devlink instance, instantiated upon probe of the first PF and removed during remove of the last PF. The shared devlink instance is backed by a faux device, as there is no PCI device related to it. The implementation uses reference counting to manage the lifecycle: each PF that probes calls devlink_shd_get() to get or create the shared instance, and calls devlink_shd_put() when it removes. The shared instance is automatically destroyed when the last PF removes. Example: $ devlink dev pci/0000:08:00.0: nested_devlink: auxiliary/mlx5_core.eth.0 faux/mlx5_core_83013c12b77faa1a30000c82a1045c91: nested_devlink: pci/0000:08:00.0 pci/0000:08:00.1 auxiliary/mlx5_core.eth.0 pci/0000:08:00.1: nested_devlink: auxiliary/mlx5_core.eth.1 auxiliary/mlx5_core.eth.1 Signed-off-by: Jiri Pirko Reviewed-by: Cosmin Ratiu Signed-off-by: Tariq Toukan --- include/net/devlink.h | 6 ++ net/devlink/Makefile | 2 +- net/devlink/sh_dev.c | 163 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 170 insertions(+), 1 deletion(-) create mode 100644 net/devlink/sh_dev.c diff --git a/include/net/devlink.h b/include/net/devlink.h index cb839e0435a1..c453faec8ebf 100644 --- a/include/net/devlink.h +++ b/include/net/devlink.h @@ -1644,6 +1644,12 @@ void devlink_register(struct devlink *devlink); void devlink_unregister(struct devlink *devlink); void devlink_free(struct devlink *devlink); =20 +struct devlink *devlink_shd_get(const char *id, + const struct devlink_ops *ops, + size_t priv_size); +void devlink_shd_put(struct devlink *devlink); +void *devlink_shd_get_priv(struct devlink *devlink); + /** * struct devlink_port_ops - Port operations * @port_split: Callback used to split the port into multiple ones. diff --git a/net/devlink/Makefile b/net/devlink/Makefile index 000da622116a..8f2adb5e5836 100644 --- a/net/devlink/Makefile +++ b/net/devlink/Makefile @@ -1,4 +1,4 @@ # SPDX-License-Identifier: GPL-2.0 =20 obj-y :=3D core.o netlink.o netlink_gen.o dev.o port.o sb.o dpipe.o \ - resource.o param.o region.o health.o trap.o rate.o linecard.o + resource.o param.o region.o health.o trap.o rate.o linecard.o sh_dev.o diff --git a/net/devlink/sh_dev.c b/net/devlink/sh_dev.c new file mode 100644 index 000000000000..acc8d549aaae --- /dev/null +++ b/net/devlink/sh_dev.c @@ -0,0 +1,163 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserve= d. */ + +#include +#include + +#include "devl_internal.h" + +static LIST_HEAD(shd_list); +static DEFINE_MUTEX(shd_mutex); /* Protects shd_list and shd->list */ + +/* This structure represents a shared devlink instance, + * there is one created per identifier (e.g., serial number). + */ +struct devlink_shd { + struct list_head list; /* Node in shd list */ + const char *id; /* Identifier string (e.g., serial number) */ + struct faux_device *faux_dev; /* Related faux device */ + refcount_t refcount; /* Reference count */ + char priv[] __aligned(NETDEV_ALIGN); /* Driver private data */ +}; + +static struct devlink_shd *devlink_shd_lookup(const char *id) +{ + struct devlink_shd *shd; + + list_for_each_entry(shd, &shd_list, list) { + if (!strcmp(shd->id, id)) + return shd; + } + + return NULL; +} + +static struct devlink_shd *devlink_shd_create(const char *id, + const struct devlink_ops *ops, + size_t priv_size) +{ + struct faux_device *faux_dev; + struct devlink_shd *shd; + struct devlink *devlink; + + /* Create faux device - probe will be called synchronously */ + faux_dev =3D faux_device_create(id, NULL, NULL); + if (!faux_dev) + return NULL; + + devlink =3D devlink_alloc(ops, sizeof(struct devlink_shd) + priv_size, + &faux_dev->dev); + if (!devlink) + goto err_devlink_alloc; + shd =3D devlink_priv(devlink); + + shd->id =3D kstrdup(id, GFP_KERNEL); + if (!shd->id) + goto err_kstrdup_id; + shd->faux_dev =3D faux_dev; + refcount_set(&shd->refcount, 1); + + devl_lock(devlink); + devl_register(devlink); + devl_unlock(devlink); + + list_add_tail(&shd->list, &shd_list); + + return shd; + +err_kstrdup_id: + devlink_free(devlink); + +err_devlink_alloc: + faux_device_destroy(faux_dev); + return NULL; +} + +static void devlink_shd_destroy(struct devlink_shd *shd) +{ + struct devlink *devlink =3D priv_to_devlink(shd); + struct faux_device *faux_dev =3D shd->faux_dev; + + list_del(&shd->list); + devl_lock(devlink); + devl_unregister(devlink); + devl_unlock(devlink); + kfree(shd->id); + devlink_free(devlink); + faux_device_destroy(faux_dev); +} + +/** + * devlink_shd_get - Get or create a shared devlink instance + * @id: Identifier string (e.g., serial number) for the shared instance + * @ops: Devlink operations structure + * @priv_size: Size of private data structure + * + * Get an existing shared devlink instance identified by @id, or create + * a new one if it doesn't exist. The device is automatically added to + * the shared instance's device list. Return the devlink instance + * with a reference held. The caller must call devlink_shd_put() when done. + * + * Return: Pointer to the shared devlink instance on success, + * NULL on failure + */ +struct devlink *devlink_shd_get(const char *id, + const struct devlink_ops *ops, + size_t priv_size) +{ + struct devlink_shd *shd; + + if (WARN_ON(!id || !ops)) + return NULL; + + mutex_lock(&shd_mutex); + + shd =3D devlink_shd_lookup(id); + if (!shd) + shd =3D devlink_shd_create(id, ops, priv_size); + else + refcount_inc(&shd->refcount); + + mutex_unlock(&shd_mutex); + return shd ? priv_to_devlink(shd) : NULL; +} +EXPORT_SYMBOL_GPL(devlink_shd_get); + +/** + * devlink_shd_put - Release a reference on a shared devlink instance + * @devlink: Shared devlink instance + * + * Release a reference on a shared devlink instance obtained via + * devlink_shd_get(). + */ +void devlink_shd_put(struct devlink *devlink) +{ + struct devlink_shd *shd; + + if (WARN_ON(!devlink)) + return; + + mutex_lock(&shd_mutex); + shd =3D devlink_priv(devlink); + if (refcount_dec_and_test(&shd->refcount)) + devlink_shd_destroy(shd); + mutex_unlock(&shd_mutex); +} +EXPORT_SYMBOL_GPL(devlink_shd_put); + +/** + * devlink_shd_get_priv - Get private data from shared devlink instance + * @devlink: Devlink instance + * + * Returns a pointer to the driver's private data structure within + * the shared devlink instance. + * + * Return: Pointer to private data + */ +void *devlink_shd_get_priv(struct devlink *devlink) +{ + struct devlink_shd *shd =3D devlink_priv(devlink); + + return shd->priv; +} +EXPORT_SYMBOL_GPL(devlink_shd_get_priv); --=20 2.44.0 From nobody Sat Feb 7 17:09:28 2026 Received: from BYAPR05CU005.outbound.protection.outlook.com (mail-westusazon11010063.outbound.protection.outlook.com [52.101.85.63]) (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 B3E4B34EEE2; Wed, 28 Jan 2026 11:28:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.85.63 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769599682; cv=fail; b=djtpK5awQ+Ygnz5oHbJvq9qzuC4flPsckZ8ffP/gsVw+4Go/JWtyvow9BFivVhMdAhz/KWS757jplP7UYQtzYaUvTkdpT3JMl1nJlW0oPqwXvU8mtH1Tu8A2mXoZdxfzQtq+dla/NLmxIfgYp1zzkuRL5MTYHw+EibaKAm/DjTU= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769599682; c=relaxed/simple; bh=VWzdc/N3eHvOuNpEWDMZSRK9dEYUvBPoVQXmOAKh/9k=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=cSyEHPYYfbAP6dfF8kx4powDSK6QlCS3VNpH/r+8z9CRLQJqkzEv8Y1nHK4uJiJQIUqm7rXzcMvamyZeAXX/AN4ydUH701BCa0k19mczvnDy4JEWAcqTENgA3GzYwJT+O6IfYWAUR3mGgrEN++mnIiCY3FlcfHwZ4fYoI1J/V1E= 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=hEEmqvYJ; arc=fail smtp.client-ip=52.101.85.63 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="hEEmqvYJ" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=KH3RKCfXaeG3PIp4v5vAUMGpiReI6XdFYmYftci3qo9NLuj3jvimJyd/Lj5i9mPSsoPwYs9D5xdWy1Spr77sFBiCLuSwYXIm0FngonU9E03Nf7QeCPU6QMg69WKN/J8CI4a26xz7pKbhtk2Qo8lBHJJj/2u/qM7jvJ0isCebyc6HWSOvnDJBQfw+0PE+wEddXH54pPCUkg05zF4gUsh/uIQYrxSaL0MyHcRhuOOCNgw7wwcktVGJki0rjMzcKcCf4RoOmL3O0LTE/47QB7UaQJYUq4SiDbbm5rCYBXVm6DPUOk37tqxRGa1/ZdnMdnx9QdNzVQ8KeXhOJGkEbP8h0g== 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=Lcu8UkvoEodiGMvwyq/H6ywtfatxV6MKanff74mRObg=; b=heFGNdh6XFZFEcVcXRm0GyBpfArtw4omz7t7ONDsfxKZyw5ypw/3tSGeDHwvbWJWqpafHa0yts+JR3p7QYk+vi5acMdDh8ztFNN+mwa26FJklJcFN9/KEaG+EACjDZPgYEEOt5FCNilDeqhKxYRz1RyInmyObl3A8Uwv/PL0WW5666RKe9uvbnYyRdgDsh+qMozsyeHoBvyVIxMQLpexFZQ8xmvilYewB7kIxML7y510dwwfV2YuUFKKI30t6CxE/CqOsFkg8mgiPD4tZbKP+1Stvom9T5gSP5jxtnmCm1ib6xi+0Yvzf5IUmxfC5KKOM0iS98a6/XNr3ach69PHKA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=google.com 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=Lcu8UkvoEodiGMvwyq/H6ywtfatxV6MKanff74mRObg=; b=hEEmqvYJXK3w37Q2g8/XNP5czcPHz5S/7TKmPcZTpfzFeCm4mXuv7/gt8zg5vS8yawMbTJ+wLbMbcqcQCdjKpf3KUADyBQ7Yx2EfzKYDuTZttneADI1b8z15RGH81USyzQTdlSGDL+Zk7UMI7lxYPV/MdHtac9RlZ0w6sL+cuSC7BLCnnBRRX0Dx8nqqqme/HPa+K2TnS2yUUkDGNAHvSLRcLM4yeHIYONcLe5e75ARudeTccvcaA3QujmXIXQheGliqM3V1FaQgDS4Gt6zJ1CaHnNqvv9o8sY11mfpjCIHobEuqP2sxxP1g+wZ2yAQdDS48T/LFxO6cbKVKnjsn7Q== Received: from BN9PR03CA0226.namprd03.prod.outlook.com (2603:10b6:408:f8::21) by BN5PR12MB9511.namprd12.prod.outlook.com (2603:10b6:408:2a9::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9542.15; Wed, 28 Jan 2026 11:27:55 +0000 Received: from BN1PEPF00004681.namprd03.prod.outlook.com (2603:10b6:408:f8:cafe::b2) by BN9PR03CA0226.outlook.office365.com (2603:10b6:408:f8::21) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9564.7 via Frontend Transport; Wed, 28 Jan 2026 11:27:55 +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 BN1PEPF00004681.mail.protection.outlook.com (10.167.243.87) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9564.3 via Frontend Transport; Wed, 28 Jan 2026 11:27:54 +0000 Received: from rnnvmail204.nvidia.com (10.129.68.6) 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.20; Wed, 28 Jan 2026 03:27:42 -0800 Received: from rnnvmail205.nvidia.com (10.129.68.10) by rnnvmail204.nvidia.com (10.129.68.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.20; Wed, 28 Jan 2026 03:27:41 -0800 Received: from vdi.nvidia.com (10.127.8.10) by mail.nvidia.com (10.129.68.10) with Microsoft SMTP Server id 15.2.2562.20 via Frontend Transport; Wed, 28 Jan 2026 03:27:36 -0800 From: Tariq Toukan To: Eric Dumazet , Jakub Kicinski , Paolo Abeni , Andrew Lunn , "David S. Miller" CC: Donald Hunter , Jiri Pirko , Jonathan Corbet , Saeed Mahameed , "Leon Romanovsky" , Tariq Toukan , Mark Bloch , , , , , Gal Pressman , Moshe Shemesh , Carolina Jubran , Cosmin Ratiu , Jiri Pirko , Randy Dunlap , Simon Horman , Krzysztof Kozlowski Subject: [PATCH net-next V7 03/14] devlink: Reverse locking order for nested instances Date: Wed, 28 Jan 2026 13:25:33 +0200 Message-ID: <20260128112544.1661250-4-tariqt@nvidia.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20260128112544.1661250-1-tariqt@nvidia.com> References: <20260128112544.1661250-1-tariqt@nvidia.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN1PEPF00004681:EE_|BN5PR12MB9511:EE_ X-MS-Office365-Filtering-Correlation-Id: a3008f44-8b7a-4335-abfc-08de5e604802 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|1800799024|376014|7416014|36860700013; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?tOptxymmmCY5ESc/cXNvNprmrbB29xzgHXAb5nXyMfHc9dCOhQiBiP7xhXkb?= =?us-ascii?Q?R9r/kMM+D6wdp6yQXaS/2QYvSLcFoyExPTzuLOeYJMOzyP8Gxz7tDjeI0MZZ?= =?us-ascii?Q?58iaOSvn6jXCjxKdqv78TEWi3Q1j07kR7TSPsZc2b+Qj4d1uQgJNfPq1m4AF?= =?us-ascii?Q?8hIbR6GSAumdR95xN8J184sA029KwN5lII6/cQzriViQNKsrliF+lrNk+yQF?= =?us-ascii?Q?fi8kIID3Qwgwmmm5uWFMGHVpfFfHNt6nbNCG4PHtqX2YlRtqq5IiSUeLi2Iz?= =?us-ascii?Q?aACHROTjziEFSqQOK5k97gQiWrK+17mphchEF09+H5gzgqkhH2GZVKaGlq9f?= =?us-ascii?Q?Qr1MbAsy8Q8wi3C1tE+al3VWcRr9XpNF/vq2zk8D5wP9sjG1eShUS3KUUXWv?= =?us-ascii?Q?ey/2opCKXC3oxmSv7Nszohu7Iy1dckt7mepojzYfght+C0XzsANIMWyHl2fo?= =?us-ascii?Q?hi1EgIIcnPgZju3/3f8hO+gp/0kJOTXSHi8m9yuuho56nYBaE/fqsQahAMqj?= =?us-ascii?Q?gbwBwRfhycf9Vln9wVig+grmAlV4BUSbmM6JFyILZas+bwA805oNEh4b4DAM?= =?us-ascii?Q?THkOjXAPqD7uoEZ8AsuZHr24VkwYHAWVLyfOi1t1753edjBuHho4wKOgdxbA?= =?us-ascii?Q?Q/27ZmHrKE0l4hT+ZSQTchEHSZsF0IqAkaXEoR799V8hgnda6B4iyFJS9J6u?= =?us-ascii?Q?9/y7FOl/Vi07cnUoZSaqTTVQ51/ojxOnSt8V9RqkO0obU+avOPSed2ALTQiE?= =?us-ascii?Q?sCGn1lzO5jpPT9Eq4YKcJDMLSnhYUc0mmofAJs8iU0c9S2whqHbD+7BVdcTa?= =?us-ascii?Q?42Wb1y7yZIwOxhxn9GO1YV6G+FxF/1MIpCLbSm6TG4i/BKaDjR1AkyGq6fJ0?= =?us-ascii?Q?lPmNR3+VbHinFTr03nLQESsRphzMmpfS1SeTMsUrPsVx55EXocBkO48o4I28?= =?us-ascii?Q?fHI66FK+MmE50leoG3qD+DR16X6Zwpbx0JGiY3NDeBlGVlA54hnNo5yGSKOW?= =?us-ascii?Q?pCNb9WaRx6XO+Rm92mnWj3VVKvByOepclmtadfw9xuYfTlKh7Ovfl3nasbjd?= =?us-ascii?Q?xvqPMRsaTMLwhUpu7di3MGtxwylC6EaFeaHUmX9zOSQiOJENmM2GWvLq9eur?= =?us-ascii?Q?508JgzkB+wrnv9+vM4IiOaRopoV1SUPeGKuTByA6GpRlsbADN9JNP0m3CRkc?= =?us-ascii?Q?NYgS3eU2Uw+kQgRP7wKs9PXrgQjsrt7spEw81bfgtFTxEHn/d4GrDMIN/EbF?= =?us-ascii?Q?J2S/IXfgvvsCJdj+rkWW/s1Api2qAV0xMusoVlWof8pjUBxaV7vNpfu3KBcO?= =?us-ascii?Q?Y2zGbHnBlhYeEGO37t/LI9LIX0V1Tdf8IQqge6QVws3zdJxZmzL1l01A/6wV?= =?us-ascii?Q?gfeDakYizp+cfkBpT2JtJun+eoYLAThxfIkY+rNg9oUa4UmqTkvZQpsnge+t?= =?us-ascii?Q?xYjaR9at+wxQwgu/QErKIt71bzFXwysttzSy+wSohAsOffpNEgEPN/OqS47a?= =?us-ascii?Q?RyJNGNkBmMo00L9rROKhhpWmYo6APs6YHHUVgrzIXvyy1K+xQxyymkycOCkV?= =?us-ascii?Q?4EetM52MJ/36TURRexTR1OUzAV9pIxqqDR0ohTzMVDyF5uFZJlhWI1+AmkN+?= =?us-ascii?Q?1QYuaR2b0VcqMwVfVC21WlgOSy2bHFqIKn0QjMG++LwrQwu7MN/Uovf7zx0n?= =?us-ascii?Q?V2XHUA=3D=3D?= X-Forefront-Antispam-Report: CIP:216.228.117.161;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge2.nvidia.com;CAT:NONE;SFS:(13230040)(82310400026)(1800799024)(376014)(7416014)(36860700013);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Jan 2026 11:27:54.9404 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a3008f44-8b7a-4335-abfc-08de5e604802 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: BN1PEPF00004681.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN5PR12MB9511 Content-Type: text/plain; charset="utf-8" From: Cosmin Ratiu Commit [1] defined the locking expectations for nested devlink instances: the nested-in devlink instance lock needs to be acquired before the nested devlink instance lock. The code handling devlink rels was architected with that assumption in mind. There are no actual users of double locking yet but that is about to change in the upcoming patches in the series. Code operating on nested devlink instances will require also obtaining the nested-in instance lock, but such code may already be called from a variety of places with the nested devlink instance lock. Then, there's no way to acquire the nested-in lock other than making sure that all callers acquire it first. Reversing the nested lock order allows incrementally acquiring the nested-in instance lock when needed (perhaps even a chain of locks up to the root) without affecting any caller. The only affected use of nesting is devlink_nl_nested_fill(), which iterates over nested devlink instances with the RCU lock, without locking them, so there's no possibility of deadlock. So this commit just updates a comment regarding the nested locks. [1] commit c137743bce02b ("devlink: introduce object and nested devlink relationship infra") Signed-off-by: Cosmin Ratiu Reviewed-by: Jiri Pirko Signed-off-by: Tariq Toukan --- net/devlink/core.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/net/devlink/core.c b/net/devlink/core.c index 58093f49c090..6ae62c7f2a80 100644 --- a/net/devlink/core.c +++ b/net/devlink/core.c @@ -178,9 +178,7 @@ int devlink_rel_nested_in_add(u32 *rel_index, u32 devli= nk_index, * a notification of a change of this object should be sent * over netlink. The parent devlink instance lock needs to be * taken during the notification preparation. - * However, since the devlink lock of nested instance is held here, - * we would end with wrong devlink instance lock ordering and - * deadlock. Therefore the work is utilized to avoid that. + * Since the parent may or may not be locked, 'work' is utilized. */ void devlink_rel_nested_in_notify(struct devlink *devlink) { --=20 2.44.0 From nobody Sat Feb 7 17:09:28 2026 Received: from MW6PR02CU001.outbound.protection.outlook.com (mail-westus2azon11012070.outbound.protection.outlook.com [52.101.48.70]) (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 27CA634EEE2; Wed, 28 Jan 2026 11:28:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.48.70 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769599691; cv=fail; b=LAJTox4CFCIP5ANtHiCP7q7mv75eO0oGxAOdgDxc7wo1dWFBSsx10b+mHMKYoN4E4+PS6KGZdpMcIhKIExjRgzOip0PiSnaTP7zrxoU7RFpmMo3OkHRjzBAPxWwVwPdH/ZnzAs5XROs+qNjFUd31BRgopTewTcufcmTaXPagDow= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769599691; c=relaxed/simple; bh=/no988dXRByA4dAv6xSmtV1gqdNqkJud8OF8Lw/T7fY=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=E6DZl5q7osqNNSM4i5NoWHtIy4zfVNZNNsKoZUMjAqn0NFFr8jl+ze1GAbpXM0hXCgrWNTLaEaa4q5OWbqectDNIYUss/5+inkbD5c0X4ailALZ6oYnV5X44utdO3wTWdQeOsM3Hy6OuWBlzrvSVWgHHMGTh5MMrUDQcd1lYqfY= 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=oSFsMEUd; arc=fail smtp.client-ip=52.101.48.70 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="oSFsMEUd" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=QhEj2NsEtV39odxRukpbJ4mFlHICHaKoyq0Qu8fJzAJ+/kd1Py4Rz7fhllfhodSWHNklbtvgvUaTIPzXiO/enLzlGYmZsDjCIXUtZb0NdzBaYiF2UtPSEkL3slwQAsoLYl84fAd5GFsi86rKDefqSMpLRsJUYLohiJKAYbDIKJljpQBAmKH0+AQM+MfLGV947Vc1fD+pjeoxPROi/5PPBl6qjqhb1NsA43x4DjW5fD9fRvmhdu6pHDNWX4gtEgv2JFI4C+JP60hWPo7rFWEPmV0ayR5B2DMGbV7siKzUgo1Dte33s0QWzx2yKQQi48GwhFahsGcGzUW7FoBYHn/Rbw== 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=yDRVdmRjGd6OOqu3CIeP6RyxaEBJy6PkXdTwAY/9YLw=; b=BnZY/+SNsDmCDKyKqP/3Vboq2P2niHjL8RQnjeDtF7UU/yUUPbvctwlssKeBIO1pdFgZa25oaKKxz6hI1M+itFCmb4ZXNIUAhQYLzEGVaXMcChWUe4NlBqeYx4jWjqHQwxvnbgglGKhdLlBEMWfDG20z99lxfKRkggKJzv+sT75pLTWCGE2KQxAkxN9Qej/qgcDyR8Kth9INmvWfINOeasqVmHip74KSa16v+qyOyhB4pftlinWSXXpSWKKOIgIZ/ezeAM8JA1kO/y8mfcyurunt0BcH9auLB2dLnoh5ZviMuzqdF+TcbUbHRddYhoDbwiN9omrHXCPtyEr4a5DwZg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=google.com 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=yDRVdmRjGd6OOqu3CIeP6RyxaEBJy6PkXdTwAY/9YLw=; b=oSFsMEUd7aJH2YaGXZ+OlY+EqAHzGCybzlgl7Bx1wvhVFd3b90DsEXoxZqebwsrVJdK0OIo1tnMFSPtSdGhqPm0mmR5zOmJt9q6EWlR8zkDVhkdDvSDfFyHJ7Aylb4JlJ75UCE3MJqzNWsQSnEiRrOlz0ix1r76rKWbNoN9XTeIsOTgXIsj3DdZkbWdk7jw7S9bqYpqQ+VaNguhNUATpXmMSMR3dL+CMfMhGnGAHG3tS4SdQGiQZd6pN9hQxOEkDoto5Ltfnw6koLmzQrQOqb9NpX+ba88N7O3caePW5kU61ULb9bccKvdPgw2jiwbJGUlpbg0vTVMrssxDSWzJ/lQ== Received: from BN1PR10CA0007.namprd10.prod.outlook.com (2603:10b6:408:e0::12) by PH0PR12MB7982.namprd12.prod.outlook.com (2603:10b6:510:28d::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9564.7; Wed, 28 Jan 2026 11:28:01 +0000 Received: from BN1PEPF00004682.namprd03.prod.outlook.com (2603:10b6:408:e0:cafe::20) by BN1PR10CA0007.outlook.office365.com (2603:10b6:408:e0::12) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9564.8 via Frontend Transport; Wed, 28 Jan 2026 11:27:59 +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 BN1PEPF00004682.mail.protection.outlook.com (10.167.243.88) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9564.3 via Frontend Transport; Wed, 28 Jan 2026 11:28:00 +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.20; Wed, 28 Jan 2026 03:27:48 -0800 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.2562.20; Wed, 28 Jan 2026 03:27:47 -0800 Received: from vdi.nvidia.com (10.127.8.10) by mail.nvidia.com (10.129.68.10) with Microsoft SMTP Server id 15.2.2562.20 via Frontend Transport; Wed, 28 Jan 2026 03:27:42 -0800 From: Tariq Toukan To: Eric Dumazet , Jakub Kicinski , Paolo Abeni , Andrew Lunn , "David S. Miller" CC: Donald Hunter , Jiri Pirko , Jonathan Corbet , Saeed Mahameed , "Leon Romanovsky" , Tariq Toukan , Mark Bloch , , , , , Gal Pressman , Moshe Shemesh , Carolina Jubran , Cosmin Ratiu , Jiri Pirko , Randy Dunlap , Simon Horman , Krzysztof Kozlowski Subject: [PATCH net-next V7 04/14] devlink: Add helpers to lock nested-in instances Date: Wed, 28 Jan 2026 13:25:34 +0200 Message-ID: <20260128112544.1661250-5-tariqt@nvidia.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20260128112544.1661250-1-tariqt@nvidia.com> References: <20260128112544.1661250-1-tariqt@nvidia.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN1PEPF00004682:EE_|PH0PR12MB7982:EE_ X-MS-Office365-Filtering-Correlation-Id: 6ee9a5d5-7f6a-4fc4-c364-08de5e604b4a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|82310400026|7416014|376014|1800799024; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?EAFlT7AJWRu7A3noIaYs59gx+y+lLYAotYnLzgBVQp81nydf1iXF5rQEpUQX?= =?us-ascii?Q?bJXt+dikOAPVnLhssPfUkI1Q3qcHH3+aSMEyqi4tnEv1czHK5PL6hOoT25w/?= =?us-ascii?Q?vu1vP2fBhKKrAr/jKUmeYzLfvAdeDOqEwMkcUux2YpQ60T8bxY2Djx491vou?= =?us-ascii?Q?RHKaDhRTDXWLDoMeeYtLFGWUxgNITe0JXF5Tqhf1eHAX85Ffuk7NlCkWhdjP?= =?us-ascii?Q?s2T9IAMA611Xu35+gBlkEz3VbPq8wSCtEQsr3gIvM/sKuaF2vyGsZvXAvpRg?= =?us-ascii?Q?nFuRGNFhYN5JzEveW4ZTTqbd/5NH9BEAQn8E04aKfH+gid/iHVJQnvMpk9Ht?= =?us-ascii?Q?YaiFDpR6KpHbYB5H+VD+pz/LrtrRkqQilwVa12fd2Vmu1ejA9z8crIcqDA2y?= =?us-ascii?Q?uqywAtX1PyaAF/bRv6dQlJZUO60/eOSA/DdZ5EFkQGBWBdWb/ZmzKKNgI2Xa?= =?us-ascii?Q?Nqg9W0LqnMGcbuZZXzbNS7LlzBYravQd7P8SnsUHJS610O9psWfuD+1Uj8/D?= =?us-ascii?Q?AgBvGFBTysYY7yFArKqJEH8fPLmkK6rG+CIc3r1N+/gbE3gNyf42t+Q4sPQq?= =?us-ascii?Q?0ywSwG2J937i1yETSydnD1umSZCuqkIimb9C/sh5z3RsIG2k17qPbobz99rs?= =?us-ascii?Q?ottKYG6HTBAZgxK02EXjs1a2tFmnTDQfrYWC7fC2giBa0A52+gqc83Oiabsr?= =?us-ascii?Q?zh00B+2VWZaOHKsYkUWJsEFigomZmU/ODKs/3wuIOZm9UTSFSm5KSjrzAPDt?= =?us-ascii?Q?RqPkWIs3J3ntVNXdgvPWHa99Q3QBumdSv3ONW/N1hqRxQSNptzvptj+8uKFI?= =?us-ascii?Q?hMDT9VeY6AVZMESwH3LZ8Tk8f2SecSnGXuzpCI0TJlClYI4vt+nXCvwILxDZ?= =?us-ascii?Q?9wUbz86ajHeRWl+M9KSXdksjPTCBn8FczDO6nXjbD/F4KHaJOxM6rcMjorGK?= =?us-ascii?Q?bnugXLqblLIhp390itHLwM2JRHoDow/Vgn9SFKpkeT6c45IbCZhHpDjZSZkZ?= =?us-ascii?Q?v0MiySNzfsl0jW3Sfb6ef6p/IF6TbXzjMrOLleVKYUb/UOrYiI2FWlc+aBal?= =?us-ascii?Q?g97t423+kSKNDK5Ujx/brsC1+JgwylR+XAWiTkGGtkxzdIdMOJ2ePlxpX+Sl?= =?us-ascii?Q?76U9hAkOfZyIVbxBojQKV0eJr34/+yf9kGaxqHcr2RDU4WVQJKAyEMFdLxi6?= =?us-ascii?Q?dZFfYFaicK4fkadeLGP2vIyrfjbozQvc8HO9WJU5bf6CYNOOfY3JRyGr0JP5?= =?us-ascii?Q?3Sve61eCEll/665jB53VksjuD3aiUXtFqVXFhi2kMDqNwz/3FZERoJv3+OMi?= =?us-ascii?Q?sonY701eT/1msWjfWCZiOS08gwuuz5pPrvkcde9peZIiPkGqNgNCgsy4054f?= =?us-ascii?Q?tvPJgG2vfaLVI8se1dtRwpZVG8m6pMU5hUD6qeB37PsxMk5evHFYxn1/LRf8?= =?us-ascii?Q?O7OyOtvVXuZ3cQ6vylQMcDAf52mzfDblz+kELhiPVgsjXXrJnZNVOphgpZDd?= =?us-ascii?Q?ISaAG7CW6AEF6IKKZ8d3ojgc+fHDHrQRvt69cW2+a1fpVWTb//7joTrgf9dd?= =?us-ascii?Q?hTbw7M7P66N5JdWEXuLrfHPewqtxiY4FPeoBpZhHSRFUmqzgWYVcK4ORbeP6?= =?us-ascii?Q?1YEqMcI8Iy0g3itpUS1Ooa4txS6CDCnlB9r2fMyWnzubWIuoGR2S0Jf4S/ru?= =?us-ascii?Q?+uEwSg=3D=3D?= 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)(36860700013)(82310400026)(7416014)(376014)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Jan 2026 11:28:00.4368 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6ee9a5d5-7f6a-4fc4-c364-08de5e604b4a 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: BN1PEPF00004682.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR12MB7982 Content-Type: text/plain; charset="utf-8" From: Cosmin Ratiu Upcoming code will need to obtain a reference to locked nested-in devlink instances. Add helpers to lock, obtain an already locked reference and unlock/unref the nested-in instance. Signed-off-by: Cosmin Ratiu Reviewed-by: Carolina Jubran Reviewed-by: Jiri Pirko Signed-off-by: Tariq Toukan --- net/devlink/core.c | 42 +++++++++++++++++++++++++++++++++++++ net/devlink/devl_internal.h | 3 +++ 2 files changed, 45 insertions(+) diff --git a/net/devlink/core.c b/net/devlink/core.c index 6ae62c7f2a80..f228190df346 100644 --- a/net/devlink/core.c +++ b/net/devlink/core.c @@ -67,6 +67,48 @@ static void __devlink_rel_put(struct devlink_rel *rel) devlink_rel_free(rel); } =20 +struct devlink *devlink_nested_in_get_lock(struct devlink_rel *rel) +{ + struct devlink *devlink; + + if (!rel) + return NULL; + devlink =3D devlinks_xa_get(rel->nested_in.devlink_index); + if (!devlink) + return NULL; + devl_lock(devlink); + if (devl_is_registered(devlink)) + return devlink; + devl_unlock(devlink); + devlink_put(devlink); + return NULL; +} + +/* Returns the nested in devlink object and validates its lock is held. */ +struct devlink *devlink_nested_in_get_locked(struct devlink_rel *rel) +{ + struct devlink *devlink; + unsigned long index; + + if (!rel) + return NULL; + index =3D rel->nested_in.devlink_index; + devlink =3D xa_find(&devlinks, &index, index, DEVLINK_REGISTERED); + if (devlink) + devl_assert_locked(devlink); + return devlink; +} + +void devlink_nested_in_put_unlock(struct devlink_rel *rel) +{ + struct devlink *devlink =3D devlink_nested_in_get_locked(rel); + + if (devlink) { + devl_unlock(devlink); + devlink_put(devlink); + } +} + static void devlink_rel_nested_in_notify_work(struct work_struct *work) { struct devlink_rel *rel =3D container_of(work, struct devlink_rel, diff --git a/net/devlink/devl_internal.h b/net/devlink/devl_internal.h index 14eaad9cfe35..aea43d750d23 100644 --- a/net/devlink/devl_internal.h +++ b/net/devlink/devl_internal.h @@ -120,6 +120,9 @@ typedef void devlink_rel_notify_cb_t(struct devlink *de= vlink, u32 obj_index); typedef void devlink_rel_cleanup_cb_t(struct devlink *devlink, u32 obj_ind= ex, u32 rel_index); =20 +struct devlink *devlink_nested_in_get_lock(struct devlink_rel *rel); +struct devlink *devlink_nested_in_get_locked(struct devlink_rel *rel); +void devlink_nested_in_put_unlock(struct devlink_rel *rel); void devlink_rel_nested_in_clear(u32 rel_index); int devlink_rel_nested_in_add(u32 *rel_index, u32 devlink_index, u32 obj_index, devlink_rel_notify_cb_t *notify_cb, --=20 2.44.0 From nobody Sat Feb 7 17:09:28 2026 Received: from BYAPR05CU005.outbound.protection.outlook.com (mail-westusazon11010042.outbound.protection.outlook.com [52.101.85.42]) (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 4D99B34F47E; Wed, 28 Jan 2026 11:28:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.85.42 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769599696; cv=fail; b=k3WPMsVS/VZ5e3BJ25+j9xND1A4gdHbrKp36JFX9qBo29Vs5qpyVDMvJt/ok7bmWaYVcLqTd0KvCm6X8Ant+d0TfQwo8TOJqjs5Y+Y5H1jWYAdHW9Sx0jmoNR+ebcK+IgFkBl6R7QyK8+Ajb6yY/78xIVRIGe3oyW681XqNoHvA= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769599696; c=relaxed/simple; bh=RjAnyV49OpqLxH1Y/1/JYniSm6cVIzb8TL2yHKgRTfY=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=fLknPQia8d9K+s05flkZWPXi9p7yOpKwgZMSL8K62KHL5/aW4k9x8j5KGOuUqIoBMknuWgWXcPT7loIcu262UaXTAUsFVL+aY7rn5Gs5mnlDmQF+JPO1B47SM1CWIVGvQwDXe3H94o3KTmGWDRiKATX7xN5HZZP6UhSi4jGtzpU= 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=gAqv1Em9; arc=fail smtp.client-ip=52.101.85.42 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="gAqv1Em9" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=k5+hoT3kisFsXerhHiZBBzVipPRbpjylYgobBGakPcqXzxdiUUM9zJGBDf07f6J6rNt41oGkMmQx/3+gJoHMhJSF6qUzcj6EovdiLRnwkSkhupgKR5LJAl9YjkVKV8VT+bbg9ozFsZ2CLxHSySopqHz16eGIDdbGIeZos8N353fa+Sq2kkNq8keHrDYp1y8+tYB1g36/NdvoecfQmQnJkulhiLqDTeJvmWk0qE05O2EZEMLvleLuMH/8jckNk9py7ZLaVFk22iAdf1OEUmrfoRBBAU3M25MXsalxvnOz3pIud/iLUomhbpIU+Pmul6gAvffyjokUB1hUut1GeEm6mg== 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=P2GtwMvng+TR169kHZ1pzGoSguw7VuTInPh8458bkCg=; b=vyZs6gdr2OjlOtuXM045HQEXDtxmiAVNq9QcWbVZKMm+oGRP2dXXlPtTJGinkH/VKTXA6QYVbJGxdkdyGclJ8xG5NwBaqau5R1ZDooOapHOFOQRNDbZPjeqd4ysfxYoPDk6WHAwAnN0979D1LjKP00xeXl60/BZ+mxYJjLspMpvqD0Eg5py3y0FsOoZS4oi5BwusE+zYKikLyoeDwTID/YsYtLsjs2qO18vF06Dc/6IIceUf82ayclYiIajNm0SvnJRGVrLXQ+pmPCoDqHuBWjLT9BkkEzVOU+V8q+XDzCafbsF6PYLP3T8ycsYzMmSbJ/v1zBIboxcSqxPC2sfjOQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=google.com 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=P2GtwMvng+TR169kHZ1pzGoSguw7VuTInPh8458bkCg=; b=gAqv1Em9fOuElc0s7z7X+akbb7mouMeS5e4GnTwDINx2IiCZFkbZlDHXXuB5qdJVaa7D4LdPoPoLU1fRPQrQtTL9QS9aTaGdRj64Q0EjwypWcmBsozbqWroBz1BU+R87+mW3lqLFhB1CQtjIj3b3jLhJNFyDmQe4F8iPC/b4wllQtPQQPVQYNpzOuDRZPOeKbaKoWcc7mMoLNT1AbMYroBFXxB/3xjKpC20Exy7WH874Jg6Gycx5j7q6HNJsSuD/NTxRDc3Hu1oJO93OqwH8Sn9SWz9KgpJpBVUc4AKlxzIWtWMQz/4z89zuBFxNfdtgJb96mAQGfnv/0YyCgmZ80g== Received: from BN9PR03CA0738.namprd03.prod.outlook.com (2603:10b6:408:110::23) by CH2PR12MB4070.namprd12.prod.outlook.com (2603:10b6:610:ae::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9564.7; Wed, 28 Jan 2026 11:28:07 +0000 Received: from BN1PEPF00004686.namprd03.prod.outlook.com (2603:10b6:408:110:cafe::3a) by BN9PR03CA0738.outlook.office365.com (2603:10b6:408:110::23) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9564.7 via Frontend Transport; Wed, 28 Jan 2026 11:28:07 +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 BN1PEPF00004686.mail.protection.outlook.com (10.167.243.91) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9564.3 via Frontend Transport; Wed, 28 Jan 2026 11:28:07 +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.20; Wed, 28 Jan 2026 03:27:54 -0800 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.2562.20; Wed, 28 Jan 2026 03:27:53 -0800 Received: from vdi.nvidia.com (10.127.8.10) by mail.nvidia.com (10.129.68.10) with Microsoft SMTP Server id 15.2.2562.20 via Frontend Transport; Wed, 28 Jan 2026 03:27:48 -0800 From: Tariq Toukan To: Eric Dumazet , Jakub Kicinski , Paolo Abeni , Andrew Lunn , "David S. Miller" CC: Donald Hunter , Jiri Pirko , Jonathan Corbet , Saeed Mahameed , "Leon Romanovsky" , Tariq Toukan , Mark Bloch , , , , , Gal Pressman , Moshe Shemesh , Carolina Jubran , Cosmin Ratiu , Jiri Pirko , Randy Dunlap , Simon Horman , Krzysztof Kozlowski Subject: [PATCH net-next V7 05/14] devlink: Refactor devlink_rate_nodes_check Date: Wed, 28 Jan 2026 13:25:35 +0200 Message-ID: <20260128112544.1661250-6-tariqt@nvidia.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20260128112544.1661250-1-tariqt@nvidia.com> References: <20260128112544.1661250-1-tariqt@nvidia.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN1PEPF00004686:EE_|CH2PR12MB4070:EE_ X-MS-Office365-Filtering-Correlation-Id: 94477fd3-f323-4926-7184-08de5e604f43 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|376014|7416014|36860700013|1800799024; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?bS74l7JpbFaTCvnqw7WdUWr51Ls4CZA8JWmOR0OqtX0+27QY2uzFPqPRKoiH?= =?us-ascii?Q?36w//7+9afs2OtnK4DoGsvvfEMKqrz2kGuyqffJL6yxeVQbOksNYqW3VfYDz?= =?us-ascii?Q?5Ddj9KRo5t5SYTLLG1HhQElJ8wBWMiU0IulgNqes3OEBOreLqsl8fBBPhobT?= =?us-ascii?Q?pMlmPcQWa5DNrovVeT2EnnYRzfzgnK5Vac+RNEYpmlruCpp0Mc5i3Hg5rNMz?= =?us-ascii?Q?0iMV0/TFnOEyo99PW6dFAesREKyBz8BEGC6PBimS/GcmBeFW9WOvC113T8R+?= =?us-ascii?Q?SQeHw6IBTBASoIKFL7l/UqSJYKtk5mSfU4HRryFKDUseLkpeoOSPwCcGys1G?= =?us-ascii?Q?F0npNzypptbjgm8bctA1RwE/+BKsfsMAe/7OOiK+UGZ5sFbLQbJ7p+HVk6ux?= =?us-ascii?Q?QW7PMB58OQYmFjCXVCEUldEPPXtUzK6OM9WNcaU9vXcArxBXW3oL0crv41L8?= =?us-ascii?Q?OY24KxLOJ7bOS6rTs4VdOQ8g+Tn7jqu2p62+OKMI6MnDuyTqFMPzhMLNeBSm?= =?us-ascii?Q?kdOZ5blu/IdxVYwu70P6Cm8pAdQO+hoMM49ya2MoqAPSmrFJMEUgbBn9qPsU?= =?us-ascii?Q?2YHbpI3dPzdPI/UqVaoRkv3lkmbwc/QaRShPhPoeukNSnTZV0JyleUiOT5xf?= =?us-ascii?Q?/P4qwNuQXNHOAPaK15yFbC+wc/IpkBN/Rt65fdDs/7pfjOWeovEB60XRvgbM?= =?us-ascii?Q?X6a8qw+FT4gTVQdW30jXEiQ4pDgDqgJdceEfQ7rXmR8tk398+63ha5aeYFp6?= =?us-ascii?Q?TGJoZJWCMmgpniHtqrk3DMK+CgTJuVb01HsU3u5qGaMT/2z2cg7xsyFQlzyd?= =?us-ascii?Q?+6sv+7KTzhKNyr651veU6agxFfHbiHsGnMLlBC4ZxLLQl6s1AmfJAkVfuL0j?= =?us-ascii?Q?6q+3ysvcsOpVox7YW6HvOHLSUlrVmzPLoVFtHPhBx6rOfGvguXbxMKynC/mI?= =?us-ascii?Q?j+AGu8wvBC3q6ez9/sLVHKbqcEz3bKQp+kJF0Z/i4p8UBrolP1m2DDaM6eFp?= =?us-ascii?Q?wk6LaHYwRMopqYULwFnrjb/ik++QKQZm9eipmW3fP/Rtz7XpsS94LnHV82ED?= =?us-ascii?Q?1HvALafVih4PlfoWC8S4S6AQBsT0sxjcpUoEF475FosCBHth7kR3IIFBNTJj?= =?us-ascii?Q?46UXegEZrQmgGB/ITgoX7uI1oVRLbfzI57DbuazlT/LhkDV7p+BKjuL8IzQW?= =?us-ascii?Q?+8u0lmGaCQ4eu8MSi241CKx5IBoPVQ1ikRNnLYuozO63zciarOAk2YdkYMFR?= =?us-ascii?Q?dAsgNm4B3i2Ym1W4DP2sLiz6hsCP0kd8RYk+RjsQP0Ouuz1fsmf9DGUHsJrf?= =?us-ascii?Q?hZwT8ZyKC/QqowpVc5GMyYrkb2+Mdi0hqe5osUirLkY0ciWUn/n1BzHVqgxa?= =?us-ascii?Q?X8CgfhEg3CbwM2jzedv91ATYRURjdlH84GJgrCJVsI8Uz5ZgmWnndljQOgmb?= =?us-ascii?Q?Qevb5u34Kq2yVS7Aq2EYMwkcWuu0axqjMBGP78iDYM856LKizjYGHGwdGWBO?= =?us-ascii?Q?5gCjhy9yCa+CBQ5gW2sCutLdYX6movxRrQ4tAn/Vr+GojkAuZDjSAWxzx9C0?= =?us-ascii?Q?opA0AXDxX4WcL+XV+g6fF0M3aYCJL8pefJEcNGC24lcnTPdEivPongoKLW8B?= =?us-ascii?Q?xuZhGZT9/jXi1+o1Vv34cY9fyE1j6BnOSThXT5iqZxL13fYEZlgIwqFo1E2V?= =?us-ascii?Q?4Jb6uQ=3D=3D?= X-Forefront-Antispam-Report: CIP:216.228.117.161;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge2.nvidia.com;CAT:NONE;SFS:(13230040)(82310400026)(376014)(7416014)(36860700013)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Jan 2026 11:28:07.1015 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 94477fd3-f323-4926-7184-08de5e604f43 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: BN1PEPF00004686.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB4070 Content-Type: text/plain; charset="utf-8" From: Cosmin Ratiu devlink_rate_nodes_check() was used to verify there are no devlink rate nodes created when switching the esw mode. Rate management code is about to become more complex, so refactor this function: - remove unused param 'mode'. - add a new 'rate_filter' param. - rename to devlink_rates_check(). - expose devlink_rate_is_node() to be used as a rate filter. This makes it more usable from multiple places, so use it from those places as well. Signed-off-by: Cosmin Ratiu Reviewed-by: Carolina Jubran Reviewed-by: Jiri Pirko Signed-off-by: Tariq Toukan --- net/devlink/core.c | 2 +- net/devlink/dev.c | 7 ++++--- net/devlink/devl_internal.h | 6 ++++-- net/devlink/rate.c | 13 +++++++------ 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/net/devlink/core.c b/net/devlink/core.c index f228190df346..f72d8cc0d6dd 100644 --- a/net/devlink/core.c +++ b/net/devlink/core.c @@ -517,7 +517,7 @@ void devlink_free(struct devlink *devlink) WARN_ON(!list_empty(&devlink->resource_list)); WARN_ON(!list_empty(&devlink->dpipe_table_list)); WARN_ON(!list_empty(&devlink->sb_list)); - WARN_ON(!list_empty(&devlink->rate_list)); + WARN_ON(devlink_rates_check(devlink, NULL, NULL)); WARN_ON(!list_empty(&devlink->linecard_list)); WARN_ON(!xa_empty(&devlink->ports)); =20 diff --git a/net/devlink/dev.c b/net/devlink/dev.c index 02602704bdea..e3a36de4f4ae 100644 --- a/net/devlink/dev.c +++ b/net/devlink/dev.c @@ -434,7 +434,7 @@ static void devlink_reload_reinit_sanity_check(struct d= evlink *devlink) WARN_ON(!list_empty(&devlink->trap_list)); WARN_ON(!list_empty(&devlink->dpipe_table_list)); WARN_ON(!list_empty(&devlink->sb_list)); - WARN_ON(!list_empty(&devlink->rate_list)); + WARN_ON(devlink_rates_check(devlink, NULL, NULL)); WARN_ON(!list_empty(&devlink->linecard_list)); WARN_ON(!xa_empty(&devlink->ports)); } @@ -713,10 +713,11 @@ int devlink_nl_eswitch_set_doit(struct sk_buff *skb, = struct genl_info *info) if (info->attrs[DEVLINK_ATTR_ESWITCH_MODE]) { if (!ops->eswitch_mode_set) return -EOPNOTSUPP; - mode =3D nla_get_u16(info->attrs[DEVLINK_ATTR_ESWITCH_MODE]); - err =3D devlink_rate_nodes_check(devlink, mode, info->extack); + err =3D devlink_rates_check(devlink, devlink_rate_is_node, + info->extack); if (err) return err; + mode =3D nla_get_u16(info->attrs[DEVLINK_ATTR_ESWITCH_MODE]); err =3D ops->eswitch_mode_set(devlink, mode, info->extack); if (err) return err; diff --git a/net/devlink/devl_internal.h b/net/devlink/devl_internal.h index aea43d750d23..8374c9cab6ce 100644 --- a/net/devlink/devl_internal.h +++ b/net/devlink/devl_internal.h @@ -300,8 +300,10 @@ int devlink_resources_validate(struct devlink *devlink, struct genl_info *info); =20 /* Rates */ -int devlink_rate_nodes_check(struct devlink *devlink, u16 mode, - struct netlink_ext_ack *extack); +bool devlink_rate_is_node(const struct devlink_rate *devlink_rate); +int devlink_rates_check(struct devlink *devlink, + bool (*rate_filter)(const struct devlink_rate *), + struct netlink_ext_ack *extack); =20 /* Linecards */ unsigned int devlink_linecard_index(struct devlink_linecard *linecard); diff --git a/net/devlink/rate.c b/net/devlink/rate.c index d157a8419bca..0d68b5c477dc 100644 --- a/net/devlink/rate.c +++ b/net/devlink/rate.c @@ -12,8 +12,7 @@ devlink_rate_is_leaf(struct devlink_rate *devlink_rate) return devlink_rate->type =3D=3D DEVLINK_RATE_TYPE_LEAF; } =20 -static inline bool -devlink_rate_is_node(struct devlink_rate *devlink_rate) +bool devlink_rate_is_node(const struct devlink_rate *devlink_rate) { return devlink_rate->type =3D=3D DEVLINK_RATE_TYPE_NODE; } @@ -688,14 +687,16 @@ int devlink_nl_rate_del_doit(struct sk_buff *skb, str= uct genl_info *info) return err; } =20 -int devlink_rate_nodes_check(struct devlink *devlink, u16 mode, - struct netlink_ext_ack *extack) +int devlink_rates_check(struct devlink *devlink, + bool (*rate_filter)(const struct devlink_rate *), + struct netlink_ext_ack *extack) { struct devlink_rate *devlink_rate; =20 list_for_each_entry(devlink_rate, &devlink->rate_list, list) - if (devlink_rate_is_node(devlink_rate)) { - NL_SET_ERR_MSG(extack, "Rate node(s) exists."); + if (!rate_filter || rate_filter(devlink_rate)) { + if (extack) + NL_SET_ERR_MSG(extack, "Rate node(s) exists."); return -EBUSY; } return 0; --=20 2.44.0 From nobody Sat Feb 7 17:09:28 2026 Received: from CH1PR05CU001.outbound.protection.outlook.com (mail-northcentralusazon11010043.outbound.protection.outlook.com [52.101.193.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 E028A34F48D; Wed, 28 Jan 2026 11:28:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.193.43 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769599698; cv=fail; b=ZFZvkEuuvFaCWLgDlS/Tt+arTFk8bfbLC1ww5ts8h95rwTpqWwruK72sC3nMdwCGtCkyQNNp7RA4pUVN+3NN5kQOJ4iazgZVBO3xpTQPxRQ1SgI22TslcD+dVkuZ9FbAXJFfCiltd2BJhE3WBAIAHQreENDC2ZgGjdVJgUnWBlo= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769599698; c=relaxed/simple; bh=bteEhhF2+0MQT8anZAMYaFKSaUbv1hd/pJM5rB9szE4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=IA4weQw2DEprEf8cacPo4JjADpFQsB5ZeFaf5QOBRug8KBdSHdVrSdIo7zEEsEXJhSu18eCv3oYS43BQ/j6aalXuOixXpOqrQIs/GAnUV8St4SQB7+FVj5BvlXgsUoK1QiBOuW9xVA4+1jkOsNx1U+9EIcKx98oTygbbFhBS6zI= 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=gVqtwxB/; arc=fail smtp.client-ip=52.101.193.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="gVqtwxB/" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=DPM3mKsu2E5x8ui+kA7JhF5t2btP+PrghZ8Rq15xZNgEN3Gs5CYeN6B8XN2TpFgH5i3j9LS8sURhyg6VKg9sAUkv7SRHx6FV5DhndW+vzFLFPAAhckZ4t/F+VCkoEj2YnRtXz6LdCnFJccU2fXi2cVsuvOKYysyNZtNyUKb5VCFEKgs41omBzbi4Yh9w3y6usCRgIyjxPzoWkH2Xgjjg5WBs4wrrh+JdyPlHWf7bL+mTDwyNwgsUxWK+AnZ1TZoEJ4y4RVr5ZNQ+Wmu7+p3rJZ6psMfftiE0gCmm2ILiH7Bh1qWphd3uF1kKvfltsEKGe8yQlxr8qObSjxJEqXblkw== 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=swuXfU9OsKz9oErO1xKCNGlsYOEkSGwCl6vX6BEUiBU=; b=b9FcSVNKpWTHpj5t/3I0KstXeP4CAZnzPjEqYLqPZVXmBc0Ptvum+IzZfL/+WPofoNVb0S/PrAZvhZR0p88UFC4t4ZHGJgKmwBDhXQW1Vxm6/RZQUrb8hTSCQRLWkd4L338RQfB2wwREsulFgDM3EWBqC03meVxn4g/0anhklr56lya4qpYE23Ix1VgvHi0ymsVRkdhG0ZMdy7Iiho2ywpjUyf+mU97uls0T2fL7PLjHO9yh89hxveOWjF5ceW/mUliNiQHMcR+PlzXEYguFY/JHpvHr+7qWkGrB3kKissa5fERiycmNI04qdF5z4KehWUYEbuXfnpXbO2wD1Bb4rQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=google.com 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=swuXfU9OsKz9oErO1xKCNGlsYOEkSGwCl6vX6BEUiBU=; b=gVqtwxB/x+acEHL4pZrOwtV9xImEhVpDPOiOHS6SjUO3YqYIQcm0PMTPq0xutUsneKr8qQQNptv3T2gy0TmAqgBfABI95BqYslDPjKoc+K0ycEk1GQAIVqwVpUC3xD2p85K4CTvtYR4Dv9WqeeVT0ry81R/Q4VzzUS94d4T02bI39zrn83n2o1yk4Yg0tdAAx2dDe0Cu4B7t5oGHZa+1jTf6zC6uMkLPxS8E9zK0M0AfdPrUp2ayUelnyJ6sjlhSMVozJajtdaRvmwx99Snxv99UjIvEgb8gxCwTm/qK34SQDGUVnsWhgR8Q0gPMOQcmWywEsN9LIGRpTvppGs1gQA== Received: from PH1PEPF000132F0.NAMP220.PROD.OUTLOOK.COM (2603:10b6:518:1::33) by IA1PR12MB6459.namprd12.prod.outlook.com (2603:10b6:208:3a9::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9564.7; Wed, 28 Jan 2026 11:28:10 +0000 Received: from SN1PEPF0002BA4D.namprd03.prod.outlook.com (2a01:111:f403:f90e::3) by PH1PEPF000132F0.outlook.office365.com (2603:1036:903:47::3) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9564.8 via Frontend Transport; Wed, 28 Jan 2026 11:28:10 +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 SN1PEPF0002BA4D.mail.protection.outlook.com (10.167.242.70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9564.3 via Frontend Transport; Wed, 28 Jan 2026 11:28:09 +0000 Received: from rnnvmail202.nvidia.com (10.129.68.7) 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.2562.20; Wed, 28 Jan 2026 03:28:00 -0800 Received: from rnnvmail205.nvidia.com (10.129.68.10) by rnnvmail202.nvidia.com (10.129.68.7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.20; Wed, 28 Jan 2026 03:27:59 -0800 Received: from vdi.nvidia.com (10.127.8.10) by mail.nvidia.com (10.129.68.10) with Microsoft SMTP Server id 15.2.2562.20 via Frontend Transport; Wed, 28 Jan 2026 03:27:54 -0800 From: Tariq Toukan To: Eric Dumazet , Jakub Kicinski , Paolo Abeni , Andrew Lunn , "David S. Miller" CC: Donald Hunter , Jiri Pirko , Jonathan Corbet , Saeed Mahameed , "Leon Romanovsky" , Tariq Toukan , Mark Bloch , , , , , Gal Pressman , Moshe Shemesh , Carolina Jubran , Cosmin Ratiu , Jiri Pirko , Randy Dunlap , Simon Horman , Krzysztof Kozlowski Subject: [PATCH net-next V7 06/14] devlink: Decouple rate storage from associated devlink object Date: Wed, 28 Jan 2026 13:25:36 +0200 Message-ID: <20260128112544.1661250-7-tariqt@nvidia.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20260128112544.1661250-1-tariqt@nvidia.com> References: <20260128112544.1661250-1-tariqt@nvidia.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN1PEPF0002BA4D:EE_|IA1PR12MB6459:EE_ X-MS-Office365-Filtering-Correlation-Id: 446f9109-ac56-4912-6f83-08de5e6050e7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|82310400026|36860700013|376014|7416014; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?AOnezcPbiWG2Ead8RjDVk5ks5XhEWktoPoH6ULQaZ6WQonb53CRs0PLsZCzb?= =?us-ascii?Q?3TlJDjD7rqKaqmGv5O+4tmpQv5IhRfdn2rrwOotWqX0bcJw+4dIlROvaz6KS?= =?us-ascii?Q?ULiPEqwoCP1tP8ujKqT33tG8ZuZMx2b6L7yLpnW7uzx2/3aGQZ8OwA4FtXhl?= =?us-ascii?Q?K3knT790jlhOcp29lTcTSoMGlGjK2KGkwoYmDpcc1NCM4moYEt4WpDzB9bq9?= =?us-ascii?Q?Do9xFuhS5g7JPLa9747vlqm2MPlrJBBNnqFBGeCN4zSXLvJzF3cS2ZHQFUPJ?= =?us-ascii?Q?RuZbjal9HrhTxjpzqWpKKrNfa5iK5kidkE+oRO7TOu9URSoDmv/G/gbIxm66?= =?us-ascii?Q?1YLr4cRA/5grCwfXqZOhB0DThlP9HQUmEMCaR24xrQZMMPscgw3QwIqYVUVb?= =?us-ascii?Q?L4dEU48FliLCoXhT8r0kyMDhsTwe5z1q3jvpflWXuLACTsefIM2oMA+MKGhy?= =?us-ascii?Q?hSaL9moCNyTBgJnKt7kN48a+5ksPV3LxQJadHt2/VRfXSW8G8UpAl61ZpyRZ?= =?us-ascii?Q?FJBvogZeP4JK7pgXkahLU60Z5fGuoAPcZbE4fgc3YOWtybl8AtkgSyjTuVYv?= =?us-ascii?Q?5iEmQTOwwtvB2m33VWFFkJfBCjIYVzfKIgfFVzz/xahNP5TlqZXoT6nBL3bZ?= =?us-ascii?Q?qW2itxPFzrGjuQPTOfcGahwlvRzGmu4TsMTFRVBFEI1PuxlWmCfLBd6ADVIU?= =?us-ascii?Q?OsBNyWR1Tr+ol5b+9fn4jPJNJ9Li2tUYnt6XKwoimkvnxUbl+wDLfW1YD6wf?= =?us-ascii?Q?xHF916G31dK2tK4a+MjjPPZRH6I6wk+1LtNm5++ZiefSxYN1Pcya1AQ+r7YZ?= =?us-ascii?Q?M4K9Sgs2d5eAi6BvVkRPKLdWcW580mA84LANgBNCSFC1k25XRiX/MiQ3mEQW?= =?us-ascii?Q?e5Tsw3mcKTijHf3E/wpzSeKnsSawGWzWwTzmJH6BGhyvHyF6sXepNovz+S85?= =?us-ascii?Q?nXeO83ZCyDdd5YUVU5Ni7CWQ25hQJWA4pUf236pyIlGfhLO02uwmeE+Yz1QG?= =?us-ascii?Q?BX8wlln3bhYzUoCWQZw3p+dgga/eMBg/LsDhMKZe5T0V2WsxpspVbA068cVU?= =?us-ascii?Q?gF+xWw0gu0tVOefxeDYM+zQQlXt3RJ5fmebSfyRReYns4YRMXFR7eDPInOV/?= =?us-ascii?Q?gK68HYts6Fmupn04tnH18Nu1JGLw3ufn8rFduIhBNHXLpI77xnHh4VJJOlZY?= =?us-ascii?Q?DJXZTkCyrkkl2dw6+Ry4Gx1heBLurfcQRhl1JAI7gB4YlKW+XQQ4WbLbmr5q?= =?us-ascii?Q?27xjAODOmZ/Z/azv9FGA+S0fzARIDXU1EfojE3EkhimTPW7MVDRSbO5ckMZV?= =?us-ascii?Q?A+WSyj4ASSF0Cd/hZnCukOD5qPrx8R85nJ7sQZbHHNvnhmXy21mi6BhGdoK8?= =?us-ascii?Q?l7x0olPksgEBrUMtNw8IZnghGCiukVWbb5uumhvPhWQUAzV6VwcvWzUSemjn?= =?us-ascii?Q?Dpj3Qz7VKIi+Kb/NQLGgyjoob141PmADGiDgKPvZlpHaVPYm1DTwSGREzH7m?= =?us-ascii?Q?1A9S6rDVz+xnPTd0MMC51M3pRYMH9RSK2ugqQ65hw9GEa0NcNs+zlwQugiGH?= =?us-ascii?Q?kvqKcSWkRgZzGvW2WEmh70INFSgl1fFoMAkDjTtX4gPm5j583/zlL5YYawJV?= =?us-ascii?Q?4dfHBFrDeYWEzAonTsoxRryiRVsSjhmgnlfqBJqye/BnRZf+umsps7DXhHga?= =?us-ascii?Q?NzGaMQ=3D=3D?= X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230040)(1800799024)(82310400026)(36860700013)(376014)(7416014);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Jan 2026 11:28:09.9059 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 446f9109-ac56-4912-6f83-08de5e6050e7 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: SN1PEPF0002BA4D.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB6459 Content-Type: text/plain; charset="utf-8" From: Cosmin Ratiu Devlink rate leafs and nodes were stored in their respective devlink objects pointed to by devlink_rate->devlink. This patch removes that association by introducing the concept of 'rate node devlink', which is where all rates that could link to each other are stored. For now this is the same as devlink_rate->devlink. After this patch, the devlink rates stored in this devlink instance could potentially be from multiple other devlink instances. So all rate node manipulation code was updated to: - correctly compare the actual devlink object during iteration. - maybe acquire additional locks (noop for now). Signed-off-by: Cosmin Ratiu Reviewed-by: Carolina Jubran Reviewed-by: Jiri Pirko Signed-off-by: Tariq Toukan --- include/net/devlink.h | 2 + net/devlink/rate.c | 192 +++++++++++++++++++++++++++++++----------- 2 files changed, 143 insertions(+), 51 deletions(-) diff --git a/include/net/devlink.h b/include/net/devlink.h index c453faec8ebf..fbb434185a67 100644 --- a/include/net/devlink.h +++ b/include/net/devlink.h @@ -1820,6 +1820,8 @@ void devlink_port_attrs_pci_sf_set(struct devlink_por= t *devlink_port, bool external); int devl_port_fn_devlink_set(struct devlink_port *devlink_port, struct devlink *fn_devlink); +struct devlink *devl_rate_lock(struct devlink *devlink); +void devl_rate_unlock(struct devlink *devlink); struct devlink_rate * devl_rate_node_create(struct devlink *devlink, void *priv, char *node_name, struct devlink_rate *parent); diff --git a/net/devlink/rate.c b/net/devlink/rate.c index 0d68b5c477dc..c062fd8a6c36 100644 --- a/net/devlink/rate.c +++ b/net/devlink/rate.c @@ -30,13 +30,31 @@ devlink_rate_leaf_get_from_info(struct devlink *devlink= , struct genl_info *info) return devlink_rate ?: ERR_PTR(-ENODEV); } =20 +struct devlink *devl_rate_lock(struct devlink *devlink) +{ + return devlink; +} + +static struct devlink * +devl_get_rate_node_instance_locked(struct devlink *devlink) +{ + return devlink; +} + +void devl_rate_unlock(struct devlink *devlink) +{ +} + static struct devlink_rate * devlink_rate_node_get_by_name(struct devlink *devlink, const char *node_na= me) { struct devlink_rate *devlink_rate; + struct devlink *rate_devlink; =20 - list_for_each_entry(devlink_rate, &devlink->rate_list, list) { - if (devlink_rate_is_node(devlink_rate) && + rate_devlink =3D devl_get_rate_node_instance_locked(devlink); + list_for_each_entry(devlink_rate, &rate_devlink->rate_list, list) { + if (devlink_rate->devlink =3D=3D devlink && + devlink_rate_is_node(devlink_rate) && !strcmp(node_name, devlink_rate->name)) return devlink_rate; } @@ -190,17 +208,25 @@ static void devlink_rate_notify(struct devlink_rate *= devlink_rate, void devlink_rates_notify_register(struct devlink *devlink) { struct devlink_rate *rate_node; + struct devlink *rate_devlink; =20 - list_for_each_entry(rate_node, &devlink->rate_list, list) - devlink_rate_notify(rate_node, DEVLINK_CMD_RATE_NEW); + rate_devlink =3D devl_rate_lock(devlink); + list_for_each_entry(rate_node, &rate_devlink->rate_list, list) + if (rate_node->devlink =3D=3D devlink) + devlink_rate_notify(rate_node, DEVLINK_CMD_RATE_NEW); + devl_rate_unlock(devlink); } =20 void devlink_rates_notify_unregister(struct devlink *devlink) { struct devlink_rate *rate_node; + struct devlink *rate_devlink; =20 - list_for_each_entry_reverse(rate_node, &devlink->rate_list, list) - devlink_rate_notify(rate_node, DEVLINK_CMD_RATE_DEL); + rate_devlink =3D devl_rate_lock(devlink); + list_for_each_entry_reverse(rate_node, &rate_devlink->rate_list, list) + if (rate_node->devlink =3D=3D devlink) + devlink_rate_notify(rate_node, DEVLINK_CMD_RATE_DEL); + devl_rate_unlock(devlink); } =20 static int @@ -209,17 +235,20 @@ devlink_nl_rate_get_dump_one(struct sk_buff *msg, str= uct devlink *devlink, { struct devlink_nl_dump_state *state =3D devlink_dump_state(cb); struct devlink_rate *devlink_rate; + struct devlink *rate_devlink; int idx =3D 0; int err =3D 0; =20 - list_for_each_entry(devlink_rate, &devlink->rate_list, list) { + rate_devlink =3D devl_rate_lock(devlink); + list_for_each_entry(devlink_rate, &rate_devlink->rate_list, list) { enum devlink_command cmd =3D DEVLINK_CMD_RATE_NEW; u32 id =3D NETLINK_CB(cb->skb).portid; =20 - if (idx < state->idx) { + if (idx < state->idx || devlink_rate->devlink !=3D devlink) { idx++; continue; } + err =3D devlink_nl_rate_fill(msg, devlink_rate, cmd, id, cb->nlh->nlmsg_seq, flags, NULL); if (err) { @@ -228,6 +257,7 @@ devlink_nl_rate_get_dump_one(struct sk_buff *msg, struc= t devlink *devlink, } idx++; } + devl_rate_unlock(devlink); =20 return err; } @@ -244,23 +274,33 @@ int devlink_nl_rate_get_doit(struct sk_buff *skb, str= uct genl_info *info) struct sk_buff *msg; int err; =20 + devl_rate_lock(devlink); devlink_rate =3D devlink_rate_get_from_info(devlink, info); - if (IS_ERR(devlink_rate)) - return PTR_ERR(devlink_rate); + if (IS_ERR(devlink_rate)) { + err =3D PTR_ERR(devlink_rate); + goto unlock; + } =20 msg =3D nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); - if (!msg) - return -ENOMEM; + if (!msg) { + err =3D -ENOMEM; + goto unlock; + } =20 err =3D devlink_nl_rate_fill(msg, devlink_rate, DEVLINK_CMD_RATE_NEW, info->snd_portid, info->snd_seq, 0, info->extack); - if (err) { - nlmsg_free(msg); - return err; - } + if (err) + goto err_fill; =20 + devl_rate_unlock(devlink); return genlmsg_reply(msg, info); + +err_fill: + nlmsg_free(msg); +unlock: + devl_rate_unlock(devlink); + return err; } =20 static bool @@ -590,24 +630,32 @@ int devlink_nl_rate_set_doit(struct sk_buff *skb, str= uct genl_info *info) const struct devlink_ops *ops; int err; =20 + devl_rate_lock(devlink); devlink_rate =3D devlink_rate_get_from_info(devlink, info); - if (IS_ERR(devlink_rate)) - return PTR_ERR(devlink_rate); + if (IS_ERR(devlink_rate)) { + err =3D PTR_ERR(devlink_rate); + goto unlock; + } =20 ops =3D devlink->ops; - if (!ops || !devlink_rate_set_ops_supported(ops, info, devlink_rate->type= )) - return -EOPNOTSUPP; + if (!ops || + !devlink_rate_set_ops_supported(ops, info, devlink_rate->type)) { + err =3D -EOPNOTSUPP; + goto unlock; + } =20 err =3D devlink_nl_rate_set(devlink_rate, ops, info); =20 if (!err) devlink_rate_notify(devlink_rate, DEVLINK_CMD_RATE_NEW); +unlock: + devl_rate_unlock(devlink); return err; } =20 int devlink_nl_rate_new_doit(struct sk_buff *skb, struct genl_info *info) { - struct devlink *devlink =3D info->user_ptr[0]; + struct devlink *rate_devlink, *devlink =3D info->user_ptr[0]; struct devlink_rate *rate_node; const struct devlink_ops *ops; int err; @@ -621,15 +669,21 @@ int devlink_nl_rate_new_doit(struct sk_buff *skb, str= uct genl_info *info) if (!devlink_rate_set_ops_supported(ops, info, DEVLINK_RATE_TYPE_NODE)) return -EOPNOTSUPP; =20 + rate_devlink =3D devl_rate_lock(devlink); rate_node =3D devlink_rate_node_get_from_attrs(devlink, info->attrs); - if (!IS_ERR(rate_node)) - return -EEXIST; - else if (rate_node =3D=3D ERR_PTR(-EINVAL)) - return -EINVAL; + if (!IS_ERR(rate_node)) { + err =3D -EEXIST; + goto unlock; + } else if (rate_node =3D=3D ERR_PTR(-EINVAL)) { + err =3D -EINVAL; + goto unlock; + } =20 rate_node =3D kzalloc(sizeof(*rate_node), GFP_KERNEL); - if (!rate_node) - return -ENOMEM; + if (!rate_node) { + err =3D -ENOMEM; + goto unlock; + } =20 rate_node->devlink =3D devlink; rate_node->type =3D DEVLINK_RATE_TYPE_NODE; @@ -648,8 +702,9 @@ int devlink_nl_rate_new_doit(struct sk_buff *skb, struc= t genl_info *info) goto err_rate_set; =20 refcount_set(&rate_node->refcnt, 1); - list_add(&rate_node->list, &devlink->rate_list); + list_add(&rate_node->list, &rate_devlink->rate_list); devlink_rate_notify(rate_node, DEVLINK_CMD_RATE_NEW); + devl_rate_unlock(devlink); return 0; =20 err_rate_set: @@ -658,6 +713,8 @@ int devlink_nl_rate_new_doit(struct sk_buff *skb, struc= t genl_info *info) kfree(rate_node->name); err_strdup: kfree(rate_node); +unlock: + devl_rate_unlock(devlink); return err; } =20 @@ -667,13 +724,17 @@ int devlink_nl_rate_del_doit(struct sk_buff *skb, str= uct genl_info *info) struct devlink_rate *rate_node; int err; =20 + devl_rate_lock(devlink); rate_node =3D devlink_rate_node_get_from_info(devlink, info); - if (IS_ERR(rate_node)) - return PTR_ERR(rate_node); + if (IS_ERR(rate_node)) { + err =3D PTR_ERR(rate_node); + goto unlock; + } =20 if (refcount_read(&rate_node->refcnt) > 1) { NL_SET_ERR_MSG(info->extack, "Node has children. Cannot delete node."); - return -EBUSY; + err =3D -EBUSY; + goto unlock; } =20 devlink_rate_notify(rate_node, DEVLINK_CMD_RATE_DEL); @@ -684,6 +745,8 @@ int devlink_nl_rate_del_doit(struct sk_buff *skb, struc= t genl_info *info) list_del(&rate_node->list); kfree(rate_node->name); kfree(rate_node); +unlock: + devl_rate_unlock(devlink); return err; } =20 @@ -692,14 +755,20 @@ int devlink_rates_check(struct devlink *devlink, struct netlink_ext_ack *extack) { struct devlink_rate *devlink_rate; + struct devlink *rate_devlink; + int err =3D 0; =20 - list_for_each_entry(devlink_rate, &devlink->rate_list, list) - if (!rate_filter || rate_filter(devlink_rate)) { + rate_devlink =3D devl_rate_lock(devlink); + list_for_each_entry(devlink_rate, &rate_devlink->rate_list, list) + if (devlink_rate->devlink =3D=3D devlink && + (!rate_filter || rate_filter(devlink_rate))) { if (extack) NL_SET_ERR_MSG(extack, "Rate node(s) exists."); - return -EBUSY; + err =3D -EBUSY; + break; } - return 0; + devl_rate_unlock(devlink); + return err; } =20 /** @@ -716,14 +785,20 @@ devl_rate_node_create(struct devlink *devlink, void *= priv, char *node_name, struct devlink_rate *parent) { struct devlink_rate *rate_node; + struct devlink *rate_devlink; =20 + rate_devlink =3D devl_rate_lock(devlink); rate_node =3D devlink_rate_node_get_by_name(devlink, node_name); - if (!IS_ERR(rate_node)) - return ERR_PTR(-EEXIST); + if (!IS_ERR(rate_node)) { + rate_node =3D ERR_PTR(-EEXIST); + goto unlock; + } =20 rate_node =3D kzalloc(sizeof(*rate_node), GFP_KERNEL); - if (!rate_node) - return ERR_PTR(-ENOMEM); + if (!rate_node) { + rate_node =3D ERR_PTR(-ENOMEM); + goto unlock; + } =20 if (parent) { rate_node->parent =3D parent; @@ -737,12 +812,15 @@ devl_rate_node_create(struct devlink *devlink, void *= priv, char *node_name, rate_node->name =3D kstrdup(node_name, GFP_KERNEL); if (!rate_node->name) { kfree(rate_node); - return ERR_PTR(-ENOMEM); + rate_node =3D ERR_PTR(-ENOMEM); + goto unlock; } =20 refcount_set(&rate_node->refcnt, 1); - list_add(&rate_node->list, &devlink->rate_list); + list_add(&rate_node->list, &rate_devlink->rate_list); devlink_rate_notify(rate_node, DEVLINK_CMD_RATE_NEW); +unlock: + devl_rate_unlock(devlink); return rate_node; } EXPORT_SYMBOL_GPL(devl_rate_node_create); @@ -758,10 +836,10 @@ EXPORT_SYMBOL_GPL(devl_rate_node_create); int devl_rate_leaf_create(struct devlink_port *devlink_port, void *priv, struct devlink_rate *parent) { - struct devlink *devlink =3D devlink_port->devlink; + struct devlink *rate_devlink, *devlink =3D devlink_port->devlink; struct devlink_rate *devlink_rate; =20 - devl_assert_locked(devlink_port->devlink); + devl_assert_locked(devlink); =20 if (WARN_ON(devlink_port->devlink_rate)) return -EBUSY; @@ -770,6 +848,7 @@ int devl_rate_leaf_create(struct devlink_port *devlink_= port, void *priv, if (!devlink_rate) return -ENOMEM; =20 + rate_devlink =3D devl_rate_lock(devlink); if (parent) { devlink_rate->parent =3D parent; refcount_inc(&devlink_rate->parent->refcnt); @@ -779,9 +858,10 @@ int devl_rate_leaf_create(struct devlink_port *devlink= _port, void *priv, devlink_rate->devlink =3D devlink; devlink_rate->devlink_port =3D devlink_port; devlink_rate->priv =3D priv; - list_add_tail(&devlink_rate->list, &devlink->rate_list); + list_add_tail(&devlink_rate->list, &rate_devlink->rate_list); devlink_port->devlink_rate =3D devlink_rate; devlink_rate_notify(devlink_rate, DEVLINK_CMD_RATE_NEW); + devl_rate_unlock(devlink); =20 return 0; } @@ -797,16 +877,19 @@ EXPORT_SYMBOL_GPL(devl_rate_leaf_create); void devl_rate_leaf_destroy(struct devlink_port *devlink_port) { struct devlink_rate *devlink_rate =3D devlink_port->devlink_rate; + struct devlink *devlink =3D devlink_port->devlink; =20 - devl_assert_locked(devlink_port->devlink); + devl_assert_locked(devlink); if (!devlink_rate) return; =20 + devl_rate_lock(devlink); devlink_rate_notify(devlink_rate, DEVLINK_CMD_RATE_DEL); if (devlink_rate->parent) refcount_dec(&devlink_rate->parent->refcnt); list_del(&devlink_rate->list); devlink_port->devlink_rate =3D NULL; + devl_rate_unlock(devlink); kfree(devlink_rate); } EXPORT_SYMBOL_GPL(devl_rate_leaf_destroy); @@ -815,18 +898,22 @@ EXPORT_SYMBOL_GPL(devl_rate_leaf_destroy); * devl_rate_nodes_destroy - destroy all devlink rate nodes on device * @devlink: devlink instance * - * Unset parent for all rate objects and destroy all rate nodes - * on specified device. + * Unset parent for all rate objects involving this device and destroy all= rate + * nodes on it. */ void devl_rate_nodes_destroy(struct devlink *devlink) { const struct devlink_ops *ops =3D devlink->ops; struct devlink_rate *devlink_rate, *tmp; + struct devlink *rate_devlink; =20 devl_assert_locked(devlink); + rate_devlink =3D devl_rate_lock(devlink); =20 - list_for_each_entry(devlink_rate, &devlink->rate_list, list) { - if (!devlink_rate->parent) + list_for_each_entry(devlink_rate, &rate_devlink->rate_list, list) { + if (!devlink_rate->parent || + (devlink_rate->devlink !=3D devlink && + devlink_rate->parent->devlink !=3D devlink)) continue; =20 if (devlink_rate_is_leaf(devlink_rate)) @@ -839,13 +926,16 @@ void devl_rate_nodes_destroy(struct devlink *devlink) refcount_dec(&devlink_rate->parent->refcnt); devlink_rate->parent =3D NULL; } - list_for_each_entry_safe(devlink_rate, tmp, &devlink->rate_list, list) { - if (devlink_rate_is_node(devlink_rate)) { + list_for_each_entry_safe(devlink_rate, tmp, &rate_devlink->rate_list, + list) { + if (devlink_rate->devlink =3D=3D devlink && + devlink_rate_is_node(devlink_rate)) { ops->rate_node_del(devlink_rate, devlink_rate->priv, NULL); list_del(&devlink_rate->list); kfree(devlink_rate->name); kfree(devlink_rate); } } + devl_rate_unlock(devlink); } EXPORT_SYMBOL_GPL(devl_rate_nodes_destroy); --=20 2.44.0 From nobody Sat Feb 7 17:09:28 2026 Received: from SN4PR0501CU005.outbound.protection.outlook.com (mail-southcentralusazon11011067.outbound.protection.outlook.com [40.93.194.67]) (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 258B734DCF2; Wed, 28 Jan 2026 11:28:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.93.194.67 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769599707; cv=fail; b=tN3BHHvI0FZZug4YMg4kRJ9ruzcEOFcF2NAL4xnRB9vAdrYLK2JmjfPvhW+/iBMV58Og+uDp0hazv3eFONwq0LyD3rBCFJ6A2ncTUQ278Zgsl/gvsb40DG3E9mTxxASbg9U/VnDx4xQmYi/8JA3scrVtWkRBpQXpMokEfe9CQCs= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769599707; c=relaxed/simple; bh=+TsFKrnKKV1p2dgtjA47WCAuMN4brrlr8HzPmFibMXU=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=r6MPhN3tuLgpichRRtHW1CA3pYLc2hBM0chVS2j8CH8N6nu39lRrUfwWd7worFtCogUkD84YKAOgRvshidCbYhHcWIqZ9yPSFMISlaJ+fnqclLjBet99LWckJwCWvH4gGPFobpO6oL7e4E95EsBBjy/NqWnk1inwEfGHovxBz+Y= 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=s2uvsoHS; arc=fail smtp.client-ip=40.93.194.67 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="s2uvsoHS" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=C/EIhUA9c333VbCpAiMvuLAgIppby9rXAR2gV9QOIjy8Ss8AXevw60gPqfpC6/OKqAlzxRvIqRjn3DfJo8CVNhyrb3MFKUEWw5mEKDVdGYJ0g4p1HrT2GOW61JjTNYdxWXVWKL07fD9p7eoKNR9I+rvZew3zlgvxN6G76hYwEYE/81uTFJyyCxiZhdvNeFj4iy7RkJ51GkqVu7IBSDXXpy9ltJ2XB9yTdPDpNmHBNBlNvTb9e75K4kaWXvepjWNlqma4hsvI4un+4Fu5EYImBMbsrdv7OyFxjmCvTSUY0cnGZQ0yWlGbO5klI2ytEmiGkgEcqlv0v3jY2si8ppMjFQ== 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=7b15WwGvDn/phApRK4B0qKnSLSXcoTi+A220DrHSE44=; b=emBLhU5qu4ezVEYjxyBZANdQhIoRcr2hP9UXzgeOuS5nrpCzuCv43ToryyAGPEs7YpxAD3B612b775YksuZUVnw5nn60+bbxGWZAZmRR1v2DJit7LuKLIRkfoI9RI3TFjIy9OCByxavMJptvfLv3b/vngezsEgPYqzEsV79f8/po19/wVGe4dBMvs00/sG3w2Wgk0JOFumMuDyX+w0bhAuLqwyvC/UuZnkOwRgDwua4B1HIHC0qClEZaNNq5AJ0zYMiRm/M6AJWS6fxYGk7DkpNGzDq6PimsGrnSwL4x0SFQuLjRKaqSm7xHjJFOCRDM8XFlx/qVux2P/cD2DdzkKg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=google.com 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=7b15WwGvDn/phApRK4B0qKnSLSXcoTi+A220DrHSE44=; b=s2uvsoHSOCFN9C06Gyay04a37ljDJbkpTUHmGayfAaNikdt3LSVUUqx3glyIbm1C0KruSSx4LS9xkx1xaiOD2hwOw8HCIngTLXLHHnDD59SCxN4Ihlu/jkoy6N5R0LuJt0swvvEG43aLS8edvctekg05Z6VHHJNUyqufgZ6ipyAvwpjqVPefm7rEXyBMUdgyx20POuqoxWl3rNfxKp8hF5SX24rKzaPo/MRDcyngtwT0PKNFn9vjd6fqxjziSfn2B1gH+v6AEBi+n+IIPqpq1ySl6y6vtpHDFqfr9O2dSDJDs+nnnsqLVL9jZYVZEt/Wvrv16Yrzb7uCwhnoHauDSA== Received: from BN1PR10CA0005.namprd10.prod.outlook.com (2603:10b6:408:e0::10) by PH7PR12MB8123.namprd12.prod.outlook.com (2603:10b6:510:2bb::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9542.15; Wed, 28 Jan 2026 11:28:17 +0000 Received: from BN1PEPF00004682.namprd03.prod.outlook.com (2603:10b6:408:e0:cafe::8e) by BN1PR10CA0005.outlook.office365.com (2603:10b6:408:e0::10) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9564.7 via Frontend Transport; Wed, 28 Jan 2026 11:28:15 +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 BN1PEPF00004682.mail.protection.outlook.com (10.167.243.88) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9564.3 via Frontend Transport; Wed, 28 Jan 2026 11:28:17 +0000 Received: from rnnvmail202.nvidia.com (10.129.68.7) 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.20; Wed, 28 Jan 2026 03:28:06 -0800 Received: from rnnvmail205.nvidia.com (10.129.68.10) by rnnvmail202.nvidia.com (10.129.68.7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.20; Wed, 28 Jan 2026 03:28:05 -0800 Received: from vdi.nvidia.com (10.127.8.10) by mail.nvidia.com (10.129.68.10) with Microsoft SMTP Server id 15.2.2562.20 via Frontend Transport; Wed, 28 Jan 2026 03:28:00 -0800 From: Tariq Toukan To: Eric Dumazet , Jakub Kicinski , Paolo Abeni , Andrew Lunn , "David S. Miller" CC: Donald Hunter , Jiri Pirko , Jonathan Corbet , Saeed Mahameed , "Leon Romanovsky" , Tariq Toukan , Mark Bloch , , , , , Gal Pressman , Moshe Shemesh , Carolina Jubran , Cosmin Ratiu , Jiri Pirko , Randy Dunlap , Simon Horman , Krzysztof Kozlowski Subject: [PATCH net-next V7 07/14] devlink: Add parent dev to devlink API Date: Wed, 28 Jan 2026 13:25:37 +0200 Message-ID: <20260128112544.1661250-8-tariqt@nvidia.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20260128112544.1661250-1-tariqt@nvidia.com> References: <20260128112544.1661250-1-tariqt@nvidia.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN1PEPF00004682:EE_|PH7PR12MB8123:EE_ X-MS-Office365-Filtering-Correlation-Id: 2accfab3-f5ad-420f-4c80-08de5e605566 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|1800799024|7416014|376014|82310400026; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?OILIFHJAd/kFIQEatw/JcVA9znxTnhIjVdSX/e03zzi6+bgK+rGF73cG1kzb?= =?us-ascii?Q?OeqsdHzLPX9irzEFy2YntIiscbAep8+s04AWLRsg39AsHCAHdDC/pE8+nzQF?= =?us-ascii?Q?iZlnN1+8/3vYI+P/sRXeV4eWQjrFX4yXM4rQ3hwa71ouKiZPmyiMbyL1FpkQ?= =?us-ascii?Q?IygGs32+8RenaUVSsbWhnVoN25P0v9OVybzPrDVn/bb+gl8XOlTprblnFcOR?= =?us-ascii?Q?YbAZ6WrdlLSjWN4Au8ytGQM24KAjrE15SpKrWHtyAXMKEFf1ueK39HjtOsHH?= =?us-ascii?Q?5hBqRcYjtgYU2tQ+J4VPgP5mPMuzj4067kSbPFhxtZHbmcBZWvQe/krW2C68?= =?us-ascii?Q?A4xhhbCjp3MKssAShwshtH773qYGpNU1Axa++LN/jZS7jwTSwlltI5u5hwi6?= =?us-ascii?Q?fNLaO6Me4aF/4ziT8Qy+dElYHTEga7PSCnqHDJF/cvAo9uasrp26oo5fdYel?= =?us-ascii?Q?4l9a+b3Ni7fHh+QRw6jeel+Jq6iccT7dDwlEsMyH39pzeQpY1HuIofogDRpo?= =?us-ascii?Q?0Tr2HvdbB0COs0kXLJXgPw+cn2pgy9jtAp5IGONPYYSVHir+U/88/tyAonaq?= =?us-ascii?Q?CHBpavsYSTNpq2lLLW49VX8FFbgHwT+HCYh81RAzATR0AjQEPWM/jX/f2OgZ?= =?us-ascii?Q?bXug0tLVGGi3O0PdiZn4jYWTFvo9LpsKpc0xS3VvKkx6BbPsXaSDSwqm1GC2?= =?us-ascii?Q?batKLkQTkxUDCzJMkud0nVBi5gdL/hucSZcOnKLnwNpqPJBw/RimQisiCsks?= =?us-ascii?Q?D/8cGA0Oqd/FWYksXKf3Y96tH3+YGeiNkcN9PictlflNwRaPKhMuyJ+g27nB?= =?us-ascii?Q?LI1tz/nNTduLDEf4UIdzepVD2SGOimTgkjsFvJcp6AjnqOvSBrpwVosBe1Lz?= =?us-ascii?Q?l2qc23ILjbXiUVClbeAPUJ/2+/VhNdYxm5Ag9awpgO0V1BqatqdLwIZp4ubZ?= =?us-ascii?Q?ZHcFfHfNSoDUVBvtWmuiOGlosLFZTiS6X+Ku8x259E7maqzVsPpEIu8KlEPf?= =?us-ascii?Q?+ZzkH9RQzOd/q+q6tQzyoPZfqoioXhQ0nr5lHOlZIDqUwOmDbY5FwomGh5cX?= =?us-ascii?Q?4KA2Tyb0nGHR4WmnEAjMpPYJlWhNjcm1BpHB/yh3zK0+w8jyKhiECHKvlBQB?= =?us-ascii?Q?8B9F5n81YUHNEdh6/T4W9i8ehkJX8028742viZkgz7n0au24OolWXwJ/AZoQ?= =?us-ascii?Q?RvM4iLHbFDqurdT9Xv1fW7/fTp5K/qvFAKaW3iPsTLDc9UUNZiPiNfrA04gY?= =?us-ascii?Q?wT6mlqs1yA7slOgCYD/TGLDEZOsQFbuUOhP/oLqLobQXwWzkjHcKUPh8ugEf?= =?us-ascii?Q?OO7MKDaUKt2ypwWqq5ZY/oS6DD1kR748TgWUQQA6iIJXSlEIFzDaogB5Ou4S?= =?us-ascii?Q?TXoFMwhhBCwyhkyfmbJcQIqAieqfo4Qg+LaOMVb4NDDIHCBGN8ut+IbA5JiC?= =?us-ascii?Q?qnox8stXmNE345zVJEAgoL1wv21i2HTR9lLdZlI2C/rONPIeldcwtu60bahC?= =?us-ascii?Q?xpiJonbOFxm3pLiKNUh5TVUirD3Rvwz+FqBX9MzOE3OxG8ln2nHlHAbOoee/?= =?us-ascii?Q?HwWOqgu0Ii6n4CBFj7vfotT7u+42zFc7yJWEWBzPFYTkvP57HB681DRY5cps?= =?us-ascii?Q?nWAnci/nzcEMPeS7IrqyA3oK5mLK+HEo7XvOfFyOnV3Xr/TtinUpQvOpUDlu?= =?us-ascii?Q?EPcMkA=3D=3D?= 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)(36860700013)(1800799024)(7416014)(376014)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Jan 2026 11:28:17.4033 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2accfab3-f5ad-420f-4c80-08de5e605566 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: BN1PEPF00004682.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB8123 Content-Type: text/plain; charset="utf-8" From: Cosmin Ratiu Upcoming changes to the rate commands need the parent devlink specified. This change adds a nested 'parent-dev' attribute to the API and helpers to obtain and put a reference to the parent devlink instance in info->user_ptr[1]. To avoid deadlocks, the parent devlink is unlocked before obtaining the main devlink instance that is the target of the request. A reference to the parent is kept until the end of the request to avoid it suddenly disappearing. This means that this reference is of limited use without additional protection. Signed-off-by: Cosmin Ratiu Reviewed-by: Carolina Jubran Reviewed-by: Jiri Pirko Signed-off-by: Tariq Toukan --- Documentation/netlink/specs/devlink.yaml | 12 ++++++ include/uapi/linux/devlink.h | 2 + net/devlink/devl_internal.h | 2 + net/devlink/netlink.c | 51 +++++++++++++++++++++--- 4 files changed, 62 insertions(+), 5 deletions(-) diff --git a/Documentation/netlink/specs/devlink.yaml b/Documentation/netli= nk/specs/devlink.yaml index 837112da6738..a8fd0a815c0d 100644 --- a/Documentation/netlink/specs/devlink.yaml +++ b/Documentation/netlink/specs/devlink.yaml @@ -867,6 +867,10 @@ attribute-sets: type: flag doc: Request restoring parameter to its default value. value: 183 + + - name: parent-dev + type: nest + nested-attributes: dl-parent-dev - name: dl-dev-stats subset-of: devlink @@ -1289,6 +1293,14 @@ attribute-sets: Specifies the bandwidth share assigned to the Traffic Class. The bandwidth for the traffic class is determined in proportion to the sum of the shares of all configured clas= ses. + - + name: dl-parent-dev + subset-of: devlink + attributes: + - + name: bus-name + - + name: dev-name =20 operations: enum-model: directional diff --git a/include/uapi/linux/devlink.h b/include/uapi/linux/devlink.h index e7d6b6d13470..94b8a4437bac 100644 --- a/include/uapi/linux/devlink.h +++ b/include/uapi/linux/devlink.h @@ -642,6 +642,8 @@ enum devlink_attr { DEVLINK_ATTR_PARAM_VALUE_DEFAULT, /* dynamic */ DEVLINK_ATTR_PARAM_RESET_DEFAULT, /* flag */ =20 + DEVLINK_ATTR_PARENT_DEV, /* nested */ + /* Add new attributes above here, update the spec in * Documentation/netlink/specs/devlink.yaml and re-generate * net/devlink/netlink_gen.c. diff --git a/net/devlink/devl_internal.h b/net/devlink/devl_internal.h index 8374c9cab6ce..3ca4cc8517cd 100644 --- a/net/devlink/devl_internal.h +++ b/net/devlink/devl_internal.h @@ -162,6 +162,8 @@ typedef int devlink_nl_dump_one_func_t(struct sk_buff *= msg, struct devlink * devlink_get_from_attrs_lock(struct net *net, struct nlattr **attrs, bool dev_lock); +struct devlink * +devlink_get_parent_from_attrs_lock(struct net *net, struct nlattr **attrs); =20 int devlink_nl_dumpit(struct sk_buff *msg, struct netlink_callback *cb, devlink_nl_dump_one_func_t *dump_one); diff --git a/net/devlink/netlink.c b/net/devlink/netlink.c index 593605c1b1ef..72897b19c372 100644 --- a/net/devlink/netlink.c +++ b/net/devlink/netlink.c @@ -12,6 +12,7 @@ #define DEVLINK_NL_FLAG_NEED_PORT BIT(0) #define DEVLINK_NL_FLAG_NEED_DEVLINK_OR_PORT BIT(1) #define DEVLINK_NL_FLAG_NEED_DEV_LOCK BIT(2) +#define DEVLINK_NL_FLAG_OPTIONAL_PARENT_DEV BIT(3) =20 static const struct genl_multicast_group devlink_nl_mcgrps[] =3D { [DEVLINK_MCGRP_CONFIG] =3D { .name =3D DEVLINK_GENL_MCGRP_CONFIG_NAME }, @@ -206,19 +207,51 @@ devlink_get_from_attrs_lock(struct net *net, struct n= lattr **attrs, return ERR_PTR(-ENODEV); } =20 +struct devlink * +devlink_get_parent_from_attrs_lock(struct net *net, struct nlattr **attrs) +{ + struct nlattr *tb[DEVLINK_ATTR_DEV_NAME + 1]; + int err; + + if (!attrs[DEVLINK_ATTR_PARENT_DEV]) + return ERR_PTR(-EINVAL); + + err =3D nla_parse_nested(tb, DEVLINK_ATTR_DEV_NAME, + attrs[DEVLINK_ATTR_PARENT_DEV], + NULL, NULL); + if (err) + return ERR_PTR(err); + + return devlink_get_from_attrs_lock(net, tb, false); +} + static int __devlink_nl_pre_doit(struct sk_buff *skb, struct genl_info *in= fo, u8 flags) { + bool parent_dev =3D flags & DEVLINK_NL_FLAG_OPTIONAL_PARENT_DEV; bool dev_lock =3D flags & DEVLINK_NL_FLAG_NEED_DEV_LOCK; + struct devlink *devlink, *parent_devlink =3D NULL; + struct net *net =3D genl_info_net(info); + struct nlattr **attrs =3D info->attrs; struct devlink_port *devlink_port; - struct devlink *devlink; int err; =20 - devlink =3D devlink_get_from_attrs_lock(genl_info_net(info), info->attrs, - dev_lock); - if (IS_ERR(devlink)) - return PTR_ERR(devlink); + if (parent_dev && attrs[DEVLINK_ATTR_PARENT_DEV]) { + parent_devlink =3D devlink_get_parent_from_attrs_lock(net, attrs); + if (IS_ERR(parent_devlink)) + return PTR_ERR(parent_devlink); + info->user_ptr[1] =3D parent_devlink; + /* Drop the parent devlink lock but don't release the reference. + * This will keep it alive until the end of the request. + */ + devl_unlock(parent_devlink); + } =20 + devlink =3D devlink_get_from_attrs_lock(net, attrs, dev_lock); + if (IS_ERR(devlink)) { + err =3D PTR_ERR(devlink); + goto parent_put; + } info->user_ptr[0] =3D devlink; if (flags & DEVLINK_NL_FLAG_NEED_PORT) { devlink_port =3D devlink_port_get_from_info(devlink, info); @@ -237,6 +270,9 @@ static int __devlink_nl_pre_doit(struct sk_buff *skb, s= truct genl_info *info, unlock: devl_dev_unlock(devlink, dev_lock); devlink_put(devlink); +parent_put: + if (parent_dev && parent_devlink) + devlink_put(parent_devlink); return err; } =20 @@ -274,6 +310,11 @@ static void __devlink_nl_post_doit(struct sk_buff *skb= , struct genl_info *info, devlink =3D info->user_ptr[0]; devl_dev_unlock(devlink, dev_lock); devlink_put(devlink); + if ((flags & DEVLINK_NL_FLAG_OPTIONAL_PARENT_DEV) && + info->user_ptr[1]) { + devlink =3D info->user_ptr[1]; + devlink_put(devlink); + } } =20 void devlink_nl_post_doit(const struct genl_split_ops *ops, --=20 2.44.0 From nobody Sat Feb 7 17:09:28 2026 Received: from BYAPR05CU005.outbound.protection.outlook.com (mail-westusazon11010061.outbound.protection.outlook.com [52.101.85.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AC28934E761; Wed, 28 Jan 2026 11:28:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.85.61 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769599710; cv=fail; b=luwYF8YPV2imXUnw2ODzQk6Kh9+jU2D2F8jS3WS/6uwtcgXAr/RNd0lNEkP+rOuiEkqqtVUyKCvftVMo9OxdH13KGsvaMFLwqQ26IEIaGSoSfZZTZjwhMJttqNHb+u3ehVmqwqpAZ8DLnwgjqkuNsAsXNuaMLnzAXKxbgCr4dho= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769599710; c=relaxed/simple; bh=CTDZfTiXyxvw6Qi971Y0UNZxHZPJDxdrDC+WW3Xcd74=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=dW4sx9Rqhmpa34nAAk5Efis8YWuZvO1jaTFT3AerNhbLuxvqzU8UXW0yt8BmPpGehkFnKX3Gb9FfxJRvWg+Hislj1u9qU0bz/wu0yFzTW5dfAi4fsBh3F/3AnGeuN3AOx0zr1F3DUnfgwCkU6qv/JQhGI36ZciXd7CQbB1oxvno= 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=SucVZX3U; arc=fail smtp.client-ip=52.101.85.61 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="SucVZX3U" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=OFEeE8EhiXXiXcYM+BanIwYDTCCyKRtGAgfXsVXAJsc+upuuXc/GZ2VeflZbzkhzT9n7qpo5xzcsvlxFQO7M16MM0IcF5HPxsoKPr1qUmZDGDSPRS+0t1XqTonXEoiT+rL74mUJn9hpKT+vKQjfoYDY3jyqL1U1+KTaWfcPY99NyeC8kUxfNA415YGheCjuAx/6e16RX++YQjtjs1rbf1ytUVXxu3b8iDC5ss7g0Z1+jhAoRoh76s0l5+I8X0boN7hpVsYwwqasDJRjsh0d0aL7hlH7DaMqufmvtvJ/WtzAm/ris/4TjLV8Jomd9n8/Glzbh3r05wHiqabkhAvU2zg== 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=yBGV6UmqcE9JfxNh53yF/0VNqem8tkyC31UNBH614XM=; b=oPFClghigE7B+0mSukWX4u8HjEh9RTwY/FC7kxU66h7sqgHq9eTCq0+4qXqZ0Qsg4O5Umsu0esd758+ma8ZCz9dRb0qoQr96BIYc8qXDrTm+dJ05hI+1WJfPZzWe+VUqA7FgVch41OwsGPH1rTuVL6euSaX2hGqwkG4b/VJnUa0RkSwrSweDudehr3Fj7XfGFTFc4jBze65YS3JlI331KE7fkHzCsEfWJnR4m9NnvRqERK5hz07k41T8PaPub661t3GRLBG6RJPOxJvE32VakyZ9dFtDaj7pUAsBto8h2DpOgAHraK8IRgknkPMynUWMKP8IUCbtFk7R6x8lscxmsw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=google.com 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=yBGV6UmqcE9JfxNh53yF/0VNqem8tkyC31UNBH614XM=; b=SucVZX3Un6pPrmplPVhVNXWqv8iHN3J1T3IPM4vMhuGyG1YAvTOL9zbUKA2T8+D6uWAUQGjxUIHGJnJ2w2Ul6NOwmEEpBA9RhqzkdySnLFydXPqQl9sKg+t42Qq5xDmpc1HcZexkjbr4ymBQqkc2HSYmKnwNCrp4IU1JvWjuuf53jr7PiYJJpA/bwSkvvtS0c+foMHNqeBRiQh75tY1p5iyNwV3kxYQd8oWxxNDoRU4vOdcGgCydGh2Xn341eW0NGTQ0B0ucPZAbRKJ4nhACsH8HJZAS+J1Qt0BNsqnT4wzzYnIRPyNcEgdROYdfQacPk+aQGHFkp1qxZVekhWrb+A== Received: from BN9PR03CA0741.namprd03.prod.outlook.com (2603:10b6:408:110::26) by CY3PR12MB9553.namprd12.prod.outlook.com (2603:10b6:930:109::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9542.15; Wed, 28 Jan 2026 11:28:23 +0000 Received: from BN1PEPF00004686.namprd03.prod.outlook.com (2603:10b6:408:110:cafe::b8) by BN9PR03CA0741.outlook.office365.com (2603:10b6:408:110::26) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9564.7 via Frontend Transport; Wed, 28 Jan 2026 11:28:23 +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 BN1PEPF00004686.mail.protection.outlook.com (10.167.243.91) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9564.3 via Frontend Transport; Wed, 28 Jan 2026 11:28:23 +0000 Received: from rnnvmail204.nvidia.com (10.129.68.6) 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.20; Wed, 28 Jan 2026 03:28:12 -0800 Received: from rnnvmail205.nvidia.com (10.129.68.10) by rnnvmail204.nvidia.com (10.129.68.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.20; Wed, 28 Jan 2026 03:28:12 -0800 Received: from vdi.nvidia.com (10.127.8.10) by mail.nvidia.com (10.129.68.10) with Microsoft SMTP Server id 15.2.2562.20 via Frontend Transport; Wed, 28 Jan 2026 03:28:06 -0800 From: Tariq Toukan To: Eric Dumazet , Jakub Kicinski , Paolo Abeni , Andrew Lunn , "David S. Miller" CC: Donald Hunter , Jiri Pirko , Jonathan Corbet , Saeed Mahameed , "Leon Romanovsky" , Tariq Toukan , Mark Bloch , , , , , Gal Pressman , Moshe Shemesh , Carolina Jubran , Cosmin Ratiu , Jiri Pirko , Randy Dunlap , Simon Horman , Krzysztof Kozlowski Subject: [PATCH net-next V7 08/14] devlink: Allow parent dev for rate-set and rate-new Date: Wed, 28 Jan 2026 13:25:38 +0200 Message-ID: <20260128112544.1661250-9-tariqt@nvidia.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20260128112544.1661250-1-tariqt@nvidia.com> References: <20260128112544.1661250-1-tariqt@nvidia.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN1PEPF00004686:EE_|CY3PR12MB9553:EE_ X-MS-Office365-Filtering-Correlation-Id: 75ee3829-1154-485b-b0ab-08de5e6058be X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|1800799024|376014|7416014|36860700013; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?v0q6WmzDl+v+2+3zNNNdFOM5D/ohMzxh/43in3xqwO0gobFBErdioS4gV3oP?= =?us-ascii?Q?JSpmeR8DuXI4peVZPTfFKQzr1Gp8zlvUp9oMAaSGYdENKchY9e+lsF65xaWM?= =?us-ascii?Q?0cYl9XH7PM610+GtVQvnLc7KI8gq/NEN3eiRsVdEXgsBze2kUz54j8lu/AAK?= =?us-ascii?Q?vTaPl1unEyhKNWRyByk94uNEg+Jl8gwwjxlcOLGnGNGihw8/3a4THHBYXtuc?= =?us-ascii?Q?GhbXHLcfwZa4JOtKmMBOcTeNsBUAyu0QCriq1jhZSInbtjUMVr0FrNd3m48W?= =?us-ascii?Q?WklBwwLSR/jX0rPqBkSSZr6VCpckGZdf38astIe3Y7iuIPoujZZuTVSsersI?= =?us-ascii?Q?Lu6euNMtHIfZZ0Erw7FNa3tztNgjmyuQf40zY4NGFKdhVoiMgyjcKAfZUqQb?= =?us-ascii?Q?ci+u2pGutiBMuLWxESAyW3QuOySICiR1hju/Ui3utRxZXN0fkN1+QKSMC+qU?= =?us-ascii?Q?BINtB0Gwc4Q4Kh4+OZa0m9QWnMYOUZRdiTRU9UvM3boP/i/6t9+AaWuXatt8?= =?us-ascii?Q?dfdfDG1JMNcPlTYqGcHTnd9f3byMKjSAto95FfYwFNlmXU89JElfR9IMHJVn?= =?us-ascii?Q?MdBclfijGqBIb2tl7P9k46POIAZHTf9vU2R2OytYxcQINyXTYznFoCsLFXyc?= =?us-ascii?Q?ProS8avW6yAPqBb+BMVzPf1Q0nxlxxrUZibbUpc4AVQmK3ezXMKog+Mg2iZB?= =?us-ascii?Q?AJ4TCIHUbZ8P8706OsA6TSeH8iCKhGElDkfOxZ88Ay11dAItZIUWgHYICka8?= =?us-ascii?Q?QFtEIyHNOWMeMCgfxrSn+Fb7qmCtc7UxPG12GoTa9eIiJSeUuVPKS6VqEUjN?= =?us-ascii?Q?meF2D5nUX3Y7qIW7iTdUU8I/aevbd0alvFVtGAV+Mkxf7ZYybxm1HJW30BcH?= =?us-ascii?Q?7YwgXxvZ0s1OZLLO0Pu7MgCiKk3/0URECuFnAD3gbC83ur5+TnbFOAITp0s3?= =?us-ascii?Q?1jdjf6BwaH3gq6tVdJ42SKcZisq4EPLR4DcsPHakueJPtYmrME6yJKjjO09+?= =?us-ascii?Q?yWW+rydtuS8CNmtB0ml4ECMH+ti6QtY+PHKUfb5/o2d9H3CtzqtLbgrV9tE4?= =?us-ascii?Q?U5HLIv+rf0OAKrNv0i1iLgm7ZFRMTK6U3b7gjk3YFVqr2hv6FafN6vGZ1RaW?= =?us-ascii?Q?EgIlSLuns2Uz1c6zHaZOwbL/UDsDrBrBcpL3ITC9NWs/tFDq+ptJZdDjKJCr?= =?us-ascii?Q?MwDmynG+76dhXE20pMLLd1tGOrlo4hCwGpCU6GR45JI+5TBG2bJYmeBwob0s?= =?us-ascii?Q?NGmkt3CKXEgEPWB4wPEPkAwvmVzqqAalLwt648A9MFymp8SlQDZb1FpcHI28?= =?us-ascii?Q?wuJgv/BrfqaUzb99ZOzNkqBDSz4QHCaOcy/6hVx2T9i3Av+geZtLhIGZ5+lD?= =?us-ascii?Q?2ICIONr/cDThCsw2aa5RNBQ7CdHoxxWAO5WE3dcIgVAcCJdmMfZXv74zR7Iq?= =?us-ascii?Q?WVumIvIYECxE92BDjuamOWtc+/cLvNgorQ24lZuZKPh283lDSflmGgskzcPH?= =?us-ascii?Q?yysIKfzqy/2QwLmAInCya4aQ4TeekfW/AJfJni1C+/x4yRMuw0w3QvM9/wF0?= =?us-ascii?Q?MMlkpoZWeYX9VDYB6R+BbMso83O3Qxvfb7CGEnaeLRXcmmbhMeN+x/PwkJv9?= =?us-ascii?Q?bZx7lysV3q+4ftBvHst4bSUrqtweGGqXsEeAJU9lQxSBpv7rgzSN54WuvDR2?= =?us-ascii?Q?3/CRZQ=3D=3D?= X-Forefront-Antispam-Report: CIP:216.228.117.161;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge2.nvidia.com;CAT:NONE;SFS:(13230040)(82310400026)(1800799024)(376014)(7416014)(36860700013);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Jan 2026 11:28:23.0120 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 75ee3829-1154-485b-b0ab-08de5e6058be 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: BN1PEPF00004686.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY3PR12MB9553 Content-Type: text/plain; charset="utf-8" From: Cosmin Ratiu Currently, a devlink rate's parent device is assumed to be the same as the one where the devlink rate is created. This patch changes that to allow rate commands to accept an additional argument that specifies the parent dev. This will allow devlink rate groups with leafs from other devices. Example of the new usage with ynl: Creating a group on pci/0000:08:00.1 with a parent to an already existing pci/0000:08:00.1/group1: ./tools/net/ynl/pyynl/cli.py --spec \ Documentation/netlink/specs/devlink.yaml --do rate-new --json '{ "bus-name": "pci", "dev-name": "0000:08:00.1", "rate-node-name": "group2", "rate-parent-node-name": "group1", "parent-dev": { "bus-name": "pci", "dev-name": "0000:08:00.1" } }' Setting the parent of leaf node pci/0000:08:00.1/65537 to pci/0000:08:00.0/group1: ./tools/net/ynl/pyynl/cli.py --spec \ Documentation/netlink/specs/devlink.yaml --do rate-set --json '{ "bus-name": "pci", "dev-name": "0000:08:00.1", "port-index": 65537, "parent-dev": { "bus-name": "pci", "dev-name": "0000:08:00.0" }, "rate-parent-node-name": "group1" }' Signed-off-by: Cosmin Ratiu Reviewed-by: Carolina Jubran Reviewed-by: Jiri Pirko Signed-off-by: Tariq Toukan --- Documentation/netlink/specs/devlink.yaml | 10 ++++++---- net/devlink/netlink.c | 18 +++++++++++++++++- net/devlink/netlink_gen.c | 23 +++++++++++++++-------- net/devlink/netlink_gen.h | 8 ++++++++ 4 files changed, 46 insertions(+), 13 deletions(-) diff --git a/Documentation/netlink/specs/devlink.yaml b/Documentation/netli= nk/specs/devlink.yaml index a8fd0a815c0d..c81c467f144f 100644 --- a/Documentation/netlink/specs/devlink.yaml +++ b/Documentation/netlink/specs/devlink.yaml @@ -2218,8 +2218,8 @@ operations: dont-validate: [strict] flags: [admin-perm] do: - pre: devlink-nl-pre-doit - post: devlink-nl-post-doit + pre: devlink-nl-pre-doit-parent-dev-optional + post: devlink-nl-post-doit-parent-dev-optional request: attributes: - bus-name @@ -2231,6 +2231,7 @@ operations: - rate-tx-weight - rate-parent-node-name - rate-tc-bws + - parent-dev =20 - name: rate-new @@ -2239,8 +2240,8 @@ operations: dont-validate: [strict] flags: [admin-perm] do: - pre: devlink-nl-pre-doit - post: devlink-nl-post-doit + pre: devlink-nl-pre-doit-parent-dev-optional + post: devlink-nl-post-doit-parent-dev-optional request: attributes: - bus-name @@ -2252,6 +2253,7 @@ operations: - rate-tx-weight - rate-parent-node-name - rate-tc-bws + - parent-dev =20 - name: rate-del diff --git a/net/devlink/netlink.c b/net/devlink/netlink.c index 72897b19c372..781758b8632c 100644 --- a/net/devlink/netlink.c +++ b/net/devlink/netlink.c @@ -218,7 +218,7 @@ devlink_get_parent_from_attrs_lock(struct net *net, str= uct nlattr **attrs) =20 err =3D nla_parse_nested(tb, DEVLINK_ATTR_DEV_NAME, attrs[DEVLINK_ATTR_PARENT_DEV], - NULL, NULL); + devlink_dl_parent_dev_nl_policy, NULL); if (err) return ERR_PTR(err); =20 @@ -301,6 +301,14 @@ int devlink_nl_pre_doit_port_optional(const struct gen= l_split_ops *ops, return __devlink_nl_pre_doit(skb, info, DEVLINK_NL_FLAG_NEED_DEVLINK_OR_P= ORT); } =20 +int devlink_nl_pre_doit_parent_dev_optional(const struct genl_split_ops *o= ps, + struct sk_buff *skb, + struct genl_info *info) +{ + return __devlink_nl_pre_doit(skb, info, + DEVLINK_NL_FLAG_OPTIONAL_PARENT_DEV); +} + static void __devlink_nl_post_doit(struct sk_buff *skb, struct genl_info *= info, u8 flags) { @@ -330,6 +338,14 @@ devlink_nl_post_doit_dev_lock(const struct genl_split_= ops *ops, __devlink_nl_post_doit(skb, info, DEVLINK_NL_FLAG_NEED_DEV_LOCK); } =20 +void +devlink_nl_post_doit_parent_dev_optional(const struct genl_split_ops *ops, + struct sk_buff *skb, + struct genl_info *info) +{ + __devlink_nl_post_doit(skb, info, DEVLINK_NL_FLAG_OPTIONAL_PARENT_DEV); +} + static int devlink_nl_inst_single_dumpit(struct sk_buff *msg, struct netlink_callback *cb, int flags, devlink_nl_dump_one_func_t *dump_one, diff --git a/net/devlink/netlink_gen.c b/net/devlink/netlink_gen.c index f4c61c2b4f22..f82656d6d7c1 100644 --- a/net/devlink/netlink_gen.c +++ b/net/devlink/netlink_gen.c @@ -39,6 +39,11 @@ devlink_attr_param_type_validate(const struct nlattr *at= tr, } =20 /* Common nested types */ +const struct nla_policy devlink_dl_parent_dev_nl_policy[DEVLINK_ATTR_DEV_N= AME + 1] =3D { + [DEVLINK_ATTR_BUS_NAME] =3D { .type =3D NLA_NUL_STRING, }, + [DEVLINK_ATTR_DEV_NAME] =3D { .type =3D NLA_NUL_STRING, }, +}; + const struct nla_policy devlink_dl_port_function_nl_policy[DEVLINK_PORT_FN= _ATTR_CAPS + 1] =3D { [DEVLINK_PORT_FUNCTION_ATTR_HW_ADDR] =3D { .type =3D NLA_BINARY, }, [DEVLINK_PORT_FN_ATTR_STATE] =3D NLA_POLICY_MAX(NLA_U8, 1), @@ -531,7 +536,7 @@ static const struct nla_policy devlink_rate_get_dump_nl= _policy[DEVLINK_ATTR_DEV_ }; =20 /* DEVLINK_CMD_RATE_SET - do */ -static const struct nla_policy devlink_rate_set_nl_policy[DEVLINK_ATTR_RAT= E_TC_BWS + 1] =3D { +static const struct nla_policy devlink_rate_set_nl_policy[DEVLINK_ATTR_PAR= ENT_DEV + 1] =3D { [DEVLINK_ATTR_BUS_NAME] =3D { .type =3D NLA_NUL_STRING, }, [DEVLINK_ATTR_DEV_NAME] =3D { .type =3D NLA_NUL_STRING, }, [DEVLINK_ATTR_RATE_NODE_NAME] =3D { .type =3D NLA_NUL_STRING, }, @@ -541,10 +546,11 @@ static const struct nla_policy devlink_rate_set_nl_po= licy[DEVLINK_ATTR_RATE_TC_B [DEVLINK_ATTR_RATE_TX_WEIGHT] =3D { .type =3D NLA_U32, }, [DEVLINK_ATTR_RATE_PARENT_NODE_NAME] =3D { .type =3D NLA_NUL_STRING, }, [DEVLINK_ATTR_RATE_TC_BWS] =3D NLA_POLICY_NESTED(devlink_dl_rate_tc_bws_n= l_policy), + [DEVLINK_ATTR_PARENT_DEV] =3D NLA_POLICY_NESTED(devlink_dl_parent_dev_nl_= policy), }; =20 /* DEVLINK_CMD_RATE_NEW - do */ -static const struct nla_policy devlink_rate_new_nl_policy[DEVLINK_ATTR_RAT= E_TC_BWS + 1] =3D { +static const struct nla_policy devlink_rate_new_nl_policy[DEVLINK_ATTR_PAR= ENT_DEV + 1] =3D { [DEVLINK_ATTR_BUS_NAME] =3D { .type =3D NLA_NUL_STRING, }, [DEVLINK_ATTR_DEV_NAME] =3D { .type =3D NLA_NUL_STRING, }, [DEVLINK_ATTR_RATE_NODE_NAME] =3D { .type =3D NLA_NUL_STRING, }, @@ -554,6 +560,7 @@ static const struct nla_policy devlink_rate_new_nl_poli= cy[DEVLINK_ATTR_RATE_TC_B [DEVLINK_ATTR_RATE_TX_WEIGHT] =3D { .type =3D NLA_U32, }, [DEVLINK_ATTR_RATE_PARENT_NODE_NAME] =3D { .type =3D NLA_NUL_STRING, }, [DEVLINK_ATTR_RATE_TC_BWS] =3D NLA_POLICY_NESTED(devlink_dl_rate_tc_bws_n= l_policy), + [DEVLINK_ATTR_PARENT_DEV] =3D NLA_POLICY_NESTED(devlink_dl_parent_dev_nl_= policy), }; =20 /* DEVLINK_CMD_RATE_DEL - do */ @@ -1197,21 +1204,21 @@ const struct genl_split_ops devlink_nl_ops[74] =3D { { .cmd =3D DEVLINK_CMD_RATE_SET, .validate =3D GENL_DONT_VALIDATE_STRICT, - .pre_doit =3D devlink_nl_pre_doit, + .pre_doit =3D devlink_nl_pre_doit_parent_dev_optional, .doit =3D devlink_nl_rate_set_doit, - .post_doit =3D devlink_nl_post_doit, + .post_doit =3D devlink_nl_post_doit_parent_dev_optional, .policy =3D devlink_rate_set_nl_policy, - .maxattr =3D DEVLINK_ATTR_RATE_TC_BWS, + .maxattr =3D DEVLINK_ATTR_PARENT_DEV, .flags =3D GENL_ADMIN_PERM | GENL_CMD_CAP_DO, }, { .cmd =3D DEVLINK_CMD_RATE_NEW, .validate =3D GENL_DONT_VALIDATE_STRICT, - .pre_doit =3D devlink_nl_pre_doit, + .pre_doit =3D devlink_nl_pre_doit_parent_dev_optional, .doit =3D devlink_nl_rate_new_doit, - .post_doit =3D devlink_nl_post_doit, + .post_doit =3D devlink_nl_post_doit_parent_dev_optional, .policy =3D devlink_rate_new_nl_policy, - .maxattr =3D DEVLINK_ATTR_RATE_TC_BWS, + .maxattr =3D DEVLINK_ATTR_PARENT_DEV, .flags =3D GENL_ADMIN_PERM | GENL_CMD_CAP_DO, }, { diff --git a/net/devlink/netlink_gen.h b/net/devlink/netlink_gen.h index 2817d53a0eba..d4db82a00522 100644 --- a/net/devlink/netlink_gen.h +++ b/net/devlink/netlink_gen.h @@ -13,6 +13,7 @@ #include =20 /* Common nested types */ +extern const struct nla_policy devlink_dl_parent_dev_nl_policy[DEVLINK_ATT= R_DEV_NAME + 1]; extern const struct nla_policy devlink_dl_port_function_nl_policy[DEVLINK_= PORT_FN_ATTR_CAPS + 1]; extern const struct nla_policy devlink_dl_rate_tc_bws_nl_policy[DEVLINK_RA= TE_TC_ATTR_BW + 1]; extern const struct nla_policy devlink_dl_selftest_id_nl_policy[DEVLINK_AT= TR_SELFTEST_ID_FLASH + 1]; @@ -29,12 +30,19 @@ int devlink_nl_pre_doit_dev_lock(const struct genl_spli= t_ops *ops, int devlink_nl_pre_doit_port_optional(const struct genl_split_ops *ops, struct sk_buff *skb, struct genl_info *info); +int devlink_nl_pre_doit_parent_dev_optional(const struct genl_split_ops *o= ps, + struct sk_buff *skb, + struct genl_info *info); void devlink_nl_post_doit(const struct genl_split_ops *ops, struct sk_buff *skb, struct genl_info *info); void devlink_nl_post_doit_dev_lock(const struct genl_split_ops *ops, struct sk_buff *skb, struct genl_info *info); +void +devlink_nl_post_doit_parent_dev_optional(const struct genl_split_ops *ops, + struct sk_buff *skb, + struct genl_info *info); =20 int devlink_nl_get_doit(struct sk_buff *skb, struct genl_info *info); int devlink_nl_get_dumpit(struct sk_buff *skb, struct netlink_callback *cb= ); --=20 2.44.0 From nobody Sat Feb 7 17:09:28 2026 Received: from BYAPR05CU005.outbound.protection.outlook.com (mail-westusazon11010064.outbound.protection.outlook.com [52.101.85.64]) (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 0010434FF6E; Wed, 28 Jan 2026 11:28:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.85.64 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769599720; cv=fail; b=RS0WwVHc7vgHWQI3CdrN8Ss+14rz4jj3Me3rvTeSIKUXmLj6NrpHiNtvR+bA0jxfSLHf01Jcz+eqmrHiQ5zPo3NvKTcGkyazsse5JRnSvugW+nZNuDiSicXObUVq8ISgfZAY9+ev5yat4SOPtlpTevNzpykbryBifjvf7OFOlqE= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769599720; c=relaxed/simple; bh=4X6OkJyt+De/hVz8lRlvSbUTEnGp07r1/E4Ydj77YHc=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=fzxwq3XzLnRnLjMc+xV5KqoyKCTh/wFnTDUzQtNBk+I7wECu2EZivteLIu1pIrdAEf2bobr6+H99lZIfcDwDQctrTJcPjn4SoTauId5nt+zu9QLFa6iebYsRuC8xtKNGRkkxbPHIVUpLzgZj2QDMVkgfP0b8untBXcDGC3fL9oE= 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=b2Aj4SSc; arc=fail smtp.client-ip=52.101.85.64 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="b2Aj4SSc" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=DWQCOO0aB15Q5dkqxuo9mEIyifraDf82m5lOGripSpFxPvpXVilB7mbZZKb8bMS3TvYjkLlwtrmtn1WB6qv0vz2+FMqFPw8g0mpOOc1oz/I69qxUGEhrVISuyOBtHUvZqMQtospB7E4qX9gZ9EaaiEUluhXgUEQ4KDpODbCurZPiJD/O9xr3snpLHIjG67yQlrJvZSX5b2kUSGzvEtSJCpQeaT4KL+jM8+9pWaQLnJpKTP0PQsLrA7kQkFhVJQQAS3KiEeTzpqKUnrpNXmpsLN9ru0zz0RkNotM5iL/5UQa6Xu3g6jw9rpLEK30SIr1VrtsJqP5Yfp2sEdsaLT/Frg== 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=nzYnVCMchYKOXWRsLJpQwZ7oAnHawQ3pC1zQfBKWudQ=; b=k3mxUH5QVN1kCU+UpgUtbrTeDkPrR263oPkPOEuFj7DUFjJejMSnNfWwzY85jryFOKMJ8i29V/sFQLgf9WATvcz0xXZTMJf5AeOSsVUrnSVLr+L0nDCCwEcz2mxxBlBvMGou85mAFoUeMcSjy34llFvrL2LP9j17mx56ZdqjqFreho0hEabyucT86XeUhR6Hn6v6q5O6G76eOYZYxfNzY5srHA5IyW6mX2m/AkpA08aufLar/IvWSfKmooJ8AhbvDfChFIhqLgI6k6idR084BDleQ5/RHoIREcy/Gu+PzKs6F4SL4bOocJiI79zWH9COWob/iyHHtToHd7pskf6/mg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=google.com 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=nzYnVCMchYKOXWRsLJpQwZ7oAnHawQ3pC1zQfBKWudQ=; b=b2Aj4SSc/IrZ+t4HHrrsZ4/PeMl3PdPTxEkc6K9PBTJkL/rrK1W5Ts/364b620+3/fV8up+TWmIpIOSg9gjv/IZNAqhWn5m1iEP5RBhfOialAS01KX4CZ+M77Jf5fRQgev7fHgXEyQWhrJ4uZHemb39rZEcvejmVXY5uf5bx4gK6k6G4G/woC4FJn3heCkygUiQYh0hgZrbBWC2L4sVaU3BcK1sPXGAW8sOn8vD3ejxkDMvW8BqrkO+ENiZr+TO0PnqkWBPV2L/VJZ0bzI5PRc9YR/YCfLaI8BXc343mvZ45u9YrrrgKGWLTz5U25puntNyKRrUim/+IV4V5IqeaVQ== Received: from PH8P221CA0062.NAMP221.PROD.OUTLOOK.COM (2603:10b6:510:349::14) by BY5PR12MB4179.namprd12.prod.outlook.com (2603:10b6:a03:211::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9564.7; Wed, 28 Jan 2026 11:28:30 +0000 Received: from SN1PEPF0002BA4C.namprd03.prod.outlook.com (2603:10b6:510:349:cafe::cf) by PH8P221CA0062.outlook.office365.com (2603:10b6:510:349::14) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9564.8 via Frontend Transport; Wed, 28 Jan 2026 11:28:35 +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 SN1PEPF0002BA4C.mail.protection.outlook.com (10.167.242.69) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9564.3 via Frontend Transport; Wed, 28 Jan 2026 11:28:29 +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.2562.20; Wed, 28 Jan 2026 03:28:18 -0800 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.2562.20; Wed, 28 Jan 2026 03:28:18 -0800 Received: from vdi.nvidia.com (10.127.8.10) by mail.nvidia.com (10.129.68.10) with Microsoft SMTP Server id 15.2.2562.20 via Frontend Transport; Wed, 28 Jan 2026 03:28:12 -0800 From: Tariq Toukan To: Eric Dumazet , Jakub Kicinski , Paolo Abeni , Andrew Lunn , "David S. Miller" CC: Donald Hunter , Jiri Pirko , Jonathan Corbet , Saeed Mahameed , "Leon Romanovsky" , Tariq Toukan , Mark Bloch , , , , , Gal Pressman , Moshe Shemesh , Carolina Jubran , Cosmin Ratiu , Jiri Pirko , Randy Dunlap , Simon Horman , Krzysztof Kozlowski Subject: [PATCH net-next V7 09/14] devlink: Allow rate node parents from other devlinks Date: Wed, 28 Jan 2026 13:25:39 +0200 Message-ID: <20260128112544.1661250-10-tariqt@nvidia.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20260128112544.1661250-1-tariqt@nvidia.com> References: <20260128112544.1661250-1-tariqt@nvidia.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN1PEPF0002BA4C:EE_|BY5PR12MB4179:EE_ X-MS-Office365-Filtering-Correlation-Id: 560eea3b-052e-4680-36f2-08de5e605cbe X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|376014|7416014|36860700013|1800799024; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?CIYVOVugLh3OvM5XdViP2YHdAERNH9wGDtslcgkGtXq5Pjt6dC5vCscgQTOF?= =?us-ascii?Q?fChjBlyugjjsPBp0DPoXiP9/h/R6LvtfF6Wfq1QAgnapNv9fT4izptHfBoq+?= =?us-ascii?Q?RGyYzG5XMY3Mzva3NqNKyWe0D6o8U0jXKE8LI3ACai6Tn+voLtxMq97DYDUw?= =?us-ascii?Q?NMnaEsVa3IC/OgS2XsTzfuUiGkLi6qfYi2Nplew0l04XIBb540lxgwgM2IgV?= =?us-ascii?Q?RwMKenPxBjkbzyvEQKmJo+cIUr1opqyHr+7UgI/cN6l5mbOfd44e4QhuMo+n?= =?us-ascii?Q?xUMVHrgPFglrdO0ZSvWFKb0Y1Ev/ldid6rkP62K7emCviCppf2YHemzx4t3L?= =?us-ascii?Q?JTRICoaJxzTSBZz3cnGX70XvYybzw39OeUQ9EPCyDgJeQAgg9dYvFhiu/YV0?= =?us-ascii?Q?bmUXZ6gBrcWEzheRTCg0K7nE8br6klhM+mbCgyjYW7qm+Y8qDBeeaGPTS5h6?= =?us-ascii?Q?Yi+z3hO88GnSzFNxGm5Uf4e1aNy38Xoc8xOPRlp93MF75A/rDnqptI/31GKa?= =?us-ascii?Q?qPKKIVo1pK8N7wT/sUO/CfcM7dxtdBrDqM8V6zqxapUQ7i63sMbOecrF5SLE?= =?us-ascii?Q?PrGsCw+dOWhrmcaKfzaDXcx9qDaFqAkkYlDvjSZ6u8sFBB8L0gtPOh1Wun36?= =?us-ascii?Q?CFnwWrsuTrDVMeox1TWhHjw6VHYGW9hooUsrT3uDTecsLpL2AAKuaoxlXOum?= =?us-ascii?Q?gbzOQk6Ou3C4u/7qPeKoVNYats1XiqXYa8UUIc9KSpFxyZ8k3XyhrT28ESRF?= =?us-ascii?Q?JK7T5RGsTQ8l/qvtjGmaI+3FxBBPUjvwADphmXd9RP+oT6yaEx8qKQEJek82?= =?us-ascii?Q?qAMTBghLSQUnBqvMgJ630MoEfhefgLVbBEZ6T//EkPQjFT/yJRXtcseY6IT7?= =?us-ascii?Q?cDcG7H7tcE/2Oy8vf8PrZSJr/l4hx+Ngf6hVQrhSANd0pEEGvzH3h+djvm+1?= =?us-ascii?Q?1yFg2ljbuOdTlueNgIF8sq67znaw/4BLJRPMtzp8YprRJZ4ieS+lIZzpJm2Z?= =?us-ascii?Q?nC4VC7Ir89cGT/TSaWQqLuO0BtJJufCvdtVU0gOZLzWLgUl4x/Jm/600r7mo?= =?us-ascii?Q?yAV5OgUDxLZCNr+cgfRWLybxSeCfDEbpBFNOujHM+PDPT2Y6MOcUxm4TfuCP?= =?us-ascii?Q?TSRKQ09xzxqct5JQ3VzYTARz0Qwi+HvcuLVTD8XagfPakPqbBCdBSwwKtfn6?= =?us-ascii?Q?QvLvNfJUWBpO57YWeCNPb6gfizFFga7oaDwXpv/pBrFsHY3YuixUU24DJUrJ?= =?us-ascii?Q?MPxr4PxEswkBCdk/f9ocamBSmoQIOQMqxQhLB1oMSfxHaqzKCMas4E0Zacqb?= =?us-ascii?Q?mPAwyu89vUUIUVSpYD1y6vMMIcI0Bvgyc7PPayKayPCPMFDxZcPqiaE3cKNy?= =?us-ascii?Q?p98efWzKsqPMtEUTZS9QL1MVFmYlF/BgOiTYvWKCaTMyViSE/D9azthKxOF9?= =?us-ascii?Q?Lj3fZCtjzhtOOPx9PVimDL6xG+e3hV06V025HTAtjZpkRwnIuIgwknghOGxL?= =?us-ascii?Q?ekSx6Tuforl6YpG1Ff1eNO43yLT0Dzoa5gS86Djs3jtw8q5NeNKCjQmVTX1+?= =?us-ascii?Q?IC7kdmEEW0bCSY90PXAxIJytRxbJcHvnT0pq+QJhEe9UKfm1GXjTxZCauXZ5?= =?us-ascii?Q?xaxZFLvbgcugUySrLpYyc4dIQeENJ5UoEz/XLGp5Fsfk29nAB2RHOlmKpMhA?= =?us-ascii?Q?3zvHzQ=3D=3D?= X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230040)(82310400026)(376014)(7416014)(36860700013)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Jan 2026 11:28:29.8040 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 560eea3b-052e-4680-36f2-08de5e605cbe 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: SN1PEPF0002BA4C.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB4179 Content-Type: text/plain; charset="utf-8" From: Cosmin Ratiu This commit makes use of the building blocks previously added to implement cross-device rate nodes. A new 'supported_cross_device_rate_nodes' bool is added to devlink_ops which lets drivers advertise support for cross-device rate objects. If enabled and if there is a common shared devlink instance, then: - all rate objects will be stored in the top-most common nested instance and - rate objects can have parents from other devices sharing the same common instance. The parent devlink from info->user_ptr[1] is not locked, so none of its mutable fields can be used. But parent setting only requires comparing devlink pointer comparisons. Additionally, since the shared devlink is locked, other rate operations cannot concurrently happen. The rate lock/unlock functions are now exported, so that drivers implementing this can protect against concurrent modifications on any shared device structures. Signed-off-by: Cosmin Ratiu Reviewed-by: Carolina Jubran Reviewed-by: Jiri Pirko Signed-off-by: Tariq Toukan --- .../networking/devlink/devlink-port.rst | 2 + include/net/devlink.h | 5 + net/devlink/rate.c | 91 +++++++++++++++++-- 3 files changed, 90 insertions(+), 8 deletions(-) diff --git a/Documentation/networking/devlink/devlink-port.rst b/Documentat= ion/networking/devlink/devlink-port.rst index 5e397798a402..976bc5ca0962 100644 --- a/Documentation/networking/devlink/devlink-port.rst +++ b/Documentation/networking/devlink/devlink-port.rst @@ -417,6 +417,8 @@ API allows to configure following rate object's paramet= ers: Parent node name. Parent node rate limits are considered as additional l= imits to all node children limits. ``tx_max`` is an upper limit for children. ``tx_share`` is a total bandwidth distributed among children. + If the device supports cross-function scheduling, the parent can be from= a + different function of the same underlying device. =20 ``tc_bw`` Allow users to set the bandwidth allocation per traffic class on rate diff --git a/include/net/devlink.h b/include/net/devlink.h index fbb434185a67..1165dc1ae165 100644 --- a/include/net/devlink.h +++ b/include/net/devlink.h @@ -1585,6 +1585,11 @@ struct devlink_ops { struct devlink_rate *parent, void *priv_child, void *priv_parent, struct netlink_ext_ack *extack); + /* Indicates if cross-device rate nodes are supported. + * This also requires a shared common ancestor object all devices that + * could share rate nodes are nested in. + */ + bool supported_cross_device_rate_nodes; /** * selftests_check() - queries if selftest is supported * @devlink: devlink instance diff --git a/net/devlink/rate.c b/net/devlink/rate.c index c062fd8a6c36..3d28a4c5bb5f 100644 --- a/net/devlink/rate.c +++ b/net/devlink/rate.c @@ -30,20 +30,56 @@ devlink_rate_leaf_get_from_info(struct devlink *devlink= , struct genl_info *info) return devlink_rate ?: ERR_PTR(-ENODEV); } =20 +/* Repeatedly locks the nested-in devlink instances while cross device rate + * nodes are supported. Returns the devlink instance where rates should be + * stored. + */ struct devlink *devl_rate_lock(struct devlink *devlink) { - return devlink; + struct devlink *rate_devlink =3D devlink; + + while (rate_devlink->ops && + rate_devlink->ops->supported_cross_device_rate_nodes) { + devlink =3D devlink_nested_in_get_lock(rate_devlink->rel); + if (!devlink) + break; + rate_devlink =3D devlink; + } + return rate_devlink; } +EXPORT_SYMBOL_GPL(devl_rate_lock); =20 +/* Variant of the above for when the nested-in devlink instances are alrea= dy + * locked. + */ static struct devlink * devl_get_rate_node_instance_locked(struct devlink *devlink) { - return devlink; + struct devlink *rate_devlink =3D devlink; + + while (rate_devlink->ops && + rate_devlink->ops->supported_cross_device_rate_nodes) { + devlink =3D devlink_nested_in_get_locked(rate_devlink->rel); + if (!devlink) + break; + rate_devlink =3D devlink; + } + return rate_devlink; } =20 +/* Repeatedly unlocks the nested-in devlink instances of 'devlink' while c= ross + * device nodes are supported. + */ void devl_rate_unlock(struct devlink *devlink) { + if (!devlink || !devlink->ops || + !devlink->ops->supported_cross_device_rate_nodes) + return; + + devl_rate_unlock(devlink_nested_in_get_locked(devlink->rel)); + devlink_nested_in_put_unlock(devlink->rel); } +EXPORT_SYMBOL_GPL(devl_rate_unlock); =20 static struct devlink_rate * devlink_rate_node_get_by_name(struct devlink *devlink, const char *node_na= me) @@ -120,6 +156,24 @@ static int devlink_rate_put_tc_bws(struct sk_buff *msg= , u32 *tc_bw) return -EMSGSIZE; } =20 +static int devlink_nl_rate_parent_fill(struct sk_buff *msg, + struct devlink_rate *devlink_rate) +{ + struct devlink_rate *parent =3D devlink_rate->parent; + struct devlink *devlink =3D parent->devlink; + + if (nla_put_string(msg, DEVLINK_ATTR_RATE_PARENT_NODE_NAME, + parent->name)) + return -EMSGSIZE; + + if (devlink !=3D devlink_rate->devlink && + devlink_nl_put_nested_handle(msg, devlink_net(devlink), devlink, + DEVLINK_ATTR_PARENT_DEV)) + return -EMSGSIZE; + + return 0; +} + static int devlink_nl_rate_fill(struct sk_buff *msg, struct devlink_rate *devlink_rate, enum devlink_command cmd, u32 portid, u32 seq, @@ -164,10 +218,9 @@ static int devlink_nl_rate_fill(struct sk_buff *msg, devlink_rate->tx_weight)) goto nla_put_failure; =20 - if (devlink_rate->parent) - if (nla_put_string(msg, DEVLINK_ATTR_RATE_PARENT_NODE_NAME, - devlink_rate->parent->name)) - goto nla_put_failure; + if (devlink_rate->parent && + devlink_nl_rate_parent_fill(msg, devlink_rate)) + goto nla_put_failure; =20 if (devlink_rate_put_tc_bws(msg, devlink_rate->tc_bw)) goto nla_put_failure; @@ -320,13 +373,14 @@ devlink_nl_rate_parent_node_set(struct devlink_rate *= devlink_rate, struct genl_info *info, struct nlattr *nla_parent) { - struct devlink *devlink =3D devlink_rate->devlink; + struct devlink *devlink =3D devlink_rate->devlink, *parent_devlink; const char *parent_name =3D nla_data(nla_parent); const struct devlink_ops *ops =3D devlink->ops; size_t len =3D strlen(parent_name); struct devlink_rate *parent; int err =3D -EOPNOTSUPP; =20 + parent_devlink =3D info->user_ptr[1] ? : devlink; parent =3D devlink_rate->parent; =20 if (parent && !len) { @@ -344,7 +398,13 @@ devlink_nl_rate_parent_node_set(struct devlink_rate *d= evlink_rate, refcount_dec(&parent->refcnt); devlink_rate->parent =3D NULL; } else if (len) { - parent =3D devlink_rate_node_get_by_name(devlink, parent_name); + /* parent_devlink (when different than devlink) isn't locked, + * but the rate node devlink instance is, so nobody from the + * same group of devices sharing rates could change the used + * fields or unregister the parent. + */ + parent =3D devlink_rate_node_get_by_name(parent_devlink, + parent_name); if (IS_ERR(parent)) return -ENODEV; =20 @@ -644,6 +704,14 @@ int devlink_nl_rate_set_doit(struct sk_buff *skb, stru= ct genl_info *info) goto unlock; } =20 + if (info->user_ptr[1] && info->user_ptr[1] !=3D devlink && + !ops->supported_cross_device_rate_nodes) { + NL_SET_ERR_MSG(info->extack, + "Cross-device rate parents aren't supported"); + err =3D -EOPNOTSUPP; + goto unlock; + } + err =3D devlink_nl_rate_set(devlink_rate, ops, info); =20 if (!err) @@ -669,6 +737,13 @@ int devlink_nl_rate_new_doit(struct sk_buff *skb, stru= ct genl_info *info) if (!devlink_rate_set_ops_supported(ops, info, DEVLINK_RATE_TYPE_NODE)) return -EOPNOTSUPP; =20 + if (info->user_ptr[1] && info->user_ptr[1] !=3D devlink && + !ops->supported_cross_device_rate_nodes) { + NL_SET_ERR_MSG(info->extack, + "Cross-device rate parents aren't supported"); + return -EOPNOTSUPP; + } + rate_devlink =3D devl_rate_lock(devlink); rate_node =3D devlink_rate_node_get_from_attrs(devlink, info->attrs); if (!IS_ERR(rate_node)) { --=20 2.44.0 From nobody Sat Feb 7 17:09:28 2026 Received: from CH4PR04CU002.outbound.protection.outlook.com (mail-northcentralusazon11013011.outbound.protection.outlook.com [40.107.201.11]) (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 9AA82352F9C; Wed, 28 Jan 2026 11:28:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.201.11 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769599723; cv=fail; b=ODIRBnBs+RdkTwtBzm1D+br7b3Z70LYje15Y/BdlCdk7DtxFYJGuD9sLWrTHH8Oymf8M4ogCvVTURx4R0ykJV7iWi6/JXFTFI7b1+MTWXrTWqSMZqJlTzyInX4DDbWxFiKntfAuEUdS5B4VxXIptfmXMy3djArfHv/PO8e63mfw= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769599723; c=relaxed/simple; bh=b+OCQkwX72piVb1VU1u4eJGnNQJtFhLSHNZeRr09xHQ=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Zx43GRl85hkAfuMH64NLiSr02QTtLGdPhfKuua0uialkDGfNJZvew+0G4buOpOptVS75dE+84jqQCceDRl4tEKHo2bzInuWescRGTAFWs9hdDsvIVrDMrWFxjYu9WKviHfF7r01MHgbJiBDXbcBEF0s4YzoRSUlHHiYFb1nzwhI= 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=Dh8Zb9v2; arc=fail smtp.client-ip=40.107.201.11 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="Dh8Zb9v2" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=hm9qUcSGJt7zUyzdmdZe9NLsnVCHFtOw4EIG0oYAwe8b5Re8iiDMuAeTllklKYLj/fveZB7LqYSMmNmYSTlMDt3aEX4df6O9EC797UvT3+XeC1IDrcG5gLhpHsyxmcA5WuZSYE/XJ3x2sSfB4mmi6z7ObYkcX02ymUaz4iwDF/IZ6VYn4+Z8ibXUd46Q4cAukkgUzWeYzIiYImGUcSk/SDpjUpzF04pUDAO0TbWzspOZbbGC1m/Zd00vI5YcXE1cuKSCzQCnxZwExs1JmNw32vHl4rDP5curpZXp6d6U6b8rbcz75WynUACkMCv1LEmjzRwy3SQ2AGMSS/EdhL9meg== 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=NU7m8Ucg+3W5NdQZfsk5rmP0GaJLgT/7ypMHaDszIBo=; b=Os1HlWD96ZNQ3LKPymwCMxsKQyBOiUlji0JlMCy2tNWHCYy6FtyBh7/J7fhOKZKqZ46qBKEE6WscqAtejlkl+xpqABT6WyHlx7vfMUGTUztWUawsx1o5YYxHO73MhItREUySqW9t+12EvgMs5KQYPm6hvas4Z8Pm1PCPIa1lZpcrFD7FxUotwz7d+lR23/F+CJp4Q68DIHf6Zj2Tg1LgUga3IhQixUiqv4BdQVSZqOuhlp8Lp/I2jquJKYCIUrhgWiouME4QYrfxy5w5w5v0m4Tv6QLOGyL9MEMxXiGRk0OgNkdcr/W0I3y+LWzBJIic7UeLI3CsZicpHOpbBF3MUA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=google.com 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=NU7m8Ucg+3W5NdQZfsk5rmP0GaJLgT/7ypMHaDszIBo=; b=Dh8Zb9v2e87EdPO140qvfmzarn1gpWiqBHWvPJ3M5CxcRQKbLrc0T19hQK1+SmX5ie5qJyD2xKrOIPY9Dl/Cnxy9mYwBh5/lOLNoz8w+P+Zss4h1M2pRBi4s1QGYVteTNnAtnu2kOiQB2Uu7FCj1sKmaXLB9fpnUKLTMkkl+v7ssGUHo1hrREi/LB0X9er55sgBF8Jr9j4cgOnMIGdE5DFK7FdAHODMbpYErIomigUEUqLWAHHKZa+wob47ky7/cGRxiOjIisCspSE9JA1fvhVgXUUw3rqmz04vJMKrNjHYYSHvO1FQcn4+gHyDJkWDCMADZS0OSlJDM0+bGiF02vg== Received: from PH8P221CA0055.NAMP221.PROD.OUTLOOK.COM (2603:10b6:510:349::8) by SJ5PPF75EAF8F39.namprd12.prod.outlook.com (2603:10b6:a0f:fc02::999) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9542.15; Wed, 28 Jan 2026 11:28:36 +0000 Received: from SN1PEPF0002BA4C.namprd03.prod.outlook.com (2603:10b6:510:349:cafe::1) by PH8P221CA0055.outlook.office365.com (2603:10b6:510:349::8) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9564.8 via Frontend Transport; Wed, 28 Jan 2026 11:28:27 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by SN1PEPF0002BA4C.mail.protection.outlook.com (10.167.242.69) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9564.3 via Frontend Transport; Wed, 28 Jan 2026 11:28:35 +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.2562.20; Wed, 28 Jan 2026 03:28:24 -0800 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.2562.20; Wed, 28 Jan 2026 03:28:24 -0800 Received: from vdi.nvidia.com (10.127.8.10) by mail.nvidia.com (10.129.68.10) with Microsoft SMTP Server id 15.2.2562.20 via Frontend Transport; Wed, 28 Jan 2026 03:28:18 -0800 From: Tariq Toukan To: Eric Dumazet , Jakub Kicinski , Paolo Abeni , Andrew Lunn , "David S. Miller" CC: Donald Hunter , Jiri Pirko , Jonathan Corbet , Saeed Mahameed , "Leon Romanovsky" , Tariq Toukan , Mark Bloch , , , , , Gal Pressman , Moshe Shemesh , Carolina Jubran , Cosmin Ratiu , Jiri Pirko , Randy Dunlap , Simon Horman , Krzysztof Kozlowski Subject: [PATCH net-next V7 10/14] net/mlx5: Add a shared devlink instance for PFs on same chip Date: Wed, 28 Jan 2026 13:25:40 +0200 Message-ID: <20260128112544.1661250-11-tariqt@nvidia.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20260128112544.1661250-1-tariqt@nvidia.com> References: <20260128112544.1661250-1-tariqt@nvidia.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN1PEPF0002BA4C:EE_|SJ5PPF75EAF8F39:EE_ X-MS-Office365-Filtering-Correlation-Id: 516b5b19-04e4-4995-4527-08de5e606067 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|82310400026|376014|7416014|36860700013; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?xZh9GyeL/hGvpSaePPijlWkiIbJUk646jCrvrbs5zMM6Q+qkAQiFZmMT+e6q?= =?us-ascii?Q?W7r47d1vYGFBrc+lIE97xFR15oldUNHESSDVmq40U9WLqFEtyHQMao+9Sl0u?= =?us-ascii?Q?QnrWqjbySnXv0T3pGOSHFhZPIoP2dR/cCTfMjTFD/PMgL+pr7BLijeCHc54n?= =?us-ascii?Q?wW91lc5EiEUl9NyK6esGSCgTJ5l1VtuT4YaqeG2TyAoqBRS72f4tqbb/8LGM?= =?us-ascii?Q?9Ax4GeXQ9llKLhlfG9rSx8Dno8cPKa1Sgzy4N9VJ3eWSmYCZjycrKC2GY+Qb?= =?us-ascii?Q?qrkjJ76f+W4LHUKw7LN6W0Er1ziS/5kSjQ8XntHxS0Znbt0fU3qe+q7ZLoic?= =?us-ascii?Q?TMQfm35vKI/Ltz2f4gM9SCUo+wooutXGnh5VmFitC3KK8Z5wv8X2jZNeUF7s?= =?us-ascii?Q?lCl3s79hGOFSUFVl5nUpYQnvdmLiF3JoPfTQyhEongOlQo7aFtQrdOmXu1vR?= =?us-ascii?Q?3QiVUawSZSb1ct7Sb9aNM7RlPzA1mdS52h+XO63RRVe57rv4LCNOie0hGa2L?= =?us-ascii?Q?8m0lXyjcusG4z8myOW2mjAoaTHL0qRn1ZL5DIgpJhESNf7E05c/yId2IJEYE?= =?us-ascii?Q?YdyOrZcvDARhInKXZZ5JhKCiEYCeMyVjEtKj/eqsXl4sNLNZhWYBPoWJEVYk?= =?us-ascii?Q?QFNw9QnWnu54qqDvHu3zF/cdSdgfsj+LoUgwj2Dv6jtg6dK22kRE7GR3LqC0?= =?us-ascii?Q?7izvmi8vsFK0ugQTUR3s9XvdrEWbFnvCu7W0ygSqZIl2sf1GfS/USLsUfBBD?= =?us-ascii?Q?H9xLvyGfggZdy/R0lMsSMOzapXRCJvBfbpNhEEbEowuNif+gEfc/4Udbpd+h?= =?us-ascii?Q?6lS4R2OwZcsYjTBYkTv5nVRgM/XDTgxytnubTIE6E1G4YI5yK0U4ksfqKjfK?= =?us-ascii?Q?zVyq8bWKHf/v0w7GqkayAHZlRxWrtZeKpMGWKcpOPvIVgvlTB5MpHr6voJHo?= =?us-ascii?Q?tXt91U3UHPDSG5OXJOgvHbm4mrzTvGCXhIeaNI0+knogvNKzM5U80OMRh5aH?= =?us-ascii?Q?YQm6xsZngtXSXradEnCq96dDe7UmChfo+BcnF0IIksSXCU/kzC4bvoTkuWuE?= =?us-ascii?Q?M8gVlwD+5ILTRYPx65tr2gI0pIbbyzPXP/mE7Q0vES78BczZeamLcCjcc1jk?= =?us-ascii?Q?s3TjOxwQXMBybORMYiWFhpfQxL5bpVk8W+e9NMVgwpGrmmc0j6fz8zOZM7jF?= =?us-ascii?Q?FG/Iq8/USWGu/LFo1KPwoZmLz+RQfgu0h4rvJHnDxajA7752dtb9lELVYwbS?= =?us-ascii?Q?sjb4T0c82/aHAasnCkgA33+pldyJaVhfsxG/+cmEXW84OH4u83GuXyxEfY6n?= =?us-ascii?Q?KXgfSER45Xo5A2zVLb2ZwxjMH4LNRLoJ6npLBAPDB/oS4NjwudD34+cndv5n?= =?us-ascii?Q?N5ooRlNzmsQbSm7dCMAPlheYRiSaFX1yIlVYpLOYzBUlscaQp3o5Wt6N9xCB?= =?us-ascii?Q?cywpws9KKax36h8Pl803dlOVkwohBB4hXCUMs4W6mmJ9dL0zQUK/W8wVned6?= =?us-ascii?Q?TC29W0OpaFKTiy+ggcyl2QnnrGDvVRQ/o4n0U5faCJj/shG6/rldG+2jiNAd?= =?us-ascii?Q?3grNzourFnNDPYZJkoEQHhuvOVnWmadIiEkWzBt0aw8u2e7rrtBVwKFA0ny/?= =?us-ascii?Q?hPWsinIUXXLlvv1hWA26hpDsk7t6b05hniBIGgoia9LDptr25Ab8LBQQp45j?= =?us-ascii?Q?k8S6Dw=3D=3D?= X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230040)(1800799024)(82310400026)(376014)(7416014)(36860700013);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Jan 2026 11:28:35.9022 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 516b5b19-04e4-4995-4527-08de5e606067 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: SN1PEPF0002BA4C.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ5PPF75EAF8F39 Content-Type: text/plain; charset="utf-8" From: Jiri Pirko Use the previously introduced shared devlink infrastructure to create a shared devlink instance for mlx5 PFs that reside on the same physical chip. The shared instance is identified by the chip's serial number extracted from PCI VPD (V3 keyword, with fallback to serial number for older devices). Each PF that probes calls mlx5_shd_init() which extracts the chip serial number and uses devlink_shd_get() to get or create the shared instance. When a PF removes, mlx5_shd_uninit() calls devlink_shd_put() to release the reference. The shared instance is automatically destroyed when the last PF removes. Make the PF devlink instances nested in this shared devlink instance, allowing userspace to identify which PFs belong to the same physical chip. Example: $ devlink dev pci/0000:08:00.0: nested_devlink: auxiliary/mlx5_core.eth.0 faux/mlx5_core_83013c12b77faa1a30000c82a1045c91: nested_devlink: pci/0000:08:00.0 pci/0000:08:00.1 auxiliary/mlx5_core.eth.0 pci/0000:08:00.1: nested_devlink: auxiliary/mlx5_core.eth.1 auxiliary/mlx5_core.eth.1 Signed-off-by: Jiri Pirko Reviewed-by: Cosmin Ratiu Signed-off-by: Tariq Toukan --- .../net/ethernet/mellanox/mlx5/core/Makefile | 5 +- .../net/ethernet/mellanox/mlx5/core/main.c | 17 +++++ .../ethernet/mellanox/mlx5/core/sh_devlink.c | 71 +++++++++++++++++++ .../ethernet/mellanox/mlx5/core/sh_devlink.h | 12 ++++ include/linux/mlx5/driver.h | 1 + 5 files changed, 104 insertions(+), 2 deletions(-) create mode 100644 drivers/net/ethernet/mellanox/mlx5/core/sh_devlink.c create mode 100644 drivers/net/ethernet/mellanox/mlx5/core/sh_devlink.h diff --git a/drivers/net/ethernet/mellanox/mlx5/core/Makefile b/drivers/net= /ethernet/mellanox/mlx5/core/Makefile index 8ffa286a18f5..d39fe9c4a87c 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/Makefile +++ b/drivers/net/ethernet/mellanox/mlx5/core/Makefile @@ -16,8 +16,9 @@ mlx5_core-y :=3D main.o cmd.o debugfs.o fw.o eq.o uar.o p= agealloc.o \ transobj.o vport.o sriov.o fs_cmd.o fs_core.o pci_irq.o \ fs_counters.o fs_ft_pool.o rl.o lag/debugfs.o lag/lag.o dev.o events.o w= q.o lib/gid.o \ lib/devcom.o lib/pci_vsc.o lib/dm.o lib/fs_ttc.o diag/fs_tracepoint.o \ - diag/fw_tracer.o diag/crdump.o devlink.o diag/rsc_dump.o diag/reporter_v= nic.o \ - fw_reset.o qos.o lib/tout.o lib/aso.o wc.o fs_pool.o lib/nv_param.o + diag/fw_tracer.o diag/crdump.o devlink.o sh_devlink.o diag/rsc_dump.o \ + diag/reporter_vnic.o fw_reset.o qos.o lib/tout.o lib/aso.o wc.o fs_pool.= o \ + lib/nv_param.o =20 # # Netdev basic diff --git a/drivers/net/ethernet/mellanox/mlx5/core/main.c b/drivers/net/e= thernet/mellanox/mlx5/core/main.c index 4209da722f9a..9cd8361ca00e 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/main.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/main.c @@ -74,6 +74,7 @@ #include "mlx5_irq.h" #include "hwmon.h" #include "lag/lag.h" +#include "sh_devlink.h" =20 MODULE_AUTHOR("Eli Cohen "); MODULE_DESCRIPTION("Mellanox 5th generation network adapters (ConnectX ser= ies) core driver"); @@ -1520,10 +1521,16 @@ int mlx5_init_one(struct mlx5_core_dev *dev) int err; =20 devl_lock(devlink); + if (dev->shd) { + err =3D devl_nested_devlink_set(dev->shd, devlink); + if (err) + goto unlock; + } devl_register(devlink); err =3D mlx5_init_one_devl_locked(dev); if (err) devl_unregister(devlink); +unlock: devl_unlock(devlink); return err; } @@ -2015,6 +2022,13 @@ static int probe_one(struct pci_dev *pdev, const str= uct pci_device_id *id) goto pci_init_err; } =20 + err =3D mlx5_shd_init(dev); + if (err) { + mlx5_core_err(dev, "mlx5_shd_init failed with error code %d\n", + err); + goto shd_init_err; + } + err =3D mlx5_init_one(dev); if (err) { mlx5_core_err(dev, "mlx5_init_one failed with error code %d\n", @@ -2026,6 +2040,8 @@ static int probe_one(struct pci_dev *pdev, const stru= ct pci_device_id *id) return 0; =20 err_init_one: + mlx5_shd_uninit(dev); +shd_init_err: mlx5_pci_close(dev); pci_init_err: mlx5_mdev_uninit(dev); @@ -2047,6 +2063,7 @@ static void remove_one(struct pci_dev *pdev) mlx5_drain_health_wq(dev); mlx5_sriov_disable(pdev, false); mlx5_uninit_one(dev); + mlx5_shd_uninit(dev); mlx5_pci_close(dev); mlx5_mdev_uninit(dev); mlx5_adev_idx_free(dev->priv.adev_idx); diff --git a/drivers/net/ethernet/mellanox/mlx5/core/sh_devlink.c b/drivers= /net/ethernet/mellanox/mlx5/core/sh_devlink.c new file mode 100644 index 000000000000..202f4ae99fa9 --- /dev/null +++ b/drivers/net/ethernet/mellanox/mlx5/core/sh_devlink.c @@ -0,0 +1,71 @@ +// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB +/* Copyright (c) 2025, NVIDIA CORPORATION & AFFILIATES. All rights reserve= d. */ + +#include +#include + +#include "sh_devlink.h" + +static const struct devlink_ops mlx5_shd_ops =3D { +}; + +int mlx5_shd_init(struct mlx5_core_dev *dev) +{ + struct pci_dev *pdev =3D dev->pdev; + unsigned int vpd_size, kw_len; + struct devlink *devlink; + const char *sn; + u8 *vpd_data; + int err =3D 0; + char *end; + int start; + + if (!mlx5_core_is_pf(dev)) + return 0; + + vpd_data =3D pci_vpd_alloc(pdev, &vpd_size); + if (IS_ERR(vpd_data)) { + err =3D PTR_ERR(vpd_data); + return err =3D=3D -ENODEV ? 0 : err; + } + start =3D pci_vpd_find_ro_info_keyword(vpd_data, vpd_size, "V3", &kw_len); + if (start < 0) { + /* Fall-back to SN for older devices. */ + start =3D pci_vpd_find_ro_info_keyword(vpd_data, vpd_size, + PCI_VPD_RO_KEYWORD_SERIALNO, + &kw_len); + if (start < 0) { + err =3D -ENOENT; + goto out; + } + } + sn =3D kstrndup(vpd_data + start, kw_len, GFP_KERNEL); + if (!sn) { + err =3D -ENOMEM; + goto out; + } + /* Firmware may return spaces at the end of the string, strip it. */ + end =3D strchrnul(sn, ' '); + *end =3D '\0'; + + /* Get or create shared devlink instance */ + devlink =3D devlink_shd_get(sn, &mlx5_shd_ops, 0); + kfree(sn); + if (!devlink) { + err =3D -ENOMEM; + goto out; + } + + dev->shd =3D devlink; +out: + kfree(vpd_data); + return err; +} + +void mlx5_shd_uninit(struct mlx5_core_dev *dev) +{ + if (!dev->shd) + return; + + devlink_shd_put(dev->shd); +} diff --git a/drivers/net/ethernet/mellanox/mlx5/core/sh_devlink.h b/drivers= /net/ethernet/mellanox/mlx5/core/sh_devlink.h new file mode 100644 index 000000000000..8ab8d6940227 --- /dev/null +++ b/drivers/net/ethernet/mellanox/mlx5/core/sh_devlink.h @@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */ +/* Copyright (c) 2025, NVIDIA CORPORATION & AFFILIATES. All rights reserve= d. */ + +#ifndef __MLX5_SH_DEVLINK_H__ +#define __MLX5_SH_DEVLINK_H__ + +#include + +int mlx5_shd_init(struct mlx5_core_dev *dev); +void mlx5_shd_uninit(struct mlx5_core_dev *dev); + +#endif /* __MLX5_SH_DEVLINK_H__ */ diff --git a/include/linux/mlx5/driver.h b/include/linux/mlx5/driver.h index e2d067b1e67b..3657cedc89b1 100644 --- a/include/linux/mlx5/driver.h +++ b/include/linux/mlx5/driver.h @@ -798,6 +798,7 @@ struct mlx5_core_dev { enum mlx5_wc_state wc_state; /* sync write combining state */ struct mutex wc_state_lock; + struct devlink *shd; }; =20 struct mlx5_db { --=20 2.44.0 From nobody Sat Feb 7 17:09:28 2026 Received: from BL2PR02CU003.outbound.protection.outlook.com (mail-eastusazon11011031.outbound.protection.outlook.com [52.101.52.31]) (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 3243434EF1E; Wed, 28 Jan 2026 11:28:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.52.31 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769599728; cv=fail; b=FnQ8m/U9ZRMBD0+B3eQG0smWfZc/iNFbMU8kVDkyUwsCVq7DW3cV0ba/ECLlNTVR4fSMaLY+zft3XAYmeYdI9CXtDeyRhli2h730WwFeNvgKsT7cQWs6YNpuLvnc4u+IBix/32gM7fjE+eUM/1tQgHqNzhzWtoLDOBG5eXrR11o= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769599728; c=relaxed/simple; bh=ZiuPw4gxpJnm8Fp0BXF0/Uke9+Efb6aDVL1bFBDGfhE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=WVUNEOsorDDStByNQ7g03v94pGBehJhCXchQ6xQ2jwZtpy2JCEnDdmycTf/sADzWFTXozHkZnZzacPqHFO58QE9CX1b8fkQk2eDF08eC3zpi4uun0KmSyvAyfmlHSP5dO4Si800ZPudqWE007DlJB5JeM+nPswTSTvUqtkVOlpE= 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=DbjyX5vw; arc=fail smtp.client-ip=52.101.52.31 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="DbjyX5vw" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=VhS3LwAwZb1Hi1dfWjW7sCGRQ4gd1pFhV1EvnHj/Lruek+mp/NkImr7AoU6/oJ/kusr15uJk+Ev8FOfmuySoC2tAZhuHsogCpNO2p8Zjspn6MwZgwwiSqzOuvTwl2Rdua+JO961N0KsRbEZG93CxGZ7d0doGOA93C0WorXRzj2NmAWuf3V1pp0bbFulEMclhGgtpWOzSqBDIRk7O2+2jfxQxYhX1aLEZq+OWEEywRlxlrP/HWYj9QOOTm8WkcpvM627NSCII7+eCPh/e3XDqu6dlGsSeErnUTfHybqEBCONDv+sqK9ieiK2Iix314FykqJrInIuCA5wxSyUzcujCmA== 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=+gbcaRZVuCbu+AI/JbON4SU/SCvsGg3RX98vpdOBgJk=; b=Nsh3sk7JhpG905+mhrOLMwPuj2imH/X2PdbUD9wJrrjBePB4nMd80T5xzfqVOzEvA/thkLQPIi/0Enp9F3Dy1WNjlQBrJsILQ3HSipPzWutKGZcc/sT5SNgxgLLWF/Z1LternlXKnZptKIopz58Pi+Z3Ya8o9uiJCq1U0Uwn7NA34hflPLV4A+s2iuddRVb573yXgugjGy3JX/4iXx5LJj8mO/aTvR5XAURx4idzH84GFuJU4pb8C2b/wGai9QNaGCmli5Nf5t7pST6EQiP3hYR6NizB/JcejTScucihnxPU9nuF6ORm03Jx5NL0/pvy83bGqPn9EVkXLFf5Dpv4xw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=google.com 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=+gbcaRZVuCbu+AI/JbON4SU/SCvsGg3RX98vpdOBgJk=; b=DbjyX5vwnckVw5wiLCvWLV9ETHl6A4kfKxreJLKRvDUXv6kSezWk63N/QYLiP6PpwLiaSgTxzxjd/ilzaiCtmbnq42JdTLgNGSndqBSV2g8kl5LBsGHuYCLxYd34ph74huTEERz94A6a+AOwuczyvI1EOy6+2R/1rFp8Mzivz4QiIJ1HpQwDKnpY/3z1x1tdt1cHuRErmWfLDsf8YIE7yRec0xHFMp8RJHJGzgHNmijfufqfwWGzVNUy5jlpPAv3azXDKceq7hztq5+CNgoesTMzSKqYeclu5mxfQDjRKpv6Ti6LsFrXBC+m9URTus8SSu0ezI3+gNc5EFtO3RuKWw== Received: from PH8PR07CA0019.namprd07.prod.outlook.com (2603:10b6:510:2cd::18) by DS0PR12MB6584.namprd12.prod.outlook.com (2603:10b6:8:d0::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9564.8; Wed, 28 Jan 2026 11:28:41 +0000 Received: from SN1PEPF0002BA4E.namprd03.prod.outlook.com (2603:10b6:510:2cd:cafe::2e) by PH8PR07CA0019.outlook.office365.com (2603:10b6:510:2cd::18) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9564.8 via Frontend Transport; Wed, 28 Jan 2026 11:28:38 +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 SN1PEPF0002BA4E.mail.protection.outlook.com (10.167.242.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9564.3 via Frontend Transport; Wed, 28 Jan 2026 11:28: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.2562.20; Wed, 28 Jan 2026 03:28:31 -0800 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.2562.20; Wed, 28 Jan 2026 03:28:30 -0800 Received: from vdi.nvidia.com (10.127.8.10) by mail.nvidia.com (10.129.68.10) with Microsoft SMTP Server id 15.2.2562.20 via Frontend Transport; Wed, 28 Jan 2026 03:28:25 -0800 From: Tariq Toukan To: Eric Dumazet , Jakub Kicinski , Paolo Abeni , Andrew Lunn , "David S. Miller" CC: Donald Hunter , Jiri Pirko , Jonathan Corbet , Saeed Mahameed , "Leon Romanovsky" , Tariq Toukan , Mark Bloch , , , , , Gal Pressman , Moshe Shemesh , Carolina Jubran , Cosmin Ratiu , Jiri Pirko , Randy Dunlap , Simon Horman , Krzysztof Kozlowski Subject: [PATCH net-next V7 11/14] net/mlx5: Expose a function to clear a vport's parent Date: Wed, 28 Jan 2026 13:25:41 +0200 Message-ID: <20260128112544.1661250-12-tariqt@nvidia.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20260128112544.1661250-1-tariqt@nvidia.com> References: <20260128112544.1661250-1-tariqt@nvidia.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN1PEPF0002BA4E:EE_|DS0PR12MB6584:EE_ X-MS-Office365-Filtering-Correlation-Id: c0acb878-4c99-4ad6-508a-08de5e606334 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|7416014|376014|82310400026|1800799024; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?rBlPqer4c/gDrQAognuN+F9ze1gA/7RJdKglLj49l078EIlBMUHZRIbC4wjj?= =?us-ascii?Q?5nGKvyyyXYwh5IpPf0N/yxs1D3Q7roo0/0iPuLXYYz36SCubXpcNJSBvCHU1?= =?us-ascii?Q?DnSt57RC0TpT0Nz8JDJBST9yWhXYBPReOLMx6qcuRuYamj/x29Jp2+pTDNwY?= =?us-ascii?Q?xjFPUjLym59dsSvLsXBtqaNJO5BLfPOFGeU4ifpm270+pqvTxfFi0Sv19AC8?= =?us-ascii?Q?v/bT91oSK8faGw/R7wCky3TgfLaQnKMDtq75CiDKrY5JDMaavdDcV5f37//N?= =?us-ascii?Q?/Gm0knbEzkHgKAAROIbevirOdtgQeKZDnA/Er13b5c4vcUH/KVakvF52K3qu?= =?us-ascii?Q?4ciSydlBPup6+HnVQxUgNy/SncIBshu0AbGXvbK2DZlX63s5756rxg4yzof4?= =?us-ascii?Q?R6yz6r9+aLzOyKbSpsSZQqzEJbT9xekR4mwlXwUsrNtxDcLYd/DaAA6SQTnE?= =?us-ascii?Q?VZsJ4wslVmcImlSsFFw66TmXZIc1o26MQJS1/8AHGrSSyyID5K1FT+D6EBAK?= =?us-ascii?Q?Yuin75D+I8aeT0XSOU8FHojWRReeCSpg3G+95So0T37y2hleqzddsBFoU0IL?= =?us-ascii?Q?zSLlBA/4mBQY08ImS0q6BzTe+pfUlZenOYLsAgOvoF45RBu16vNum8+5y3QW?= =?us-ascii?Q?tqgXOXM8EyUDyWOyP1wPQkMyZSUUehCobljjAGu4AK10RdP8etXLpM66RbBs?= =?us-ascii?Q?1J/H8b14+/DSf9xnSGG5AvEyZ7fbaVnDeFSv4/7LSMpxKOIATsloA+rK081P?= =?us-ascii?Q?879zJBjnIwMesKsTCIwy2woYu58QKqZGiZaUAXyBjXV3QtK2vU09VF/vzQ/q?= =?us-ascii?Q?uY9l181pRBRoA+U7tK7mTA1saK1lc8Mg5he/gnRRKaTuhpzIXyFhXU6XEZXO?= =?us-ascii?Q?u/6TxQAh0GYnIsg8f0XRbf9U3wvUXdFy6dJxlZH//IYK85Ahukz2f9wVuKhM?= =?us-ascii?Q?RkS88lSqa1HLwLVT90ih02jqfSGPOfQYPeyBKUIF49FAci71qkZyW7L1yVFF?= =?us-ascii?Q?p0cffskt284jdcNTp2BZwCmyB7i7oKVF+s0AFWe43GmakZYlSeyZu1vcH63B?= =?us-ascii?Q?4+gp922Doeaj1idSNtrPVtuyYTwsEXZuIk1idbmCEjh+i81ZJfPblLPbIHLb?= =?us-ascii?Q?5brjEfZq7zi8TwEqlO2cM9HNsZM/LelieReQ5jzSTQ0mQj+kICznOgTr836t?= =?us-ascii?Q?SKAnSh4W3t7YaCXmjwH6QTCDO9fesvio75u0778LgeSWPJayNhSYttRa3N+G?= =?us-ascii?Q?rOz+a8GlVn9Uz61CgP9ZBDpi0M9R6U3Ab1sFazFfzCsSIRwUBhio8mucurqd?= =?us-ascii?Q?oGMP2LJQpRFfVht2EAOjlgpRTIzRShdHYMRck9VJ2GTNik6BwrL35+iHSu0z?= =?us-ascii?Q?pb0I8rQh06dHLthQEDzKIk1vJbRChZkQo4UtzWRDyB6OC3ZrtxUyQV2eguMU?= =?us-ascii?Q?tfGZ68xjb3/ZIv1DUjPrW7D4g1vo7DuMLn1AjVSq3I9kOG/8Jh+oFl0LF+uD?= =?us-ascii?Q?Y2OWnRfxYwyMrfrL4k6p9EL6w5T5ftk9Cdk52KF9kD5tyeJoSfc9SbSHCGxt?= =?us-ascii?Q?EDQ0Q56LJH1wt7/Fn0Us9wi6/NI7bKTvjFkaL/j/vTdyyPCvES3ylTCBgCUG?= =?us-ascii?Q?uJVqAo51OFZfSY36151vieAP2XvZ6Qadwa16enYqi8QDJuyQMK9FI61FQ+5n?= =?us-ascii?Q?JG6HKA=3D=3D?= X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230040)(36860700013)(7416014)(376014)(82310400026)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Jan 2026 11:28:40.6150 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c0acb878-4c99-4ad6-508a-08de5e606334 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: SN1PEPF0002BA4E.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB6584 Content-Type: text/plain; charset="utf-8" From: Cosmin Ratiu Currently, clearing a vport's parent happens with a call that looks like this: mlx5_esw_qos_vport_update_parent(vport, NULL, NULL); Change that to something nicer that looks like this: mlx5_esw_qos_vport_clear_parent(vport); Signed-off-by: Cosmin Ratiu Reviewed-by: Carolina Jubran Signed-off-by: Tariq Toukan --- .../ethernet/mellanox/mlx5/core/esw/devlink_port.c | 2 +- drivers/net/ethernet/mellanox/mlx5/core/esw/qos.c | 11 +++++++++-- drivers/net/ethernet/mellanox/mlx5/core/eswitch.h | 3 +-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/esw/devlink_port.c b/d= rivers/net/ethernet/mellanox/mlx5/core/esw/devlink_port.c index 89a58dee50b3..31704ea9cdb4 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/esw/devlink_port.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/esw/devlink_port.c @@ -202,7 +202,7 @@ void mlx5_esw_offloads_devlink_port_unregister(struct m= lx5_vport *vport) return; dl_port =3D vport->dl_port; =20 - mlx5_esw_qos_vport_update_parent(vport, NULL, NULL); + mlx5_esw_qos_vport_clear_parent(vport); devl_rate_leaf_destroy(&dl_port->dl_port); =20 devl_port_unregister(&dl_port->dl_port); diff --git a/drivers/net/ethernet/mellanox/mlx5/core/esw/qos.c b/drivers/ne= t/ethernet/mellanox/mlx5/core/esw/qos.c index 4278bcb04c72..8c3a026b8db4 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/esw/qos.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/esw/qos.c @@ -1896,8 +1896,10 @@ int mlx5_esw_devlink_rate_node_del(struct devlink_ra= te *rate_node, void *priv, return 0; } =20 -int mlx5_esw_qos_vport_update_parent(struct mlx5_vport *vport, struct mlx5= _esw_sched_node *parent, - struct netlink_ext_ack *extack) +static int +mlx5_esw_qos_vport_update_parent(struct mlx5_vport *vport, + struct mlx5_esw_sched_node *parent, + struct netlink_ext_ack *extack) { struct mlx5_eswitch *esw =3D vport->dev->priv.eswitch; int err =3D 0; @@ -1922,6 +1924,11 @@ int mlx5_esw_qos_vport_update_parent(struct mlx5_vpo= rt *vport, struct mlx5_esw_s return err; } =20 +void mlx5_esw_qos_vport_clear_parent(struct mlx5_vport *vport) +{ + mlx5_esw_qos_vport_update_parent(vport, NULL, NULL); +} + int mlx5_esw_devlink_rate_leaf_parent_set(struct devlink_rate *devlink_rat= e, struct devlink_rate *parent, void *priv, void *parent_priv, diff --git a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.h b/drivers/ne= t/ethernet/mellanox/mlx5/core/eswitch.h index ad1073f7b79f..20cf9dd542a1 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.h +++ b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.h @@ -452,8 +452,7 @@ int mlx5_eswitch_set_vport_trust(struct mlx5_eswitch *e= sw, u16 vport_num, bool setting); int mlx5_eswitch_set_vport_rate(struct mlx5_eswitch *esw, u16 vport, u32 max_rate, u32 min_rate); -int mlx5_esw_qos_vport_update_parent(struct mlx5_vport *vport, struct mlx5= _esw_sched_node *node, - struct netlink_ext_ack *extack); +void mlx5_esw_qos_vport_clear_parent(struct mlx5_vport *vport); int mlx5_eswitch_set_vepa(struct mlx5_eswitch *esw, u8 setting); int mlx5_eswitch_get_vepa(struct mlx5_eswitch *esw, u8 *setting); int mlx5_eswitch_get_vport_config(struct mlx5_eswitch *esw, --=20 2.44.0 From nobody Sat Feb 7 17:09:28 2026 Received: from CY3PR05CU001.outbound.protection.outlook.com (mail-westcentralusazon11013051.outbound.protection.outlook.com [40.93.201.51]) (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 036793542EA; Wed, 28 Jan 2026 11:28:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.93.201.51 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769599740; cv=fail; b=otbenjIjhaqFgMiRhBGUtJap0YscRgihBNxnAe31ZRvqXMDDS1M582Nl9uHmmkuq7fGdFruck/vMPP9/p8XxSiU3T6XfmoJjxjc3DGf+gGNT1Ws1ZHf75X4Phttplj4sa6dVsAmfgEvt9NJFn+jbL00Cq5LViTV+YreQu16276k= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769599740; c=relaxed/simple; bh=fvD7xDuu7auUJXUITzkkcmgOyewcAPtPGeigJWFv2yc=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=bM8ge21EeUn+HLXXbnkT6hnE4J+pkuikfRqBZVE9ThBxmA2/dPMdQ8UBeYUpqmOig1YI7U+hUH+tb9sZnFrppSvga8GmCvgyoz6Z3mKwvsdG86eosnrJ6wUvS8mfWMXKwegGPuZJjr2q9MtLTnhwdXU7Duns07uBGv1XbHUKbyE= 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=T75ZEAPW; arc=fail smtp.client-ip=40.93.201.51 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="T75ZEAPW" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=OTtyNVO5p9CRiqj+3LVDG8eEmsgO7QU84buUOQ06kLGwDEaFVe3J7sLEUP/NzYPAFS3gy5/YhVPXU2GacmJRBCaYyDXVh2u4n9FlPAleIteLDfIf5V7NRGdp5NrmHspytuRZo83EWO/zMlJkru/eu4NEN19uw/zUIyEPKkKneVs6wyvWcQH8II5qhVeSskW82VfSy2Lr06MbiQMZgdP49AYd+XO0XdWwVAh0wlgbbHRFlzt/O1wPHzb+w+tNdCYkjTO+D/F0D9cD1OH5z0Yc7WzrflakK2/tzd7ktAyle5bhvTDNadHJnPrOYNHhpaFwj4+qZEaRfemnXA0wDEpBiw== 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=MwgwDv0rBR4dsZKTftvK9Mj0+5SpWmJkLLfaVYtwvhc=; b=f1p51heTjeP1IcxSBU3PdQ5FZ/fpktslInRGSwUstRsnZ8FE/Ag81nlLRzBnEKZW1oXN0NQfdv765olwSPjXEcTC4KFtbO0OqPeq3vmb+qsPxlVInNNjwtaP07YUHP4wOUEwMAEmSnRrUBgqwTOQuynNPK9NLh6WnkkaG+XmZF/ODG2NekhGZqh4LLBndMMghwTNL/Ei+R/aciAv/pjZQWe8sLwEPXF32isBMxY8KeqilZz5DNiGzuZa2ZFuKOYPqCriPrgXhlXOaKh0/YiEhUzniuVLS8nRBhbIF5Jqn/uOtSXPb1Jt8pOluUyezWLk+UE0iDER5MHMshpr+9OkwA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=google.com 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=MwgwDv0rBR4dsZKTftvK9Mj0+5SpWmJkLLfaVYtwvhc=; b=T75ZEAPWqMn6I7NV5OsBEE1dWy3B+YlTqEsvEz27E+DMcLvNKxXqxaCNihIwMfYhX22q5KzmAlHCh7VTPxFFxGSh77s4j9ncDb6xRNO94mhk3YuyI8/0SV2gBTSCgCQPyHfj4VDIYO/6pavPnKTj9hX3b8G0mxhw/6oPXJg8wlp1hRfdqUdphPuUqhNlU6+sHAaAv+qYLOkgSwh0bm87sNHHjPPCLMSwoVItNuCoA5+vWJ7zt/8rxBj85gBdIhZkqngeMxvq/CTPDfLVmJshLb9v442hCXVPhtozkDHGMF+SBq8v5dH1pjDKXjHWuq2wgakkfs2UbHtrqMyLVlq3wg== Received: from SA0PR11CA0032.namprd11.prod.outlook.com (2603:10b6:806:d0::7) by SA0PR12MB4480.namprd12.prod.outlook.com (2603:10b6:806:99::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9564.7; Wed, 28 Jan 2026 11:28:48 +0000 Received: from SN1PEPF0002BA52.namprd03.prod.outlook.com (2603:10b6:806:d0:cafe::9c) by SA0PR11CA0032.outlook.office365.com (2603:10b6:806:d0::7) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9542.16 via Frontend Transport; Wed, 28 Jan 2026 11:28:48 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by SN1PEPF0002BA52.mail.protection.outlook.com (10.167.242.75) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9564.3 via Frontend Transport; Wed, 28 Jan 2026 11:28:48 +0000 Received: from rnnvmail202.nvidia.com (10.129.68.7) 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.2562.20; Wed, 28 Jan 2026 03:28:37 -0800 Received: from rnnvmail205.nvidia.com (10.129.68.10) by rnnvmail202.nvidia.com (10.129.68.7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.20; Wed, 28 Jan 2026 03:28:36 -0800 Received: from vdi.nvidia.com (10.127.8.10) by mail.nvidia.com (10.129.68.10) with Microsoft SMTP Server id 15.2.2562.20 via Frontend Transport; Wed, 28 Jan 2026 03:28:31 -0800 From: Tariq Toukan To: Eric Dumazet , Jakub Kicinski , Paolo Abeni , Andrew Lunn , "David S. Miller" CC: Donald Hunter , Jiri Pirko , Jonathan Corbet , Saeed Mahameed , "Leon Romanovsky" , Tariq Toukan , Mark Bloch , , , , , Gal Pressman , Moshe Shemesh , Carolina Jubran , Cosmin Ratiu , Jiri Pirko , Randy Dunlap , Simon Horman , Krzysztof Kozlowski Subject: [PATCH net-next V7 12/14] net/mlx5: Store QoS sched nodes in the sh_devlink Date: Wed, 28 Jan 2026 13:25:42 +0200 Message-ID: <20260128112544.1661250-13-tariqt@nvidia.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20260128112544.1661250-1-tariqt@nvidia.com> References: <20260128112544.1661250-1-tariqt@nvidia.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN1PEPF0002BA52:EE_|SA0PR12MB4480:EE_ X-MS-Office365-Filtering-Correlation-Id: 958c5ee8-59a7-4bb5-19f3-08de5e6067f8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|36860700013|82310400026|7416014|376014|13003099007; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?kzjIef0c+LHKoLuHpXAeYKZpGh9vX17PmR1WkWvkXH/lgy9GFjh2DXUeRgTO?= =?us-ascii?Q?0WjgHg/t9MXRcoE1VKqbGARYzlWPASLeFqMA/xttEwlUU+Pk3AoNRsdkqUtN?= =?us-ascii?Q?ImCYUdF1Y9T4EFPJg0HxF6Hez/Rjuc60838KsUe6L8jeqAHVL/cboKTypZzQ?= =?us-ascii?Q?oiaVFhAaql19CaqZ0NnDZxwuyqyVn0I0KX8U94CZVozWZUt2k2KAoRSJYyqb?= =?us-ascii?Q?ufPEa76gAS/v9Egat2+tUNJyqPIB1N6KIq3ZY9QXH30P0Sk+LmXNJkGsoHVr?= =?us-ascii?Q?nb0FvNrvc7GDgyLI/E7iu7jmOXWy3YqJqjiVTb/9Zx6viu57hJhy2qTMPWrk?= =?us-ascii?Q?448x5jW68hzuIkErN3j9jK4ca+BEjddJBWuvlaTEO6LgX8jax435jLRN+/oc?= =?us-ascii?Q?L0EYaJqIepD6wkCY4PfdR5DBPMFzzLj54cEtW+HzMqqSTluaGARgPPkjsuLn?= =?us-ascii?Q?nI/ekeFeUCwlsFHaXpicLmUhv461sgRXC+Zu0KdwW+USEopqPR8Yc1FH+NqS?= =?us-ascii?Q?mfiuuFCkLzekd0+RCWySvueH07G691DGbkhs2yLWOlymiYfVMxzJ+h4p2YkQ?= =?us-ascii?Q?E0Ot8R9zwKIeDlzib2dcZkasu+ZYKMLngV69nDqDNqocudUqjLww30zgY9Is?= =?us-ascii?Q?9U9JWDfAkEm4TzBfFIT1Z65o2wsIiFbuEvYhKUjo32L8afN3ZleReqhIlF4F?= =?us-ascii?Q?HkAuqouFf4yPLurzEaQgq16RM/mqUzQJ60+monf6aGVWT3WnMSdZUROozbT1?= =?us-ascii?Q?BmaY6ftlzPpdF3woOeJ+YasQzF9342uAOs1cVDPUKjCNkD4Noc11PO8zxl6S?= =?us-ascii?Q?TudR0raJUNWvZq9uGIg6Q773VRk+usAg1NuJ/7dawNohBiF7M4+Z0FJA/+nU?= =?us-ascii?Q?vYkX+KbpAzKIInJaZzH+dpm2physBPiKkjaWlYh+0p815AiBTgAtWNPSUpPu?= =?us-ascii?Q?R7VS1USJ0z1XH5+erWfzibqMc7GvLtaNIg/J3Sz9my0uUHoM4sPMmYVZUPjN?= =?us-ascii?Q?AbsnMauUcVj9R8N2Gxzv9hojbXUoa6HbRAqG/En0L1LAhYSNkMByFsRGZnRT?= =?us-ascii?Q?M1zu1zVMolGFO07qORt28nwauqv59aewmRPJBDbai5KoRCfKq6jmLKoCrl+Y?= =?us-ascii?Q?SEU9w/v8OMyB3Q6UnGR+UnQ+kbuQV5/HFGxC6D0LSVngIort91BpQLixtds8?= =?us-ascii?Q?tknqRWsct/Fb7bBFndckTtR7/iUGdlR/Aql9eIwBzavtF1cYrD4YR7O8tGO8?= =?us-ascii?Q?s8S8D1m6d+ScQcvOE48+xJ6/2ILetK51QqjHPm9XhfwUfH8AyivzjEkW76y4?= =?us-ascii?Q?DvVShMD+aSyab8RbBgH+y/KqiCNBiHxq+GixIK1HWWRtxjrce2R1X0jYLfAi?= =?us-ascii?Q?NMBTyXJV/S4bSZZN+C5zr7N1NHigSM7VUrDVv0RfxJejuVazCqMZgVQ8xySm?= =?us-ascii?Q?itp9A5g2LRdRBtdNJOmPDNkx35yDc5C8C+gjbYnSKA4THoE5Ogt2J2kgszl1?= =?us-ascii?Q?NNQYrPZzRtbAmxqYm2ZU0X6mfsouclRtevSV0cb1JyDlStpR0odJTE180nZj?= =?us-ascii?Q?nmc+wIhzc009HfOplwAr66lMlz08IUaAwbJzYB/P1ApDzZrBoo0plaRvu8KC?= =?us-ascii?Q?o8Dm6ZoesO+G/3Umli/mCfNf1IN+4AiOWQRX4OK/KM394kxco6Mm9I5X0rBS?= =?us-ascii?Q?/TzJpw=3D=3D?= X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230040)(1800799024)(36860700013)(82310400026)(7416014)(376014)(13003099007);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Jan 2026 11:28:48.5953 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 958c5ee8-59a7-4bb5-19f3-08de5e6067f8 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: SN1PEPF0002BA52.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4480 Content-Type: text/plain; charset="utf-8" From: Cosmin Ratiu In order to support cross-esw scheduling, the nodes for all devices need to be accessible from the same place so that normalization can work. Store them in the shared devlink instance and provide an accessor for them. Protecting against concurrent QoS modifications is now done with the shd lock. Enable the supported_cross_device_rate_nodes devink ops attribute so that all calls originating from devlink rate acquire the shd lock. Only the additional entry points into QoS need to acquire the shd lock. Enabling supported_cross_device_rate_nodes now is safe, because mlx5_esw_qos_vport_update_parent will reject cross-esw parent updates. This will change in the next patch. As part of this change, the E-Switch qos domain concept was removed. E-Switch QoS domains were added with the intention of eventually implementing shared qos domains to support cross-esw scheduling in the previous approach ([1]), but they are no longer necessary in the new approach. [1] https://lore.kernel.org/netdev/20250213180134.323929-1-tariqt@nvidia.co= m/ Signed-off-by: Cosmin Ratiu Reviewed-by: Carolina Jubran Signed-off-by: Tariq Toukan --- .../net/ethernet/mellanox/mlx5/core/devlink.c | 1 + .../net/ethernet/mellanox/mlx5/core/esw/qos.c | 201 +++++------------- .../net/ethernet/mellanox/mlx5/core/esw/qos.h | 3 - .../net/ethernet/mellanox/mlx5/core/eswitch.c | 9 +- .../net/ethernet/mellanox/mlx5/core/eswitch.h | 11 +- .../ethernet/mellanox/mlx5/core/sh_devlink.c | 30 ++- .../ethernet/mellanox/mlx5/core/sh_devlink.h | 2 + 7 files changed, 88 insertions(+), 169 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/devlink.c b/drivers/ne= t/ethernet/mellanox/mlx5/core/devlink.c index ea77fbd98396..a040c81b10ce 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/devlink.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/devlink.c @@ -385,6 +385,7 @@ static const struct devlink_ops mlx5_devlink_ops =3D { .rate_node_del =3D mlx5_esw_devlink_rate_node_del, .rate_leaf_parent_set =3D mlx5_esw_devlink_rate_leaf_parent_set, .rate_node_parent_set =3D mlx5_esw_devlink_rate_node_parent_set, + .supported_cross_device_rate_nodes =3D true, #endif #ifdef CONFIG_MLX5_SF_MANAGER .port_new =3D mlx5_devlink_sf_port_new, diff --git a/drivers/net/ethernet/mellanox/mlx5/core/esw/qos.c b/drivers/ne= t/ethernet/mellanox/mlx5/core/esw/qos.c index 8c3a026b8db4..0d187399d846 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/esw/qos.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/esw/qos.c @@ -5,60 +5,16 @@ #include "lib/mlx5.h" #include "esw/qos.h" #include "en/port.h" +#include "sh_devlink.h" #define CREATE_TRACE_POINTS #include "diag/qos_tracepoint.h" =20 /* Minimum supported BW share value by the HW is 1 Mbit/sec */ #define MLX5_MIN_BW_SHARE 1 =20 -/* Holds rate nodes associated with an E-Switch. */ -struct mlx5_qos_domain { - /* Serializes access to all qos changes in the qos domain. */ - struct mutex lock; - /* List of all mlx5_esw_sched_nodes. */ - struct list_head nodes; -}; - -static void esw_qos_lock(struct mlx5_eswitch *esw) -{ - mutex_lock(&esw->qos.domain->lock); -} - -static void esw_qos_unlock(struct mlx5_eswitch *esw) -{ - mutex_unlock(&esw->qos.domain->lock); -} - static void esw_assert_qos_lock_held(struct mlx5_eswitch *esw) { - lockdep_assert_held(&esw->qos.domain->lock); -} - -static struct mlx5_qos_domain *esw_qos_domain_alloc(void) -{ - struct mlx5_qos_domain *qos_domain; - - qos_domain =3D kzalloc(sizeof(*qos_domain), GFP_KERNEL); - if (!qos_domain) - return NULL; - - mutex_init(&qos_domain->lock); - INIT_LIST_HEAD(&qos_domain->nodes); - - return qos_domain; -} - -static int esw_qos_domain_init(struct mlx5_eswitch *esw) -{ - esw->qos.domain =3D esw_qos_domain_alloc(); - - return esw->qos.domain ? 0 : -ENOMEM; -} - -static void esw_qos_domain_release(struct mlx5_eswitch *esw) -{ - kfree(esw->qos.domain); - esw->qos.domain =3D NULL; + devl_assert_locked(esw->dev->shd); } =20 enum sched_node_type { @@ -111,7 +67,8 @@ static void esw_qos_node_attach_to_parent(struct mlx5_es= w_sched_node *node) if (!node->parent) { /* Root children are assigned a depth level of 2. */ node->level =3D 2; - list_add_tail(&node->entry, &node->esw->qos.domain->nodes); + list_add_tail(&node->entry, + mlx5_shd_get_qos_nodes(node->esw->dev)); } else { node->level =3D node->parent->level + 1; list_add_tail(&node->entry, &node->parent->children); @@ -324,14 +281,15 @@ static int esw_qos_create_rate_limit_element(struct m= lx5_esw_sched_node *node, static u32 esw_qos_calculate_min_rate_divider(struct mlx5_eswitch *esw, struct mlx5_esw_sched_node *parent) { - struct list_head *nodes =3D parent ? &parent->children : &esw->qos.domain= ->nodes; u32 fw_max_bw_share =3D MLX5_CAP_QOS(esw->dev, max_tsar_bw_share); struct mlx5_esw_sched_node *node; + struct list_head *nodes; u32 max_guarantee =3D 0; =20 /* Find max min_rate across all nodes. * This will correspond to fw_max_bw_share in the final bw_share calculat= ion. */ + nodes =3D parent ? &parent->children : mlx5_shd_get_qos_nodes(esw->dev); list_for_each_entry(node, nodes, entry) { if (node->esw =3D=3D esw && node->ix !=3D esw->qos.root_tsar_ix && node->min_rate > max_guarantee) @@ -372,10 +330,11 @@ static void esw_qos_normalize_min_rate(struct mlx5_es= witch *esw, struct mlx5_esw_sched_node *parent, struct netlink_ext_ack *extack) { - struct list_head *nodes =3D parent ? &parent->children : &esw->qos.domain= ->nodes; u32 divider =3D esw_qos_calculate_min_rate_divider(esw, parent); struct mlx5_esw_sched_node *node; + struct list_head *nodes; =20 + nodes =3D parent ? &parent->children : mlx5_shd_get_qos_nodes(esw->dev); list_for_each_entry(node, nodes, entry) { if (node->esw !=3D esw || node->ix =3D=3D esw->qos.root_tsar_ix) continue; @@ -715,7 +674,7 @@ __esw_qos_create_vports_sched_node(struct mlx5_eswitch = *esw, struct mlx5_esw_sch goto err_alloc_node; } =20 - list_add_tail(&node->entry, &esw->qos.domain->nodes); + list_add_tail(&node->entry, mlx5_shd_get_qos_nodes(esw->dev)); esw_qos_normalize_min_rate(esw, NULL, extack); trace_mlx5_esw_node_qos_create(esw->dev, node, node->ix); =20 @@ -1108,7 +1067,8 @@ static int mlx5_esw_qos_vport_enable(struct mlx5_vpor= t *vport, enum sched_node_t return -ENOMEM; } if (!parent) - list_add_tail(&sched_node->entry, &esw->qos.domain->nodes); + list_add_tail(&sched_node->entry, + mlx5_shd_get_qos_nodes(esw->dev)); =20 sched_node->max_rate =3D max_rate; sched_node->min_rate =3D min_rate; @@ -1143,7 +1103,7 @@ void mlx5_esw_qos_vport_disable(struct mlx5_vport *vp= ort) struct mlx5_esw_sched_node *parent; =20 lockdep_assert_held(&esw->state_lock); - esw_qos_lock(esw); + devl_lock(esw->dev->shd); if (!vport->qos.sched_node) goto unlock; =20 @@ -1152,7 +1112,7 @@ void mlx5_esw_qos_vport_disable(struct mlx5_vport *vp= ort) =20 mlx5_esw_qos_vport_disable_locked(vport); unlock: - esw_qos_unlock(esw); + devl_unlock(esw->dev->shd); } =20 static int mlx5_esw_qos_set_vport_max_rate(struct mlx5_vport *vport, u32 m= ax_rate, @@ -1191,26 +1151,25 @@ int mlx5_esw_qos_set_vport_rate(struct mlx5_vport *= vport, u32 max_rate, u32 min_ struct mlx5_eswitch *esw =3D vport->dev->priv.eswitch; int err; =20 - esw_qos_lock(esw); + devl_lock(esw->dev->shd); err =3D mlx5_esw_qos_set_vport_min_rate(vport, min_rate, NULL); if (!err) err =3D mlx5_esw_qos_set_vport_max_rate(vport, max_rate, NULL); - esw_qos_unlock(esw); + devl_unlock(esw->dev->shd); return err; } =20 bool mlx5_esw_qos_get_vport_rate(struct mlx5_vport *vport, u32 *max_rate, = u32 *min_rate) { - struct mlx5_eswitch *esw =3D vport->dev->priv.eswitch; bool enabled; =20 - esw_qos_lock(esw); + devl_lock(vport->dev->shd); enabled =3D !!vport->qos.sched_node; if (enabled) { *max_rate =3D vport->qos.sched_node->max_rate; *min_rate =3D vport->qos.sched_node->min_rate; } - esw_qos_unlock(esw); + devl_unlock(vport->dev->shd); return enabled; } =20 @@ -1576,9 +1535,9 @@ int mlx5_esw_qos_modify_vport_rate(struct mlx5_eswitc= h *esw, u16 vport_num, u32 return err; } =20 - esw_qos_lock(esw); + devl_lock(esw->dev->shd); err =3D mlx5_esw_qos_set_vport_max_rate(vport, rate_mbps, NULL); - esw_qos_unlock(esw); + devl_unlock(esw->dev->shd); =20 return err; } @@ -1667,44 +1626,24 @@ static void esw_vport_qos_prune_empty(struct mlx5_v= port *vport) mlx5_esw_qos_vport_disable_locked(vport); } =20 -int mlx5_esw_qos_init(struct mlx5_eswitch *esw) -{ - if (esw->qos.domain) - return 0; /* Nothing to change. */ - - return esw_qos_domain_init(esw); -} - -void mlx5_esw_qos_cleanup(struct mlx5_eswitch *esw) -{ - if (esw->qos.domain) - esw_qos_domain_release(esw); -} - /* Eswitch devlink rate API */ =20 int mlx5_esw_devlink_rate_leaf_tx_share_set(struct devlink_rate *rate_leaf= , void *priv, u64 tx_share, struct netlink_ext_ack *extack) { struct mlx5_vport *vport =3D priv; - struct mlx5_eswitch *esw; int err; =20 - esw =3D vport->dev->priv.eswitch; - if (!mlx5_esw_allowed(esw)) + if (!mlx5_esw_allowed(vport->dev->priv.eswitch)) return -EPERM; =20 err =3D esw_qos_devlink_rate_to_mbps(vport->dev, "tx_share", &tx_share, e= xtack); if (err) return err; =20 - esw_qos_lock(esw); err =3D mlx5_esw_qos_set_vport_min_rate(vport, tx_share, extack); - if (err) - goto out; - esw_vport_qos_prune_empty(vport); -out: - esw_qos_unlock(esw); + if (!err) + esw_vport_qos_prune_empty(vport); return err; } =20 @@ -1712,24 +1651,18 @@ int mlx5_esw_devlink_rate_leaf_tx_max_set(struct de= vlink_rate *rate_leaf, void * u64 tx_max, struct netlink_ext_ack *extack) { struct mlx5_vport *vport =3D priv; - struct mlx5_eswitch *esw; int err; =20 - esw =3D vport->dev->priv.eswitch; - if (!mlx5_esw_allowed(esw)) + if (!mlx5_esw_allowed(vport->dev->priv.eswitch)) return -EPERM; =20 err =3D esw_qos_devlink_rate_to_mbps(vport->dev, "tx_max", &tx_max, extac= k); if (err) return err; =20 - esw_qos_lock(esw); err =3D mlx5_esw_qos_set_vport_max_rate(vport, tx_max, extack); - if (err) - goto out; - esw_vport_qos_prune_empty(vport); -out: - esw_qos_unlock(esw); + if (!err) + esw_vport_qos_prune_empty(vport); return err; } =20 @@ -1740,34 +1673,30 @@ int mlx5_esw_devlink_rate_leaf_tc_bw_set(struct dev= link_rate *rate_leaf, { struct mlx5_esw_sched_node *vport_node; struct mlx5_vport *vport =3D priv; - struct mlx5_eswitch *esw; bool disable; int err =3D 0; =20 - esw =3D vport->dev->priv.eswitch; - if (!mlx5_esw_allowed(esw)) + if (!mlx5_esw_allowed(vport->dev->priv.eswitch)) return -EPERM; =20 disable =3D esw_qos_tc_bw_disabled(tc_bw); - esw_qos_lock(esw); =20 if (!esw_qos_vport_validate_unsupported_tc_bw(vport, tc_bw)) { NL_SET_ERR_MSG_MOD(extack, "E-Switch traffic classes number is not supported"); - err =3D -EOPNOTSUPP; - goto unlock; + return -EOPNOTSUPP; } =20 vport_node =3D vport->qos.sched_node; if (disable && !vport_node) - goto unlock; + return 0; =20 if (disable) { if (vport_node->type =3D=3D SCHED_NODE_TYPE_TC_ARBITER_TSAR) err =3D esw_qos_vport_update(vport, SCHED_NODE_TYPE_VPORT, vport_node->parent, extack); esw_vport_qos_prune_empty(vport); - goto unlock; + return err; } =20 if (!vport_node) { @@ -1782,8 +1711,6 @@ int mlx5_esw_devlink_rate_leaf_tc_bw_set(struct devli= nk_rate *rate_leaf, } if (!err) esw_qos_set_tc_arbiter_bw_shares(vport_node, tc_bw, extack); -unlock: - esw_qos_unlock(esw); return err; } =20 @@ -1793,28 +1720,22 @@ int mlx5_esw_devlink_rate_node_tc_bw_set(struct dev= link_rate *rate_node, struct netlink_ext_ack *extack) { struct mlx5_esw_sched_node *node =3D priv; - struct mlx5_eswitch *esw =3D node->esw; bool disable; int err; =20 - if (!esw_qos_validate_unsupported_tc_bw(esw, tc_bw)) { + if (!esw_qos_validate_unsupported_tc_bw(node->esw, tc_bw)) { NL_SET_ERR_MSG_MOD(extack, "E-Switch traffic classes number is not supported"); return -EOPNOTSUPP; } =20 disable =3D esw_qos_tc_bw_disabled(tc_bw); - esw_qos_lock(esw); - if (disable) { - err =3D esw_qos_node_disable_tc_arbitration(node, extack); - goto unlock; - } + if (disable) + return esw_qos_node_disable_tc_arbitration(node, extack); =20 err =3D esw_qos_node_enable_tc_arbitration(node, extack); if (!err) esw_qos_set_tc_arbiter_bw_shares(node, tc_bw, extack); -unlock: - esw_qos_unlock(esw); return err; } =20 @@ -1822,17 +1743,14 @@ int mlx5_esw_devlink_rate_node_tx_share_set(struct = devlink_rate *rate_node, void u64 tx_share, struct netlink_ext_ack *extack) { struct mlx5_esw_sched_node *node =3D priv; - struct mlx5_eswitch *esw =3D node->esw; int err; =20 - err =3D esw_qos_devlink_rate_to_mbps(esw->dev, "tx_share", &tx_share, ext= ack); + err =3D esw_qos_devlink_rate_to_mbps(node->esw->dev, "tx_share", + &tx_share, extack); if (err) return err; =20 - esw_qos_lock(esw); - err =3D esw_qos_set_node_min_rate(node, tx_share, extack); - esw_qos_unlock(esw); - return err; + return esw_qos_set_node_min_rate(node, tx_share, extack); } =20 int mlx5_esw_devlink_rate_node_tx_max_set(struct devlink_rate *rate_node, = void *priv, @@ -1846,10 +1764,7 @@ int mlx5_esw_devlink_rate_node_tx_max_set(struct dev= link_rate *rate_node, void * if (err) return err; =20 - esw_qos_lock(esw); - err =3D esw_qos_sched_elem_config(node, tx_max, node->bw_share, extack); - esw_qos_unlock(esw); - return err; + return esw_qos_sched_elem_config(node, tx_max, node->bw_share, extack); } =20 int mlx5_esw_devlink_rate_node_new(struct devlink_rate *rate_node, void **= priv, @@ -1857,30 +1772,23 @@ int mlx5_esw_devlink_rate_node_new(struct devlink_r= ate *rate_node, void **priv, { struct mlx5_esw_sched_node *node; struct mlx5_eswitch *esw; - int err =3D 0; =20 esw =3D mlx5_devlink_eswitch_get(rate_node->devlink); if (IS_ERR(esw)) return PTR_ERR(esw); =20 - esw_qos_lock(esw); if (esw->mode !=3D MLX5_ESWITCH_OFFLOADS) { NL_SET_ERR_MSG_MOD(extack, "Rate node creation supported only in switchdev mode"); - err =3D -EOPNOTSUPP; - goto unlock; + return -EOPNOTSUPP; } =20 node =3D esw_qos_create_vports_sched_node(esw, extack); - if (IS_ERR(node)) { - err =3D PTR_ERR(node); - goto unlock; - } + if (IS_ERR(node)) + return PTR_ERR(node); =20 *priv =3D node; -unlock: - esw_qos_unlock(esw); - return err; + return 0; } =20 int mlx5_esw_devlink_rate_node_del(struct devlink_rate *rate_node, void *p= riv, @@ -1889,10 +1797,9 @@ int mlx5_esw_devlink_rate_node_del(struct devlink_ra= te *rate_node, void *priv, struct mlx5_esw_sched_node *node =3D priv; struct mlx5_eswitch *esw =3D node->esw; =20 - esw_qos_lock(esw); __esw_qos_destroy_node(node, extack); esw_qos_put(esw); - esw_qos_unlock(esw); + return 0; } =20 @@ -1909,7 +1816,6 @@ mlx5_esw_qos_vport_update_parent(struct mlx5_vport *v= port, return -EOPNOTSUPP; } =20 - esw_qos_lock(esw); if (!vport->qos.sched_node && parent) { enum sched_node_type type; =20 @@ -1920,13 +1826,15 @@ mlx5_esw_qos_vport_update_parent(struct mlx5_vport = *vport, } else if (vport->qos.sched_node) { err =3D esw_qos_vport_update_parent(vport, parent, extack); } - esw_qos_unlock(esw); + return err; } =20 void mlx5_esw_qos_vport_clear_parent(struct mlx5_vport *vport) { + devl_lock(vport->dev->shd); mlx5_esw_qos_vport_update_parent(vport, NULL, NULL); + devl_unlock(vport->dev->shd); } =20 int mlx5_esw_devlink_rate_leaf_parent_set(struct devlink_rate *devlink_rat= e, @@ -1939,13 +1847,8 @@ int mlx5_esw_devlink_rate_leaf_parent_set(struct dev= link_rate *devlink_rate, int err; =20 err =3D mlx5_esw_qos_vport_update_parent(vport, node, extack); - if (!err) { - struct mlx5_eswitch *esw =3D vport->dev->priv.eswitch; - - esw_qos_lock(esw); + if (!err) esw_vport_qos_prune_empty(vport); - esw_qos_unlock(esw); - } =20 return err; } @@ -2071,14 +1974,12 @@ static int mlx5_esw_qos_node_update_parent(struct m= lx5_esw_sched_node *node, struct netlink_ext_ack *extack) { struct mlx5_esw_sched_node *curr_parent; - struct mlx5_eswitch *esw =3D node->esw; int err; =20 err =3D mlx5_esw_qos_node_validate_set_parent(node, parent, extack); if (err) return err; =20 - esw_qos_lock(esw); curr_parent =3D node->parent; if (node->type =3D=3D SCHED_NODE_TYPE_TC_ARBITER_TSAR) { err =3D esw_qos_tc_arbiter_node_update_parent(node, parent, @@ -2088,15 +1989,11 @@ static int mlx5_esw_qos_node_update_parent(struct m= lx5_esw_sched_node *node, } =20 if (err) - goto out; - - esw_qos_normalize_min_rate(esw, curr_parent, extack); - esw_qos_normalize_min_rate(esw, parent, extack); - -out: - esw_qos_unlock(esw); + return err; =20 - return err; + esw_qos_normalize_min_rate(node->esw, curr_parent, extack); + esw_qos_normalize_min_rate(node->esw, parent, extack); + return 0; } =20 int mlx5_esw_devlink_rate_node_parent_set(struct devlink_rate *devlink_rat= e, diff --git a/drivers/net/ethernet/mellanox/mlx5/core/esw/qos.h b/drivers/ne= t/ethernet/mellanox/mlx5/core/esw/qos.h index 0a50982b0e27..f275e850d2c9 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/esw/qos.h +++ b/drivers/net/ethernet/mellanox/mlx5/core/esw/qos.h @@ -6,9 +6,6 @@ =20 #ifdef CONFIG_MLX5_ESWITCH =20 -int mlx5_esw_qos_init(struct mlx5_eswitch *esw); -void mlx5_esw_qos_cleanup(struct mlx5_eswitch *esw); - int mlx5_esw_qos_set_vport_rate(struct mlx5_vport *evport, u32 max_rate, u= 32 min_rate); bool mlx5_esw_qos_get_vport_rate(struct mlx5_vport *vport, u32 *max_rate, = u32 *min_rate); void mlx5_esw_qos_vport_disable(struct mlx5_vport *vport); diff --git a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c b/drivers/ne= t/ethernet/mellanox/mlx5/core/eswitch.c index 4b7a1ce7f406..51eacc286cbb 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c @@ -49,6 +49,7 @@ #include "ecpf.h" #include "en/mod_hdr.h" #include "en_accel/ipsec.h" +#include "sh_devlink.h" =20 enum { MLX5_ACTION_NONE =3D 0, @@ -1618,10 +1619,6 @@ int mlx5_eswitch_enable_locked(struct mlx5_eswitch *= esw, int num_vfs) MLX5_NB_INIT(&esw->nb, eswitch_vport_event, NIC_VPORT_CHANGE); mlx5_eq_notifier_register(esw->dev, &esw->nb); =20 - err =3D mlx5_esw_qos_init(esw); - if (err) - goto err_esw_init; - if (esw->mode =3D=3D MLX5_ESWITCH_LEGACY) { err =3D esw_legacy_enable(esw); } else { @@ -2028,9 +2025,6 @@ int mlx5_eswitch_init(struct mlx5_core_dev *dev) goto reps_err; =20 esw->mode =3D MLX5_ESWITCH_LEGACY; - err =3D mlx5_esw_qos_init(esw); - if (err) - goto reps_err; =20 mutex_init(&esw->offloads.encap_tbl_lock); hash_init(esw->offloads.encap_tbl); @@ -2080,7 +2074,6 @@ void mlx5_eswitch_cleanup(struct mlx5_eswitch *esw) =20 esw_info(esw->dev, "cleanup\n"); =20 - mlx5_esw_qos_cleanup(esw); destroy_workqueue(esw->work_queue); WARN_ON(refcount_read(&esw->qos.refcnt)); mutex_destroy(&esw->state_lock); diff --git a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.h b/drivers/ne= t/ethernet/mellanox/mlx5/core/eswitch.h index 20cf9dd542a1..d145591b3434 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.h +++ b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.h @@ -224,8 +224,9 @@ struct mlx5_vport { =20 struct mlx5_vport_info info; =20 - /* Protected with the E-Switch qos domain lock. The Vport QoS can - * either be disabled (sched_node is NULL) or in one of three states: + /* Protected by mlx5_shd_lock(). + * The Vport QoS can either be disabled (sched_node is NULL) or in one + * of three states: * 1. Regular QoS (sched_node is a vport node). * 2. TC QoS enabled on the vport (sched_node is a TC arbiter). * 3. TC QoS enabled on the vport's parent node @@ -356,7 +357,6 @@ enum { }; =20 struct dentry; -struct mlx5_qos_domain; =20 struct mlx5_eswitch { struct mlx5_core_dev *dev; @@ -383,12 +383,13 @@ struct mlx5_eswitch { struct rw_semaphore mode_lock; atomic64_t user_count; =20 - /* Protected with the E-Switch qos domain lock. */ + /* The QoS tree is stored in mlx5_shd. + * QoS changes are serialized with mlx5_shd_lock(). + */ struct { /* Initially 0, meaning no QoS users and QoS is disabled. */ refcount_t refcnt; u32 root_tsar_ix; - struct mlx5_qos_domain *domain; } qos; =20 struct mlx5_esw_bridge_offloads *br_offloads; diff --git a/drivers/net/ethernet/mellanox/mlx5/core/sh_devlink.c b/drivers= /net/ethernet/mellanox/mlx5/core/sh_devlink.c index 202f4ae99fa9..22fd6e0e4b7a 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/sh_devlink.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/sh_devlink.c @@ -9,6 +9,16 @@ static const struct devlink_ops mlx5_shd_ops =3D { }; =20 +struct mlx5_shd_priv { + struct list_head qos_nodes; +}; + +static int mlx5_shd_priv_init(struct mlx5_shd_priv *shd_priv) +{ + INIT_LIST_HEAD(&shd_priv->qos_nodes); + return 0; +} + int mlx5_shd_init(struct mlx5_core_dev *dev) { struct pci_dev *pdev =3D dev->pdev; @@ -49,13 +59,20 @@ int mlx5_shd_init(struct mlx5_core_dev *dev) *end =3D '\0'; =20 /* Get or create shared devlink instance */ - devlink =3D devlink_shd_get(sn, &mlx5_shd_ops, 0); + devlink =3D devlink_shd_get(sn, &mlx5_shd_ops, + sizeof(struct mlx5_shd_priv)); kfree(sn); if (!devlink) { err =3D -ENOMEM; goto out; } =20 + err =3D mlx5_shd_priv_init(devlink_shd_get_priv(devlink)); + if (err < 0) { + devlink_shd_put(devlink); + return err; + } + dev->shd =3D devlink; out: kfree(vpd_data); @@ -69,3 +86,14 @@ void mlx5_shd_uninit(struct mlx5_core_dev *dev) =20 devlink_shd_put(dev->shd); } + +struct list_head *mlx5_shd_get_qos_nodes(struct mlx5_core_dev *dev) +{ + struct mlx5_shd_priv *shd_priv; + + if (!dev->shd) + return NULL; + devl_assert_locked(dev->shd); + shd_priv =3D devlink_shd_get_priv(dev->shd); + return &shd_priv->qos_nodes; +} diff --git a/drivers/net/ethernet/mellanox/mlx5/core/sh_devlink.h b/drivers= /net/ethernet/mellanox/mlx5/core/sh_devlink.h index 8ab8d6940227..ec6a03471204 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/sh_devlink.h +++ b/drivers/net/ethernet/mellanox/mlx5/core/sh_devlink.h @@ -9,4 +9,6 @@ int mlx5_shd_init(struct mlx5_core_dev *dev); void mlx5_shd_uninit(struct mlx5_core_dev *dev); =20 +struct list_head *mlx5_shd_get_qos_nodes(struct mlx5_core_dev *dev); + #endif /* __MLX5_SH_DEVLINK_H__ */ --=20 2.44.0 From nobody Sat Feb 7 17:09:28 2026 Received: from DM5PR21CU001.outbound.protection.outlook.com (mail-centralusazon11011042.outbound.protection.outlook.com [52.101.62.42]) (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 33E14354AD0; Wed, 28 Jan 2026 11:29:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.62.42 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769599742; cv=fail; b=ONkoZnRFyfMP/+TPs16JSKTcuhcJvpkNEryK7R940rxT+aIntOy73dSSDDI5CXBLtUHcJinCn92OUJCaoHdsrNwAZUI/K0h0t2UqjsoVOdXdJSJsAmJhUIzCpO7ntS71mBIuXxrTC0e4KApKyr5nmYcD14VtCiTyP0GBkTSV9ok= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769599742; c=relaxed/simple; bh=M0fu/5OPmWeOQ4UzhidjqtcBeNtijcyvb1Hxj28Uj0E=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=JfHIlzm7DfL2R0lhgRjiFjVKon3rMCLeY8zqTv0msii0COy3xsLjFXWtwF4bZ7K7U8x3gL/lV21zCz9eX7iEIHIpEmIsjon7mt7GMuvFtJp+OoGRrc2MJdS54SUlaHK4lBpC7wuh/z7o6YsscXgkRgOgudpd3L3UC80SkZiAk+4= 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=tznEwWSp; arc=fail smtp.client-ip=52.101.62.42 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="tznEwWSp" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=y0p/9jL/F9lMwfGtjfZCsm/DqP9I8BJ9Es7qL7z2cTmBN9Vj+vgykcFwnrQsED0EfAmNit3v6bGKD6f3IC2ziZma1IV7NoMEf/a9mPay9C3YmqLR3Frb2Pv3ESlmNlxF8aFw1UcDVLt6uN0gWrww3/Fd1bBITvox+4WU22UAI51InZmPsNLXxlqVFa3PSU2XE+jDTo9hFfBu0XQN8TKJslDc0SgO1eqXNnW5kDz8qwRUjYwyY2Fr+dxlJc63tJMgVdHSl+712arXabdJT+NbReRmvSebtZD5Rl5eWhLGkptyX344jt2dLHenN54HYFzq2EGgGbfiT6FPU/vsd+IXJQ== 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=IsGrIuUMAb+FUG2KyVyDhz0Z9IaNWv+cQkgBkIzgZC0=; b=F4N4KPoRNSF19OH2OB7cqcuywdizB1QvpQ8vXoZ+TX4HjrtZp4rcol4AMrDLN4JZXEG9YiHn1iBUDx0+QZZAMsFpXp579ymoC04LiLXOWrKDoz/5RXuCy0ZlF3o4tB4Lz+obAkSpc7k/+eyFT2njIKxojh7Bj8QY2gqNxNhm7C2+rW5lcFxTeuc9fCp58Wv3epg19daukZA5B4gnNuNQaS3tbuOc0ippN9mi4tR8BjfyqNYp2sXLlDLhtkvSZ6CgB7eXRar764bJk7+SQxTlj1No2V2goW1pDWBeTACh/XmmrOUvUSO96BjkK5CWNJNxknjuTfPZzg328hzdbvTrpQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=google.com 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=IsGrIuUMAb+FUG2KyVyDhz0Z9IaNWv+cQkgBkIzgZC0=; b=tznEwWSpYz7NEfU1cHoeBFJJ5LR8dUmTpia89VSo29rrCAu1OgaOXVrdvU11MYmYKAEUbMVvTwD+yHF5P9fqZmhpaDZguysJ8tWwGw8Pe5T9nC7WCIeKUPdJ3jNge0Dci7rScVBBF/ILfpK11fSzeB2d2RnBPXQWr4bfwoFQzpTYqkLY+WllN93yaQtncb5RCBcwIF9+Ii7+JvfP9i8RdU8tv9RHNcMOCVaqzTJeg0Z5iI1Ae0gJdwahbs7MFAPlfqEnclKjayRr5ruC4GgbmCo1BZK0iiqkTGsAZe82K8lNlWVdAlogGGrAdXYtQ5R1pgBulsOvYwQPYfYYk2jz8w== Received: from BN9PR03CA0273.namprd03.prod.outlook.com (2603:10b6:408:f5::8) by IA1PR12MB8585.namprd12.prod.outlook.com (2603:10b6:208:451::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9542.15; Wed, 28 Jan 2026 11:28:55 +0000 Received: from BN1PEPF0000467F.namprd03.prod.outlook.com (2603:10b6:408:f5:cafe::a1) by BN9PR03CA0273.outlook.office365.com (2603:10b6:408:f5::8) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9564.8 via Frontend Transport; Wed, 28 Jan 2026 11:28:53 +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 BN1PEPF0000467F.mail.protection.outlook.com (10.167.243.84) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9564.3 via Frontend Transport; Wed, 28 Jan 2026 11:28:55 +0000 Received: from rnnvmail202.nvidia.com (10.129.68.7) 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.20; Wed, 28 Jan 2026 03:28:43 -0800 Received: from rnnvmail205.nvidia.com (10.129.68.10) by rnnvmail202.nvidia.com (10.129.68.7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.20; Wed, 28 Jan 2026 03:28:42 -0800 Received: from vdi.nvidia.com (10.127.8.10) by mail.nvidia.com (10.129.68.10) with Microsoft SMTP Server id 15.2.2562.20 via Frontend Transport; Wed, 28 Jan 2026 03:28:37 -0800 From: Tariq Toukan To: Eric Dumazet , Jakub Kicinski , Paolo Abeni , Andrew Lunn , "David S. Miller" CC: Donald Hunter , Jiri Pirko , Jonathan Corbet , Saeed Mahameed , "Leon Romanovsky" , Tariq Toukan , Mark Bloch , , , , , Gal Pressman , Moshe Shemesh , Carolina Jubran , Cosmin Ratiu , Jiri Pirko , Randy Dunlap , Simon Horman , Krzysztof Kozlowski Subject: [PATCH net-next V7 13/14] net/mlx5: qos: Support cross-device tx scheduling Date: Wed, 28 Jan 2026 13:25:43 +0200 Message-ID: <20260128112544.1661250-14-tariqt@nvidia.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20260128112544.1661250-1-tariqt@nvidia.com> References: <20260128112544.1661250-1-tariqt@nvidia.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN1PEPF0000467F:EE_|IA1PR12MB8585:EE_ X-MS-Office365-Filtering-Correlation-Id: f6cfaa41-64b4-4569-2610-08de5e606bf7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|82310400026|36860700013|376014|7416014; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?5rObm3Jst/ApdmS90EQZ/K4JTdZN4BO9t3QKTg2CBaqJ8radaduUc3f90WvJ?= =?us-ascii?Q?6fz70N9gw5QN7N/hJky/2MZ75OayoxUTcROSi4Eb8BjNlRqVBKYDliO7zgQF?= =?us-ascii?Q?6XbAqf4njmadyOnh0P+AlcUKfnUm1kC3s5fA7ofXxV/7XQnCmPlKReIQEfdo?= =?us-ascii?Q?JP9FDtvmCCuj87sNODtguiyD/GZH11GFLHIE2On4ZlIi+3SU8y7NHLX1BJ13?= =?us-ascii?Q?4ulAQl2V2y+8hy08k2Bkq5vVkkHKQ8eQX6dHR3rmdcbyIAbyVBWS2HGi9RHs?= =?us-ascii?Q?KzOwRIiwm/5HRPJEQbzMM+s9i8i8IRrgpchSxX5TTI1/cBZRJstOpslqNTeH?= =?us-ascii?Q?kDyorgFLt8MTVcVPOmKm1Z87rpcIOEu3ihThQC9Y2DrNiMJv3kD4vyWehJ4A?= =?us-ascii?Q?JRq7GSoiR53BakPoeH1/qKfbIS99jmguFRf1A1SBKG2wGRz73e4s6GhHmmL7?= =?us-ascii?Q?vAiUHszFbGC1afkwxOaAmvuBnL64U0GWbmOG7AnLHSFvt8Jo47eiQAnL948l?= =?us-ascii?Q?CAnqqzEYxSt61g3b7O5XxKwCagkuaI/swOrbSF4B5eNTcSfwI07XHISN6+py?= =?us-ascii?Q?i8bVuuctqjvGkngvM3i0P+V+UqBavfqN9MhpW4kXU/ZcPiYIPmenV+ZfIgAN?= =?us-ascii?Q?3cwpqVBGnnJCPSewQU9aNLulycgLHkReSNqMG8hSE6paduy8fHNFfSksyWA6?= =?us-ascii?Q?asr5z0JtmKxzA7i8Qzn17reFQarzB/CVjEatSZz6z3kvCS4gBj+qQRIsA2Q2?= =?us-ascii?Q?CXKgCIqFD3U1aIGOGYtYdZVqA91R5wcQIoCIsdqfGCqUZRGEkL4lnXqk24Uq?= =?us-ascii?Q?wOaCufDAFAQbPGp4H2X5XQDH01H7I38IZB5I22bgy0SpeEVi22okH3HQFhNo?= =?us-ascii?Q?GucTIuoBRX96gomWKytg0Oof3hbPY4uekE+xHrZqvXCk0kv5sQZAthyhp0lO?= =?us-ascii?Q?o+wEoj2Mb04vsodiOv/X9iT7nNUowKsJFj4w9gvLCxcif2nKcFFipCXSfNKb?= =?us-ascii?Q?J4zC1ppSiXbvDuahqxQCv3l7qBXRzx9szJysFRTSMo+7EaWA/t3ThZZTAkPe?= =?us-ascii?Q?7F9WYWm2SThFqx9F3TVTycBScYVBUPbHoFvV7ftmMIihCB4cb85Yuqplf2AM?= =?us-ascii?Q?5/WNg0XGR3BbTl+RUudFcmPv7xlBsvYKhkaax8syQQ9R3CEgb3joqR3I6VDE?= =?us-ascii?Q?hcj8HkI8zG8yeF1ajsqyJs0Rt5zZlVTdnJmhW1jQUszzZodehBOS4iIf/21j?= =?us-ascii?Q?e6okkf51Idssy+DZwsNuvMtVXuDeEMiLqs46R/6ePWR8gUHcvgx2Lx0QR8SL?= =?us-ascii?Q?eItSaQMy5odGOF4hnO18Ax8uuZLh9CG5l+RK7NQh0qhbIu1Ox3A/lmOtDu4B?= =?us-ascii?Q?0z//v8IxgqZTwVRwByFPe1JYAJD9l34UY5skGfQCMCCP5xB0MMGemIv+SAsy?= =?us-ascii?Q?VeS6Am04VxNNhmDBPF05qQJIbcBGIRSL1BluH8vQGMet1VtH8qMR0EgMnuNY?= =?us-ascii?Q?b/HsAssmU4rUnhd+4jFOycKKKvB0jqz7GdotbeMFSxWIU1R5I+cZwk5a0ZvZ?= =?us-ascii?Q?ySddtRM7HclT/6vvY6//q6bXdv/NSgx01e5vllrwYkZRZ4c0o6dpduDEXHQP?= =?us-ascii?Q?9celqIx37Bmb/2yZCmFutENzS2aPuEEj9ONhVPcgiUGDx4DtUWRfkomp8VTR?= =?us-ascii?Q?TQ2y/Q=3D=3D?= 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)(1800799024)(82310400026)(36860700013)(376014)(7416014);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Jan 2026 11:28:55.2642 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f6cfaa41-64b4-4569-2610-08de5e606bf7 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: BN1PEPF0000467F.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB8585 Content-Type: text/plain; charset="utf-8" From: Cosmin Ratiu Up to now, rate groups could only contain vports from the same E-Switch. This patch relaxes that restriction if the device supports it (HCA_CAP.esw_cross_esw_sched =3D=3D true) and the right conditions are met: - Link Aggregation (LAG) is enabled. - The E-Switches are from the same shared devlink device. Signed-off-by: Cosmin Ratiu Reviewed-by: Carolina Jubran Signed-off-by: Tariq Toukan --- .../net/ethernet/mellanox/mlx5/core/esw/qos.c | 122 ++++++++++++------ 1 file changed, 86 insertions(+), 36 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/esw/qos.c b/drivers/ne= t/ethernet/mellanox/mlx5/core/esw/qos.c index 0d187399d846..b4abb6fa2168 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/esw/qos.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/esw/qos.c @@ -50,7 +50,9 @@ struct mlx5_esw_sched_node { enum sched_node_type type; /* The eswitch this node belongs to. */ struct mlx5_eswitch *esw; - /* The children nodes of this node, empty list for leaf nodes. */ + /* The children nodes of this node, empty list for leaf nodes. + * Can be from multiple E-Switches. + */ struct list_head children; /* Valid only if this node is associated with a vport. */ struct mlx5_vport *vport; @@ -419,6 +421,7 @@ esw_qos_vport_create_sched_element(struct mlx5_esw_sche= d_node *vport_node, struct mlx5_esw_sched_node *parent =3D vport_node->parent; u32 sched_ctx[MLX5_ST_SZ_DW(scheduling_context)] =3D {}; struct mlx5_core_dev *dev =3D vport_node->esw->dev; + struct mlx5_vport *vport =3D vport_node->vport; void *attr; =20 if (!mlx5_qos_element_type_supported( @@ -430,11 +433,18 @@ esw_qos_vport_create_sched_element(struct mlx5_esw_sc= hed_node *vport_node, MLX5_SET(scheduling_context, sched_ctx, element_type, SCHEDULING_CONTEXT_ELEMENT_TYPE_VPORT); attr =3D MLX5_ADDR_OF(scheduling_context, sched_ctx, element_attributes); - MLX5_SET(vport_element, attr, vport_number, vport_node->vport->vport); + MLX5_SET(vport_element, attr, vport_number, vport->vport); MLX5_SET(scheduling_context, sched_ctx, parent_element_id, parent ? parent->ix : vport_node->esw->qos.root_tsar_ix); MLX5_SET(scheduling_context, sched_ctx, max_average_bw, vport_node->max_rate); + if (vport->dev !=3D dev) { + /* The port is assigned to a node on another eswitch. */ + MLX5_SET(vport_element, attr, eswitch_owner_vhca_id_valid, + true); + MLX5_SET(vport_element, attr, eswitch_owner_vhca_id, + MLX5_CAP_GEN(vport->dev, vhca_id)); + } =20 return esw_qos_node_create_sched_element(vport_node, sched_ctx, extack); } @@ -446,6 +456,7 @@ esw_qos_vport_tc_create_sched_element(struct mlx5_esw_s= ched_node *vport_tc_node, { u32 sched_ctx[MLX5_ST_SZ_DW(scheduling_context)] =3D {}; struct mlx5_core_dev *dev =3D vport_tc_node->esw->dev; + struct mlx5_vport *vport =3D vport_tc_node->vport; void *attr; =20 if (!mlx5_qos_element_type_supported( @@ -457,8 +468,7 @@ esw_qos_vport_tc_create_sched_element(struct mlx5_esw_s= ched_node *vport_tc_node, MLX5_SET(scheduling_context, sched_ctx, element_type, SCHEDULING_CONTEXT_ELEMENT_TYPE_VPORT_TC); attr =3D MLX5_ADDR_OF(scheduling_context, sched_ctx, element_attributes); - MLX5_SET(vport_tc_element, attr, vport_number, - vport_tc_node->vport->vport); + MLX5_SET(vport_tc_element, attr, vport_number, vport->vport); MLX5_SET(vport_tc_element, attr, traffic_class, vport_tc_node->tc); MLX5_SET(scheduling_context, sched_ctx, max_bw_obj_id, rate_limit_elem_ix); @@ -466,6 +476,13 @@ esw_qos_vport_tc_create_sched_element(struct mlx5_esw_= sched_node *vport_tc_node, vport_tc_node->parent->ix); MLX5_SET(scheduling_context, sched_ctx, bw_share, vport_tc_node->bw_share); + if (vport->dev !=3D dev) { + /* The port is assigned to a node on another eswitch. */ + MLX5_SET(vport_tc_element, attr, eswitch_owner_vhca_id_valid, + true); + MLX5_SET(vport_tc_element, attr, eswitch_owner_vhca_id, + MLX5_CAP_GEN(vport->dev, vhca_id)); + } =20 return esw_qos_node_create_sched_element(vport_tc_node, sched_ctx, extack); @@ -1194,6 +1211,29 @@ static int esw_qos_vport_tc_check_type(enum sched_no= de_type curr_type, return 0; } =20 +static bool esw_qos_validate_unsupported_tc_bw(struct mlx5_eswitch *esw, + u32 *tc_bw) +{ + int i, num_tcs =3D esw_qos_num_tcs(esw->dev); + + for (i =3D num_tcs; i < DEVLINK_RATE_TCS_MAX; i++) + if (tc_bw[i]) + return false; + + return true; +} + +static bool esw_qos_vport_validate_unsupported_tc_bw(struct mlx5_vport *vp= ort, + u32 *tc_bw) +{ + struct mlx5_esw_sched_node *node =3D vport->qos.sched_node; + struct mlx5_eswitch *esw =3D vport->dev->priv.eswitch; + + esw =3D (node && node->parent) ? node->parent->esw : esw; + + return esw_qos_validate_unsupported_tc_bw(esw, tc_bw); +} + static int esw_qos_vport_update(struct mlx5_vport *vport, enum sched_node_type type, struct mlx5_esw_sched_node *parent, @@ -1213,8 +1253,17 @@ static int esw_qos_vport_update(struct mlx5_vport *v= port, if (err) return err; =20 - if (curr_type =3D=3D SCHED_NODE_TYPE_TC_ARBITER_TSAR && curr_type =3D=3D = type) + if (curr_type =3D=3D SCHED_NODE_TYPE_TC_ARBITER_TSAR && curr_type =3D=3D = type) { + struct mlx5_eswitch *esw =3D parent ? + parent->esw : vport->dev->priv.eswitch; + esw_qos_tc_arbiter_get_bw_shares(vport_node, curr_tc_bw); + if (!esw_qos_validate_unsupported_tc_bw(esw, curr_tc_bw)) { + NL_SET_ERR_MSG_MOD(extack, + "Unsupported traffic classes on the new device"); + return -EOPNOTSUPP; + } + } =20 esw_qos_vport_disable(vport, extack); =20 @@ -1224,10 +1273,9 @@ static int esw_qos_vport_update(struct mlx5_vport *v= port, extack =3D NULL; } =20 - if (curr_type =3D=3D SCHED_NODE_TYPE_TC_ARBITER_TSAR && curr_type =3D=3D = type) { + if (curr_type =3D=3D SCHED_NODE_TYPE_TC_ARBITER_TSAR && curr_type =3D=3D = type) esw_qos_set_tc_arbiter_bw_shares(vport_node, curr_tc_bw, extack); - } =20 return err; } @@ -1575,30 +1623,6 @@ static int esw_qos_devlink_rate_to_mbps(struct mlx5_= core_dev *mdev, const char * return 0; } =20 -static bool esw_qos_validate_unsupported_tc_bw(struct mlx5_eswitch *esw, - u32 *tc_bw) -{ - int i, num_tcs =3D esw_qos_num_tcs(esw->dev); - - for (i =3D num_tcs; i < DEVLINK_RATE_TCS_MAX; i++) { - if (tc_bw[i]) - return false; - } - - return true; -} - -static bool esw_qos_vport_validate_unsupported_tc_bw(struct mlx5_vport *vp= ort, - u32 *tc_bw) -{ - struct mlx5_esw_sched_node *node =3D vport->qos.sched_node; - struct mlx5_eswitch *esw =3D vport->dev->priv.eswitch; - - esw =3D (node && node->parent) ? node->parent->esw : esw; - - return esw_qos_validate_unsupported_tc_bw(esw, tc_bw); -} - static bool esw_qos_tc_bw_disabled(u32 *tc_bw) { int i; @@ -1803,18 +1827,44 @@ int mlx5_esw_devlink_rate_node_del(struct devlink_r= ate *rate_node, void *priv, return 0; } =20 +static int +mlx5_esw_validate_cross_esw_scheduling(struct mlx5_eswitch *esw, + struct mlx5_esw_sched_node *parent, + struct netlink_ext_ack *extack) +{ + if (!parent || esw =3D=3D parent->esw) + return 0; + + if (!MLX5_CAP_QOS(esw->dev, esw_cross_esw_sched)) { + NL_SET_ERR_MSG_MOD(extack, + "Cross E-Switch scheduling is not supported"); + return -EOPNOTSUPP; + } + if (esw->dev->shd !=3D parent->esw->dev->shd) { + NL_SET_ERR_MSG_MOD(extack, + "Cannot add vport to a parent belonging to a different device"); + return -EOPNOTSUPP; + } + if (!mlx5_lag_is_active(esw->dev)) { + NL_SET_ERR_MSG_MOD(extack, + "Cross E-Switch scheduling requires LAG to be activated"); + return -EOPNOTSUPP; + } + + return 0; +} + static int mlx5_esw_qos_vport_update_parent(struct mlx5_vport *vport, struct mlx5_esw_sched_node *parent, struct netlink_ext_ack *extack) { struct mlx5_eswitch *esw =3D vport->dev->priv.eswitch; - int err =3D 0; + int err; =20 - if (parent && parent->esw !=3D esw) { - NL_SET_ERR_MSG_MOD(extack, "Cross E-Switch scheduling is not supported"); - return -EOPNOTSUPP; - } + err =3D mlx5_esw_validate_cross_esw_scheduling(esw, parent, extack); + if (err) + return err; =20 if (!vport->qos.sched_node && parent) { enum sched_node_type type; --=20 2.44.0 From nobody Sat Feb 7 17:09:28 2026 Received: from CO1PR03CU002.outbound.protection.outlook.com (mail-westus2azon11010063.outbound.protection.outlook.com [52.101.46.63]) (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 22BC4350A35; Wed, 28 Jan 2026 11:29:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.46.63 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769599748; cv=fail; b=hVRJqBFgjvRDJnM7Q6IO1RX48D4evvnQGsiHRBDenQOezjwuTdCZzpfupxyZD1ac2XS2I4w5UENIXq4D40NvP3Zw/xA8LJ9uIHYpqCxi/8WaZ4po3FTQdINakqfnldPeINDV+IZdP8WS7Gp51audTIQ/d0EvnfAgwkPBiSgzMuk= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769599748; c=relaxed/simple; bh=4eeUc9RIHIgWXag318UGpUedrMXCEQ+cUkvCB4gfNTs=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=sv43yVLja0+q2LCaVYq56zoLT7mZAzFASyTE/w7VvYvUGgzVkB0p4/8uw+6g9mZmjKYIRirsyWefpQz59aGoENweyyMsV3y8bAUzq5p9Ryj5kc3zPyULsbst0/Vq6+rl69NvO4T7hklRanlBpXl/Uhb1o+WPN+2NCNJTyiemzzM= 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=rIl2ppYp; arc=fail smtp.client-ip=52.101.46.63 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="rIl2ppYp" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=XNqKtbGMfztUHSpHlSBjRSDrv/IUsfAq15smfoPd+wSwU5yPMYwvsDIRjlddvbur9sQZjBrPVi3Yt5hPt6lW5r0/mLqcjm+ix6QprXg7lNAXkdnUHJE8cAWxjkIJzOYXb1tJTaTxlmYwGfZmdBnaG9r1F0rqfGKDOn78Tl4LNDEhHuK5YxBq64SzP4UccWSCJahOqtnrN7cFIXu2YOlzt9pmIsuQ3JJdd0NNSSONobQGNvXzgzUZNuoIdTElO9xy98pCCCxHkf5bWsLScSsyFApiK1zl42jLq/Cr0jeH0PgLG8cHQMam6bWSqejL96x9kdDqC5cVxAMSYRO+rDigsA== 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=2unoNL8G4Xxr5VtprXpzS1NFU/fJvHFzPSMcT54g87Y=; b=SRz0PCDfBODDYM+X2gFBM8f9jd/RG9WoQ6JcXJtzZjdS8R6hGHscE0gjHOQSuXmj4/u7d/+rU8/qVFzwX4bnHimBm8B9qk1kkD3vrnnIXVyKaf6fGhL+CD0ABt9RPa6tBp61UI9VVt+r5+Ffh4cyCEvheyCaNgRBu16A4Cz+TYYinnnJtg/B5EQOTHSU1sfmeZH3mkGsaQLKdomSvx6W3nzlX9A/D01NOOUTbk0XDvWDcQVzZL4Y5Qnj1eZCKdUYQ+3Ip6wfuDXoyq2qMDi6+2xWuCFFSWKTGW5mjaxJJ1dxQ6zogBcRe5qPXn/2ttL8jyhNq5WZyZTe+1YUfMgtzg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=google.com 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=2unoNL8G4Xxr5VtprXpzS1NFU/fJvHFzPSMcT54g87Y=; b=rIl2ppYp2cfjujQeOwBzqnEfKVpYA5um+62CO6PkmrZfDjqECXTcicD9ur/fTklWsCUqewcWjD0i4L1U3v8r8Amf5BLiXNckvg/NdDL4VmO4g311IiqB7mKC9QSAONhwwAKOCuWbFh4kpRkyVQJYIuV+TUsisA3ubKSTRHQQeOLWfzoDFF6oUF2qPkjRs9S60ng+ztb/QlW3n6Z9xm0NRyLSvz9Dz0eixe2iu8ongdnK+MBR+IY8hThLEnrddYBAFltAESgy2Qr6kaMIN8+cbrjPFjGyRtbRaKiYaQ7M7tfkAdtd2OohBziyAzBj34t3n9neBd8IGnbuZHWW7XKs7A== Received: from SA0PR11CA0047.namprd11.prod.outlook.com (2603:10b6:806:d0::22) by DM4PR12MB7503.namprd12.prod.outlook.com (2603:10b6:8:111::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9542.16; Wed, 28 Jan 2026 11:29:01 +0000 Received: from SN1PEPF0002BA52.namprd03.prod.outlook.com (2603:10b6:806:d0:cafe::34) by SA0PR11CA0047.outlook.office365.com (2603:10b6:806:d0::22) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9542.15 via Frontend Transport; Wed, 28 Jan 2026 11:29:00 +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 SN1PEPF0002BA52.mail.protection.outlook.com (10.167.242.75) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9564.3 via Frontend Transport; Wed, 28 Jan 2026 11:29:00 +0000 Received: from rnnvmail202.nvidia.com (10.129.68.7) 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.2562.20; Wed, 28 Jan 2026 03:28:49 -0800 Received: from rnnvmail205.nvidia.com (10.129.68.10) by rnnvmail202.nvidia.com (10.129.68.7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.20; Wed, 28 Jan 2026 03:28:48 -0800 Received: from vdi.nvidia.com (10.127.8.10) by mail.nvidia.com (10.129.68.10) with Microsoft SMTP Server id 15.2.2562.20 via Frontend Transport; Wed, 28 Jan 2026 03:28:43 -0800 From: Tariq Toukan To: Eric Dumazet , Jakub Kicinski , Paolo Abeni , Andrew Lunn , "David S. Miller" CC: Donald Hunter , Jiri Pirko , Jonathan Corbet , Saeed Mahameed , "Leon Romanovsky" , Tariq Toukan , Mark Bloch , , , , , Gal Pressman , Moshe Shemesh , Carolina Jubran , Cosmin Ratiu , Jiri Pirko , Randy Dunlap , Simon Horman , Krzysztof Kozlowski Subject: [PATCH net-next V7 14/14] net/mlx5: Document devlink rates Date: Wed, 28 Jan 2026 13:25:44 +0200 Message-ID: <20260128112544.1661250-15-tariqt@nvidia.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20260128112544.1661250-1-tariqt@nvidia.com> References: <20260128112544.1661250-1-tariqt@nvidia.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN1PEPF0002BA52:EE_|DM4PR12MB7503:EE_ X-MS-Office365-Filtering-Correlation-Id: be471104-1475-4262-6387-08de5e606f2e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|82310400026|376014|7416014|36860700013; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?8IRZeV+d+M7Lmw9P6vweNwL5C4I4Vs75MYChM+YZu4uRU1nRj5dEHrpf/xgu?= =?us-ascii?Q?9ugYIQYEioEtEIkyxyuRf4KjBfmDcXgCiv0L9labK6p2IQbs7mAFAUpEQutf?= =?us-ascii?Q?+Oup3Z4GanFj8ZzP7c/0o/M4jeYheNLEoU/INzsewQvDSBLqBCI5KImKDrHh?= =?us-ascii?Q?j80gZp7S6SoyK8Hp5yiR71JSITY3vAlnPRHUxjo+Kix4egZfOvStUn/NoioN?= =?us-ascii?Q?WWOnCCTSjT02V1c5FhS7Fr9IvtGM0m/eUqScOEAI4qz6ahKR8LJ3eRlbjCWv?= =?us-ascii?Q?2fjQOntT2VbWZKVJCjGYdTSHcr9Q0KQ5YS78KC9T5v0qlwrevumi8Y9ADNc0?= =?us-ascii?Q?3ggiUuzV7KNwmWEtN4jINHc3RShYIIbwfF+lNl8l+R6U7yaqY7NxrpJpLVGI?= =?us-ascii?Q?lz5Yz08GOOdnRm9Zr/GleZOeLR6LxXEk1DaNawkjgctGDl2CkcI+vjvCKd2k?= =?us-ascii?Q?UbQZ30dP6gshlqkE48B+yVifhhslZDPgoww0VMqfLoxxOT1yVNsg8M5KOJ39?= =?us-ascii?Q?pk+4DK1/oGV1k79YiRlUe9tHbpBo/OfolCaRNlF9lo/WUHA9WIECz41a5wx8?= =?us-ascii?Q?1EtIDdsF8HFFCQ7hZUKamPbgh4VEvqI2xorQAXVGoszN37FWqga8LSzQKN6g?= =?us-ascii?Q?3y768HyBOhve63yhvxe2i4BTwzuLQ+3SoDH0BwPeNRun2l1FTSqdqzv3VuKk?= =?us-ascii?Q?MhAvldMaQrZIOa6UpD0axstou1IR6JWUtXLTkj+keaQCfbDSHSrK7ONS9i/F?= =?us-ascii?Q?ywZJ0r5C9rSaqGYZL33uF1qUwktszCt/07lt4Cbs60wXq8a8z4JxM5LvkUIM?= =?us-ascii?Q?KZcWdps4yPvXNGcFceJ+jzsWSD6IBIJCVjX19V3mmz2PD6tvK6JKb3rhkEiq?= =?us-ascii?Q?beVr4+UwhmkbNoUQq06GEeVV90fFTjj5ZtpjJnqq2MJKUHFkkm9w/e0OqiKo?= =?us-ascii?Q?od6/dRUYOWIuAoOHDkQj1OLsbLQl99VzelXNtl2ac+Lk2NvWrEHvcAlz6XtU?= =?us-ascii?Q?VeeryN0Nh2BIcAXnpIFOe4LVPK9dwpKMWz4x2xwbvTvbJWVAde3ubbbNF/bc?= =?us-ascii?Q?gmcKFCja4xM1kmdWOMFncrpQFotrlRCYbV9h2GsBhqm9gnd8k7/cT8Eg89CN?= =?us-ascii?Q?l2Fbh7NYSGWwQLJ2GBy6IEX32u2rOO6K8n3rRg5Dx4lP9HzfTI6brSRV5N0/?= =?us-ascii?Q?lWng+HjbFVEFheaKR9h6Wb1qYPRw2NiUJokybY/lFO6IdF1fUUVZcp6Lf50T?= =?us-ascii?Q?cpy8J4hp15D+cVGOEnbI8T3BEnIWpbml55ir69Dh1ofsZKVyUUw3bkE0VZSt?= =?us-ascii?Q?FusqDLvAgm57umM/ypiYE5KEmhMPsAQhOm9RO2V92TxOXdiP9MM9s5PTZMSW?= =?us-ascii?Q?Ql5zMG/Jog7KjOfZ0VdP7vYCRW2xeITN/eb5arQp8sZzEENN5sAUUycMM8gx?= =?us-ascii?Q?0R+EKYfsQ6rYuxc/LAxKRQ1KdwD6OaOnQcbig61vDS7e8q6DDg3p+9GnqtZ1?= =?us-ascii?Q?elVCVQjjOBPqun8i+cndfQNY/u2KgYnKyKw5cCgx/NxkXCbeZfOqXc6bj0uI?= =?us-ascii?Q?dOf/8lczzb3mjlb/jSzZWMjrSESt7Ze83/4W7+tMjAwOKVjLu7ifQObT9kcX?= =?us-ascii?Q?v2zm/mrC/2KW4YHitYqWIBNygG9p9n9m6hZ3FY8Gps7YOV9LDSVafsnx6dqG?= =?us-ascii?Q?osFSWQ=3D=3D?= X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230040)(1800799024)(82310400026)(376014)(7416014)(36860700013);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Jan 2026 11:29:00.7225 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: be471104-1475-4262-6387-08de5e606f2e 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: SN1PEPF0002BA52.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB7503 Content-Type: text/plain; charset="utf-8" From: Cosmin Ratiu It seems rates were not documented in the mlx5-specific file, so add examples on how to limit VFs and groups and also provide an example of the intended way to achieve cross-esw scheduling. Signed-off-by: Cosmin Ratiu Reviewed-by: Carolina Jubran Signed-off-by: Tariq Toukan --- Documentation/networking/devlink/mlx5.rst | 33 +++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/Documentation/networking/devlink/mlx5.rst b/Documentation/netw= orking/devlink/mlx5.rst index 4bba4d780a4a..62c4d7bf0877 100644 --- a/Documentation/networking/devlink/mlx5.rst +++ b/Documentation/networking/devlink/mlx5.rst @@ -419,3 +419,36 @@ User commands examples: =20 .. note:: This command can run over all interfaces such as PF/VF and representor = ports. + +Rates +=3D=3D=3D=3D=3D + +mlx5 devices can limit transmission of individual VFs or a group of them v= ia +the devlink-rate API in switchdev mode. + +User commands examples: + +- Print the existing rates:: + + $ devlink port function rate show + +- Set a max tx limit on traffic from VF0:: + + $ devlink port function rate set pci/0000:82:00.0/1 tx_max 10Gbit + +- Create a rate group with a max tx limit and adding two VFs to it:: + + $ devlink port function rate add pci/0000:82:00.0/group1 tx_max 10Gbit + $ devlink port function rate set pci/0000:82:00.0/1 parent group1 + $ devlink port function rate set pci/0000:82:00.0/2 parent group1 + +- Same scenario, with a min guarantee of 20% of the bandwidth for the firs= t VFs:: + + $ devlink port function rate add pci/0000:82:00.0/group1 tx_max 10Gbit + $ devlink port function rate set pci/0000:82:00.0/1 parent group1 tx_s= hare 2Gbit + $ devlink port function rate set pci/0000:82:00.0/2 parent group1 + +- Cross-device scheduling:: + + $ devlink port function rate add pci/0000:82:00.0/group1 tx_max 10Gbit + $ devlink port function rate set pci/0000:82:00.1/32769 parent pci/000= 0:82:00.0/group1 --=20 2.44.0