devlink: params cleanups and devl_param_driverinit_value_get() fix
Subsystems (3)
Jiri Pirko
maintainerv2 cover devlink: params cleanups and devl_param_driverinit_value_get() fix
From: Jiri Pirko <[email protected]>
The primary motivation of this patchset is the patch #6, which fixes an issue introduced by 075935f0ae0f ("devlink: protect devlink param list by instance lock") and reported by Kim Phillips <[email protected]>
(https://lore.kernel.org/netdev/[email protected]/)
and my colleagues doing mlx5 driver regression testing.
The basis idea is that devl_param_driverinit_value_get() could be possible to the called without holding devlink intance lock in most of the cases (all existing ones in the current codebase), which would fix some mlx5 flows where the lock is not held.
To achieve that, make sure that the param value does not change between reloads with patch #2.
Also, convert the param list to xarray which removes the worry about list_head consistency when doing lockless lookup.
The rest of the patches are doing some small related cleanup of things that poke me in the eye during the work.
---v1->v2:
- a small bug was fixed in patch #2, the rest of the code stays the same so I left review/ack tags attached to them
Jiri Pirko (7):
devlink: don't use strcpy() to copy param value
devlink: make sure driver does not read updated driverinit param
before reload
devlink: fix the name of value arg of
devl_param_driverinit_value_get()
devlink: use xa_for_each_start() helper in
devlink_nl_cmd_port_get_dump_one()
devlink: convert param list to xarray
devlink: allow to call devl_param_driverinit_value_get() without
holding instance lock
devlink: add forgotten devlink instance lock assertion to
devl_param_driverinit_value_set()
include/net/devlink.h | 6 +- net/devlink/core.c | 4 +- net/devlink/dev.c | 3 + net/devlink/devl_internal.h | 5 +- net/devlink/leftover.c | 139 ++++++++++++++++++++---------------- 5 files changed, 91 insertions(+), 66 deletions(-)
Signature · 1 line
2.39.0
Jiri Pirko
maintainerPATCH v2 1/7 devlink: don't use strcpy() to copy param value
From: Jiri Pirko <[email protected]>
No need to treat string params any different comparing to other types. Rely on the struct assign to copy the whole struct, including the string.
--- net/devlink/leftover.c | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-)
net/devlink/leftover.c +3 -12
@@ -4388,10 +4388,7 @@ static int __devlink_nl_cmd_param_set_doit(struct devlink *devlink,return -EOPNOTSUPP ;if (cmode ==DEVLINK_PARAM_CMODE_DRIVERINIT ) { -if (param->type ==DEVLINK_PARAM_TYPE_STRING ) -strcpy (param_item->driverinit_value.vstr, value.vstr); -else - param_item->driverinit_value = value; + param_item->driverinit_value = value; param_item->driverinit_value_valid = true; }else {if (!param->set)
@@ -9656,10 +9653,7 @@ int devl_param_driverinit_value_get(struct devlink *devlink, u32 param_id, DEVLINK_PARAM_CMODE_DRIVERINIT)))return -EOPNOTSUPP ; -if (param_item->param->type ==DEVLINK_PARAM_TYPE_STRING ) -strcpy (init_val->vstr, param_item->driverinit_value.vstr); -else - *init_val = param_item->driverinit_value; + *init_val = param_item->driverinit_value;return 0 ; }
@@ -9690,10 +9684,7 @@ void devl_param_driverinit_value_set(struct devlink *devlink, u32 param_id, DEVLINK_PARAM_CMODE_DRIVERINIT)))return ; -if (param_item->param->type ==DEVLINK_PARAM_TYPE_STRING ) -strcpy (param_item->driverinit_value.vstr, init_val.vstr); -else - param_item->driverinit_value = init_val; + param_item->driverinit_value = init_val; param_item->driverinit_value_valid = true;devlink_param_notify (devlink,0 , param_item,DEVLINK_CMD_PARAM_NEW );
Signature · 1 line
2.39.0
Re: [patch net-next v2 1/7] devlink: don't use strcpy() to copy param value
Quoted 5 lines · Jiri Pirko
From: Jiri Pirko <[email protected]>
No need to treat string params any different comparing to other types. Rely on the struct assign to copy the whole struct, including the string.
I suspect the strcpy came from thinking about it as if it stored a pointer to the string and not as an array struct member.
Makes sense.
Quoted 48 lines
Signed-off-by Jiri Pirko <[email protected]>Reviewed-by Simon Horman <[email protected]>Acked-by Jakub Kicinski <[email protected]>--- net/devlink/leftover.c | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-)net/devlink/leftover.c +3
-12@@ -4388,10 +4388,7 @@ static int __devlink_nl_cmd_param_set_doit(struct devlink *devlink,return -EOPNOTSUPP ;if (cmode ==DEVLINK_PARAM_CMODE_DRIVERINIT ) { -if (param->type ==DEVLINK_PARAM_TYPE_STRING ) -strcpy (param_item->driverinit_value.vstr, value.vstr); -else - param_item->driverinit_value = value; + param_item->driverinit_value = value; param_item->driverinit_value_valid = true; }else {if (!param->set)@@ -9656,10 +9653,7 @@ int devl_param_driverinit_value_get(struct devlink *devlink, u32 param_id, DEVLINK_PARAM_CMODE_DRIVERINIT)))return -EOPNOTSUPP ; -if (param_item->param->type ==DEVLINK_PARAM_TYPE_STRING ) -strcpy (init_val->vstr, param_item->driverinit_value.vstr); -else - *init_val = param_item->driverinit_value; + *init_val = param_item->driverinit_value;return 0 ; }@@ -9690,10 +9684,7 @@ void devl_param_driverinit_value_set(struct devlink *devlink, u32 param_id, DEVLINK_PARAM_CMODE_DRIVERINIT)))return ; -if (param_item->param->type ==DEVLINK_PARAM_TYPE_STRING ) -strcpy (param_item->driverinit_value.vstr, init_val.vstr); -else - param_item->driverinit_value = init_val; + param_item->driverinit_value = init_val; param_item->driverinit_value_valid = true;devlink_param_notify (devlink,0 , param_item,DEVLINK_CMD_PARAM_NEW );
Jiri Pirko
maintainerPATCH v2 2/7 devlink: make sure driver does not read updated driverinit param before reload
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
The driverinit param purpose is to serve the driver during init/reload time to provide a value, either default or set by user.
Make sure that driver does not read value updated by user before the reload is performed. Hold the new value in a separate struct and switch it during reload.
Note that this is required to be eventually possible to call devl_param_driverinit_value_get() without holding instance lock.
---v1->v2:
- extended patch description with a note
- call driverinit_load_new only if action is REINIT
--- include/net/devlink.h | 4 ++++ net/devlink/dev.c | 3 +++ net/devlink/devl_internal.h | 3 +++ net/devlink/leftover.c | 26 ++++++++++++++++++++++---- 4 files changed, 32 insertions(+), 4 deletions(-)
include/net/devlink.h +4 -0
@@ -489,6 +489,10 @@ struct devlink_param_item {const struct devlink_param *param;union devlink_param_value driverinit_value;bool driverinit_value_valid; +union devlink_param_value driverinit_value_new;/* Not reachable +* until reload. +*/ +bool driverinit_value_new_valid; };enum devlink_param_generic_id {
net/devlink/dev.c +3 -0
@@ -369,6 +369,9 @@ int devlink_reload(struct devlink *devlink, struct net *dest_net,if (dest_net && !net_eq (dest_net, curr_net))devlink_reload_netns_change (devlink, curr_net, dest_net); +if (action ==DEVLINK_RELOAD_ACTION_DRIVER_REINIT ) +devlink_params_driverinit_load_new (devlink); + err = devlink->ops->reload_up (devlink, action, limit, actions_performed, extack);devlink_reload_failed_set (devlink, !!err);if (err)
net/devlink/devl_internal.h +3 -0
@@ -189,6 +189,9 @@ static inline bool devlink_reload_supported(const struct devlink_ops *ops)return ops->reload_down && ops->reload_up; } +/* Params */ +void devlink_params_driverinit_load_new (struct devlink *devlink); +/* Resources */ struct devlink_resource ; int devlink_resources_validate(struct devlink *devlink,
net/devlink/leftover.c +22 -4
@@ -4098,9 +4098,12 @@ static int devlink_nl_param_fill(struct sk_buff *msg, struct devlink *devlink,if (!devlink_param_cmode_is_supported (param, i))continue ;if (i ==DEVLINK_PARAM_CMODE_DRIVERINIT ) { -if (!param_item->driverinit_value_valid) +if (param_item->driverinit_value_new_valid) + param_value[i] = param_item->driverinit_value_new; +else if (param_item->driverinit_value_valid) + param_value[i] = param_item->driverinit_value; +else return -EOPNOTSUPP ; - param_value[i] = param_item->driverinit_value; }else { ctx.cmode = i; err =devlink_param_get (devlink, param, &ctx);
@@ -4388,8 +4391,8 @@ static int __devlink_nl_cmd_param_set_doit(struct devlink *devlink,return -EOPNOTSUPP ;if (cmode ==DEVLINK_PARAM_CMODE_DRIVERINIT ) { - param_item->driverinit_value = value; - param_item->driverinit_value_valid = true; + param_item->driverinit_value_new = value; + param_item->driverinit_value_new_valid = true; }else {if (!param->set)return -EOPNOTSUPP ;
@@ -9691,6 +9694,21 @@ void devl_param_driverinit_value_set(struct devlink *devlink, u32 param_id, }EXPORT_SYMBOL_GPL (devl_param_driverinit_value_set); +void devlink_params_driverinit_load_new (struct devlink *devlink) +{ +struct devlink_param_item *param_item; + +list_for_each_entry (param_item, &devlink->param_list, list) { +if (!devlink_param_cmode_is_supported (param_item->param, +DEVLINK_PARAM_CMODE_DRIVERINIT ) || + !param_item->driverinit_value_new_valid) +continue ; + param_item->driverinit_value = param_item->driverinit_value_new; + param_item->driverinit_value_valid = true; + param_item->driverinit_value_new_valid = false; + } +} +/** * devl_param_value_changed - notify devlink on a parameter's value * change. Should be called by the driver
Signature · 1 line
2.39.0
Re: [patch net-next v2 2/7] devlink: make sure driver does not read updated driverinit param before reload
Quoted 9 lines · Jiri Pirko
From: Jiri Pirko <[email protected]>
The driverinit param purpose is to serve the driver during init/reload time to provide a value, either default or set by user.
Make sure that driver does not read value updated by user before the reload is performed. Hold the new value in a separate struct and switch it during reload.
Quoted 7 lines
Note that this is required to be eventually possible to call
devl_param_driverinit_value_get()without holding instance lock.Signed-off-by Jiri Pirko <[email protected]>---
v1->v2:
- extended patch description with a note
Thanks!
Quoted 1 line
- call
driverinit_load_newonly if action is REINIT
Jiri Pirko
maintainerPATCH v2 3/7 devlink: fix the name of value arg of devl_param_driverinit_value_get()
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
Probably due to copy-paste error, the name of the arg is "init_val" which is misleading, as the pointer is used to point to struct where to store the current value. Rename it to "val" and change the arg comment a bit on the way.
--- include/net/devlink.h | 2 +- net/devlink/leftover.c | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-)
include/net/devlink.h +1 -1
@@ -1784,7 +1784,7 @@ void devlink_params_unregister(struct devlink *devlink,const struct devlink_param *params, size_t params_count);int devl_param_driverinit_value_get (struct devlink *devlink,u32 param_id, -union devlink_param_value *init_val); +union devlink_param_value *val);void devl_param_driverinit_value_set (struct devlink *devlink,u32 param_id,union devlink_param_value init_val);void devl_param_value_changed (struct devlink *devlink,u32 param_id);
net/devlink/leftover.c +4 -3
@@ -9630,13 +9630,14 @@ EXPORT_SYMBOL_GPL(devlink_params_unregister);* * @devlink: devlink * @param_id: parameter ID -* @init_val: value of parameter in driverinit configuration mode +* @val: pointer to store the value of parameter in driverinit +* configuration mode * * This function should be used by the driver to get driverinit * configuration for initialization after reload command. */ int devl_param_driverinit_value_get (struct devlink *devlink,u32 param_id, -union devlink_param_value *init_val) +union devlink_param_value *val) {struct devlink_param_item *param_item;
@@ -9656,7 +9657,7 @@ int devl_param_driverinit_value_get(struct devlink *devlink, u32 param_id, DEVLINK_PARAM_CMODE_DRIVERINIT)))return -EOPNOTSUPP ; - *init_val = param_item->driverinit_value; + *val = param_item->driverinit_value;return 0 ; }
Signature · 1 line
2.39.0
Re: [patch net-next v2 3/7] devlink: fix the name of value arg of devl_param_driverinit_value_get()
Quoted 10 lines · Jiri Pirko
From: Jiri Pirko <[email protected]>
Probably due to copy-paste error, the name of the arg is "
init_val" which is misleading, as the pointer is used to point to struct where to store the current value. Rename it to "val" and change the arg comment a bit on the way.Signed-off-by Jiri Pirko <[email protected]>Reviewed-by Simon Horman <[email protected]>Acked-by Jakub Kicinski <[email protected]>
Quoted 48 lines
--- include/net/devlink.h | 2 +- net/devlink/leftover.c | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-)include/net/devlink.h +1
-1@@ -1784,7 +1784,7 @@ void devlink_params_unregister(struct devlink *devlink,const struct devlink_param *params, size_t params_count);int devl_param_driverinit_value_get (struct devlink *devlink,u32 param_id, -union devlink_param_value *init_val); +union devlink_param_value *val);void devl_param_driverinit_value_set (struct devlink *devlink,u32 param_id,union devlink_param_value init_val);void devl_param_value_changed (struct devlink *devlink,u32 param_id);net/devlink/leftover.c +4
-3@@ -9630,13 +9630,14 @@ EXPORT_SYMBOL_GPL(devlink_params_unregister);* * @devlink: devlink * @param_id: parameter ID -* @init_val: value of parameter in driverinit configuration mode +* @val: pointer to store the value of parameter in driverinit +* configuration mode * * This function should be used by the driver to get driverinit * configuration for initialization after reload command. */ int devl_param_driverinit_value_get (struct devlink *devlink,u32 param_id, -union devlink_param_value *init_val) +union devlink_param_value *val) {struct devlink_param_item *param_item;@@ -9656,7 +9657,7 @@ int devl_param_driverinit_value_get(struct devlink *devlink, u32 param_id, DEVLINK_PARAM_CMODE_DRIVERINIT)))return -EOPNOTSUPP ; - *init_val = param_item->driverinit_value; + *val = param_item->driverinit_value;return 0 ; }
Jiri Pirko
maintainerPATCH v2 4/7 devlink: use xa_for_each_start() helper in devlink_nl_cmd_port_get_dump_one()
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
As xarray has an iterator helper that allows to start from specified index, use this directly and avoid repeated iteration from 0.
--- net/devlink/leftover.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-)
net/devlink/leftover.c +2 -8
@@ -1111,24 +1111,18 @@ devlink_nl_cmd_port_get_dump_one(struct sk_buff *msg, struct devlink *devlink,struct devlink_nl_dump_state *state =devlink_dump_state (cb);struct devlink_port *devlink_port;unsigned long port_index; -int idx =0 ;int err =0 ; -xa_for_each (&devlink->ports, port_index, devlink_port) { -if (idx < state->idx) { - idx++; -continue ; - } +xa_for_each_start (&devlink->ports, port_index, devlink_port, state->idx) { err =devlink_nl_port_fill (msg, devlink_port,DEVLINK_CMD_NEW ,NETLINK_CB (cb->skb).portid, cb->nlh->nlmsg_seq,NLM_F_MULTI , cb->extack);if (err) { - state->idx = idx; + state->idx = port_index;break ; } - idx++; }return err;
Signature · 1 line
2.39.0
Re: [patch net-next v2 4/7] devlink: use xa_for_each_start() helper in devlink_nl_cmd_port_get_dump_one()
Quoted 8 lines · Jiri Pirko
From: Jiri Pirko <[email protected]>
As xarray has an iterator helper that allows to start from specified index, use this directly and avoid repeated iteration from 0.
Signed-off-by Jiri Pirko <[email protected]>Reviewed-by Simon Horman <[email protected]>Acked-by Jakub Kicinski <[email protected]>
Jiri Pirko
maintainerPATCH v2 5/7 devlink: convert param list to xarray
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
Loose the linked list for params and use xarray instead.
Note that this is required to be eventually possible to call devl_param_driverinit_value_get() without holding instance lock.
---v1->v2:
- extended patch description with a note
--- net/devlink/core.c | 4 +-- net/devlink/devl_internal.h | 2 +- net/devlink/leftover.c | 72 ++++++++++++++++++------------------- 3 files changed, 39 insertions(+), 39 deletions(-)
net/devlink/core.c +2 -2
@@ -212,6 +212,7 @@ struct devlink *devlink_alloc_ns(const struct devlink_ops *ops, devlink->dev = dev; devlink->ops = ops;xa_init_flags (&devlink->ports,XA_FLAGS_ALLOC ); +xa_init_flags (&devlink->params,XA_FLAGS_ALLOC );xa_init_flags (&devlink->snapshot_ids,XA_FLAGS_ALLOC );write_pnet (&devlink->_net, net);INIT_LIST_HEAD (&devlink->rate_list);
@@ -219,7 +220,6 @@ struct devlink *devlink_alloc_ns(const struct devlink_ops *ops,INIT_LIST_HEAD (&devlink->sb_list);INIT_LIST_HEAD_RCU (&devlink->dpipe_table_list);INIT_LIST_HEAD (&devlink->resource_list); -INIT_LIST_HEAD (&devlink->param_list);INIT_LIST_HEAD (&devlink->region_list);INIT_LIST_HEAD (&devlink->reporter_list);INIT_LIST_HEAD (&devlink->trap_list);
@@ -255,7 +255,6 @@ void devlink_free(struct devlink *devlink)WARN_ON (!list_empty (&devlink->trap_list));WARN_ON (!list_empty (&devlink->reporter_list));WARN_ON (!list_empty (&devlink->region_list)); -WARN_ON (!list_empty (&devlink->param_list));WARN_ON (!list_empty (&devlink->resource_list));WARN_ON (!list_empty (&devlink->dpipe_table_list));WARN_ON (!list_empty (&devlink->sb_list));
@@ -264,6 +263,7 @@ void devlink_free(struct devlink *devlink)WARN_ON (!xa_empty (&devlink->ports));xa_destroy (&devlink->snapshot_ids); +xa_destroy (&devlink->params);xa_destroy (&devlink->ports);WARN_ON_ONCE (unregister_netdevice_notifier (&devlink->netdevice_nb));
net/devlink/devl_internal.h +1 -1
@@ -29,7 +29,7 @@ struct devlink {struct list_head sb_list;struct list_head dpipe_table_list;struct list_head resource_list; -struct list_head param_list; +struct xarray params;struct list_head region_list;struct list_head reporter_list;struct devlink_dpipe_headers *dpipe_headers;
net/devlink/leftover.c +36 -36
209 lines not on this page · raw message
Signature · 1 line
2.39.0
Re: [patch net-next v2 5/7] devlink: convert param list to xarray
Quoted 10 lines · Jiri Pirko
From: Jiri Pirko <[email protected]>
Loose the linked list for params and use xarray instead.
Note that this is required to be eventually possible to call
devl_param_driverinit_value_get()without holding instance lock.Signed-off-by Jiri Pirko <[email protected]>Reviewed-by Simon Horman <[email protected]>Acked-by Jakub Kicinski <[email protected]>
That makes loading by the parameter id faster too since we don't have to iterate the full list. Nice.
Jiri Pirko
maintainerPATCH v2 6/7 devlink: allow to call devl_param_driverinit_value_get() without holding instance lock
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
If the driver maintains following basic sane behavior, the devl_param_driverinit_value_get() function could be called without holding instance lock:
1) Driver ensures a call to devl_param_driverinit_value_get() cannot race with registering/unregistering the parameter with the same parameter ID.
2) Driver ensures a call to devl_param_driverinit_value_get() cannot race with devl_param_driverinit_value_set() call with the same parameter ID.
3) Driver ensures a call to devl_param_driverinit_value_get() cannot race with reload operation.
By the nature of params usage, these requirements should be trivially achievable. If the driver for some off reason is not able to comply, it has to take the devlink->lock while calling devl_param_driverinit_value_get().
Remove the lock assertion and add comment describing the locking requirements.
This fixes a splat in mlx5 driver introduced by the commit referenced in the "Fixes" tag.
Lore: https://lore.kernel.org/netdev/[email protected]/
--- net/devlink/leftover.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
net/devlink/leftover.c +11 -2
@@ -9628,14 +9628,23 @@ EXPORT_SYMBOL_GPL(devlink_params_unregister);* * This function should be used by the driver to get driverinit * configuration for initialization after reload command. +* +* Note that lockless call of this function relies on the +* driver to maintain following basic sane behavior: +* 1) Driver ensures a call to this function cannot race with +* registering/unregistering the parameter with the same parameter ID. +* 2) Driver ensures a call to this function cannot race with +* devl_param_driverinit_value_set() call with the same parameter ID. +* 3) Driver ensures a call to this function cannot race with +* reload operation. +* If the driver is not able to comply, it has to take the devlink->lock +* while calling this. */ int devl_param_driverinit_value_get (struct devlink *devlink,u32 param_id,union devlink_param_value *val) {struct devlink_param_item *param_item; -lockdep_assert_held (&devlink->lock); -if (WARN_ON (!devlink_reload_supported (devlink->ops)))return -EOPNOTSUPP ;
Signature · 1 line
2.39.0
Re: [patch net-next v2 6/7] devlink: allow to call devl_param_driverinit_value_get() without holding instance lock
Quoted 20 lines · Jiri Pirko
From: Jiri Pirko <[email protected]>
If the driver maintains following basic sane behavior, the
devl_param_driverinit_value_get()function could be called without holding instance lock:1) Driver ensures a call to
devl_param_driverinit_value_get()cannot race with registering/unregistering the parameter with the same parameter ID.
2) Driver ensures a call todevl_param_driverinit_value_get()cannot race withdevl_param_driverinit_value_set()call with the same parameter ID.
3) Driver ensures a call todevl_param_driverinit_value_get()cannot race with reload operation.By the nature of params usage, these requirements should be trivially achievable. If the driver for some off reason is not able to comply, it has to take the
devlink->lockwhile callingdevl_param_driverinit_value_get().
Quoted 5 lines
Remove the lock assertion and add comment describing the locking requirements.
This fixes a splat in mlx5 driver introduced by the commit referenced in the "Fixes" tag.
Just to clarify, is it possible for mlx5 to take the instance lock instead of these changes? I agree the improvements make sense here, but it seems like an alternative fix would be to grab the lock around the get function call in mlx5.
Either way, the assumptions here seem reasonable and the series makes sense.
Thanks,
Jake
Quoted 41 lines
Lore: https://lore.kernel.org/netdev/[email protected]/
Reported-by Kim Phillips <[email protected]>Fixes 075935f0ae0f ("devlink: protect devlink param list by instance lock")Signed-off-by Jiri Pirko <[email protected]>Reviewed-by Simon Horman <[email protected]>Acked-by Jakub Kicinski <[email protected]>--- net/devlink/leftover.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)net/devlink/leftover.c +11
-2@@ -9628,14 +9628,23 @@ EXPORT_SYMBOL_GPL(devlink_params_unregister);* * This function should be used by the driver to get driverinit * configuration for initialization after reload command. +* +* Note that lockless call of this function relies on the +* driver to maintain following basic sane behavior: +* 1) Driver ensures a call to this function cannot race with +* registering/unregistering the parameter with the same parameter ID. +* 2) Driver ensures a call to this function cannot race with +* devl_param_driverinit_value_set() call with the same parameter ID. +* 3) Driver ensures a call to this function cannot race with +* reload operation. +* If the driver is not able to comply, it has to take the devlink->lock +* while calling this. */ int devl_param_driverinit_value_get (struct devlink *devlink,u32 param_id,union devlink_param_value *val) {struct devlink_param_item *param_item; -lockdep_assert_held (&devlink->lock); -if (WARN_ON (!devlink_reload_supported (devlink->ops)))return -EOPNOTSUPP ;
Jiri Pirko
maintainerRe: [patch net-next v2 6/7] devlink: allow to call devl_param_driverinit_value_get() without holding instance lock
Quoted 26 lines · Fri, Feb 10, 2023 at 08:41:27PM CET, [email protected] wrote:
Quoted 23 lines · Jiri Pirko
From: Jiri Pirko <[email protected]>
If the driver maintains following basic sane behavior, the
devl_param_driverinit_value_get()function could be called without holding instance lock:1) Driver ensures a call to
devl_param_driverinit_value_get()cannot race with registering/unregistering the parameter with the same parameter ID.
2) Driver ensures a call todevl_param_driverinit_value_get()cannot race withdevl_param_driverinit_value_set()call with the same parameter ID.
3) Driver ensures a call todevl_param_driverinit_value_get()cannot race with reload operation.By the nature of params usage, these requirements should be trivially achievable. If the driver for some off reason is not able to comply, it has to take the
devlink->lockwhile callingdevl_param_driverinit_value_get().Remove the lock assertion and add comment describing the locking requirements.
Quoted 7 lines
Quoted 2 lines
This fixes a splat in mlx5 driver introduced by the commit referenced in the "Fixes" tag.
Just to clarify, is it possible for mlx5 to take the instance lock instead of these changes? I agree the improvements make sense here, but it seems like an alternative fix would be to grab the lock around the get function call in mlx5.
You are correct, yes.
Quoted 49 lines
Either way, the assumptions here seem reasonable and the series makes sense.
Reviewed-by Jacob Keller <[email protected]>Thanks,
JakeQuoted 41 lines
Lore: https://lore.kernel.org/netdev/[email protected]/
Reported-by Kim Phillips <[email protected]>Fixes 075935f0ae0f ("devlink: protect devlink param list by instance lock")Signed-off-by Jiri Pirko <[email protected]>Reviewed-by Simon Horman <[email protected]>Acked-by Jakub Kicinski <[email protected]>--- net/devlink/leftover.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)net/devlink/leftover.c +11
-2@@ -9628,14 +9628,23 @@ EXPORT_SYMBOL_GPL(devlink_params_unregister);* * This function should be used by the driver to get driverinit * configuration for initialization after reload command. +* +* Note that lockless call of this function relies on the +* driver to maintain following basic sane behavior: +* 1) Driver ensures a call to this function cannot race with +* registering/unregistering the parameter with the same parameter ID. +* 2) Driver ensures a call to this function cannot race with +* devl_param_driverinit_value_set() call with the same parameter ID. +* 3) Driver ensures a call to this function cannot race with +* reload operation. +* If the driver is not able to comply, it has to take the devlink->lock +* while calling this. */ int devl_param_driverinit_value_get (struct devlink *devlink,u32 param_id,union devlink_param_value *val) {struct devlink_param_item *param_item; -lockdep_assert_held (&devlink->lock); -if (WARN_ON (!devlink_reload_supported (devlink->ops)))return -EOPNOTSUPP ;
Re: [patch net-next v2 6/7] devlink: allow to call devl_param_driverinit_value_get() without holding instance lock
In reply to Jiri PirkoQuoted 26 lines · Jiri Pirko
From: Jiri Pirko <[email protected]>
If the driver maintains following basic sane behavior, the
devl_param_driverinit_value_get()function could be called without holding instance lock:1) Driver ensures a call to
devl_param_driverinit_value_get()cannot race with registering/unregistering the parameter with the same parameter ID.
2) Driver ensures a call todevl_param_driverinit_value_get()cannot race withdevl_param_driverinit_value_set()call with the same parameter ID.
3) Driver ensures a call todevl_param_driverinit_value_get()cannot race with reload operation.By the nature of params usage, these requirements should be trivially achievable. If the driver for some off reason is not able to comply, it has to take the
devlink->lockwhile callingdevl_param_driverinit_value_get().Remove the lock assertion and add comment describing the locking requirements.
This fixes a splat in mlx5 driver introduced by the commit referenced in the "Fixes" tag.
Quoted 7 lines
Lore: https://lore.kernel.org/netdev/[email protected]/
Reported-by Kim Phillips <[email protected]>Fixes 075935f0ae0f ("devlink: protect devlink param list by instance lock")Signed-off-by Jiri Pirko <[email protected]>Reviewed-by Simon Horman <[email protected]>Acked-by Jakub Kicinski <[email protected]>---
Please add my:
to this patch, if not the entire series.
Thanks!
Kim
p.s. Sorry about my testing snafu on v1 of this series - it wasn't clear to me what fixes were where...
Jiri Pirko
maintainerPATCH v2 7/7 devlink: add forgotten devlink instance lock assertion to devl_param_driverinit_value_set()
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
Driver calling devl_param_driverinit_value_set() has to hold devlink instance lock while doing that. Put an assertion there.
--- net/devlink/leftover.c | 2 ++ 1 file changed, 2 insertions(+)
net/devlink/leftover.c +2 -0
@@ -9682,6 +9682,8 @@ void devl_param_driverinit_value_set(struct devlink *devlink, u32 param_id, {struct devlink_param_item *param_item; +devl_assert_locked (devlink); + param_item =devlink_param_find_by_id (&devlink->params, param_id);if (WARN_ON (!param_item))return ;
Signature · 1 line
2.39.0
Re: [patch net-next v2 7/7] devlink: add forgotten devlink instance lock assertion to devl_param_driverinit_value_set()
Quoted 8 lines · Jiri Pirko
From: Jiri Pirko <[email protected]>
Driver calling
devl_param_driverinit_value_set()has to hold devlink instance lock while doing that. Put an assertion there.Signed-off-by Jiri Pirko <[email protected]>Reviewed-by Simon Horman <[email protected]>Acked-by Jakub Kicinski <[email protected]>
Quoted 17 lines
--- net/devlink/leftover.c | 2 ++ 1 file changed, 2 insertions(+)net/devlink/leftover.c +2
-0@@ -9682,6 +9682,8 @@ void devl_param_driverinit_value_set(struct devlink *devlink, u32 param_id, {struct devlink_param_item *param_item; +devl_assert_locked (devlink); + param_item =devlink_param_find_by_id (&devlink->params, param_id);if (WARN_ON (!param_item))return ;
This series was applied to netdev/net-next.git (master) by David S. Miller <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (master) by David S. Miller <[email protected]>:
Quoted 9 lines · On Fri, 10 Feb 2023 11:01:24 +0100 you wrote:
From: Jiri Pirko <[email protected]>
The primary motivation of this patchset is the patch #6, which fixes an issue introduced by
075935f0ae0f("devlink: protect devlink param list by instance lock") and reported by Kim Phillips <[email protected]>
(https://lore.kernel.org/netdev/[email protected]/)
and my colleagues doing mlx5 driver regression testing.[...]
Here is the summary with links:
- [net-next,v2,1/7] devlink: don't use strcpy() to copy param value
https://git.kernel.org/netdev/net-next/c/fa2f921f3bf1 - [net-next,v2,2/7] devlink: make sure driver does not read updated driverinit param before reload https://git.kernel.org/netdev/net-next/c/afd888c3e19c - [net-next,v2,3/7] devlink: fix the name of value arg of devl_param_driverinit_value_get() https://git.kernel.org/netdev/net-next/c/94ba1c316b9c - [net-next,v2,4/7] devlink: use xa_for_each_start() helper in devlink_nl_cmd_port_get_dump_one() https://git.kernel.org/netdev/net-next/c/fbcf938150ec - [net-next,v2,5/7] devlink: convert param list to xarray https://git.kernel.org/netdev/net-next/c/a72e17b45232 - [net-next,v2,6/7] devlink: allow to call devl_param_driverinit_value_get() without holding instance lock https://git.kernel.org/netdev/net-next/c/280f7b2adca0 - [net-next,v2,7/7] devlink: add forgotten devlink instance lock assertion to devl_param_driverinit_value_set() https://git.kernel.org/netdev/net-next/c/6b4bfa43ce29
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html