[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20260202200035.742f9500@kernel.org>
Date: Mon, 2 Feb 2026 20:00:35 -0800
From: Jakub Kicinski <kuba@...nel.org>
To: Tariq Toukan <tariqt@...dia.com>
Cc: Eric Dumazet <edumazet@...gle.com>, Paolo Abeni <pabeni@...hat.com>,
Andrew Lunn <andrew+netdev@...n.ch>, "David S. Miller"
<davem@...emloft.net>, Donald Hunter <donald.hunter@...il.com>, Jiri Pirko
<jiri@...nulli.us>, Jonathan Corbet <corbet@....net>, Saeed Mahameed
<saeedm@...dia.com>, "Leon Romanovsky" <leon@...nel.org>, Mark Bloch
<mbloch@...dia.com>, <netdev@...r.kernel.org>,
<linux-kernel@...r.kernel.org>, <linux-doc@...r.kernel.org>,
<linux-rdma@...r.kernel.org>, Gal Pressman <gal@...dia.com>, Moshe Shemesh
<moshe@...dia.com>, Carolina Jubran <cjubran@...dia.com>, Cosmin Ratiu
<cratiu@...dia.com>, Jiri Pirko <jiri@...dia.com>, Randy Dunlap
<rdunlap@...radead.org>, Simon Horman <horms@...nel.org>, Krzysztof
Kozlowski <krzk@...nel.org>
Subject: Re: [PATCH net-next V7 07/14] devlink: Add parent dev to devlink
API
On Wed, 28 Jan 2026 13:25:37 +0200 Tariq Toukan wrote:
> 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);
> + info->user_ptr[1] = parent_devlink;
Let's convert devlink to use proper overlay struct over info->cb ?
The user_ptr array only has two entries so devlink stuffs all the
extra pointers into the second slot. But the cb is much larger - 48B
so we can easily give each of these values a dedicated pointer.
> + /* Drop the parent devlink lock but don't release the reference.
> + * This will keep it alive until the end of the request.
> + */
To be clear -- devlink instances do not behave like netdev instances.
netdev instances prevent unregistration of the netdev.
devlink refs are normal refs, they just keep the memory around.
If memory serves me..
> + 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;
> + }
Powered by blists - more mailing lists