devlink: introduce shared devlink instance for PFs on same chip
Subsystems (9)
Jiri Pirko
maintainerv2 cover devlink: introduce shared devlink instance for PFs on same chip
From: Jiri Pirko <[email protected]>
Multiple PFs on a network adapter often reside on the same physical chip, running a single firmware. Some resources and configurations are inherently shared among these PFs - PTP clocks, VF group rates, firmware parameters, and others. Today there is no good object in the devlink model to attach these chip-wide configuration knobs to. Drivers resort to workarounds like pinning shared state to PF0 or maintaining ad-hoc internal structures (e.g., ice_adapter) that are invisible to userspace.
This problem was discussed extensively starting with Przemek Kitszel's "whole device devlink instance" RFC for the ice driver [1]. Several approaches for representing the parent instance were considered:
using a partial PCI BDF as the dev_name (breaks when PFs have different BDFs in VMs), creating a per-driver bus, using auxiliary devices, or using faux devices. All of these required a backing struct device for the parent devlink instance, which does not naturally exist - there is no PCI device that represents the chip as a whole.
This patchset takes a different approach: allow devlink instances to exist without any backing struct device. The instance is identified purely by its internal index, exposed over devlin netlink. This avoids fabricating fake devices and keeps the devlink handle semantics clean.
The first seven patches prepare the devlink core for device-less instances by decoupling the handle from the parent device. The last three introduce the shared devlink infrastructure and its first user in the mlx5 driver.
Example output showing the shared instance and nesting:
pci/0000:08:00.0: index 0
nested_devlink:
auxiliary/mlx5_core.eth.0
devlink_index/1: index 1
nested_devlink:
pci/0000:08:00.0
pci/0000:08:00.1 auxiliary/mlx5_core.eth.0: index 2
pci/0000:08:00.1: index 3
nested_devlink:
auxiliary/mlx5_core.eth.1
auxiliary/mlx5_core.eth.1: index 4
[1] https://lore.kernel.org/netdev/[email protected]/
---
Decoupled from "devlink and mlx5: Support cross-function rate scheduling" patchset to maintain 15-patches limit.
See individual patches for changelog.
Jiri Pirko (10):
devlink: expose devlink instance index over netlink
devlink: store bus_name and dev_name pointers in struct devlink
devlink: avoid extra iterations when found devlink is not registered
devlink: allow to use devlink index as a command handle
devlink: support index-based lookup via bus_name/dev_name handle
devlink: add devlink_dev_driver_name() helper and use it in trace
events
devlink: allow devlink instance allocation without a backing device
devlink: introduce shared devlink instance for PFs on same chip
documentation: networking: add shared devlink documentation net/mlx5: Add a shared devlink instance for PFs on same chip
Documentation/netlink/specs/devlink.yaml | 56 +++ .../networking/devlink/devlink-shared.rst | 89 +++++ Documentation/networking/devlink/index.rst | 1 + .../net/ethernet/mellanox/mlx5/core/Makefile | 5 +- .../net/ethernet/mellanox/mlx5/core/main.c | 17 + .../ethernet/mellanox/mlx5/core/sh_devlink.c | 62 ++++ .../ethernet/mellanox/mlx5/core/sh_devlink.h | 12 + include/linux/mlx5/driver.h | 1 + include/net/devlink.h | 9 + include/trace/events/devlink.h | 36 +- include/uapi/linux/devlink.h | 4 + net/devlink/Makefile | 2 +- net/devlink/core.c | 59 ++- net/devlink/dev.c | 11 +- net/devlink/devl_internal.h | 17 +- net/devlink/netlink.c | 38 +- net/devlink/netlink_gen.c | 350 +++++++++++------- net/devlink/port.c | 19 +- net/devlink/sh_dev.c | 142 +++++++ 19 files changed, 738 insertions(+), 192 deletions(-) create mode 100644 Documentation/networking/devlink/devlink-shared.rst create mode 100644 drivers/net/ethernet/mellanox/mlx5/core/sh_devlink.c create mode 100644 drivers/net/ethernet/mellanox/mlx5/core/sh_devlink.h create mode 100644 net/devlink/sh_dev.c
Signature · 1 line
2.51.1
Jiri Pirko
maintainerPATCH v2 1/10 devlink: expose devlink instance index over netlink
From: Jiri Pirko <[email protected]>
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.
--- Documentation/netlink/specs/devlink.yaml | 5 +++++ include/uapi/linux/devlink.h | 2 ++ net/devlink/devl_internal.h | 2 ++ net/devlink/port.c | 1 + 4 files changed, 10 insertions(+)
Documentation/netlink/specs/devlink.yaml +5 -0
@@ -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:
include/uapi/linux/devlink.h +2 -0
@@ -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.
net/devlink/devl_internal.h +2 -0
@@ -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 ; }
net/devlink/port.c +1 -0
@@ -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 */ }
Signature · 1 line
2.51.1
Jiri Pirko
maintainerPATCH v2 2/10 devlink: store bus_name and dev_name pointers in struct devlink
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
Currently, bus_name and dev_name are obtained from the parent dev instance every time they are needed.
In preparation to dev-less devlinks, store bus_name and dev_name pointers in struct devlink during devlink_alloc_ns() and use them throughout.
--- include/net/devlink.h | 2 ++ include/trace/events/devlink.h | 24 ++++++++++++------------ net/devlink/core.c | 14 ++++++++++++++ net/devlink/devl_internal.h | 10 ++++++---- net/devlink/netlink.c | 4 ++-- net/devlink/port.c | 4 ++-- 6 files changed, 38 insertions(+), 20 deletions(-)
include/net/devlink.h +2 -0
@@ -1611,6 +1611,8 @@ struct devlink_ops {void *devlink_priv (struct devlink *devlink);struct devlink *priv_to_devlink (void *priv);struct device *devlink_to_dev (const struct devlink *devlink); +const char *devlink_bus_name (const struct devlink *devlink); +const char *devlink_dev_name (const struct devlink *devlink);/* Devlink instance explicit locking */ void devl_lock (struct devlink *devlink);
include/trace/events/devlink.h +12 -12
@@ -21,8 +21,8 @@ TRACE_EVENT(devlink_hwmsg, TP_ARGS(devlink, incoming, type, buf, len),TP_STRUCT__entry ( - __string(bus_name, devlink_to_dev(devlink)->bus->name) - __string(dev_name, dev_name(devlink_to_dev(devlink))) +__string (bus_name ,devlink_bus_name (devlink )) +__string (dev_name,devlink_dev_name (devlink)) __string(driver_name, devlink_to_dev(devlink)->driver->name)__field (bool, incoming) __field(unsigned long, type)
@@ -55,8 +55,8 @@ TRACE_EVENT(devlink_hwerr, TP_ARGS(devlink, err, msg),TP_STRUCT__entry ( - __string(bus_name, devlink_to_dev(devlink)->bus->name) - __string(dev_name, dev_name(devlink_to_dev(devlink))) +__string (bus_name ,devlink_bus_name (devlink )) +__string (dev_name,devlink_dev_name (devlink)) __string(driver_name, devlink_to_dev(devlink)->driver->name)__field (int, err) __string(msg, msg)
@@ -85,8 +85,8 @@ TRACE_EVENT(devlink_health_report, TP_ARGS(devlink, reporter_name, msg),TP_STRUCT__entry ( - __string(bus_name, devlink_to_dev(devlink)->bus->name) - __string(dev_name, dev_name(devlink_to_dev(devlink))) +__string (bus_name ,devlink_bus_name (devlink )) +__string (dev_name,devlink_dev_name (devlink)) __string(driver_name, devlink_to_dev(devlink)->driver->name)__string (reporter_name, reporter_name) __string(msg, msg)
@@ -116,8 +116,8 @@ TRACE_EVENT(devlink_health_recover_aborted, TP_ARGS(devlink, reporter_name, health_state, time_since_last_recover),TP_STRUCT__entry ( - __string(bus_name, devlink_to_dev(devlink)->bus->name) - __string(dev_name, dev_name(devlink_to_dev(devlink))) +__string (bus_name ,devlink_bus_name (devlink )) +__string (dev_name,devlink_dev_name (devlink)) __string(driver_name, devlink_to_dev(devlink)->driver->name)__string (reporter_name, reporter_name) __field(bool, health_state)
@@ -150,8 +150,8 @@ TRACE_EVENT(devlink_health_reporter_state_update, TP_ARGS(devlink, reporter_name, new_state),TP_STRUCT__entry ( - __string(bus_name, devlink_to_dev(devlink)->bus->name) - __string(dev_name, dev_name(devlink_to_dev(devlink))) +__string (bus_name ,devlink_bus_name (devlink )) +__string (dev_name,devlink_dev_name (devlink)) __string(driver_name, devlink_to_dev(devlink)->driver->name)__string (reporter_name, reporter_name) __field(u8, new_state)
@@ -181,8 +181,8 @@ TRACE_EVENT(devlink_trap_report, TP_ARGS(devlink, skb, metadata),TP_STRUCT__entry ( - __string(bus_name, devlink_to_dev(devlink)->bus->name) - __string(dev_name, dev_name(devlink_to_dev(devlink))) +__string (bus_name ,devlink_bus_name (devlink )) +__string (dev_name,devlink_dev_name (devlink)) __string(driver_name, devlink_to_dev(devlink)->driver->name) __string(trap_name, metadata->trap_name) __string(trap_group_name, metadata->trap_group_name)
net/devlink/core.c +14 -0
@@ -248,6 +248,18 @@ struct device *devlink_to_dev(const struct devlink *devlink) }EXPORT_SYMBOL_GPL (devlink_to_dev); +const char *devlink_bus_name (const struct devlink *devlink) +{ +return devlink->bus_name; +} +EXPORT_SYMBOL_GPL (devlink_bus_name); + +const char *devlink_dev_name (const struct devlink *devlink) +{ +return devlink->dev_name; +} +EXPORT_SYMBOL_GPL (devlink_dev_name); +struct net *devlink_net (const struct devlink *devlink) {return read_pnet (&devlink->_net);
@@ -428,6 +440,8 @@ struct devlink *devlink_alloc_ns(const struct devlink_ops *ops, 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 );
net/devlink/devl_internal.h +6 -4
@@ -32,6 +32,8 @@ struct devlink_dev_stats {struct devlink {u32 index; +const char *bus_name; +const char *dev_name;struct xarray ports;struct list_head rate_list;struct list_head sb_list;
@@ -174,9 +176,9 @@ devlink_dump_state(struct netlink_callback *cb)static inline int devlink_nl_put_handle (struct sk_buff *msg,struct devlink *devlink) { -if (nla_put_string (msg,DEVLINK_ATTR_BUS_NAME , devlink->dev->bus->name)) +if (nla_put_string (msg,DEVLINK_ATTR_BUS_NAME , devlink->bus_name))return -EMSGSIZE ; -if (nla_put_string (msg,DEVLINK_ATTR_DEV_NAME ,dev_name (devlink->dev))) +if (nla_put_string (msg,DEVLINK_ATTR_DEV_NAME , devlink->dev_name))return -EMSGSIZE ;if (nla_put_uint (msg,DEVLINK_ATTR_INDEX , devlink->index))return -EMSGSIZE ;
@@ -211,8 +213,8 @@ static inline void devlink_nl_obj_desc_init(struct devlink_obj_desc *desc, struct devlink *devlink) {memset (desc,0 ,sizeof (*desc)); - desc->bus_name = devlink->dev->bus->name; - desc->dev_name =dev_name (devlink->dev); + desc->bus_name = devlink->bus_name; + desc->dev_name = devlink->dev_name; } static inline void devlink_nl_obj_desc_port_set(struct devlink_obj_desc *desc,
net/devlink/netlink.c +2 -2
@@ -193,8 +193,8 @@ devlink_get_from_attrs_lock(struct net *net, struct nlattr **attrs, devname =nla_data (attrs[DEVLINK_ATTR_DEV_NAME ]);devlinks_xa_for_each_registered_get (net, index, devlink) { -if (strcmp (devlink->dev->bus->name, busname) ==0 && -strcmp (dev_name (devlink->dev), devname) ==0 ) { +if (strcmp (devlink->bus_name, busname) ==0 && +strcmp (devlink->dev_name, devname) ==0 ) {devl_dev_lock (devlink, dev_lock);if (devl_is_registered (devlink))return devlink;
net/devlink/port.c +2 -2
@@ -220,8 +220,8 @@ size_t devlink_nl_port_handle_size(struct devlink_port *devlink_port) {struct devlink *devlink = devlink_port->devlink; -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 */ +return nla_total_size (strlen (devlink->bus_name) +1 )/* DEVLINK_ATTR_BUS_NAME */ + +nla_total_size (strlen (devlink->dev_name) +1 )/* DEVLINK_ATTR_DEV_NAME */ +nla_total_size (8 )/* DEVLINK_ATTR_INDEX */ +nla_total_size (4 );/* DEVLINK_ATTR_PORT_INDEX */ }
Signature · 1 line
2.51.1
Jiri Pirko
maintainerPATCH v2 3/10 devlink: avoid extra iterations when found devlink is not registered
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
Since the one found is not registered, very unlikely another one with the same bus_name/dev_name is going to be found. Stop right away and prepare common "found" path for the follow-up patch.
--- net/devlink/netlink.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-)
net/devlink/netlink.c +10 -6
@@ -194,16 +194,20 @@ devlink_get_from_attrs_lock(struct net *net, struct nlattr **attrs,devlinks_xa_for_each_registered_get (net, index, devlink) {if (strcmp (devlink->bus_name, busname) ==0 && -strcmp (devlink->dev_name, devname) ==0 ) { -devl_dev_lock (devlink, dev_lock); -if (devl_is_registered (devlink)) -return devlink; -devl_dev_unlock (devlink, dev_lock); - } +strcmp (devlink->dev_name, devname) ==0 ) + goto found;devlink_put (devlink); }return ERR_PTR (-ENODEV ); + +found: +devl_dev_lock (devlink, dev_lock); +if (devl_is_registered (devlink)) +return devlink; +devl_dev_unlock (devlink, dev_lock); +devlink_put (devlink); +return ERR_PTR (-ENODEV ); } static int __devlink_nl_pre_doit(struct sk_buff *skb, struct genl_info *info,
Signature · 1 line
2.51.1
Jiri Pirko
maintainerPATCH v2 4/10 devlink: allow to use devlink index as a command handle
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
Currently devlink instances are addressed bus_name/dev_name tuple. Allow the newly introduced DEVLINK_ATTR_INDEX to be used as an alternative handle for all devlink commands.
When DEVLINK_ATTR_INDEX is present in the request, use it for a direct xarray lookup instead of iterating over all instances comparing bus_name/dev_name strings.
--- Documentation/netlink/specs/devlink.yaml | 51 ++++ net/devlink/core.c | 16 +- net/devlink/devl_internal.h | 1 + net/devlink/netlink.c | 11 +- net/devlink/netlink_gen.c | 350 ++++++++++++++--------- 5 files changed, 286 insertions(+), 143 deletions(-)
Documentation/netlink/specs/devlink.yaml +51 -0
@@ -1310,6 +1310,7 @@ operations: attributes: &dev-id-attrs - bus-name - dev-name + - index reply: &get-reply value: 3 attributes:
@@ -1334,6 +1335,7 @@ operations: attributes: &port-id-attrs - bus-name - dev-name + - index - port-index reply: value: 7
@@ -1358,6 +1360,7 @@ operations: attributes: - bus-name - dev-name + - index - port-index - port-type - port-function
@@ -1375,6 +1378,7 @@ operations: attributes: - bus-name - dev-name + - index - port-index - port-flavour - port-pci-pf-number
@@ -1409,6 +1413,7 @@ operations: attributes: - bus-name - dev-name + - index - port-index - port-split-count
@@ -1437,6 +1442,7 @@ operations: attributes: &sb-id-attrs - bus-name - dev-name + - index - sb-index reply: &sb-get-reply value: 13
@@ -1459,6 +1465,7 @@ operations: attributes: &sb-pool-id-attrs - bus-name - dev-name + - index - sb-index - sb-pool-index reply: &sb-pool-get-reply
@@ -1482,6 +1489,7 @@ operations: attributes: - bus-name - dev-name + - index - sb-index - sb-pool-index - sb-pool-threshold-type
@@ -1500,6 +1508,7 @@ operations: attributes: &sb-port-pool-id-attrs - bus-name - dev-name + - index - port-index - sb-index - sb-pool-index
@@ -1524,6 +1533,7 @@ operations: attributes: - bus-name - dev-name + - index - port-index - sb-index - sb-pool-index
@@ -1542,6 +1552,7 @@ operations: attributes: &sb-tc-pool-bind-id-attrs - bus-name - dev-name + - index - port-index - sb-index - sb-pool-type
@@ -1567,6 +1578,7 @@ operations: attributes: - bus-name - dev-name + - index - port-index - sb-index - sb-pool-index
@@ -1588,6 +1600,7 @@ operations: attributes: - bus-name - dev-name + - index - sb-index -
@@ -1603,6 +1616,7 @@ operations: attributes: - bus-name - dev-name + - index - sb-index -
@@ -1621,6 +1635,7 @@ operations: attributes: &eswitch-attrs - bus-name - dev-name + - index - eswitch-mode - eswitch-inline-mode - eswitch-encap-mode
@@ -1649,12 +1664,14 @@ operations: attributes: - bus-name - dev-name + - index - dpipe-table-name reply: value: 31 attributes: - bus-name - dev-name + - index - dpipe-tables -
@@ -1669,11 +1686,13 @@ operations: attributes: - bus-name - dev-name + - index - dpipe-table-name reply: attributes: - bus-name - dev-name + - index - dpipe-entries -
@@ -1688,10 +1707,12 @@ operations: attributes: - bus-name - dev-name + - index reply: attributes: - bus-name - dev-name + - index - dpipe-headers -
@@ -1707,6 +1728,7 @@ operations: attributes: - bus-name - dev-name + - index - dpipe-table-name - dpipe-table-counters-enabled
@@ -1723,6 +1745,7 @@ operations: attributes: - bus-name - dev-name + - index - resource-id - resource-size
@@ -1738,11 +1761,13 @@ operations: attributes: - bus-name - dev-name + - index reply: value: 36 attributes: - bus-name - dev-name + - index - resource-list -
@@ -1758,6 +1783,7 @@ operations: attributes: - bus-name - dev-name + - index - reload-action - reload-limits - netns-pid
@@ -1767,6 +1793,7 @@ operations: attributes: - bus-name - dev-name + - index - reload-actions-performed -
@@ -1781,6 +1808,7 @@ operations: attributes: ¶m-id-attrs - bus-name - dev-name + - index - param-name reply: ¶m-get-reply attributes: *param-id-attrs
@@ -1802,6 +1830,7 @@ operations: attributes: - bus-name - dev-name + - index - param-name - param-type # param-value-data is missing here as the type is variable
@@ -1821,6 +1850,7 @@ operations: attributes: ®ion-id-attrs - bus-name - dev-name + - index - port-index - region-name reply: ®ion-get-reply
@@ -1845,6 +1875,7 @@ operations: attributes: ®ion-snapshot-id-attrs - bus-name - dev-name + - index - port-index - region-name - region-snapshot-id
@@ -1875,6 +1906,7 @@ operations: attributes: - bus-name - dev-name + - index - port-index - region-name - region-snapshot-id
@@ -1886,6 +1918,7 @@ operations: attributes: - bus-name - dev-name + - index - port-index - region-name
@@ -1935,6 +1968,7 @@ operations: attributes: - bus-name - dev-name + - index - info-driver-name - info-serial-number - info-version-fixed
@@ -1956,6 +1990,7 @@ operations: attributes: &health-reporter-id-attrs - bus-name - dev-name + - index - port-index - health-reporter-name reply: &health-reporter-get-reply
@@ -1978,6 +2013,7 @@ operations: attributes: - bus-name - dev-name + - index - port-index - health-reporter-name - health-reporter-graceful-period
@@ -2048,6 +2084,7 @@ operations: attributes: - bus-name - dev-name + - index - flash-update-file-name - flash-update-component - flash-update-overwrite-mask
@@ -2065,6 +2102,7 @@ operations: attributes: &trap-id-attrs - bus-name - dev-name + - index - trap-name reply: &trap-get-reply value: 63
@@ -2087,6 +2125,7 @@ operations: attributes: - bus-name - dev-name + - index - trap-name - trap-action
@@ -2103,6 +2142,7 @@ operations: attributes: &trap-group-id-attrs - bus-name - dev-name + - index - trap-group-name reply: &trap-group-get-reply value: 67
@@ -2125,6 +2165,7 @@ operations: attributes: - bus-name - dev-name + - index - trap-group-name - trap-action - trap-policer-id
@@ -2142,6 +2183,7 @@ operations: attributes: &trap-policer-id-attrs - bus-name - dev-name + - index - trap-policer-id reply: &trap-policer-get-reply value: 71
@@ -2164,6 +2206,7 @@ operations: attributes: - bus-name - dev-name + - index - trap-policer-id - trap-policer-rate - trap-policer-burst
@@ -2194,6 +2237,7 @@ operations: attributes: &rate-id-attrs - bus-name - dev-name + - index - port-index - rate-node-name reply: &rate-get-reply
@@ -2217,6 +2261,7 @@ operations: attributes: - bus-name - dev-name + - index - rate-node-name - rate-tx-share - rate-tx-max
@@ -2238,6 +2283,7 @@ operations: attributes: - bus-name - dev-name + - index - rate-node-name - rate-tx-share - rate-tx-max
@@ -2259,6 +2305,7 @@ operations: attributes: - bus-name - dev-name + - index - rate-node-name -
@@ -2274,6 +2321,7 @@ operations: attributes: &linecard-id-attrs - bus-name - dev-name + - index - linecard-index reply: &linecard-get-reply value: 80
@@ -2296,6 +2344,7 @@ operations: attributes: - bus-name - dev-name + - index - linecard-index - linecard-type
@@ -2329,6 +2378,7 @@ operations: attributes: - bus-name - dev-name + - index - selftests -
@@ -2340,4 +2390,5 @@ operations: attributes: - bus-name - dev-name + - index - port-index
net/devlink/core.c +14 -2
@@ -333,13 +333,15 @@ void devlink_put(struct devlink *devlink)queue_rcu_work (system_percpu_wq, &devlink->rwork); } -struct devlink *devlinks_xa_find_get (struct net *net,unsigned long *indexp) +static struct devlink *__devlinks_xa_find_get (struct net *net, +unsigned long *indexp, +unsigned long end) {struct devlink *devlink =NULL ;rcu_read_lock (); retry: - devlink =xa_find (&devlinks, indexp,ULONG_MAX ,DEVLINK_REGISTERED ); + devlink =xa_find (&devlinks, indexp, end,DEVLINK_REGISTERED );if (!devlink) goto unlock;
@@ -358,6 +360,16 @@ struct devlink *devlinks_xa_find_get(struct net *net, unsigned long *indexp) goto retry; } +struct devlink *devlinks_xa_find_get (struct net *net,unsigned long *indexp) +{ +return __devlinks_xa_find_get (net, indexp,ULONG_MAX ); +} + +struct devlink *devlinks_xa_lookup_get (struct net *net,unsigned long index) +{ +return __devlinks_xa_find_get (net, &index, index); +} +/** * devl_register - Register devlink instance * @devlink: devlink
net/devlink/devl_internal.h +1 -0
@@ -92,6 +92,7 @@ extern struct genl_family devlink_nl_family;for (index =0 ; (devlink =devlinks_xa_find_get (net, &index)); index++) struct devlink *devlinks_xa_find_get(struct net *net, unsigned long *indexp); +struct devlink *devlinks_xa_lookup_get (struct net *net,unsigned long index);static inline bool __devl_is_registered (struct devlink *devlink) {
net/devlink/netlink.c +10 -1
@@ -186,6 +186,14 @@ devlink_get_from_attrs_lock(struct net *net, struct nlattr **attrs,char *busname;char *devname; +if (attrs[DEVLINK_ATTR_INDEX ]) { + index =nla_get_uint (attrs[DEVLINK_ATTR_INDEX ]); + devlink =devlinks_xa_lookup_get (net, index); +if (!devlink) +return ERR_PTR (-ENODEV ); + goto found; + } +if (!attrs[DEVLINK_ATTR_BUS_NAME ] || !attrs[DEVLINK_ATTR_DEV_NAME ])return ERR_PTR (-EINVAL );
@@ -356,7 +364,8 @@ int devlink_nl_dumpit(struct sk_buff *msg, struct netlink_callback *cb,int flags =NLM_F_MULTI ;if (attrs && - (attrs[DEVLINK_ATTR_BUS_NAME ] || attrs[DEVLINK_ATTR_DEV_NAME ])) + (attrs[DEVLINK_ATTR_BUS_NAME ] || attrs[DEVLINK_ATTR_DEV_NAME ] || + attrs[DEVLINK_ATTR_INDEX ]))return devlink_nl_inst_single_dumpit (msg, cb, flags, dump_one, attrs);else
net/devlink/netlink_gen.c +210 -140
1,226 lines not on this page · raw message
Signature · 1 line
2.51.1
Jakub Kicinski
maintainerRe: [PATCH net-next v2 04/10] devlink: allow to use devlink index as a command handle
net/devlink/netlink.c devlink_get_from_attrs_lock(struct net *net, struct nlattr **attrs, · line 198
Quoted 10 lines · On Wed, 25 Feb 2026 14:34:16 +0100 Jiri Pirko wrote:
net/devlink/netlink.c +8
-0+if (attrs[DEVLINK_ATTR_INDEX ]) { + index =nla_get_uint (attrs[DEVLINK_ATTR_INDEX ]); + devlink =devlinks_xa_lookup_get (net, index); +if (!devlink) +return ERR_PTR (-ENODEV ); + goto found; + } +if (!attrs[DEVLINK_ATTR_BUS_NAME ] || !attrs[DEVLINK_ATTR_DEV_NAME ])return ERR_PTR (-EINVAL );
If both INDEX and BUS_NAME + DEV_NAME are provided we should check that they point to the same device? Or reject user space passing both?
Jiri Pirko
maintainerRe: [PATCH net-next v2 04/10] devlink: allow to use devlink index as a command handle
Quoted 14 lines · Sat, Feb 28, 2026 at 11:48:46PM +0100, [email protected] wrote:
net/devlink/netlink.c devlink_get_from_attrs_lock(struct net *net, struct nlattr **attrs, · line 198
Quoted 10 lines · On Wed, 25 Feb 2026 14:34:16 +0100 Jiri Pirko wrote:
net/devlink/netlink.c +8
-0+if (attrs[DEVLINK_ATTR_INDEX ]) { + index =nla_get_uint (attrs[DEVLINK_ATTR_INDEX ]); + devlink =devlinks_xa_lookup_get (net, index); +if (!devlink) +return ERR_PTR (-ENODEV ); + goto found; + } +if (!attrs[DEVLINK_ATTR_BUS_NAME ] || !attrs[DEVLINK_ATTR_DEV_NAME ])return ERR_PTR (-EINVAL );If both INDEX and
BUS_NAME+DEV_NAMEare provided we should check that they point to the same device? Or reject user space passing both?
I implemented reject. I don't see much of value of allowing both. The code that would do the checking is too much for this hypothetical case.
Jiri Pirko
maintainerPATCH v2 5/10 devlink: support index-based lookup via bus_name/dev_name handle
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
Devlink instances without a backing device use bus_name "devlink_index" and dev_name set to the decimal index string. When user space sends this handle, detect the pattern and perform a direct xarray lookup by index instead of iterating all instances.
---v1->v2:
- moved DEVLINK_INDEX_BUS_NAME definition here from patch #7
--- include/uapi/linux/devlink.h | 2 ++ net/devlink/netlink.c | 9 +++++++++ 2 files changed, 11 insertions(+)
include/uapi/linux/devlink.h +2 -0
@@ -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 ,
net/devlink/netlink.c +9 -0
@@ -200,6 +200,15 @@ devlink_get_from_attrs_lock(struct net *net, struct nlattr **attrs, busname =nla_data (attrs[DEVLINK_ATTR_BUS_NAME ]); devname =nla_data (attrs[DEVLINK_ATTR_DEV_NAME ]); +if (!strcmp (busname,DEVLINK_INDEX_BUS_NAME )) { +if (kstrtoul (devname,10 , &index)) +return ERR_PTR (-EINVAL ); + devlink =devlinks_xa_lookup_get (net, index); +if (!devlink) +return ERR_PTR (-ENODEV ); + goto found; + } +devlinks_xa_for_each_registered_get (net, index, devlink) {if (strcmp (devlink->bus_name, busname) ==0 &&strcmp (devlink->dev_name, devname) ==0 )
Signature · 1 line
2.51.1
Jiri Pirko
maintainerPATCH v2 6/10 devlink: add devlink_dev_driver_name() helper and use it in trace events
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
In preparation to dev-less devlinks, add devlink_dev_driver_name() that safely returns the driver name or NULL, and use it in all trace events. The trace __string() macro handles NULL via __string_src(), recording "(null)".
---v1->v2:
- added missing symbol export
--- include/net/devlink.h | 1 + include/trace/events/devlink.h | 12 ++++++------ net/devlink/core.c | 8 ++++++++ 3 files changed, 15 insertions(+), 6 deletions(-)
include/net/devlink.h +1 -0
@@ -1613,6 +1613,7 @@ struct devlink *priv_to_devlink(void *priv);struct device *devlink_to_dev (const struct devlink *devlink);const char *devlink_bus_name (const struct devlink *devlink);const char *devlink_dev_name (const struct devlink *devlink); +const char *devlink_dev_driver_name (const struct devlink *devlink);/* Devlink instance explicit locking */ void devl_lock (struct devlink *devlink);
include/trace/events/devlink.h +6 -6
@@ -23,7 +23,7 @@ TRACE_EVENT(devlink_hwmsg,TP_STRUCT__entry (__string (bus_name ,devlink_bus_name (devlink ))__string (dev_name,devlink_dev_name (devlink)) - __string(driver_name, devlink_to_dev(devlink)->driver->name) +__string (driver_name,devlink_dev_driver_name (devlink))__field (bool, incoming) __field(unsigned long, type) __dynamic_array(u8, buf, len)
@@ -57,7 +57,7 @@ TRACE_EVENT(devlink_hwerr,TP_STRUCT__entry (__string (bus_name ,devlink_bus_name (devlink ))__string (dev_name,devlink_dev_name (devlink)) - __string(driver_name, devlink_to_dev(devlink)->driver->name) +__string (driver_name,devlink_dev_driver_name (devlink))__field (int, err)__string (msg, msg) ),
@@ -87,7 +87,7 @@ TRACE_EVENT(devlink_health_report,TP_STRUCT__entry (__string (bus_name ,devlink_bus_name (devlink ))__string (dev_name,devlink_dev_name (devlink)) - __string(driver_name, devlink_to_dev(devlink)->driver->name) +__string (driver_name,devlink_dev_driver_name (devlink))__string (reporter_name, reporter_name)__string (msg, msg) ),
@@ -118,7 +118,7 @@ TRACE_EVENT(devlink_health_recover_aborted,TP_STRUCT__entry (__string (bus_name ,devlink_bus_name (devlink ))__string (dev_name,devlink_dev_name (devlink)) - __string(driver_name, devlink_to_dev(devlink)->driver->name) +__string (driver_name,devlink_dev_driver_name (devlink))__string (reporter_name, reporter_name)__field (bool, health_state) __field(u64, time_since_last_recover)
@@ -152,7 +152,7 @@ TRACE_EVENT(devlink_health_reporter_state_update,TP_STRUCT__entry (__string (bus_name ,devlink_bus_name (devlink ))__string (dev_name,devlink_dev_name (devlink)) - __string(driver_name, devlink_to_dev(devlink)->driver->name) +__string (driver_name,devlink_dev_driver_name (devlink))__string (reporter_name, reporter_name)__field (u8, new_state) ),
@@ -183,7 +183,7 @@ TRACE_EVENT(devlink_trap_report,TP_STRUCT__entry (__string (bus_name ,devlink_bus_name (devlink ))__string (dev_name,devlink_dev_name (devlink)) - __string(driver_name, devlink_to_dev(devlink)->driver->name) +__string (driver_name,devlink_dev_driver_name (devlink)) __string(trap_name, metadata->trap_name) __string(trap_group_name, metadata->trap_group_name) __array(char, input_dev_name, IFNAMSIZ)
net/devlink/core.c +8 -0
@@ -260,6 +260,14 @@ const char *devlink_dev_name(const struct devlink *devlink) }EXPORT_SYMBOL_GPL (devlink_dev_name); +const char *devlink_dev_driver_name (const struct devlink *devlink) +{ +struct device *dev = devlink->dev; + +return dev ? dev->driver->name :NULL ; +} +EXPORT_SYMBOL_GPL (devlink_dev_driver_name); +struct net *devlink_net (const struct devlink *devlink) {return read_pnet (&devlink->_net);
Signature · 1 line
2.51.1
Jakub Kicinski
maintainerRe: [PATCH net-next v2 06/10] devlink: add devlink_dev_driver_name() helper and use it in trace events
net/devlink/core.c const char *devlink_dev_name(const struct devlink *devlink) · line 269
Quoted 7 lines · On Wed, 25 Feb 2026 14:34:18 +0100 Jiri Pirko wrote:
net/devlink/core.c +7
-0+const char *devlink_dev_driver_name (const struct devlink *devlink) +{ +struct device *dev = devlink->dev; + +return dev ? dev->driver->name :NULL ; +} +EXPORT_SYMBOL_GPL (devlink_dev_driver_name);
You say we need this in prep for shared instances, which is fair, but shared instances should presumably share across the same driver, most of the time? So perhaps we should do a similar thing here as you did to the bus/dev name? Maybe when shared instance is allocated:
devlink->driver_name = kasprintf("%s+", dev->driver);And then:
+const char *devlink_dev_driver_name(const struct devlink *devlink) +{
+ struct device *dev = devlink->dev;
+
+ return dev ? dev->driver->name : devlink->driver_name;
+}
+EXPORT_SYMBOL_GPL(devlink_dev_driver_name);
?
Jiri Pirko
maintainerRe: [PATCH net-next v2 06/10] devlink: add devlink_dev_driver_name() helper and use it in trace events
Quoted 26 lines · Sat, Feb 28, 2026 at 11:58:05PM +0100, [email protected] wrote:
net/devlink/core.c const char *devlink_dev_name(const struct devlink *devlink) · line 269
Quoted 7 lines · On Wed, 25 Feb 2026 14:34:18 +0100 Jiri Pirko wrote:
net/devlink/core.c +7
-0+const char *devlink_dev_driver_name (const struct devlink *devlink) +{ +struct device *dev = devlink->dev; + +return dev ? dev->driver->name :NULL ; +} +EXPORT_SYMBOL_GPL (devlink_dev_driver_name);You say we need this in prep for shared instances, which is fair, but shared instances should presumably share across the same driver, most of the time? So perhaps we should do a similar thing here as you did to the bus/dev name? Maybe when shared instance is allocated:
devlink->driver_name = kasprintf("%s+", dev->driver);And then:
net/devlink/core.c +7
-0+const char *devlink_dev_driver_name (const struct devlink *devlink) +{ +struct device *dev = devlink->dev; + +return dev ? dev->driver->name : devlink->driver_name; +} +EXPORT_SYMBOL_GPL (devlink_dev_driver_name);
Quoted 2 lines
?
Good idea. Will add is in some form.
Jiri Pirko
maintainerPATCH v2 7/10 devlink: allow devlink instance allocation without a backing device
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
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.
---v1->v2:
- moved DEVLINK_INDEX_BUS_NAME definition to patch #5
- added comment to dev arg that it can be NULL
- fixed the index sprintf for dev-less
--- net/devlink/core.c | 25 +++++++++++++++++++------ net/devlink/dev.c | 11 +++++++---- net/devlink/devl_internal.h | 4 ++-- net/devlink/port.c | 14 +++++++++----- 4 files changed, 37 insertions(+), 17 deletions(-)
net/devlink/core.c +19 -6
@@ -331,7 +331,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); }
@@ -433,7 +436,7 @@ EXPORT_SYMBOL_GPL(devlink_unregister);* @ops: ops * @priv_size: size of user private data * @net: net namespace -* @dev: parent device +* @dev: parent device, or NULL for a device-less devlink instance * * Allocate new devlink instance resources, including devlink index * and name.
@@ -446,7 +449,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 ;
@@ -459,9 +462,17 @@ struct devlink *devlink_alloc_ns(const struct devlink_ops *ops,if (ret <0 ) goto err_xa_alloc; - devlink->dev =get_device (dev); - devlink->bus_name = dev->bus->name; - devlink->dev_name =dev_name (dev); +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; + } + devlink->ops = ops;xa_init_flags (&devlink->ports,XA_FLAGS_ALLOC );xa_init_flags (&devlink->params,XA_FLAGS_ALLOC );
@@ -486,6 +497,8 @@ struct devlink *devlink_alloc_ns(const struct devlink_ops *ops,return devlink; +err_kasprintf: +xa_erase (&devlinks, devlink->index); err_xa_alloc:kvfree (devlink);return NULL ;
net/devlink/dev.c +7 -4
@@ -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 ;
net/devlink/devl_internal.h +2 -2
@@ -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); }
net/devlink/port.c +9 -5
@@ -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);
Signature · 1 line
2.51.1
Jakub Kicinski
maintainerRe: [PATCH net-next v2 07/10] devlink: allow devlink instance allocation without a backing device
net/devlink/port.c static void devlink_port_type_warn(struct work_struct *work) · line 981
Quoted 4 lines · On Wed, 25 Feb 2026 14:34:19 +0100 Jiri Pirko wrote:
net/devlink/port.c +3
-1-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." );
since I'm already nit-picking - maybe we should have a helper for this case an pr_warn() the message if dev is NULL?
Jiri Pirko
maintainerRe: [PATCH net-next v2 07/10] devlink: allow devlink instance allocation without a backing device
Quoted 8 lines · Sun, Mar 01, 2026 at 12:01:38AM +0100, [email protected] wrote:
net/devlink/port.c static void devlink_port_type_warn(struct work_struct *work) · line 981
Quoted 4 lines · On Wed, 25 Feb 2026 14:34:19 +0100 Jiri Pirko wrote:
net/devlink/port.c +3
-1-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." );since I'm already nit-picking - maybe we should have a helper for this case an
pr_warn()the message if dev is NULL?
Okay
Jiri Pirko
maintainerPATCH v2 8/10 devlink: introduce shared devlink instance for PFs on same chip
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
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 not backed by any device 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:
pci/0000:08:00.0: index 0
nested_devlink:
auxiliary/mlx5_core.eth.0
devlink_index/1: index 1
nested_devlink:
pci/0000:08:00.0
pci/0000:08:00.1auxiliary/mlx5_core.eth.0: index 2
pci/0000:08:00.1: index 3
nested_devlink:
auxiliary/mlx5_core.eth.1
auxiliary/mlx5_core.eth.1: index 4
---v1->v2:
- s/err_kstrdup_id/err_devlink_free/
- fixed kernel-doc comment of devlink_shd_get()
- removed NULL arg check in devlink_shd_get/put()
--- include/net/devlink.h | 6 ++ net/devlink/Makefile | 2 +- net/devlink/sh_dev.c | 142 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 149 insertions(+), 1 deletion(-) create mode 100644 net/devlink/sh_dev.c
include/net/devlink.h +6 -0
@@ -1647,6 +1647,12 @@ void devlink_register(struct devlink *devlink);void devlink_unregister (struct devlink *devlink);void devlink_free (struct devlink *devlink); +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.
net/devlink/Makefile +1 -1
@@ -1,4 +1,4 @@ # SPDX-License-Identifier: GPL-2.0 obj-y := 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
net/devlink/sh_dev.c new file +142 -0
142 lines not on this page · raw message
Signature · 1 line
2.51.1
Jakub Kicinski
maintainernet/devlink/sh_dev.c line 19
Quoted 6 lines · On Wed, 25 Feb 2026 14:34:20 +0100 Jiri Pirko wrote:
net/devlink/sh_dev.c new file +6
-0+struct devlink_shd { +struct list_head list;/* Node in shd list */ +const char *id;/* Identifier string (e.g., serial number) */ +refcount_t refcount;/* Reference count */ +char priv[]__aligned(NETDEV_ALIGN) ;/* Driver private data */ +};
As pointed out by AI you promised a size member and a __counted_by() annotation :)
Signature · 1 line
pw-bot: cr
Jiri Pirko
maintainerQuoted 10 lines · Sun, Mar 01, 2026 at 12:03:11AM +0100, [email protected] wrote:
net/devlink/sh_dev.c line 19
Quoted 6 lines · On Wed, 25 Feb 2026 14:34:20 +0100 Jiri Pirko wrote:
net/devlink/sh_dev.c new file +6
-0+struct devlink_shd { +struct list_head list;/* Node in shd list */ +const char *id;/* Identifier string (e.g., serial number) */ +refcount_t refcount;/* Reference count */ +char priv[]__aligned(NETDEV_ALIGN) ;/* Driver private data */ +};As pointed out by AI you promised a size member and a
__counted_by()annotation :)
Yeah, somehow I got false impression this is not needed for priv. My bad, sorry, adding it.
Jiri Pirko
maintainerPATCH v2 9/10 documentation: networking: add shared devlink documentation
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
Document shared devlink instances for multiple PFs on the same chip.
---v1->v2:
- fixed number of "="'s
--- .../networking/devlink/devlink-shared.rst | 89 +++++++++++++++++++ Documentation/networking/devlink/index.rst | 1 + 2 files changed, 90 insertions(+) create mode 100644 Documentation/networking/devlink/devlink-shared.rst
Documentation/networking/devlink/devlink-shared.rst new file +89 -0
@@ -0,0 +1,89 @@ +.. SPDX-License-Identifier: GPL-2.0 + +======================== +Devlink Shared Instances +======================== + +Overview +======== + +Shared devlink instances allow multiple physical functions (PFs) on the same +chip to share an additional devlink instance for chip-wide operations. This +is implemented within individual drivers alongside the individual PF devlink +instances, not replacing them. + +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. The +shared devlink instance provides an object to pin configuration knobs on. + +The shared devlink instance is not backed by any struct *device*. + +Implementation +============== + +Architecture +------------ + +The implementation uses: + +* **Chip identification**: PFs are grouped by chip using a driver-specific identifier +* **Shared instance management**: Global list of shared instances with reference counting + +API Functions +------------- + +The following functions are provided for managing shared devlink instances: + +* ``devlink_shd_get()``: Get or create a shared devlink instance identified 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 device 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: + - 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 reference count) +3. **Shared instance is automatically destroyed** when the last PF removes (reference count reaches zero) + +Chip Identification +------------------- + +PFs belonging to the same chip are identified using a driver-specific method. +The driver is free to choose any identifier that is suitable for determining +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 groups 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 refcount``). +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.
Documentation/networking/devlink/index.rst +1 -0
@@ -68,6 +68,7 @@ general. devlink-resource devlink-selftests devlink-trap + devlink-shared Driver-specific documentation -----------------------------
Signature · 1 line
2.51.1
Jakub Kicinski
maintainerRe: [PATCH net-next v2 09/10] documentation: networking: add shared devlink documentation
Documentation/networking/devlink/devlink-shared.rst line 13
Quoted 4 lines · On Wed, 25 Feb 2026 14:34:21 +0100 Jiri Pirko wrote:
Documentation/networking/devlink/devlink-shared.rst new file +4
-0+Shared devlink instances allow multiple physical functions (PFs) on the same +chip to share an additional devlink instance for chip-wide operations. This +is implemented within individual drivers alongside the individual PF devlink +instances, not replacing them.
Sounds like you want to preclude what was the goal in the discussion with Przemek you quoted - a shared instance _only_ case. We don't have to implement it today, but I think it's an entirely sane direction. So the docs should not state otherwise.
Jiri Pirko
maintainerRe: [PATCH net-next v2 09/10] documentation: networking: add shared devlink documentation
Quoted 10 lines · Sun, Mar 01, 2026 at 12:05:58AM +0100, [email protected] wrote:
Documentation/networking/devlink/devlink-shared.rst line 13
Quoted 4 lines · On Wed, 25 Feb 2026 14:34:21 +0100 Jiri Pirko wrote:
Documentation/networking/devlink/devlink-shared.rst new file +4
-0+Shared devlink instances allow multiple physical functions (PFs) on the same +chip to share an additional devlink instance for chip-wide operations. This +is implemented within individual drivers alongside the individual PF devlink +instances, not replacing them.Sounds like you want to preclude what was the goal in the discussion with Przemek you quoted - a shared instance _only_ case. We don't have to implement it today, but I think it's an entirely sane direction. So the docs should not state otherwise.
Fair enough, I can do it.
Jiri Pirko
maintainerPATCH v2 10/10 net/mlx5: Add a shared devlink instance for PFs on same chip
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
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 is removed, mlx5_shd_uninit() calls devlink_shd_put() to release the reference. The shared instance is automatically destroyed when the last PF is removed.
Make the PF devlink instances nested in this shared devlink instance, allowing userspace to identify which PFs belong to the same physical chip.
Example:
pci/0000:08:00.0: index 0
nested_devlink:
auxiliary/mlx5_core.eth.0
devlink_index/1: index 1
nested_devlink:
pci/0000:08:00.0
pci/0000:08:00.1auxiliary/mlx5_core.eth.0: index 2
pci/0000:08:00.1: index 3
nested_devlink:
auxiliary/mlx5_core.eth.1
auxiliary/mlx5_core.eth.1: index 4
--- .../net/ethernet/mellanox/mlx5/core/Makefile | 5 +- .../net/ethernet/mellanox/mlx5/core/main.c | 17 +++++ .../ethernet/mellanox/mlx5/core/sh_devlink.c | 62 +++++++++++++++++++ .../ethernet/mellanox/mlx5/core/sh_devlink.h | 12 ++++ include/linux/mlx5/driver.h | 1 + 5 files changed, 95 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
drivers/net/ethernet/mellanox/mlx5/core/Makefile +3 -2
@@ -16,8 +16,9 @@ mlx5_core-y := main.o cmd.o debugfs.o fw.o eq.o uar.o pagealloc.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 wq.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_vnic.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 # # Netdev basic
drivers/net/ethernet/mellanox/mlx5/core/main.c +17 -0
@@ -74,6 +74,7 @@#include "mlx5_irq.h" #include "hwmon.h" #include "lag/lag.h" +#include "sh_devlink.h" MODULE_AUTHOR ("Eli Cohen <[email protected]>" );MODULE_DESCRIPTION ("Mellanox 5th generation network adapters (ConnectX series) core driver" );
@@ -1520,10 +1521,16 @@ int mlx5_init_one(struct mlx5_core_dev *dev)int err;devl_lock (devlink); +if (dev->shd) { + err =devl_nested_devlink_set (dev->shd, devlink); +if (err) + goto unlock; + }devl_register (devlink); err =mlx5_init_one_devl_locked (dev);if (err)devl_unregister (devlink); +unlock:devl_unlock (devlink);return err; }
@@ -2005,6 +2012,13 @@ static int probe_one(struct pci_dev *pdev, const struct pci_device_id *id) goto pci_init_err; } + err =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 =mlx5_init_one (dev);if (err) { mlx5_core_err(dev, "mlx5_init_one failed with error code %d\n",
@@ -2018,6 +2032,8 @@ static int probe_one(struct pci_dev *pdev, const struct pci_device_id *id)return 0 ; err_init_one: +mlx5_shd_uninit (dev); +shd_init_err:mlx5_pci_close (dev); pci_init_err:mlx5_mdev_uninit (dev);
@@ -2039,6 +2055,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);
drivers/net/ethernet/mellanox/mlx5/core/sh_devlink.c new file +62 -0
62 lines not on this page · raw message
drivers/net/ethernet/mellanox/mlx5/core/sh_devlink.h new file +12 -0
@@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */ +/* Copyright (c) 2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved. */ + +#ifndef __MLX5_SH_DEVLINK_H__ +#define __MLX5_SH_DEVLINK_H__ + +#include <linux/mlx5/driver.h> + +int mlx5_shd_init (struct mlx5_core_dev *dev); +void mlx5_shd_uninit (struct mlx5_core_dev *dev); + +#endif /* __MLX5_SH_DEVLINK_H__ */
include/linux/mlx5/driver.h +1 -0
@@ -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; };struct mlx5_db {
Signature · 1 line
2.51.1