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: d9f9b9a4d0
("devlink: Add support for resource abstraction")
Signed-off-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:

committed by
David S. Miller

parent
5571196135
commit
fc56be47da
@@ -231,14 +231,6 @@ struct devlink_dpipe_headers {
|
||||
unsigned int headers_count;
|
||||
};
|
||||
|
||||
/**
|
||||
* 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
|
||||
@@ -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_ */
|
||||
|
Reference in New Issue
Block a user