net/mlx5: Move notifiers outside the devlink lock
Subsystems (5)
Tariq Toukan
maintainercover net/mlx5: Move notifiers outside the devlink lock
Hi,
This series by Cosmin moves blocking notifier registration in the mlx5 driver outside the devlink lock during probe.
This is mostly a no-op refactoring that consists of multiple pieces. It is necessary because upcoming code will introduce a potential locking cycle between the devlink lock and the blocking notifier head mutexes, so these notifiers must move out of the devlink-locked critical section.
Regards,
Tariq
Cosmin Ratiu (6):
net/mlx5: Initialize events outside devlink lock net/mlx5: Move the esw mode notifier chain outside the devlink lock net/mlx5: Move the vhca event notifier outside of the devlink lock net/mlx5: Move the SF HW table notifier outside the devlink lock net/mlx5: Move the SF table notifiers outside the devlink lock net/mlx5: Move SF dev table notifier registration outside the PF
devlink lock
.../net/ethernet/mellanox/mlx5/core/eswitch.c | 13 +-- .../net/ethernet/mellanox/mlx5/core/eswitch.h | 7 +- .../net/ethernet/mellanox/mlx5/core/main.c | 70 +++++++++++---- .../ethernet/mellanox/mlx5/core/sf/dev/dev.c | 48 ++++++---- .../ethernet/mellanox/mlx5/core/sf/dev/dev.h | 11 +++ .../ethernet/mellanox/mlx5/core/sf/devlink.c | 90 ++++++++++++------- .../ethernet/mellanox/mlx5/core/sf/hw_table.c | 61 ++++++++----- .../net/ethernet/mellanox/mlx5/core/sf/sf.h | 20 ++++- .../mellanox/mlx5/core/sf/vhca_event.c | 69 ++++++-------- .../mellanox/mlx5/core/sf/vhca_event.h | 5 ++ include/linux/mlx5/driver.h | 10 ++- 11 files changed, 253 insertions(+), 151 deletions(-)
base-commit: c9dfb92de0738eb7fe6a591ad1642333793e8b6e
Signature · 1 line
2.31.1
Tariq Toukan
maintainerPATCH 1/6 net/mlx5: Initialize events outside devlink lock
From: Cosmin Ratiu <[email protected]>
Move event init/cleanup outside of mlx5_init_one() / mlx5_uninit_one() and into the mlx5_mdev_init() / mlx5_mdev_uninit() functions.
By doing this, we avoid the events being reinitialized on devlink reload and, more importantly, the events->sw_nh notifier chain becomes available earlier in the init procedure, which will be used in subsequent patches. This makes sense because the events struct is pure software, independent of any HW details.
--- .../net/ethernet/mellanox/mlx5/core/main.c | 34 +++++++++++++------ 1 file changed, 24 insertions(+), 10 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/main.c +24 -10
@@ -1010,16 +1010,10 @@ static int mlx5_init_once(struct mlx5_core_dev *dev) goto err_irq_cleanup; } - err =mlx5_events_init (dev); -if (err) { -mlx5_core_err (dev,"failed to initialize events\n" ); - goto err_eq_cleanup; - } - err =mlx5_fw_reset_init (dev);if (err) {mlx5_core_err (dev,"failed to initialize fw reset events\n" ); - goto err_events_cleanup; + goto err_eq_cleanup; }mlx5_cq_debugfs_init (dev);
@@ -1121,8 +1115,6 @@ static int mlx5_init_once(struct mlx5_core_dev *dev)mlx5_cleanup_reserved_gids (dev);mlx5_cq_debugfs_cleanup (dev);mlx5_fw_reset_cleanup (dev); -err_events_cleanup: -mlx5_events_cleanup (dev); err_eq_cleanup:mlx5_eq_table_cleanup (dev); err_irq_cleanup:
@@ -1155,7 +1147,6 @@ static void mlx5_cleanup_once(struct mlx5_core_dev *dev)mlx5_cleanup_reserved_gids (dev);mlx5_cq_debugfs_cleanup (dev);mlx5_fw_reset_cleanup (dev); -mlx5_events_cleanup (dev);mlx5_eq_table_cleanup (dev);mlx5_irq_table_cleanup (dev);mlx5_devcom_unregister_device (dev->priv.devc);
@@ -1833,6 +1824,24 @@ static int vhca_id_show(struct seq_file *file, void *priv)DEFINE_SHOW_ATTRIBUTE (vhca_id); +static int mlx5_notifiers_init (struct mlx5_core_dev *dev) +{ +int err; + + err =mlx5_events_init (dev); +if (err) { +mlx5_core_err (dev,"failed to initialize events\n" ); +return err; + } + +return 0 ; +} + +static void mlx5_notifiers_cleanup (struct mlx5_core_dev *dev) +{ +mlx5_events_cleanup (dev); +} +int mlx5_mdev_init (struct mlx5_core_dev *dev,int profile_idx) {struct mlx5_priv *priv = &dev->priv;
@@ -1888,6 +1897,10 @@ int mlx5_mdev_init(struct mlx5_core_dev *dev, int profile_idx)if (err) goto err_hca_caps; + err =mlx5_notifiers_init (dev); +if (err) + goto err_hca_caps; +/* The conjunction of sw_vhca_id with sw_owner_id will be a global * unique id per function which uses mlx5_core. * Those values are supplied to FW as part of the init HCA command to
@@ -1930,6 +1943,7 @@ void mlx5_mdev_uninit(struct mlx5_core_dev *dev)if (priv->sw_vhca_id >0 )ida_free (&sw_vhca_ida, dev->priv.sw_vhca_id); +mlx5_notifiers_cleanup (dev);mlx5_hca_caps_free (dev);mlx5_adev_cleanup (dev);mlx5_pagealloc_cleanup (dev);
Signature · 1 line
2.31.1
Tariq Toukan
maintainerPATCH 2/6 net/mlx5: Move the esw mode notifier chain outside the devlink lock
In reply to Tariq ToukanFrom: Cosmin Ratiu <[email protected]>
The esw mode change notifier chain is initialized/cleaned up in mlx5_init_one() / mlx5_uninit_one() with the devlink lock held.
Move the notifier head from the eswitch struct into mlx5_priv directly, and initialize it outside the critical section. This will allow notifier registration to happen earlier in the init procedure in subsequent patches.
--- drivers/net/ethernet/mellanox/mlx5/core/eswitch.c | 13 +++++++------ drivers/net/ethernet/mellanox/mlx5/core/eswitch.h | 7 ++++--- drivers/net/ethernet/mellanox/mlx5/core/main.c | 2 ++ .../net/ethernet/mellanox/mlx5/core/sf/devlink.c | 6 +++--- include/linux/mlx5/driver.h | 1 + 5 files changed, 17 insertions(+), 12 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/eswitch.c +7 -6
@@ -1474,7 +1474,7 @@ static void mlx5_esw_mode_change_notify(struct mlx5_eswitch *esw, u16 mode) info.new_mode = mode; -blocking_notifier_call_chain (&esw->n_head,0 , &info); +blocking_notifier_call_chain (&esw->dev->priv.esw_n_head,0 , &info); }static int mlx5_esw_egress_acls_init (struct mlx5_core_dev *dev)
@@ -2050,7 +2050,6 @@ int mlx5_eswitch_init(struct mlx5_core_dev *dev) esw->offloads.encap =DEVLINK_ESWITCH_ENCAP_MODE_BASIC ; else esw->offloads.encap = DEVLINK_ESWITCH_ENCAP_MODE_NONE; -BLOCKING_INIT_NOTIFIER_HEAD (&esw->n_head); esw_info(dev, "Total vports %d, per vport: max uc(%d) max mc(%d)\n",
@@ -2379,14 +2378,16 @@ bool mlx5_esw_multipath_prereq(struct mlx5_core_dev *dev0, dev1->priv.eswitch->mode == MLX5_ESWITCH_OFFLOADS); } -int mlx5_esw_event_notifier_register (struct mlx5_eswitch *esw,struct notifier_block *nb) +int mlx5_esw_event_notifier_register (struct mlx5_core_dev *dev, +struct notifier_block *nb) { -return blocking_notifier_chain_register (&esw->n_head, nb); +return blocking_notifier_chain_register (&dev->priv.esw_n_head, nb); } -void mlx5_esw_event_notifier_unregister (struct mlx5_eswitch *esw,struct notifier_block *nb) +void mlx5_esw_event_notifier_unregister (struct mlx5_core_dev *dev, +struct notifier_block *nb) { -blocking_notifier_chain_unregister (&esw->n_head, nb); +blocking_notifier_chain_unregister (&dev->priv.esw_n_head, nb); }/**
drivers/net/ethernet/mellanox/mlx5/core/eswitch.h +4 -3
@@ -403,7 +403,6 @@ struct mlx5_eswitch {struct {u32 large_group_num; } params; -struct blocking_notifier_head n_head;struct xarray paired;struct mlx5_devcom_comp_dev *devcom;u16 enabled_ipsec_vf_count;
@@ -864,8 +863,10 @@ struct mlx5_esw_event_info {u16 new_mode; }; -int mlx5_esw_event_notifier_register (struct mlx5_eswitch *esw,struct notifier_block *n); -void mlx5_esw_event_notifier_unregister (struct mlx5_eswitch *esw,struct notifier_block *n); +int mlx5_esw_event_notifier_register (struct mlx5_core_dev *dev, +struct notifier_block *n); +void mlx5_esw_event_notifier_unregister (struct mlx5_core_dev *dev, +struct notifier_block *n);bool mlx5_esw_hold (struct mlx5_core_dev *dev);void mlx5_esw_release (struct mlx5_core_dev *dev);
drivers/net/ethernet/mellanox/mlx5/core/main.c +2 -0
@@ -1834,6 +1834,8 @@ static int mlx5_notifiers_init(struct mlx5_core_dev *dev)return err; } +BLOCKING_INIT_NOTIFIER_HEAD (&dev->priv.esw_n_head); +return 0 ; }
drivers/net/ethernet/mellanox/mlx5/core/sf/devlink.c +3 -3
@@ -481,7 +481,7 @@ int mlx5_sf_table_init(struct mlx5_core_dev *dev)xa_init (&table->function_ids); dev->priv.sf_table = table; table->esw_nb.notifier_call = mlx5_sf_esw_event; - err =mlx5_esw_event_notifier_register (dev->priv.eswitch, &table->esw_nb); + err =mlx5_esw_event_notifier_register (dev, &table->esw_nb);if (err) goto reg_err;
@@ -496,7 +496,7 @@ int mlx5_sf_table_init(struct mlx5_core_dev *dev)return 0 ; vhca_err: -mlx5_esw_event_notifier_unregister (dev->priv.eswitch, &table->esw_nb); +mlx5_esw_event_notifier_unregister (dev, &table->esw_nb); reg_err:mutex_destroy (&table->sf_state_lock);kfree (table);
@@ -513,7 +513,7 @@ void mlx5_sf_table_cleanup(struct mlx5_core_dev *dev)mlx5_blocking_notifier_unregister (dev, &table->mdev_nb);mlx5_vhca_event_notifier_unregister (table->dev, &table->vhca_nb); -mlx5_esw_event_notifier_unregister (dev->priv.eswitch, &table->esw_nb); +mlx5_esw_event_notifier_unregister (dev, &table->esw_nb);mutex_destroy (&table->sf_state_lock);WARN_ON (!xa_empty (&table->function_ids));kfree (table);
include/linux/mlx5/driver.h +1 -0
@@ -599,6 +599,7 @@ struct mlx5_priv {struct mlx5_flow_steering *steering;struct mlx5_mpfs *mpfs; +struct blocking_notifier_head esw_n_head;struct mlx5_eswitch *eswitch;struct mlx5_core_sriov sriov;struct mlx5_lag *lag;
Signature · 1 line
2.31.1
Tariq Toukan
maintainerPATCH 3/6 net/mlx5: Move the vhca event notifier outside of the devlink lock
In reply to Tariq ToukanFrom: Cosmin Ratiu <[email protected]>
The vhca event notifier consists of an atomic notifier for vhca state changes (used for SF events), multiple workqueues and a blocking notifier chain for delivering the vhca state change events for further processing.
This patch moves the vhca notifier head outside of mlx5_init_one() / mlx5_uninit_one() and into the mlx5_mdev_init() / mlx5_mdev_uninit() functions.
This allows called notifiers to grab the PF devlink lock which was previously impossible because it would create a circular lock dependency.
mlx5_vhca_event_stop() is now called earlier in the cleanup phase and flushes the workqueues to ensure that after the call, there are no pending events. This simplifies the cleanup flow for vhca event consumers.
--- .../net/ethernet/mellanox/mlx5/core/main.c | 3 +- .../ethernet/mellanox/mlx5/core/sf/dev/dev.c | 1 - .../ethernet/mellanox/mlx5/core/sf/hw_table.c | 1 + .../mellanox/mlx5/core/sf/vhca_event.c | 69 +++++++------------ .../mellanox/mlx5/core/sf/vhca_event.h | 5 ++ include/linux/mlx5/driver.h | 4 +- 6 files changed, 35 insertions(+), 48 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/main.c +2 -1
@@ -1438,12 +1438,12 @@ static void mlx5_unload(struct mlx5_core_dev *dev) {mlx5_eswitch_disable (dev->priv.eswitch);mlx5_devlink_traps_unregister (priv_to_devlink (dev)); +mlx5_vhca_event_stop (dev);mlx5_sf_dev_table_destroy (dev);mlx5_sriov_detach (dev);mlx5_lag_remove_mdev (dev);mlx5_ec_cleanup (dev);mlx5_sf_hw_table_destroy (dev); -mlx5_vhca_event_stop (dev);mlx5_fs_core_cleanup (dev);mlx5_fpga_device_stop (dev);mlx5_rsc_dump_cleanup (dev);
@@ -1835,6 +1835,7 @@ static int mlx5_notifiers_init(struct mlx5_core_dev *dev) }BLOCKING_INIT_NOTIFIER_HEAD (&dev->priv.esw_n_head); +mlx5_vhca_state_notifier_init (dev);return 0 ; }
drivers/net/ethernet/mellanox/mlx5/core/sf/dev/dev.c +0 -1
@@ -381,7 +381,6 @@ void mlx5_sf_dev_table_destroy(struct mlx5_core_dev *dev)mlx5_sf_dev_destroy_active_works (table);mlx5_vhca_event_notifier_unregister (dev, &table->nb); -mlx5_vhca_event_work_queues_flush (dev);/* Now that event handler is not running, it is safe to destroy * the sf device without race.
drivers/net/ethernet/mellanox/mlx5/core/sf/hw_table.c +1 -0
@@ -389,6 +389,7 @@ void mlx5_sf_hw_table_destroy(struct mlx5_core_dev *dev)return ;mlx5_vhca_event_notifier_unregister (dev, &table->vhca_nb); +/* Dealloc SFs whose firmware event has been missed. */ mlx5_sf_hw_table_dealloc_all (table); }
drivers/net/ethernet/mellanox/mlx5/core/sf/vhca_event.c +25 -44
152 lines not on this page · raw message
drivers/net/ethernet/mellanox/mlx5/core/sf/vhca_event.h +5 -0
@@ -18,6 +18,7 @@ static inline bool mlx5_vhca_event_supported(const struct mlx5_core_dev *dev) }void mlx5_vhca_state_cap_handle (struct mlx5_core_dev *dev,void *set_hca_cap); +void mlx5_vhca_state_notifier_init (struct mlx5_core_dev *dev);int mlx5_vhca_event_init (struct mlx5_core_dev *dev);void mlx5_vhca_event_cleanup (struct mlx5_core_dev *dev);void mlx5_vhca_event_start (struct mlx5_core_dev *dev);
@@ -37,6 +38,10 @@ static inline void mlx5_vhca_state_cap_handle(struct mlx5_core_dev *dev, void *s { } +static inline void mlx5_vhca_state_notifier_init (struct mlx5_core_dev *dev) +{ +} +static inline int mlx5_vhca_event_init (struct mlx5_core_dev *dev) {return 0 ;
include/linux/mlx5/driver.h +2 -2
@@ -488,7 +488,6 @@ struct mlx5_devcom_dev;struct mlx5_fw_reset ;struct mlx5_eq_table ;struct mlx5_irq_table ; -struct mlx5_vhca_state_notifier ;struct mlx5_sf_dev_table ;struct mlx5_sf_hw_table ;struct mlx5_sf_table ;
@@ -615,7 +614,8 @@ struct mlx5_priv {struct mlx5_bfreg_data bfregs;struct mlx5_sq_bfreg bfreg;#ifdef CONFIG_MLX5_SF -struct mlx5_vhca_state_notifier *vhca_state_notifier; +struct mlx5_nb vhca_state_nb; +struct blocking_notifier_head vhca_state_n_head;struct mlx5_sf_dev_table *sf_dev_table;struct mlx5_core_dev *parent_mdev;#endif
Signature · 1 line
2.31.1
Tariq Toukan
maintainerPATCH 4/6 net/mlx5: Move the SF HW table notifier outside the devlink lock
In reply to Tariq ToukanFrom: Cosmin Ratiu <[email protected]>
Move the SF HW table notifier registration/unregistration outside of mlx5_init_one() / mlx5_uninit_one() and into the mlx5_mdev_init() / mlx5_mdev_uninit() functions.
This is only done for non-SFs, since SFs do not have a SF HW table themselves.
--- .../net/ethernet/mellanox/mlx5/core/main.c | 17 ++--- .../ethernet/mellanox/mlx5/core/sf/hw_table.c | 62 +++++++++++-------- .../net/ethernet/mellanox/mlx5/core/sf/sf.h | 9 ++- include/linux/mlx5/driver.h | 1 + 4 files changed, 54 insertions(+), 35 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/main.c +9 -8
@@ -1377,12 +1377,6 @@ static int mlx5_load(struct mlx5_core_dev *dev)mlx5_vhca_event_start (dev); - err =mlx5_sf_hw_table_create (dev); -if (err) { -mlx5_core_err (dev,"sf table create failed %d\n" , err); - goto err_vhca; - } - err =mlx5_ec_init (dev);if (err) {mlx5_core_err (dev,"Failed to init embedded CPU\n" );
@@ -1411,8 +1405,6 @@ static int mlx5_load(struct mlx5_core_dev *dev)mlx5_lag_remove_mdev (dev);mlx5_ec_cleanup (dev); err_ec: -mlx5_sf_hw_table_destroy (dev); -err_vhca:mlx5_vhca_event_stop (dev); err_set_hca:mlx5_fs_core_cleanup (dev);
@@ -1837,11 +1829,20 @@ static int mlx5_notifiers_init(struct mlx5_core_dev *dev)BLOCKING_INIT_NOTIFIER_HEAD (&dev->priv.esw_n_head);mlx5_vhca_state_notifier_init (dev); + err =mlx5_sf_hw_notifier_init (dev); +if (err) + goto err_sf_hw_notifier; +return 0 ; + +err_sf_hw_notifier: +mlx5_events_cleanup (dev); +return err; }static void mlx5_notifiers_cleanup (struct mlx5_core_dev *dev) { +mlx5_sf_hw_notifier_cleanup (dev);mlx5_events_cleanup (dev); }
drivers/net/ethernet/mellanox/mlx5/core/sf/hw_table.c +37 -25
158 lines not on this page · raw message
drivers/net/ethernet/mellanox/mlx5/core/sf/sf.h +7 -2
@@ -12,7 +12,8 @@int mlx5_sf_hw_table_init (struct mlx5_core_dev *dev);void mlx5_sf_hw_table_cleanup (struct mlx5_core_dev *dev); -int mlx5_sf_hw_table_create (struct mlx5_core_dev *dev); +int mlx5_sf_hw_notifier_init (struct mlx5_core_dev *dev); +void mlx5_sf_hw_notifier_cleanup (struct mlx5_core_dev *dev);void mlx5_sf_hw_table_destroy (struct mlx5_core_dev *dev);int mlx5_sf_table_init (struct mlx5_core_dev *dev);
@@ -44,11 +45,15 @@ static inline void mlx5_sf_hw_table_cleanup(struct mlx5_core_dev *dev) { } -static inline int mlx5_sf_hw_table_create (struct mlx5_core_dev *dev) +static inline int mlx5_sf_hw_notifier_init (struct mlx5_core_dev *dev) {return 0 ; } +static inline void mlx5_sf_hw_notifier_cleanup (struct mlx5_core_dev *dev) +{ +} +static inline void mlx5_sf_hw_table_destroy (struct mlx5_core_dev *dev) { }
include/linux/mlx5/driver.h +1 -0
@@ -620,6 +620,7 @@ struct mlx5_priv {struct mlx5_core_dev *parent_mdev;#endif #ifdef CONFIG_MLX5_SF_MANAGER +struct notifier_block sf_hw_table_vhca_nb;struct mlx5_sf_hw_table *sf_hw_table;struct mlx5_sf_table *sf_table;#endif
Signature · 1 line
2.31.1
Tariq Toukan
maintainerPATCH 5/6 net/mlx5: Move the SF table notifiers outside the devlink lock
In reply to Tariq ToukanFrom: Cosmin Ratiu <[email protected]>
Move the SF table notifiers registration/unregistration outside of mlx5_init_one() / mlx5_uninit_one() and into the mlx5_mdev_init() / mlx5_mdev_uninit() functions.
This is only done for non-SFs, since SFs do not have a SF table themselves and thus don't need notifiers.
--- .../net/ethernet/mellanox/mlx5/core/main.c | 7 ++ .../ethernet/mellanox/mlx5/core/sf/devlink.c | 90 ++++++++++++------- .../net/ethernet/mellanox/mlx5/core/sf/sf.h | 11 +++ include/linux/mlx5/driver.h | 3 + 4 files changed, 78 insertions(+), 33 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/main.c +7 -0
@@ -1833,8 +1833,14 @@ static int mlx5_notifiers_init(struct mlx5_core_dev *dev)if (err) goto err_sf_hw_notifier; + err =mlx5_sf_notifiers_init (dev); +if (err) + goto err_sf_notifiers; +return 0 ; +err_sf_notifiers: +mlx5_sf_hw_notifier_cleanup (dev); err_sf_hw_notifier:mlx5_events_cleanup (dev);return err;
@@ -1842,6 +1848,7 @@ static int mlx5_notifiers_init(struct mlx5_core_dev *dev)static void mlx5_notifiers_cleanup (struct mlx5_core_dev *dev) { +mlx5_sf_notifiers_cleanup (dev);mlx5_sf_hw_notifier_cleanup (dev);mlx5_events_cleanup (dev); }
drivers/net/ethernet/mellanox/mlx5/core/sf/devlink.c +57 -33
158 lines not on this page · raw message
drivers/net/ethernet/mellanox/mlx5/core/sf/sf.h +11 -0
@@ -16,7 +16,9 @@ int mlx5_sf_hw_notifier_init(struct mlx5_core_dev *dev);void mlx5_sf_hw_notifier_cleanup (struct mlx5_core_dev *dev);void mlx5_sf_hw_table_destroy (struct mlx5_core_dev *dev); +int mlx5_sf_notifiers_init (struct mlx5_core_dev *dev);int mlx5_sf_table_init (struct mlx5_core_dev *dev); +void mlx5_sf_notifiers_cleanup (struct mlx5_core_dev *dev);void mlx5_sf_table_cleanup (struct mlx5_core_dev *dev);bool mlx5_sf_table_empty (const struct mlx5_core_dev *dev);
@@ -58,11 +60,20 @@ static inline void mlx5_sf_hw_table_destroy(struct mlx5_core_dev *dev) { } +static inline int mlx5_sf_notifiers_init (struct mlx5_core_dev *dev) +{ +return 0 ; +} +static inline int mlx5_sf_table_init (struct mlx5_core_dev *dev) {return 0 ; } +static inline void mlx5_sf_notifiers_cleanup (struct mlx5_core_dev *dev) +{ +} +static inline void mlx5_sf_table_cleanup (struct mlx5_core_dev *dev) { }
include/linux/mlx5/driver.h +3 -0
@@ -622,6 +622,9 @@ struct mlx5_priv {#ifdef CONFIG_MLX5_SF_MANAGER struct notifier_block sf_hw_table_vhca_nb;struct mlx5_sf_hw_table *sf_hw_table; +struct notifier_block sf_table_esw_nb; +struct notifier_block sf_table_vhca_nb; +struct notifier_block sf_table_mdev_nb;struct mlx5_sf_table *sf_table;#endif struct blocking_notifier_head lag_nh;
Signature · 1 line
2.31.1
Tariq Toukan
maintainerPATCH 6/6 net/mlx5: Move SF dev table notifier registration outside the PF devlink lock
In reply to Tariq ToukanFrom: Cosmin Ratiu <[email protected]>
This completes the previous patches by moving notifier registration for SF dev tables outside the devlink locked critical section in mlx5_init_one() / mlx5_uninit_one() and into the mlx5_mdev_init() / mlx5_mdev_uninit() functions.
This is only done for non-SFs, since SFs do not have a SF HW table themselves.
After this patch, notifiers can grab the PF devlink lock (soon to be necessary) without creating a locking cycle.
--- .../net/ethernet/mellanox/mlx5/core/main.c | 7 +++ .../ethernet/mellanox/mlx5/core/sf/dev/dev.c | 47 ++++++++++++------- .../ethernet/mellanox/mlx5/core/sf/dev/dev.h | 11 +++++ include/linux/mlx5/driver.h | 1 + 4 files changed, 49 insertions(+), 17 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/main.c +7 -0
@@ -1837,8 +1837,14 @@ static int mlx5_notifiers_init(struct mlx5_core_dev *dev)if (err) goto err_sf_notifiers; + err =mlx5_sf_dev_notifier_init (dev); +if (err) + goto err_sf_dev_notifier; +return 0 ; +err_sf_dev_notifier: +mlx5_sf_notifiers_cleanup (dev); err_sf_notifiers:mlx5_sf_hw_notifier_cleanup (dev); err_sf_hw_notifier:
@@ -1848,6 +1854,7 @@ static int mlx5_notifiers_init(struct mlx5_core_dev *dev)static void mlx5_notifiers_cleanup (struct mlx5_core_dev *dev) { +mlx5_sf_dev_notifier_cleanup (dev);mlx5_sf_notifiers_cleanup (dev);mlx5_sf_hw_notifier_cleanup (dev);mlx5_events_cleanup (dev);
drivers/net/ethernet/mellanox/mlx5/core/sf/dev/dev.c +30 -17
120 lines not on this page · raw message
drivers/net/ethernet/mellanox/mlx5/core/sf/dev/dev.h +11 -0
@@ -25,7 +25,9 @@ struct mlx5_sf_peer_devlink_event_ctx {int err; }; +int mlx5_sf_dev_notifier_init (struct mlx5_core_dev *dev);void mlx5_sf_dev_table_create (struct mlx5_core_dev *dev); +void mlx5_sf_dev_notifier_cleanup (struct mlx5_core_dev *dev);void mlx5_sf_dev_table_destroy (struct mlx5_core_dev *dev);int mlx5_sf_driver_register (void );
@@ -35,10 +37,19 @@ bool mlx5_sf_dev_allocated(const struct mlx5_core_dev *dev);#else +static inline int mlx5_sf_dev_notifier_init (struct mlx5_core_dev *dev) +{ +return 0 ; +} +static inline void mlx5_sf_dev_table_create (struct mlx5_core_dev *dev) { } +static inline void mlx5_sf_dev_notifier_cleanup (struct mlx5_core_dev *dev) +{ +} +static inline void mlx5_sf_dev_table_destroy (struct mlx5_core_dev *dev) { }
include/linux/mlx5/driver.h +1 -0
@@ -616,6 +616,7 @@ struct mlx5_priv {#ifdef CONFIG_MLX5_SF struct mlx5_nb vhca_state_nb;struct blocking_notifier_head vhca_state_n_head; +struct notifier_block sf_dev_nb;struct mlx5_sf_dev_table *sf_dev_table;struct mlx5_core_dev *parent_mdev;#endif
Signature · 1 line
2.31.1
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Quoted 11 lines · On Sun, 16 Nov 2025 22:45:34 +0200 you wrote:
Hi,
This series by Cosmin moves blocking notifier registration in the mlx5 driver outside the devlink lock during probe.
This is mostly a no-op refactoring that consists of multiple pieces. It is necessary because upcoming code will introduce a potential locking cycle between the devlink lock and the blocking notifier head mutexes, so these notifiers must move out of the devlink-locked critical section.
[...]
Here is the summary with links:
- [net-next,1/6] net/mlx5: Initialize events outside devlink lock
https://git.kernel.org/netdev/net-next/c/b6b03097f982 - [net-next,2/6] net/mlx5: Move the esw mode notifier chain outside the devlink lock https://git.kernel.org/netdev/net-next/c/3fee828789b1 - [net-next,3/6] net/mlx5: Move the vhca event notifier outside of the devlink lock https://git.kernel.org/netdev/net-next/c/d3a356db853b - [net-next,4/6] net/mlx5: Move the SF HW table notifier outside the devlink lock https://git.kernel.org/netdev/net-next/c/e63c9c5f0a48 - [net-next,5/6] net/mlx5: Move the SF table notifiers outside the devlink lock https://git.kernel.org/netdev/net-next/c/d4a0acbd94c2 - [net-next,6/6] net/mlx5: Move SF dev table notifier registration outside the PF devlink lock https://git.kernel.org/netdev/net-next/c/64ad6470c882
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html