e8058a49 | 28-Mar-2024 |
Johannes Berg <johannes.berg@intel.com> |
netlink: introduce type-checking attribute iteration
There are, especially with multi-attr arrays, many cases of needing to iterate all attributes of a specific type in a netlink message or a nested
netlink: introduce type-checking attribute iteration
There are, especially with multi-attr arrays, many cases of needing to iterate all attributes of a specific type in a netlink message or a nested attribute. Add specific macros to support that case.
Also convert many instances using this spatch:
@@ iterator nla_for_each_attr; iterator name nla_for_each_attr_type; identifier nla; expression head, len, rem; expression ATTR; type T; identifier x; @@ -nla_for_each_attr(nla, head, len, rem) +nla_for_each_attr_type(nla, ATTR, head, len, rem) { <... T x; ...> -if (nla_type(nla) == ATTR) { ... -} }
@@ identifier nla; iterator nla_for_each_nested; iterator name nla_for_each_nested_type; expression attr, rem; expression ATTR; type T; identifier x; @@ -nla_for_each_nested(nla, attr, rem) +nla_for_each_nested_type(nla, ATTR, attr, rem) { <... T x; ...> -if (nla_type(nla) == ATTR) { ... -} }
@@ iterator nla_for_each_attr; iterator name nla_for_each_attr_type; identifier nla; expression head, len, rem; expression ATTR; type T; identifier x; @@ -nla_for_each_attr(nla, head, len, rem) +nla_for_each_attr_type(nla, ATTR, head, len, rem) { <... T x; ...> -if (nla_type(nla) != ATTR) continue; ... }
@@ identifier nla; iterator nla_for_each_nested; iterator name nla_for_each_nested_type; expression attr, rem; expression ATTR; type T; identifier x; @@ -nla_for_each_nested(nla, attr, rem) +nla_for_each_nested_type(nla, ATTR, attr, rem) { <... T x; ...> -if (nla_type(nla) != ATTR) continue; ... }
Although I had to undo one bad change this made, and I also adjusted some other code for whitespace and to use direct variable initialization now.
Signed-off-by: Johannes Berg <johannes.berg@intel.com> Link: https://lore.kernel.org/r/20240328203144.b5a6c895fb80.I1869b44767379f204998ff44dd239803f39c23e0@changeid Signed-off-by: Jakub Kicinski <kuba@kernel.org>
show more ...
|
61c43780 | 20-Feb-2024 |
Jiri Pirko <jiri@nvidia.com> |
devlink: fix port dump cmd type
Unlike other commands, due to a c&p error, port dump fills-up cmd with wrong value, different from port-get request cmd, port-get doit reply and port notification.
F
devlink: fix port dump cmd type
Unlike other commands, due to a c&p error, port dump fills-up cmd with wrong value, different from port-get request cmd, port-get doit reply and port notification.
Fix it by filling cmd with value DEVLINK_CMD_PORT_NEW.
Skimmed through devlink userspace implementations, none of them cares about this cmd value. Only ynl, for which, this is actually a fix, as it expects doit and dumpit ops rsp_value to be the same.
Omit the fixes tag, even thought this is fix, better to target this for next release.
Fixes: bfcd3a466172 ("Introduce devlink infrastructure") Signed-off-by: Jiri Pirko <jiri@nvidia.com> Reviewed-by: Simon Horman <horms@kernel.org> Reviewed-by: Jakub Kicinski <kuba@kernel.org> Link: https://lore.kernel.org/r/20240220075245.75416-1-jiri@resnulli.us Signed-off-by: Jakub Kicinski <kuba@kernel.org>
show more ...
|
13b127d2 | 16-Dec-2023 |
Jiri Pirko <jiri@nvidia.com> |
devlink: add a command to set notification filter and use it for multicasts
Currently the user listening on a socket for devlink notifications gets always all messages for all existing instances, ev
devlink: add a command to set notification filter and use it for multicasts
Currently the user listening on a socket for devlink notifications gets always all messages for all existing instances, even if he is interested only in one of those. That may cause unnecessary overhead on setups with thousands of instances present.
User is currently able to narrow down the devlink objects replies to dump commands by specifying select attributes.
Allow similar approach for notifications. Introduce a new devlink NOTIFY_FILTER_SET which the user passes the select attributes. Store these per-socket and use them for filtering messages during multicast send.
Signed-off-by: Jiri Pirko <jiri@nvidia.com> Signed-off-by: Paolo Abeni <pabeni@redhat.com>
show more ...
|
5648de0b | 16-Dec-2023 |
Jiri Pirko <jiri@nvidia.com> |
devlink: introduce a helper for netlink multicast send
Introduce a helper devlink_nl_notify_send() so each object notification function does not have to call genlmsg_multicast_netns() with the same
devlink: introduce a helper for netlink multicast send
Introduce a helper devlink_nl_notify_send() so each object notification function does not have to call genlmsg_multicast_netns() with the same arguments.
Signed-off-by: Jiri Pirko <jiri@nvidia.com> Signed-off-by: Paolo Abeni <pabeni@redhat.com>
show more ...
|
cddbff47 | 16-Dec-2023 |
Jiri Pirko <jiri@nvidia.com> |
devlink: send notifications only if there are listeners
Introduce devlink_nl_notify_need() helper and using it to check at the beginning of notification functions to avoid overhead of composing noti
devlink: send notifications only if there are listeners
Introduce devlink_nl_notify_need() helper and using it to check at the beginning of notification functions to avoid overhead of composing notification messages in case nobody listens.
Signed-off-by: Jiri Pirko <jiri@nvidia.com> Signed-off-by: Paolo Abeni <pabeni@redhat.com>
show more ...
|
11280dde | 16-Dec-2023 |
Jiri Pirko <jiri@nvidia.com> |
devlink: introduce __devl_is_registered() helper and use it instead of xa_get_mark()
Introduce __devl_is_registered() which does not assert on devlink instance lock and use it in notifications which
devlink: introduce __devl_is_registered() helper and use it instead of xa_get_mark()
Introduce __devl_is_registered() which does not assert on devlink instance lock and use it in notifications which may be called without devlink instance lock held.
Signed-off-by: Jiri Pirko <jiri@nvidia.com> Signed-off-by: Paolo Abeni <pabeni@redhat.com>
show more ...
|
527a07e1 | 15-Nov-2023 |
Ido Schimmel <idosch@nvidia.com> |
devlink: Add device lock assert in reload operation
Add an assert to verify that the device lock is always held throughout reload operations.
Tested the following flows with netdevsim and mlxsw whi
devlink: Add device lock assert in reload operation
Add an assert to verify that the device lock is always held throughout reload operations.
Tested the following flows with netdevsim and mlxsw while lockdep is enabled:
netdevsim:
# echo "10 1" > /sys/bus/netdevsim/new_device # devlink dev reload netdevsim/netdevsim10 # ip netns add bla # devlink dev reload netdevsim/netdevsim10 netns bla # ip netns del bla # echo 10 > /sys/bus/netdevsim/del_device
mlxsw:
# devlink dev reload pci/0000:01:00.0 # ip netns add bla # devlink dev reload pci/0000:01:00.0 netns bla # ip netns del bla # echo 1 > /sys/bus/pci/devices/0000\:01\:00.0/remove # echo 1 > /sys/bus/pci/rescan
Signed-off-by: Ido Schimmel <idosch@nvidia.com> Reviewed-by: Jiri Pirko <jiri@nvidia.com> Signed-off-by: Petr Machata <petrm@nvidia.com> Reviewed-by: Simon Horman <horms@kernel.org> Signed-off-by: David S. Miller <davem@davemloft.net>
show more ...
|
bf6b200b | 15-Nov-2023 |
Ido Schimmel <idosch@nvidia.com> |
devlink: Acquire device lock during reload command
Device drivers register with devlink from their probe routines (under the device lock) by acquiring the devlink instance lock and calling devl_regi
devlink: Acquire device lock during reload command
Device drivers register with devlink from their probe routines (under the device lock) by acquiring the devlink instance lock and calling devl_register().
Drivers that support a devlink reload usually implement the reload_{down, up}() operations in a similar fashion to their remove and probe routines, respectively.
However, while the remove and probe routines are invoked with the device lock held, the reload operations are only invoked with the devlink instance lock held. It is therefore impossible for drivers to acquire the device lock from their reload operations, as this would result in lock inversion.
The motivating use case for invoking the reload operations with the device lock held is in mlxsw which needs to trigger a PCI reset as part of the reload. The driver cannot call pci_reset_function() as this function acquires the device lock. Instead, it needs to call __pci_reset_function_locked which expects the device lock to be held.
To that end, adjust devlink to always acquire the device lock before the devlink instance lock when performing a reload.
Do that when reload is explicitly triggered by user space by specifying the 'DEVLINK_NL_FLAG_NEED_DEV_LOCK' flag in the pre_doit and post_doit operations of the reload command.
A previous patch already handled the case where reload is invoked as part of netns dismantle.
Signed-off-by: Ido Schimmel <idosch@nvidia.com> Reviewed-by: Jiri Pirko <jiri@nvidia.com> Signed-off-by: Petr Machata <petrm@nvidia.com> Reviewed-by: Simon Horman <horms@kernel.org> Signed-off-by: David S. Miller <davem@davemloft.net>
show more ...
|
d32c3825 | 15-Nov-2023 |
Ido Schimmel <idosch@nvidia.com> |
devlink: Allow taking device lock in pre_doit operations
Introduce a new private flag ('DEVLINK_NL_FLAG_NEED_DEV_LOCK') to allow netlink commands to specify that they need to acquire the device lock
devlink: Allow taking device lock in pre_doit operations
Introduce a new private flag ('DEVLINK_NL_FLAG_NEED_DEV_LOCK') to allow netlink commands to specify that they need to acquire the device lock in their pre_doit operation and release it in their post_doit operation.
The reload command will use this flag in the subsequent patch.
No functional changes intended.
Signed-off-by: Ido Schimmel <idosch@nvidia.com> Reviewed-by: Jiri Pirko <jiri@nvidia.com> Signed-off-by: Petr Machata <petrm@nvidia.com> Reviewed-by: Simon Horman <horms@kernel.org> Signed-off-by: David S. Miller <davem@davemloft.net>
show more ...
|
c8d0a7d6 | 15-Nov-2023 |
Ido Schimmel <idosch@nvidia.com> |
devlink: Enable the use of private flags in post_doit operations
Currently, private flags (e.g., 'DEVLINK_NL_FLAG_NEED_PORT') are only used in pre_doit operations, but a subsequent patch will need t
devlink: Enable the use of private flags in post_doit operations
Currently, private flags (e.g., 'DEVLINK_NL_FLAG_NEED_PORT') are only used in pre_doit operations, but a subsequent patch will need to conditionally lock and unlock the device lock in pre and post doit operations, respectively.
As a preparation, enable the use of private flags in post_doit operations in a similar fashion to how it is done for pre_doit operations.
No functional changes intended.
Signed-off-by: Ido Schimmel <idosch@nvidia.com> Reviewed-by: Jiri Pirko <jiri@nvidia.com> Signed-off-by: Petr Machata <petrm@nvidia.com> Reviewed-by: Simon Horman <horms@kernel.org> Signed-off-by: David S. Miller <davem@davemloft.net>
show more ...
|
e21c52d7 | 15-Nov-2023 |
Ido Schimmel <idosch@nvidia.com> |
devlink: Acquire device lock during netns dismantle
Device drivers register with devlink from their probe routines (under the device lock) by acquiring the devlink instance lock and calling devl_reg
devlink: Acquire device lock during netns dismantle
Device drivers register with devlink from their probe routines (under the device lock) by acquiring the devlink instance lock and calling devl_register().
Drivers that support a devlink reload usually implement the reload_{down, up}() operations in a similar fashion to their remove and probe routines, respectively.
However, while the remove and probe routines are invoked with the device lock held, the reload operations are only invoked with the devlink instance lock held. It is therefore impossible for drivers to acquire the device lock from their reload operations, as this would result in lock inversion.
The motivating use case for invoking the reload operations with the device lock held is in mlxsw which needs to trigger a PCI reset as part of the reload. The driver cannot call pci_reset_function() as this function acquires the device lock. Instead, it needs to call __pci_reset_function_locked which expects the device lock to be held.
To that end, adjust devlink to always acquire the device lock before the devlink instance lock when performing a reload.
For now, only do that when reload is triggered as part of netns dismantle. Subsequent patches will handle the case where reload is explicitly triggered by user space.
Signed-off-by: Ido Schimmel <idosch@nvidia.com> Reviewed-by: Jiri Pirko <jiri@nvidia.com> Signed-off-by: Petr Machata <petrm@nvidia.com> Reviewed-by: Simon Horman <horms@kernel.org> Signed-off-by: David S. Miller <davem@davemloft.net>
show more ...
|
cebe7306 | 21-Oct-2023 |
Jiri Pirko <jiri@nvidia.com> |
devlink: remove netlink small_ops
All commands are now covered by generated split_ops. Remove the small_ops entirely alongside with unified devlink netlink policy array.
Signed-off-by: Jiri Pirko <
devlink: remove netlink small_ops
All commands are now covered by generated split_ops. Remove the small_ops entirely alongside with unified devlink netlink policy array.
Signed-off-by: Jiri Pirko <jiri@nvidia.com> Reviewed-by: Jacob Keller <jacob.e.keller@intel.com> Link: https://lore.kernel.org/r/20231021112711.660606-11-jiri@resnulli.us Signed-off-by: Jakub Kicinski <kuba@kernel.org>
show more ...
|
15c80e7a | 21-Oct-2023 |
Jiri Pirko <jiri@nvidia.com> |
devlink: remove duplicated netlink callback prototypes
The prototypes are now generated, remove the old ones.
Signed-off-by: Jiri Pirko <jiri@nvidia.com> Reviewed-by: Jacob Keller <jacob.e.keller@i
devlink: remove duplicated netlink callback prototypes
The prototypes are now generated, remove the old ones.
Signed-off-by: Jiri Pirko <jiri@nvidia.com> Reviewed-by: Jacob Keller <jacob.e.keller@intel.com> Link: https://lore.kernel.org/r/20231021112711.660606-10-jiri@resnulli.us Signed-off-by: Jakub Kicinski <kuba@kernel.org>
show more ...
|