]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
net/mlx5: E-Switch, add representor lifecycle lock
authorMark Bloch <mbloch@nvidia.com>
Sun, 3 May 2026 20:27:22 +0000 (23:27 +0300)
committerJakub Kicinski <kuba@kernel.org>
Thu, 7 May 2026 02:03:37 +0000 (19:03 -0700)
Add a per-E-Switch mutex for serializing representor lifecycle work and
provide small helpers for taking and dropping it. Initialize and destroy
the mutex with the E-Switch offloads state.

Add the lock and helper API first. Follow-up patches will take the lock in
the individual representor lifecycle components. This keeps the functional
changes split by component and leaves this patch without intended behavior
change, making the series easier to review and bisectable.

Signed-off-by: Mark Bloch <mbloch@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
Link: https://patch.msgid.link/20260503202726.266415-4-tariqt@nvidia.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/mellanox/mlx5/core/eswitch.h
drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c

index 2fd601bd102f42d1e66413721d7309138d3bd9a0..3858690e09b42fdade6f6c8441df55a35b4f5256 100644 (file)
@@ -316,6 +316,7 @@ struct mlx5_esw_offload {
        DECLARE_HASHTABLE(termtbl_tbl, 8);
        struct mutex termtbl_mutex; /* protects termtbl hash */
        struct xarray vhca_map;
+       struct mutex reps_lock; /* protects representor load/unload/register */
        const struct mlx5_eswitch_rep_ops *rep_ops[NUM_REP_TYPES];
        u8 inline_mode;
        atomic64_t num_flows;
@@ -951,6 +952,8 @@ mlx5_esw_lag_demux_fg_create(struct mlx5_eswitch *esw,
 struct mlx5_flow_handle *
 mlx5_esw_lag_demux_rule_create(struct mlx5_eswitch *esw, u16 vport_num,
                               struct mlx5_flow_table *lag_ft);
+void mlx5_esw_reps_block(struct mlx5_eswitch *esw);
+void mlx5_esw_reps_unblock(struct mlx5_eswitch *esw);
 #else  /* CONFIG_MLX5_ESWITCH */
 /* eswitch API stubs */
 static inline int  mlx5_eswitch_init(struct mlx5_core_dev *dev) { return 0; }
@@ -1028,6 +1031,9 @@ mlx5_esw_host_functions_enabled(const struct mlx5_core_dev *dev)
        return true;
 }
 
+static inline void mlx5_esw_reps_block(struct mlx5_eswitch *esw) {}
+static inline void mlx5_esw_reps_unblock(struct mlx5_eswitch *esw) {}
+
 static inline bool
 mlx5_esw_vport_vhca_id(struct mlx5_eswitch *esw, u16 vportn, u16 *vhca_id)
 {
index 69134ce2a908186c2345be6095caafecc115770b..af7d0d58c048b5038b6ff508b49cba00a374159c 100644 (file)
@@ -2413,6 +2413,16 @@ out_free:
        return err;
 }
 
+void mlx5_esw_reps_block(struct mlx5_eswitch *esw)
+{
+       mutex_lock(&esw->offloads.reps_lock);
+}
+
+void mlx5_esw_reps_unblock(struct mlx5_eswitch *esw)
+{
+       mutex_unlock(&esw->offloads.reps_lock);
+}
+
 static void esw_mode_change(struct mlx5_eswitch *esw, u16 mode)
 {
        mlx5_devcom_comp_lock(esw->dev->priv.hca_devcom_comp);
@@ -2645,6 +2655,7 @@ static void esw_offloads_cleanup_reps(struct mlx5_eswitch *esw)
        mlx5_esw_for_each_rep(esw, i, rep)
                mlx5_esw_offloads_rep_cleanup(esw, rep);
        xa_destroy(&esw->offloads.vport_reps);
+       mutex_destroy(&esw->offloads.reps_lock);
 }
 
 static int esw_offloads_init_reps(struct mlx5_eswitch *esw)
@@ -2654,6 +2665,7 @@ static int esw_offloads_init_reps(struct mlx5_eswitch *esw)
        int err;
 
        xa_init(&esw->offloads.vport_reps);
+       mutex_init(&esw->offloads.reps_lock);
 
        mlx5_esw_for_each_vport(esw, i, vport) {
                err = mlx5_esw_offloads_rep_add(esw, vport);