1 From foo@baz Mon Apr 15 07:47:06 CEST 2019
2 From: Yuval Avnery <yuvalav@mellanox.com>
3 Date: Mon, 11 Mar 2019 06:18:24 +0200
4 Subject: net/mlx5e: Add a lock on tir list
6 From: Yuval Avnery <yuvalav@mellanox.com>
8 [ Upstream commit 80a2a9026b24c6bd34b8d58256973e22270bedec ]
10 Refresh tirs is looping over a global list of tirs while netdevs are
11 adding and removing tirs from that list. That is why a lock is
14 Fixes: 724b2aa15126 ("net/mlx5e: TIRs management refactoring")
15 Signed-off-by: Yuval Avnery <yuvalav@mellanox.com>
16 Signed-off-by: Saeed Mahameed <saeedm@mellanox.com>
17 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
19 drivers/net/ethernet/mellanox/mlx5/core/en_common.c | 7 +++++++
20 include/linux/mlx5/driver.h | 2 ++
21 2 files changed, 9 insertions(+)
23 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_common.c
24 +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_common.c
25 @@ -45,7 +45,9 @@ int mlx5e_create_tir(struct mlx5_core_de
29 + mutex_lock(&mdev->mlx5e_res.td.list_lock);
30 list_add(&tir->list, &mdev->mlx5e_res.td.tirs_list);
31 + mutex_unlock(&mdev->mlx5e_res.td.list_lock);
35 @@ -53,8 +55,10 @@ int mlx5e_create_tir(struct mlx5_core_de
36 void mlx5e_destroy_tir(struct mlx5_core_dev *mdev,
37 struct mlx5e_tir *tir)
39 + mutex_lock(&mdev->mlx5e_res.td.list_lock);
40 mlx5_core_destroy_tir(mdev, tir->tirn);
42 + mutex_unlock(&mdev->mlx5e_res.td.list_lock);
45 static int mlx5e_create_mkey(struct mlx5_core_dev *mdev, u32 pdn,
46 @@ -114,6 +118,7 @@ int mlx5e_create_mdev_resources(struct m
49 INIT_LIST_HEAD(&mdev->mlx5e_res.td.tirs_list);
50 + mutex_init(&mdev->mlx5e_res.td.list_lock);
54 @@ -158,6 +163,7 @@ int mlx5e_refresh_tirs(struct mlx5e_priv
56 MLX5_SET(modify_tir_in, in, bitmask.self_lb_en, 1);
58 + mutex_lock(&mdev->mlx5e_res.td.list_lock);
59 list_for_each_entry(tir, &mdev->mlx5e_res.td.tirs_list, list) {
61 err = mlx5_core_modify_tir(mdev, tirn, in, inlen);
62 @@ -169,6 +175,7 @@ out:
65 netdev_err(priv->netdev, "refresh tir(0x%x) failed, %d\n", tirn, err);
66 + mutex_unlock(&mdev->mlx5e_res.td.list_lock);
70 --- a/include/linux/mlx5/driver.h
71 +++ b/include/linux/mlx5/driver.h
72 @@ -743,6 +743,8 @@ struct mlx5_pagefault {
76 + /* protects tirs list changes while tirs refresh */
77 + struct mutex list_lock;
78 struct list_head tirs_list;