From: Jiri Pirko <jiri@resnulli.us>
To: netdev@vger.kernel.org
Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
pabeni@redhat.com, horms@kernel.org, donald.hunter@gmail.com,
corbet@lwn.net, skhan@linuxfoundation.org, saeedm@nvidia.com,
leon@kernel.org, tariqt@nvidia.com, mbloch@nvidia.com,
przemyslaw.kitszel@intel.com, mschmidt@redhat.com,
andrew+netdev@lunn.ch, rostedt@goodmis.org, mhiramat@kernel.org,
mathieu.desnoyers@efficios.com, chuck.lever@oracle.com,
matttbe@kernel.org, cjubran@nvidia.com, daniel.zahka@gmail.com,
Jiri Pirko <jiri@nvidia.com>
Subject: [PATCH net-next 07/10] devlink: allow devlink instance allocation without a backing device
Date: Mon, 23 Feb 2026 15:55:54 +0100 [thread overview]
Message-ID: <20260223145557.248679-8-jiri@resnulli.us> (raw)
In-Reply-To: <20260223145557.248679-1-jiri@resnulli.us>
From: Jiri Pirko <jiri@nvidia.com>
Allow devlink_alloc_ns() to be called with dev=NULL to support
device-less devlink instances. When dev is NULL, the instance is
identified over netlink using "devlink_index" as bus_name and
the decimal index value as dev_name.
Signed-off-by: Jiri Pirko <jiri@nvidia.com>
---
include/uapi/linux/devlink.h | 2 ++
net/devlink/core.c | 26 +++++++++++++++++++++-----
net/devlink/dev.c | 11 +++++++----
net/devlink/devl_internal.h | 4 ++--
net/devlink/port.c | 14 +++++++++-----
5 files changed, 41 insertions(+), 16 deletions(-)
diff --git a/include/uapi/linux/devlink.h b/include/uapi/linux/devlink.h
index 1ba3436db4ae..7de2d8cc862f 100644
--- a/include/uapi/linux/devlink.h
+++ b/include/uapi/linux/devlink.h
@@ -19,6 +19,8 @@
#define DEVLINK_GENL_VERSION 0x1
#define DEVLINK_GENL_MCGRP_CONFIG_NAME "config"
+#define DEVLINK_INDEX_BUS_NAME "devlink_index"
+
enum devlink_command {
/* don't change the order or add anything between, this is ABI! */
DEVLINK_CMD_UNSPEC,
diff --git a/net/devlink/core.c b/net/devlink/core.c
index 85e83a3b082a..9cdda570e584 100644
--- a/net/devlink/core.c
+++ b/net/devlink/core.c
@@ -330,7 +330,10 @@ static void devlink_release(struct work_struct *work)
mutex_destroy(&devlink->lock);
lockdep_unregister_key(&devlink->lock_key);
- put_device(devlink->dev);
+ if (devlink->dev)
+ put_device(devlink->dev);
+ else
+ kfree(devlink->dev_name);
kvfree(devlink);
}
@@ -445,7 +448,7 @@ struct devlink *devlink_alloc_ns(const struct devlink_ops *ops,
static u32 last_id;
int ret;
- WARN_ON(!ops || !dev);
+ WARN_ON(!ops);
if (!devlink_reload_actions_valid(ops))
return NULL;
@@ -453,14 +456,22 @@ struct devlink *devlink_alloc_ns(const struct devlink_ops *ops,
if (!devlink)
return NULL;
+ if (dev) {
+ devlink->dev = get_device(dev);
+ devlink->bus_name = dev->bus->name;
+ devlink->dev_name = dev_name(dev);
+ } else {
+ devlink->bus_name = DEVLINK_INDEX_BUS_NAME;
+ devlink->dev_name = kasprintf(GFP_KERNEL, "%u", devlink->index);
+ if (!devlink->dev_name)
+ goto err_kasprintf;
+ }
+
ret = xa_alloc_cyclic(&devlinks, &devlink->index, devlink, xa_limit_31b,
&last_id, GFP_KERNEL);
if (ret < 0)
goto err_xa_alloc;
- devlink->dev = get_device(dev);
- devlink->bus_name = dev->bus->name;
- devlink->dev_name = dev_name(dev);
devlink->ops = ops;
xa_init_flags(&devlink->ports, XA_FLAGS_ALLOC);
xa_init_flags(&devlink->params, XA_FLAGS_ALLOC);
@@ -486,6 +497,11 @@ struct devlink *devlink_alloc_ns(const struct devlink_ops *ops,
return devlink;
err_xa_alloc:
+ if (devlink->dev)
+ put_device(devlink->dev);
+ else
+ kfree(devlink->dev_name);
+err_kasprintf:
kvfree(devlink);
return NULL;
}
diff --git a/net/devlink/dev.c b/net/devlink/dev.c
index e3a36de4f4ae..b63597312bbd 100644
--- a/net/devlink/dev.c
+++ b/net/devlink/dev.c
@@ -453,7 +453,8 @@ int devlink_reload(struct devlink *devlink, struct net *dest_net,
* (e.g., PCI reset) and to close possible races between these
* operations and probe/remove.
*/
- device_lock_assert(devlink->dev);
+ if (devlink->dev)
+ device_lock_assert(devlink->dev);
memcpy(remote_reload_stats, devlink->stats.remote_reload_stats,
sizeof(remote_reload_stats));
@@ -892,9 +893,11 @@ devlink_nl_info_fill(struct sk_buff *msg, struct devlink *devlink,
goto err_cancel_msg;
}
- err = devlink_nl_driver_info_get(dev->driver, &req);
- if (err)
- goto err_cancel_msg;
+ if (dev) {
+ err = devlink_nl_driver_info_get(dev->driver, &req);
+ if (err)
+ goto err_cancel_msg;
+ }
genlmsg_end(msg, hdr);
return 0;
diff --git a/net/devlink/devl_internal.h b/net/devlink/devl_internal.h
index 67425c5d8cfc..89d08fd511cb 100644
--- a/net/devlink/devl_internal.h
+++ b/net/devlink/devl_internal.h
@@ -107,7 +107,7 @@ static inline bool devl_is_registered(struct devlink *devlink)
static inline void devl_dev_lock(struct devlink *devlink, bool dev_lock)
{
- if (dev_lock)
+ if (dev_lock && devlink->dev)
device_lock(devlink->dev);
devl_lock(devlink);
}
@@ -115,7 +115,7 @@ static inline void devl_dev_lock(struct devlink *devlink, bool dev_lock)
static inline void devl_dev_unlock(struct devlink *devlink, bool dev_lock)
{
devl_unlock(devlink);
- if (dev_lock)
+ if (dev_lock && devlink->dev)
device_unlock(devlink->dev);
}
diff --git a/net/devlink/port.c b/net/devlink/port.c
index 1d4a79c6d4d3..f19b690ebe7e 100644
--- a/net/devlink/port.c
+++ b/net/devlink/port.c
@@ -976,7 +976,9 @@ static void devlink_port_type_warn(struct work_struct *work)
struct devlink_port *port = container_of(to_delayed_work(work),
struct devlink_port,
type_warn_dw);
- dev_warn(port->devlink->dev, "Type was not set for devlink port.");
+ if (port->devlink->dev)
+ dev_warn(port->devlink->dev,
+ "Type was not set for devlink port.");
}
static bool devlink_port_type_should_warn(struct devlink_port *devlink_port)
@@ -1242,9 +1244,10 @@ static void __devlink_port_type_set(struct devlink_port *devlink_port,
*/
void devlink_port_type_eth_set(struct devlink_port *devlink_port)
{
- dev_warn(devlink_port->devlink->dev,
- "devlink port type for port %d set to Ethernet without a software interface reference, device type not supported by the kernel?\n",
- devlink_port->index);
+ if (devlink_port->devlink->dev)
+ dev_warn(devlink_port->devlink->dev,
+ "devlink port type for port %d set to Ethernet without a software interface reference, device type not supported by the kernel?\n",
+ devlink_port->index);
__devlink_port_type_set(devlink_port, DEVLINK_PORT_TYPE_ETH, NULL);
}
EXPORT_SYMBOL_GPL(devlink_port_type_eth_set);
@@ -1272,7 +1275,8 @@ EXPORT_SYMBOL_GPL(devlink_port_type_ib_set);
*/
void devlink_port_type_clear(struct devlink_port *devlink_port)
{
- if (devlink_port->type == DEVLINK_PORT_TYPE_ETH)
+ if (devlink_port->type == DEVLINK_PORT_TYPE_ETH &&
+ devlink_port->devlink->dev)
dev_warn(devlink_port->devlink->dev,
"devlink port type for port %d cleared without a software interface reference, device type not supported by the kernel?\n",
devlink_port->index);
--
2.51.1
next prev parent reply other threads:[~2026-02-23 14:56 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-23 14:55 [PATCH net-next 00/10] devlink: introduce shared devlink instance for PFs on same chip Jiri Pirko
2026-02-23 14:55 ` [PATCH net-next 01/10] devlink: expose devlink instance index over netlink Jiri Pirko
2026-02-23 14:55 ` [PATCH net-next 02/10] devlink: store bus_name and dev_name pointers in struct devlink Jiri Pirko
2026-02-23 14:55 ` [PATCH net-next 03/10] devlink: avoid extra iterations when found devlink is not registered Jiri Pirko
2026-02-23 14:55 ` [PATCH net-next 04/10] devlink: allow to use devlink index as a command handle Jiri Pirko
2026-02-23 14:55 ` [PATCH net-next 05/10] devlink: support index-based lookup via bus_name/dev_name handle Jiri Pirko
2026-02-25 2:22 ` Jakub Kicinski
2026-02-25 2:23 ` [net-next,05/10] " Jakub Kicinski
2026-02-23 14:55 ` [PATCH net-next 06/10] devlink: add devlink_dev_driver_name() helper and use it in trace events Jiri Pirko
2026-02-25 2:23 ` [net-next,06/10] " Jakub Kicinski
2026-02-23 14:55 ` Jiri Pirko [this message]
2026-02-25 2:23 ` [net-next,07/10] devlink: allow devlink instance allocation without a backing device Jakub Kicinski
2026-02-23 14:55 ` [PATCH net-next 08/10] devlink: introduce shared devlink instance for PFs on same chip Jiri Pirko
2026-02-25 2:23 ` [net-next,08/10] " Jakub Kicinski
2026-02-23 14:55 ` [PATCH net-next 09/10] documentation: networking: add shared devlink documentation Jiri Pirko
2026-02-25 2:23 ` [net-next,09/10] " Jakub Kicinski
2026-02-23 14:55 ` [PATCH net-next 10/10] net/mlx5: Add a shared devlink instance for PFs on same chip Jiri Pirko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260223145557.248679-8-jiri@resnulli.us \
--to=jiri@resnulli.us \
--cc=andrew+netdev@lunn.ch \
--cc=chuck.lever@oracle.com \
--cc=cjubran@nvidia.com \
--cc=corbet@lwn.net \
--cc=daniel.zahka@gmail.com \
--cc=davem@davemloft.net \
--cc=donald.hunter@gmail.com \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=jiri@nvidia.com \
--cc=kuba@kernel.org \
--cc=leon@kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=matttbe@kernel.org \
--cc=mbloch@nvidia.com \
--cc=mhiramat@kernel.org \
--cc=mschmidt@redhat.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=przemyslaw.kitszel@intel.com \
--cc=rostedt@goodmis.org \
--cc=saeedm@nvidia.com \
--cc=skhan@linuxfoundation.org \
--cc=tariqt@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox