Blob Blame History Raw
From 408a7bc962940848151942ebf8ee76c0f150d893 Mon Sep 17 00:00:00 2001
From: Alaa Hleihel <ahleihel@redhat.com>
Date: Tue, 19 May 2020 07:49:12 -0400
Subject: [PATCH 250/312] [netdrv] net/mlx5: E-switch, Fix mutex init order

Message-id: <20200519074934.6303-42-ahleihel@redhat.com>
Patchwork-id: 310554
Patchwork-instance: patchwork
O-Subject: [RHEL8.3 BZ 1663246 41/63] net/mlx5: E-switch, Fix mutex init order
Bugzilla: 1663246
RH-Acked-by: Marcelo Leitner <mleitner@redhat.com>
RH-Acked-by: Jarod Wilson <jarod@redhat.com>
RH-Acked-by: John Linville <linville@redhat.com>
RH-Acked-by: Ivan Vecera <ivecera@redhat.com>
RH-Acked-by: Tony Camuso <tcamuso@redhat.com>
RH-Acked-by: Kamal Heib <kheib@redhat.com>

Bugzilla: http://bugzilla.redhat.com/1663246
Upstream: v5.7-rc5

commit f8d1eddaf94abdc459ccfb881aa7233cb9f7f39a
Author: Parav Pandit <parav@mellanox.com>
Date:   Tue Apr 21 05:36:07 2020 -0500

    net/mlx5: E-switch, Fix mutex init order

    In cited patch mutex is initialized after its used.
    Below call trace is observed.
    Fix the order to initialize the mutex early enough.
    Similarly follow mirror sequence during cleanup.

    kernel: DEBUG_LOCKS_WARN_ON(lock->magic != lock)
    kernel: WARNING: CPU: 5 PID: 45916 at kernel/locking/mutex.c:938
    __mutex_lock+0x7d6/0x8a0
    kernel: Call Trace:
    kernel: ? esw_vport_tbl_get+0x3b/0x250 [mlx5_core]
    kernel: ? mark_held_locks+0x55/0x70
    kernel: ? __slab_free+0x274/0x400
    kernel: ? lockdep_hardirqs_on+0x140/0x1d0
    kernel: esw_vport_tbl_get+0x3b/0x250 [mlx5_core]
    kernel: ? mlx5_esw_chains_create_fdb_prio+0xa57/0xc20 [mlx5_core]
    kernel: mlx5_esw_vport_tbl_get+0x88/0xf0 [mlx5_core]
    kernel: mlx5_esw_chains_create+0x2f3/0x3e0 [mlx5_core]
    kernel: esw_create_offloads_fdb_tables+0x11d/0x580 [mlx5_core]
    kernel: esw_offloads_enable+0x26d/0x540 [mlx5_core]
    kernel: mlx5_eswitch_enable_locked+0x155/0x860 [mlx5_core]
    kernel: mlx5_devlink_eswitch_mode_set+0x1af/0x320 [mlx5_core]
    kernel: devlink_nl_cmd_eswitch_set_doit+0x41/0xb0

    Fixes: 96e326878fa5 ("net/mlx5e: Eswitch, Use per vport tables for mirroring")
    Signed-off-by: Parav Pandit <parav@mellanox.com>
    Reviewed-by: Roi Dayan <roid@mellanox.com>
    Reviewed-by: Eli Cohen <eli@mellanox.com>
    Signed-off-by: Saeed Mahameed <saeedm@mellanox.com>

Signed-off-by: Alaa Hleihel <ahleihel@redhat.com>
Signed-off-by: Frantisek Hrbata <fhrbata@redhat.com>
---
 drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c b/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c
index 3a6434ba2a58..f6fd7df0e864 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c
@@ -2292,10 +2292,12 @@ static int esw_offloads_steering_init(struct mlx5_eswitch *esw)
 		total_vports = num_vfs + MLX5_SPECIAL_VPORTS(esw->dev);
 
 	memset(&esw->fdb_table.offloads, 0, sizeof(struct offloads_fdb));
+	mutex_init(&esw->fdb_table.offloads.vports.lock);
+	hash_init(esw->fdb_table.offloads.vports.table);
 
 	err = esw_create_uplink_offloads_acl_tables(esw);
 	if (err)
-		return err;
+		goto create_acl_err;
 
 	err = esw_create_offloads_table(esw, total_vports);
 	if (err)
@@ -2313,9 +2315,6 @@ static int esw_offloads_steering_init(struct mlx5_eswitch *esw)
 	if (err)
 		goto create_fg_err;
 
-	mutex_init(&esw->fdb_table.offloads.vports.lock);
-	hash_init(esw->fdb_table.offloads.vports.table);
-
 	return 0;
 
 create_fg_err:
@@ -2326,18 +2325,19 @@ static int esw_offloads_steering_init(struct mlx5_eswitch *esw)
 	esw_destroy_offloads_table(esw);
 create_offloads_err:
 	esw_destroy_uplink_offloads_acl_tables(esw);
-
+create_acl_err:
+	mutex_destroy(&esw->fdb_table.offloads.vports.lock);
 	return err;
 }
 
 static void esw_offloads_steering_cleanup(struct mlx5_eswitch *esw)
 {
-	mutex_destroy(&esw->fdb_table.offloads.vports.lock);
 	esw_destroy_vport_rx_group(esw);
 	esw_destroy_offloads_fdb_tables(esw);
 	esw_destroy_restore_table(esw);
 	esw_destroy_offloads_table(esw);
 	esw_destroy_uplink_offloads_acl_tables(esw);
+	mutex_destroy(&esw->fdb_table.offloads.vports.lock);
 }
 
 static void
-- 
2.13.6