summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJiri Pirko <jiri@nvidia.com>2026-03-12 13:03:55 +0300
committerJakub Kicinski <kuba@kernel.org>2026-03-14 23:08:46 +0300
commit68deca0f0f4bba8c5278340c7c142500171d5f9b (patch)
tree9bfd61247c12a33285748a81db60cea65da621dd
parent9d9d7b4b153bc44e5d3226f1d0b445fb70320da9 (diff)
downloadlinux-68deca0f0f4bba8c5278340c7c142500171d5f9b.tar.xz
devlink: expose devlink instance index over netlink
Each devlink instance has an internally assigned index used for xarray storage. Expose it as a new DEVLINK_ATTR_INDEX uint attribute alongside the existing bus_name and dev_name handle. Signed-off-by: Jiri Pirko <jiri@nvidia.com> Link: https://patch.msgid.link/20260312100407.551173-2-jiri@resnulli.us Signed-off-by: Jakub Kicinski <kuba@kernel.org>
-rw-r--r--Documentation/netlink/specs/devlink.yaml5
-rw-r--r--include/uapi/linux/devlink.h2
-rw-r--r--net/devlink/devl_internal.h2
-rw-r--r--net/devlink/port.c1
4 files changed, 10 insertions, 0 deletions
diff --git a/Documentation/netlink/specs/devlink.yaml b/Documentation/netlink/specs/devlink.yaml
index 837112da6738..1bed67a0eefb 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: index
+ type: uint
+ doc: Unique devlink instance index.
-
name: dl-dev-stats
subset-of: devlink
@@ -1311,6 +1315,7 @@ operations:
attributes:
- bus-name
- dev-name
+ - index
- reload-failed
- dev-stats
dump:
diff --git a/include/uapi/linux/devlink.h b/include/uapi/linux/devlink.h
index e7d6b6d13470..1ba3436db4ae 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 */
+ DEVLINK_ATTR_INDEX, /* uint */
+
/* 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 1377864383bc..31fa98af418e 100644
--- a/net/devlink/devl_internal.h
+++ b/net/devlink/devl_internal.h
@@ -178,6 +178,8 @@ devlink_nl_put_handle(struct sk_buff *msg, struct devlink *devlink)
return -EMSGSIZE;
if (nla_put_string(msg, DEVLINK_ATTR_DEV_NAME, dev_name(devlink->dev)))
return -EMSGSIZE;
+ if (nla_put_uint(msg, DEVLINK_ATTR_INDEX, devlink->index))
+ return -EMSGSIZE;
return 0;
}
diff --git a/net/devlink/port.c b/net/devlink/port.c
index 93d8a25bb920..1ff609571ea4 100644
--- a/net/devlink/port.c
+++ b/net/devlink/port.c
@@ -222,6 +222,7 @@ size_t devlink_nl_port_handle_size(struct devlink_port *devlink_port)
return nla_total_size(strlen(devlink->dev->bus->name) + 1) /* DEVLINK_ATTR_BUS_NAME */
+ nla_total_size(strlen(dev_name(devlink->dev)) + 1) /* DEVLINK_ATTR_DEV_NAME */
+ + nla_total_size(8) /* DEVLINK_ATTR_INDEX */
+ nla_total_size(4); /* DEVLINK_ATTR_PORT_INDEX */
}