summaryrefslogtreecommitdiffstats
path: root/net/devlink
diff options
context:
space:
mode:
authorJiri Pirko <jiri@nvidia.com>2023-02-10 11:01:26 +0100
committerDavid S. Miller <davem@davemloft.net>2023-02-13 09:49:14 +0000
commitafd888c3e19ceb5247158fe2fabbf7234937a515 (patch)
tree6ee81524048814d2708e1997aaf29f55c9444dcf /net/devlink
parentfa2f921f3bf1ed98956ad341b920a55aab69bc35 (diff)
downloadlinux-afd888c3e19ceb5247158fe2fabbf7234937a515.tar.gz
linux-afd888c3e19ceb5247158fe2fabbf7234937a515.tar.bz2
linux-afd888c3e19ceb5247158fe2fabbf7234937a515.zip
devlink: make sure driver does not read updated driverinit param before reload
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. Signed-off-by: Jiri Pirko <jiri@nvidia.com> Reviewed-by: Simon Horman <simon.horman@corigine.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/devlink')
-rw-r--r--net/devlink/dev.c3
-rw-r--r--net/devlink/devl_internal.h3
-rw-r--r--net/devlink/leftover.c26
3 files changed, 28 insertions, 4 deletions
diff --git a/net/devlink/dev.c b/net/devlink/dev.c
index 7cf2de44e02f..ab4e0f3c4e3d 100644
--- a/net/devlink/dev.c
+++ b/net/devlink/dev.c
@@ -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)
diff --git a/net/devlink/devl_internal.h b/net/devlink/devl_internal.h
index 941174e157d4..5c117e8d4377 100644
--- a/net/devlink/devl_internal.h
+++ b/net/devlink/devl_internal.h
@@ -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,
diff --git a/net/devlink/leftover.c b/net/devlink/leftover.c
index 2f9e309727c7..f74aca8ba3ab 100644
--- a/net/devlink/leftover.c
+++ b/net/devlink/leftover.c
@@ -4097,9 +4097,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);
@@ -4387,8 +4390,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;
@@ -9690,6 +9693,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