devlink: linecard and reporters locking cleanup
Subsystems (6)
Jiri Pirko
maintainerv4 cover devlink: linecard and reporters locking cleanup
From: Jiri Pirko <[email protected]>
This patchset does not change functionality.
Patches 1-6 removes linecards and reporters locks and reference counting, converting them to be protected by devlink instance lock as the rest of the objects.
Patches 7 and 8 convert linecards and reporters dumpit callbacks to recently introduced devlink_nl_instance_iter_dump() infra. Patch 9 removes no longer needed devlink_dump_for_each_instance_get() helper.
The last patch adds assertion to devl_is_registered() as dependency on other locks is removed.
---v3->v4:
- patch #1 was removed from the set and will be sent as a part of another patchsetv2->v3:
- see individual patches for changelog, mainly original patch #4 was split into 3 patches for easier reviewv1->v2:
- patch 7 bits were unsquashed to patch 8
Jiri Pirko (10):
devlink: remove linecards lock
devlink: remove linecard reference counting
devlink: protect health reporter operation with instance lock
devlink: remove reporters_lock
devlink: remove devl_port_health_reporter_destroy()
devlink: remove reporter reference counting
devlink: convert linecards dump to devlink_nl_instance_iter_dump()
devlink: convert reporters dump to devlink_nl_instance_iter_dump()
devlink: remove devlink_dump_for_each_instance_get() helper
devlink: add instance lock assertion in devl_is_registered()
.../ethernet/mellanox/mlx5/core/en/health.c | 12 + .../mellanox/mlx5/core/en/reporter_rx.c | 6 +- .../mellanox/mlx5/core/en/reporter_tx.c | 6 +- drivers/net/ethernet/mellanox/mlxsw/core.c | 8 +- .../ethernet/mellanox/mlxsw/core_linecards.c | 8 +- drivers/net/netdevsim/health.c | 20 +- include/net/devlink.h | 26 +- net/devlink/core.c | 4 - net/devlink/devl_internal.h | 20 +- net/devlink/leftover.c | 428 +++++++----------- net/devlink/netlink.c | 12 +- 11 files changed, 213 insertions(+), 337 deletions(-)
Signature · 1 line
2.39.0
Jiri Pirko
maintainerPATCH v4 1/10 devlink: remove linecards lock
From: Jiri Pirko <[email protected]>
Similar to other devlink objects, convert the linecards list to be protected by devlink instance lock. Alongside with that rename the create/destroy() functions to devl_* to indicate the devlink instance lock needs to be held while calling them.
---v2->v3: fixed typo in patch description
--- .../ethernet/mellanox/mlxsw/core_linecards.c | 8 ++-- include/net/devlink.h | 6 +-- net/devlink/core.c | 2 - net/devlink/devl_internal.h | 1 - net/devlink/leftover.c | 41 +++++++------------ 5 files changed, 21 insertions(+), 37 deletions(-)
drivers/net/ethernet/mellanox/mlxsw/core_linecards.c +4 -4
@@ -1259,9 +1259,9 @@ static int mlxsw_linecard_init(struct mlxsw_core *mlxsw_core, linecard->linecards = linecards;mutex_init (&linecard->lock); - devlink_linecard =devlink_linecard_create (priv_to_devlink (mlxsw_core), - slot_index, &mlxsw_linecard_ops, - linecard); + devlink_linecard =devl_linecard_create (priv_to_devlink (mlxsw_core), + slot_index, &mlxsw_linecard_ops, + linecard);if (IS_ERR (devlink_linecard))return PTR_ERR (devlink_linecard);
@@ -1285,7 +1285,7 @@ static void mlxsw_linecard_fini(struct mlxsw_core *mlxsw_core,if (linecard->active)mlxsw_linecard_active_clear (linecard);mlxsw_linecard_bdev_del (linecard); -devlink_linecard_destroy (linecard->devlink_linecard); +devl_linecard_destroy (linecard->devlink_linecard);mutex_destroy (&linecard->lock); }
include/net/devlink.h +3 -3
@@ -1687,9 +1687,9 @@ void devl_rate_nodes_destroy(struct devlink *devlink);void devlink_port_linecard_set (struct devlink_port *devlink_port,struct devlink_linecard *linecard);struct devlink_linecard * -devlink_linecard_create (struct devlink *devlink,unsigned int linecard_index, -const struct devlink_linecard_ops *ops,void *priv); -void devlink_linecard_destroy (struct devlink_linecard *linecard); +devl_linecard_create (struct devlink *devlink,unsigned int linecard_index, +const struct devlink_linecard_ops *ops,void *priv); +void devl_linecard_destroy (struct devlink_linecard *linecard);void devlink_linecard_provision_set (struct devlink_linecard *linecard,const char *type);void devlink_linecard_provision_clear (struct devlink_linecard *linecard);
net/devlink/core.c +0 -2
@@ -235,7 +235,6 @@ struct devlink *devlink_alloc_ns(const struct devlink_ops *ops,mutex_init (&devlink->lock);lockdep_set_class (&devlink->lock, &devlink->lock_key);mutex_init (&devlink->reporters_lock); -mutex_init (&devlink->linecards_lock);refcount_set (&devlink->refcount,1 );return devlink;
@@ -257,7 +256,6 @@ void devlink_free(struct devlink *devlink) {ASSERT_DEVLINK_NOT_REGISTERED (devlink); -mutex_destroy (&devlink->linecards_lock);mutex_destroy (&devlink->reporters_lock);mutex_destroy (&devlink->lock);lockdep_unregister_key (&devlink->lock_key);
net/devlink/devl_internal.h +0 -1
@@ -37,7 +37,6 @@ struct devlink {struct list_head trap_group_list;struct list_head trap_policer_list;struct list_head linecard_list; -struct mutex linecards_lock;/* protects linecard_list */ const struct devlink_ops *ops;u64 features;struct xarray snapshot_ids;
net/devlink/leftover.c +14 -27
115 lines not on this page · raw message
Signature · 1 line
2.39.0
Jiri Pirko
maintainerPATCH v4 2/10 devlink: remove linecard reference counting
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
As long as the linecard life time is protected by devlink instance lock, the reference counting is no longer needed. Remove it.
---v2->v3:
- removed devlink_linecard_put() prototype from devl_internal.h
- fixed typo in patch description
--- net/devlink/devl_internal.h | 1 - net/devlink/leftover.c | 14 ++------------ net/devlink/netlink.c | 5 ----- 3 files changed, 2 insertions(+), 18 deletions(-)
net/devlink/devl_internal.h +0 -1
@@ -192,7 +192,6 @@ struct devlink_linecard;struct devlink_linecard *devlink_linecard_get_from_info (struct devlink *devlink,struct genl_info *info); -void devlink_linecard_put (struct devlink_linecard *linecard);/* Rates */ extern const struct devlink_gen_cmd devl_gen_rate_get;
net/devlink/leftover.c +2 -12
@@ -37,7 +37,6 @@ struct devlink_linecard {struct list_head list;struct devlink *devlink;unsigned int index; -refcount_t refcount;const struct devlink_linecard_ops *ops;void *priv;enum devlink_linecard_state state;
@@ -285,7 +284,6 @@ devlink_linecard_get_from_attrs(struct devlink *devlink, struct nlattr **attrs) linecard =devlink_linecard_get_by_index (devlink, linecard_index);if (!linecard)return ERR_PTR (-ENODEV ); -refcount_inc (&linecard->refcount);return linecard; }return ERR_PTR (-EINVAL );
@@ -297,14 +295,6 @@ devlink_linecard_get_from_info(struct devlink *devlink, struct genl_info *info)return devlink_linecard_get_from_attrs (devlink, info->attrs); } -void devlink_linecard_put (struct devlink_linecard *linecard) -{ -if (refcount_dec_and_test (&linecard->refcount)) { -mutex_destroy (&linecard->state_lock); -kfree (linecard); - } -} -struct devlink_sb {struct list_head list;unsigned int index;
@@ -10271,7 +10261,6 @@ devl_linecard_create(struct devlink *devlink, unsigned int linecard_index, }list_add_tail (&linecard->list, &devlink->linecard_list); -refcount_set (&linecard->refcount,1 );devlink_linecard_notify (linecard,DEVLINK_CMD_LINECARD_NEW );return linecard; }
@@ -10287,7 +10276,8 @@ void devl_linecard_destroy(struct devlink_linecard *linecard)devlink_linecard_notify (linecard,DEVLINK_CMD_LINECARD_DEL );list_del (&linecard->list);devlink_linecard_types_fini (linecard); -devlink_linecard_put (linecard); +mutex_destroy (&linecard->state_lock); +kfree (linecard); }EXPORT_SYMBOL_GPL (devl_linecard_destroy);
net/devlink/netlink.c +0 -5
@@ -170,14 +170,9 @@ static int devlink_nl_pre_doit(const struct genl_split_ops *ops,static void devlink_nl_post_doit (const struct genl_split_ops *ops,struct sk_buff *skb,struct genl_info *info) { -struct devlink_linecard *linecard;struct devlink *devlink; devlink = info->user_ptr[0 ]; -if (ops->internal_flags &DEVLINK_NL_FLAG_NEED_LINECARD ) { - linecard = info->user_ptr[1 ]; -devlink_linecard_put (linecard); - }devl_unlock (devlink);devlink_put (devlink); }
Signature · 1 line
2.39.0
Jiri Pirko
maintainerPATCH v4 3/10 devlink: protect health reporter operation with instance lock
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
Similar to other devlink objects, protect the reporters list by devlink instance lock. Alongside add unlocked versions of health reporter create/destroy functions and use them in drivers on call paths where the instance lock is held.
---v2->v3:
- split from v2 patch #4 - "devlink: remove reporters_lock", no change
--- .../ethernet/mellanox/mlx5/core/en/health.c | 12 +++ .../mellanox/mlx5/core/en/reporter_rx.c | 6 +- .../mellanox/mlx5/core/en/reporter_tx.c | 6 +- drivers/net/ethernet/mellanox/mlxsw/core.c | 8 +- drivers/net/netdevsim/health.c | 20 ++--- include/net/devlink.h | 18 +++-- net/devlink/leftover.c | 76 +++++++++++++------ 7 files changed, 97 insertions(+), 49 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en/health.c +12 -0
@@ -137,14 +137,26 @@ int mlx5e_health_eq_diag_fmsg(struct mlx5_eq_comp *eq, struct devlink_fmsg *fmsgvoid mlx5e_health_create_reporters (struct mlx5e_priv *priv) { +struct devlink *devlink =priv_to_devlink (priv->mdev); + +if (!(priv->mdev->priv.flags &MLX5_PRIV_FLAGS_MLX5E_LOCKED_FLOW )) +devl_lock (devlink);mlx5e_reporter_tx_create (priv);mlx5e_reporter_rx_create (priv); +if (!(priv->mdev->priv.flags &MLX5_PRIV_FLAGS_MLX5E_LOCKED_FLOW )) +devl_unlock (devlink); }void mlx5e_health_destroy_reporters (struct mlx5e_priv *priv) { +struct devlink *devlink =priv_to_devlink (priv->mdev); + +if (!(priv->mdev->priv.flags &MLX5_PRIV_FLAGS_MLX5E_LOCKED_FLOW )) +devl_lock (devlink);mlx5e_reporter_rx_destroy (priv);mlx5e_reporter_tx_destroy (priv); +if (!(priv->mdev->priv.flags &MLX5_PRIV_FLAGS_MLX5E_LOCKED_FLOW )) +devl_unlock (devlink); }void mlx5e_health_channels_update (struct mlx5e_priv *priv)
drivers/net/ethernet/mellanox/mlx5/core/en/reporter_rx.c +3 -3
@@ -739,8 +739,8 @@ void mlx5e_reporter_rx_create(struct mlx5e_priv *priv)struct devlink_port *dl_port =mlx5e_devlink_get_dl_port (priv);struct devlink_health_reporter *reporter; - reporter =devlink_port_health_reporter_create (dl_port, &mlx5_rx_reporter_ops, -MLX5E_REPORTER_RX_GRACEFUL_PERIOD , priv); + reporter =devl_port_health_reporter_create (dl_port, &mlx5_rx_reporter_ops, +MLX5E_REPORTER_RX_GRACEFUL_PERIOD , priv);if (IS_ERR (reporter)) {netdev_warn (priv->netdev,"Failed to create rx reporter, err = %ld\n" ,PTR_ERR (reporter));
@@ -754,6 +754,6 @@ void mlx5e_reporter_rx_destroy(struct mlx5e_priv *priv)if (!priv->rx_reporter)return ; -devlink_port_health_reporter_destroy (priv->rx_reporter); +devl_port_health_reporter_destroy (priv->rx_reporter); priv->rx_reporter =NULL ; }
drivers/net/ethernet/mellanox/mlx5/core/en/reporter_tx.c +3 -3
@@ -593,8 +593,8 @@ void mlx5e_reporter_tx_create(struct mlx5e_priv *priv)struct devlink_port *dl_port =mlx5e_devlink_get_dl_port (priv);struct devlink_health_reporter *reporter; - reporter =devlink_port_health_reporter_create (dl_port, &mlx5_tx_reporter_ops, -MLX5_REPORTER_TX_GRACEFUL_PERIOD , priv); + reporter =devl_port_health_reporter_create (dl_port, &mlx5_tx_reporter_ops, +MLX5_REPORTER_TX_GRACEFUL_PERIOD , priv);if (IS_ERR (reporter)) { netdev_warn(priv->netdev, "Failed to create tx reporter, err = %ld\n",
@@ -609,6 +609,6 @@ void mlx5e_reporter_tx_destroy(struct mlx5e_priv *priv)if (!priv->tx_reporter)return ; -devlink_port_health_reporter_destroy (priv->tx_reporter); +devl_port_health_reporter_destroy (priv->tx_reporter); priv->tx_reporter =NULL ; }
drivers/net/ethernet/mellanox/mlxsw/core.c +4 -4
@@ -2051,8 +2051,8 @@ static int mlxsw_core_health_init(struct mlxsw_core *mlxsw_core)if (!(mlxsw_core->bus->features &MLXSW_BUS_F_TXRX ))return 0 ; - fw_fatal =devlink_health_reporter_create (devlink, &mlxsw_core_health_fw_fatal_ops, -0 , mlxsw_core); + fw_fatal =devl_health_reporter_create (devlink, &mlxsw_core_health_fw_fatal_ops, +0 , mlxsw_core);if (IS_ERR (fw_fatal)) {dev_err (mlxsw_core->bus_info->dev,"Failed to create fw fatal reporter" );return PTR_ERR (fw_fatal);
@@ -2072,7 +2072,7 @@ static int mlxsw_core_health_init(struct mlxsw_core *mlxsw_core) err_fw_fatal_config:mlxsw_core_trap_unregister (mlxsw_core, &mlxsw_core_health_listener, mlxsw_core); err_trap_register: -devlink_health_reporter_destroy (mlxsw_core->health.fw_fatal); +devl_health_reporter_destroy (mlxsw_core->health.fw_fatal);return err; }
@@ -2085,7 +2085,7 @@ static void mlxsw_core_health_fini(struct mlxsw_core *mlxsw_core)mlxsw_core_trap_unregister (mlxsw_core, &mlxsw_core_health_listener, mlxsw_core);/* Make sure there is no more event work scheduled */ mlxsw_core_flush_owq (); -devlink_health_reporter_destroy (mlxsw_core->health.fw_fatal); +devl_health_reporter_destroy (mlxsw_core->health.fw_fatal); }static void mlxsw_core_irq_event_handler_init (struct mlxsw_core *mlxsw_core)
drivers/net/netdevsim/health.c +10 -10
@@ -233,16 +233,16 @@ int nsim_dev_health_init(struct nsim_dev *nsim_dev, struct devlink *devlink)int err; health->empty_reporter = -devlink_health_reporter_create (devlink, - &nsim_dev_empty_reporter_ops, -0 , health); +devl_health_reporter_create (devlink, + &nsim_dev_empty_reporter_ops, +0 , health);if (IS_ERR (health->empty_reporter))return PTR_ERR (health->empty_reporter); health->dummy_reporter = -devlink_health_reporter_create (devlink, - &nsim_dev_dummy_reporter_ops, -0 , health); +devl_health_reporter_create (devlink, + &nsim_dev_dummy_reporter_ops, +0 , health);if (IS_ERR (health->dummy_reporter)) { err =PTR_ERR (health->dummy_reporter); goto err_empty_reporter_destroy;
@@ -266,9 +266,9 @@ int nsim_dev_health_init(struct nsim_dev *nsim_dev, struct devlink *devlink)return 0 ; err_dummy_reporter_destroy: -devlink_health_reporter_destroy (health->dummy_reporter); +devl_health_reporter_destroy (health->dummy_reporter); err_empty_reporter_destroy: -devlink_health_reporter_destroy (health->empty_reporter); +devl_health_reporter_destroy (health->empty_reporter);return err; }
@@ -278,6 +278,6 @@ void nsim_dev_health_exit(struct nsim_dev *nsim_dev)debugfs_remove_recursive (health->ddir);kfree (health->recovered_break_msg); -devlink_health_reporter_destroy (health->dummy_reporter); -devlink_health_reporter_destroy (health->empty_reporter); +devl_health_reporter_destroy (health->dummy_reporter); +devl_health_reporter_destroy (health->empty_reporter); }
include/net/devlink.h +13 -5
@@ -1864,21 +1864,29 @@ int devlink_fmsg_string_pair_put(struct devlink_fmsg *fmsg, const char *name,int devlink_fmsg_binary_pair_put (struct devlink_fmsg *fmsg,const char *name,const void *value,u32 value_len); +struct devlink_health_reporter * +devl_port_health_reporter_create (struct devlink_port *port, +const struct devlink_health_reporter_ops *ops, +u64 graceful_period,void *priv); + +struct devlink_health_reporter * +devl_health_reporter_create (struct devlink *devlink, +const struct devlink_health_reporter_ops *ops, +u64 graceful_period,void *priv); +struct devlink_health_reporter *devlink_health_reporter_create (struct devlink *devlink,const struct devlink_health_reporter_ops *ops,u64 graceful_period,void *priv); -struct devlink_health_reporter * -devlink_port_health_reporter_create (struct devlink_port *port, -const struct devlink_health_reporter_ops *ops, -u64 graceful_period,void *priv); +void +devl_health_reporter_destroy (struct devlink_health_reporter *reporter);void devlink_health_reporter_destroy (struct devlink_health_reporter *reporter);void -devlink_port_health_reporter_destroy (struct devlink_health_reporter *reporter); +devl_port_health_reporter_destroy (struct devlink_health_reporter *reporter);void *devlink_health_reporter_priv (struct devlink_health_reporter *reporter);
net/devlink/leftover.c +52 -24
164 lines not on this page · raw message
Signature · 1 line
2.39.0
Jiri Pirko
maintainerPATCH v4 4/10 devlink: remove reporters_lock
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
Similar to other devlink objects, rely on devlink instance lock and remove object specific reporters_lock.
---v2->v3:
- split from v2 patch #4 - "devlink: remove reporters_lock", no change
--- include/net/devlink.h | 1 - net/devlink/core.c | 2 -- net/devlink/devl_internal.h | 1 - net/devlink/leftover.c | 53 +++++++------------------------------ 4 files changed, 9 insertions(+), 48 deletions(-)
include/net/devlink.h +0 -1
@@ -146,7 +146,6 @@ struct devlink_port { initialized:1 ;struct delayed_work type_warn_dw;struct list_head reporter_list; -struct mutex reporters_lock;/* Protects reporter_list */ struct devlink_rate *devlink_rate;struct devlink_linecard *linecard;
net/devlink/core.c +0 -2
@@ -234,7 +234,6 @@ struct devlink *devlink_alloc_ns(const struct devlink_ops *ops,lockdep_register_key (&devlink->lock_key);mutex_init (&devlink->lock);lockdep_set_class (&devlink->lock, &devlink->lock_key); -mutex_init (&devlink->reporters_lock);refcount_set (&devlink->refcount,1 );return devlink;
@@ -256,7 +255,6 @@ void devlink_free(struct devlink *devlink) {ASSERT_DEVLINK_NOT_REGISTERED (devlink); -mutex_destroy (&devlink->reporters_lock);mutex_destroy (&devlink->lock);lockdep_unregister_key (&devlink->lock_key);WARN_ON (!list_empty (&devlink->trap_policer_list));
net/devlink/devl_internal.h +0 -1
@@ -31,7 +31,6 @@ struct devlink {struct list_head param_list;struct list_head region_list;struct list_head reporter_list; -struct mutex reporters_lock;/* protects reporter_list */ struct devlink_dpipe_headers *dpipe_headers;struct list_head trap_list;struct list_head trap_group_list;
net/devlink/leftover.c +9 -44
178 lines not on this page · raw message
Signature · 1 line
2.39.0
Jiri Pirko
maintainerPATCH v4 5/10 devlink: remove devl_port_health_reporter_destroy()
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
Remove port-specific health reporter destroy function as it is currently the same as the instance one so no longer needed. Inline __devlink_health_reporter_destroy() as it is no longer called from multiple places.
---v2->v3:
- split from v2 patch #4 - "devlink: remove reporters_lock", no change
--- .../mellanox/mlx5/core/en/reporter_rx.c | 2 +- .../mellanox/mlx5/core/en/reporter_tx.c | 2 +- include/net/devlink.h | 3 --- net/devlink/leftover.c | 24 ++----------------- 4 files changed, 4 insertions(+), 27 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en/reporter_rx.c +1 -1
@@ -754,6 +754,6 @@ void mlx5e_reporter_rx_destroy(struct mlx5e_priv *priv)if (!priv->rx_reporter)return ; -devl_port_health_reporter_destroy (priv->rx_reporter); +devl_health_reporter_destroy (priv->rx_reporter); priv->rx_reporter =NULL ; }
drivers/net/ethernet/mellanox/mlx5/core/en/reporter_tx.c +1 -1
@@ -609,6 +609,6 @@ void mlx5e_reporter_tx_destroy(struct mlx5e_priv *priv)if (!priv->tx_reporter)return ; -devl_port_health_reporter_destroy (priv->tx_reporter); +devl_health_reporter_destroy (priv->tx_reporter); priv->tx_reporter =NULL ; }
include/net/devlink.h +0 -3
@@ -1884,9 +1884,6 @@ devl_health_reporter_destroy(struct devlink_health_reporter *reporter);void devlink_health_reporter_destroy (struct devlink_health_reporter *reporter); -void -devl_port_health_reporter_destroy (struct devlink_health_reporter *reporter); -void *devlink_health_reporter_priv (struct devlink_health_reporter *reporter); int devlink_health_report(struct devlink_health_reporter *reporter,
net/devlink/leftover.c +2 -22
@@ -7426,13 +7426,6 @@ devlink_health_reporter_put(struct devlink_health_reporter *reporter)devlink_health_reporter_free (reporter); } -static void -__devlink_health_reporter_destroy (struct devlink_health_reporter *reporter) -{ -list_del (&reporter->list); -devlink_health_reporter_put (reporter); -} -/** * devl_health_reporter_destroy - destroy devlink health reporter *
@@ -7443,7 +7436,8 @@ devl_health_reporter_destroy(struct devlink_health_reporter *reporter) {devl_assert_locked (reporter->devlink); -__devlink_health_reporter_destroy (reporter); +list_del (&reporter->list); +devlink_health_reporter_put (reporter); }EXPORT_SYMBOL_GPL (devl_health_reporter_destroy);
@@ -7458,20 +7452,6 @@ devlink_health_reporter_destroy(struct devlink_health_reporter *reporter) }EXPORT_SYMBOL_GPL (devlink_health_reporter_destroy); -/** -* devl_port_health_reporter_destroy - destroy devlink port health reporter -* -* @reporter: devlink health reporter to destroy -*/ -void -devl_port_health_reporter_destroy (struct devlink_health_reporter *reporter) -{ -devl_assert_locked (reporter->devlink); - -__devlink_health_reporter_destroy (reporter); -} -EXPORT_SYMBOL_GPL (devl_port_health_reporter_destroy); - static int devlink_nl_health_reporter_fill(struct sk_buff *msg, struct devlink_health_reporter *reporter,
Signature · 1 line
2.39.0
Jiri Pirko
maintainerPATCH v4 6/10 devlink: remove reporter reference counting
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
As long as the reporter life time is protected by devlink instance lock, the reference counting is no longer needed. Remove it.
---v2->v3
- fixed typo in patch description
--- net/devlink/leftover.c | 113 +++++++++++------------------------------ 1 file changed, 30 insertions(+), 83 deletions(-)
net/devlink/leftover.c +30 -83
@@ -7269,7 +7269,6 @@ struct devlink_health_reporter {u64 error_count;u64 recovery_count;u64 last_recovery_ts; -refcount_t refcount; }; void *
@@ -7328,7 +7327,6 @@ __devlink_health_reporter_create(struct devlink *devlink, reporter->auto_recover = !!ops->recover; reporter->auto_dump = !!ops->dump;mutex_init (&reporter->dump_lock); -refcount_set (&reporter->refcount,1 );return reporter; }
@@ -7419,13 +7417,6 @@ devlink_health_reporter_free(struct devlink_health_reporter *reporter)kfree (reporter); } -static void -devlink_health_reporter_put (struct devlink_health_reporter *reporter) -{ -if (refcount_dec_and_test (&reporter->refcount)) -devlink_health_reporter_free (reporter); -} -/** * devl_health_reporter_destroy - destroy devlink health reporter *
@@ -7437,7 +7428,7 @@ devl_health_reporter_destroy(struct devlink_health_reporter *reporter)devl_assert_locked (reporter->devlink);list_del (&reporter->list); -devlink_health_reporter_put (reporter); +devlink_health_reporter_free (reporter); }EXPORT_SYMBOL_GPL (devl_health_reporter_destroy);
@@ -7681,7 +7672,6 @@ static struct devlink_health_reporter * devlink_health_reporter_get_from_attrs(struct devlink *devlink, struct nlattr **attrs) { - struct devlink_health_reporter *reporter; struct devlink_port *devlink_port;char *reporter_name;
@@ -7690,17 +7680,12 @@ devlink_health_reporter_get_from_attrs(struct devlink *devlink, reporter_name =nla_data (attrs[DEVLINK_ATTR_HEALTH_REPORTER_NAME ]); devlink_port =devlink_port_get_from_attrs (devlink, attrs); -if (IS_ERR (devlink_port)) { - reporter =devlink_health_reporter_find_by_name (devlink, reporter_name); -if (reporter) -refcount_inc (&reporter->refcount); - }else { - reporter =devlink_port_health_reporter_find_by_name (devlink_port, reporter_name); -if (reporter) -refcount_inc (&reporter->refcount); - } - -return reporter; +if (IS_ERR (devlink_port)) +return devlink_health_reporter_find_by_name (devlink, + reporter_name); +else +return devlink_port_health_reporter_find_by_name (devlink_port, + reporter_name); } static struct devlink_health_reporter *
@@ -7759,10 +7744,8 @@ static int devlink_nl_cmd_health_reporter_get_doit(struct sk_buff *skb,return -EINVAL ; msg =nlmsg_new (NLMSG_DEFAULT_SIZE ,GFP_KERNEL ); -if (!msg) { - err = -ENOMEM ; - goto out; - } +if (!msg) +return -ENOMEM ; err = devlink_nl_health_reporter_fill(msg, reporter, DEVLINK_CMD_HEALTH_REPORTER_GET,
@@ -7770,13 +7753,10 @@ static int devlink_nl_cmd_health_reporter_get_doit(struct sk_buff *skb, 0);if (err) {nlmsg_free (msg); - goto out; +return err; } - err =genlmsg_reply (msg, info); -out: -devlink_health_reporter_put (reporter); -return err; +return genlmsg_reply (msg, info); } static int
@@ -7850,7 +7830,6 @@ devlink_nl_cmd_health_reporter_set_doit(struct sk_buff *skb, {struct devlink *devlink = info->user_ptr[0 ];struct devlink_health_reporter *reporter; -int err; reporter =devlink_health_reporter_get_from_info (devlink, info);if (!reporter)
@@ -7858,15 +7837,12 @@ devlink_nl_cmd_health_reporter_set_doit(struct sk_buff *skb,if (!reporter->ops->recover && (info->attrs[DEVLINK_ATTR_HEALTH_REPORTER_GRACEFUL_PERIOD ] || - info->attrs[DEVLINK_ATTR_HEALTH_REPORTER_AUTO_RECOVER ])) { - err = -EOPNOTSUPP ; - goto out; - } + info->attrs[DEVLINK_ATTR_HEALTH_REPORTER_AUTO_RECOVER ])) +return -EOPNOTSUPP ; +if (!reporter->ops->dump && - info->attrs[DEVLINK_ATTR_HEALTH_REPORTER_AUTO_DUMP ]) { - err = -EOPNOTSUPP ; - goto out; - } + info->attrs[DEVLINK_ATTR_HEALTH_REPORTER_AUTO_DUMP ]) +return -EOPNOTSUPP ;if (info->attrs[DEVLINK_ATTR_HEALTH_REPORTER_GRACEFUL_PERIOD ]) reporter->graceful_period =
@@ -7880,11 +7856,7 @@ devlink_nl_cmd_health_reporter_set_doit(struct sk_buff *skb, reporter->auto_dump =nla_get_u8 (info->attrs[DEVLINK_ATTR_HEALTH_REPORTER_AUTO_DUMP ]); -devlink_health_reporter_put (reporter);return 0 ; -out: -devlink_health_reporter_put (reporter); -return err; } static int devlink_nl_cmd_health_reporter_recover_doit(struct sk_buff *skb,
@@ -7892,16 +7864,12 @@ static int devlink_nl_cmd_health_reporter_recover_doit(struct sk_buff *skb, {struct devlink *devlink = info->user_ptr[0 ];struct devlink_health_reporter *reporter; -int err; reporter =devlink_health_reporter_get_from_info (devlink, info);if (!reporter)return -EINVAL ; - err =devlink_health_reporter_recover (reporter,NULL , info->extack); - -devlink_health_reporter_put (reporter); -return err; +return devlink_health_reporter_recover (reporter,NULL , info->extack); } static int devlink_nl_cmd_health_reporter_diagnose_doit(struct sk_buff *skb,
@@ -7916,36 +7884,27 @@ static int devlink_nl_cmd_health_reporter_diagnose_doit(struct sk_buff *skb,if (!reporter)return -EINVAL ; -if (!reporter->ops->diagnose) { -devlink_health_reporter_put (reporter); +if (!reporter->ops->diagnose)return -EOPNOTSUPP ; - } fmsg =devlink_fmsg_alloc (); -if (!fmsg) { -devlink_health_reporter_put (reporter); +if (!fmsg)return -ENOMEM ; - } err =devlink_fmsg_obj_nest_start (fmsg);if (err) - goto out; +return err; err = reporter->ops->diagnose (reporter, fmsg, info->extack);if (err) - goto out; +return err; err =devlink_fmsg_obj_nest_end (fmsg);if (err) - goto out; - - err =devlink_fmsg_snd (fmsg, info, -DEVLINK_CMD_HEALTH_REPORTER_DIAGNOSE ,0 ); +return err; -out: -devlink_fmsg_free (fmsg); -devlink_health_reporter_put (reporter); -return err; +return devlink_fmsg_snd (fmsg, info, +DEVLINK_CMD_HEALTH_REPORTER_DIAGNOSE ,0 ); } static int
@@ -7960,10 +7919,9 @@ devlink_nl_cmd_health_reporter_dump_get_dumpit(struct sk_buff *skb,if (!reporter)return -EINVAL ; -if (!reporter->ops->dump) { - err = -EOPNOTSUPP ; - goto out; - } +if (!reporter->ops->dump) +return -EOPNOTSUPP ; +mutex_lock (&reporter->dump_lock);if (!state->idx) { err =devlink_health_do_dump (reporter,NULL , cb->extack);
@@ -7981,8 +7939,6 @@ devlink_nl_cmd_health_reporter_dump_get_dumpit(struct sk_buff *skb, DEVLINK_CMD_HEALTH_REPORTER_DUMP_GET); unlock:mutex_unlock (&reporter->dump_lock); -out: -devlink_health_reporter_put (reporter);return err; }
@@ -7997,15 +7953,12 @@ devlink_nl_cmd_health_reporter_dump_clear_doit(struct sk_buff *skb,if (!reporter)return -EINVAL ; -if (!reporter->ops->dump) { -devlink_health_reporter_put (reporter); +if (!reporter->ops->dump)return -EOPNOTSUPP ; - }mutex_lock (&reporter->dump_lock);devlink_health_dump_clear (reporter);mutex_unlock (&reporter->dump_lock); -devlink_health_reporter_put (reporter);return 0 ; }
@@ -8014,21 +7967,15 @@ static int devlink_nl_cmd_health_reporter_test_doit(struct sk_buff *skb, {struct devlink *devlink = info->user_ptr[0 ];struct devlink_health_reporter *reporter; -int err; reporter =devlink_health_reporter_get_from_info (devlink, info);if (!reporter)return -EINVAL ; -if (!reporter->ops->test) { -devlink_health_reporter_put (reporter); +if (!reporter->ops->test)return -EOPNOTSUPP ; - } - - err = reporter->ops->test (reporter, info->extack); -devlink_health_reporter_put (reporter); -return err; +return reporter->ops->test (reporter, info->extack); }struct devlink_stats {
Signature · 1 line
2.39.0
Jiri Pirko
maintainerPATCH v4 7/10 devlink: convert linecards dump to devlink_nl_instance_iter_dump()
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
Benefit from recently introduced instance iteration and convert linecards .dumpit generic netlink callback to use it.
--- net/devlink/devl_internal.h | 1 + net/devlink/leftover.c | 64 ++++++++++++++++--------------------- net/devlink/netlink.c | 1 + 3 files changed, 30 insertions(+), 36 deletions(-)
net/devlink/devl_internal.h +1 -0
@@ -166,6 +166,7 @@ extern const struct devlink_gen_cmd devl_gen_info;extern const struct devlink_gen_cmd devl_gen_trap;extern const struct devlink_gen_cmd devl_gen_trap_group;extern const struct devlink_gen_cmd devl_gen_trap_policer; +extern const struct devlink_gen_cmd devl_gen_linecard;/* Ports */ int devlink_port_netdevice_event(struct notifier_block *nb,
net/devlink/leftover.c +28 -36
85 lines not on this page · raw message
net/devlink/netlink.c +1 -0
@@ -191,6 +191,7 @@ static const struct devlink_gen_cmd *devl_gen_cmds[] = { [DEVLINK_CMD_TRAP_GET] = &devl_gen_trap, [DEVLINK_CMD_TRAP_GROUP_GET] = &devl_gen_trap_group, [DEVLINK_CMD_TRAP_POLICER_GET] = &devl_gen_trap_policer, + [DEVLINK_CMD_LINECARD_GET] = &devl_gen_linecard, [DEVLINK_CMD_SELFTESTS_GET] = &devl_gen_selftests, };
Signature · 1 line
2.39.0
Jiri Pirko
maintainerPATCH v4 8/10 devlink: convert reporters dump to devlink_nl_instance_iter_dump()
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
Benefit from recently introduced instance iteration and convert reporters .dumpit generic netlink callback to use it.
---v1->v2:
- unsquashed the next patch (devlink: remove devlink_dump_for_each_instance_get() helper) from this one
--- net/devlink/devl_internal.h | 1 + net/devlink/leftover.c | 87 ++++++++++++++++--------------------- net/devlink/netlink.c | 1 + 3 files changed, 40 insertions(+), 49 deletions(-)
net/devlink/devl_internal.h +1 -0
@@ -163,6 +163,7 @@ extern const struct devlink_gen_cmd devl_gen_selftests;extern const struct devlink_gen_cmd devl_gen_param;extern const struct devlink_gen_cmd devl_gen_region;extern const struct devlink_gen_cmd devl_gen_info; +extern const struct devlink_gen_cmd devl_gen_health_reporter;extern const struct devlink_gen_cmd devl_gen_trap;extern const struct devlink_gen_cmd devl_gen_trap_group;extern const struct devlink_gen_cmd devl_gen_trap_policer;
net/devlink/leftover.c +38 -49
115 lines not on this page · raw message
net/devlink/netlink.c +1 -0
@@ -187,6 +187,7 @@ static const struct devlink_gen_cmd *devl_gen_cmds[] = { [DEVLINK_CMD_PARAM_GET] = &devl_gen_param, [DEVLINK_CMD_REGION_GET] = &devl_gen_region, [DEVLINK_CMD_INFO_GET] = &devl_gen_info, + [DEVLINK_CMD_HEALTH_REPORTER_GET] = &devl_gen_health_reporter, [DEVLINK_CMD_RATE_GET] = &devl_gen_rate_get, [DEVLINK_CMD_TRAP_GET] = &devl_gen_trap, [DEVLINK_CMD_TRAP_GROUP_GET] = &devl_gen_trap_group,
Signature · 1 line
2.39.0
Jiri Pirko
maintainerPATCH v4 9/10 devlink: remove devlink_dump_for_each_instance_get() helper
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
devlink_dump_for_each_instance_get() is currently called from a single place in netlink.c. As there is no need to use this helper anywhere else in the future, remove it and call devlinks_xa_find_get() directly from while loop in devlink_nl_instance_iter_dump(). Also remove redundant idx clear on loop end as it is already done
in devlink_nl_instance_iter_dump().
---v1->v2: new patch, unsquashed from the previous one
--- net/devlink/devl_internal.h | 11 ----------- net/devlink/netlink.c | 5 ++++- 2 files changed, 4 insertions(+), 12 deletions(-)
net/devlink/devl_internal.h +0 -11
@@ -122,17 +122,6 @@ struct devlink_gen_cmd { struct netlink_callback *cb); }; -/* Iterate over registered devlink instances for devlink dump. -* devlink_put() needs to be called for each iterated devlink pointer -* in loop body in order to release the reference. -* Note: this is NOT a generic iterator, it makes assumptions about the use -* of @state and can only be used once per dumpit implementation. -*/ -#define devlink_dump_for_each_instance_get (msg, state, devlink) \ - for (; (devlink = devlinks_xa_find_get(sock_net(msg->sk), \ - &state->instance)); \ - state->instance++, state->idx = 0) -extern const struct genl_small_ops devlink_nl_ops[56 ]; struct devlink *
net/devlink/netlink.c +4 -1
@@ -207,7 +207,8 @@ int devlink_nl_instance_iter_dump(struct sk_buff *msg, cmd = devl_gen_cmds[info->op.cmd]; -devlink_dump_for_each_instance_get (msg, state, devlink) { +while ((devlink =devlinks_xa_find_get (sock_net (msg->sk), + &state->instance))) {devl_lock (devlink);if (devl_is_registered (devlink))
@@ -221,6 +222,8 @@ int devlink_nl_instance_iter_dump(struct sk_buff *msg,if (err)break ; + state->instance++; +/* restart sub-object walk for the next instance */ state->idx =0 ; }
Signature · 1 line
2.39.0
Jiri Pirko
maintainerPATCH v4 10/10 devlink: add instance lock assertion in devl_is_registered()
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
After region and linecard lock removals, this helper is always supposed to be called with instance lock held. So put the assertion here and remove the comment which is no longer accurate.
--- net/devlink/devl_internal.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
net/devlink/devl_internal.h +1 -3
@@ -84,9 +84,7 @@ struct devlink *devlinks_xa_find_get(struct net *net, unsigned long *indexp);static inline bool devl_is_registered (struct devlink *devlink) { -/* To prevent races the caller must hold the instance lock -* or another lock taken during unregistration. -*/ +devl_assert_locked (devlink);return xa_get_mark (&devlinks, devlink->index,DEVLINK_REGISTERED ); }
Signature · 1 line
2.39.0
Quoted 13 lines · Jiri Pirko
From: Jiri Pirko <[email protected]>
This patchset does not change functionality.
Patches 1-6 removes linecards and reporters locks and reference counting, converting them to be protected by devlink instance lock as the rest of the objects.
Patches 7 and 8 convert linecards and reporters dumpit callbacks to recently introduced
devlink_nl_instance_iter_dump()infra. Patch 9 removes no longer neededdevlink_dump_for_each_instance_get()helper.
Quoted 4 lines
The last patch adds assertion to
devl_is_registered()as dependency on other locks is removed.---
I think you said a v5 would be posted rebased on top of Kuba's fix, but the whole series looks good to me.
Quoted 35 lines
v3->v4:
- patch #1 was removed from the set and will be sent as a part of another patchsetv2->v3:
- see individual patches for changelog, mainly original patch #4 was split into 3 patches for easier reviewv1->v2:
- patch 7 bits were unsquashed to patch 8Jiri Pirko (10):
devlink: remove linecards lock
devlink: remove linecard reference counting
devlink: protect health reporter operation with instance lock
devlink: removereporters_lock
devlink: removedevl_port_health_reporter_destroy()
devlink: remove reporter reference counting
devlink: convert linecards dump todevlink_nl_instance_iter_dump()
devlink: convert reporters dump todevlink_nl_instance_iter_dump()
devlink: removedevlink_dump_for_each_instance_get()helper
devlink: add instance lock assertion indevl_is_registered().../ethernet/mellanox/mlx5/core/en/health.c | 12 + .../mellanox/mlx5/core/en/reporter_rx.c | 6 +- .../mellanox/mlx5/core/en/reporter_tx.c | 6 +- drivers/net/ethernet/mellanox/mlxsw/core.c | 8 +- .../ethernet/mellanox/mlxsw/core_linecards.c | 8 +- drivers/net/netdevsim/health.c | 20 +- include/net/devlink.h | 26 +- net/devlink/core.c | 4 - net/devlink/devl_internal.h | 20 +- net/devlink/leftover.c | 428 +++++++----------- net/devlink/netlink.c | 12 +- 11 files changed, 213 insertions(+), 337 deletions(-)
Quoted 3 lines · Jiri Pirko
From: Jiri Pirko <[email protected]>
This patchset does not change functionality.
This series causes to some glitches in our CI. Jiri is looking into it.
Thanks
Jiri Pirko
maintainerQuoted 6 lines · Sun, Jan 15, 2023 at 10:16:24AM CET, [email protected] wrote:
Quoted 3 lines · Jiri Pirko
From: Jiri Pirko <[email protected]>
This patchset does not change functionality.
This series causes to some glitches in our CI. Jiri is looking into it.
I'm trying to untangle odd locking scheme during mlx5 auxdev probe. Stay tuned.
Quoted 2 lines
Thanks