diff options
author | Jiri Pirko <jiri@mellanox.com> | 2018-04-05 23:13:21 +0300 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2018-04-08 19:45:57 +0300 |
commit | fc56be47da8cb111add373c36230b0139139898f (patch) | |
tree | db38258b8c93ea6920c61702fbd43d5840584b1c /include/net | |
parent | 5571196135abb6d51e01592812997403c136067c (diff) | |
download | linux-fc56be47da8cb111add373c36230b0139139898f.tar.xz |
devlink: convert occ_get op to separate registration
This resolves race during initialization where the resources with
ops are registered before driver and the structures used by occ_get
op is initialized. So keep occ_get callbacks registered only when
all structs are initialized.
The example flows, as it is in mlxsw:
1) driver load/asic probe:
mlxsw_core
-> mlxsw_sp_resources_register
-> mlxsw_sp_kvdl_resources_register
-> devlink_resource_register IDX
mlxsw_spectrum
-> mlxsw_sp_kvdl_init
-> mlxsw_sp_kvdl_parts_init
-> mlxsw_sp_kvdl_part_init
-> devlink_resource_size_get IDX (to get the current setup
size from devlink)
-> devlink_resource_occ_get_register IDX (register current
occupancy getter)
2) reload triggered by devlink command:
-> mlxsw_devlink_core_bus_device_reload
-> mlxsw_sp_fini
-> mlxsw_sp_kvdl_fini
-> devlink_resource_occ_get_unregister IDX
(struct mlxsw_sp *mlxsw_sp is freed at this point, call to occ get
which is using mlxsw_sp would cause use-after free)
-> mlxsw_sp_init
-> mlxsw_sp_kvdl_init
-> mlxsw_sp_kvdl_parts_init
-> mlxsw_sp_kvdl_part_init
-> devlink_resource_size_get IDX (to get the current setup
size from devlink)
-> devlink_resource_occ_get_register IDX (register current
occupancy getter)
Fixes: d9f9b9a4d05f ("devlink: Add support for resource abstraction")
Signed-off-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'include/net')
-rw-r--r-- | include/net/devlink.h | 40 |
1 files changed, 26 insertions, 14 deletions
diff --git a/include/net/devlink.h b/include/net/devlink.h index e21d8cadd480..2e4f71e16e95 100644 --- a/include/net/devlink.h +++ b/include/net/devlink.h @@ -232,14 +232,6 @@ struct devlink_dpipe_headers { }; /** - * struct devlink_resource_ops - resource ops - * @occ_get: get the occupied size - */ -struct devlink_resource_ops { - u64 (*occ_get)(struct devlink *devlink); -}; - -/** * struct devlink_resource_size_params - resource's size parameters * @size_min: minimum size which can be set * @size_max: maximum size which can be set @@ -265,6 +257,8 @@ devlink_resource_size_params_init(struct devlink_resource_size_params *size_para size_params->unit = unit; } +typedef u64 devlink_resource_occ_get_t(void *priv); + /** * struct devlink_resource - devlink resource * @name: name of the resource @@ -277,7 +271,6 @@ devlink_resource_size_params_init(struct devlink_resource_size_params *size_para * @size_params: size parameters * @list: parent list * @resource_list: list of child resources - * @resource_ops: resource ops */ struct devlink_resource { const char *name; @@ -289,7 +282,8 @@ struct devlink_resource { struct devlink_resource_size_params size_params; struct list_head list; struct list_head resource_list; - const struct devlink_resource_ops *resource_ops; + devlink_resource_occ_get_t *occ_get; + void *occ_get_priv; }; #define DEVLINK_RESOURCE_ID_PARENT_TOP 0 @@ -409,8 +403,7 @@ int devlink_resource_register(struct devlink *devlink, u64 resource_size, u64 resource_id, u64 parent_resource_id, - const struct devlink_resource_size_params *size_params, - const struct devlink_resource_ops *resource_ops); + const struct devlink_resource_size_params *size_params); void devlink_resources_unregister(struct devlink *devlink, struct devlink_resource *resource); int devlink_resource_size_get(struct devlink *devlink, @@ -419,6 +412,12 @@ int devlink_resource_size_get(struct devlink *devlink, int devlink_dpipe_table_resource_set(struct devlink *devlink, const char *table_name, u64 resource_id, u64 resource_units); +void devlink_resource_occ_get_register(struct devlink *devlink, + u64 resource_id, + devlink_resource_occ_get_t *occ_get, + void *occ_get_priv); +void devlink_resource_occ_get_unregister(struct devlink *devlink, + u64 resource_id); #else @@ -562,8 +561,7 @@ devlink_resource_register(struct devlink *devlink, u64 resource_size, u64 resource_id, u64 parent_resource_id, - const struct devlink_resource_size_params *size_params, - const struct devlink_resource_ops *resource_ops) + const struct devlink_resource_size_params *size_params) { return 0; } @@ -589,6 +587,20 @@ devlink_dpipe_table_resource_set(struct devlink *devlink, return -EOPNOTSUPP; } +static inline void +devlink_resource_occ_get_register(struct devlink *devlink, + u64 resource_id, + devlink_resource_occ_get_t *occ_get, + void *occ_get_priv) +{ +} + +static inline void +devlink_resource_occ_get_unregister(struct devlink *devlink, + u64 resource_id) +{ +} + #endif #endif /* _NET_DEVLINK_H_ */ |