From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from SN4PR2101CU001.outbound.protection.outlook.com (mail-southcentralusazon11012013.outbound.protection.outlook.com [40.93.195.13]) (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 8D58B34EF05; Thu, 26 Mar 2026 07:01:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.93.195.13 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774508496; cv=fail; b=u38vsyqeMn5e0OTubEvMDS96Wxz/ZkNybVnmgZsmfrQShbnzFPyldl2/VfWTydoG73A6LO9nmCUKc7tsPQF9nYPX4Ici6yzWpRxieY7Oc9GJKhUT1P6jjwVxihKe1mkW33qrGn7+4BdktHSlR2tprZpi6xQTlA6rgI7D7L/9bts= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774508496; c=relaxed/simple; bh=Dg7wX5H+kvpkmqTezdFMbj/IYYIg4wE+6SZZK5g2tJE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=uefNm9xhu3EudZF619TtqetpGbh20xpbABnd6RtT8/7CGMZ7yZ2nooJmWbdpINKYJosuam8Xvl+PrUHg4cVrdV45LpFudiZo9Pdy0YCFzFZhhgS19G/eHhshYM7qxvvjhs5qKgEfFri21EoVbcwAvFY2Y9LPTrC5XlgCI/izqTI= 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=Y/YLMFiS; arc=fail smtp.client-ip=40.93.195.13 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="Y/YLMFiS" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=WObMlZ7+6tMiNVvj7wHo75YOARJJGEbeXlkM4kDSctPrGJ3jlRmMMJ0FrYdL4KOwFok8yY3jw01PL28e6L72CbZ6F5Hv1aSHTTPKLmvcghofyZ6MfwW9D/y12bc0GM5xWkMLV5NY8twnssz3W9jL1uSCts7Nc6xB/wkVEdrGYJX+SebOzYzkldrdboTnkeRLyk+2hfV1/g02kYb9yPU34CxQXe7H3bV6llZqzcBh/hj1yGCE1Y4QeXbsyZNWj8v99xrXB5A4GcjF78z9ufDwkCTFgkbMMXnOT1AJ6a4wA8ckB0rdQT5MfCaa5d3xGjJFYc7jfCzmw7dqzSkx4jxVMg== 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=IsicyKUJvobH8RjMVSM6RAsIi2KLcNEhNIzJ/7Nf+iw=; b=tAKXiDegKn1vU6/bA/IxKGUDfr5DSZCaVKcAHnHvGa3HJyc/SzGADQRxtlpDFzR4FI87SafWVY1UbRpeh3CawMkHqTtyxTOZSPovQ1szDsodDPuw11XDa3qVwXANxEaHNxMKKHh803OGzOQyK24TdrdwA/TIUrNpRadO9x2pfmQVYXJLHm9GoiqF1mECnX+61pImxOfTdQh3g/KD1cxxnRywb3aMcfeVQonDG9TVWiSs7mIk82kRHFzKpItlWrf9xikX0Q2PclgzuydG5pMfspWmj47iF33ni0i37Ngl5nF4YC1CGhfPgRU/TnN1lMnQZbntNGv8mCmj1Ih0TrJqAg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.232) 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=IsicyKUJvobH8RjMVSM6RAsIi2KLcNEhNIzJ/7Nf+iw=; b=Y/YLMFiS8Tma0YPVMFT887yB0y+EvUwGItfE0x787ZmCxyW/S1VBHs9Mu01ASiDTSR+iAIQdFzc4PE7QEt+fiX2GS8aj9PYjnWxp8yd5XKDF7Tjbo0iiRUiwo9WKsU4uQsrYb3EyN815B/3OHScQvuV48j3w2P4ykfMopVkgJGuVlfz6qBekKYVh1QQqRKPJtHf0eER0UROQ3jV9AynzNrBf4XpeQc52ky8wSYCaBlzl8a10arfR3XrvpJ6tKgr825JdMhmrAP78ae7gTveR5BzEdZrDO8lYwa2rVUstTQiCpRW1FqhZFGkzlMuReKbIy0rtETRjWri5w7rMOejpaw== Received: from MN0PR04CA0006.namprd04.prod.outlook.com (2603:10b6:208:52d::23) by DS7PR12MB5768.namprd12.prod.outlook.com (2603:10b6:8:77::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9745.20; Thu, 26 Mar 2026 07:01:24 +0000 Received: from BN2PEPF00004FBC.namprd04.prod.outlook.com (2603:10b6:208:52d:cafe::f9) by MN0PR04CA0006.outlook.office365.com (2603:10b6:208:52d::23) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9723.32 via Frontend Transport; Thu, 26 Mar 2026 07:01:18 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.118.232) 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.118.232 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.118.232; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.118.232) by BN2PEPF00004FBC.mail.protection.outlook.com (10.167.243.182) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9745.21 via Frontend Transport; Thu, 26 Mar 2026 07:01:24 +0000 Received: from drhqmail203.nvidia.com (10.126.190.182) by mail.nvidia.com (10.127.129.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.20; Thu, 26 Mar 2026 00:01:14 -0700 Received: from drhqmail202.nvidia.com (10.126.190.181) by drhqmail203.nvidia.com (10.126.190.182) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.20; Thu, 26 Mar 2026 00:01:13 -0700 Received: from vdi.nvidia.com (10.127.8.10) by mail.nvidia.com (10.126.190.181) with Microsoft SMTP Server id 15.2.2562.20 via Frontend Transport; Thu, 26 Mar 2026 00:01:03 -0700 From: Tariq Toukan To: Eric Dumazet , Jakub Kicinski , Paolo Abeni , Andrew Lunn , "David S. Miller" CC: Donald Hunter , Simon Horman , Jiri Pirko , Jonathan Corbet , Shuah Khan , Saeed Mahameed , "Leon Romanovsky" , Tariq Toukan , Mark Bloch , Shuah Khan , Chuck Lever , "Matthieu Baerts (NGI0)" , Carolina Jubran , Cosmin Ratiu , Dragos Tatulea , Jacob Keller , Shahar Shitrit , "Daniel Zahka" , Parav Pandit , "Adithya Jayachandran" , Kees Cook , "Shay Drori" , Daniel Jurgens , Moshe Shemesh , Willem de Bruijn , David Wei , Petr Machata , Stanislav Fomichev , Daniel Borkmann , Joe Damato , Nikolay Aleksandrov , Vadim Fedorenko , "Michael S. Tsirkin" , "Antonio Quartulli" , Allison Henderson , Bui Quang Minh , Nimrod Oren , , , , , , Gal Pressman , Jiri Pirko Subject: [PATCH net-next V9 05/14] devlink: Add parent dev to devlink API Date: Thu, 26 Mar 2026 08:59:40 +0200 Message-ID: <20260326065949.44058-6-tariqt@nvidia.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20260326065949.44058-1-tariqt@nvidia.com> References: <20260326065949.44058-1-tariqt@nvidia.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN2PEPF00004FBC:EE_|DS7PR12MB5768:EE_ X-MS-Office365-Filtering-Correlation-Id: cd545eaf-29ec-430d-7338-08de8b057e62 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|1800799024|7416014|82310400026|36860700016|22082099003|56012099003|18002099003; X-Microsoft-Antispam-Message-Info: z28Pd/iTqordQCabv40jwuwB7EowSIGyAiAEroMqblEDswu47vSnWehADDBazcOPqHzZAvexrbvIPItg5LZg8yAqPHmjHH0uvovJenQNhjrQPFuKuzBLeyTm7qVSTGu5SIlrTW4fDRJN6Zbl0B8xj30uvLaFhJP6ln7GpUg8XsIiszY3a90ErFbm7uRgrYEVPSFkRQScXdNX9+d/z21q7qWxf1EtuUWCWY450vX633fXF8bl1tULxMr/0OQd90eisnY+XQ11uMCcLSzC0ZbyLiKHZqACVfKNFUd8evmIRFBqaJxjFWpiEPXeH5M23XqjX3NNp55fqoMrdFCSF2Ihfh6zvsemb6riTjr7XMVCueeJNUL/PIsoLXq5FTcuUcFggyyLmA8qPH8rrXewKiOhSgFFyaVsft19W+qGyVMcOVqM0Oe9O5tHQxQ66EWrC4Yt9wtbq6+MPvoYEy261GAGobc+p+ANKezWGO1NcJNFywAWIkvJucdtmI7xAZ5v+8cvpvgNxWzk1bjCP5g9vo6vjTsekKZsDvm6q9BFUOtpKIzMOnnooo/D2iKz3XqPOtkbzYXDejTN1OaEqesfkjTnwWV/ujBCS0WT2fE41T1kAcLv4lOtVY1ilf37iOErm00v0oHBvovbJC8p7RIEKJWJOCWb/kfaMJ7MsX7weyJrgYxjz+iTD6xYo+aoBsWEPr0AQMm0NSY+QPbqGc7z7lxF6CMMaCnjIJqTxbEM3WKGd8eWzi9fBiLiQ7DVOiuMMfnMgy3kI6iXPKtinv6hlUNkYQ== X-Forefront-Antispam-Report: CIP:216.228.118.232;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc7edge1.nvidia.com;CAT:NONE;SFS:(13230040)(376014)(1800799024)(7416014)(82310400026)(36860700016)(22082099003)(56012099003)(18002099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Vtmy76ZMHFhIZwyrXzc58uncYuiI93l4Br7269eci3QLBNPvxGm/5pGUaJyozFyIo6jvHU6jgdCRzvMu9tk+kh/ukw3Bc64Iz+osq7OiVhYDomYnwc30LQxPjHNuvqVe3lql0GY3iVn/ZHlTmR47dVAwc12qxRSNFHpiBZ4qWVBZFnTfAMkdAie8YOzKkW1zrCzNjzFgKXvz5SUWNUEypkjDaxVHNIruz/+ZDo5IegBDJxCm80Jp/O/IaYp/3RcentOAFyV3c1dITybz8sJ7Fdd8Om0U9jz6SlClRBx6AC7ipvkszS2UZ/Nox2XeYJ9Tb+jOdNkQyyi6MuIB70+gZuhcdI1RgPp1biyx4geRUOGIZMwMrycnnHiodsAXVT2UzU7kumOVY7ORNdUHpx2nBuG5pNq7Kdh+Lp4yNXrcRUuM7biIH8obdYV7kGmM3Yqo X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Mar 2026 07:01:24.3073 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: cd545eaf-29ec-430d-7338-08de8b057e62 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.118.232];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN2PEPF00004FBC.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR12MB5768 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->ctx. 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 | 14 +++++++++ include/uapi/linux/devlink.h | 2 ++ net/devlink/devl_internal.h | 3 ++ net/devlink/netlink.c | 36 ++++++++++++++++++++---- 4 files changed, 50 insertions(+), 5 deletions(-) diff --git a/Documentation/netlink/specs/devlink.yaml b/Documentation/netlink/specs/devlink.yaml index b495d56b9137..43cc0abf7235 100644 --- a/Documentation/netlink/specs/devlink.yaml +++ b/Documentation/netlink/specs/devlink.yaml @@ -873,6 +873,10 @@ attribute-sets: doc: Unique devlink instance index. checks: max: u32-max + - + name: parent-dev + type: nest + nested-attributes: dl-parent-dev - name: dl-dev-stats subset-of: devlink @@ -1295,6 +1299,16 @@ 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 classes. + - + name: dl-parent-dev + subset-of: devlink + attributes: + - + name: bus-name + - + name: dev-name + - + name: index operations: enum-model: directional diff --git a/include/uapi/linux/devlink.h b/include/uapi/linux/devlink.h index 7de2d8cc862f..01b7a4fcfedd 100644 --- a/include/uapi/linux/devlink.h +++ b/include/uapi/linux/devlink.h @@ -646,6 +646,8 @@ enum devlink_attr { DEVLINK_ATTR_INDEX, /* uint */ + 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 1af445f044e5..414b3d8f70a5 100644 --- a/net/devlink/devl_internal.h +++ b/net/devlink/devl_internal.h @@ -153,6 +153,7 @@ int devlink_rel_devlink_handle_put(struct sk_buff *msg, struct devlink *devlink, struct devlink_nl_ctx { struct devlink *devlink; struct devlink_port *devlink_port; + struct devlink *parent_devlink; }; static inline struct devlink_nl_ctx * @@ -191,6 +192,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); 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 5624cf71592f..21a34e4d2a49 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) static const struct genl_multicast_group devlink_nl_mcgrps[] = { [DEVLINK_MCGRP_CONFIG] = { .name = DEVLINK_GENL_MCGRP_CONFIG_NAME }, @@ -239,19 +240,39 @@ devlink_get_from_attrs_lock(struct net *net, struct nlattr **attrs, return ERR_PTR(-ENODEV); } +struct devlink * +devlink_get_parent_from_attrs_lock(struct net *net, struct nlattr **attrs) +{ + return ERR_PTR(-EOPNOTSUPP); +} + static int __devlink_nl_pre_doit(struct sk_buff *skb, struct genl_info *info, u8 flags) { + bool parent_dev = flags & DEVLINK_NL_FLAG_OPTIONAL_PARENT_DEV; bool dev_lock = flags & DEVLINK_NL_FLAG_NEED_DEV_LOCK; + struct devlink *devlink, *parent_devlink = NULL; + struct net *net = genl_info_net(info); + struct nlattr **attrs = info->attrs; struct devlink_port *devlink_port; - struct devlink *devlink; int err; - devlink = 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 = devlink_get_parent_from_attrs_lock(net, attrs); + if (IS_ERR(parent_devlink)) + return PTR_ERR(parent_devlink); + devlink_nl_ctx(info)->parent_devlink = 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); + } + devlink = devlink_get_from_attrs_lock(net, attrs, dev_lock); + if (IS_ERR(devlink)) { + err = PTR_ERR(devlink); + goto parent_put; + } devlink_nl_ctx(info)->devlink = devlink; if (flags & DEVLINK_NL_FLAG_NEED_PORT) { devlink_port = devlink_port_get_from_info(devlink, info); @@ -270,6 +291,9 @@ static int __devlink_nl_pre_doit(struct sk_buff *skb, struct 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; } @@ -307,6 +331,8 @@ static void __devlink_nl_post_doit(struct sk_buff *skb, struct genl_info *info, devlink = devlink_nl_ctx(info)->devlink; devl_dev_unlock(devlink, dev_lock); devlink_put(devlink); + if (devlink_nl_ctx(info)->parent_devlink) + devlink_put(devlink_nl_ctx(info)->parent_devlink); } void devlink_nl_post_doit(const struct genl_split_ops *ops, -- 2.44.0